OpenTTD Source: src/command.cpp Source File

OpenTTD Source 13.1

command.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "landscape.h"
12 #include "error.h"
13 #include "gui.h"
14 #include "command_func.h"
15 #include "network/network_type.h"
16 #include "network/network.h"
17 #include "genworld.h"
18 #include "strings_func.h"
19 #include "texteff.hpp"
20 #include "town.h"
21 #include "date_func.h"
22 #include "company_func.h"
23 #include "company_base.h"
24 #include "signal_func.h"
25 #include "core/backup_type.hpp"
26 #include "object_base.h"
27 #include "autoreplace_cmd.h"
28 #include "company_cmd.h"
29 #include "depot_cmd.h"
30 #include "economy_cmd.h"
31 #include "engine_cmd.h"
32 #include "goal_cmd.h"
33 #include "group_cmd.h"
34 #include "industry_cmd.h"
35 #include "league_cmd.h"
36 #include "landscape_cmd.h"
37 #include "misc_cmd.h"
38 #include "news_cmd.h"
39 #include "object_cmd.h"
40 #include "order_cmd.h"
41 #include "rail_cmd.h"
42 #include "road_cmd.h"
43 #include "roadveh_cmd.h"
44 #include "settings_cmd.h"
45 #include "signs_cmd.h"
46 #include "station_cmd.h"
47 #include "story_cmd.h"
48 #include "subsidy_cmd.h"
49 #include "terraform_cmd.h"
50 #include "timetable_cmd.h"
51 #include "town_cmd.h"
52 #include "train_cmd.h"
53 #include "tree_cmd.h"
54 #include "tunnelbridge_cmd.h"
55 #include "vehicle_cmd.h"
56 #include "viewport_cmd.h"
57 #include "water_cmd.h"
58 #include "waypoint_cmd.h"
59 #include "misc/endian_buffer.hpp"
60 #include "string_func.h"
61
62 #include <array>
63
64 #include "table/strings.h"
65
66 #include "safeguards.h"
67
68
69 int RecursiveCommandCounter::_counter = 0;
70
71
78 struct CommandInfo {
79 const char *name;
80 CommandFlags flags;
81 CommandType type;
82 };
83 /* Helpers to generate the master command table from the command traits. */
84 template <typename T>
85 inline constexpr CommandInfo CommandFromTrait() noexcept { return { T::name, T::flags, T::type }; };
86
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)>>()... }};
90 }
91
99 static constexpr auto _command_proc_table = MakeCommandsFromTraits(std::make_integer_sequence<std::underlying_type_t<Commands>, CMD_END>{});
100
101
108 bool IsValidCommand(Commands cmd)
109 {
110 return cmd < _command_proc_table.size();
111 }
112
120 CommandFlags GetCommandFlags(Commands cmd)
121 {
122 assert(IsValidCommand(cmd));
123
124 return _command_proc_table[cmd].flags;
125 }
126
134 const char *GetCommandName(Commands cmd)
135 {
136 assert(IsValidCommand(cmd));
137
138 return _command_proc_table[cmd].name;
139 }
140
146 bool IsCommandAllowedWhilePaused(Commands cmd)
147 {
148 /* Lookup table for the command types that are allowed for a given pause level setting. */
149 static const int command_type_lookup[] = {
150 CMDPL_ALL_ACTIONS,
151 CMDPL_NO_LANDSCAPING,
152 CMDPL_NO_LANDSCAPING,
153 CMDPL_NO_CONSTRUCTION,
154 CMDPL_NO_CONSTRUCTION,
155 CMDPL_NO_CONSTRUCTION,
156 CMDPL_NO_CONSTRUCTION,
157 CMDPL_NO_ACTIONS,
158 CMDPL_NO_ACTIONS,
159 };
160 static_assert(lengthof(command_type_lookup) == CMDT_END);
161
162 assert(IsValidCommand(cmd));
163 return _game_mode == GM_EDITOR || command_type_lookup[_command_proc_table[cmd].type] <= _settings_game.construction.command_pause_level;
164 }
165
173 Money GetAvailableMoneyForCommand()
174 {
175 CompanyID company = _current_company;
176 if (!Company::IsValidID(company)) return INT64_MAX;
177 return Company::Get(company)->money;
178 }
179
180
186 void CommandHelperBase::InternalDoBefore(bool top_level, bool test)
187 {
188 if (top_level) _cleared_object_areas.clear();
189 if (test) SetTownRatingTestMode(true);
190 }
191
199 void CommandHelperBase::InternalDoAfter(CommandCost &res, DoCommandFlag flags, bool top_level, bool test)
200 {
201 if (test) {
202 SetTownRatingTestMode(false);
203
204 if (res.Succeeded() && top_level && !(flags & DC_QUERY_COST) && !(flags & DC_BANKRUPT)) {
205 CheckCompanyHasMoney(res); // CheckCompanyHasMoney() modifies 'res' to an error if it fails.
206 }
207 } else {
208 /* If top-level, subtract the money. */
209 if (res.Succeeded() && top_level && !(flags & DC_BANKRUPT)) {
210 SubtractMoneyFromCompany(res);
211 }
212 }
213 }
214
224 std::tuple<bool, bool, bool> CommandHelperBase::InternalPostBefore(Commands cmd, CommandFlags flags, TileIndex tile, StringID err_message, bool network_command)
225 {
226 /* Cost estimation is generally only done when the
227 * local user presses shift while doing something.
228 * However, in case of incoming network commands,
229 * map generation or the pause button we do want
230 * to execute. */
231 bool estimate_only = _shift_pressed && IsLocalCompany() && !_generating_world && !network_command && !(flags & CMD_NO_EST);
232
233 /* We're only sending the command, so don't do
234 * fancy things for 'success'. */
235 bool only_sending = _networking && !network_command;
236
237 if (_pause_mode != PM_UNPAUSED && !IsCommandAllowedWhilePaused(cmd) && !estimate_only) {
238 ShowErrorMessage(err_message, STR_ERROR_NOT_ALLOWED_WHILE_PAUSED, WL_INFO, TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE);
239 return { true, estimate_only, only_sending };
240 } else {
241 return { false, estimate_only, only_sending };
242 }
243 }
244
254 void CommandHelperBase::InternalPostResult(const CommandCost &res, TileIndex tile, bool estimate_only, bool only_sending, StringID err_message, bool my_cmd)
255 {
256 int x = TileX(tile) * TILE_SIZE;
257 int y = TileY(tile) * TILE_SIZE;
258
259 if (res.Failed()) {
260 /* Only show the error when it's for us. */
261 if (estimate_only || (IsLocalCompany() && err_message != 0 && my_cmd)) {
262 ShowErrorMessage(err_message, res.GetErrorMessage(), WL_INFO, x, y, res.GetTextRefStackGRF(), res.GetTextRefStackSize(), res.GetTextRefStack());
263 }
264 } else if (estimate_only) {
265 ShowEstimatedCostOrIncome(res.GetCost(), x, y);
266 } else if (!only_sending && tile != 0 && IsLocalCompany() && _game_mode != GM_EDITOR) {
267 /* Only show the cost animation when we did actually
268 * execute the command, i.e. we're not sending it to
269 * the server, when it has cost the local company
270 * something. Furthermore in the editor there is no
271 * concept of cost, so don't show it there either. */
272 ShowCostOrIncomeAnimation(x, y, GetSlopePixelZ(x, y), res.GetCost());
273 }
274 }
275
277 void CommandHelperBase::LogCommandExecution(Commands cmd, StringID err_message, TileIndex tile, const CommandDataBuffer &args, bool failed)
278 {
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));
280 }
281
289 bool CommandHelperBase::InternalExecutePrepTest(CommandFlags cmd_flags, TileIndex tile, Backup<CompanyID> &cur_company)
290 {
291 /* Always execute server and spectator commands as spectator */
292 bool exec_as_spectator = (cmd_flags & (CMD_SPECTATOR | CMD_SERVER)) != 0;
293
294 /* If the company isn't valid it may only do server command or start a new company!
295 * The server will ditch any server commands a client sends to it, so effectively
296 * this guards the server from executing functions for an invalid company. */
297 if (_game_mode == GM_NORMAL && !exec_as_spectator && !Company::IsValidID(_current_company) && !(_current_company == OWNER_DEITY && (cmd_flags & CMD_DEITY) != 0)) {
298 return false;
299 }
300
301 if (exec_as_spectator) cur_company.Change(COMPANY_SPECTATOR);
302
303 /* Enter test mode. */
304 _cleared_object_areas.clear();
305 SetTownRatingTestMode(true);
306 BasePersistentStorageArray::SwitchMode(PSM_ENTER_TESTMODE);
307 return true;
308 }
309
319 std::tuple<bool, bool, bool> CommandHelperBase::InternalExecuteValidateTestAndPrepExec(CommandCost &res, CommandFlags cmd_flags, bool estimate_only, bool network_command, Backup<CompanyID> &cur_company)
320 {
321 BasePersistentStorageArray::SwitchMode(PSM_LEAVE_TESTMODE);
322 SetTownRatingTestMode(false);
323
324 /* Make sure we're not messing things up here. */
325 assert((cmd_flags & (CMD_SPECTATOR | CMD_SERVER)) != 0 ? _current_company == COMPANY_SPECTATOR : cur_company.Verify());
326
327 /* If the command fails, we're doing an estimate
328 * or the player does not have enough money
329 * (unless it's a command where the test and
330 * execution phase might return different costs)
331 * we bail out here. */
332 bool test_and_exec_can_differ = (cmd_flags & CMD_NO_TEST) != 0;
333 if (res.Failed() || estimate_only || (!test_and_exec_can_differ && !CheckCompanyHasMoney(res))) {
334 return { true, !_networking || _generating_world || network_command, false };
335 }
336
337 bool send_net = _networking && !_generating_world && !network_command;
338
339 if (!send_net) {
340 /* Prepare for command execution. */
341 _cleared_object_areas.clear();
342 BasePersistentStorageArray::SwitchMode(PSM_ENTER_COMMAND);
343 }
344
345 return { false, _debug_desync_level >= 1, send_net };
346 }
347
359 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)
360 {
361 BasePersistentStorageArray::SwitchMode(PSM_LEAVE_COMMAND);
362
363 if (cmd == CMD_COMPANY_CTRL) {
364 cur_company.Trash();
365 /* We are a new company -> Switch to new local company.
366 * We were closed down -> Switch to spectator
367 * Some other company opened/closed down -> The outside function will switch back */
368 _current_company = _local_company;
369 } else {
370 /* Make sure nothing bad happened, like changing the current company. */
371 assert((cmd_flags & (CMD_SPECTATOR | CMD_SERVER)) != 0 ? _current_company == COMPANY_SPECTATOR : cur_company.Verify());
372 cur_company.Restore();
373 }
374
375 /* If the test and execution can differ we have to check the
376 * return of the command. Otherwise we can check whether the
377 * test and execution have yielded the same result,
378 * i.e. cost and error state are the same. */
379 bool test_and_exec_can_differ = (cmd_flags & CMD_NO_TEST) != 0;
380 if (!test_and_exec_can_differ) {
381 assert(res_test.GetCost() == res_exec.GetCost() && res_test.Failed() == res_exec.Failed()); // sanity check
382 } else if (res_exec.Failed()) {
383 return res_exec;
384 }
385
386 /* If we're needing more money and we haven't done
387 * anything yet, ask for the money! */
388 if (extra_cash != 0 && res_exec.GetCost() == 0) {
389 /* It could happen we removed rail, thus gained money, and deleted something else.
390 * So make sure the signal buffer is empty even in this case */
391 UpdateSignalsInBuffer();
392 SetDParam(0, extra_cash);
393 return CommandCost(STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY);
394 }
395
396 /* update last build coordinate of company. */
397 if (tile != 0) {
398 Company *c = Company::GetIfValid(_current_company);
399 if (c != nullptr) c->last_build_coordinate = tile;
400 }
401
402 SubtractMoneyFromCompany(res_exec);
403
404 /* update signals if needed */
405 UpdateSignalsInBuffer();
406
407 return res_exec;
408 }
409
410
416 void CommandCost::AddCost(const CommandCost &ret)
417 {
418 this->AddCost(ret.cost);
419 if (this->success && !ret.success) {
420 this->message = ret.message;
421 this->success = false;
422 }
423 }
424
430 uint32 CommandCost::textref_stack[16];
431
437 void CommandCost::UseTextRefStack(const GRFFile *grffile, uint num_registers)
438 {
439 extern TemporaryStorageArray<int32, 0x110> _temp_store;
440
441 assert(num_registers < lengthof(textref_stack));
442 this->textref_stack_grffile = grffile;
443 this->textref_stack_size = num_registers;
444 for (uint i = 0; i < num_registers; i++) {
445 textref_stack[i] = _temp_store.GetValue(0x100 + i);
446 }
447 }
PSM_LEAVE_TESTMODE
@ PSM_LEAVE_TESTMODE
Leave command test mode, revert to previous mode.
Definition: newgrf_storage.h:25
Backup::Change
void Change(const U &new_value)
Change the value of the variable.
Definition: backup_type.hpp:84
CommandInfo::name
const char * name
A human readable name for the procedure.
Definition: command.cpp:79
news_cmd.h
economy_cmd.h
order_cmd.h
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
CMDPL_NO_ACTIONS
@ CMDPL_NO_ACTIONS
No user actions may be executed.
Definition: command_type.h:410
UpdateSignalsInBuffer
static SigSegState UpdateSignalsInBuffer(Owner owner)
Updates blocks in _globset buffer.
Definition: signal.cpp:468
command_func.h
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:348
Commands
Commands
List of commands.
Definition: command_type.h:176
CommandDataBuffer
std::vector< byte > CommandDataBuffer
Storage buffer for serialized command data.
Definition: command_type.h:451
Backup
Class to backup a specific variable and restore it later.
Definition: backup_type.hpp:21
terraform_cmd.h
company_base.h
tree_cmd.h
waypoint_cmd.h
_date_fract
DateFract _date_fract
Fractional part of the day.
Definition: date.cpp:29
GetCommandFlags
CommandFlags GetCommandFlags(Commands cmd)
Definition: command.cpp:120
depot_cmd.h
CommandType
CommandType
Types of commands we have.
Definition: command_type.h:394
CommandHelperBase::InternalExecuteValidateTestAndPrepExec
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.
Definition: command.cpp:319
misc_cmd.h
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
CMD_NO_EST
@ CMD_NO_EST
the command is never estimated.
Definition: command_type.h:388
CommandHelperBase::InternalDoBefore
static void InternalDoBefore(bool top_level, bool test)
Prepare for calling a command proc.
Definition: command.cpp:186
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
Backup::Verify
bool Verify() const
Check whether the variable is currently equals the backup.
Definition: backup_type.hpp:132
town.h
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
CompanyProperties::last_build_coordinate
TileIndex last_build_coordinate
Coordinate of the last build thing by this company.
Definition: company_base.h:76
CommandCost::GetTextRefStack
const uint32 * GetTextRefStack() const
Returns a pointer to the values for the TextRefStack of the error message.
Definition: command_type.h:132
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
CommandCost::GetErrorMessage
StringID GetErrorMessage() const
Returns the error message of a command.
Definition: command_type.h:141
IsLocalCompany
static bool IsLocalCompany()
Is the current company the local company?
Definition: company_func.h:43
CommandCost::textref_stack
static uint32 textref_stack[16]
Values to put on the TextRefStack for the error message.
Definition: command_type.h:32
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:355
genworld.h
engine_cmd.h
CMD_END
@ CMD_END
Must ALWAYS be on the end of this list!! (period)
Definition: command_type.h:347
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:151
CMD_DEITY
@ CMD_DEITY
the command may be executed by COMPANY_DEITY
Definition: command_type.h:386
object_base.h
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
train_cmd.h
ShowErrorMessage
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.
Definition: error_gui.cpp:377
CMDT_END
@ CMDT_END
Magic end marker.
Definition: command_type.h:405
endian_buffer.hpp
PM_UNPAUSED
@ PM_UNPAUSED
A normal unpaused game.
Definition: openttd.h:61
FormatArrayAsHex
std::string FormatArrayAsHex(span< const byte > data)
Format a byte array into a continuous hex string.
Definition: string.cpp:169
timetable_cmd.h
company_cmd.h
landscape_cmd.h
CommandFlags
CommandFlags
Command flags for the command table _command_proc_table.
Definition: command_type.h:377
signs_cmd.h
CommandHelperBase::InternalExecutePrepTest
static bool InternalExecutePrepTest(CommandFlags cmd_flags, TileIndex tile, Backup< CompanyID > &cur_company)
Prepare for the test run of a command proc call.
Definition: command.cpp:289
CommandCost::UseTextRefStack
void UseTextRefStack(const GRFFile *grffile, uint num_registers)
Activate usage of the NewGRF TextRefStack for the error message.
Definition: command.cpp:437
CommandCost
Common return value for all commands.
Definition: command_type.h:24
CommandCost::textref_stack_size
uint textref_stack_size
Number of uint32 values to put on the TextRefStack for the error message.
Definition: command_type.h:30
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
town_cmd.h
CommandCost::GetTextRefStackSize
uint GetTextRefStackSize() const
Returns the number of uint32 values for the TextRefStack of the error message.
Definition: command_type.h:123
rail_cmd.h
station_cmd.h
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:160
CMDPL_NO_LANDSCAPING
@ CMDPL_NO_LANDSCAPING
No landscaping actions may be executed.
Definition: command_type.h:412
_pause_mode
PauseMode _pause_mode
The current pause mode.
Definition: gfx.cpp:50
autoreplace_cmd.h
CommandCost::GetTextRefStackGRF
const GRFFile * GetTextRefStackGRF() const
Returns the NewGRF providing the TextRefStack of the error message.
Definition: command_type.h:114
CMD_COMPANY_CTRL
@ CMD_COMPANY_CTRL
used in multiplayer to create a new companies etc.
Definition: command_type.h:283
PSM_LEAVE_COMMAND
@ PSM_LEAVE_COMMAND
Leave command scope, revert to previous mode.
Definition: newgrf_storage.h:23
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:22
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
safeguards.h
vehicle_cmd.h
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:83
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:58
_shift_pressed
bool _shift_pressed
Is Shift pressed?
Definition: gfx.cpp:39
CommandHelperBase::InternalDoAfter
static void InternalDoAfter(CommandCost &res, DoCommandFlag flags, bool top_level, bool test)
Process result after calling a command proc.
Definition: command.cpp:199
GetAvailableMoneyForCommand
Money GetAvailableMoneyForCommand()
Definition: command.cpp:173
CommandHelperBase::InternalPostBefore
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.
Definition: command.cpp:224
error.h
subsidy_cmd.h
tunnelbridge_cmd.h
date_func.h
CommandCost::AddCost
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition: command_type.h:63
stdafx.h
ShowCostOrIncomeAnimation
void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost)
Display animated income or costs on the map.
Definition: misc_gui.cpp:572
landscape.h
DC_BANKRUPT
@ DC_BANKRUPT
company bankrupts, skip money check, skip vehicle on tile check in some cases
Definition: command_type.h:363
CheckCompanyHasMoney
bool CheckCompanyHasMoney(CommandCost &cost)
Verify whether the company can pay the bill.
Definition: company_cmd.cpp:200
CommandInfo::type
CommandType type
The type of command.
Definition: command.cpp:81
object_cmd.h
_command_proc_table
static constexpr auto _command_proc_table
The master command table.
Definition: command.cpp:99
group_cmd.h
_generating_world
bool _generating_world
Whether we are generating the map or not.
Definition: genworld.cpp:61
CommandCost::textref_stack_grffile
const GRFFile * textref_stack_grffile
NewGRF providing the TextRefStack content.
Definition: command_type.h:29
texteff.hpp
string_func.h
CommandHelperBase::InternalPostResult
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.
Definition: command.cpp:254
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
CommandHelperBase::InternalExecuteProcessResult
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.
Definition: command.cpp:359
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
strings_func.h
Backup::Trash
void Trash()
Trash the backup.
Definition: backup_type.hpp:103
CommandCost::message
StringID message
Warning message for when success is unset.
Definition: command_type.h:27
IsValidCommand
bool IsValidCommand(Commands cmd)
Definition: command.cpp:108
Backup::Restore
void Restore()
Restore the variable.
Definition: backup_type.hpp:112
COMPANY_SPECTATOR
@ COMPANY_SPECTATOR
The client is spectating.
Definition: company_type.h:35
story_cmd.h
industry_cmd.h
CommandInfo::flags
CommandFlags flags
The (command) flags to that apply to this command.
Definition: command.cpp:80
GetCommandName
const char * GetCommandName(Commands cmd)
Definition: command.cpp:134
goal_cmd.h
settings_cmd.h
signal_func.h
IsCommandAllowedWhilePaused
bool IsCommandAllowedWhilePaused(Commands cmd)
Returns whether the command is allowed while the game is paused.
Definition: command.cpp:146
CommandHelperBase::LogCommandExecution
static void LogCommandExecution(Commands cmd, StringID err_message, TileIndex tile, const CommandDataBuffer &args, bool failed)
Helper to make a desync log for a command.
Definition: command.cpp:277
OWNER_DEITY
@ OWNER_DEITY
The object is owned by a superuser / goal script.
Definition: company_type.h:27
CMD_NO_TEST
@ CMD_NO_TEST
the command's output may differ between test and execute due to town rating changes etc.
Definition: command_type.h:383
company_func.h
network.h
ShowEstimatedCostOrIncome
void ShowEstimatedCostOrIncome(Money cost, int x, int y)
Display estimated costs.
Definition: misc_gui.cpp:553
CommandCost::cost
Money cost
The cost of this action.
Definition: command_type.h:26
league_cmd.h
Debug
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
CMDPL_ALL_ACTIONS
@ CMDPL_ALL_ACTIONS
All actions may be executed.
Definition: command_type.h:413
OverflowSafeInt< int64 >
TemporaryStorageArray
Class for temporary storage of data.
Definition: newgrf_storage.h:150
BasePersistentStorageArray::SwitchMode
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...
Definition: newgrf_storage.cpp:55
gui.h
PSM_ENTER_COMMAND
@ PSM_ENTER_COMMAND
Enter command scope, changes will be permanent.
Definition: newgrf_storage.h:22
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:588
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:326
SubtractMoneyFromCompany
void SubtractMoneyFromCompany(const CommandCost &cost)
Subtract money from the _current_company, if the company is valid.
Definition: company_cmd.cpp:247
CMD_SERVER
@ CMD_SERVER
the command can only be initiated by the server
Definition: command_type.h:378
CMD_SPECTATOR
@ CMD_SPECTATOR
the command may be initiated by a spectator
Definition: command_type.h:379
DC_QUERY_COST
@ DC_QUERY_COST
query cost only, don't build.
Definition: command_type.h:359
ConstructionSettings::command_pause_level
uint8 command_pause_level
level/amount of commands that can't be executed while paused
Definition: settings_type.h:356
CommandInfo
Define a command with the flags which belongs to it.
Definition: command.cpp:78
Company
Definition: company_base.h:117
PSM_ENTER_TESTMODE
@ PSM_ENTER_TESTMODE
Enter command test mode, changes will be temporary.
Definition: newgrf_storage.h:24
CMDPL_NO_CONSTRUCTION
@ CMDPL_NO_CONSTRUCTION
No construction actions may be executed.
Definition: command_type.h:411
roadveh_cmd.h
SetTownRatingTestMode
void SetTownRatingTestMode(bool mode)
Switch the town rating to test-mode, to allow commands to be tested without affecting current ratings...
Definition: town_cmd.cpp:3635
viewport_cmd.h
road_cmd.h
network_type.h
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:106
CommandCost::success
bool success
Whether the comment went fine up to this moment.
Definition: command_type.h:28
water_cmd.h
backup_type.hpp