OpenTTD: src/command_type.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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 {
26 ExpensesType expense_type;
27 Money cost;
28 StringID message;
29 bool success;
30 const GRFFile *textref_stack_grffile;
31 uint textref_stack_size;
32
33 static uint32 textref_stack[16];
34
35 public:
39 CommandCost() : expense_type(INVALID_EXPENSES), cost(0), message(INVALID_STRING_ID), success(true), textref_stack_grffile(NULL), textref_stack_size(0) {}
40
44 explicit CommandCost(StringID msg) : expense_type(INVALID_EXPENSES), cost(0), message(msg), success(false), textref_stack_grffile(NULL), textref_stack_size(0) {}
45
50 explicit CommandCost(ExpensesType ex_t) : expense_type(ex_t), cost(0), message(INVALID_STRING_ID), success(true), textref_stack_grffile(NULL), textref_stack_size(0) {}
51
57 CommandCost(ExpensesType ex_t, const Money &cst) : expense_type(ex_t), cost(cst), message(INVALID_STRING_ID), success(true), textref_stack_grffile(NULL), textref_stack_size(0) {}
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
93 inline ExpensesType GetExpensesType() const
94 {
95 return this->expense_type;
96 }
97
102 void MakeError(StringID message)
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
115 const GRFFile *GetTextRefStackGRF() const
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
142 StringID GetErrorMessage() const
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 {
178 CMD_BUILD_RAILROAD_TRACK,
179 CMD_REMOVE_RAILROAD_TRACK,
180 CMD_BUILD_SINGLE_RAIL,
181 CMD_REMOVE_SINGLE_RAIL,
182 CMD_LANDSCAPE_CLEAR,
183 CMD_BUILD_BRIDGE,
184 CMD_BUILD_RAIL_STATION,
185 CMD_BUILD_TRAIN_DEPOT,
186 CMD_BUILD_SIGNALS,
187 CMD_REMOVE_SIGNALS,
188 CMD_TERRAFORM_LAND,
189 CMD_BUILD_OBJECT,
190 CMD_BUILD_TUNNEL,
191
192 CMD_REMOVE_FROM_RAIL_STATION,
193 CMD_CONVERT_RAIL,
194
195 CMD_BUILD_RAIL_WAYPOINT,
196 CMD_RENAME_WAYPOINT,
197 CMD_REMOVE_FROM_RAIL_WAYPOINT,
198
199 CMD_BUILD_ROAD_STOP,
200 CMD_REMOVE_ROAD_STOP,
201 CMD_BUILD_LONG_ROAD,
202 CMD_REMOVE_LONG_ROAD,
203 CMD_BUILD_ROAD,
204 CMD_BUILD_ROAD_DEPOT,
205
206 CMD_BUILD_AIRPORT,
207
208 CMD_BUILD_DOCK,
209
210 CMD_BUILD_SHIP_DEPOT,
211 CMD_BUILD_BUOY,
212
213 CMD_PLANT_TREE,
214
215 CMD_BUILD_VEHICLE,
216 CMD_SELL_VEHICLE,
217 CMD_REFIT_VEHICLE,
218 CMD_SEND_VEHICLE_TO_DEPOT,
219 CMD_SET_VEHICLE_VISIBILITY,
220
221 CMD_MOVE_RAIL_VEHICLE,
222 CMD_FORCE_TRAIN_PROCEED,
223 CMD_REVERSE_TRAIN_DIRECTION,
224
225 CMD_CLEAR_ORDER_BACKUP,
226 CMD_MODIFY_ORDER,
227 CMD_SKIP_TO_ORDER,
228 CMD_DELETE_ORDER,
229 CMD_INSERT_ORDER,
230
231 CMD_CHANGE_SERVICE_INT,
232
233 CMD_BUILD_INDUSTRY,
234
235 CMD_SET_COMPANY_MANAGER_FACE,
236 CMD_SET_COMPANY_COLOUR,
237
238 CMD_INCREASE_LOAN,
239 CMD_DECREASE_LOAN,
240
241 CMD_WANT_ENGINE_PREVIEW,
242
243 CMD_RENAME_VEHICLE,
244 CMD_RENAME_ENGINE,
245 CMD_RENAME_COMPANY,
246 CMD_RENAME_PRESIDENT,
247 CMD_RENAME_STATION,
248 CMD_RENAME_DEPOT,
249
250 CMD_PLACE_SIGN,
251 CMD_RENAME_SIGN,
252
253 CMD_TURN_ROADVEH,
254
255 CMD_PAUSE,
256
257 CMD_BUY_SHARE_IN_COMPANY,
258 CMD_SELL_SHARE_IN_COMPANY,
259 CMD_BUY_COMPANY,
260
261 CMD_FOUND_TOWN,
262 CMD_RENAME_TOWN,
263 CMD_DO_TOWN_ACTION,
264 CMD_TOWN_CARGO_GOAL,
265 CMD_TOWN_GROWTH_RATE,
266 CMD_TOWN_SET_TEXT,
267 CMD_EXPAND_TOWN,
268 CMD_DELETE_TOWN,
269
270 CMD_ORDER_REFIT,
271 CMD_CLONE_ORDER,
272 CMD_CLEAR_AREA,
273
274 CMD_MONEY_CHEAT,
275 CMD_CHANGE_BANK_BALANCE,
276 CMD_BUILD_CANAL,
277
278 CMD_CREATE_SUBSIDY,
279 CMD_COMPANY_CTRL,
280 CMD_CUSTOM_NEWS_ITEM,
281 CMD_CREATE_GOAL,
282 CMD_REMOVE_GOAL,
283 CMD_SET_GOAL_TEXT,
284 CMD_SET_GOAL_PROGRESS,
285 CMD_SET_GOAL_COMPLETED,
286 CMD_GOAL_QUESTION,
287 CMD_GOAL_QUESTION_ANSWER,
288 CMD_CREATE_STORY_PAGE,
289 CMD_CREATE_STORY_PAGE_ELEMENT,
290 CMD_UPDATE_STORY_PAGE_ELEMENT,
291 CMD_SET_STORY_PAGE_TITLE,
292 CMD_SET_STORY_PAGE_DATE,
293 CMD_SHOW_STORY_PAGE,
294 CMD_REMOVE_STORY_PAGE,
295 CMD_REMOVE_STORY_PAGE_ELEMENT,
296 CMD_LEVEL_LAND,
297
298 CMD_BUILD_LOCK,
299
300 CMD_BUILD_SIGNAL_TRACK,
301 CMD_REMOVE_SIGNAL_TRACK,
302
303 CMD_GIVE_MONEY,
304 CMD_CHANGE_SETTING,
305 CMD_CHANGE_COMPANY_SETTING,
306
307 CMD_SET_AUTOREPLACE,
308
309 CMD_CLONE_VEHICLE,
310 CMD_START_STOP_VEHICLE,
311 CMD_MASS_START_STOP,
312 CMD_AUTOREPLACE_VEHICLE,
313 CMD_DEPOT_SELL_ALL_VEHICLES,
314 CMD_DEPOT_MASS_AUTOREPLACE,
315
316 CMD_CREATE_GROUP,
317 CMD_DELETE_GROUP,
318 CMD_ALTER_GROUP,
319 CMD_ADD_VEHICLE_GROUP,
320 CMD_ADD_SHARED_VEHICLE_GROUP,
321 CMD_REMOVE_ALL_VEHICLES_GROUP,
322 CMD_SET_GROUP_REPLACE_PROTECTION,
323
324 CMD_MOVE_ORDER,
325 CMD_CHANGE_TIMETABLE,
326 CMD_SET_VEHICLE_ON_TIME,
327 CMD_AUTOFILL_TIMETABLE,
328 CMD_SET_TIMETABLE_START,
329
330 CMD_OPEN_CLOSE_AIRPORT,
331
332 CMD_END,
333 };
334
340 enum DoCommandFlag {
341 DC_NONE = 0x000,
342 DC_EXEC = 0x001,
343 DC_AUTO = 0x002,
344 DC_QUERY_COST = 0x004,
345 DC_NO_WATER = 0x008,
346 DC_NO_RAIL_OVERLAP = 0x010,
347 DC_NO_TEST_TOWN_RATING = 0x020,
348 DC_BANKRUPT = 0x040,
349 DC_AUTOREPLACE = 0x080,
350 DC_NO_CARGO_CAP_CHECK = 0x100,
351 DC_ALL_TILES = 0x200,
352 DC_NO_MODIFY_TOWN_RATING = 0x400,
353 DC_FORCE_CLEAR_TILE = 0x800,
354 };
355 DECLARE_ENUM_AS_BIT_SET(DoCommandFlag)
356
357
366 #define CMD_MSG(x) ((x) << 16)
367
373 enum FlaggedCommands {
374 CMD_NETWORK_COMMAND = 0x0100,
375 CMD_FLAGS_MASK = 0xFF00,
376 CMD_ID_MASK = 0x00FF,
377 };
378
384 enum CommandFlags {
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 };
396 DECLARE_ENUM_AS_BIT_SET(CommandFlags)
397
398
399 enum CommandType {
400 CMDT_LANDSCAPE_CONSTRUCTION,
401 CMDT_VEHICLE_CONSTRUCTION,
402 CMDT_MONEY_MANAGEMENT,
403 CMDT_VEHICLE_MANAGEMENT,
404 CMDT_ROUTE_MANAGEMENT,
405 CMDT_OTHER_MANAGEMENT,
406 CMDT_COMPANY_SETTING,
407 CMDT_SERVER_SETTING,
408 CMDT_CHEAT,
409
410 CMDT_END,
411 };
412
414 enum CommandPauseLevel {
415 CMDPL_NO_ACTIONS,
416 CMDPL_NO_CONSTRUCTION,
417 CMDPL_NO_LANDSCAPING,
418 CMDPL_ALL_ACTIONS,
419 };
420
439 typedef CommandCost CommandProc(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text);
440
447 struct Command {
448 CommandProc *proc;
449 const char *name;
450 CommandFlags flags;
451 CommandType type;
452 };
453
467 typedef void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2);
468
472 struct CommandContainer {
473 TileIndex tile;
474 uint32 p1;
475 uint32 p2;
476 uint32 cmd;
477 CommandCallback *callback;
478 char text[32 * MAX_CHAR_LENGTH];
479 };
480
481 #endif /* COMMAND_TYPE_H */