Go to the documentation of this file.
64 #include "table/strings.h"
69 int RecursiveCommandCounter::_counter = 0;
85 inline constexpr
CommandInfo CommandFromTrait() noexcept {
return { T::name, T::flags, T::type }; };
87 template<
typename T, T... i>
88 inline constexpr
auto MakeCommandsFromTraits(std::integer_sequence<T, i...>) noexcept {
89 return std::array<
CommandInfo,
sizeof...(i)>{{ CommandFromTrait<CommandTraits<static_cast<Commands>(i)>>()... }};
99 static constexpr
auto _command_proc_table = MakeCommandsFromTraits(std::make_integer_sequence<std::underlying_type_t<Commands>,
CMD_END>{});
149 static const int command_type_lookup[] = {
188 if (top_level) _cleared_object_areas.clear();
235 bool only_sending =
_networking && !network_command;
239 return {
true, estimate_only, only_sending };
241 return {
false, estimate_only, only_sending };
261 if (estimate_only || (
IsLocalCompany() && err_message != 0 && my_cmd)) {
264 }
else if (estimate_only) {
266 }
else if (!only_sending && tile != 0 &&
IsLocalCompany() && _game_mode != GM_EDITOR) {
279 Debug(desync, 1,
"{}: {:08x}; {:02x}; {:02x}; {:08x}; {:08x}; {:06x}; {} ({})", failed ?
"cmdf" :
"cmd",
_date,
_date_fract, (
int)
_current_company, cmd, err_message, tile,
FormatArrayAsHex(args),
GetCommandName(cmd));
304 _cleared_object_areas.clear();
332 bool test_and_exec_can_differ = (cmd_flags &
CMD_NO_TEST) != 0;
341 _cleared_object_areas.clear();
345 return {
false, _debug_desync_level >= 1, send_net };
379 bool test_and_exec_can_differ = (cmd_flags &
CMD_NO_TEST) != 0;
380 if (!test_and_exec_can_differ) {
382 }
else if (res_exec.
Failed()) {
388 if (extra_cash != 0 && res_exec.
GetCost() == 0) {
393 return CommandCost(STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY);
444 for (uint i = 0; i < num_registers; i++) {
@ PSM_LEAVE_TESTMODE
Leave command test mode, revert to previous mode.
void Change(const U &new_value)
Change the value of the variable.
const char * name
A human readable name for the procedure.
static Titem * Get(size_t index)
Returns Titem with given index.
@ CMDPL_NO_ACTIONS
No user actions may be executed.
static SigSegState UpdateSignalsInBuffer(Owner owner)
Updates blocks in _globset buffer.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Commands
List of commands.
std::vector< byte > CommandDataBuffer
Storage buffer for serialized command data.
Class to backup a specific variable and restore it later.
DateFract _date_fract
Fractional part of the day.
CommandFlags GetCommandFlags(Commands cmd)
CommandType
Types of commands we have.
static std::tuple< bool, bool, bool > InternalExecuteValidateTestAndPrepExec(CommandCost &res, CommandFlags cmd_flags, bool estimate_only, bool network_command, Backup< CompanyID > &cur_company)
Validate result of test run and prepare for real execution.
@ CMD_NO_EST
the command is never estimated.
static void InternalDoBefore(bool top_level, bool test)
Prepare for calling a command proc.
static const uint TILE_SIZE
Tile size in world coordinates.
bool Verify() const
Check whether the variable is currently equals the backup.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
TileIndex last_build_coordinate
Coordinate of the last build thing by this company.
const uint32 * GetTextRefStack() const
Returns a pointer to the values for the TextRefStack of the error message.
Owner
Enum for all companies/owners.
StringID GetErrorMessage() const
Returns the error message of a command.
static bool IsLocalCompany()
Is the current company the local company?
static uint32 textref_stack[16]
Values to put on the TextRefStack for the error message.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
DoCommandFlag
List of flags for a command.
@ CMD_END
Must ALWAYS be on the end of this list!! (period)
bool Succeeded() const
Did this command succeed?
@ CMD_DEITY
the command may be executed by COMPANY_DEITY
static uint TileX(TileIndex tile)
Get the X component of a tile.
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
@ CMDT_END
Magic end marker.
@ PM_UNPAUSED
A normal unpaused game.
std::string FormatArrayAsHex(span< const byte > data)
Format a byte array into a continuous hex string.
CommandFlags
Command flags for the command table _command_proc_table.
static bool InternalExecutePrepTest(CommandFlags cmd_flags, TileIndex tile, Backup< CompanyID > &cur_company)
Prepare for the test run of a command proc call.
void UseTextRefStack(const GRFFile *grffile, uint num_registers)
Activate usage of the NewGRF TextRefStack for the error message.
Common return value for all commands.
uint textref_stack_size
Number of uint32 values to put on the TextRefStack for the error message.
Date _date
Current date in days (day counter)
uint GetTextRefStackSize() const
Returns the number of uint32 values for the TextRefStack of the error message.
bool Failed() const
Did this command fail?
@ CMDPL_NO_LANDSCAPING
No landscaping actions may be executed.
PauseMode _pause_mode
The current pause mode.
const GRFFile * GetTextRefStackGRF() const
Returns the NewGRF providing the TextRefStack of the error message.
@ CMD_COMPANY_CTRL
used in multiplayer to create a new companies etc.
@ PSM_LEAVE_COMMAND
Leave command scope, revert to previous mode.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Money GetCost() const
The costs as made up to this moment.
bool _networking
are we in networking mode?
bool _shift_pressed
Is Shift pressed?
static void InternalDoAfter(CommandCost &res, DoCommandFlag flags, bool top_level, bool test)
Process result after calling a command proc.
Money GetAvailableMoneyForCommand()
static std::tuple< bool, bool, bool > InternalPostBefore(Commands cmd, CommandFlags flags, TileIndex tile, StringID err_message, bool network_command)
Decide what to do with the command depending on current game state.
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost)
Display animated income or costs on the map.
@ DC_BANKRUPT
company bankrupts, skip money check, skip vehicle on tile check in some cases
bool CheckCompanyHasMoney(CommandCost &cost)
Verify whether the company can pay the bill.
CommandType type
The type of command.
static constexpr auto _command_proc_table
The master command table.
bool _generating_world
Whether we are generating the map or not.
const GRFFile * textref_stack_grffile
NewGRF providing the TextRefStack content.
static void InternalPostResult(const CommandCost &res, TileIndex tile, bool estimate_only, bool only_sending, StringID err_message, bool my_cmd)
Process result of executing a command, possibly displaying any error to the player.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
static CommandCost InternalExecuteProcessResult(Commands cmd, CommandFlags cmd_flags, const CommandCost &res_test, const CommandCost &res_exec, Money extra_cash, TileIndex tile, Backup< CompanyID > &cur_company)
Process the result of a command test run and execution run.
CompanyID _current_company
Company currently doing an action.
void Trash()
Trash the backup.
StringID message
Warning message for when success is unset.
bool IsValidCommand(Commands cmd)
void Restore()
Restore the variable.
@ COMPANY_SPECTATOR
The client is spectating.
CommandFlags flags
The (command) flags to that apply to this command.
const char * GetCommandName(Commands cmd)
bool IsCommandAllowedWhilePaused(Commands cmd)
Returns whether the command is allowed while the game is paused.
static void LogCommandExecution(Commands cmd, StringID err_message, TileIndex tile, const CommandDataBuffer &args, bool failed)
Helper to make a desync log for a command.
@ OWNER_DEITY
The object is owned by a superuser / goal script.
@ CMD_NO_TEST
the command's output may differ between test and execute due to town rating changes etc.
void ShowEstimatedCostOrIncome(Money cost, int x, int y)
Display estimated costs.
Money cost
The cost of this action.
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
#define lengthof(x)
Return the length of an fixed size array.
@ CMDPL_ALL_ACTIONS
All actions may be executed.
Class for temporary storage of data.
static void SwitchMode(PersistentStorageMode mode, bool ignore_prev_mode=false)
Clear temporary changes made since the last call to SwitchMode, and set whether subsequent changes sh...
@ PSM_ENTER_COMMAND
Enter command scope, changes will be permanent.
ConstructionSettings construction
construction of things in-game
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
void SubtractMoneyFromCompany(const CommandCost &cost)
Subtract money from the _current_company, if the company is valid.
@ CMD_SERVER
the command can only be initiated by the server
@ CMD_SPECTATOR
the command may be initiated by a spectator
@ DC_QUERY_COST
query cost only, don't build.
uint8 command_pause_level
level/amount of commands that can't be executed while paused
Define a command with the flags which belongs to it.
@ PSM_ENTER_TESTMODE
Enter command test mode, changes will be temporary.
@ CMDPL_NO_CONSTRUCTION
No construction actions may be executed.
void SetTownRatingTestMode(bool mode)
Switch the town rating to test-mode, to allow commands to be tested without affecting current ratings...
Dynamic data of a loaded NewGRF.
bool success
Whether the comment went fine up to this moment.