From 04708736d9eb403773d7384c43ca6a93e246f28f Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sat, 15 Feb 2025 09:36:20 +0000 Subject: [PATCH] Codechange: Use EnumBitSet for CommandFlags. (#13560) --- src/autoreplace_cmd.h | 4 ++-- src/command.cpp | 16 ++++++++-------- src/command_func.h | 14 +++++++------- src/command_type.h | 30 +++++++++++++++--------------- src/company_cmd.h | 14 +++++++------- src/depot_cmd.h | 2 +- src/economy_cmd.h | 2 +- src/engine_cmd.h | 8 ++++---- src/goal_cmd.h | 16 ++++++++-------- src/group_cmd.h | 16 ++++++++-------- src/industry_cmd.h | 10 +++++----- src/landscape_cmd.h | 4 ++-- src/league_cmd.h | 10 +++++----- src/misc_cmd.h | 12 ++++++------ src/network/network_command.cpp | 4 ++-- src/network/network_server.cpp | 6 +++--- src/news_cmd.h | 2 +- src/object_cmd.h | 4 ++-- src/order_cmd.h | 16 ++++++++-------- src/rail_cmd.h | 20 ++++++++++---------- src/road_cmd.h | 10 +++++----- src/roadveh_cmd.h | 2 +- src/script/api/script_object.hpp | 6 +++--- src/settings_cmd.h | 4 ++-- src/signs_cmd.h | 4 ++-- src/station_cmd.h | 16 ++++++++-------- src/story_cmd.h | 18 +++++++++--------- src/subsidy_cmd.h | 2 +- src/terraform_cmd.h | 4 ++-- src/timetable_cmd.h | 10 +++++----- src/town_cmd.h | 20 ++++++++++---------- src/train_cmd.h | 6 +++--- src/tree_cmd.h | 2 +- src/tunnelbridge_cmd.h | 4 ++-- src/vehicle_cmd.h | 22 +++++++++++----------- src/viewport_cmd.h | 2 +- src/water_cmd.h | 6 +++--- src/waypoint_cmd.h | 12 ++++++------ 38 files changed, 180 insertions(+), 180 deletions(-) diff --git a/src/autoreplace_cmd.h b/src/autoreplace_cmd.h index 71450a95eb..5f9af672d2 100644 --- a/src/autoreplace_cmd.h +++ b/src/autoreplace_cmd.h @@ -18,7 +18,7 @@ CommandCost CmdAutoreplaceVehicle(DoCommandFlags flags, VehicleID veh_id); CommandCost CmdSetAutoReplace(DoCommandFlags flags, GroupID id_g, EngineID old_engine_type, EngineID new_engine_type, bool when_old); -DEF_CMD_TRAIT(CMD_AUTOREPLACE_VEHICLE, CmdAutoreplaceVehicle, 0, CMDT_VEHICLE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_SET_AUTOREPLACE, CmdSetAutoReplace, 0, CMDT_VEHICLE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_AUTOREPLACE_VEHICLE, CmdAutoreplaceVehicle, {}, CMDT_VEHICLE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_SET_AUTOREPLACE, CmdSetAutoReplace, {}, CMDT_VEHICLE_MANAGEMENT) #endif /* AUTOREPLACE_CMD_H */ diff --git a/src/command.cpp b/src/command.cpp index a6a10e5a1b..7d53af14f8 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -71,7 +71,7 @@ int RecursiveCommandCounter::_counter = 0; * Define a command with the flags which belongs to it. * * This struct connects a command handler function with the flags created with - * the #CMD_AUTO, #CMD_OFFLINE and #CMD_SERVER values. + * the #CommandFlag::Auto, #CommandFlag::Offline and #CommandFlag::Server values. */ struct CommandInfo { const char *name; ///< A human readable name for the procedure @@ -211,7 +211,7 @@ std::tuple CommandHelperBase::InternalPostBefore(Commands cmd, * However, in case of incoming network commands, * map generation or the pause button we do want * to execute. */ - bool estimate_only = _shift_pressed && IsLocalCompany() && !_generating_world && !network_command && !(flags & CMD_NO_EST); + bool estimate_only = _shift_pressed && IsLocalCompany() && !_generating_world && !network_command && !flags.Test(CommandFlag::NoEst); /* We're only sending the command, so don't do * fancy things for 'success'. */ @@ -271,12 +271,12 @@ void CommandHelperBase::LogCommandExecution(Commands cmd, StringID err_message, bool CommandHelperBase::InternalExecutePrepTest(CommandFlags cmd_flags, TileIndex, Backup &cur_company) { /* Always execute server and spectator commands as spectator */ - bool exec_as_spectator = (cmd_flags & (CMD_SPECTATOR | CMD_SERVER)) != 0; + bool exec_as_spectator = cmd_flags.Any({CommandFlag::Spectator, CommandFlag::Server}); /* If the company isn't valid it may only do server command or start a new company! * The server will ditch any server commands a client sends to it, so effectively * this guards the server from executing functions for an invalid company. */ - if (_game_mode == GM_NORMAL && !exec_as_spectator && !Company::IsValidID(_current_company) && !(_current_company == OWNER_DEITY && (cmd_flags & CMD_DEITY) != 0)) { + if (_game_mode == GM_NORMAL && !exec_as_spectator && !Company::IsValidID(_current_company) && !(_current_company == OWNER_DEITY && cmd_flags.Test(CommandFlag::Deity))) { return false; } @@ -304,14 +304,14 @@ std::tuple CommandHelperBase::InternalExecuteValidateTestAndPr SetTownRatingTestMode(false); /* Make sure we're not messing things up here. */ - assert((cmd_flags & (CMD_SPECTATOR | CMD_SERVER)) != 0 ? _current_company == COMPANY_SPECTATOR : cur_company.Verify()); + assert(cmd_flags.Any({CommandFlag::Spectator, CommandFlag::Server}) ? _current_company == COMPANY_SPECTATOR : cur_company.Verify()); /* If the command fails, we're doing an estimate * or the player does not have enough money * (unless it's a command where the test and * execution phase might return different costs) * we bail out here. */ - bool test_and_exec_can_differ = (cmd_flags & CMD_NO_TEST) != 0; + bool test_and_exec_can_differ = cmd_flags.Test(CommandFlag::NoTest); if (res.Failed() || estimate_only || (!test_and_exec_can_differ && !CheckCompanyHasMoney(res))) { return { true, !_networking || _generating_world || network_command, false }; } @@ -350,7 +350,7 @@ CommandCost CommandHelperBase::InternalExecuteProcessResult(Commands cmd, Comman _current_company = _local_company; } else { /* Make sure nothing bad happened, like changing the current company. */ - assert((cmd_flags & (CMD_SPECTATOR | CMD_SERVER)) != 0 ? _current_company == COMPANY_SPECTATOR : cur_company.Verify()); + assert(cmd_flags.Any({CommandFlag::Spectator, CommandFlag::Server}) ? _current_company == COMPANY_SPECTATOR : cur_company.Verify()); cur_company.Restore(); } @@ -358,7 +358,7 @@ CommandCost CommandHelperBase::InternalExecuteProcessResult(Commands cmd, Comman * return of the command. Otherwise we can check whether the * test and execution have yielded the same result, * i.e. cost and error state are the same. */ - bool test_and_exec_can_differ = (cmd_flags & CMD_NO_TEST) != 0; + bool test_and_exec_can_differ = cmd_flags.Test(CommandFlag::NoTest); if (!test_and_exec_can_differ) { assert(res_test.GetCost() == res_exec.GetCost() && res_test.Failed() == res_exec.Failed()); // sanity check } else if (res_exec.Failed()) { diff --git a/src/command_func.h b/src/command_func.h index 1181459987..188a51bbca 100644 --- a/src/command_func.h +++ b/src/command_func.h @@ -48,9 +48,9 @@ constexpr CommandFlags GetCommandFlags() static constexpr inline DoCommandFlags CommandFlagsToDCFlags(CommandFlags cmd_flags) { DoCommandFlags flags = {}; - if (cmd_flags & CMD_NO_WATER) flags.Set(DoCommandFlag::NoWater); - if (cmd_flags & CMD_AUTO) flags.Set(DoCommandFlag::Auto); - if (cmd_flags & CMD_ALL_TILES) flags.Set(DoCommandFlag::AllTiles); + if (cmd_flags.Test(CommandFlag::NoWater)) flags.Set(DoCommandFlag::NoWater); + if (cmd_flags.Test(CommandFlag::Auto)) flags.Set(DoCommandFlag::Auto); + if (cmd_flags.Test(CommandFlag::AllTiles)) flags.Set(DoCommandFlag::AllTiles); return flags; } @@ -283,13 +283,13 @@ protected: static bool InternalPost(StringID err_message, Tcallback *callback, bool my_cmd, bool network_command, TileIndex tile, std::tuple args) { /* Do not even think about executing out-of-bounds tile-commands. */ - if (tile != 0 && (tile >= Map::Size() || (!IsValidTile(tile) && (GetCommandFlags() & CMD_ALL_TILES) == 0))) return false; + if (tile != 0 && (tile >= Map::Size() || (!IsValidTile(tile) && !GetCommandFlags().Test(CommandFlag::AllTiles)))) return false; auto [err, estimate_only, only_sending] = InternalPostBefore(Tcmd, GetCommandFlags(), tile, err_message, network_command); if (err) return false; /* Only set client IDs when the command does not come from the network. */ - if (!network_command && GetCommandFlags() & CMD_CLIENT_ID) SetClientIds(args, std::index_sequence_for{}); + if (!network_command && GetCommandFlags().Test(CommandFlag::ClientID)) SetClientIds(args, std::index_sequence_for{}); Tret res = Execute(err_message, reinterpret_cast(reinterpret_cast(callback)), my_cmd, estimate_only, network_command, tile, args); InternalPostResult(ExtractCommandCost(res), tile, estimate_only, only_sending, err_message, my_cmd); @@ -357,7 +357,7 @@ protected: /* Command flags are used internally */ constexpr CommandFlags cmd_flags = GetCommandFlags(); - if constexpr ((cmd_flags & CMD_CLIENT_ID) != 0) { + if constexpr (cmd_flags.Test(CommandFlag::ClientID)) { /* Make sure arguments are properly set to a ClientID also when processing external commands. */ assert(AllClientIdsSet(args, std::index_sequence_for{})); } @@ -473,6 +473,6 @@ struct CommandHelper : CommandHe #endif template -using Command = CommandHelper::ProcType, (GetCommandFlags() & CMD_LOCATION) == 0>; +using Command = CommandHelper::ProcType, !GetCommandFlags().Test(CommandFlag::Location)>; #endif /* COMMAND_FUNC_H */ diff --git a/src/command_type.h b/src/command_type.h index 37a82b538f..fd5a98e7f9 100644 --- a/src/command_type.h +++ b/src/command_type.h @@ -391,21 +391,21 @@ using DoCommandFlags = EnumBitSet; * * This enumeration defines flags for the _command_proc_table. */ -enum CommandFlags : uint16_t { - CMD_SERVER = 0x001, ///< the command can only be initiated by the server - CMD_SPECTATOR = 0x002, ///< the command may be initiated by a spectator - CMD_OFFLINE = 0x004, ///< the command cannot be executed in a multiplayer game; single-player only - CMD_AUTO = 0x008, ///< set the DoCommandFlag::Auto flag on this command - CMD_ALL_TILES = 0x010, ///< allow this command also on MP_VOID tiles - CMD_NO_TEST = 0x020, ///< the command's output may differ between test and execute due to town rating changes etc. - CMD_NO_WATER = 0x040, ///< set the DoCommandFlag::NoWater flag on this command - CMD_CLIENT_ID = 0x080, ///< set p2 with the ClientID of the sending client. - CMD_DEITY = 0x100, ///< the command may be executed by COMPANY_DEITY - CMD_STR_CTRL = 0x200, ///< the command's string may contain control strings - CMD_NO_EST = 0x400, ///< the command is never estimated. - CMD_LOCATION = 0x800, ///< the command has implicit location argument. +enum class CommandFlag : uint8_t { + Server, ///< the command can only be initiated by the server + Spectator, ///< the command may be initiated by a spectator + Offline, ///< the command cannot be executed in a multiplayer game; single-player only + Auto, ///< set the DoCommandFlag::Auto flag on this command + AllTiles, ///< allow this command also on MP_VOID tiles + NoTest, ///< the command's output may differ between test and execute due to town rating changes etc. + NoWater, ///< set the DoCommandFlag::NoWater flag on this command + ClientID, ///< set p2 with the ClientID of the sending client. + Deity, ///< the command may be executed by COMPANY_DEITY + StrCtrl, ///< the command's string may contain control strings + NoEst, ///< the command is never estimated. + Location, ///< the command has implicit location argument. }; -DECLARE_ENUM_AS_BIT_SET(CommandFlags) +using CommandFlags = EnumBitSet; /** Types of commands we have. */ enum CommandType : uint8_t { @@ -459,7 +459,7 @@ template struct CommandTraits; using RetCallbackProc = typename CommandFunctionTraitHelper::CbProcType; \ static constexpr Commands cmd = cmd_; \ static constexpr auto &proc = proc_; \ - static constexpr CommandFlags flags = (CommandFlags)(flags_); \ + static constexpr CommandFlags flags = flags_; \ static constexpr CommandType type = type_; \ static inline constexpr const char *name = #proc_; \ }; diff --git a/src/company_cmd.h b/src/company_cmd.h index e8d3934622..8359d5e07f 100644 --- a/src/company_cmd.h +++ b/src/company_cmd.h @@ -25,12 +25,12 @@ CommandCost CmdRenamePresident(DoCommandFlags flags, const std::string &text); CommandCost CmdSetCompanyManagerFace(DoCommandFlags flags, CompanyManagerFace cmf); CommandCost CmdSetCompanyColour(DoCommandFlags 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_COMPANY_ALLOW_LIST_CTRL, CmdCompanyAllowListCtrl, CMD_NO_EST, CMDT_SERVER_SETTING) -DEF_CMD_TRAIT(CMD_GIVE_MONEY, CmdGiveMoney, 0, CMDT_MONEY_MANAGEMENT) -DEF_CMD_TRAIT(CMD_RENAME_COMPANY, CmdRenameCompany, 0, CMDT_COMPANY_SETTING) -DEF_CMD_TRAIT(CMD_RENAME_PRESIDENT, CmdRenamePresident, 0, CMDT_COMPANY_SETTING) -DEF_CMD_TRAIT(CMD_SET_COMPANY_MANAGER_FACE, CmdSetCompanyManagerFace, 0, CMDT_COMPANY_SETTING) -DEF_CMD_TRAIT(CMD_SET_COMPANY_COLOUR, CmdSetCompanyColour, 0, CMDT_COMPANY_SETTING) +DEF_CMD_TRAIT(CMD_COMPANY_CTRL, CmdCompanyCtrl, CommandFlags({CommandFlag::Spectator, CommandFlag::ClientID, CommandFlag::NoEst}), CMDT_SERVER_SETTING) +DEF_CMD_TRAIT(CMD_COMPANY_ALLOW_LIST_CTRL, CmdCompanyAllowListCtrl, CommandFlag::NoEst, CMDT_SERVER_SETTING) +DEF_CMD_TRAIT(CMD_GIVE_MONEY, CmdGiveMoney, {}, CMDT_MONEY_MANAGEMENT) +DEF_CMD_TRAIT(CMD_RENAME_COMPANY, CmdRenameCompany, {}, CMDT_COMPANY_SETTING) +DEF_CMD_TRAIT(CMD_RENAME_PRESIDENT, CmdRenamePresident, {}, CMDT_COMPANY_SETTING) +DEF_CMD_TRAIT(CMD_SET_COMPANY_MANAGER_FACE, CmdSetCompanyManagerFace, {}, CMDT_COMPANY_SETTING) +DEF_CMD_TRAIT(CMD_SET_COMPANY_COLOUR, CmdSetCompanyColour, {}, CMDT_COMPANY_SETTING) #endif /* COMPANY_CMD_H */ diff --git a/src/depot_cmd.h b/src/depot_cmd.h index 78eb291b31..8e4a7098cd 100644 --- a/src/depot_cmd.h +++ b/src/depot_cmd.h @@ -15,7 +15,7 @@ CommandCost CmdRenameDepot(DoCommandFlags flags, DepotID depot_id, const std::string &text); -DEF_CMD_TRAIT(CMD_RENAME_DEPOT, CmdRenameDepot, 0, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_RENAME_DEPOT, CmdRenameDepot, {}, CMDT_OTHER_MANAGEMENT) void CcCloneVehicle(Commands cmd, const CommandCost &result, VehicleID veh_id); diff --git a/src/economy_cmd.h b/src/economy_cmd.h index f0086b0d95..15825aa7b8 100644 --- a/src/economy_cmd.h +++ b/src/economy_cmd.h @@ -15,6 +15,6 @@ CommandCost CmdBuyCompany(DoCommandFlags flags, CompanyID target_company, bool hostile_takeover); -DEF_CMD_TRAIT(CMD_BUY_COMPANY, CmdBuyCompany, 0, CMDT_MONEY_MANAGEMENT) +DEF_CMD_TRAIT(CMD_BUY_COMPANY, CmdBuyCompany, {}, CMDT_MONEY_MANAGEMENT) #endif /* ECONOMY_CMD_H */ diff --git a/src/engine_cmd.h b/src/engine_cmd.h index 7654070a38..0f99119145 100644 --- a/src/engine_cmd.h +++ b/src/engine_cmd.h @@ -17,9 +17,9 @@ CommandCost CmdEngineCtrl(DoCommandFlags flags, EngineID engine_id, CompanyID co CommandCost CmdRenameEngine(DoCommandFlags flags, EngineID engine_id, const std::string &text); CommandCost CmdSetVehicleVisibility(DoCommandFlags flags, EngineID engine_id, bool hide); -DEF_CMD_TRAIT(CMD_WANT_ENGINE_PREVIEW, CmdWantEnginePreview, 0, CMDT_VEHICLE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_ENGINE_CTRL, CmdEngineCtrl, CMD_DEITY, CMDT_VEHICLE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_RENAME_ENGINE, CmdRenameEngine, CMD_SERVER, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_SET_VEHICLE_VISIBILITY, CmdSetVehicleVisibility, 0, CMDT_COMPANY_SETTING) +DEF_CMD_TRAIT(CMD_WANT_ENGINE_PREVIEW, CmdWantEnginePreview, {}, CMDT_VEHICLE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_ENGINE_CTRL, CmdEngineCtrl, CommandFlag::Deity, CMDT_VEHICLE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_RENAME_ENGINE, CmdRenameEngine, CommandFlag::Server, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_SET_VEHICLE_VISIBILITY, CmdSetVehicleVisibility, {}, CMDT_COMPANY_SETTING) #endif /* ENGINE_CMD_H */ diff --git a/src/goal_cmd.h b/src/goal_cmd.h index 171019a5e4..41b61c80d5 100644 --- a/src/goal_cmd.h +++ b/src/goal_cmd.h @@ -22,13 +22,13 @@ CommandCost CmdSetGoalCompleted(DoCommandFlags flags, GoalID goal, bool complete CommandCost CmdGoalQuestion(DoCommandFlags flags, uint16_t uniqueid, uint32_t target, bool is_client, uint32_t button_mask, GoalQuestionType type, const std::string &text); CommandCost CmdGoalQuestionAnswer(DoCommandFlags flags, uint16_t uniqueid, uint8_t button); -DEF_CMD_TRAIT(CMD_CREATE_GOAL, CmdCreateGoal, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_REMOVE_GOAL, CmdRemoveGoal, CMD_DEITY, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_SET_GOAL_DESTINATION, CmdSetGoalDestination, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_SET_GOAL_TEXT, CmdSetGoalText, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_SET_GOAL_PROGRESS, CmdSetGoalProgress, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_SET_GOAL_COMPLETED, CmdSetGoalCompleted, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_GOAL_QUESTION, CmdGoalQuestion, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_GOAL_QUESTION_ANSWER, CmdGoalQuestionAnswer, CMD_DEITY, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_CREATE_GOAL, CmdCreateGoal, CommandFlags({CommandFlag::Deity, CommandFlag::StrCtrl}), CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_REMOVE_GOAL, CmdRemoveGoal, CommandFlag::Deity, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_SET_GOAL_DESTINATION, CmdSetGoalDestination, CommandFlags({CommandFlag::Deity, CommandFlag::StrCtrl}), CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_SET_GOAL_TEXT, CmdSetGoalText, CommandFlags({CommandFlag::Deity, CommandFlag::StrCtrl}), CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_SET_GOAL_PROGRESS, CmdSetGoalProgress, CommandFlags({CommandFlag::Deity, CommandFlag::StrCtrl}), CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_SET_GOAL_COMPLETED, CmdSetGoalCompleted, CommandFlags({CommandFlag::Deity, CommandFlag::StrCtrl}), CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_GOAL_QUESTION, CmdGoalQuestion, CommandFlags({CommandFlag::Deity, CommandFlag::StrCtrl}), CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_GOAL_QUESTION_ANSWER, CmdGoalQuestionAnswer, CommandFlag::Deity, CMDT_OTHER_MANAGEMENT) #endif /* GOAL_CMD_H */ diff --git a/src/group_cmd.h b/src/group_cmd.h index 2868d4b10f..abef37b542 100644 --- a/src/group_cmd.h +++ b/src/group_cmd.h @@ -34,14 +34,14 @@ CommandCost CmdRemoveAllVehiclesGroup(DoCommandFlags flags, GroupID group_id); CommandCost CmdSetGroupFlag(DoCommandFlags flags, GroupID group_id, GroupFlag flag, bool value, bool recursive); CommandCost CmdSetGroupLivery(DoCommandFlags flags, GroupID group_id, bool primary, Colours colour); -DEF_CMD_TRAIT(CMD_CREATE_GROUP, CmdCreateGroup, 0, CMDT_ROUTE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_DELETE_GROUP, CmdDeleteGroup, 0, CMDT_ROUTE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_ALTER_GROUP, CmdAlterGroup, 0, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_ADD_VEHICLE_GROUP, CmdAddVehicleGroup, 0, CMDT_ROUTE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_ADD_SHARED_VEHICLE_GROUP, CmdAddSharedVehicleGroup, 0, CMDT_ROUTE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_REMOVE_ALL_VEHICLES_GROUP, CmdRemoveAllVehiclesGroup, 0, CMDT_ROUTE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_SET_GROUP_FLAG, CmdSetGroupFlag, 0, CMDT_ROUTE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_SET_GROUP_LIVERY, CmdSetGroupLivery, 0, CMDT_ROUTE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_CREATE_GROUP, CmdCreateGroup, {}, CMDT_ROUTE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_DELETE_GROUP, CmdDeleteGroup, {}, CMDT_ROUTE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_ALTER_GROUP, CmdAlterGroup, {}, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_ADD_VEHICLE_GROUP, CmdAddVehicleGroup, {}, CMDT_ROUTE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_ADD_SHARED_VEHICLE_GROUP, CmdAddSharedVehicleGroup, {}, CMDT_ROUTE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_REMOVE_ALL_VEHICLES_GROUP, CmdRemoveAllVehiclesGroup, {}, CMDT_ROUTE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_SET_GROUP_FLAG, CmdSetGroupFlag, {}, CMDT_ROUTE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_SET_GROUP_LIVERY, CmdSetGroupLivery, {}, CMDT_ROUTE_MANAGEMENT) void CcCreateGroup(Commands cmd, const CommandCost &result, GroupID new_group, VehicleType vt, GroupID parent_group); void CcAddVehicleNewGroup(Commands cmd, const CommandCost &result, GroupID new_group, GroupID, VehicleID veh_id, bool, const VehicleListIdentifier &); diff --git a/src/industry_cmd.h b/src/industry_cmd.h index 0eb077c3fb..37dc494e9e 100644 --- a/src/industry_cmd.h +++ b/src/industry_cmd.h @@ -21,11 +21,11 @@ CommandCost CmdIndustrySetExclusivity(DoCommandFlags flags, IndustryID ind_id, O CommandCost CmdIndustrySetText(DoCommandFlags flags, IndustryID ind_id, const std::string &text); CommandCost CmdIndustrySetProduction(DoCommandFlags flags, IndustryID ind_id, uint8_t prod_level, bool show_news, const std::string &text); -DEF_CMD_TRAIT(CMD_BUILD_INDUSTRY, CmdBuildIndustry, CMD_DEITY, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_INDUSTRY_SET_FLAGS, CmdIndustrySetFlags, CMD_DEITY, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_INDUSTRY_SET_EXCLUSIVITY, CmdIndustrySetExclusivity, CMD_DEITY, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_INDUSTRY_SET_TEXT, CmdIndustrySetText, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_INDUSTRY_SET_PRODUCTION, CmdIndustrySetProduction, CMD_DEITY, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_BUILD_INDUSTRY, CmdBuildIndustry, CommandFlag::Deity, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_INDUSTRY_SET_FLAGS, CmdIndustrySetFlags, CommandFlag::Deity, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_INDUSTRY_SET_EXCLUSIVITY, CmdIndustrySetExclusivity, CommandFlag::Deity, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_INDUSTRY_SET_TEXT, CmdIndustrySetText, CommandFlags({CommandFlag::Deity, CommandFlag::StrCtrl}), CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_INDUSTRY_SET_PRODUCTION, CmdIndustrySetProduction, CommandFlag::Deity, CMDT_OTHER_MANAGEMENT) void CcBuildIndustry(Commands cmd, const CommandCost &result, TileIndex tile, IndustryType indtype, uint32_t, bool, uint32_t); diff --git a/src/landscape_cmd.h b/src/landscape_cmd.h index fb6a70f9c1..2062eac619 100644 --- a/src/landscape_cmd.h +++ b/src/landscape_cmd.h @@ -15,7 +15,7 @@ CommandCost CmdLandscapeClear(DoCommandFlags flags, TileIndex tile); std::tuple CmdClearArea(DoCommandFlags flags, TileIndex tile, TileIndex start_tile, bool diagonal); -DEF_CMD_TRAIT(CMD_LANDSCAPE_CLEAR, CmdLandscapeClear, CMD_DEITY, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_CLEAR_AREA, CmdClearArea, CMD_NO_TEST, CMDT_LANDSCAPE_CONSTRUCTION) // destroying multi-tile houses makes town rating differ between test and execution +DEF_CMD_TRAIT(CMD_LANDSCAPE_CLEAR, CmdLandscapeClear, CommandFlag::Deity, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_CLEAR_AREA, CmdClearArea, CommandFlag::NoTest, CMDT_LANDSCAPE_CONSTRUCTION) // destroying multi-tile houses makes town rating differ between test and execution #endif /* LANDSCAPE_CMD_H */ diff --git a/src/league_cmd.h b/src/league_cmd.h index 4ead9e37c9..600aafc3c8 100644 --- a/src/league_cmd.h +++ b/src/league_cmd.h @@ -20,10 +20,10 @@ CommandCost CmdUpdateLeagueTableElementData(DoCommandFlags flags, LeagueTableEle CommandCost CmdUpdateLeagueTableElementScore(DoCommandFlags flags, LeagueTableElementID element, int64_t rating, const std::string &score); CommandCost CmdRemoveLeagueTableElement(DoCommandFlags flags, LeagueTableElementID element); -DEF_CMD_TRAIT(CMD_CREATE_LEAGUE_TABLE, CmdCreateLeagueTable, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_CREATE_LEAGUE_TABLE_ELEMENT, CmdCreateLeagueTableElement, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_UPDATE_LEAGUE_TABLE_ELEMENT_DATA, CmdUpdateLeagueTableElementData, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_UPDATE_LEAGUE_TABLE_ELEMENT_SCORE, CmdUpdateLeagueTableElementScore, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_REMOVE_LEAGUE_TABLE_ELEMENT, CmdRemoveLeagueTableElement, CMD_DEITY, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_CREATE_LEAGUE_TABLE, CmdCreateLeagueTable, CommandFlags({CommandFlag::Deity, CommandFlag::StrCtrl}), CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_CREATE_LEAGUE_TABLE_ELEMENT, CmdCreateLeagueTableElement, CommandFlags({CommandFlag::Deity, CommandFlag::StrCtrl}), CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_UPDATE_LEAGUE_TABLE_ELEMENT_DATA, CmdUpdateLeagueTableElementData, CommandFlags({CommandFlag::Deity, CommandFlag::StrCtrl}), CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_UPDATE_LEAGUE_TABLE_ELEMENT_SCORE, CmdUpdateLeagueTableElementScore, CommandFlags({CommandFlag::Deity, CommandFlag::StrCtrl}), CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_REMOVE_LEAGUE_TABLE_ELEMENT, CmdRemoveLeagueTableElement, CommandFlag::Deity, CMDT_OTHER_MANAGEMENT) #endif /* LEAGUE_CMD_H */ diff --git a/src/misc_cmd.h b/src/misc_cmd.h index f9b9628753..3c9ab9535c 100644 --- a/src/misc_cmd.h +++ b/src/misc_cmd.h @@ -27,11 +27,11 @@ CommandCost CmdDecreaseLoan(DoCommandFlags flags, LoanCommand cmd, Money amount) CommandCost CmdSetCompanyMaxLoan(DoCommandFlags flags, CompanyID company, Money amount); CommandCost CmdPause(DoCommandFlags 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) -DEF_CMD_TRAIT(CMD_INCREASE_LOAN, CmdIncreaseLoan, 0, CMDT_MONEY_MANAGEMENT) -DEF_CMD_TRAIT(CMD_DECREASE_LOAN, CmdDecreaseLoan, 0, CMDT_MONEY_MANAGEMENT) -DEF_CMD_TRAIT(CMD_SET_COMPANY_MAX_LOAN, CmdSetCompanyMaxLoan, CMD_DEITY, CMDT_MONEY_MANAGEMENT) -DEF_CMD_TRAIT(CMD_PAUSE, CmdPause, CMD_SERVER | CMD_NO_EST, CMDT_SERVER_SETTING) +DEF_CMD_TRAIT(CMD_MONEY_CHEAT, CmdMoneyCheat, CommandFlag::Offline, CMDT_CHEAT) +DEF_CMD_TRAIT(CMD_CHANGE_BANK_BALANCE, CmdChangeBankBalance, CommandFlag::Deity, CMDT_MONEY_MANAGEMENT) +DEF_CMD_TRAIT(CMD_INCREASE_LOAN, CmdIncreaseLoan, {}, CMDT_MONEY_MANAGEMENT) +DEF_CMD_TRAIT(CMD_DECREASE_LOAN, CmdDecreaseLoan, {}, CMDT_MONEY_MANAGEMENT) +DEF_CMD_TRAIT(CMD_SET_COMPANY_MAX_LOAN, CmdSetCompanyMaxLoan, CommandFlag::Deity, CMDT_MONEY_MANAGEMENT) +DEF_CMD_TRAIT(CMD_PAUSE, CmdPause, CommandFlags({CommandFlag::Server, CommandFlag::NoEst}), CMDT_SERVER_SETTING) #endif /* MISC_CMD_H */ diff --git a/src/network/network_command.cpp b/src/network/network_command.cpp index 6e4752406b..20a709f7d7 100644 --- a/src/network/network_command.cpp +++ b/src/network/network_command.cpp @@ -365,7 +365,7 @@ const char *NetworkGameSocketHandler::ReceiveCommand(Packet &p, CommandPacket &c cp.company = (CompanyID)p.Recv_uint8(); cp.cmd = static_cast(p.Recv_uint16()); if (!IsValidCommand(cp.cmd)) return "invalid command"; - if (GetCommandFlags(cp.cmd) & CMD_OFFLINE) return "single-player only command"; + if (GetCommandFlags(cp.cmd).Test(CommandFlag::Offline)) return "single-player only command"; cp.err_msg = p.Recv_uint16(); cp.data = _cmd_dispatch[cp.cmd].Sanitize(p.Recv_buffer()); @@ -441,7 +441,7 @@ template static inline void SanitizeSingleStringHelper([[maybe_unused]] CommandFlags cmd_flags, T &data) { if constexpr (std::is_same_v) { - data = StrMakeValid(data, (!_network_server && HasFlag(cmd_flags, CMD_STR_CTRL)) ? SVS_ALLOW_CONTROL_CODE | SVS_REPLACE_WITH_QUESTION_MARK : SVS_REPLACE_WITH_QUESTION_MARK); + data = StrMakeValid(data, (!_network_server && cmd_flags.Test(CommandFlag::StrCtrl)) ? SVS_ALLOW_CONTROL_CODE | SVS_REPLACE_WITH_QUESTION_MARK : SVS_REPLACE_WITH_QUESTION_MARK); } } diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index e5a58ff80f..9cfecda341 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -1076,12 +1076,12 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(Packet } - if ((GetCommandFlags(cp.cmd) & CMD_SERVER) && ci->client_id != CLIENT_ID_SERVER) { + if (GetCommandFlags(cp.cmd).Test(CommandFlag::Server) && ci->client_id != CLIENT_ID_SERVER) { IConsolePrint(CC_WARNING, "Kicking client #{} (IP: {}) due to calling a server only command {}.", ci->client_id, this->GetClientIP(), cp.cmd); return this->SendError(NETWORK_ERROR_KICKED); } - if ((GetCommandFlags(cp.cmd) & CMD_SPECTATOR) == 0 && !Company::IsValidID(cp.company) && ci->client_id != CLIENT_ID_SERVER) { + if (!GetCommandFlags(cp.cmd).Test(CommandFlag::Spectator) && !Company::IsValidID(cp.company) && ci->client_id != CLIENT_ID_SERVER) { IConsolePrint(CC_WARNING, "Kicking client #{} (IP: {}) due to calling a non-spectator command {}.", ci->client_id, this->GetClientIP(), cp.cmd); return this->SendError(NETWORK_ERROR_KICKED); } @@ -1128,7 +1128,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(Packet if (!found) return NETWORK_RECV_STATUS_OKAY; } - if (GetCommandFlags(cp.cmd) & CMD_CLIENT_ID) NetworkReplaceCommandClientId(cp, this->client_id); + if (GetCommandFlags(cp.cmd).Test(CommandFlag::ClientID)) NetworkReplaceCommandClientId(cp, this->client_id); this->incoming_queue.push_back(cp); return NETWORK_RECV_STATUS_OKAY; diff --git a/src/news_cmd.h b/src/news_cmd.h index 0a90f3b02d..28a27eb026 100644 --- a/src/news_cmd.h +++ b/src/news_cmd.h @@ -16,6 +16,6 @@ CommandCost CmdCustomNewsItem(DoCommandFlags flags, NewsType type, NewsReferenceType reftype1, CompanyID company, uint32_t reference, const std::string &text); -DEF_CMD_TRAIT(CMD_CUSTOM_NEWS_ITEM, CmdCustomNewsItem, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_CUSTOM_NEWS_ITEM, CmdCustomNewsItem, CommandFlags({CommandFlag::StrCtrl, CommandFlag::Deity}), CMDT_OTHER_MANAGEMENT) #endif /* NEWS_CMD_H */ diff --git a/src/object_cmd.h b/src/object_cmd.h index 772b1c11a5..0fb18d7fa8 100644 --- a/src/object_cmd.h +++ b/src/object_cmd.h @@ -16,7 +16,7 @@ CommandCost CmdBuildObject(DoCommandFlags flags, TileIndex tile, ObjectType type, uint8_t view); CommandCost CmdBuildObjectArea(DoCommandFlags flags, TileIndex tile, TileIndex start_tile, ObjectType type, uint8_t view, bool diagonal); -DEF_CMD_TRAIT(CMD_BUILD_OBJECT, CmdBuildObject, CMD_DEITY | CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_BUILD_OBJECT_AREA, CmdBuildObjectArea, CMD_DEITY | CMD_NO_WATER | CMD_NO_TEST | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_BUILD_OBJECT, CmdBuildObject, CommandFlags({CommandFlag::Deity, CommandFlag::NoWater, CommandFlag::Auto}), CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_BUILD_OBJECT_AREA, CmdBuildObjectArea, CommandFlags({CommandFlag::Deity, CommandFlag::NoWater, CommandFlag::NoTest, CommandFlag::Auto}), CMDT_LANDSCAPE_CONSTRUCTION) #endif /* OBJECT_CMD_H */ diff --git a/src/order_cmd.h b/src/order_cmd.h index 7400ba665d..5d1e9039d4 100644 --- a/src/order_cmd.h +++ b/src/order_cmd.h @@ -23,14 +23,14 @@ CommandCost CmdCloneOrder(DoCommandFlags flags, CloneOptions action, VehicleID v CommandCost CmdMoveOrder(DoCommandFlags flags, VehicleID veh, VehicleOrderID moving_order, VehicleOrderID target_order); CommandCost CmdClearOrderBackup(DoCommandFlags flags, TileIndex tile, ClientID user_id); -DEF_CMD_TRAIT(CMD_MODIFY_ORDER, CmdModifyOrder, CMD_LOCATION, CMDT_ROUTE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_SKIP_TO_ORDER, CmdSkipToOrder, CMD_LOCATION, CMDT_ROUTE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_DELETE_ORDER, CmdDeleteOrder, CMD_LOCATION, CMDT_ROUTE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_INSERT_ORDER, CmdInsertOrder, CMD_LOCATION, CMDT_ROUTE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_ORDER_REFIT, CmdOrderRefit, CMD_LOCATION, CMDT_ROUTE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_CLONE_ORDER, CmdCloneOrder, CMD_LOCATION, CMDT_ROUTE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_MOVE_ORDER, CmdMoveOrder, CMD_LOCATION, CMDT_ROUTE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_CLEAR_ORDER_BACKUP, CmdClearOrderBackup, CMD_CLIENT_ID, CMDT_SERVER_SETTING) +DEF_CMD_TRAIT(CMD_MODIFY_ORDER, CmdModifyOrder, CommandFlag::Location, CMDT_ROUTE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_SKIP_TO_ORDER, CmdSkipToOrder, CommandFlag::Location, CMDT_ROUTE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_DELETE_ORDER, CmdDeleteOrder, CommandFlag::Location, CMDT_ROUTE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_INSERT_ORDER, CmdInsertOrder, CommandFlag::Location, CMDT_ROUTE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_ORDER_REFIT, CmdOrderRefit, CommandFlag::Location, CMDT_ROUTE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_CLONE_ORDER, CmdCloneOrder, CommandFlag::Location, CMDT_ROUTE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_MOVE_ORDER, CmdMoveOrder, CommandFlag::Location, CMDT_ROUTE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_CLEAR_ORDER_BACKUP, CmdClearOrderBackup, CommandFlag::ClientID, CMDT_SERVER_SETTING) template inline EndianBufferWriter &operator <<(EndianBufferWriter &buffer, const Order &order) diff --git a/src/rail_cmd.h b/src/rail_cmd.h index 6ef5e8f8b8..fc27e50b8a 100644 --- a/src/rail_cmd.h +++ b/src/rail_cmd.h @@ -26,16 +26,16 @@ CommandCost CmdConvertRail(DoCommandFlags flags, TileIndex tile, TileIndex area_ CommandCost CmdBuildSignalTrack(DoCommandFlags flags, TileIndex tile, TileIndex end_tile, Track track, SignalType sigtype, SignalVariant sigvar, bool mode, bool autofill, bool minimise_gaps, uint8_t signal_density); CommandCost CmdRemoveSignalTrack(DoCommandFlags flags, TileIndex tile, TileIndex end_tile, Track track, bool autofill); -DEF_CMD_TRAIT(CMD_BUILD_RAILROAD_TRACK, CmdBuildRailroadTrack, CMD_AUTO | CMD_NO_WATER, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_REMOVE_RAILROAD_TRACK, CmdRemoveRailroadTrack, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_BUILD_SINGLE_RAIL, CmdBuildSingleRail, CMD_AUTO | CMD_NO_WATER, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_REMOVE_SINGLE_RAIL, CmdRemoveSingleRail, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_BUILD_TRAIN_DEPOT, CmdBuildTrainDepot, CMD_AUTO | CMD_NO_WATER, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_BUILD_SINGLE_SIGNAL, CmdBuildSingleSignal, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_REMOVE_SINGLE_SIGNAL, CmdRemoveSingleSignal, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_CONVERT_RAIL, CmdConvertRail, 0, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_BUILD_SIGNAL_TRACK, CmdBuildSignalTrack, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_REMOVE_SIGNAL_TRACK, CmdRemoveSignalTrack, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_BUILD_RAILROAD_TRACK, CmdBuildRailroadTrack, CommandFlags({CommandFlag::Auto, CommandFlag::NoWater}), CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_REMOVE_RAILROAD_TRACK, CmdRemoveRailroadTrack, CommandFlag::Auto, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_BUILD_SINGLE_RAIL, CmdBuildSingleRail, CommandFlags({CommandFlag::Auto, CommandFlag::NoWater}), CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_REMOVE_SINGLE_RAIL, CmdRemoveSingleRail, CommandFlag::Auto, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_BUILD_TRAIN_DEPOT, CmdBuildTrainDepot, CommandFlags({CommandFlag::Auto, CommandFlag::NoWater}), CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_BUILD_SINGLE_SIGNAL, CmdBuildSingleSignal, CommandFlag::Auto, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_REMOVE_SINGLE_SIGNAL, CmdRemoveSingleSignal, CommandFlag::Auto, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_CONVERT_RAIL, CmdConvertRail, {}, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_BUILD_SIGNAL_TRACK, CmdBuildSignalTrack, CommandFlag::Auto, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_REMOVE_SIGNAL_TRACK, CmdRemoveSignalTrack, CommandFlag::Auto, CMDT_LANDSCAPE_CONSTRUCTION) CommandCallback CcPlaySound_CONSTRUCTION_RAIL; CommandCallback CcStation; diff --git a/src/road_cmd.h b/src/road_cmd.h index dfd3482492..ad53a3e111 100644 --- a/src/road_cmd.h +++ b/src/road_cmd.h @@ -25,11 +25,11 @@ CommandCost CmdBuildRoad(DoCommandFlags flags, TileIndex tile, RoadBits pieces, CommandCost CmdBuildRoadDepot(DoCommandFlags flags, TileIndex tile, RoadType rt, DiagDirection dir); CommandCost CmdConvertRoad(DoCommandFlags flags, TileIndex tile, TileIndex area_start, RoadType to_type); -DEF_CMD_TRAIT(CMD_BUILD_LONG_ROAD, CmdBuildLongRoad, CMD_AUTO | CMD_NO_WATER | CMD_DEITY, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_REMOVE_LONG_ROAD, CmdRemoveLongRoad, CMD_AUTO | CMD_NO_TEST, CMDT_LANDSCAPE_CONSTRUCTION) // towns may disallow removing road bits (as they are connected) in test, but in exec they're removed and thus removing is allowed. -DEF_CMD_TRAIT(CMD_BUILD_ROAD, CmdBuildRoad, CMD_AUTO | CMD_NO_WATER | CMD_DEITY, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_BUILD_ROAD_DEPOT, CmdBuildRoadDepot, CMD_AUTO | CMD_NO_WATER, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_CONVERT_ROAD, CmdConvertRoad, 0, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_BUILD_LONG_ROAD, CmdBuildLongRoad, CommandFlags({CommandFlag::Auto, CommandFlag::NoWater, CommandFlag::Deity}), CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_REMOVE_LONG_ROAD, CmdRemoveLongRoad, CommandFlags({CommandFlag::Auto, CommandFlag::NoTest}), CMDT_LANDSCAPE_CONSTRUCTION) // towns may disallow removing road bits (as they are connected) in test, but in exec they're removed and thus removing is allowed. +DEF_CMD_TRAIT(CMD_BUILD_ROAD, CmdBuildRoad, CommandFlags({CommandFlag::Auto, CommandFlag::NoWater, CommandFlag::Deity}), CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_BUILD_ROAD_DEPOT, CmdBuildRoadDepot, CommandFlags({CommandFlag::Auto, CommandFlag::NoWater}), CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_CONVERT_ROAD, CmdConvertRoad, {}, CMDT_LANDSCAPE_CONSTRUCTION) CommandCallback CcPlaySound_CONSTRUCTION_OTHER; CommandCallback CcBuildRoadTunnel; diff --git a/src/roadveh_cmd.h b/src/roadveh_cmd.h index 78e26d26f7..ed9a7a11c5 100644 --- a/src/roadveh_cmd.h +++ b/src/roadveh_cmd.h @@ -22,6 +22,6 @@ CommandCost CmdBuildRoadVehicle(DoCommandFlags flags, TileIndex tile, const Engi CommandCost CmdTurnRoadVeh(DoCommandFlags flags, VehicleID veh_id); -DEF_CMD_TRAIT(CMD_TURN_ROADVEH, CmdTurnRoadVeh, CMD_LOCATION, CMDT_VEHICLE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_TURN_ROADVEH, CmdTurnRoadVeh, CommandFlag::Location, CMDT_VEHICLE_MANAGEMENT) #endif /* ROADVEH_CMD_H */ diff --git a/src/script/api/script_object.hpp b/src/script/api/script_object.hpp index 3918fe92fe..3ca05ece2f 100644 --- a/src/script/api/script_object.hpp +++ b/src/script/api/script_object.hpp @@ -382,7 +382,7 @@ bool ScriptObject::ScriptDoCommandHelper() & CMD_STR_CTRL) == 0) { + if (!::GetCommandFlags().Test(CommandFlag::StrCtrl)) { ScriptObjectInternal::SanitizeStringsHelper(args, std::index_sequence_for{}); } @@ -392,10 +392,10 @@ bool ScriptObject::ScriptDoCommandHelper= Map::Size() || (!IsValidTile(tile) && (GetCommandFlags() & CMD_ALL_TILES) == 0))) return false; + if (tile != 0 && (tile >= Map::Size() || (!IsValidTile(tile) && !GetCommandFlags().Test(CommandFlag::AllTiles)))) return false; /* Only set ClientID parameters when the command does not come from the network. */ - if constexpr ((::GetCommandFlags() & CMD_CLIENT_ID) != 0) ScriptObjectInternal::SetClientIds(args, std::index_sequence_for{}); + if constexpr (::GetCommandFlags().Test(CommandFlag::ClientID)) ScriptObjectInternal::SetClientIds(args, std::index_sequence_for{}); /* Store the command for command callback validation. */ if (!estimate_only && networking) ScriptObject::SetLastCommand(EndianBufferWriter::FromValue(args), Tcmd); diff --git a/src/settings_cmd.h b/src/settings_cmd.h index c4294da2b4..613fcfb42a 100644 --- a/src/settings_cmd.h +++ b/src/settings_cmd.h @@ -15,7 +15,7 @@ CommandCost CmdChangeSetting(DoCommandFlags flags, const std::string &name, int32_t value); CommandCost CmdChangeCompanySetting(DoCommandFlags flags, const std::string &name, int32_t value); -DEF_CMD_TRAIT(CMD_CHANGE_SETTING, CmdChangeSetting, CMD_SERVER | CMD_NO_EST, CMDT_SERVER_SETTING) -DEF_CMD_TRAIT(CMD_CHANGE_COMPANY_SETTING, CmdChangeCompanySetting, CMD_NO_EST, CMDT_COMPANY_SETTING) +DEF_CMD_TRAIT(CMD_CHANGE_SETTING, CmdChangeSetting, CommandFlags({CommandFlag::Server, CommandFlag::NoEst}), CMDT_SERVER_SETTING) +DEF_CMD_TRAIT(CMD_CHANGE_COMPANY_SETTING, CmdChangeCompanySetting, CommandFlag::NoEst, CMDT_COMPANY_SETTING) #endif /* SETTINGS_CMD_H */ diff --git a/src/signs_cmd.h b/src/signs_cmd.h index 126210d83c..53b76091de 100644 --- a/src/signs_cmd.h +++ b/src/signs_cmd.h @@ -16,8 +16,8 @@ std::tuple CmdPlaceSign(DoCommandFlags flags, TileIndex tile, const std::string &text); CommandCost CmdRenameSign(DoCommandFlags flags, SignID sign_id, const std::string &text); -DEF_CMD_TRAIT(CMD_PLACE_SIGN, CmdPlaceSign, CMD_DEITY, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_RENAME_SIGN, CmdRenameSign, CMD_DEITY, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_PLACE_SIGN, CmdPlaceSign, CommandFlag::Deity, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_RENAME_SIGN, CmdRenameSign, CommandFlag::Deity, CMDT_OTHER_MANAGEMENT) void CcPlaceSign(Commands cmd, const CommandCost &result, SignID new_sign); diff --git a/src/station_cmd.h b/src/station_cmd.h index 32c2491671..e1310da686 100644 --- a/src/station_cmd.h +++ b/src/station_cmd.h @@ -28,13 +28,13 @@ CommandCost CmdRemoveRoadStop(DoCommandFlags flags, TileIndex tile, uint8_t widt CommandCost CmdRenameStation(DoCommandFlags flags, StationID station_id, const std::string &text); CommandCost CmdOpenCloseAirport(DoCommandFlags flags, StationID station_id); -DEF_CMD_TRAIT(CMD_BUILD_AIRPORT, CmdBuildAirport, CMD_AUTO | CMD_NO_WATER, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_BUILD_DOCK, CmdBuildDock, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_BUILD_RAIL_STATION, CmdBuildRailStation, CMD_AUTO | CMD_NO_WATER, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_REMOVE_FROM_RAIL_STATION, CmdRemoveFromRailStation, 0, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_BUILD_ROAD_STOP, CmdBuildRoadStop, CMD_AUTO | CMD_NO_WATER, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_REMOVE_ROAD_STOP, CmdRemoveRoadStop, 0, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_RENAME_STATION, CmdRenameStation, 0, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_OPEN_CLOSE_AIRPORT, CmdOpenCloseAirport, 0, CMDT_ROUTE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_BUILD_AIRPORT, CmdBuildAirport, CommandFlags({CommandFlag::Auto, CommandFlag::NoWater}), CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_BUILD_DOCK, CmdBuildDock, CommandFlag::Auto, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_BUILD_RAIL_STATION, CmdBuildRailStation, CommandFlags({CommandFlag::Auto, CommandFlag::NoWater}), CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_REMOVE_FROM_RAIL_STATION, CmdRemoveFromRailStation, {}, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_BUILD_ROAD_STOP, CmdBuildRoadStop, CommandFlags({CommandFlag::Auto, CommandFlag::NoWater}), CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_REMOVE_ROAD_STOP, CmdRemoveRoadStop, {}, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_RENAME_STATION, CmdRenameStation, {}, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_OPEN_CLOSE_AIRPORT, CmdOpenCloseAirport, {}, CMDT_ROUTE_MANAGEMENT) #endif /* STATION_CMD_H */ diff --git a/src/story_cmd.h b/src/story_cmd.h index 3ff418f02e..4f652385a3 100644 --- a/src/story_cmd.h +++ b/src/story_cmd.h @@ -25,14 +25,14 @@ CommandCost CmdRemoveStoryPage(DoCommandFlags flags, StoryPageID page_id); CommandCost CmdRemoveStoryPageElement(DoCommandFlags flags, StoryPageElementID page_element_id); CommandCost CmdStoryPageButton(DoCommandFlags flags, TileIndex tile, StoryPageElementID page_element_id, VehicleID reference); -DEF_CMD_TRAIT(CMD_CREATE_STORY_PAGE, CmdCreateStoryPage, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_CREATE_STORY_PAGE_ELEMENT, CmdCreateStoryPageElement, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_UPDATE_STORY_PAGE_ELEMENT, CmdUpdateStoryPageElement, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_SET_STORY_PAGE_TITLE, CmdSetStoryPageTitle, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_SET_STORY_PAGE_DATE, CmdSetStoryPageDate, CMD_DEITY, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_SHOW_STORY_PAGE, CmdShowStoryPage, CMD_DEITY, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_REMOVE_STORY_PAGE, CmdRemoveStoryPage, CMD_DEITY, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_REMOVE_STORY_PAGE_ELEMENT, CmdRemoveStoryPageElement, CMD_DEITY, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_STORY_PAGE_BUTTON, CmdStoryPageButton, CMD_DEITY, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_CREATE_STORY_PAGE, CmdCreateStoryPage, CommandFlags({CommandFlag::Deity, CommandFlag::StrCtrl}), CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_CREATE_STORY_PAGE_ELEMENT, CmdCreateStoryPageElement, CommandFlags({CommandFlag::Deity, CommandFlag::StrCtrl}), CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_UPDATE_STORY_PAGE_ELEMENT, CmdUpdateStoryPageElement, CommandFlags({CommandFlag::Deity, CommandFlag::StrCtrl}), CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_SET_STORY_PAGE_TITLE, CmdSetStoryPageTitle, CommandFlags({CommandFlag::Deity, CommandFlag::StrCtrl}), CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_SET_STORY_PAGE_DATE, CmdSetStoryPageDate, CommandFlag::Deity, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_SHOW_STORY_PAGE, CmdShowStoryPage, CommandFlag::Deity, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_REMOVE_STORY_PAGE, CmdRemoveStoryPage, CommandFlag::Deity, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_REMOVE_STORY_PAGE_ELEMENT, CmdRemoveStoryPageElement, CommandFlag::Deity, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_STORY_PAGE_BUTTON, CmdStoryPageButton, CommandFlag::Deity, CMDT_OTHER_MANAGEMENT) #endif /* STORY_CMD_H */ diff --git a/src/subsidy_cmd.h b/src/subsidy_cmd.h index 6bd7cad278..a090774490 100644 --- a/src/subsidy_cmd.h +++ b/src/subsidy_cmd.h @@ -17,7 +17,7 @@ CommandCost CmdCreateSubsidy(DoCommandFlags flags, CargoType cargo_type, Source src, Source dst); -DEF_CMD_TRAIT(CMD_CREATE_SUBSIDY, CmdCreateSubsidy, CMD_DEITY, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_CREATE_SUBSIDY, CmdCreateSubsidy, CommandFlag::Deity, CMDT_OTHER_MANAGEMENT) template diff --git a/src/terraform_cmd.h b/src/terraform_cmd.h index d12b711b4e..8d4dea20d5 100644 --- a/src/terraform_cmd.h +++ b/src/terraform_cmd.h @@ -17,8 +17,8 @@ std::tuple CmdTerraformLand(DoCommandFlags flags, TileIndex tile, Slope slope, bool dir_up); std::tuple CmdLevelLand(DoCommandFlags flags, TileIndex tile, TileIndex start_tile, bool diagonal, LevelMode lm); -DEF_CMD_TRAIT(CMD_TERRAFORM_LAND, CmdTerraformLand, CMD_ALL_TILES | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_LEVEL_LAND, CmdLevelLand, CMD_ALL_TILES | CMD_AUTO | CMD_NO_TEST, CMDT_LANDSCAPE_CONSTRUCTION) // test run might clear tiles multiple times, in execution that only happens once +DEF_CMD_TRAIT(CMD_TERRAFORM_LAND, CmdTerraformLand, CommandFlags({CommandFlag::AllTiles, CommandFlag::Auto}), CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_LEVEL_LAND, CmdLevelLand, CommandFlags({CommandFlag::AllTiles, CommandFlag::Auto, CommandFlag::NoTest}), CMDT_LANDSCAPE_CONSTRUCTION) // test run might clear tiles multiple times, in execution that only happens once CommandCallback CcPlaySound_EXPLOSION; void CcTerraform(Commands cmd, const CommandCost &result, Money, TileIndex tile); diff --git a/src/timetable_cmd.h b/src/timetable_cmd.h index 6ab2b4d6d6..eeda1ff4c1 100644 --- a/src/timetable_cmd.h +++ b/src/timetable_cmd.h @@ -19,10 +19,10 @@ CommandCost CmdSetVehicleOnTime(DoCommandFlags flags, VehicleID veh, bool apply_ CommandCost CmdAutofillTimetable(DoCommandFlags flags, VehicleID veh, bool autofill, bool preserve_wait_time); CommandCost CmdSetTimetableStart(DoCommandFlags flags, VehicleID veh_id, bool timetable_all, TimerGameTick::TickCounter start_tick); -DEF_CMD_TRAIT(CMD_CHANGE_TIMETABLE, CmdChangeTimetable, 0, CMDT_ROUTE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_BULK_CHANGE_TIMETABLE, CmdBulkChangeTimetable, 0, CMDT_ROUTE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_SET_VEHICLE_ON_TIME, CmdSetVehicleOnTime, 0, CMDT_ROUTE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_AUTOFILL_TIMETABLE, CmdAutofillTimetable, 0, CMDT_ROUTE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_SET_TIMETABLE_START, CmdSetTimetableStart, 0, CMDT_ROUTE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_CHANGE_TIMETABLE, CmdChangeTimetable, {}, CMDT_ROUTE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_BULK_CHANGE_TIMETABLE, CmdBulkChangeTimetable, {}, CMDT_ROUTE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_SET_VEHICLE_ON_TIME, CmdSetVehicleOnTime, {}, CMDT_ROUTE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_AUTOFILL_TIMETABLE, CmdAutofillTimetable, {}, CMDT_ROUTE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_SET_TIMETABLE_START, CmdSetTimetableStart, {}, CMDT_ROUTE_MANAGEMENT) #endif /* TIMETABLE_CMD_H */ diff --git a/src/town_cmd.h b/src/town_cmd.h index 5f6b5b0e60..c23eb6c91a 100644 --- a/src/town_cmd.h +++ b/src/town_cmd.h @@ -29,16 +29,16 @@ CommandCost CmdExpandTown(DoCommandFlags flags, TownID town_id, uint32_t grow_am CommandCost CmdDeleteTown(DoCommandFlags flags, TownID town_id); CommandCost CmdPlaceHouse(DoCommandFlags flags, TileIndex tile, HouseID house, bool house_protected); -DEF_CMD_TRAIT(CMD_FOUND_TOWN, CmdFoundTown, CMD_DEITY | CMD_NO_TEST, CMDT_LANDSCAPE_CONSTRUCTION) // founding random town can fail only in exec run -DEF_CMD_TRAIT(CMD_RENAME_TOWN, CmdRenameTown, CMD_DEITY | CMD_SERVER, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_DO_TOWN_ACTION, CmdDoTownAction, CMD_LOCATION, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_TOWN_CARGO_GOAL, CmdTownCargoGoal, CMD_DEITY, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_TOWN_GROWTH_RATE, CmdTownGrowthRate, CMD_DEITY, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_TOWN_RATING, CmdTownRating, CMD_DEITY, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_TOWN_SET_TEXT, CmdTownSetText, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_EXPAND_TOWN, CmdExpandTown, CMD_DEITY, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_DELETE_TOWN, CmdDeleteTown, CMD_OFFLINE, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_PLACE_HOUSE, CmdPlaceHouse, CMD_DEITY, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_FOUND_TOWN, CmdFoundTown, CommandFlags({CommandFlag::Deity, CommandFlag::NoTest}), CMDT_LANDSCAPE_CONSTRUCTION) // founding random town can fail only in exec run +DEF_CMD_TRAIT(CMD_RENAME_TOWN, CmdRenameTown, CommandFlags({CommandFlag::Deity, CommandFlag::Server}), CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_DO_TOWN_ACTION, CmdDoTownAction, CommandFlags({CommandFlag::Location}), CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_TOWN_CARGO_GOAL, CmdTownCargoGoal, CommandFlags({CommandFlag::Deity}), CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_TOWN_GROWTH_RATE, CmdTownGrowthRate, CommandFlags({CommandFlag::Deity}), CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_TOWN_RATING, CmdTownRating, CommandFlags({CommandFlag::Deity}), CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_TOWN_SET_TEXT, CmdTownSetText, CommandFlags({CommandFlag::Deity, CommandFlag::StrCtrl}), CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_EXPAND_TOWN, CmdExpandTown, CommandFlags({CommandFlag::Deity}), CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_DELETE_TOWN, CmdDeleteTown, CommandFlags({CommandFlag::Offline}), CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_PLACE_HOUSE, CmdPlaceHouse, CommandFlags({CommandFlag::Deity}), CMDT_OTHER_MANAGEMENT) CommandCallback CcFoundTown; void CcFoundRandomTown(Commands cmd, const CommandCost &result, Money, TownID town_id); diff --git a/src/train_cmd.h b/src/train_cmd.h index 907b3ddd46..cbc84eca85 100644 --- a/src/train_cmd.h +++ b/src/train_cmd.h @@ -21,9 +21,9 @@ CommandCost CmdMoveRailVehicle(DoCommandFlags flags, VehicleID src_veh, VehicleI CommandCost CmdForceTrainProceed(DoCommandFlags flags, VehicleID veh_id); CommandCost CmdReverseTrainDirection(DoCommandFlags flags, VehicleID veh_id, bool reverse_single_veh); -DEF_CMD_TRAIT(CMD_MOVE_RAIL_VEHICLE, CmdMoveRailVehicle, CMD_LOCATION, CMDT_VEHICLE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_FORCE_TRAIN_PROCEED, CmdForceTrainProceed, CMD_LOCATION, CMDT_VEHICLE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_REVERSE_TRAIN_DIRECTION, CmdReverseTrainDirection, CMD_LOCATION, CMDT_VEHICLE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_MOVE_RAIL_VEHICLE, CmdMoveRailVehicle, CommandFlag::Location, CMDT_VEHICLE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_FORCE_TRAIN_PROCEED, CmdForceTrainProceed, CommandFlag::Location, CMDT_VEHICLE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_REVERSE_TRAIN_DIRECTION, CmdReverseTrainDirection, CommandFlag::Location, CMDT_VEHICLE_MANAGEMENT) void CcBuildWagon(Commands cmd, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray, TileIndex tile, EngineID, bool, CargoType, ClientID); diff --git a/src/tree_cmd.h b/src/tree_cmd.h index 11263a1885..116d50c5f6 100644 --- a/src/tree_cmd.h +++ b/src/tree_cmd.h @@ -14,6 +14,6 @@ CommandCost CmdPlantTree(DoCommandFlags flags, TileIndex tile, TileIndex start_tile, uint8_t tree_to_plant, bool diagonal); -DEF_CMD_TRAIT(CMD_PLANT_TREE, CmdPlantTree, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_PLANT_TREE, CmdPlantTree, CommandFlag::Auto, CMDT_LANDSCAPE_CONSTRUCTION) #endif /* TREE_CMD_H */ diff --git a/src/tunnelbridge_cmd.h b/src/tunnelbridge_cmd.h index a45b0f7bce..25bd0cc226 100644 --- a/src/tunnelbridge_cmd.h +++ b/src/tunnelbridge_cmd.h @@ -17,8 +17,8 @@ CommandCost CmdBuildBridge(DoCommandFlags flags, TileIndex tile_end, TileIndex tile_start, TransportType transport_type, BridgeType bridge_type, uint8_t road_rail_type); CommandCost CmdBuildTunnel(DoCommandFlags flags, TileIndex start_tile, TransportType transport_type, uint8_t road_rail_type); -DEF_CMD_TRAIT(CMD_BUILD_BRIDGE, CmdBuildBridge, CMD_DEITY | CMD_AUTO | CMD_NO_WATER, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_BUILD_TUNNEL, CmdBuildTunnel, CMD_DEITY | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_BUILD_BRIDGE, CmdBuildBridge, CommandFlags({CommandFlag::Deity, CommandFlag::Auto, CommandFlag::NoWater}), CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_BUILD_TUNNEL, CmdBuildTunnel, CommandFlags({CommandFlag::Deity, CommandFlag::Auto}), CMDT_LANDSCAPE_CONSTRUCTION) void CcBuildBridge(Commands cmd, const CommandCost &result, TileIndex end_tile, TileIndex tile_start, TransportType transport_type, BridgeType, uint8_t); diff --git a/src/vehicle_cmd.h b/src/vehicle_cmd.h index f7b994dab6..8f663673bc 100644 --- a/src/vehicle_cmd.h +++ b/src/vehicle_cmd.h @@ -29,17 +29,17 @@ CommandCost CmdMassStartStopVehicle(DoCommandFlags flags, TileIndex tile, bool d CommandCost CmdDepotSellAllVehicles(DoCommandFlags flags, TileIndex tile, VehicleType vehicle_type); CommandCost CmdDepotMassAutoReplace(DoCommandFlags flags, TileIndex tile, VehicleType vehicle_type); -DEF_CMD_TRAIT(CMD_BUILD_VEHICLE, CmdBuildVehicle, CMD_CLIENT_ID, CMDT_VEHICLE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_SELL_VEHICLE, CmdSellVehicle, CMD_CLIENT_ID | CMD_LOCATION, CMDT_VEHICLE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_REFIT_VEHICLE, CmdRefitVehicle, CMD_LOCATION, CMDT_VEHICLE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_SEND_VEHICLE_TO_DEPOT, CmdSendVehicleToDepot, 0, CMDT_VEHICLE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_CHANGE_SERVICE_INT, CmdChangeServiceInt, 0, CMDT_VEHICLE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_RENAME_VEHICLE, CmdRenameVehicle, 0, CMDT_OTHER_MANAGEMENT) -DEF_CMD_TRAIT(CMD_CLONE_VEHICLE, CmdCloneVehicle, CMD_NO_TEST, CMDT_VEHICLE_CONSTRUCTION) // NewGRF callbacks influence building and refitting making it impossible to correctly estimate the cost -DEF_CMD_TRAIT(CMD_START_STOP_VEHICLE, CmdStartStopVehicle, CMD_LOCATION, CMDT_VEHICLE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_MASS_START_STOP, CmdMassStartStopVehicle, 0, CMDT_VEHICLE_MANAGEMENT) -DEF_CMD_TRAIT(CMD_DEPOT_SELL_ALL_VEHICLES, CmdDepotSellAllVehicles, 0, CMDT_VEHICLE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_DEPOT_MASS_AUTOREPLACE, CmdDepotMassAutoReplace, 0, CMDT_VEHICLE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_BUILD_VEHICLE, CmdBuildVehicle, CommandFlag::ClientID, CMDT_VEHICLE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_SELL_VEHICLE, CmdSellVehicle, CommandFlags({CommandFlag::ClientID, CommandFlag::Location}), CMDT_VEHICLE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_REFIT_VEHICLE, CmdRefitVehicle, CommandFlag::Location, CMDT_VEHICLE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_SEND_VEHICLE_TO_DEPOT, CmdSendVehicleToDepot, {}, CMDT_VEHICLE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_CHANGE_SERVICE_INT, CmdChangeServiceInt, {}, CMDT_VEHICLE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_RENAME_VEHICLE, CmdRenameVehicle, {}, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_CLONE_VEHICLE, CmdCloneVehicle, CommandFlag::NoTest, CMDT_VEHICLE_CONSTRUCTION) // NewGRF callbacks influence building and refitting making it impossible to correctly estimate the cost +DEF_CMD_TRAIT(CMD_START_STOP_VEHICLE, CmdStartStopVehicle, CommandFlag::Location, CMDT_VEHICLE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_MASS_START_STOP, CmdMassStartStopVehicle, {}, CMDT_VEHICLE_MANAGEMENT) +DEF_CMD_TRAIT(CMD_DEPOT_SELL_ALL_VEHICLES, CmdDepotSellAllVehicles, {}, CMDT_VEHICLE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_DEPOT_MASS_AUTOREPLACE, CmdDepotMassAutoReplace, {}, CMDT_VEHICLE_CONSTRUCTION) void CcBuildPrimaryVehicle(Commands cmd, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray); void CcStartStopVehicle(Commands cmd, const CommandCost &result, VehicleID veh_id, bool); diff --git a/src/viewport_cmd.h b/src/viewport_cmd.h index 8f0d79261a..c50f9db1a7 100644 --- a/src/viewport_cmd.h +++ b/src/viewport_cmd.h @@ -15,6 +15,6 @@ CommandCost CmdScrollViewport(DoCommandFlags flags, TileIndex tile, ViewportScrollTarget target, uint32_t ref); -DEF_CMD_TRAIT(CMD_SCROLL_VIEWPORT, CmdScrollViewport, CMD_DEITY, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_SCROLL_VIEWPORT, CmdScrollViewport, CommandFlag::Deity, CMDT_OTHER_MANAGEMENT) #endif /* VIEWPORT_CMD_H */ diff --git a/src/water_cmd.h b/src/water_cmd.h index 3ee90523a4..56911695b1 100644 --- a/src/water_cmd.h +++ b/src/water_cmd.h @@ -17,8 +17,8 @@ CommandCost CmdBuildShipDepot(DoCommandFlags flags, TileIndex tile, Axis axis); CommandCost CmdBuildCanal(DoCommandFlags flags, TileIndex tile, TileIndex start_tile, WaterClass wc, bool diagonal); CommandCost CmdBuildLock(DoCommandFlags flags, TileIndex tile); -DEF_CMD_TRAIT(CMD_BUILD_SHIP_DEPOT, CmdBuildShipDepot, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_BUILD_CANAL, CmdBuildCanal, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_BUILD_LOCK, CmdBuildLock, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_BUILD_SHIP_DEPOT, CmdBuildShipDepot, CommandFlag::Auto, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_BUILD_CANAL, CmdBuildCanal, CommandFlag::Auto, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_BUILD_LOCK, CmdBuildLock, CommandFlag::Auto, CMDT_LANDSCAPE_CONSTRUCTION) #endif /* WATER_CMD_H */ diff --git a/src/waypoint_cmd.h b/src/waypoint_cmd.h index 161a8c15d9..e0aaf9853c 100644 --- a/src/waypoint_cmd.h +++ b/src/waypoint_cmd.h @@ -23,11 +23,11 @@ CommandCost CmdRemoveFromRoadWaypoint(DoCommandFlags flags, TileIndex start, Til CommandCost CmdBuildBuoy(DoCommandFlags flags, TileIndex tile); CommandCost CmdRenameWaypoint(DoCommandFlags flags, StationID waypoint_id, const std::string &text); -DEF_CMD_TRAIT(CMD_BUILD_RAIL_WAYPOINT, CmdBuildRailWaypoint, 0, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_REMOVE_FROM_RAIL_WAYPOINT, CmdRemoveFromRailWaypoint, 0, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_BUILD_ROAD_WAYPOINT, CmdBuildRoadWaypoint, 0, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_REMOVE_FROM_ROAD_WAYPOINT, CmdRemoveFromRoadWaypoint, 0, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_BUILD_BUOY, CmdBuildBuoy, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION) -DEF_CMD_TRAIT(CMD_RENAME_WAYPOINT, CmdRenameWaypoint, 0, CMDT_OTHER_MANAGEMENT) +DEF_CMD_TRAIT(CMD_BUILD_RAIL_WAYPOINT, CmdBuildRailWaypoint, {}, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_REMOVE_FROM_RAIL_WAYPOINT, CmdRemoveFromRailWaypoint, {}, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_BUILD_ROAD_WAYPOINT, CmdBuildRoadWaypoint, {}, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_REMOVE_FROM_ROAD_WAYPOINT, CmdRemoveFromRoadWaypoint, {}, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_BUILD_BUOY, CmdBuildBuoy, CommandFlag::Auto, CMDT_LANDSCAPE_CONSTRUCTION) +DEF_CMD_TRAIT(CMD_RENAME_WAYPOINT, CmdRenameWaypoint, {}, CMDT_OTHER_MANAGEMENT) #endif /* WAYPOINT_CMD_H */