OpenTTD
command_type.h
Go to the documentation of this file.
1 /* $Id: command_type.h 26802 2014-09-07 16:12:58Z alberth $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #ifndef COMMAND_TYPE_H
13 #define COMMAND_TYPE_H
14 
15 #include "economy_type.h"
16 #include "strings_type.h"
17 #include "tile_type.h"
18 
19 struct GRFFile;
20 
25 class CommandCost {
29  bool success;
32 
33  static uint32 textref_stack[16];
34 
35 public:
40 
45 
51 
58 
59 
64  inline void AddCost(const Money &cost)
65  {
66  this->cost += cost;
67  }
68 
69  void AddCost(const CommandCost &cmd_cost);
70 
75  inline void MultiplyCost(int factor)
76  {
77  this->cost *= factor;
78  }
79 
84  inline Money GetCost() const
85  {
86  return this->cost;
87  }
88 
94  {
95  return this->expense_type;
96  }
97 
103  {
104  assert(message != INVALID_STRING_ID);
105  this->success = false;
106  this->message = message;
107  }
108 
109  void UseTextRefStack(const GRFFile *grffile, uint num_registers);
110 
116  {
117  return this->textref_stack_grffile;
118  }
119 
124  uint GetTextRefStackSize() const
125  {
126  return this->textref_stack_size;
127  }
128 
133  const uint32 *GetTextRefStack() const
134  {
135  return textref_stack;
136  }
137 
143  {
144  if (this->success) return INVALID_STRING_ID;
145  return this->message;
146  }
147 
152  inline bool Succeeded() const
153  {
154  return this->success;
155  }
156 
161  inline bool Failed() const
162  {
163  return !this->success;
164  }
165 };
166 
177 enum Commands {
191 
194 
198 
205 
207 
209 
212 
214 
220 
224 
230 
232 
234 
237 
240 
242 
249 
252 
254 
256 
260 
269 
273 
277 
297 
299 
302 
306 
308 
315 
323 
329 
331 
333 };
334 
341  DC_NONE = 0x000,
342  DC_EXEC = 0x001,
343  DC_AUTO = 0x002,
344  DC_QUERY_COST = 0x004,
345  DC_NO_WATER = 0x008,
348  DC_BANKRUPT = 0x040,
349  DC_AUTOREPLACE = 0x080,
351  DC_ALL_TILES = 0x200,
354 };
356 
357 
366 #define CMD_MSG(x) ((x) << 16)
367 
375  CMD_FLAGS_MASK = 0xFF00,
376  CMD_ID_MASK = 0x00FF,
377 };
378 
385  CMD_SERVER = 0x001,
386  CMD_SPECTATOR = 0x002,
387  CMD_OFFLINE = 0x004,
388  CMD_AUTO = 0x008,
389  CMD_ALL_TILES = 0x010,
390  CMD_NO_TEST = 0x020,
391  CMD_NO_WATER = 0x040,
392  CMD_CLIENT_ID = 0x080,
393  CMD_DEITY = 0x100,
394  CMD_STR_CTRL = 0x200,
395 };
397 
398 
409 
411 };
412 
419 };
420 
439 typedef CommandCost CommandProc(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text);
440 
447 struct Command {
449  const char *name;
452 };
453 
467 typedef void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2);
468 
474  uint32 p1;
475  uint32 p2;
476  uint32 cmd;
478  char text[32 * MAX_CHAR_LENGTH];
479 };
480 
481 #endif /* COMMAND_TYPE_H */