OpenTTD
command.cpp
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 #include "stdafx.h"
13 #include "landscape.h"
14 #include "error.h"
15 #include "gui.h"
16 #include "command_func.h"
17 #include "network/network_type.h"
18 #include "network/network.h"
19 #include "genworld.h"
20 #include "strings_func.h"
21 #include "texteff.hpp"
22 #include "town.h"
23 #include "date_func.h"
24 #include "company_func.h"
25 #include "company_base.h"
26 #include "signal_func.h"
27 #include "core/backup_type.hpp"
28 #include "object_base.h"
29 
30 #include "table/strings.h"
31 
32 #include "safeguards.h"
33 
38 
40 
42 
46 
49 
51 
53 CommandProc CmdSellLandArea;
54 
56 
61 
64 
68 
70 
72 
74 
76 
78 
80 
82 
88 
91 
98 
100 
103 
106 
108 
111 
114 
117 
120 
122 
124 
128 
137 
140 
143 
145 
151 
171 
173 
176 
178 
185 
194 
200 
202 
203 #define DEF_CMD(proc, flags, type) {proc, #proc, (CommandFlags)flags, type}
204 
212 static const Command _command_proc_table[] = {
213  DEF_CMD(CmdBuildRailroadTrack, CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_RAILROAD_TRACK
214  DEF_CMD(CmdRemoveRailroadTrack, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_REMOVE_RAILROAD_TRACK
215  DEF_CMD(CmdBuildSingleRail, CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_SINGLE_RAIL
216  DEF_CMD(CmdRemoveSingleRail, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_REMOVE_SINGLE_RAIL
217  DEF_CMD(CmdLandscapeClear, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_LANDSCAPE_CLEAR
218  DEF_CMD(CmdBuildBridge, CMD_DEITY | CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_BRIDGE
219  DEF_CMD(CmdBuildRailStation, CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_RAIL_STATION
220  DEF_CMD(CmdBuildTrainDepot, CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_TRAIN_DEPOT
221  DEF_CMD(CmdBuildSingleSignal, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_SIGNALS
222  DEF_CMD(CmdRemoveSingleSignal, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_REMOVE_SIGNALS
223  DEF_CMD(CmdTerraformLand, CMD_ALL_TILES | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_TERRAFORM_LAND
224  DEF_CMD(CmdBuildObject, CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_OBJECT
225  DEF_CMD(CmdBuildTunnel, CMD_DEITY | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_TUNNEL
226  DEF_CMD(CmdRemoveFromRailStation, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_REMOVE_FROM_RAIL_STATION
227  DEF_CMD(CmdConvertRail, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_CONVERT_RAILD
228  DEF_CMD(CmdBuildRailWaypoint, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_RAIL_WAYPOINT
229  DEF_CMD(CmdRenameWaypoint, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_WAYPOINT
230  DEF_CMD(CmdRemoveFromRailWaypoint, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_REMOVE_FROM_RAIL_WAYPOINT
231 
232  DEF_CMD(CmdBuildRoadStop, CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_ROAD_STOP
233  DEF_CMD(CmdRemoveRoadStop, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_REMOVE_ROAD_STOP
234  DEF_CMD(CmdBuildLongRoad,CMD_DEITY | CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_LONG_ROAD
235  DEF_CMD(CmdRemoveLongRoad, CMD_NO_TEST | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_REMOVE_LONG_ROAD; towns may disallow removing road bits (as they are connected) in test, but in exec they're removed and thus removing is allowed.
237  DEF_CMD(CmdBuildRoadDepot, CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_ROAD_DEPOT
238 
239  DEF_CMD(CmdBuildAirport, CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_AIRPORT
240  DEF_CMD(CmdBuildDock, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_DOCK
241  DEF_CMD(CmdBuildShipDepot, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_SHIP_DEPOT
242  DEF_CMD(CmdBuildBuoy, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_BUOY
243  DEF_CMD(CmdPlantTree, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_PLANT_TREE
244 
245  DEF_CMD(CmdBuildVehicle, CMD_CLIENT_ID, CMDT_VEHICLE_CONSTRUCTION ), // CMD_BUILD_VEHICLE
246  DEF_CMD(CmdSellVehicle, CMD_CLIENT_ID, CMDT_VEHICLE_CONSTRUCTION ), // CMD_SELL_VEHICLE
247  DEF_CMD(CmdRefitVehicle, 0, CMDT_VEHICLE_CONSTRUCTION ), // CMD_REFIT_VEHICLE
248  DEF_CMD(CmdSendVehicleToDepot, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_SEND_VEHICLE_TO_DEPOT
249  DEF_CMD(CmdSetVehicleVisibility, 0, CMDT_COMPANY_SETTING ), // CMD_SET_VEHICLE_VISIBILITY
250 
251  DEF_CMD(CmdMoveRailVehicle, 0, CMDT_VEHICLE_CONSTRUCTION ), // CMD_MOVE_RAIL_VEHICLE
252  DEF_CMD(CmdForceTrainProceed, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_FORCE_TRAIN_PROCEED
253  DEF_CMD(CmdReverseTrainDirection, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_REVERSE_TRAIN_DIRECTION
254 
255  DEF_CMD(CmdClearOrderBackup, CMD_CLIENT_ID, CMDT_SERVER_SETTING ), // CMD_CLEAR_ORDER_BACKUP
256  DEF_CMD(CmdModifyOrder, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_MODIFY_ORDER
257  DEF_CMD(CmdSkipToOrder, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_SKIP_TO_ORDER
258  DEF_CMD(CmdDeleteOrder, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_DELETE_ORDER
259  DEF_CMD(CmdInsertOrder, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_INSERT_ORDER
260 
261  DEF_CMD(CmdChangeServiceInt, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_CHANGE_SERVICE_INT
262 
263  DEF_CMD(CmdBuildIndustry, CMD_DEITY, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_INDUSTRY
264  DEF_CMD(CmdSetCompanyManagerFace, 0, CMDT_OTHER_MANAGEMENT ), // CMD_SET_COMPANY_MANAGER_FACE
265  DEF_CMD(CmdSetCompanyColour, 0, CMDT_OTHER_MANAGEMENT ), // CMD_SET_COMPANY_COLOUR
266 
267  DEF_CMD(CmdIncreaseLoan, 0, CMDT_MONEY_MANAGEMENT ), // CMD_INCREASE_LOAN
268  DEF_CMD(CmdDecreaseLoan, 0, CMDT_MONEY_MANAGEMENT ), // CMD_DECREASE_LOAN
269 
270  DEF_CMD(CmdWantEnginePreview, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_WANT_ENGINE_PREVIEW
271 
272  DEF_CMD(CmdRenameVehicle, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_VEHICLE
273  DEF_CMD(CmdRenameEngine, CMD_SERVER, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_ENGINE
274 
275  DEF_CMD(CmdRenameCompany, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_COMPANY
276  DEF_CMD(CmdRenamePresident, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_PRESIDENT
277 
278  DEF_CMD(CmdRenameStation, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_STATION
279  DEF_CMD(CmdRenameDepot, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_DEPOT
280 
281  DEF_CMD(CmdPlaceSign, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_PLACE_SIGN
282  DEF_CMD(CmdRenameSign, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_SIGN
283 
284  DEF_CMD(CmdTurnRoadVeh, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_TURN_ROADVEH
285 
286  DEF_CMD(CmdPause, CMD_SERVER, CMDT_SERVER_SETTING ), // CMD_PAUSE
287 
288  DEF_CMD(CmdBuyShareInCompany, 0, CMDT_MONEY_MANAGEMENT ), // CMD_BUY_SHARE_IN_COMPANY
289  DEF_CMD(CmdSellShareInCompany, 0, CMDT_MONEY_MANAGEMENT ), // CMD_SELL_SHARE_IN_COMPANY
290  DEF_CMD(CmdBuyCompany, 0, CMDT_MONEY_MANAGEMENT ), // CMD_BUY_COMANY
291 
292  DEF_CMD(CmdFoundTown, CMD_DEITY | CMD_NO_TEST, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_FOUND_TOWN; founding random town can fail only in exec run
293  DEF_CMD(CmdRenameTown, CMD_DEITY | CMD_SERVER, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_TOWN
294  DEF_CMD(CmdDoTownAction, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_DO_TOWN_ACTION
295  DEF_CMD(CmdTownCargoGoal, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_TOWN_CARGO_GOAL
296  DEF_CMD(CmdTownGrowthRate, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_TOWN_GROWTH_RATE
297  DEF_CMD(CmdTownSetText, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_TOWN_SET_TEXT
298  DEF_CMD(CmdExpandTown, CMD_DEITY, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_EXPAND_TOWN
299  DEF_CMD(CmdDeleteTown, CMD_OFFLINE, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_DELETE_TOWN
300 
301  DEF_CMD(CmdOrderRefit, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_ORDER_REFIT
302  DEF_CMD(CmdCloneOrder, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_CLONE_ORDER
303 
304  DEF_CMD(CmdClearArea, CMD_NO_TEST, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_CLEAR_AREA; destroying multi-tile houses makes town rating differ between test and execution
305 
306  DEF_CMD(CmdMoneyCheat, CMD_OFFLINE, CMDT_CHEAT ), // CMD_MONEY_CHEAT
307  DEF_CMD(CmdChangeBankBalance, CMD_DEITY, CMDT_MONEY_MANAGEMENT ), // CMD_CHANGE_BANK_BALANCE
308  DEF_CMD(CmdBuildCanal, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_CANAL
309  DEF_CMD(CmdCreateSubsidy, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_CREATE_SUBSIDY
310  DEF_CMD(CmdCompanyCtrl, CMD_SPECTATOR | CMD_CLIENT_ID, CMDT_SERVER_SETTING ), // CMD_COMPANY_CTRL
311  DEF_CMD(CmdCustomNewsItem, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_CUSTOM_NEWS_ITEM
312  DEF_CMD(CmdCreateGoal, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_CREATE_GOAL
313  DEF_CMD(CmdRemoveGoal, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_REMOVE_GOAL
314  DEF_CMD(CmdSetGoalText, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_SET_GOAL_TEXT
315  DEF_CMD(CmdSetGoalProgress, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_SET_GOAL_PROGRESS
316  DEF_CMD(CmdSetGoalCompleted, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_SET_GOAL_COMPLETED
317  DEF_CMD(CmdGoalQuestion, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_GOAL_QUESTION
318  DEF_CMD(CmdGoalQuestionAnswer, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_GOAL_QUESTION_ANSWER
319  DEF_CMD(CmdCreateStoryPage, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_CREATE_STORY_PAGE
320  DEF_CMD(CmdCreateStoryPageElement, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_CREATE_STORY_PAGE_ELEMENT
321  DEF_CMD(CmdUpdateStoryPageElement, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_UPDATE_STORY_PAGE_ELEMENT
322  DEF_CMD(CmdSetStoryPageTitle, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_SET_STORY_PAGE_TITLE
323  DEF_CMD(CmdSetStoryPageDate, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_SET_STORY_PAGE_DATE
324  DEF_CMD(CmdShowStoryPage, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_SHOW_STORY_PAGE
325  DEF_CMD(CmdRemoveStoryPage, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_REMOVE_STORY_PAGE
326  DEF_CMD(CmdRemoveStoryPageElement, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_REMOVE_STORY_ELEMENT_PAGE
327  DEF_CMD(CmdScrollViewport, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_SCROLL_VIEWPORT
328 
329  DEF_CMD(CmdLevelLand, CMD_ALL_TILES | CMD_NO_TEST | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_LEVEL_LAND; test run might clear tiles multiple times, in execution that only happens once
330 
331  DEF_CMD(CmdBuildLock, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_LOCK
332 
333  DEF_CMD(CmdBuildSignalTrack, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_SIGNAL_TRACK
334  DEF_CMD(CmdRemoveSignalTrack, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_REMOVE_SIGNAL_TRACK
335 
336  DEF_CMD(CmdGiveMoney, 0, CMDT_MONEY_MANAGEMENT ), // CMD_GIVE_MONEY
337  DEF_CMD(CmdChangeSetting, CMD_SERVER, CMDT_SERVER_SETTING ), // CMD_CHANGE_SETTING
338  DEF_CMD(CmdChangeCompanySetting, 0, CMDT_COMPANY_SETTING ), // CMD_CHANGE_COMPANY_SETTING
339  DEF_CMD(CmdSetAutoReplace, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_SET_AUTOREPLACE
340  DEF_CMD(CmdCloneVehicle, CMD_NO_TEST, CMDT_VEHICLE_CONSTRUCTION ), // CMD_CLONE_VEHICLE; NewGRF callbacks influence building and refitting making it impossible to correctly estimate the cost
341  DEF_CMD(CmdStartStopVehicle, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_START_STOP_VEHICLE
342  DEF_CMD(CmdMassStartStopVehicle, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_MASS_START_STOP
343  DEF_CMD(CmdAutoreplaceVehicle, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_AUTOREPLACE_VEHICLE
344  DEF_CMD(CmdDepotSellAllVehicles, 0, CMDT_VEHICLE_CONSTRUCTION ), // CMD_DEPOT_SELL_ALL_VEHICLES
345  DEF_CMD(CmdDepotMassAutoReplace, 0, CMDT_VEHICLE_CONSTRUCTION ), // CMD_DEPOT_MASS_AUTOREPLACE
346  DEF_CMD(CmdCreateGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_CREATE_GROUP
347  DEF_CMD(CmdDeleteGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_DELETE_GROUP
348  DEF_CMD(CmdAlterGroup, 0, CMDT_OTHER_MANAGEMENT ), // CMD_ALTER_GROUP
349  DEF_CMD(CmdAddVehicleGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_ADD_VEHICLE_GROUP
350  DEF_CMD(CmdAddSharedVehicleGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_ADD_SHARE_VEHICLE_GROUP
351  DEF_CMD(CmdRemoveAllVehiclesGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_REMOVE_ALL_VEHICLES_GROUP
352  DEF_CMD(CmdSetGroupReplaceProtection, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_SET_GROUP_REPLACE_PROTECTION
353  DEF_CMD(CmdSetGroupLivery, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_SET_GROUP_LIVERY
354  DEF_CMD(CmdMoveOrder, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_MOVE_ORDER
355  DEF_CMD(CmdChangeTimetable, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_CHANGE_TIMETABLE
356  DEF_CMD(CmdSetVehicleOnTime, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_SET_VEHICLE_ON_TIME
357  DEF_CMD(CmdAutofillTimetable, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_AUTOFILL_TIMETABLE
358  DEF_CMD(CmdSetTimetableStart, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_SET_TIMETABLE_START
359 
360  DEF_CMD(CmdOpenCloseAirport, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_OPEN_CLOSE_AIRPORT
361 };
362 
369 bool IsValidCommand(uint32 cmd)
370 {
371  cmd &= CMD_ID_MASK;
372 
373  return cmd < lengthof(_command_proc_table) && _command_proc_table[cmd].proc != NULL;
374 }
375 
384 {
385  assert(IsValidCommand(cmd));
386 
387  return _command_proc_table[cmd & CMD_ID_MASK].flags;
388 }
389 
397 const char *GetCommandName(uint32 cmd)
398 {
399  assert(IsValidCommand(cmd));
400 
401  return _command_proc_table[cmd & CMD_ID_MASK].name;
402 }
403 
410 {
411  /* Lookup table for the command types that are allowed for a given pause level setting. */
412  static const int command_type_lookup[] = {
422  };
423  assert_compile(lengthof(command_type_lookup) == CMDT_END);
424 
425  assert(IsValidCommand(cmd));
426  return _game_mode == GM_EDITOR || command_type_lookup[_command_proc_table[cmd & CMD_ID_MASK].type] <= _settings_game.construction.command_pause_level;
427 }
428 
429 
430 static int _docommand_recursive = 0;
431 
441 {
442  return DoCommand(container->tile, container->p1, container->p2, flags, container->cmd & CMD_ID_MASK, container->text);
443 }
444 
458 CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags, uint32 cmd, const char *text)
459 {
460  CommandCost res;
461 
462  /* Do not even think about executing out-of-bounds tile-commands */
463  if (tile != 0 && (tile >= MapSize() || (!IsValidTile(tile) && (flags & DC_ALL_TILES) == 0))) return CMD_ERROR;
464 
465  /* Chop of any CMD_MSG or other flags; we don't need those here */
466  CommandProc *proc = _command_proc_table[cmd & CMD_ID_MASK].proc;
467 
468  _docommand_recursive++;
469 
470  /* only execute the test call if it's toplevel, or we're not execing. */
471  if (_docommand_recursive == 1 || !(flags & DC_EXEC) ) {
472  if (_docommand_recursive == 1) _cleared_object_areas.Clear();
473  SetTownRatingTestMode(true);
474  res = proc(tile, flags & ~DC_EXEC, p1, p2, text);
475  SetTownRatingTestMode(false);
476  if (res.Failed()) {
477  goto error;
478  }
479 
480  if (_docommand_recursive == 1 &&
481  !(flags & DC_QUERY_COST) &&
482  !(flags & DC_BANKRUPT) &&
483  !CheckCompanyHasMoney(res)) { // CheckCompanyHasMoney() modifies 'res' to an error if it fails.
484  goto error;
485  }
486 
487  if (!(flags & DC_EXEC)) {
488  _docommand_recursive--;
489  return res;
490  }
491  }
492 
493  /* Execute the command here. All cost-relevant functions set the expenses type
494  * themselves to the cost object at some point */
495  if (_docommand_recursive == 1) _cleared_object_areas.Clear();
496  res = proc(tile, flags, p1, p2, text);
497  if (res.Failed()) {
498 error:
499  _docommand_recursive--;
500  return res;
501  }
502 
503  /* if toplevel, subtract the money. */
504  if (--_docommand_recursive == 0 && !(flags & DC_BANKRUPT)) {
506  }
507 
508  return res;
509 }
510 
519 {
520  CompanyID company = _current_company;
521  if (!Company::IsValidID(company)) return INT64_MAX;
522  return Company::Get(company)->money;
523 }
524 
531 bool DoCommandP(const CommandContainer *container, bool my_cmd)
532 {
533  return DoCommandP(container->tile, container->p1, container->p2, container->cmd, container->callback, container->text, my_cmd);
534 }
535 
551 bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd)
552 {
553  /* Cost estimation is generally only done when the
554  * local user presses shift while doing somthing.
555  * However, in case of incoming network commands,
556  * map generation or the pause button we do want
557  * to execute. */
558  bool estimate_only = _shift_pressed && IsLocalCompany() &&
560  !(cmd & CMD_NETWORK_COMMAND) &&
561  (cmd & CMD_ID_MASK) != CMD_PAUSE;
562 
563  /* We're only sending the command, so don't do
564  * fancy things for 'success'. */
565  bool only_sending = _networking && !(cmd & CMD_NETWORK_COMMAND);
566 
567  /* Where to show the message? */
568  int x = TileX(tile) * TILE_SIZE;
569  int y = TileY(tile) * TILE_SIZE;
570 
572  ShowErrorMessage(GB(cmd, 16, 16), STR_ERROR_NOT_ALLOWED_WHILE_PAUSED, WL_INFO, x, y);
573  return false;
574  }
575 
576 #ifdef ENABLE_NETWORK
577  /* Only set p2 when the command does not come from the network. */
578  if (!(cmd & CMD_NETWORK_COMMAND) && GetCommandFlags(cmd) & CMD_CLIENT_ID && p2 == 0) p2 = CLIENT_ID_SERVER;
579 #endif
580 
581  CommandCost res = DoCommandPInternal(tile, p1, p2, cmd, callback, text, my_cmd, estimate_only);
582  if (res.Failed()) {
583  /* Only show the error when it's for us. */
584  StringID error_part1 = GB(cmd, 16, 16);
585  if (estimate_only || (IsLocalCompany() && error_part1 != 0 && my_cmd)) {
586  ShowErrorMessage(error_part1, res.GetErrorMessage(), WL_INFO, x, y, res.GetTextRefStackGRF(), res.GetTextRefStackSize(), res.GetTextRefStack());
587  }
588  } else if (estimate_only) {
589  ShowEstimatedCostOrIncome(res.GetCost(), x, y);
590  } else if (!only_sending && res.GetCost() != 0 && tile != 0 && IsLocalCompany() && _game_mode != GM_EDITOR) {
591  /* Only show the cost animation when we did actually
592  * execute the command, i.e. we're not sending it to
593  * the server, when it has cost the local company
594  * something. Furthermore in the editor there is no
595  * concept of cost, so don't show it there either. */
596  ShowCostOrIncomeAnimation(x, y, GetSlopePixelZ(x, y), res.GetCost());
597  }
598 
599  if (!estimate_only && !only_sending && callback != NULL) {
600  callback(res, tile, p1, p2, cmd);
601  }
602 
603  return res.Succeeded();
604 }
605 
606 
611 #define return_dcpi(cmd) { _docommand_recursive = 0; return cmd; }
612 
626 CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only)
627 {
628  /* Prevent recursion; it gives a mess over the network */
629  assert(_docommand_recursive == 0);
630  _docommand_recursive = 1;
631 
632  /* Reset the state. */
633  _additional_cash_required = 0;
634 
635  /* Get pointer to command handler */
636  byte cmd_id = cmd & CMD_ID_MASK;
637  assert(cmd_id < lengthof(_command_proc_table));
638 
639  CommandProc *proc = _command_proc_table[cmd_id].proc;
640  /* Shouldn't happen, but you never know when someone adds
641  * NULLs to the _command_proc_table. */
642  assert(proc != NULL);
643 
644  /* Command flags are used internally */
645  CommandFlags cmd_flags = GetCommandFlags(cmd);
646  /* Flags get send to the DoCommand */
647  DoCommandFlag flags = CommandFlagsToDCFlags(cmd_flags);
648 
649 #ifdef ENABLE_NETWORK
650  /* Make sure p2 is properly set to a ClientID. */
651  assert(!(cmd_flags & CMD_CLIENT_ID) || p2 != 0);
652 #endif
653 
654  /* Do not even think about executing out-of-bounds tile-commands */
655  if (tile != 0 && (tile >= MapSize() || (!IsValidTile(tile) && (cmd_flags & CMD_ALL_TILES) == 0))) return_dcpi(CMD_ERROR);
656 
657  /* Always execute server and spectator commands as spectator */
658  bool exec_as_spectator = (cmd_flags & (CMD_SPECTATOR | CMD_SERVER)) != 0;
659 
660  /* If the company isn't valid it may only do server command or start a new company!
661  * The server will ditch any server commands a client sends to it, so effectively
662  * this guards the server from executing functions for an invalid company. */
663  if (_game_mode == GM_NORMAL && !exec_as_spectator && !Company::IsValidID(_current_company) && !(_current_company == OWNER_DEITY && (cmd_flags & CMD_DEITY) != 0)) {
665  }
666 
667  Backup<CompanyByte> cur_company(_current_company, FILE_LINE);
668  if (exec_as_spectator) cur_company.Change(COMPANY_SPECTATOR);
669 
670  bool test_and_exec_can_differ = (cmd_flags & CMD_NO_TEST) != 0;
671 
672  /* Test the command. */
673  _cleared_object_areas.Clear();
674  SetTownRatingTestMode(true);
676  CommandCost res = proc(tile, flags, p1, p2, text);
678  SetTownRatingTestMode(false);
679 
680  /* Make sure we're not messing things up here. */
681  assert(exec_as_spectator ? _current_company == COMPANY_SPECTATOR : cur_company.Verify());
682 
683  /* If the command fails, we're doing an estimate
684  * or the player does not have enough money
685  * (unless it's a command where the test and
686  * execution phase might return different costs)
687  * we bail out here. */
688  if (res.Failed() || estimate_only ||
689  (!test_and_exec_can_differ && !CheckCompanyHasMoney(res))) {
690  if (!_networking || _generating_world || (cmd & CMD_NETWORK_COMMAND) != 0) {
691  /* Log the failed command as well. Just to be able to be find
692  * causes of desyncs due to bad command test implementations. */
693  DEBUG(desync, 1, "cmdf: %08x; %02x; %02x; %06x; %08x; %08x; %08x; \"%s\" (%s)", _date, _date_fract, (int)_current_company, tile, p1, p2, cmd & ~CMD_NETWORK_COMMAND, text, GetCommandName(cmd));
694  }
695  cur_company.Restore();
696  return_dcpi(res);
697  }
698 
699 #ifdef ENABLE_NETWORK
700  /*
701  * If we are in network, and the command is not from the network
702  * send it to the command-queue and abort execution
703  */
704  if (_networking && !_generating_world && !(cmd & CMD_NETWORK_COMMAND)) {
705  NetworkSendCommand(tile, p1, p2, cmd & ~CMD_FLAGS_MASK, callback, text, _current_company);
706  cur_company.Restore();
707 
708  /* Don't return anything special here; no error, no costs.
709  * This way it's not handled by DoCommand and only the
710  * actual execution of the command causes messages. Also
711  * reset the storages as we've not executed the command. */
713  }
714 #endif /* ENABLE_NETWORK */
715  DEBUG(desync, 1, "cmd: %08x; %02x; %02x; %06x; %08x; %08x; %08x; \"%s\" (%s)", _date, _date_fract, (int)_current_company, tile, p1, p2, cmd & ~CMD_NETWORK_COMMAND, text, GetCommandName(cmd));
716 
717  /* Actually try and execute the command. If no cost-type is given
718  * use the construction one */
719  _cleared_object_areas.Clear();
721  CommandCost res2 = proc(tile, flags | DC_EXEC, p1, p2, text);
723 
724  if (cmd_id == CMD_COMPANY_CTRL) {
725  cur_company.Trash();
726  /* We are a new company -> Switch to new local company.
727  * We were closed down -> Switch to spectator
728  * Some other company opened/closed down -> The outside function will switch back */
729  _current_company = _local_company;
730  } else {
731  /* Make sure nothing bad happened, like changing the current company. */
732  assert(exec_as_spectator ? _current_company == COMPANY_SPECTATOR : cur_company.Verify());
733  cur_company.Restore();
734  }
735 
736  /* If the test and execution can differ we have to check the
737  * return of the command. Otherwise we can check whether the
738  * test and execution have yielded the same result,
739  * i.e. cost and error state are the same. */
740  if (!test_and_exec_can_differ) {
741  assert(res.GetCost() == res2.GetCost() && res.Failed() == res2.Failed()); // sanity check
742  } else if (res2.Failed()) {
743  return_dcpi(res2);
744  }
745 
746  /* If we're needing more money and we haven't done
747  * anything yet, ask for the money! */
748  if (_additional_cash_required != 0 && res2.GetCost() == 0) {
749  /* It could happen we removed rail, thus gained money, and deleted something else.
750  * So make sure the signal buffer is empty even in this case */
752  SetDParam(0, _additional_cash_required);
753  return_dcpi(CommandCost(STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY));
754  }
755 
756  /* update last build coordinate of company. */
757  if (tile != 0) {
758  Company *c = Company::GetIfValid(_current_company);
759  if (c != NULL) c->last_build_coordinate = tile;
760  }
761 
763 
764  /* update signals if needed */
766 
767  return_dcpi(res2);
768 }
769 #undef return_dcpi
770 
771 
778 {
779  this->AddCost(ret.cost);
780  if (this->success && !ret.success) {
781  this->message = ret.message;
782  this->success = false;
783  }
784 }
785 
791 uint32 CommandCost::textref_stack[16];
792 
798 void CommandCost::UseTextRefStack(const GRFFile *grffile, uint num_registers)
799 {
800  extern TemporaryStorageArray<int32, 0x110> _temp_store;
801 
802  assert(num_registers < lengthof(textref_stack));
803  this->textref_stack_grffile = grffile;
804  this->textref_stack_size = num_registers;
805  for (uint i = 0; i < num_registers; i++) {
806  textref_stack[i] = _temp_store.GetValue(0x100 + i);
807  }
808 }
Functions related to OTTD&#39;s strings.
CommandCost CmdSetGroupLivery(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Set the livery for a vehicle group.
Definition: group_cmd.cpp:653
CommandCost CmdGiveMoney(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Transfer funds (money) from one company to another.
Definition: misc_cmd.cpp:254
CommandCost CmdRemoveSignalTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Remove signals on a stretch of track.
Definition: rail_cmd.cpp:1526
static bool IsLocalCompany()
Is the current company the local company?
Definition: company_func.h:45
CommandCost CmdRenameSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Rename a sign.
Definition: signs_cmd.cpp:79
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:77
used in multiplayer to create a new companies etc.
Definition: command_type.h:279
Definition of stuff that is very close to a company, like the company struct itself.
CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a vehicle.
Definition: vehicle_cmd.cpp:85
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:257
CommandCost CmdDeleteOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Delete an order from the orderlist of a vehicle.
Definition: order_cmd.cpp:1041
bool _networking
are we in networking mode?
Definition: network.cpp:56
CommandCost CmdCreateGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Create a new goal.
Definition: goal.cpp:48
set the DC_NO_WATER flag on this command
Definition: command_type.h:394
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company)
Prepare a DoCommand to be send over the network.
CommandCost CmdBuildCanal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a piece of canal.
Definition: water_cmd.cpp:394
const char * GetCommandName(uint32 cmd)
Definition: command.cpp:397
CommandCost CmdPlaceSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Place a sign at the given coordinates.
Definition: signs_cmd.cpp:40
No landscaping actions may be executed.
Definition: command_type.h:420
A normal unpaused game.
Definition: openttd.h:58
Leave command test mode, revert to previous mode.
CommandCost CmdGoalQuestion(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Ask a goal related question.
Definition: goal.cpp:247
CommandCost CmdCreateGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Create a new vehicle group.
Definition: group_cmd.cpp:318
Enter command test mode, changes will be tempoary.
set p2 with the ClientID of the sending client.
Definition: command_type.h:395
CommandCost CmdBuildSignalTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build signals on a stretch of track.
Definition: rail_cmd.cpp:1434
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
Money GetAvailableMoneyForCommand()
Definition: command.cpp:518
Functions related to dates.
CommandCost CmdBuildSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build signals, alternate between double/single, signal/semaphore, pre/exit/combo-signals, and what-else not.
Definition: rail_cmd.cpp:1038
CommandCost CmdSetCompanyManagerFace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change the company manager&#39;s face.
static uint32 textref_stack[16]
Values to put on the TextRefStack for the error message.
Definition: command_type.h:33
CommandCost CmdSetGroupReplaceProtection(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
(Un)set global replace protection from a group
Definition: group_cmd.cpp:708
Class for temporary storage of data.
query cost only, don&#39;t build.
Definition: command_type.h:347
CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a piece of road.
Definition: road_cmd.cpp:484
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:25
CommandType type
The type of command.
Definition: command_type.h:454
set the DC_AUTO flag on this command
Definition: command_type.h:391
bool CheckCompanyHasMoney(CommandCost &cost)
Verify whether the company can pay the bill.
CommandCost CmdMoneyCheat(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change the financial flow of your company.
Definition: misc_cmd.cpp:205
CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a single piece of rail.
Definition: rail_cmd.cpp:446
CommandCost CmdDepotSellAllVehicles(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Sells all vehicles in a depot.
uint32 p2
parameter p2.
Definition: command_type.h:478
CommandCost CmdClearArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Clear a big piece of landscape.
Definition: landscape.cpp:744
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:207
CommandCost CmdBuyShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Acquire shares in an opposing company.
Definition: economy.cpp:2022
CommandCost CmdRemoveRailroadTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build rail on a stretch of track.
Definition: rail_cmd.cpp:947
void Change(const U &new_value)
Change the value of the variable.
Definition: backup_type.hpp:86
CommandFlags
Command flags for the command table _command_proc_table.
Definition: command_type.h:387
CommandCost CmdUpdateStoryPageElement(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Update a new story page element.
Definition: story.cpp:204
All actions may be executed.
Definition: command_type.h:421
CommandCost CmdReverseTrainDirection(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Reverse train.
Definition: train_cmd.cpp:1894
void UseTextRefStack(const GRFFile *grffile, uint num_registers)
Activate usage of the NewGRF TextRefStack for the error message.
Definition: command.cpp:798
CommandCost CmdDoTownAction(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Do a town action.
Definition: town_cmd.cpp:3090
static SigSegState UpdateSignalsInBuffer(Owner owner)
Updates blocks in _globset buffer.
Definition: signal.cpp:472
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:3370
The client is spectating.
Definition: company_type.h:37
Define a command with the flags which belongs to it.
Definition: command_type.h:450
const char * name
A human readable name for the procedure.
Definition: command_type.h:452
Functions related to world/map generation.
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:84
Common return value for all commands.
Definition: command_type.h:25
CommandCost CmdMassStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Starts or stops a lot of vehicles.
CommandFlags GetCommandFlags(uint32 cmd)
Definition: command.cpp:383
CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Network-safe changing of settings (server-only).
Definition: settings.cpp:1848
CommandCost CmdSetVehicleVisibility(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Set the visibility of an engine.
Definition: engine.cpp:868
char text[32 *MAX_CHAR_LENGTH]
possible text sent for name changes etc, in bytes including &#39;\0&#39;.
Definition: command_type.h:481
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition: command_type.h:64
CommandCost CmdDepotMassAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Autoreplace all vehicles in the depot.
CommandCost CmdScrollViewport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Scroll players main viewport.
Definition: viewport.cpp:3140
CommandCost CmdRenameVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Give a custom name to your vehicle.
Servers always have this ID.
Definition: network_type.h:45
CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a bus or truck stop.
const GRFFile * GetTextRefStackGRF() const
Returns the NewGRF providing the TextRefStack of the error message.
Definition: command_type.h:115
CommandCost CmdRenameDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Rename a depot.
Definition: depot_cmd.cpp:51
CommandCost CmdSetVehicleOnTime(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Clear the lateness counter to make the vehicle on time.
bool IsValidCommand(uint32 cmd)
Definition: command.cpp:369
Class to backup a specific variable and restore it later.
Definition: backup_type.hpp:23
CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Clone a vehicle.
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
company bankrupts, skip money check, skip vehicle on tile check in some cases
Definition: command_type.h:351
The object is owned by a superuser / goal script.
Definition: company_type.h:29
Pausing/removing companies/server settings.
Definition: command_type.h:410
CommandCost CmdExpandTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Expand a town (scenario editor only).
Definition: town_cmd.cpp:2669
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:163
CommandCost CmdRemoveStoryPage(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Remove a story page and associated story page elements.
Definition: story.cpp:313
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=NULL, uint textref_stack_size=0, const uint32 *textref_stack=NULL)
Display an error message in a window.
Definition: error_gui.cpp:378
Base for all objects.
CommandCost CmdPause(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Pause/Unpause the game (server-only).
Definition: misc_cmd.cpp:148
CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a ship depot.
Definition: water_cmd.cpp:102
CommandCost CmdRenameCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change the name of the company.
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:470
mask for all command flags
Definition: command_type.h:378
CommandCost CmdRemoveStoryPageElement(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Remove a story page element.
Definition: story.cpp:347
Functions related to errors.
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
Definition: command.cpp:440
DateFract _date_fract
Fractional part of the day.
Definition: date.cpp:29
CommandCost CmdCreateSubsidy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Create a new subsidy.
Definition: subsidy.cpp:252
bool Verify() const
Check whether the variable is currently equals the backup.
CommandCost CmdDecreaseLoan(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Decrease the loan of your company.
Definition: misc_cmd.cpp:88
CommandCost CmdSetGoalProgress(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Update progress text of a goal.
Definition: goal.cpp:181
A cheat of some sorts.
Definition: command_type.h:411
execute the command without sending it on the network
Definition: command_type.h:377
CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Remove bus or truck stops.
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...
CommandCost CmdBuyCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Buy up another company.
Definition: economy.cpp:2115
mask for the command ID
Definition: command_type.h:379
CommandCost CmdTerraformLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Terraform land.
uint32 p1
parameter p1.
Definition: command_type.h:477
CommandCost CmdForceTrainProceed(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Force a train through a red signal.
Definition: train_cmd.cpp:1967
CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Convert one rail type to the other.
Definition: rail_cmd.cpp:1554
StringID GetErrorMessage() const
Returns the error message of a command.
Definition: command_type.h:142
Construction, modification (incl. refit) and destruction of vehicles.
Definition: command_type.h:404
Structure for buffering the build command when selecting a station to join.
Definition: command_type.h:475
CommandCost CmdWantEnginePreview(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Accept an engine prototype.
Definition: engine.cpp:892
DoCommandFlag
List of flags for a command.
Definition: command_type.h:343
CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change the company&#39;s company-colour.
CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Add an order to the orderlist of a vehicle.
Definition: order_cmd.cpp:729
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:152
the command may be executed by COMPANY_DEITY
Definition: command_type.h:396
Definition of base types and functions in a cross-platform compatible way.
CommandCost CmdRemoveSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Remove signals.
Definition: rail_cmd.cpp:1451
const GRFFile * textref_stack_grffile
NewGRF providing the TextRefStack content.
Definition: command_type.h:30
CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a road depot.
Definition: road_cmd.cpp:1015
A number of safeguards to prevent using unsafe methods.
CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only)
Definition: command.cpp:626
CommandCost CmdMoveOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Move an order inside the orderlist.
Definition: order_cmd.cpp:1188
the command&#39;s output may differ between test and execute due to town rating changes etc...
Definition: command_type.h:393
CommandCost CmdTownGrowthRate(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change the growth rate of the town.
Definition: town_cmd.cpp:2629
StringID message
Warning message for when success is unset.
Definition: command_type.h:28
const uint32 * GetTextRefStack() const
Returns a pointer to the values for the TextRefStack of the error message.
Definition: command_type.h:133
CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change timetable data of an order.
CommandCost CmdTurnRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Turn a roadvehicle around.
uint textref_stack_size
Number of uint32 values to put on the TextRefStack for the error message.
Definition: command_type.h:31
Renaming stuff, changing company colours, placing signs, etc.
Definition: command_type.h:408
static DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
Definition: command_func.h:62
CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a dock/haven.
Basic functions/variables used all over the place.
CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build an object object.
Definition: object_cmd.cpp:206
Construction and destruction of objects on the map.
Definition: command_type.h:403
CommandCost CmdRenameStation(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Rename a station.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:531
CommandCost CmdDeleteTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Delete a town (scenario editor or worldgen only).
Definition: town_cmd.cpp:2709
CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Remove all vehicles from a group.
Definition: group_cmd.cpp:617
CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build Tunnel.
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
PauseModeByte _pause_mode
The current pause mode.
Definition: gfx.cpp:48
CommandCost CmdSellShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Sell shares in an opposing company.
Definition: economy.cpp:2074
CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a train depot.
Definition: rail_cmd.cpp:964
CommandCost CmdSetAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change engine renewal parameters.
CommandCost CmdSkipToOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Goto order of order-list.
Definition: order_cmd.cpp:1147
the command can only be initiated by the server
Definition: command_type.h:388
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
CommandCost CmdSetStoryPageTitle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Update title of a story page.
Definition: story.cpp:234
the command&#39;s string may contain control strings
Definition: command_type.h:397
bool Failed() const
Did this command fail?
Definition: command_type.h:161
CommandCost CmdLandscapeClear(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Clear a piece of landscape.
Definition: landscape.cpp:694
CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Modify an order in the orderlist of a vehicle.
Definition: order_cmd.cpp:1292
Enter command scope, changes will be permanent.
Magic end marker.
Definition: command_type.h:413
CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build/Fund an industry.
CommandCost CmdCreateStoryPageElement(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Create a new story page element.
Definition: story.cpp:153
Leave command scope, revert to previous mode.
No construction actions may be executed.
Definition: command_type.h:419
the command may be initiated by a spectator
Definition: command_type.h:389
allow this command also on MP_VOID tiles
Definition: command_type.h:354
bool _shift_pressed
Is Shift pressed?
Definition: gfx.cpp:37
CommandCost CmdSetStoryPageDate(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Update date of a story page.
Definition: story.cpp:264
CommandCallback * callback
any callback function executed upon successful completion of the command.
Definition: command_type.h:480
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:36
CommandCost CmdRemoveSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Remove a single piece of track.
Definition: rail_cmd.cpp:610
bool IsCommandAllowedWhilePaused(uint32 cmd)
Returns whether the command is allowed while the game is paused.
Definition: command.cpp:409
void ShowEstimatedCostOrIncome(Money cost, int x, int y)
Display estimated costs.
Definition: misc_gui.cpp:534
Management of money, i.e. loans and shares.
Definition: command_type.h:405
CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Move a rail vehicle around inside the depot.
Definition: train_cmd.cpp:1156
execute the given command
Definition: command_type.h:345
void Trash()
Trash the backup.
CommandCost CmdTownCargoGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change the cargo goal of a town.
Definition: town_cmd.cpp:2572
uint GetTextRefStackSize() const
Returns the number of uint32 values for the TextRefStack of the error message.
Definition: command_type.h:124
Functions related to companies.
CommandCost CmdClearOrderBackup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Clear an OrderBackup.
CommandCost CmdAlterGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Alter a group.
Definition: group_cmd.cpp:423
CommandCost CmdShowStoryPage(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Display a story page for all clients that are allowed to view the story page.
Definition: story.cpp:291
static uint MapSize()
Get the size of the map.
Definition: map_func.h:94
bool _generating_world
Whether we are generating the map or not.
Definition: genworld.cpp:61
CommandCost CmdOpenCloseAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Open/close an airport to incoming aircraft.
CommandCost CmdChangeBankBalance(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change the bank bank balance of a company by inserting or removing money without affecting the loan...
Definition: misc_cmd.cpp:220
CommandProc * proc
The procedure to actually executing.
Definition: command_type.h:451
CommandCost CmdRenamePresident(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change the name of the president.
CompanyByte _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
CommandFlags flags
The (command) flags to that apply to this command.
Definition: command_type.h:453
Modifications to route management (orders, groups, etc).
Definition: command_type.h:407
CommandCost CmdBuildLock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Builds a lock.
Definition: water_cmd.cpp:370
Types used for networking.
uint8 command_pause_level
level/amount of commands that can&#39;t be executed while paused
CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a buoy.
CommandCost CmdCustomNewsItem(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Create a new custom news item.
Definition: news_gui.cpp:709
CommandCost CmdDeleteGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Add all vehicles in the given group to the default group and then deletes the group.
Definition: group_cmd.cpp:367
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:217
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
Definition: openttd.cpp:112
CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Convert existing rail to waypoint.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
TileIndex last_build_coordinate
Coordinate of the last build thing by this company.
Definition: company_base.h:73
CommandCost CmdRenameEngine(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Rename an engine.
Definition: engine.cpp:1038
CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a long piece of road.
Definition: road_cmd.cpp:835
#define return_dcpi(cmd)
Helper to deduplicate the code for returning.
Definition: command.cpp:611
CommandCost CmdRemoveGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Remove a goal.
Definition: goal.cpp:121
CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Set the start date of the timetable.
CommandCost CmdCreateStoryPage(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Create a new story page.
Definition: story.cpp:107
void SubtractMoneyFromCompany(CommandCost cost)
Subtract money from the _current_company, if the company is valid.
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:442
Functions related to OTTD&#39;s landscape.
CommandCost CmdIncreaseLoan(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Increase the loan of your company.
Definition: misc_cmd.cpp:41
Stopping, starting, sending to depot, turning around, replace orders etc.
Definition: command_type.h:406
Functions related to commands.
static const Command _command_proc_table[]
The master command table.
Definition: command.cpp:212
CommandCost CmdOrderRefit(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Add/remove refit orders from an order.
Definition: order_cmd.cpp:1712
CommandCost CmdRemoveFromRailStation(TileIndex start, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Remove a single tile from a rail station.
CommandCost CmdSendVehicleToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Send a vehicle to the depot.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
Definition: pool_type.hpp:235
TileIndex tile
tile command being executed on.
Definition: command_type.h:476
CommandCost CmdRefitVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Refits a vehicle to the specified cargo type.
bool success
Whether the comment went fine up to this moment.
Definition: command_type.h:29
CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Clone/share/copy an order-list of another vehicle.
Definition: order_cmd.cpp:1561
ConstructionSettings construction
construction of things in-game
CommandCost CmdSetGoalText(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Update goal text of a goal.
Definition: goal.cpp:151
the command cannot be executed in a multiplayer game; single-player only
Definition: command_type.h:390
CommandCost CmdChangeServiceInt(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change the service interval of a vehicle.
CommandCost CmdAutoreplaceVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Autoreplaces a vehicle Trains are replaced as a whole chain, free wagons in depot are replaced on the...
CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Place an Airport.
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:23
CommandCost CmdAutofillTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Start or stop filling the timetable automatically from the time the vehicle actually takes to complet...
CommandCost CmdRenameWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Rename a waypoint.
Changing settings related to a company.
Definition: command_type.h:409
CommandCost CmdAddVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Add a vehicle to a group.
Definition: group_cmd.cpp:523
void Restore()
Restore the variable.
Base of the town class.
CommandCost CmdGoalQuestionAnswer(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Reply to a goal question.
Definition: goal.cpp:298
CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build rail station.
CommandCost CmdAddSharedVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Add all shared vehicles of all vehicles from a group.
Definition: group_cmd.cpp:578
TYPE GetValue(uint pos) const
Gets the value from a given position.
No user actions may be executed.
Definition: command_type.h:418
Owner
Enum for all companies/owners.
Definition: company_type.h:20
CommandCost CmdRemoveLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Remove a long piece of road.
Definition: road_cmd.cpp:940
CommandCost CmdSetGoalCompleted(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Update completed state of a goal.
Definition: goal.cpp:214
void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost)
Display animated income or costs on the map.
Definition: misc_gui.cpp:553
CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change one of the per-company settings.
Definition: settings.cpp:1895
Functions related to signals.
Functions related to text effects.
CommandCost CmdRemoveFromRailWaypoint(TileIndex start, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Remove a single tile from a waypoint.
GUI functions that shouldn&#39;t be here.
CommandCost CmdTownSetText(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Set a custom text in the Town window.
Definition: town_cmd.cpp:2605
CommandCost CmdRenameTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Rename a town (server-only).
Definition: town_cmd.cpp:2524
CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Plant a tree.
Definition: tree_cmd.cpp:335
CommandCost CmdBuildRailroadTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build rail on a stretch of track.
Definition: rail_cmd.cpp:928
Date _date
Current date in days (day counter)
Definition: date.cpp:28
Money cost
The cost of this action.
Definition: command_type.h:27
CommandCost CmdSellVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Sell a vehicle.
Class for backupping variables and making sure they are restored later.
CommandCost CmdLevelLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Levels a selected (rectangle) area of land.
uint32 cmd
command being executed.
Definition: command_type.h:479
CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Create a new town.
Definition: town_cmd.cpp:1718
allow this command also on MP_VOID tiles
Definition: command_type.h:392
CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a Bridge.
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:104
CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Control the companies: add, delete, etc.
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:201
CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Start/Stop a vehicle.
pause the game
Definition: command_type.h:255