diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index 5e0c720f00..c4a8667620 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -1332,7 +1332,7 @@ struct AIDebugWindow : public Window { } if (all_unpaused) { /* All scripts have been unpaused => unpause the game. */ - Command::Post(0, PM_PAUSED_NORMAL, 0, {}); + Command::Post(PM_PAUSED_NORMAL, false); } } } @@ -1381,7 +1381,7 @@ struct AIDebugWindow : public Window { /* Pause the game. */ if ((_pause_mode & PM_PAUSED_NORMAL) == PM_UNPAUSED) { - Command::Post(0, PM_PAUSED_NORMAL, 1, {}); + Command::Post(PM_PAUSED_NORMAL, true); } /* Highlight row that matched */ diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp index 00eba4044b..4dae0eedc7 100644 --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -547,7 +547,7 @@ public: Command::Post(this->sel_group, GroupFlags::GF_REPLACE_WAGON_REMOVAL, !HasBit(g->flags, GroupFlags::GF_REPLACE_WAGON_REMOVAL), _ctrl_pressed); } else { // toggle renew_keep_length - Command::Post(0, 0, Company::Get(_local_company)->settings.renew_keep_length ? 0 : 1, "company.renew_keep_length"); + Command::Post("company.renew_keep_length", Company::Get(_local_company)->settings.renew_keep_length ? 0 : 1); } break; } diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp index fcc9a3ef07..eb62dc0317 100644 --- a/src/cheat_gui.cpp +++ b/src/cheat_gui.cpp @@ -55,7 +55,7 @@ static int32 _money_cheat_amount = 10000000; */ static int32 ClickMoneyCheat(int32 p1, int32 p2) { - Command::Post(0, (uint32)(p2 * _money_cheat_amount), 0, {}); + Command::Post(p2 * _money_cheat_amount); return _money_cheat_amount; } diff --git a/src/command_type.h b/src/command_type.h index 59331dc7cc..0424782a23 100644 --- a/src/command_type.h +++ b/src/command_type.h @@ -404,26 +404,6 @@ enum CommandPauseLevel { CMDPL_ALL_ACTIONS, ///< All actions may be executed. }; -/** - * Defines the callback type for all command handler functions. - * - * This type defines the function header for all functions which handles a CMD_* command. - * A command handler use the parameters to act according to the meaning of the command. - * The tile parameter defines the tile to perform an action on. - * The flag parameter is filled with flags from the DC_* enumeration. The parameters - * p1 and p2 are filled with parameters for the command like "which road type", "which - * order" or "direction". Each function should mentioned in there doxygen comments - * the usage of these parameters. - * - * @param tile The tile to apply a command on - * @param flags Flags for the command, from the DC_* enumeration - * @param p1 Additional data for the command - * @param p2 Additional data for the command - * @param text Additional text - * @return The CommandCost of the command, which can be succeeded or failed. - */ -typedef CommandCost CommandProc(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text); - template struct CommandFunctionTraitHelper; template diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 87231f3eb6..016a830bf9 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -916,16 +916,11 @@ CommandCost CmdCompanyCtrl(DoCommandFlag flags, CompanyCtrlAction cca, CompanyID /** * Change the company manager's face. * @param flags operation to perform - * @param tile unused - * @param p1 unused - * @param p2 face bitmasked - * @param text unused + * @param cmf face bitmasked * @return the cost of this operation or an error */ -CommandCost CmdSetCompanyManagerFace(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdSetCompanyManagerFace(DoCommandFlag flags, CompanyManagerFace cmf) { - CompanyManagerFace cmf = (CompanyManagerFace)p2; - if (!IsValidCompanyManagerFace(cmf)) return CMD_ERROR; if (flags & DC_EXEC) { @@ -938,20 +933,13 @@ CommandCost CmdSetCompanyManagerFace(DoCommandFlag flags, TileIndex tile, uint32 /** * Change the company's company-colour * @param flags operation to perform - * @param tile unused - * @param p1 bitstuffed: - * p1 bits 0-7 scheme to set - * p1 bit 8 set first/second colour - * @param p2 new colour for vehicles, property, etc. - * @param text unused + * @param scheme scheme to set + * @param primary set first/second colour + * @param colour new colour for vehicles, property, etc. * @return the cost of this operation or an error */ -CommandCost CmdSetCompanyColour(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdSetCompanyColour(DoCommandFlag flags, LiveryScheme scheme, bool primary, Colours colour) { - Colours colour = Extract(p2); - LiveryScheme scheme = Extract(p1); - bool second = HasBit(p1, 8); - if (scheme >= LS_END || (colour >= COLOUR_END && colour != INVALID_COLOUR)) return CMD_ERROR; /* Default scheme can't be reset to invalid. */ @@ -960,14 +948,14 @@ CommandCost CmdSetCompanyColour(DoCommandFlag flags, TileIndex tile, uint32 p1, Company *c = Company::Get(_current_company); /* Ensure no two companies have the same primary colour */ - if (scheme == LS_DEFAULT && !second) { + if (scheme == LS_DEFAULT && primary) { for (const Company *cc : Company::Iterate()) { if (cc != c && cc->colour == colour) return CMD_ERROR; } } if (flags & DC_EXEC) { - if (!second) { + if (primary) { if (scheme != LS_DEFAULT) SB(c->livery[scheme].in_use, 0, 1, colour != INVALID_COLOUR); if (colour == INVALID_COLOUR) colour = (Colours)c->livery[LS_DEFAULT].colour1; c->livery[scheme].colour1 = colour; @@ -1051,13 +1039,10 @@ static bool IsUniqueCompanyName(const std::string &name) /** * Change the name of the company. * @param flags operation to perform - * @param tile unused - * @param p1 unused - * @param p2 unused * @param text the new name or an empty string when resetting to the default * @return the cost of this operation or an error */ -CommandCost CmdRenameCompany(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdRenameCompany(DoCommandFlag flags, const std::string &text) { bool reset = text.empty(); @@ -1097,13 +1082,10 @@ static bool IsUniquePresidentName(const std::string &name) /** * Change the name of the president. * @param flags operation to perform - * @param tile unused - * @param p1 unused - * @param p2 unused * @param text the new name or an empty string when resetting to the default * @return the cost of this operation or an error */ -CommandCost CmdRenamePresident(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdRenamePresident(DoCommandFlag flags, const std::string &text) { bool reset = text.empty(); @@ -1121,7 +1103,7 @@ CommandCost CmdRenamePresident(DoCommandFlag flags, TileIndex tile, uint32 p1, u c->president_name = text; if (c->name_1 == STR_SV_UNNAMED && c->name.empty()) { - Command::Do(DC_EXEC, 0, 0, 0, text + " Transport"); + Command::Do(DC_EXEC, text + " Transport"); } } @@ -1182,19 +1164,16 @@ uint32 CompanyInfrastructure::GetTramTotal() const * companies if you have paid off your loan (either explicitly, or implicitly * given the fact that you have more money than loan). * @param flags operation to perform - * @param tile unused - * @param p1 the amount of money to transfer; max 20.000.000 - * @param p2 the company to transfer the money to - * @param text unused + * @param money the amount of money to transfer; max 20.000.000 + * @param dest_company the company to transfer the money to * @return the cost of this operation or an error */ -CommandCost CmdGiveMoney(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdGiveMoney(DoCommandFlag flags, uint32 money, CompanyID dest_company) { if (!_settings_game.economy.give_money) return CMD_ERROR; const Company *c = Company::Get(_current_company); - CommandCost amount(EXPENSES_OTHER, std::min(p1, 20000000LL)); - CompanyID dest_company = (CompanyID)p2; + CommandCost amount(EXPENSES_OTHER, std::min(money, 20000000LL)); /* You can only transfer funds that is in excess of your loan */ if (c->money - c->current_loan < amount.GetCost() || amount.GetCost() < 0) return_cmd_error(STR_ERROR_INSUFFICIENT_FUNDS); diff --git a/src/company_cmd.h b/src/company_cmd.h index 107a77f29c..5ffac5cbde 100644 --- a/src/company_cmd.h +++ b/src/company_cmd.h @@ -11,15 +11,18 @@ #define COMPANY_CMD_H #include "command_type.h" +#include "company_type.h" +#include "livery.h" enum ClientID : uint32; +enum Colours : byte; CommandCost CmdCompanyCtrl(DoCommandFlag flags, CompanyCtrlAction cca, CompanyID company_id, CompanyRemoveReason reason, ClientID client_id); -CommandProc CmdGiveMoney; -CommandProc CmdRenameCompany; -CommandProc CmdRenamePresident; -CommandProc CmdSetCompanyManagerFace; -CommandProc CmdSetCompanyColour; +CommandCost CmdGiveMoney(DoCommandFlag flags, uint32 money, CompanyID dest_company); +CommandCost CmdRenameCompany(DoCommandFlag flags, const std::string &text); +CommandCost CmdRenamePresident(DoCommandFlag flags, const std::string &text); +CommandCost CmdSetCompanyManagerFace(DoCommandFlag flags, CompanyManagerFace cmf); +CommandCost CmdSetCompanyColour(DoCommandFlag flags, LiveryScheme scheme, bool primary, Colours colour); DEF_CMD_TRAIT(CMD_COMPANY_CTRL, CmdCompanyCtrl, CMD_SPECTATOR | CMD_CLIENT_ID | CMD_NO_EST, CMDT_SERVER_SETTING) DEF_CMD_TRAIT(CMD_GIVE_MONEY, CmdGiveMoney, 0, CMDT_MONEY_MANAGEMENT) diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 7e65b43ac2..66ef1a9898 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -440,11 +440,11 @@ struct CompanyFinancesWindow : Window { break; case WID_CF_INCREASE_LOAN: // increase loan - Command::Post(STR_ERROR_CAN_T_BORROW_ANY_MORE_MONEY, 0, 0, _ctrl_pressed, {}); + Command::Post(STR_ERROR_CAN_T_BORROW_ANY_MORE_MONEY, _ctrl_pressed ? LoanCommand::Max : LoanCommand::Interval, 0); break; case WID_CF_REPAY_LOAN: // repay loan - Command::Post(STR_ERROR_CAN_T_REPAY_LOAN, 0, 0, _ctrl_pressed, {}); + Command::Post(STR_ERROR_CAN_T_REPAY_LOAN, _ctrl_pressed ? LoanCommand::Max : LoanCommand::Interval, 0); break; case WID_CF_INFRASTRUCTURE: // show infrastructure details @@ -1000,7 +1000,7 @@ public: for (LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) { /* Changed colour for the selected scheme, or all visible schemes if CTRL is pressed. */ if (HasBit(this->sel, scheme) || (_ctrl_pressed && _livery_class[scheme] == this->livery_class && HasBit(_loaded_newgrf_features.used_liveries, scheme))) { - Command::Post(0, scheme | (widget == WID_SCL_PRI_COL_DROPDOWN ? 0 : 256), index, {}); + Command::Post(scheme, widget == WID_SCL_PRI_COL_DROPDOWN, (Colours)index); } } } else { @@ -1586,7 +1586,7 @@ public: /* OK button */ case WID_SCMF_ACCEPT: - Command::Post(0, 0, this->face, {}); + Command::Post(this->face); FALLTHROUGH; /* Cancel button */ @@ -2581,11 +2581,11 @@ struct CompanyWindow : Window break; case WID_C_BUY_SHARE: - Command::Post(STR_ERROR_CAN_T_BUY_25_SHARE_IN_THIS, 0, this->window_number, 0, {}); + Command::Post(STR_ERROR_CAN_T_BUY_25_SHARE_IN_THIS, (CompanyID)this->window_number); break; case WID_C_SELL_SHARE: - Command::Post(STR_ERROR_CAN_T_SELL_25_SHARE_IN, 0, this->window_number, 0, {}); + Command::Post(STR_ERROR_CAN_T_SELL_25_SHARE_IN, (CompanyID)this->window_number); break; case WID_C_COMPANY_PASSWORD: @@ -2640,16 +2640,16 @@ struct CompanyWindow : Window Money money = (Money)(strtoull(str, nullptr, 10) / _currency->rate); uint32 money_c = Clamp(ClampToI32(money), 0, 20000000); // Clamp between 20 million and 0 - Command::Post(STR_ERROR_CAN_T_GIVE_MONEY, 0, money_c, this->window_number, {}); + Command::Post(STR_ERROR_CAN_T_GIVE_MONEY, money_c, (CompanyID)this->window_number); break; } case WID_C_PRESIDENT_NAME: - Command::Post(STR_ERROR_CAN_T_CHANGE_PRESIDENT, 0, 0, 0, str); + Command::Post(STR_ERROR_CAN_T_CHANGE_PRESIDENT, str); break; case WID_C_COMPANY_NAME: - Command::Post(STR_ERROR_CAN_T_CHANGE_COMPANY_NAME, 0, 0, 0, str); + Command::Post(STR_ERROR_CAN_T_CHANGE_COMPANY_NAME, str); break; case WID_C_COMPANY_JOIN: @@ -2776,7 +2776,7 @@ struct BuyCompanyWindow : Window { break; case WID_BC_YES: - Command::Post(STR_ERROR_CAN_T_BUY_COMPANY, 0, this->window_number, 0, {}); + Command::Post(STR_ERROR_CAN_T_BUY_COMPANY, (CompanyID)this->window_number); break; } } diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 9e244dd439..7f663fe863 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -632,7 +632,7 @@ DEF_CONSOLE_CMD(ConPauseGame) } if ((_pause_mode & PM_PAUSED_NORMAL) == PM_UNPAUSED) { - Command::Post(0, PM_PAUSED_NORMAL, 1, {}); + Command::Post(PM_PAUSED_NORMAL, true); if (!_networking) IConsolePrint(CC_DEFAULT, "Game paused."); } else { IConsolePrint(CC_DEFAULT, "Game is already paused."); @@ -654,7 +654,7 @@ DEF_CONSOLE_CMD(ConUnpauseGame) } if ((_pause_mode & PM_PAUSED_NORMAL) != PM_UNPAUSED) { - Command::Post(0, PM_PAUSED_NORMAL, 0, {}); + Command::Post(PM_PAUSED_NORMAL, false); if (!_networking) IConsolePrint(CC_DEFAULT, "Game unpaused."); } else if ((_pause_mode & PM_PAUSED_ERROR) != PM_UNPAUSED) { IConsolePrint(CC_DEFAULT, "Game is in error state and cannot be unpaused via console."); diff --git a/src/core/overflowsafe_type.hpp b/src/core/overflowsafe_type.hpp index 29aab175b3..14f0eaa7a7 100644 --- a/src/core/overflowsafe_type.hpp +++ b/src/core/overflowsafe_type.hpp @@ -39,9 +39,10 @@ public: constexpr OverflowSafeInt() : m_value(0) { } constexpr OverflowSafeInt(const OverflowSafeInt& other) : m_value(other.m_value) { } - constexpr OverflowSafeInt(const int64 int_) : m_value(int_) { } + constexpr OverflowSafeInt(const T int_) : m_value(int_) { } inline constexpr OverflowSafeInt& operator = (const OverflowSafeInt& other) { this->m_value = other.m_value; return *this; } + inline constexpr OverflowSafeInt& operator = (T other) { this->m_value = other; return *this; } inline constexpr OverflowSafeInt operator - () const { return OverflowSafeInt(this->m_value == T_MIN ? T_MAX : -this->m_value); } @@ -174,7 +175,7 @@ public: inline constexpr bool operator < (const int other) const { return !(*this >= other); } inline constexpr bool operator <= (const int other) const { return !(*this > other); } - inline constexpr operator int64 () const { return this->m_value; } + inline constexpr operator T () const { return this->m_value; } }; diff --git a/src/economy.cpp b/src/economy.cpp index 5c7c2cee51..6fb3d2795d 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -315,7 +315,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner) for (i = 0; i < 4; i++) { if (c->share_owners[i] == old_owner) { /* Sell its shares */ - CommandCost res = Command::Do(DC_EXEC | DC_BANKRUPT, 0, c->index, 0, {}); + CommandCost res = Command::Do(DC_EXEC | DC_BANKRUPT, c->index); /* Because we are in a DoCommand, we can't just execute another one and * expect the money to be removed. We need to do it ourself! */ SubtractMoneyFromCompany(res); @@ -335,7 +335,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner) } else { cur_company2.Change(c->share_owners[i]); /* Sell the shares */ - CommandCost res = Command::Do(DC_EXEC | DC_BANKRUPT, 0, old_owner, 0, {}); + CommandCost res = Command::Do(DC_EXEC | DC_BANKRUPT, old_owner); /* Because we are in a DoCommand, we can't just execute another one and * expect the money to be removed. We need to do it ourself! */ SubtractMoneyFromCompany(res); @@ -2013,16 +2013,12 @@ extern int GetAmountOwnedBy(const Company *c, Owner owner); /** * Acquire shares in an opposing company. * @param flags type of operation - * @param tile unused * @param p1 company to buy the shares from - * @param p2 unused - * @param text unused * @return the cost of this operation or an error */ -CommandCost CmdBuyShareInCompany(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdBuyShareInCompany(DoCommandFlag flags, TileIndex tile, CompanyID target_company) { CommandCost cost(EXPENSES_OTHER); - CompanyID target_company = (CompanyID)p1; Company *c = Company::GetIfValid(target_company); /* Check if buying shares is allowed (protection against modified clients) @@ -2065,15 +2061,11 @@ CommandCost CmdBuyShareInCompany(DoCommandFlag flags, TileIndex tile, uint32 p1, /** * Sell shares in an opposing company. * @param flags type of operation - * @param tile unused - * @param p1 company to sell the shares from - * @param p2 unused - * @param text unused + * @param target_company company to sell the shares from * @return the cost of this operation or an error */ -CommandCost CmdSellShareInCompany(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdSellShareInCompany(DoCommandFlag flags, CompanyID target_company) { - CompanyID target_company = (CompanyID)p1; Company *c = Company::GetIfValid(target_company); /* Cannot sell own shares */ @@ -2106,15 +2098,11 @@ CommandCost CmdSellShareInCompany(DoCommandFlag flags, TileIndex tile, uint32 p1 * that company. * @todo currently this only works for AI companies * @param flags type of operation - * @param tile unused - * @param p1 company to buy up - * @param p2 unused - * @param text unused + * @param target_company company to buy up * @return the cost of this operation or an error */ -CommandCost CmdBuyCompany(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdBuyCompany(DoCommandFlag flags, CompanyID target_company) { - CompanyID target_company = (CompanyID)p1; Company *c = Company::GetIfValid(target_company); if (c == nullptr) return CMD_ERROR; diff --git a/src/economy_cmd.h b/src/economy_cmd.h index f182af81f2..e5cc282c99 100644 --- a/src/economy_cmd.h +++ b/src/economy_cmd.h @@ -11,10 +11,11 @@ #define ECONOMY_CMD_H #include "command_type.h" +#include "company_type.h" -CommandProc CmdBuyShareInCompany; -CommandProc CmdSellShareInCompany; -CommandProc CmdBuyCompany; +CommandCost CmdBuyShareInCompany(DoCommandFlag flags, TileIndex tile, CompanyID target_company); +CommandCost CmdSellShareInCompany(DoCommandFlag flags, CompanyID target_company); +CommandCost CmdBuyCompany(DoCommandFlag flags, CompanyID target_company); DEF_CMD_TRAIT(CMD_BUY_SHARE_IN_COMPANY, CmdBuyShareInCompany, 0, CMDT_MONEY_MANAGEMENT) DEF_CMD_TRAIT(CMD_SELL_SHARE_IN_COMPANY, CmdSellShareInCompany, 0, CMDT_MONEY_MANAGEMENT) diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index 73315edf0f..3014bc00ec 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -359,7 +359,7 @@ public: /* pause is only used in single-player, non-editor mode, non-menu mode. It * will be unpaused in the WE_DESTROY event handler. */ if (_game_mode != GM_MENU && !_networking && _game_mode != GM_EDITOR) { - Command::Post(0, PM_PAUSED_SAVELOAD, 1, {}); + Command::Post(PM_PAUSED_SAVELOAD, true); } SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, HT_NONE, WC_MAIN_WINDOW, 0); @@ -403,7 +403,7 @@ public: { /* pause is only used in single-player, non-editor mode, non menu mode */ if (!_networking && _game_mode != GM_EDITOR && _game_mode != GM_MENU) { - Command::Post(0, PM_PAUSED_SAVELOAD, 0, {}); + Command::Post(PM_PAUSED_SAVELOAD, false); } this->Window::Close(); } diff --git a/src/highscore_gui.cpp b/src/highscore_gui.cpp index bf09b1b949..0ccc288f05 100644 --- a/src/highscore_gui.cpp +++ b/src/highscore_gui.cpp @@ -97,7 +97,7 @@ struct EndGameWindow : EndGameHighScoreBaseWindow { EndGameWindow(WindowDesc *desc) : EndGameHighScoreBaseWindow(desc) { /* Pause in single-player to have a look at the highscore at your own leisure */ - if (!_networking) Command::Post(0, PM_PAUSED_NORMAL, 1, {}); + if (!_networking) Command::Post(PM_PAUSED_NORMAL, true); this->background_img = SPR_TYCOON_IMG1_BEGIN; @@ -125,7 +125,7 @@ struct EndGameWindow : EndGameHighScoreBaseWindow { void Close() override { - if (!_networking) Command::Post(0, PM_PAUSED_NORMAL, 0, {}); // unpause + if (!_networking) Command::Post(PM_PAUSED_NORMAL, false); // unpause ShowHighscoreTable(this->window_number, this->rank); this->EndGameHighScoreBaseWindow::Close(); } @@ -160,7 +160,7 @@ struct HighScoreWindow : EndGameHighScoreBaseWindow { { /* pause game to show the chart */ this->game_paused_by_player = _pause_mode == PM_PAUSED_NORMAL; - if (!_networking && !this->game_paused_by_player) Command::Post(0, PM_PAUSED_NORMAL, 1, {}); + if (!_networking && !this->game_paused_by_player) Command::Post(PM_PAUSED_NORMAL, true); /* Close all always on-top windows to get a clean screen */ if (_game_mode != GM_MENU) HideVitalWindows(); @@ -175,7 +175,7 @@ struct HighScoreWindow : EndGameHighScoreBaseWindow { { if (_game_mode != GM_MENU) ShowVitalWindows(); - if (!_networking && !this->game_paused_by_player) Command::Post(0, PM_PAUSED_NORMAL, 0, {}); // unpause + if (!_networking && !this->game_paused_by_player) Command::Post(PM_PAUSED_NORMAL, false); // unpause this->EndGameHighScoreBaseWindow::Close(); } diff --git a/src/linkgraph/linkgraphschedule.cpp b/src/linkgraph/linkgraphschedule.cpp index 0a6b891502..3581c72ac9 100644 --- a/src/linkgraph/linkgraphschedule.cpp +++ b/src/linkgraph/linkgraphschedule.cpp @@ -174,7 +174,7 @@ void StateGameLoop_LinkGraphPauseControl() if (_pause_mode & PM_PAUSED_LINK_GRAPH) { /* We are paused waiting on a job, check the job every tick. */ if (!LinkGraphSchedule::instance.IsJoinWithUnfinishedJobDue()) { - Command::Post(0, PM_PAUSED_LINK_GRAPH, 0, {}); + Command::Post(PM_PAUSED_LINK_GRAPH, false); } } else if (_pause_mode == PM_UNPAUSED && _date_fract == LinkGraphSchedule::SPAWN_JOIN_TICK - 2 && @@ -182,7 +182,7 @@ void StateGameLoop_LinkGraphPauseControl() LinkGraphSchedule::instance.IsJoinWithUnfinishedJobDue()) { /* Perform check two _date_fract ticks before we would join, to make * sure it also works in multiplayer. */ - Command::Post(0, PM_PAUSED_LINK_GRAPH, 1, {}); + Command::Post(PM_PAUSED_LINK_GRAPH, true); } } diff --git a/src/livery.h b/src/livery.h index dc01c390a7..352cf6972e 100644 --- a/src/livery.h +++ b/src/livery.h @@ -17,7 +17,7 @@ static const byte LIT_COMPANY = 1; ///< Show the liveries of your own company static const byte LIT_ALL = 2; ///< Show the liveries of all companies /** List of different livery schemes. */ -enum LiveryScheme { +enum LiveryScheme : byte { LS_BEGIN = 0, LS_DEFAULT = 0, diff --git a/src/main_gui.cpp b/src/main_gui.cpp index 680493c12c..c25186164a 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -327,7 +327,7 @@ struct MainWindow : Window case GHK_MONEY: // Gimme money /* You can only cheat for money in singleplayer mode. */ - if (!_networking) Command::Post(0, 10000000, 0, {}); + if (!_networking) Command::Post(10000000); break; case GHK_UPDATE_COORDS: // Update the coordinates of all station signs diff --git a/src/misc/endian_buffer.hpp b/src/misc/endian_buffer.hpp index c20d9a8b99..87d527d9d8 100644 --- a/src/misc/endian_buffer.hpp +++ b/src/misc/endian_buffer.hpp @@ -14,6 +14,7 @@ #include #include "../core/span_type.hpp" #include "../core/bitmath_func.hpp" +#include "../core/overflowsafe_type.hpp" struct StrongTypedefBase; @@ -37,6 +38,9 @@ public: EndianBufferWriter &operator <<(std::string_view data) { this->Write(data); return *this; } EndianBufferWriter &operator <<(bool data) { return *this << static_cast(data ? 1 : 0); } + template + EndianBufferWriter &operator <<(const OverflowSafeInt &data) { return *this << static_cast(data); }; + template EndianBufferWriter &operator <<(const std::tuple &data) { @@ -127,6 +131,9 @@ public: EndianBufferReader &operator >>(std::string &data) { data = this->ReadStr(); return *this; } EndianBufferReader &operator >>(bool &data) { data = this->Read() != 0; return *this; } + template + EndianBufferReader &operator >>(OverflowSafeInt &data) { data = this->Read(); return *this; }; + template EndianBufferReader &operator >>(std::tuple &data) { diff --git a/src/misc_cmd.cpp b/src/misc_cmd.cpp index 84c61e3f18..fd8f79476e 100644 --- a/src/misc_cmd.cpp +++ b/src/misc_cmd.cpp @@ -28,22 +28,16 @@ #include "safeguards.h" -/* Make sure we can discard lower 2 bits of 64bit amount when passing it to Cmd[In|De]creaseLoan() */ -static_assert((LOAN_INTERVAL & 3) == 0); - /** * Increase the loan of your company. * @param flags operation to perform - * @param tile unused - * @param p1 higher half of amount to increase the loan with, multitude of LOAN_INTERVAL. Only used when (p2 & 3) == 2. - * @param p2 (bit 2-31) - lower half of amount (lower 2 bits assumed to be 0) - * (bit 0-1) - when 0: loans LOAN_INTERVAL - * when 1: loans the maximum loan permitting money (press CTRL), - * when 2: loans the amount specified in p1 and p2 - * @param text unused + * @param cmd when LoanCommand::Interval: loans LOAN_INTERVAL, + * when LoanCommand::Max: loans the maximum loan permitting money (press CTRL), + * when LoanCommand::Amount: loans the amount specified in \c amount + * @param amount amount to increase the loan with, multitude of LOAN_INTERVAL. Only used when cmd == LoanCommand::Amount. * @return the cost of this operation or an error */ -CommandCost CmdIncreaseLoan(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdIncreaseLoan(DoCommandFlag flags, LoanCommand cmd, Money amount) { Company *c = Company::Get(_current_company); @@ -53,16 +47,16 @@ CommandCost CmdIncreaseLoan(DoCommandFlag flags, TileIndex tile, uint32 p1, uint } Money loan; - switch (p2 & 3) { + switch (cmd) { default: return CMD_ERROR; // Invalid method - case 0: // Take some extra loan + case LoanCommand::Interval: // Take some extra loan loan = LOAN_INTERVAL; break; - case 1: // Take a loan as big as possible + case LoanCommand::Max: // Take a loan as big as possible loan = _economy.max_loan - c->current_loan; break; - case 2: // Take the given amount of loan - loan = ((uint64)p1 << 32) | (p2 & 0xFFFFFFFC); + case LoanCommand::Amount: // Take the given amount of loan + loan = amount; if (loan < LOAN_INTERVAL || c->current_loan + loan > _economy.max_loan || loan % LOAN_INTERVAL != 0) return CMD_ERROR; break; } @@ -82,33 +76,30 @@ CommandCost CmdIncreaseLoan(DoCommandFlag flags, TileIndex tile, uint32 p1, uint /** * Decrease the loan of your company. * @param flags operation to perform - * @param tile unused - * @param p1 higher half of amount to decrease the loan with, multitude of LOAN_INTERVAL. Only used when (p2 & 3) == 2. - * @param p2 (bit 2-31) - lower half of amount (lower 2 bits assumed to be 0) - * (bit 0-1) - when 0: pays back LOAN_INTERVAL - * when 1: pays back the maximum loan permitting money (press CTRL), - * when 2: pays back the amount specified in p1 and p2 - * @param text unused + * @param cmd when LoanCommand::Interval: pays back LOAN_INTERVAL, + * when LoanCommand::Max: pays back the maximum loan permitting money (press CTRL), + * when LoanCommand::Amount: pays back the amount specified in \c amount + * @param amount amount to decrease the loan with, multitude of LOAN_INTERVAL. Only used when cmd == LoanCommand::Amount. * @return the cost of this operation or an error */ -CommandCost CmdDecreaseLoan(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdDecreaseLoan(DoCommandFlag flags, LoanCommand cmd, Money amount) { Company *c = Company::Get(_current_company); if (c->current_loan == 0) return_cmd_error(STR_ERROR_LOAN_ALREADY_REPAYED); Money loan; - switch (p2 & 3) { + switch (cmd) { default: return CMD_ERROR; // Invalid method - case 0: // Pay back one step + case LoanCommand::Interval: // Pay back one step loan = std::min(c->current_loan, (Money)LOAN_INTERVAL); break; - case 1: // Pay back as much as possible + case LoanCommand::Max: // Pay back as much as possible loan = std::max(std::min(c->current_loan, c->money), (Money)LOAN_INTERVAL); loan -= loan % LOAN_INTERVAL; break; - case 2: // Repay the given amount of loan - loan = ((uint64)p1 << 32) | (p2 & 0xFFFFFFFC); + case LoanCommand::Amount: // Repay the given amount of loan + loan = amount; if (loan % LOAN_INTERVAL != 0 || loan < LOAN_INTERVAL || loan > c->current_loan) return CMD_ERROR; // Invalid amount to loan break; } @@ -135,7 +126,7 @@ CommandCost CmdDecreaseLoan(DoCommandFlag flags, TileIndex tile, uint32 p1, uint static void AskUnsafeUnpauseCallback(Window *w, bool confirmed) { if (confirmed) { - Command::Post(0, PM_PAUSED_ERROR, 0, {}); + Command::Post(PM_PAUSED_ERROR, false); } } @@ -145,15 +136,13 @@ static void AskUnsafeUnpauseCallback(Window *w, bool confirmed) * unpaused. A bitset is used instead of a boolean value/counter to have * more control over the game when saving/loading, etc. * @param flags operation to perform - * @param tile unused - * @param p1 the pause mode to change - * @param p2 1 pauses, 0 unpauses this mode - * @param text unused + * @param mode the pause mode to change + * @param pause true pauses, false unpauses this mode * @return the cost of this operation or an error */ -CommandCost CmdPause(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdPause(DoCommandFlag flags, PauseMode mode, bool pause) { - switch (p1) { + switch (mode) { case PM_PAUSED_SAVELOAD: case PM_PAUSED_ERROR: case PM_PAUSED_NORMAL: @@ -169,7 +158,7 @@ CommandCost CmdPause(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, default: return CMD_ERROR; } if (flags & DC_EXEC) { - if (p1 == PM_PAUSED_NORMAL && _pause_mode & PM_PAUSED_ERROR) { + if (mode == PM_PAUSED_NORMAL && _pause_mode & PM_PAUSED_ERROR) { ShowQuery( STR_NEWGRF_UNPAUSE_WARNING_TITLE, STR_NEWGRF_UNPAUSE_WARNING, @@ -179,13 +168,13 @@ CommandCost CmdPause(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, } else { PauseMode prev_mode = _pause_mode; - if (p2 == 0) { - _pause_mode = static_cast(_pause_mode & (byte)~p1); + if (pause) { + _pause_mode |= mode; } else { - _pause_mode = static_cast(_pause_mode | (byte)p1); + _pause_mode &= ~mode; } - NetworkHandlePauseChange(prev_mode, (PauseMode)p1); + NetworkHandlePauseChange(prev_mode, mode); } SetWindowDirty(WC_STATUS_BAR, 0); @@ -197,33 +186,25 @@ CommandCost CmdPause(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, /** * Change the financial flow of your company. * @param flags operation to perform - * @param tile unused - * @param p1 the amount of money to receive (if positive), or spend (if negative) - * @param p2 unused - * @param text unused + * @param amount the amount of money to receive (if positive), or spend (if negative) * @return the cost of this operation or an error */ -CommandCost CmdMoneyCheat(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdMoneyCheat(DoCommandFlag flags, Money amount) { - return CommandCost(EXPENSES_OTHER, -(int32)p1); + return CommandCost(EXPENSES_OTHER, -amount); } /** * Change the bank bank balance of a company by inserting or removing money without affecting the loan. * @param flags operation to perform * @param tile tile to show text effect on (if not 0) - * @param p1 the amount of money to receive (if positive), or spend (if negative) - * @param p2 (bit 0-7) - the company ID. - * (bit 8-15) - the expenses type which should register the cost/income @see ExpensesType. - * @param text unused + * @param delta the amount of money to receive (if positive), or spend (if negative) + * @param company the company ID. + * @param expenses_type the expenses type which should register the cost/income @see ExpensesType. * @return zero cost or an error */ -CommandCost CmdChangeBankBalance(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdChangeBankBalance(DoCommandFlag flags, TileIndex tile, Money delta, CompanyID company, ExpensesType expenses_type) { - int32 delta = (int32)p1; - CompanyID company = (CompanyID) GB(p2, 0, 8); - ExpensesType expenses_type = Extract(p2); - if (!Company::IsValidID(company)) return CMD_ERROR; if (expenses_type >= EXPENSES_END) return CMD_ERROR; if (_current_company != OWNER_DEITY) return CMD_ERROR; diff --git a/src/misc_cmd.h b/src/misc_cmd.h index 6827db3ac2..77250b551c 100644 --- a/src/misc_cmd.h +++ b/src/misc_cmd.h @@ -11,12 +11,21 @@ #define MISC_CMD_H #include "command_type.h" +#include "economy_type.h" -CommandProc CmdMoneyCheat; -CommandProc CmdChangeBankBalance; -CommandProc CmdIncreaseLoan; -CommandProc CmdDecreaseLoan; -CommandProc CmdPause; +enum PauseMode : byte; + +enum class LoanCommand : byte { + Interval, + Max, + Amount, +}; + +CommandCost CmdMoneyCheat(DoCommandFlag flags, Money amount); +CommandCost CmdChangeBankBalance(DoCommandFlag flags, TileIndex tile, Money delta, CompanyID company, ExpensesType expenses_type); +CommandCost CmdIncreaseLoan(DoCommandFlag flags, LoanCommand cmd, Money amount); +CommandCost CmdDecreaseLoan(DoCommandFlag flags, LoanCommand cmd, Money amount); +CommandCost CmdPause(DoCommandFlag flags, PauseMode mode, bool pause); DEF_CMD_TRAIT(CMD_MONEY_CHEAT, CmdMoneyCheat, CMD_OFFLINE, CMDT_CHEAT) DEF_CMD_TRAIT(CMD_CHANGE_BANK_BALANCE, CmdChangeBankBalance, CMD_DEITY, CMDT_MONEY_MANAGEMENT) diff --git a/src/network/network.cpp b/src/network/network.cpp index 3bd287f85a..19cb6ab3a4 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -395,7 +395,7 @@ static void CheckPauseHelper(bool pause, PauseMode pm) { if (pause == ((_pause_mode & pm) != PM_UNPAUSED)) return; - Command::Post(0, pm, pause ? 1 : 0, {}); + Command::Post(pm, pause); } /** @@ -1128,7 +1128,7 @@ void NetworkGameLoop() cp = new CommandPacket(); cp->company = COMPANY_SPECTATOR; cp->cmd = CMD_PAUSE; - cp->data = EndianBufferWriter<>::FromValue(CommandTraits::Args{ 0, PM_PAUSED_NORMAL, 1, "" }); + cp->data = EndianBufferWriter<>::FromValue(CommandTraits::Args{ PM_PAUSED_NORMAL, true }); _ddc_fastforward = false; } else if (strncmp(p, "sync: ", 6) == 0) { int ret = sscanf(p + 6, "%x; %x; %x; %x", &next_date, &next_date_fract, &sync_state[0], &sync_state[1]); diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index 197d398bf6..36ab3840a4 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -2081,7 +2081,7 @@ void NetworkServerNewCompany(const Company *c, NetworkClientInfo *ci) /* ci is nullptr when replaying, or for AIs. In neither case there is a client. */ ci->client_playas = c->index; NetworkUpdateClientInfo(ci->client_id); - Command::SendNet(STR_NULL, nullptr, c->index, 0, 0, 0, ci->client_name); + Command::SendNet(STR_NULL, nullptr, c->index, ci->client_name); } /* Announce new company on network. */ diff --git a/src/news_cmd.h b/src/news_cmd.h index 4a75037b3b..6ebb1b84d9 100644 --- a/src/news_cmd.h +++ b/src/news_cmd.h @@ -11,8 +11,10 @@ #define NEWS_CMD_H #include "command_type.h" +#include "company_type.h" +#include "news_type.h" -CommandProc CmdCustomNewsItem; +CommandCost CmdCustomNewsItem(DoCommandFlag flags, NewsType type, NewsReferenceType reftype1, CompanyID company, uint32 reference, const std::string &text); DEF_CMD_TRAIT(CMD_CUSTOM_NEWS_ITEM, CmdCustomNewsItem, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT) diff --git a/src/news_gui.cpp b/src/news_gui.cpp index 69ab19b3b4..ee0e17fac0 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -837,23 +837,17 @@ void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceTy /** * Create a new custom news item. * @param flags type of operation - * @param tile unused - * @param p1 various bitstuffed elements - * - p1 = (bit 0 - 7) - NewsType of the message. - * - p1 = (bit 8 - 15) - NewsReferenceType of first reference. - * - p1 = (bit 16 - 23) - Company this news message is for. - * @param p2 First reference of the news message. + * @aram type NewsType of the message. + * @param reftype1 NewsReferenceType of first reference. + * @param company Company this news message is for. + * @param reference First reference of the news message. * @param text The text of the news message. * @return the cost of this operation or an error */ -CommandCost CmdCustomNewsItem(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdCustomNewsItem(DoCommandFlag flags, NewsType type, NewsReferenceType reftype1, CompanyID company, uint32 reference, const std::string &text) { if (_current_company != OWNER_DEITY) return CMD_ERROR; - NewsType type = (NewsType)GB(p1, 0, 8); - NewsReferenceType reftype1 = (NewsReferenceType)GB(p1, 8, 8); - CompanyID company = (CompanyID)GB(p1, 16, 8); - if (company != INVALID_OWNER && !Company::IsValidID(company)) return CMD_ERROR; if (type >= NT_END) return CMD_ERROR; if (text.empty()) return CMD_ERROR; @@ -861,27 +855,27 @@ CommandCost CmdCustomNewsItem(DoCommandFlag flags, TileIndex tile, uint32 p1, ui switch (reftype1) { case NR_NONE: break; case NR_TILE: - if (!IsValidTile(p2)) return CMD_ERROR; + if (!IsValidTile(reference)) return CMD_ERROR; break; case NR_VEHICLE: - if (!Vehicle::IsValidID(p2)) return CMD_ERROR; + if (!Vehicle::IsValidID(reference)) return CMD_ERROR; break; case NR_STATION: - if (!Station::IsValidID(p2)) return CMD_ERROR; + if (!Station::IsValidID(reference)) return CMD_ERROR; break; case NR_INDUSTRY: - if (!Industry::IsValidID(p2)) return CMD_ERROR; + if (!Industry::IsValidID(reference)) return CMD_ERROR; break; case NR_TOWN: - if (!Town::IsValidID(p2)) return CMD_ERROR; + if (!Town::IsValidID(reference)) return CMD_ERROR; break; case NR_ENGINE: - if (!Engine::IsValidID(p2)) return CMD_ERROR; + if (!Engine::IsValidID(reference)) return CMD_ERROR; break; default: return CMD_ERROR; @@ -892,7 +886,7 @@ CommandCost CmdCustomNewsItem(DoCommandFlag flags, TileIndex tile, uint32 p1, ui if (flags & DC_EXEC) { NewsStringData *news = new NewsStringData(text); SetDParamStr(0, news->string); - AddNewsItem(STR_NEWS_CUSTOM_ITEM, type, NF_NORMAL, reftype1, p2, NR_NONE, UINT32_MAX, news); + AddNewsItem(STR_NEWS_CUSTOM_ITEM, type, NF_NORMAL, reftype1, reference, NR_NONE, UINT32_MAX, news); } return CommandCost(); diff --git a/src/news_type.h b/src/news_type.h index 188305b52f..7d9f6b7720 100644 --- a/src/news_type.h +++ b/src/news_type.h @@ -18,7 +18,7 @@ /** * Type of news. */ -enum NewsType { +enum NewsType : byte { NT_ARRIVAL_COMPANY, ///< First vehicle arrived for company NT_ARRIVAL_OTHER, ///< First vehicle arrived for competitor NT_ACCIDENT, ///< An accident or disaster has occurred @@ -47,7 +47,7 @@ enum NewsType { * You have to make sure, #ChangeVehicleNews catches the DParams of your message. * This is NOT ensured by the references. */ -enum NewsReferenceType { +enum NewsReferenceType : byte { NR_NONE, ///< Empty reference NR_TILE, ///< Reference tile. Scroll to tile when clicking on the news. NR_VEHICLE, ///< Reference vehicle. Scroll to vehicle when clicking on the news. Delete news when vehicle is deleted. diff --git a/src/openttd.cpp b/src/openttd.cpp index c5c849e71c..230529a786 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -852,7 +852,7 @@ static void MakeNewGameDone() /* In a dedicated server, the server does not play */ if (!VideoDriver::GetInstance()->HasGUI()) { OnStartGame(true); - if (_settings_client.gui.pause_on_newgame) Command::Post(0, PM_PAUSED_NORMAL, 1, {}); + if (_settings_client.gui.pause_on_newgame) Command::Post(PM_PAUSED_NORMAL, true); return; } @@ -881,7 +881,7 @@ static void MakeNewGameDone() NetworkChangeCompanyPassword(_local_company, _settings_client.network.default_company_pass); } - if (_settings_client.gui.pause_on_newgame) Command::Post(0, PM_PAUSED_NORMAL, 1, {}); + if (_settings_client.gui.pause_on_newgame) Command::Post(PM_PAUSED_NORMAL, true); CheckEngines(); CheckIndustries(); @@ -1046,7 +1046,7 @@ void SwitchToMode(SwitchMode new_mode) } OnStartGame(_network_dedicated); /* Decrease pause counter (was increased from opening load dialog) */ - Command::Post(0, PM_PAUSED_SAVELOAD, 0, {}); + Command::Post(PM_PAUSED_SAVELOAD, false); } break; } @@ -1068,7 +1068,7 @@ void SwitchToMode(SwitchMode new_mode) SetLocalCompany(OWNER_NONE); _settings_newgame.game_creation.starting_year = _cur_year; /* Cancel the saveload pausing */ - Command::Post(0, PM_PAUSED_SAVELOAD, 0, {}); + Command::Post(PM_PAUSED_SAVELOAD, false); } else { SetDParamStr(0, GetSaveLoadErrorString()); ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR); diff --git a/src/script/api/script_company.cpp b/src/script/api/script_company.cpp index 1cc69bc93f..6a06852da5 100644 --- a/src/script/api/script_company.cpp +++ b/src/script/api/script_company.cpp @@ -52,7 +52,7 @@ EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_COMPANY_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); - return ScriptObject::Command::Do(0, 0, 0, text); + return ScriptObject::Command::Do(text); } /* static */ char *ScriptCompany::GetName(ScriptCompany::CompanyID company) @@ -73,7 +73,7 @@ EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_PRESIDENT_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); - return ScriptObject::Command::Do(0, 0, 0, text); + return ScriptObject::Command::Do(text); } /* static */ char *ScriptCompany::GetPresidentName(ScriptCompany::CompanyID company) @@ -101,7 +101,7 @@ GenderEthnicity ge = (GenderEthnicity)((gender == GENDER_FEMALE ? (1 << ::GENDER_FEMALE) : 0) | (::InteractiveRandom() & (1 << ETHNICITY_BLACK))); RandomCompanyManagerFaceBits(cmf, ge, false); - return ScriptObject::Command::Do(0, 0, cmf, {}); + return ScriptObject::Command::Do(cmf); } /* static */ ScriptCompany::Gender ScriptCompany::GetPresidentGender(CompanyID company) @@ -211,9 +211,9 @@ Money amount = abs(loan - GetLoanAmount()); if (loan > GetLoanAmount()) { - return ScriptObject::Command::Do(0, amount >> 32, (amount & 0xFFFFFFFC) | 2, {}); + return ScriptObject::Command::Do(LoanCommand::Amount, amount); } else { - return ScriptObject::Command::Do(0, amount >> 32, (amount & 0xFFFFFFFC) | 2, {}); + return ScriptObject::Command::Do(LoanCommand::Amount, amount); } } @@ -244,7 +244,7 @@ EnforcePrecondition(false, company != COMPANY_INVALID); /* Network commands only allow 0 to indicate invalid tiles, not INVALID_TILE */ - return ScriptObject::Command::Do(tile == INVALID_TILE ? (TileIndex)0U : tile, (uint32)(delta), company | expenses_type << 8, {}); + return ScriptObject::Command::Do(tile == INVALID_TILE ? (TileIndex)0U : tile, delta, (::CompanyID)company, (::ExpensesType)expenses_type); } /* static */ bool ScriptCompany::BuildCompanyHQ(TileIndex tile) @@ -266,7 +266,7 @@ /* static */ bool ScriptCompany::SetAutoRenewStatus(bool autorenew) { - return ScriptObject::Command::Do(0, 0, autorenew ? 1 : 0, "company.engine_renew"); + return ScriptObject::Command::Do("company.engine_renew", autorenew ? 1 : 0); } /* static */ bool ScriptCompany::GetAutoRenewStatus(CompanyID company) @@ -279,7 +279,7 @@ /* static */ bool ScriptCompany::SetAutoRenewMonths(int16 months) { - return ScriptObject::Command::Do(0, 0, months, "company.engine_renew_months"); + return ScriptObject::Command::Do("company.engine_renew_months", months); } /* static */ int16 ScriptCompany::GetAutoRenewMonths(CompanyID company) @@ -294,7 +294,7 @@ { EnforcePrecondition(false, money >= 0); EnforcePrecondition(false, (int64)money <= UINT32_MAX); - return ScriptObject::Command::Do(0, 0, money, "company.engine_renew_money"); + return ScriptObject::Command::Do("company.engine_renew_money", money); } /* static */ Money ScriptCompany::GetAutoRenewMoney(CompanyID company) @@ -307,12 +307,12 @@ /* static */ bool ScriptCompany::SetPrimaryLiveryColour(LiveryScheme scheme, Colours colour) { - return ScriptObject::Command::Do(0, scheme, colour, {}); + return ScriptObject::Command::Do((::LiveryScheme)scheme, true, (::Colours)colour); } /* static */ bool ScriptCompany::SetSecondaryLiveryColour(LiveryScheme scheme, Colours colour) { - return ScriptObject::Command::Do(0, scheme | 1 << 8, colour, {}); + return ScriptObject::Command::Do((::LiveryScheme)scheme, false, (::Colours)colour); } /* static */ ScriptCompany::Colours ScriptCompany::GetPrimaryLiveryColour(ScriptCompany::LiveryScheme scheme) diff --git a/src/script/api/script_controller.cpp b/src/script/api/script_controller.cpp index 74a3ad3ea8..232ce5a3b6 100644 --- a/src/script/api/script_controller.cpp +++ b/src/script/api/script_controller.cpp @@ -60,7 +60,7 @@ ShowAIDebugWindow(ScriptObject::GetRootCompany()); if ((_pause_mode & PM_PAUSED_NORMAL) == PM_UNPAUSED) { - ScriptObject::Command::Do(0, PM_PAUSED_NORMAL, 1, {}); + ScriptObject::Command::Do(PM_PAUSED_NORMAL, true); } } diff --git a/src/script/api/script_event_types.cpp b/src/script/api/script_event_types.cpp index e876febc28..e9349a035f 100644 --- a/src/script/api/script_event_types.cpp +++ b/src/script/api/script_event_types.cpp @@ -117,7 +117,7 @@ bool ScriptEventEnginePreview::AcceptPreview() bool ScriptEventCompanyAskMerger::AcceptMerger() { - return ScriptObject::Command::Do(0, this->owner, 0, {}); + return ScriptObject::Command::Do((::CompanyID)this->owner); } ScriptEventAdminPort::ScriptEventAdminPort(const std::string &json) : diff --git a/src/script/api/script_game.cpp b/src/script/api/script_game.cpp index 9b40a1cd3b..3df6aef154 100644 --- a/src/script/api/script_game.cpp +++ b/src/script/api/script_game.cpp @@ -18,12 +18,12 @@ /* static */ bool ScriptGame::Pause() { - return ScriptObject::Command::Do(0, PM_PAUSED_GAME_SCRIPT, 1, {}); + return ScriptObject::Command::Do(PM_PAUSED_GAME_SCRIPT, true); } /* static */ bool ScriptGame::Unpause() { - return ScriptObject::Command::Do(0, PM_PAUSED_GAME_SCRIPT, 0, {}); + return ScriptObject::Command::Do(PM_PAUSED_GAME_SCRIPT, false); } /* static */ bool ScriptGame::IsPaused() diff --git a/src/script/api/script_gamesettings.cpp b/src/script/api/script_gamesettings.cpp index 611b78b8b6..2791aba006 100644 --- a/src/script/api/script_gamesettings.cpp +++ b/src/script/api/script_gamesettings.cpp @@ -38,7 +38,7 @@ if ((sd->flags & SF_NO_NETWORK_SYNC) != 0) return false; - return ScriptObject::Command::Do(0, 0, value, sd->GetName()); + return ScriptObject::Command::Do(sd->GetName(), value); } /* static */ bool ScriptGameSettings::IsDisabledVehicleType(ScriptVehicle::VehicleType vehicle_type) diff --git a/src/script/api/script_group.cpp b/src/script/api/script_group.cpp index 5047dc5c0e..dbf4c0280e 100644 --- a/src/script/api/script_group.cpp +++ b/src/script/api/script_group.cpp @@ -130,7 +130,7 @@ { if (HasWagonRemoval() == enable_removal) return true; - return ScriptObject::Command::Do(0, 0, enable_removal ? 1 : 0, "company.renew_keep_length"); + return ScriptObject::Command::Do("company.renew_keep_length", enable_removal ? 1 : 0); } /* static */ bool ScriptGroup::HasWagonRemoval() diff --git a/src/script/api/script_news.cpp b/src/script/api/script_news.cpp index 7f46f5aa6c..119cbc735c 100644 --- a/src/script/api/script_news.cpp +++ b/src/script/api/script_news.cpp @@ -39,5 +39,5 @@ if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY; if (ref_type == NR_NONE) reference = 0; - return ScriptObject::Command::Do(0, type | (ref_type << 8) | (c << 16), reference, encoded); + return ScriptObject::Command::Do((::NewsType)type, (::NewsReferenceType)ref_type, (::CompanyID)c, reference, encoded); } diff --git a/src/script/api/script_subsidy.cpp b/src/script/api/script_subsidy.cpp index 32962d1581..5e1180d1bb 100644 --- a/src/script/api/script_subsidy.cpp +++ b/src/script/api/script_subsidy.cpp @@ -39,7 +39,7 @@ EnforcePrecondition(false, (from_type == SPT_INDUSTRY && ScriptIndustry::IsValidIndustry(from_id)) || (from_type == SPT_TOWN && ScriptTown::IsValidTown(from_id))); EnforcePrecondition(false, (to_type == SPT_INDUSTRY && ScriptIndustry::IsValidIndustry(to_id)) || (to_type == SPT_TOWN && ScriptTown::IsValidTown(to_id))); - return ScriptObject::Command::Do(0, from_type | (from_id << 8) | (cargo_type << 24), to_type | (to_id << 8), {}); + return ScriptObject::Command::Do(cargo_type, (::SourceType)from_type, from_id, (::SourceType)to_type, to_id); } /* static */ ScriptCompany::CompanyID ScriptSubsidy::GetAwardedTo(SubsidyID subsidy_id) diff --git a/src/settings.cpp b/src/settings.cpp index 3c0f92f39b..25eeb964a5 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1487,18 +1487,16 @@ const SettingDesc *GetSettingFromName(const std::string_view name) /** * Network-safe changing of settings (server-only). * @param flags operation to perform - * @param tile unused - * @param p1 unused - * @param p2 the new value for the setting + * @param name the name of the setting to change + * @param value the new value for the setting * The new value is properly clamped to its minimum/maximum when setting - * @param text the name of the setting to change * @return the cost of this operation or an error * @see _settings */ -CommandCost CmdChangeSetting(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdChangeSetting(DoCommandFlag flags, const std::string &name, int32 value) { - if (text.empty()) return CMD_ERROR; - const SettingDesc *sd = GetSettingFromName(text); + if (name.empty()) return CMD_ERROR; + const SettingDesc *sd = GetSettingFromName(name); if (sd == nullptr) return CMD_ERROR; if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) return CMD_ERROR; @@ -1507,7 +1505,7 @@ CommandCost CmdChangeSetting(DoCommandFlag flags, TileIndex tile, uint32 p1, uin if (!sd->IsEditable(true)) return CMD_ERROR; if (flags & DC_EXEC) { - sd->AsIntSetting()->ChangeValue(&GetGameSettings(), p2); + sd->AsIntSetting()->ChangeValue(&GetGameSettings(), value); } return CommandCost(); @@ -1516,23 +1514,21 @@ CommandCost CmdChangeSetting(DoCommandFlag flags, TileIndex tile, uint32 p1, uin /** * Change one of the per-company settings. * @param flags operation to perform - * @param tile unused - * @param p1 unused - * @param p2 the new value for the setting + * @param name the name of the company setting to change + * @param value the new value for the setting * The new value is properly clamped to its minimum/maximum when setting - * @param text the name of the company setting to change * @return the cost of this operation or an error */ -CommandCost CmdChangeCompanySetting(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdChangeCompanySetting(DoCommandFlag flags, const std::string &name, int32 value) { - if (text.empty()) return CMD_ERROR; - const SettingDesc *sd = GetCompanySettingFromName(text.c_str()); + if (name.empty()) return CMD_ERROR; + const SettingDesc *sd = GetCompanySettingFromName(name); if (sd == nullptr) return CMD_ERROR; if (!sd->IsIntSetting()) return CMD_ERROR; if (flags & DC_EXEC) { - sd->AsIntSetting()->ChangeValue(&Company::Get(_current_company)->settings, p2); + sd->AsIntSetting()->ChangeValue(&Company::Get(_current_company)->settings, value); } return CommandCost(); @@ -1550,7 +1546,7 @@ bool SetSettingValue(const IntSettingDesc *sd, int32 value, bool force_newgame) const IntSettingDesc *setting = sd->AsIntSetting(); if ((setting->flags & SF_PER_COMPANY) != 0) { if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) { - return Command::Post(0, 0, value, setting->GetName()); + return Command::Post(setting->GetName(), value); } setting->ChangeValue(&_settings_client.company, value); @@ -1576,7 +1572,7 @@ bool SetSettingValue(const IntSettingDesc *sd, int32 value, bool force_newgame) /* send non-company-based settings over the network */ if (!_networking || (_networking && _network_server)) { - return Command::Post(0, 0, value, setting->GetName()); + return Command::Post(setting->GetName(), value); } return false; } @@ -1604,7 +1600,7 @@ void SyncCompanySettings() const SettingDesc *sd = GetSettingDesc(desc); uint32 old_value = (uint32)sd->AsIntSetting()->Read(new_object); uint32 new_value = (uint32)sd->AsIntSetting()->Read(old_object); - if (old_value != new_value) Command::SendNet(STR_NULL, nullptr, _local_company, 0, 0, new_value, sd->GetName()); + if (old_value != new_value) Command::SendNet(STR_NULL, nullptr, _local_company, sd->GetName(), new_value); } } diff --git a/src/settings_cmd.h b/src/settings_cmd.h index 15b9c31a48..d41f229e1b 100644 --- a/src/settings_cmd.h +++ b/src/settings_cmd.h @@ -12,8 +12,8 @@ #include "command_type.h" -CommandProc CmdChangeSetting; -CommandProc CmdChangeCompanySetting; +CommandCost CmdChangeSetting(DoCommandFlag flags, const std::string &name, int32 value); +CommandCost CmdChangeCompanySetting(DoCommandFlag flags, const std::string &name, int32 value); DEF_CMD_TRAIT(CMD_CHANGE_SETTING, CmdChangeSetting, CMD_SERVER, CMDT_SERVER_SETTING) DEF_CMD_TRAIT(CMD_CHANGE_COMPANY_SETTING, CmdChangeCompanySetting, 0, CMDT_COMPANY_SETTING) diff --git a/src/subsidy.cpp b/src/subsidy.cpp index 992c7a6726..0c32dbcf12 100644 --- a/src/subsidy.cpp +++ b/src/subsidy.cpp @@ -232,27 +232,17 @@ void CreateSubsidy(CargoID cid, SourceType src_type, SourceID src, SourceType ds /** * Create a new subsidy. * @param flags type of operation - * @param tile unused. - * @param p1 various bitstuffed elements - * - p1 = (bit 0 - 7) - SourceType of source. - * - p1 = (bit 8 - 23) - SourceID of source. - * - p1 = (bit 24 - 31) - CargoID of subsidy. - * @param p2 various bitstuffed elements - * - p2 = (bit 0 - 7) - SourceType of destination. - * - p2 = (bit 8 - 23) - SourceID of destination. - * @param text unused. + * @param cid CargoID of subsidy. + * @param src_type SourceType of source. + * @param src SourceID of source. + * @param dst_type SourceType of destination. + * @param dst SourceID of destination. * @return the cost of this operation or an error */ -CommandCost CmdCreateSubsidy(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdCreateSubsidy(DoCommandFlag flags, CargoID cid, SourceType src_type, SourceID src, SourceType dst_type, SourceID dst) { if (!Subsidy::CanAllocateItem()) return CMD_ERROR; - CargoID cid = GB(p1, 24, 8); - SourceType src_type = (SourceType)GB(p1, 0, 8); - SourceID src = GB(p1, 8, 16); - SourceType dst_type = (SourceType)GB(p2, 0, 8); - SourceID dst = GB(p2, 8, 16); - if (_current_company != OWNER_DEITY) return CMD_ERROR; if (cid >= NUM_CARGO || !::CargoSpec::Get(cid)->IsValid()) return CMD_ERROR; diff --git a/src/subsidy_cmd.h b/src/subsidy_cmd.h index f68c9b3034..d018688dad 100644 --- a/src/subsidy_cmd.h +++ b/src/subsidy_cmd.h @@ -11,8 +11,9 @@ #define SUBSIDY_CMD_H #include "command_type.h" +#include "cargo_type.h" -CommandProc CmdCreateSubsidy; +CommandCost CmdCreateSubsidy(DoCommandFlag flags, CargoID cid, SourceType src_type, SourceID src, SourceType dst_type, SourceID dst); DEF_CMD_TRAIT(CMD_CREATE_SUBSIDY, CmdCreateSubsidy, CMD_DEITY, CMDT_OTHER_MANAGEMENT) diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index b2b25afa6c..13c52f2b4e 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -266,7 +266,7 @@ static CallBackFunction ToolbarPauseClick(Window *w) { if (_networking && !_network_server) return CBF_NONE; // only server can pause the game - if (Command::Post(0, PM_PAUSED_NORMAL, _pause_mode == PM_UNPAUSED, {})) { + if (Command::Post(PM_PAUSED_NORMAL, _pause_mode == PM_UNPAUSED)) { if (_settings_client.sound.confirm) SndPlayFx(SND_15_BEEP); } return CBF_NONE; diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 8bfc332f65..6bb8d0986a 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -88,7 +88,7 @@ void CheckTrainsLengths() if (!_networking && first) { first = false; - Command::Post(0, PM_PAUSED_ERROR, 1, {}); + Command::Post(PM_PAUSED_ERROR, true); } /* Break so we warn only once for each train. */ break; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index d5d39b6e8d..3bbca46f0e 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -311,7 +311,7 @@ void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRF SetDParamStr(0, grfconfig->GetName()); SetDParam(1, engine); ShowErrorMessage(part1, part2, WL_CRITICAL); - if (!_networking) Command::Do(DC_EXEC, 0, critical ? PM_PAUSED_ERROR : PM_PAUSED_NORMAL, 1, {}); + if (!_networking) Command::Do(DC_EXEC, critical ? PM_PAUSED_ERROR : PM_PAUSED_NORMAL, true); } /* debug output */