OpenTTD Source: src/command.cpp File Reference

OpenTTD Source 1.11.0-RC1

Macros | Functions | Variables
command.cpp File Reference
`#include "stdafx.h"`
`#include "landscape.h"`
`#include "error.h"`
`#include "gui.h"`
`#include "command_func.h"`
`#include "network/network_type.h"`
`#include "network/network.h"`
`#include "genworld.h"`
`#include "strings_func.h"`
`#include "texteff.hpp"`
`#include "town.h"`
`#include "date_func.h"`
`#include "company_func.h"`
`#include "company_base.h"`
`#include "signal_func.h"`
`#include "core/backup_type.hpp"`
`#include "object_base.h"`
`#include "table/strings.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Macros
#define | DEF_CMD(proc, flags, type) {proc, #proc, (CommandFlags)flags, type}
#define | return_dcpi(cmd) { _docommand_recursive = 0; return cmd; }
| Helper to deduplicate the code for returning. More...

## Functions
bool | IsValidCommand (uint32 cmd)
CommandFlags | GetCommandFlags (uint32 cmd)
const char * | GetCommandName (uint32 cmd)
bool | IsCommandAllowedWhilePaused (uint32 cmd)
| Returns whether the command is allowed while the game is paused. More...
CommandCost | DoCommand (const CommandContainer *container, DoCommandFlag flags)
| Shorthand for calling the long DoCommand with a container. More...
CommandCost | DoCommand (TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags, uint32 cmd, const char *text)
Money | GetAvailableMoneyForCommand ()
bool | DoCommandP (const CommandContainer *container, bool my_cmd)
| Shortcut for the long DoCommandP when having a container with the data. More...
bool | DoCommandP (TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd)
CommandCost | DoCommandPInternal (TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only)

## Variables
CommandProc | CmdBuildRailroadTrack
CommandProc | CmdRemoveRailroadTrack
CommandProc | CmdBuildSingleRail
CommandProc | CmdRemoveSingleRail
CommandProc | CmdLandscapeClear
CommandProc | CmdBuildBridge
CommandProc | CmdBuildRailStation
CommandProc | CmdRemoveFromRailStation
CommandProc | CmdConvertRail
CommandProc | CmdBuildSingleSignal
CommandProc | CmdRemoveSingleSignal
CommandProc | CmdTerraformLand
CommandProc | CmdBuildObject
CommandProc | CmdSellLandArea
CommandProc | CmdBuildTunnel
CommandProc | CmdBuildTrainDepot
CommandProc | CmdBuildRailWaypoint
CommandProc | CmdRenameWaypoint
CommandProc | CmdRemoveFromRailWaypoint
CommandProc | CmdBuildRoadStop
CommandProc | CmdRemoveRoadStop
CommandProc | CmdBuildLongRoad
CommandProc | CmdRemoveLongRoad
CommandProc | CmdBuildRoad
CommandProc | CmdBuildRoadDepot
CommandProc | CmdConvertRoad
CommandProc | CmdBuildAirport
CommandProc | CmdBuildDock
CommandProc | CmdBuildShipDepot
CommandProc | CmdBuildBuoy
CommandProc | CmdPlantTree
CommandProc | CmdMoveRailVehicle
CommandProc | CmdBuildVehicle
CommandProc | CmdSellVehicle
CommandProc | CmdRefitVehicle
| Refits a vehicle to the specified cargo type. More...
CommandProc | CmdSendVehicleToDepot
CommandProc | CmdSetVehicleVisibility
CommandProc | CmdForceTrainProceed
CommandProc | CmdReverseTrainDirection
CommandProc | CmdClearOrderBackup
CommandProc | CmdModifyOrder
CommandProc | CmdSkipToOrder
CommandProc | CmdDeleteOrder
CommandProc | CmdInsertOrder
CommandProc | CmdChangeServiceInt
CommandProc | CmdBuildIndustry
CommandProc | CmdIndustryCtrl
CommandProc | CmdSetCompanyManagerFace
CommandProc | CmdSetCompanyColour
CommandProc | CmdIncreaseLoan
CommandProc | CmdDecreaseLoan
CommandProc | CmdWantEnginePreview
CommandProc | CmdEngineCtrl
CommandProc | CmdRenameVehicle
CommandProc | CmdRenameEngine
CommandProc | CmdRenameCompany
CommandProc | CmdRenamePresident
CommandProc | CmdRenameStation
CommandProc | CmdRenameDepot
CommandProc | CmdPlaceSign
CommandProc | CmdRenameSign
CommandProc | CmdTurnRoadVeh
CommandProc | CmdPause
CommandProc | CmdBuyShareInCompany
CommandProc | CmdSellShareInCompany
CommandProc | CmdBuyCompany
CommandProc | CmdFoundTown
CommandProc | CmdRenameTown
CommandProc | CmdDoTownAction
CommandProc | CmdTownGrowthRate
CommandProc | CmdTownRating
CommandProc | CmdTownCargoGoal
CommandProc | CmdTownSetText
CommandProc | CmdExpandTown
CommandProc | CmdDeleteTown
CommandProc | CmdChangeSetting
CommandProc | CmdChangeCompanySetting
CommandProc | CmdOrderRefit
CommandProc | CmdCloneOrder
CommandProc | CmdClearArea
CommandProc | CmdGiveMoney
CommandProc | CmdMoneyCheat
CommandProc | CmdChangeBankBalance
CommandProc | CmdBuildCanal
CommandProc | CmdBuildLock
CommandProc | CmdCreateSubsidy
CommandProc | CmdCompanyCtrl
CommandProc | CmdCustomNewsItem
CommandProc | CmdCreateGoal
CommandProc | CmdRemoveGoal
CommandProc | CmdSetGoalText
CommandProc | CmdSetGoalProgress
CommandProc | CmdSetGoalCompleted
CommandProc | CmdGoalQuestion
CommandProc | CmdGoalQuestionAnswer
CommandProc | CmdCreateStoryPage
CommandProc | CmdCreateStoryPageElement
CommandProc | CmdUpdateStoryPageElement
CommandProc | CmdSetStoryPageTitle
CommandProc | CmdSetStoryPageDate
CommandProc | CmdShowStoryPage
CommandProc | CmdRemoveStoryPage
CommandProc | CmdRemoveStoryPageElement
CommandProc | CmdScrollViewport
CommandProc | CmdStoryPageButton
CommandProc | CmdLevelLand
CommandProc | CmdBuildSignalTrack
CommandProc | CmdRemoveSignalTrack
CommandProc | CmdSetAutoReplace
CommandProc | CmdCloneVehicle
CommandProc | CmdStartStopVehicle
CommandProc | CmdMassStartStopVehicle
CommandProc | CmdAutoreplaceVehicle
CommandProc | CmdDepotSellAllVehicles
CommandProc | CmdDepotMassAutoReplace
CommandProc | CmdCreateGroup
CommandProc | CmdAlterGroup
CommandProc | CmdDeleteGroup
CommandProc | CmdAddVehicleGroup
CommandProc | CmdAddSharedVehicleGroup
CommandProc | CmdRemoveAllVehiclesGroup
CommandProc | CmdSetGroupReplaceProtection
CommandProc | CmdSetGroupLivery
CommandProc | CmdMoveOrder
CommandProc | CmdChangeTimetable
CommandProc | CmdSetVehicleOnTime
CommandProc | CmdAutofillTimetable
CommandProc | CmdSetTimetableStart
CommandProc | CmdOpenCloseAirport
static const Command | _command_proc_table []
| The master command table. More...
static int | _docommand_recursive = 0

## Detailed Description

Handling of commands.

Definition in file command.cpp.

## Macro Definition Documentation

## ◆ return_dcpi

#define return_dcpi | ( |  | cmd | ) | { _docommand_recursive = 0; return cmd; }

Helper to deduplicate the code for returning.

Parameters

  cmd | the command cost to return.

Definition at line 619 of file command.cpp.

## Function Documentation

## ◆ DoCommand() [1/2]

CommandCost DoCommand | ( | const CommandContainer * | container,
|  | DoCommandFlag | flags
| ) |  |

Shorthand for calling the long DoCommand with a container.

Parameters

  container | Container with (almost) all information
  flags | Flags for the command and how to execute the command

See also
  CommandProc

Returns
  the cost

Definition at line 450 of file command.cpp.

References CommandContainer::cmd, CMD_ID_MASK, DoCommand(), CommandContainer::p1, CommandContainer::p2, CommandContainer::text, and CommandContainer::tile.

Referenced by BuildReplacementVehicle(), CanBuildHouseHere(), CheckFlatLandAirport(), ClearMakeHouseTile(), CmdAddSharedVehicleGroup(), CmdBuildLongRoad(), CmdCloneVehicle(), CmdDeleteGroup(), CmdDepotMassAutoReplace(), CmdMassStartStopVehicle(), CmdMoveVehicle(), CmdRemoveAllVehiclesGroup(), CmdRenamePresident(), CmdStartStopVehicle(), CopyHeadSpecificThings(), DoBuildLock(), DoCommand(), OrderBackup::DoRestore(), RefitWindow::GetCapacityString(), NormalizeTrainVehInDepot(), BuildRoadToolbarWindow::OnPlacePresize(), BuildRailToolbarWindow::OnPlacePresize(), RemoveRailStation(), RemoveRailWaypoint(), ReplaceFreeUnit(), ResetLandscapeConfirmationCallback(), SendAllVehiclesToDepot(), ShowBuildBridgeWindow(), ShowNewGrfVehicleError(), and StationJoinerNeeded().

## ◆ DoCommand() [2/2]

CommandCost DoCommand | ( | TileIndex | tile,
|  | uint32 | p1,
|  | uint32 | p2,
|  | DoCommandFlag | flags,
|  | uint32 | cmd,
|  | const char * | text
| ) |  |

This function executes a given command with the parameters from the CommandProc parameter list. Depending on the flags parameter it execute or test a command.

Parameters

  tile | The tile to apply the command on (for the CommandProc)
  p1 | Additional data for the command (for the CommandProc)
  p2 | Additional data for the command (for the CommandProc)
  flags | Flags for the command and how to execute the command
  cmd | The command-id to execute (a value of the CMD_* enums)
  text | The text to pass

See also
  CommandProc

Returns
  the cost

Definition at line 468 of file command.cpp.

References _command_proc_table, CMD_ERROR, CMD_ID_MASK, DC_ALL_TILES, IsValidTile(), MapSize(), and Command::proc.

## ◆ DoCommandP() [1/2]

bool DoCommandP | ( | const CommandContainer * | container,
|  | bool | my_cmd
| ) |  |

Shortcut for the long DoCommandP when having a container with the data.

Parameters

  container | the container with information.
  my_cmd | indicator if the command is from a company or server (to display error messages for a user)

Returns
  true if the command succeeded, else false

Definition at line 541 of file command.cpp.

References CommandContainer::callback, CommandContainer::cmd, DoCommandP(), CommandContainer::p1, CommandContainer::p2, CommandContainer::text, and CommandContainer::tile.

Referenced by AskUnsafeUnpauseCallback(), CcBuildWagon(), ChangeTimetableStartCallback(), CheckPauseHelper(), CheckTrainsLengths(), ClickMoneyCheat(), DoCommandP(), GUIPlaceProcDragXY(), MaybeStartNewCompany(), NetworkAutoCleanCompanies(), NetworkExecuteLocalCommandQueue(), EnginePreviewWindow::OnClick(), GoalQuestionWindow::OnClick(), CompanyFinancesWindow::OnClick(), AIDebugWindow::OnClick(), BuildVehicleWindow::OnClick(), SelectCompanyManagerFaceWindow::OnClick(), StationViewWindow::OnClick(), VehicleDetailsWindow::OnClick(), BuyCompanyWindow::OnClick(), VehicleViewWindow::OnClick(), DepotWindow::OnDragDrop(), OrdersWindow::OnDragDrop(), VehicleGroupWindow::OnDropdownSelect(), VehicleListWindow::OnDropdownSelect(), VehicleDetailsWindow::OnDropdownSelect(), AIDebugWindow::OnInvalidateData(), StoryBookWindow::OnPageElementClick(), BuildDocksToolbarWindow::OnPlaceMouseUp(), TerraformToolbarWindow::OnPlaceObject(), BuildObjectWindow::OnPlaceObject(), BuildRailToolbarWindow::OnPlaceObject(), StoryBookWindow::OnPlaceObject(), CompanyWindow::OnPlaceObject(), WaypointWindow::OnQueryTextFinished(), TownViewWindow::OnQueryTextFinished(), DepotWindow::OnQueryTextFinished(), VehicleGroupWindow::OnQueryTextFinished(), OrdersWindow::OnQueryTextFinished(), BuildVehicleWindow::OnQueryTextFinished(), StationViewWindow::OnQueryTextFinished(), VehicleViewWindow::OnQueryTextFinished(), DepotWindow::OnVehicleSelect(), OrdersWindow::OrderClick_Delete(), OrdersWindow::OrderClick_FullLoad(), OrdersWindow::OrderClick_NearestDepot(), OrdersWindow::OrderClick_Nonstop(), OrdersWindow::OrderClick_Refit(), OrdersWindow::OrderClick_Service(), OrdersWindow::OrderClick_Skip(), OrdersWindow::OrderClick_StopSharing(), OrdersWindow::OrderClick_Unload(), PlaceExtraDepotRail(), PlaceProc_Sign(), RenameSign(), ReplaceVehicleWindow::ReplaceClick_StartReplace(), OrderBackup::ResetUser(), ShowBuildBridgeWindow(), StartStopVehicle(), and StateGameLoop_LinkGraphPauseControl().

## ◆ DoCommandP() [2/2]

bool DoCommandP | ( | TileIndex | tile,
|  | uint32 | p1,
|  | uint32 | p2,
|  | uint32 | cmd,
|  | CommandCallback * | callback,
|  | const char * | text,
|  | bool | my_cmd
| ) |  |

Toplevel network safe docommand function for the current company. Must not be called recursively. The callback is called when the command succeeded or failed. The parameters tile, p1, and p2 are from the CommandProc function. The parameter cmd is the command to execute. The parameter my_cmd is used to indicate if the command is from a company or the server.

Parameters

  tile | The tile to perform a command on (see CommandProc)
  p1 | Additional data for the command (see CommandProc)
  p2 | Additional data for the command (see CommandProc)
  cmd | The command to execute (a CMD_* value)
  callback | A callback function to call after the command is finished
  text | The text to pass
  my_cmd | indicator if the command is from a company or server (to display error messages for a user)

Returns
  `true` if the command succeeded, else `false`.

Definition at line 561 of file command.cpp.

References _generating_world, _networking, _shift_pressed, CMD_NETWORK_COMMAND, CMD_NO_EST, GetCommandFlags(), and IsLocalCompany().

## ◆ DoCommandPInternal()

CommandCost DoCommandPInternal | ( | TileIndex | tile,
|  | uint32 | p1,
|  | uint32 | p2,
|  | uint32 | cmd,
|  | CommandCallback * | callback,
|  | const char * | text,
|  | bool | my_cmd,
|  | bool | estimate_only
| ) |  |

Helper function for the toplevel network safe docommand function for the current company.

Parameters

  tile | The tile to perform a command on (see CommandProc)
  p1 | Additional data for the command (see CommandProc)
  p2 | Additional data for the command (see CommandProc)
  cmd | The command to execute (a CMD_* value)
  callback | A callback function to call after the command is finished
  text | The text to pass
  my_cmd | indicator if the command is from a company or server (to display error messages for a user)
  estimate_only | whether to give only the estimate or also execute the command

Returns
  the command cost of this function.

Definition at line 634 of file command.cpp.

Referenced by OrderBackup::Reset().

## ◆ GetAvailableMoneyForCommand()

Money GetAvailableMoneyForCommand | ( |  | ) |

This functions returns the money which can be used to execute a command. This is either the money of the current company or INT64_MAX if there is no such a company "at the moment" like the server itself.

Returns
  The available money of a company or INT64_MAX

Definition at line 528 of file command.cpp.

References _current_company, and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID().

Referenced by CmdClearArea(), CmdLevelLand(), and CmdRemoveLongRoad().

## ◆ GetCommandFlags()

CommandFlags GetCommandFlags | ( | uint32 | cmd | ) |

This function mask the parameter with CMD_ID_MASK and returns the flags which belongs to the given command.

Parameters

  cmd | The integer value of the command

Returns
  The flags for this command

Definition at line 393 of file command.cpp.

References _command_proc_table, CMD_ID_MASK, Command::flags, and IsValidCommand().

Referenced by DoCommandP(), ShowBuildBridgeWindow(), and StationJoinerNeeded().

## ◆ GetCommandName()

const char* GetCommandName | ( | uint32 | cmd | ) |

This function mask the parameter with CMD_ID_MASK and returns the name which belongs to the given command.

Parameters

  cmd | The integer value of the command

Returns
  The name for this command

Definition at line 407 of file command.cpp.

References _command_proc_table, CMD_ID_MASK, IsValidCommand(), and Command::name.

Referenced by ServerNetworkAdminSocketHandler::SendCmdNames().

## ◆ IsCommandAllowedWhilePaused()

bool IsCommandAllowedWhilePaused | ( | uint32 | cmd | ) |

Returns whether the command is allowed while the game is paused.

Parameters

  cmd | The command to check.

Returns
  True if the command is allowed while paused, false otherwise.

< CMDT_LANDSCAPE_CONSTRUCTION

< CMDT_VEHICLE_CONSTRUCTION

< CMDT_MONEY_MANAGEMENT

< CMDT_VEHICLE_MANAGEMENT

< CMDT_ROUTE_MANAGEMENT

< CMDT_OTHER_MANAGEMENT

< CMDT_COMPANY_SETTING

< CMDT_SERVER_SETTING

< CMDT_CHEAT

Definition at line 419 of file command.cpp.

References CMDPL_ALL_ACTIONS, CMDPL_NO_ACTIONS, CMDPL_NO_CONSTRUCTION, CMDPL_NO_LANDSCAPING, CMDT_END, IsValidCommand(), and lengthof.

Referenced by CommandQueue::Peek(), and CommandQueue::Pop().

## ◆ IsValidCommand()

bool IsValidCommand | ( | uint32 | cmd | ) |

This function range-checks a cmd, and checks if the cmd is not nullptr

Parameters

  cmd | The integer value of a command

Returns
  true if the command is valid (and got a CommandProc function)

Definition at line 379 of file command.cpp.

References _command_proc_table, CMD_ID_MASK, lengthof, and Command::proc.

Referenced by GetCommandFlags(), GetCommandName(), and IsCommandAllowedWhilePaused().

## Variable Documentation

## ◆ _command_proc_table

const Command _command_proc_table[]
| static

The master command table.

This table contains all possible CommandProc functions with the flags which belongs to it. The indices are the same as the value from the CMD_* enums.

Definition at line 216 of file command.cpp.

Referenced by DoCommand(), GetCommandFlags(), GetCommandName(), and IsValidCommand().

## ◆ CmdRefitVehicle

CommandCost CmdRefitVehicle

Refits a vehicle to the specified cargo type.

Parameters

  tile | unused
  flags | type of operation
  p1 | vehicle ID to refit
  p2 | various bitstuffed elements p2 = (bit 0-7) - New cargo type to refit to. p2 = (bit 8-15) - New cargo subtype to refit to. 0xFF means to try keeping the same subtype according to GetBestFittingSubType(). p2 = (bit 16-23) - Number of vehicles to refit (not counting articulated parts). Zero means all vehicles. Only used if "refit only this vehicle" is false. p2 = (bit 24) - Automatic refitting. p2 = (bit 25) - Refit only this vehicle. Used only for cloning vehicles.
  text | unused

Returns
  the cost of this operation or an error

Definition at line 85 of file command.cpp.