OpenTTD Source 20250312-master-gcdcc6b491d
CommandHelperBase Class Reference
Inheritance diagram for CommandHelperBase:
CommandHelper< Tcmd, Tret(*)(DoCommandFlags, Targs...), true > CommandHelper< Tcmd, Tret(*)(DoCommandFlags, Targs...), false >

Static Protected Member Functions

static void InternalDoBefore (bool top_level, bool test)
 Prepare for calling a command proc.
 
static void InternalDoAfter (CommandCost &res, DoCommandFlags flags, bool top_level, bool test)
 Process result after calling a command proc.
 
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 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 bool InternalExecutePrepTest (CommandFlags cmd_flags, TileIndex tile, Backup< CompanyID > &cur_company)
 Prepare for the test run of a command proc call.
 
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 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 LogCommandExecution (Commands cmd, StringID err_message, const CommandDataBuffer &args, bool failed)
 Helper to make a desync log for a command.
 

Detailed Description

Definition at line 85 of file command_func.h.

Member Function Documentation

◆ InternalDoAfter()

void CommandHelperBase::InternalDoAfter ( CommandCost res,
DoCommandFlags  flags,
bool  top_level,
bool  test 
)
staticprotected

Process result after calling a command proc.

Parameters
[in,out]resCommand result, may be modified.
flagsCommand flags.
top_levelTop level of command execution, i.e. command from a command.
testTest run of command?

Definition at line 182 of file command.cpp.

References Bankrupt, CheckCompanyHasMoney(), QueryCost, SetTownRatingTestMode(), SubtractMoneyFromCompany(), CommandCost::Succeeded(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

◆ InternalDoBefore()

void CommandHelperBase::InternalDoBefore ( bool  top_level,
bool  test 
)
staticprotected

Prepare for calling a command proc.

Parameters
top_levelTop level of command execution, i.e. command from a command.
testTest run of command?

Definition at line 169 of file command.cpp.

References SetTownRatingTestMode().

◆ InternalExecutePrepTest()

bool CommandHelperBase::InternalExecutePrepTest ( CommandFlags  cmd_flags,
TileIndex  tile,
Backup< CompanyID > &  cur_company 
)
staticprotected

Prepare for the test run of a command proc call.

Parameters
cmd_flagsCommand flags.
[in,out]cur_companyBackup of current company at start of command execution.
Returns
True if test run can go ahead, false on error.

Definition at line 272 of file command.cpp.

References _current_company, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), Backup< T >::Change(), COMPANY_SPECTATOR, Deity, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), OWNER_DEITY, PSM_ENTER_TESTMODE, Server, SetTownRatingTestMode(), Spectator, BasePersistentStorageArray::SwitchMode(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

◆ InternalExecuteProcessResult()

CommandCost CommandHelperBase::InternalExecuteProcessResult ( Commands  cmd,
CommandFlags  cmd_flags,
const CommandCost res_test,
const CommandCost res_exec,
Money  extra_cash,
TileIndex  tile,
Backup< CompanyID > &  cur_company 
)
staticprotected

Process the result of a command test run and execution run.

Parameters
cmdCommand that was executed.
cmd_flagsCommand flags.
res_testCommand result of test run.
tes_execCommand result of real run.
extra_cashAdditional cash required for successful command execution.
tileTile of command execution.
[in,out]cur_companyBackup of current company at start of command execution.
Returns
Final command result.

Definition at line 342 of file command.cpp.

References _command_proc_table, _current_company, _local_company, _pause_mode, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), CMD_COMPANY_CTRL, CMDT_SERVER_SETTING, CommandCostWithParam(), CommandDuringPause, COMPANY_SPECTATOR, CommandCost::Failed(), CommandCost::GetCost(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::GetIfValid(), CompanyProperties::last_build_coordinate, NoTest, PSM_LEAVE_COMMAND, Backup< T >::Restore(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SubtractMoneyFromCompany(), BasePersistentStorageArray::SwitchMode(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Backup< T >::Trash(), UpdateSignalsInBuffer(), and Backup< T >::Verify().

◆ InternalExecuteValidateTestAndPrepExec()

std::tuple< bool, bool, bool > CommandHelperBase::InternalExecuteValidateTestAndPrepExec ( CommandCost res,
CommandFlags  cmd_flags,
bool  estimate_only,
bool  network_command,
Backup< CompanyID > &  cur_company 
)
staticprotected

Validate result of test run and prepare for real execution.

Parameters
cmd_flagsCommand flags.
[in,out]resCommand result of test run, may be modified.
estimate_onlyIs this just cost estimation?
network_commandDoes this command come from the network?
[in,out]cur_companyBackup of current company at start of command execution.
Returns
True if test run can go ahead, false on error.

Definition at line 302 of file command.cpp.

References _current_company, _generating_world, _networking, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), CheckCompanyHasMoney(), COMPANY_SPECTATOR, CommandCost::Failed(), NoTest, PSM_ENTER_COMMAND, PSM_LEAVE_TESTMODE, SetTownRatingTestMode(), BasePersistentStorageArray::SwitchMode(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

◆ InternalPostBefore()

std::tuple< bool, bool, bool > CommandHelperBase::InternalPostBefore ( Commands  cmd,
CommandFlags  flags,
TileIndex  tile,
StringID  err_message,
bool  network_command 
)
staticprotected

Decide what to do with the command depending on current game state.

Parameters
cmdCommand to execute.
flagsCommand flags.
tileTile of command execution.
err_messageMessage prefix to show on error.
network_commandDoes this command come from the network?
Returns
error state + do only cost estimation? + send to network only?

Definition at line 207 of file command.cpp.

References _generating_world, _networking, _pause_mode, _shift_pressed, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), GetEncodedString(), IsCommandAllowedWhilePaused(), IsLocalCompany(), NoEst, ShowErrorMessage(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TILE_SIZE, TileX(), TileY(), and WL_INFO.

◆ InternalPostResult()

void CommandHelperBase::InternalPostResult ( const CommandCost res,
TileIndex  tile,
bool  estimate_only,
bool  only_sending,
StringID  err_message,
bool  my_cmd 
)
staticprotected

Process result of executing a command, possibly displaying any error to the player.

Parameters
resCommand result.
tileTile of command execution.
estimate_onlyIs this just cost estimation?
only_sendingWas the command only sent to network?
err_messageMessage prefix to show on error.
my_cmdIs the command from this client?

Definition at line 238 of file command.cpp.

References CommandCost::Failed(), CommandCost::GetCost(), GetEncodedString(), GetSlopePixelZ(), IsLocalCompany(), ShowCostOrIncomeAnimation(), ShowErrorMessage(), ShowEstimatedCostOrIncome(), TILE_SIZE, TileX(), and TileY().

◆ LogCommandExecution()

void CommandHelperBase::LogCommandExecution ( Commands  cmd,
StringID  err_message,
const CommandDataBuffer args,
bool  failed 
)
staticprotected

Helper to make a desync log for a command.

Definition at line 261 of file command.cpp.

References _current_company, TimerGameEconomy::date, TimerGameEconomy::date_fract, Debug, FormatArrayAsHex(), and GetCommandName().


The documentation for this class was generated from the following files: