OpenTTD Source: CommandCost Class Reference

OpenTTD Source 12.0-beta1

Public Member Functions | Private Attributes | Static Private Attributes
CommandCost Class Reference

Common return value for all commands. More...

`#include <command_type.h>`

## Public Member Functions
| CommandCost ()
| Creates a command cost return with no cost and no error.
| CommandCost (StringID msg)
| Creates a command return value the is failed with the given message.
| CommandCost (ExpensesType ex_t)
| Creates a command cost with given expense type and start cost of 0. More...
| CommandCost (ExpensesType ex_t, const Money &cst)
| Creates a command return value with the given start cost and expense type. More...
void | AddCost (const Money &cost)
| Adds the given cost to the cost of the command. More...
void | AddCost (const CommandCost &cmd_cost)
| Adds the cost of the given command return value to this cost. More...
void | MultiplyCost (int factor)
| Multiplies the cost of the command by the given factor. More...
Money | GetCost () const
| The costs as made up to this moment. More...
ExpensesType | GetExpensesType () const
| The expense type of the cost. More...
void | MakeError (StringID message)
| Makes this CommandCost behave like an error command. More...
void | UseTextRefStack (const GRFFile *grffile, uint num_registers)
| Activate usage of the NewGRF TextRefStack for the error message. More...
const GRFFile * | GetTextRefStackGRF () const
| Returns the NewGRF providing the TextRefStack of the error message. More...
uint | GetTextRefStackSize () const
| Returns the number of uint32 values for the TextRefStack of the error message. More...
const uint32 * | GetTextRefStack () const
| Returns a pointer to the values for the TextRefStack of the error message. More...
StringID | GetErrorMessage () const
| Returns the error message of a command. More...
bool | Succeeded () const
| Did this command succeed? More...
bool | Failed () const
| Did this command fail? More...

## Private Attributes
ExpensesType | expense_type
| the type of expence as shown on the finances view
Money | cost
| The cost of this action.
StringID | message
| Warning message for when success is unset.
bool | success
| Whether the comment went fine up to this moment.
const GRFFile * | textref_stack_grffile
| NewGRF providing the TextRefStack content.
uint | textref_stack_size
| Number of uint32 values to put on the TextRefStack for the error message.

## Static Private Attributes
static uint32 | textref_stack [16]
| Values to put on the TextRefStack for the error message. More...

## Detailed Description

Common return value for all commands.

Wraps the cost and a possible error message/state together.

Definition at line 23 of file command_type.h.

## Constructor & Destructor Documentation

## ◆ CommandCost() [1/2]

CommandCost::CommandCost | ( | ExpensesType | ex_t | ) |
| inlineexplicit

Creates a command cost with given expense type and start cost of 0.

Parameters

  ex_t | the expense type

Definition at line 48 of file command_type.h.

## ◆ CommandCost() [2/2]

CommandCost::CommandCost | ( | ExpensesType | ex_t,
|  | const Money & | cst
| ) |  |
| inline

Creates a command return value with the given start cost and expense type.

Parameters

  ex_t | the expense type
  cst | the initial cost of this command

Definition at line 55 of file command_type.h.

## Member Function Documentation

## ◆ AddCost() [1/2]

void CommandCost::AddCost | ( | const CommandCost & | ret | ) |

Adds the cost of the given command return value to this cost.

Also takes a possible error message when it is set.

Parameters

  ret | The command to add the cost of.

Definition at line 781 of file command.cpp.

References AddCost(), cost, message, and success.

## ◆ AddCost() [2/2]

void CommandCost::AddCost | ( | const Money & | cost | ) |
| inline

Adds the given cost to the cost of the command.

Parameters

  cost | the cost to add

Definition at line 62 of file command_type.h.

References cost.

Referenced by AddCost(), CheckBuildableTile(), CheckFlatLandAirport(), CheckFlatLandRailStation(), CheckFlatLandRoadStop(), CmdAutoreplaceVehicle(), CmdBuildLongRoad(), CmdBuildRoadDepot(), CmdBuildTrainDepot(), CmdConvertRail(), CmdDepotMassAutoReplace(), CmdLandscapeClear(), CmdSellRailWagon(), CmdTerraformLand(), CopyHeadSpecificThings(), DoBuildLock(), RemoveAirport(), ReplaceChain(), and ReplaceFreeUnit().

## ◆ Failed()

bool CommandCost::Failed | ( |  | ) | const
| inline

Did this command fail?

Returns
  true if and only if it failed

Definition at line 159 of file command_type.h.

References success.

Referenced by BuildReplacementVehicle(), BuildStationPart(), CcAddVehicleNewGroup(), CcBuildBridge(), CcBuildPrimaryVehicle(), CcBuildWagon(), CcCloneVehicle(), CcCreateGroup(), CcPlaceSign(), CcRoadStop(), CcStartStopVehicle(), CheckBuildableTile(), CheckFlatLandAirport(), CheckFlatLandRailStation(), CheckFlatLandRoadStop(), CheckIfIndustryTilesAreFree(), CmdAutofillTimetable(), CmdAutoreplaceVehicle(), CmdBuildLongRoad(), CmdBuildRailStation(), CmdChangeServiceInt(), CmdChangeTimetable(), CmdCloneOrder(), CmdCloneVehicle(), CmdConvertRail(), CmdDeleteOrder(), CmdForceTrainProceed(), CmdInsertOrder(), CmdMoveOrder(), CmdMoveRailVehicle(), CmdOpenCloseAirport(), CmdOrderRefit(), CmdRefitVehicle(), CmdRenameDepot(), CmdRenameStation(), CmdRenameVehicle(), CmdRenameWaypoint(), CmdReverseTrainDirection(), CmdSellRailWagon(), CmdSellVehicle(), CmdSetTimetableStart(), CmdSetVehicleOnTime(), CmdSkipToOrder(), CmdStartStopVehicle(), CmdTerraformLand(), CmdTurnRoadVeh(), DoBuildLock(), DoClearBridge(), DoClearTunnel(), ScriptInstance::DoCommandCallback(), NormalizeTrainVehInDepot(), RemoveAirport(), RemoveBuoy(), RemoveDock(), RemoveFromRailBaseStation(), RemoveLock(), RemoveRoadStop(), ReplaceChain(), Vehicle::SendToDepot(), ShowBuildBridgeWindow(), StationJoinerNeeded(), and ValidateTrains().

## ◆ GetCost()

Money CommandCost::GetCost | ( |  | ) | const
| inline

The costs as made up to this moment.

Returns
  the costs

Definition at line 82 of file command_type.h.

References cost.

Referenced by CheckCompanyHasMoney(), CmdAutoreplaceVehicle(), ScriptInstance::DoCommandCallback(), ReplaceChain(), SubtractMoneyFromAnyCompany(), and SubtractMoneyFromCompanyFract().

## ◆ GetErrorMessage()

StringID CommandCost::GetErrorMessage | ( |  | ) | const
| inline

Returns the error message of a command.

Returns
  the error message, if succeeded INVALID_STRING_ID

Definition at line 140 of file command_type.h.

References INVALID_STRING_ID, and message.

Referenced by CcBuildIndustry(), CmdBuildLongRoad(), ScriptInstance::DoCommandCallback(), and ShowBuildBridgeWindow().

## ◆ GetExpensesType()

ExpensesType CommandCost::GetExpensesType | ( |  | ) | const
| inline

The expense type of the cost.

Returns
  the expense type

Definition at line 91 of file command_type.h.

References expense_type.

Referenced by SubtractMoneyFromAnyCompany().

## ◆ GetTextRefStack()

const uint32* CommandCost::GetTextRefStack | ( |  | ) | const
| inline

Returns a pointer to the values for the TextRefStack of the error message.

Returns
  uint32 values for the TextRefStack

Definition at line 131 of file command_type.h.

References textref_stack.

## ◆ GetTextRefStackGRF()

const GRFFile* CommandCost::GetTextRefStackGRF | ( |  | ) | const
| inline

Returns the NewGRF providing the TextRefStack of the error message.

Returns
  the NewGRF.

Definition at line 113 of file command_type.h.

References textref_stack_grffile.

## ◆ GetTextRefStackSize()

uint CommandCost::GetTextRefStackSize | ( |  | ) | const
| inline

Returns the number of uint32 values for the TextRefStack of the error message.

Returns
  number of uint32 values.

Definition at line 122 of file command_type.h.

References textref_stack_size.

## ◆ MakeError()

void CommandCost::MakeError | ( | StringID | message | ) |
| inline

Makes this CommandCost behave like an error command.

Parameters

  message | The error message.

Definition at line 100 of file command_type.h.

References INVALID_STRING_ID, and message.

Referenced by CheckCompanyHasMoney().

## ◆ MultiplyCost()

void CommandCost::MultiplyCost | ( | int | factor | ) |
| inline

Multiplies the cost of the command by the given factor.

Parameters

  factor | factor to multiply the costs with

Definition at line 73 of file command_type.h.

## ◆ Succeeded()

bool CommandCost::Succeeded | ( |  | ) | const
| inline

Did this command succeed?

Returns
  true if and only if it succeeded

Definition at line 150 of file command_type.h.

References success.

Referenced by CanBuildHouseHere(), CcBuildIndustry(), CcBuildRailTunnel(), CcBuildRoadTunnel(), ClearMakeHouseTile(), CmdAutoreplaceVehicle(), CmdDepotMassAutoReplace(), CopyHeadSpecificThings(), DoBuildLock(), ScriptInstance::DoCommandCallback(), RemoveDock(), RemoveLock(), ReplaceChain(), and ReplaceFreeUnit().

## ◆ UseTextRefStack()

void CommandCost::UseTextRefStack | ( | const GRFFile * | grffile,
|  | uint | num_registers
| ) |  |

Activate usage of the NewGRF TextRefStack for the error message.

Parameters

  grffile | NewGRF that provides the TextRefStack
  num_registers | number of entries to copy from the temporary NewGRF registers

Definition at line 802 of file command.cpp.

Referenced by GetErrorMessageFromLocationCallbackResult().

## Field Documentation

## ◆ textref_stack

uint32 CommandCost::textref_stack
| staticprivate

Values to put on the TextRefStack for the error message.

There is only one static instance of the array, just like there is only one instance of normal DParams.

Definition at line 31 of file command_type.h.

Referenced by GetTextRefStack().

The documentation for this class was generated from the following files:

- src/command_type.h
- src/command.cpp