OpenTTD
command_type.h
Go to the documentation of this file.
1 /* $Id$ */
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 
236 
239 
242 
244 
251 
254 
256 
258 
262 
271 
275 
279 
299 
301 
304 
308 
310 
317 
325 
331 
333 
335 };
336 
343  DC_NONE = 0x000,
344  DC_EXEC = 0x001,
345  DC_AUTO = 0x002,
346  DC_QUERY_COST = 0x004,
347  DC_NO_WATER = 0x008,
350  DC_BANKRUPT = 0x040,
351  DC_AUTOREPLACE = 0x080,
353  DC_ALL_TILES = 0x200,
356 };
358 
359 
368 #define CMD_MSG(x) ((x) << 16)
369 
377  CMD_FLAGS_MASK = 0xFF00,
378  CMD_ID_MASK = 0x00FF,
379 };
380 
387  CMD_SERVER = 0x001,
388  CMD_SPECTATOR = 0x002,
389  CMD_OFFLINE = 0x004,
390  CMD_AUTO = 0x008,
391  CMD_ALL_TILES = 0x010,
392  CMD_NO_TEST = 0x020,
393  CMD_NO_WATER = 0x040,
394  CMD_CLIENT_ID = 0x080,
395  CMD_DEITY = 0x100,
396  CMD_STR_CTRL = 0x200,
397 };
399 
400 
411 
413 };
414 
421 };
422 
441 typedef CommandCost CommandProc(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text);
442 
449 struct Command {
451  const char *name;
454 };
455 
469 typedef void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2);
470 
476  uint32 p1;
477  uint32 p2;
478  uint32 cmd;
480  char text[32 * MAX_CHAR_LENGTH];
481 };
482 
483 #endif /* COMMAND_TYPE_H */