OpenTTD Source  1.10.0-RC1
command_type.h
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 #ifndef COMMAND_TYPE_H
11 #define COMMAND_TYPE_H
12 
13 #include "economy_type.h"
14 #include "strings_type.h"
15 #include "tile_type.h"
16 
17 struct GRFFile;
18 
23 class CommandCost {
27  bool success;
30 
31  static uint32 textref_stack[16];
32 
33 public:
37  CommandCost() : expense_type(INVALID_EXPENSES), cost(0), message(INVALID_STRING_ID), success(true), textref_stack_grffile(nullptr), textref_stack_size(0) {}
38 
42  explicit CommandCost(StringID msg) : expense_type(INVALID_EXPENSES), cost(0), message(msg), success(false), textref_stack_grffile(nullptr), textref_stack_size(0) {}
43 
48  explicit CommandCost(ExpensesType ex_t) : expense_type(ex_t), cost(0), message(INVALID_STRING_ID), success(true), textref_stack_grffile(nullptr), textref_stack_size(0) {}
49 
55  CommandCost(ExpensesType ex_t, const Money &cst) : expense_type(ex_t), cost(cst), message(INVALID_STRING_ID), success(true), textref_stack_grffile(nullptr), textref_stack_size(0) {}
56 
57 
62  inline void AddCost(const Money &cost)
63  {
64  this->cost += cost;
65  }
66 
67  void AddCost(const CommandCost &cmd_cost);
68 
73  inline void MultiplyCost(int factor)
74  {
75  this->cost *= factor;
76  }
77 
82  inline Money GetCost() const
83  {
84  return this->cost;
85  }
86 
92  {
93  return this->expense_type;
94  }
95 
100  void MakeError(StringID message)
101  {
102  assert(message != INVALID_STRING_ID);
103  this->success = false;
104  this->message = message;
105  }
106 
107  void UseTextRefStack(const GRFFile *grffile, uint num_registers);
108 
114  {
115  return this->textref_stack_grffile;
116  }
117 
122  uint GetTextRefStackSize() const
123  {
124  return this->textref_stack_size;
125  }
126 
131  const uint32 *GetTextRefStack() const
132  {
133  return textref_stack;
134  }
135 
141  {
142  if (this->success) return INVALID_STRING_ID;
143  return this->message;
144  }
145 
150  inline bool Succeeded() const
151  {
152  return this->success;
153  }
154 
159  inline bool Failed() const
160  {
161  return !this->success;
162  }
163 };
164 
175 enum Commands {
189 
192 
196 
204 
206 
208 
211 
213 
219 
223 
229 
231 
233 
236 
239 
242 
249 
252 
254 
256 
260 
270 
274 
278 
298 
300 
302 
305 
309 
311 
318 
327 
333 
335 
337 };
338 
345  DC_NONE = 0x000,
346  DC_EXEC = 0x001,
347  DC_AUTO = 0x002,
348  DC_QUERY_COST = 0x004,
349  DC_NO_WATER = 0x008,
352  DC_BANKRUPT = 0x040,
353  DC_AUTOREPLACE = 0x080,
355  DC_ALL_TILES = 0x200,
358 };
360 
361 
370 #define CMD_MSG(x) ((x) << 16)
371 
379  CMD_FLAGS_MASK = 0xFF00,
380  CMD_ID_MASK = 0x00FF,
381 };
382 
389  CMD_SERVER = 0x001,
390  CMD_SPECTATOR = 0x002,
391  CMD_OFFLINE = 0x004,
392  CMD_AUTO = 0x008,
393  CMD_ALL_TILES = 0x010,
394  CMD_NO_TEST = 0x020,
395  CMD_NO_WATER = 0x040,
396  CMD_CLIENT_ID = 0x080,
397  CMD_DEITY = 0x100,
398  CMD_STR_CTRL = 0x200,
399  CMD_NO_EST = 0x400,
400 };
402 
403 
414 
416 };
417 
424 };
425 
444 typedef CommandCost CommandProc(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text);
445 
452 struct Command {
454  const char *name;
457 };
458 
472 typedef void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd);
473 
479  uint32 p1;
480  uint32 p2;
481  uint32 cmd;
483  char text[32 * MAX_CHAR_LENGTH];
484 };
485 
486 #endif /* COMMAND_TYPE_H */
CommandType
Types of commands we have.
Definition: command_type.h:404
clear the order backup of a given user/tile
Definition: command_type.h:224
don&#39;t allow building on structures
Definition: command_type.h:347
do not change town rating
Definition: command_type.h:356
change the timetable for a vehicle
Definition: command_type.h:329
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
rename a depot
Definition: command_type.h:248
used in multiplayer to create a new companies etc.
Definition: command_type.h:280
set the DC_NO_WATER flag on this command
Definition: command_type.h:395
build a waypoint
Definition: command_type.h:193
do not only remove the object on the tile, but also clear any water left on it
Definition: command_type.h:357
No landscaping actions may be executed.
Definition: command_type.h:422
rename a sign
Definition: command_type.h:251
Invalid expense type.
Definition: economy_type.h:163
build a dock
Definition: command_type.h:207
rename a town
Definition: command_type.h:262
open/close an airport to incoming aircraft
Definition: command_type.h:334
set the vehicle on time feature (timetable)
Definition: command_type.h:330
rename a whole vehicle
Definition: command_type.h:243
build a complete road (not a "half" one)
Definition: command_type.h:199
create a new goal
Definition: command_type.h:282
set p2 with the ClientID of the sending client.
Definition: command_type.h:396
remove a complete road (not a "half" one)
Definition: command_type.h:200
plant a tree
Definition: command_type.h:212
static uint32 textref_stack[16]
Values to put on the TextRefStack for the error message.
Definition: command_type.h:31
remove signals along a track (by dragging)
Definition: command_type.h:304
change bank balance to charge costs or give money from a GS
Definition: command_type.h:276
change the server interval of a vehicle
Definition: command_type.h:230
terraform a tile
Definition: command_type.h:186
ExpensesType GetExpensesType() const
The expense type of the cost.
Definition: command_type.h:91
query cost only, don&#39;t build.
Definition: command_type.h:348
CommandType type
The type of command.
Definition: command_type.h:456
set the DC_AUTO flag on this command
Definition: command_type.h:392
no flag is set
Definition: command_type.h:345
uint32 p2
parameter p2.
Definition: command_type.h:480
autofill the timetable
Definition: command_type.h:331
change a company setting
Definition: command_type.h:308
CommandFlags
Command flags for the command table _command_proc_table.
Definition: command_type.h:388
set the livery for a group
Definition: command_type.h:326
buy a company which is bankrupt
Definition: command_type.h:259
add signals along a track (by dragging)
Definition: command_type.h:303
All actions may be executed.
Definition: command_type.h:423
demolish a tile
Definition: command_type.h:180
CommandCost(StringID msg)
Creates a command return value the is failed with the given message.
Definition: command_type.h:42
void UseTextRefStack(const GRFFile *grffile, uint num_registers)
Activate usage of the NewGRF TextRefStack for the error message.
Definition: command.cpp:797
update title of a story page
Definition: command_type.h:292
build a "half" road
Definition: command_type.h:201
build a rail station
Definition: command_type.h:182
do a action from the town detail window (like advertises or bribe)
Definition: command_type.h:263
Define a command with the flags which belongs to it.
Definition: command_type.h:452
const char * name
A human readable name for the procedure.
Definition: command_type.h:454
clone (and share) an order
Definition: command_type.h:272
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:82
update date of a story page
Definition: command_type.h:293
Common return value for all commands.
Definition: command_type.h:23
set the custom text of a town
Definition: command_type.h:267
void MultiplyCost(int factor)
Multiplies the cost of the command by the given factor.
Definition: command_type.h:73
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition: command_type.h:62
void MakeError(StringID message)
Makes this CommandCost behave like an error command.
Definition: command_type.h:100
skip an order to the next of specific one
Definition: command_type.h:226
const GRFFile * GetTextRefStackGRF() const
Returns the NewGRF providing the TextRefStack of the error message.
Definition: command_type.h:113
delete a group
Definition: command_type.h:320
when autoreplace/autorenew is in progress, this shall prevent truncating the amount of cargo in the v...
Definition: command_type.h:354
build an airport
Definition: command_type.h:205
replace/renew a vehicle while it is in a depot
Definition: command_type.h:315
company bankrupts, skip money check, skip vehicle on tile check in some cases
Definition: command_type.h:352
start or stop a vehicle
Definition: command_type.h:313
alter a group
Definition: command_type.h:321
Pausing/removing companies/server settings.
Definition: command_type.h:412
build a single rail track
Definition: command_type.h:178
hide or unhide a vehicle in the build vehicle and autoreplace GUIs
Definition: command_type.h:218
proceed a train to pass a red signal
Definition: command_type.h:221
add all other shared vehicles to a group which are missing
Definition: command_type.h:323
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
Definition: strings_type.h:18
void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Define a callback function for the client, after the command is finished.
Definition: command_type.h:472
decrease the loan from the bank
Definition: command_type.h:238
CommandPauseLevel
Different command pause levels.
Definition: command_type.h:419
remove all vehicles from a group
Definition: command_type.h:324
mask for all command flags
Definition: command_type.h:379
set the town growth rate
Definition: command_type.h:265
create a custom news message
Definition: command_type.h:281
Types related to the economy.
A cheat of some sorts.
Definition: command_type.h:413
remove a story page element
Definition: command_type.h:296
execute the command without sending it on the network
Definition: command_type.h:378
found a town
Definition: command_type.h:261
mask for the command ID
Definition: command_type.h:380
increase the loan from the bank
Definition: command_type.h:237
uint32 p1
parameter p1.
Definition: command_type.h:479
refit the cargo space of a vehicle
Definition: command_type.h:216
remove a goal
Definition: command_type.h:283
StringID GetErrorMessage() const
Returns the error message of a command.
Definition: command_type.h:140
Construction, modification (incl. refit) and destruction of vehicles.
Definition: command_type.h:406
Structure for buffering the build command when selecting a station to join.
Definition: command_type.h:477
DoCommandFlag
List of flags for a command.
Definition: command_type.h:344
build a tunnel
Definition: command_type.h:188
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:150
the command may be executed by COMPANY_DEITY
Definition: command_type.h:397
build a vehicle
Definition: command_type.h:214
const GRFFile * textref_stack_grffile
NewGRF providing the TextRefStack content.
Definition: command_type.h:28
remove a story page
Definition: command_type.h:295
CommandCost(ExpensesType ex_t, const Money &cst)
Creates a command return value with the given start cost and expense type.
Definition: command_type.h:55
ExpensesType expense_type
the type of expence as shown on the finances view
Definition: command_type.h:24
set the manager&#39;s face of the company
Definition: command_type.h:234
insert a new order
Definition: command_type.h:228
the command&#39;s output may differ between test and execute due to town rating changes etc...
Definition: command_type.h:394
delete a town
Definition: command_type.h:269
set the date that a timetable should start
Definition: command_type.h:332
show a story page
Definition: command_type.h:294
StringID message
Warning message for when success is unset.
Definition: command_type.h:26
expand a town
Definition: command_type.h:268
const uint32 * GetTextRefStack() const
Returns a pointer to the values for the TextRefStack of the error message.
Definition: command_type.h:131
change the company name
Definition: command_type.h:245
don&#39;t allow building on water
Definition: command_type.h:349
set the colour of the company
Definition: command_type.h:235
CommandCost(ExpensesType ex_t)
Creates a command cost with given expense type and start cost of 0.
Definition: command_type.h:48
uint textref_stack_size
Number of uint32 values to put on the TextRefStack for the error message.
Definition: command_type.h:29
Renaming stuff, changing company colours, placing signs, etc.
Definition: command_type.h:410
set the goal of a cargo for a town
Definition: command_type.h:264
place a sign
Definition: command_type.h:250
give money to another company
Definition: command_type.h:306
Construction and destruction of objects on the map.
Definition: command_type.h:405
do the money cheat
Definition: command_type.h:275
the command can only be initiated by the server
Definition: command_type.h:389
build a road depot
Definition: command_type.h:202
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
the command&#39;s string may contain control strings
Definition: command_type.h:398
bool Failed() const
Did this command fail?
Definition: command_type.h:159
rename a waypoint
Definition: command_type.h:194
Magic end marker.
Definition: command_type.h:415
update a story page element
Definition: command_type.h:291
build a signal
Definition: command_type.h:184
force the autoreplace to take action in a given depot
Definition: command_type.h:317
No construction actions may be executed.
Definition: command_type.h:421
the command may be initiated by a spectator
Definition: command_type.h:390
allow this command also on MP_VOID tiles
Definition: command_type.h:355
autoreplace/autorenew is in progress, this shall disable vehicle limits when building, and ignore certain restrictions when undoing things (like vehicle attach callback)
Definition: command_type.h:353
CommandCallback * callback
any callback function executed upon successful completion of the command.
Definition: command_type.h:482
create a new story page
Definition: command_type.h:289
convert a rail type
Definition: command_type.h:191
Management of money, i.e. loans and shares.
Definition: command_type.h:407
update goal progress text of a goal
Definition: command_type.h:285
confirm the preview of an engine
Definition: command_type.h:240
change a setting
Definition: command_type.h:307
execute the given command
Definition: command_type.h:346
uint GetTextRefStackSize() const
Returns the number of uint32 values for the TextRefStack of the error message.
Definition: command_type.h:122
build a road stop
Definition: command_type.h:197
add a vehicle to a group
Definition: command_type.h:322
sell a vehicle
Definition: command_type.h:215
set rating of a company in a town
Definition: command_type.h:266
CommandProc * proc
The procedure to actually executing.
Definition: command_type.h:453
Must ALWAYS be on the end of this list!! (period)
Definition: command_type.h:336
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
CommandFlags flags
The (command) flags to that apply to this command.
Definition: command_type.h:455
Modifications to route management (orders, groups, etc).
Definition: command_type.h:409
sell a share from a company
Definition: command_type.h:258
create a new story page element
Definition: command_type.h:290
turn a train around
Definition: command_type.h:222
change the president name
Definition: command_type.h:246
FlaggedCommands
Defines some flags.
Definition: command_type.h:377
change the refit information of an order (for "goto depot" )
Definition: command_type.h:271
build a canal
Definition: command_type.h:277
ask a goal related question
Definition: command_type.h:287
CommandCost CommandProc(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Defines the callback type for all command handler functions.
Definition: command_type.h:444
clear an area
Definition: command_type.h:273
create a new group
Definition: command_type.h:319
sell all vehicles which are in a given depot
Definition: command_type.h:316
Stopping, starting, sending to depot, turning around, replace orders etc.
Definition: command_type.h:408
remove a single rail track
Definition: command_type.h:179
set the autoreplace-protection for a group
Definition: command_type.h:325
clone a vehicle
Definition: command_type.h:312
build a buoy
Definition: command_type.h:210
rename a engine (in the engine list)
Definition: command_type.h:244
TileIndex tile
tile command being executed on.
Definition: command_type.h:478
build a train depot
Definition: command_type.h:183
rename a station
Definition: command_type.h:247
start/stop all vehicles (in a depot)
Definition: command_type.h:314
create a new subsidy
Definition: command_type.h:279
Types related to strings.
build a bridge
Definition: command_type.h:181
bool success
Whether the comment went fine up to this moment.
Definition: command_type.h:27
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
the command cannot be executed in a multiplayer game; single-player only
Definition: command_type.h:391
scroll main viewport of players
Definition: command_type.h:297
Commands
List of commands.
Definition: command_type.h:175
remove a signal
Definition: command_type.h:185
don&#39;t allow overlap of rails (used in buildrail)
Definition: command_type.h:350
remove a (rectangle of) tiles from a rail station
Definition: command_type.h:190
Changing settings related to a company.
Definition: command_type.h:411
update goal text of a goal
Definition: command_type.h:284
remove a rail track
Definition: command_type.h:177
answer(s) to CMD_GOAL_QUESTION
Definition: command_type.h:288
send a vehicle to a depot
Definition: command_type.h:217
buy a share from a company
Definition: command_type.h:257
No user actions may be executed.
Definition: command_type.h:420
build a ship depot
Definition: command_type.h:209
CommandCost()
Creates a command cost return with no cost and no error.
Definition: command_type.h:37
Types related to tiles.
town rating does not disallow you from building
Definition: command_type.h:351
move a rail vehicle (in the depot)
Definition: command_type.h:220
the command is never estimated.
Definition: command_type.h:399
set an autoreplace entry
Definition: command_type.h:310
move an order
Definition: command_type.h:328
ExpensesType
Types of expenses.
Definition: economy_type.h:148
Money cost
The cost of this action.
Definition: command_type.h:25
remove a (rectangle of) tiles from a rail waypoint
Definition: command_type.h:195
uint32 cmd
command being executed.
Definition: command_type.h:481
remove a road stop
Definition: command_type.h:198
convert a road type
Definition: command_type.h:203
level land
Definition: command_type.h:299
modify an order (like set full-load)
Definition: command_type.h:225
allow this command also on MP_VOID tiles
Definition: command_type.h:393
build a new industry
Definition: command_type.h:232
turn a road vehicle around
Definition: command_type.h:253
update goal completed status of a goal
Definition: command_type.h:286
delete an order
Definition: command_type.h:227
build a lock
Definition: command_type.h:301
control availability of the engine for companies
Definition: command_type.h:241
build an object
Definition: command_type.h:187
build a rail track
Definition: command_type.h:176
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:105
pause the game
Definition: command_type.h:255