62 #include "table/strings.h"
67 int RecursiveCommandCounter::_counter = 0;
83 inline constexpr
CommandInfo CommandFromTrait() noexcept {
return { T::name, T::flags, T::type }; };
85 template<
typename T, T... i>
86 inline constexpr
auto MakeCommandsFromTraits(std::integer_sequence<T, i...>) noexcept {
87 return std::array<
CommandInfo,
sizeof...(i)>{{ CommandFromTrait<CommandTraits<static_cast<Commands>(i)>>()... }};
97 static constexpr
auto _command_proc_table = MakeCommandsFromTraits(std::make_integer_sequence<std::underlying_type_t<Commands>,
CMD_END>{});
147 static const int command_type_lookup[] = {
171 if (top_level) _cleared_object_areas.clear();
218 bool only_sending =
_networking && !network_command;
222 return {
true, estimate_only, only_sending };
224 return {
false, estimate_only, only_sending };
244 if (estimate_only || (
IsLocalCompany() && err_message != 0 && my_cmd)) {
247 }
else if (estimate_only) {
249 }
else if (!only_sending && tile != 0 &&
IsLocalCompany() && _game_mode != GM_EDITOR) {
262 Debug(desync, 1,
"{}: {:08x}; {:02x}; {:02x}; {:08x}; {:08x}; {} ({})", failed ?
"cmdf" :
"cmd", (uint32_t)
TimerGameEconomy::date.base(),
TimerGameEconomy::date_fract, (
int)
_current_company, cmd, err_message,
FormatArrayAsHex(args),
GetCommandName(cmd));
286 _cleared_object_areas.clear();
314 bool test_and_exec_can_differ = (cmd_flags &
CMD_NO_TEST) != 0;
323 _cleared_object_areas.clear();
327 return {
false, _debug_desync_level >= 1, send_net };
361 bool test_and_exec_can_differ = (cmd_flags &
CMD_NO_TEST) != 0;
362 if (!test_and_exec_can_differ) {
363 assert(res_test.GetCost() == res_exec.
GetCost() && res_test.Failed() == res_exec.
Failed());
364 }
else if (res_exec.
Failed()) {
370 if (extra_cash != 0 && res_exec.
GetCost() == 0) {
375 return CommandCost(STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY);
429 for (uint i = 0; i < num_registers; i++) {
Command definitions related to autoreplace.
Class for backupping variables and making sure they are restored later.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Money cost
The cost of this action.
Money GetCost() const
The costs as made up to this moment.
uint textref_stack_size
Number of uint32_t values to put on the TextRefStack for the error message.
void UseTextRefStack(const GRFFile *grffile, uint num_registers)
Activate usage of the NewGRF TextRefStack for the error message.
static uint32_t textref_stack[16]
Values to put on the TextRefStack for the error message.
StringID message
Warning message for when success is unset.
bool Failed() const
Did this command fail?
const GRFFile * textref_stack_grffile
NewGRF providing the TextRefStack content.
bool success
Whether the command went fine up to this moment.
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.
static void InternalDoBefore(bool top_level, bool test)
Prepare for calling a command proc.
static void LogCommandExecution(Commands cmd, StringID err_message, const CommandDataBuffer &args, bool failed)
Helper to make a desync log for a command.
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.
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.
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.
static bool InternalExecutePrepTest(CommandFlags cmd_flags, TileIndex tile, Backup< CompanyID > &cur_company)
Prepare for the test run of a command proc call.
static void InternalDoAfter(CommandCost &res, DoCommandFlag flags, bool top_level, bool test)
Process result after calling a command proc.
static Date date
Current date in days (day counter).
static DateFract date_fract
Fractional part of the day.
CommandFlags GetCommandFlags(Commands cmd)
This function mask the parameter with CMD_ID_MASK and returns the flags which belongs to the given co...
bool IsCommandAllowedWhilePaused(Commands cmd)
Returns whether the command is allowed while the game is paused.
const char * GetCommandName(Commands cmd)
This function mask the parameter with CMD_ID_MASK and returns the name which belongs to the given com...
bool IsValidCommand(Commands cmd)
This function range-checks a cmd.
static constexpr auto _command_proc_table
The master command table.
Functions related to commands.
@ CMDPL_NO_LANDSCAPING
No landscaping actions may be executed.
@ CMDPL_ALL_ACTIONS
All actions may be executed.
@ CMDPL_NO_ACTIONS
No user actions may be executed.
@ CMDPL_NO_CONSTRUCTION
No construction actions may be executed.
CommandType
Types of commands we have.
@ CMDT_END
Magic end marker.
@ CMDT_SERVER_SETTING
Pausing/removing companies/server settings.
DoCommandFlag
List of flags for a command.
@ DC_BANKRUPT
company bankrupts, skip money check, skip vehicle on tile check in some cases
@ DC_QUERY_COST
query cost only, don't build.
std::vector< uint8_t > CommandDataBuffer
Storage buffer for serialized command data.
Commands
List of commands.
@ CMD_COMPANY_CTRL
used in multiplayer to create a new companies etc.
@ CMD_END
Must ALWAYS be on the end of this list!! (period)
CommandFlags
Command flags for the command table _command_proc_table.
@ CMD_NO_EST
the command is never estimated.
@ CMD_SPECTATOR
the command may be initiated by a spectator
@ CMD_NO_TEST
the command's output may differ between test and execute due to town rating changes etc.
@ CMD_SERVER
the command can only be initiated by the server
@ CMD_DEITY
the command may be executed by COMPANY_DEITY
Definition of stuff that is very close to a company, like the company struct itself.
bool CheckCompanyHasMoney(CommandCost &cost)
Verify whether the company can pay the bill.
void SubtractMoneyFromCompany(const CommandCost &cost)
Subtract money from the _current_company, if the company is valid.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
Command definitions related to companies.
Functions related to companies.
bool IsLocalCompany()
Is the current company the local company?
@ COMPANY_SPECTATOR
The client is spectating.
@ OWNER_DEITY
The object is owned by a superuser / goal script.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Command definitions related to depots.
Command definitions related to the economy.
Command definitions related to engines.
Functions related to errors.
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
bool _generating_world
Whether we are generating the map or not.
Functions related to world/map generation.
bool _shift_pressed
Is Shift pressed?
PauseMode _pause_mode
The current pause mode.
Command definitions related to goals.
Command definitions related to engine groups.
GUI functions that shouldn't be here.
void ShowEstimatedCostOrIncome(Money cost, int x, int y)
Display estimated costs.
Command definitions related to industries.
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
Functions related to OTTD's landscape.
Command definitions related to landscape (slopes etc.).
Command definitions related to league tables.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Miscellaneous command definitions.
void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost)
Display animated income or costs on the map.
bool _networking
are we in networking mode?
Basic functions/variables used all over the place.
Types used for networking.
@ PSM_LEAVE_TESTMODE
Leave command test mode, revert to previous mode.
@ PSM_LEAVE_COMMAND
Leave command scope, revert to previous mode.
@ PSM_ENTER_COMMAND
Enter command scope, changes will be permanent.
@ PSM_ENTER_TESTMODE
Enter command test mode, changes will be temporary.
Command definitions related to news messages.
Command definitions related to objects.
@ PM_COMMAND_DURING_PAUSE
A game paused, and a command executed during the pause; resets on autosave.
@ PM_UNPAUSED
A normal unpaused game.
Command definitions related to orders.
Command definitions for rail.
Command definitions related to road vehicles.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Command definitions related to settings.
static SigSegState UpdateSignalsInBuffer(Owner owner)
Updates blocks in _globset buffer.
Functions related to signals.
Command definitions related to signs.
Command definitions related to stations.
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
Command definitions related to stories.
std::string FormatArrayAsHex(std::span< const uint8_t > data)
Format a byte array into a continuous hex string.
Functions related to low-level strings.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Class to backup a specific variable and restore it later.
void Trash()
Trash the backup.
bool Verify() const
Check whether the variable is currently equals the backup.
void Change(const U &new_value)
Change the value of the variable.
void Restore()
Restore the variable.
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...
Define a command with the flags which belongs to it.
const char * name
A human readable name for the procedure.
CommandType type
The type of command.
CommandFlags flags
The (command) flags to that apply to this command.
TileIndex last_build_coordinate
Coordinate of the last build thing by this company.
uint8_t command_pause_level
level/amount of commands that can't be executed while paused
Dynamic data of a loaded NewGRF.
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.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Class for temporary storage of data.
Command definitions related to subsidies.
Functions related to text effects.
static const uint TILE_SIZE
Tile size in world coordinates.
Definition of the game-economy-timer.
void SetTownRatingTestMode(bool mode)
Switch the town rating to test-mode, to allow commands to be tested without affecting current ratings...
Command definitions related to towns.
Command definitions related to trains.
Command definitions related to tree tiles.
Command definitions related to tunnels and bridges.
Command definitions for vehicles.
Command definitions related to viewports.
Command definitions related to water tiles.
Command definitions related to waypoints.