# 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.
| CommandCost (ExpensesType ex_t, const Money &cst)
| Creates a command return value with the given start cost and expense type.
FORCEINLINE void | AddCost (const Money &cost)
| Adds the given cost to the cost of the command.
void | AddCost (const CommandCost &cmd_cost)
| Adds the cost of the given command return value to this cost.
FORCEINLINE void | MultiplyCost (int factor)
| Multiplies the cost of the command by the given factor.
FORCEINLINE Money | GetCost () const
| The costs as made up to this moment.
FORCEINLINE ExpensesType | GetExpensesType () const
| The expense type of the cost.
FORCEINLINE void | SetGlobalErrorMessage () const
| Sets the global error message *if* this class has one.
void | MakeError (StringID message)
| Makes this CommandCost behave like an error command.
StringID | GetErrorMessage () const
| Returns the error message of a command.
FORCEINLINE bool | Succeeded () const
| Did this command succeed?
FORCEINLINE bool | Failed () const
| Did this command fail?

## 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.

## 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::CommandCost | ( | ExpensesType | ex_t | ) | `[inline]`

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

Parameters:

  | ex_t | the expense type

Definition at line 44 of file command_type.h.

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 51 of file command_type.h.

## Member Function Documentation

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 690 of file command.cpp.

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

FORCEINLINE 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 58 of file command_type.h.

Referenced by AddCost(), BuildReplacementVehicle(), CheckFlatLandBelow(), CmdAutoreplaceVehicle(), CmdBuildAirport(), CmdBuildBridge(), CmdBuildCanal(), CmdBuildCompanyHQ(), CmdBuildLongRoad(), CmdBuildRailStation(), CmdBuildRoad(), CmdBuildRoadDepot(), CmdBuildRoadStop(), CmdBuildSingleRail(), CmdBuildTrainDepot(), CmdBuildTunnel(), CmdBuyShareInCompany(), CmdClearArea(), CmdCloneVehicle(), CmdConvertRail(), CmdDepotMassAutoReplace(), CmdDepotSellAllVehicles(), CmdLevelLand(), CmdPlantTree(), CmdPurchaseLandArea(), CmdRailTrackHelper(), CmdRemoveLongRoad(), CmdRemoveSingleRail(), CmdSellRailWagon(), CmdSignalTrackHelper(), CmdTerraformLand(), CopyHeadSpecificThings(), AIObject::IncreaseDoCommandCosts(), RemoveAirport(), RemoveFromRailBaseStation(), RemoveRailStation(), RemoveRoad(), TerraformTileHeight(), and TestAutoslopeOnRailTile().

FORCEINLINE bool CommandCost::Failed | ( |  | ) | const`[inline]`

Did this command fail?

Returns:
  true if and only if it failed

Definition at line 138 of file command_type.h.

References success.

Referenced by BuildReplacementVehicle(), TownViewWindow::CanDeleteTown(), CcBuildPrimaryVehicle(), CcCloneVehicle(), CcCreateGroup(), CcPlaceSign(), CheckFlatLandBelow(), CmdAutoreplaceVehicle(), CmdBuildAirport(), CmdBuildBridge(), CmdBuildCanal(), CmdBuildCompanyHQ(), CmdBuildDock(), CmdBuildLongRoad(), CmdBuildRailStation(), CmdBuildRailWaypoint(), CmdBuildRoad(), CmdBuildRoadDepot(), CmdBuildRoadStop(), CmdBuildShipDepot(), CmdBuildSingleRail(), CmdBuildTrainDepot(), CmdBuildTunnel(), CmdClearArea(), CmdCloneVehicle(), CmdFoundTown(), CmdLevelLand(), CmdMoveRailVehicle(), CmdPlantTree(), CmdPurchaseLandArea(), CmdRailTrackHelper(), CmdRemoveFromRailStation(), CmdSellRailWagon(), CmdTerraformLand(), DoBuildShiplift(), DoCommand(), AIObject::DoCommand(), DoCommandP(), DoCommandPInternal(), IsRoadAllowedHere(), NormalizeTrainVehInDepot(), ShowBuildBridgeWindow(), StationJoinerNeeded(), TerraformTileHeight(), and ValidateTrains().

FORCEINLINE Money CommandCost::GetCost | ( |  | ) | const`[inline]`

The costs as made up to this moment.

Returns:
  the costs

Definition at line 78 of file command_type.h.

References cost.

Referenced by CmdAutoreplaceVehicle(), CmdBuildBridge(), CmdBuildCanal(), CmdBuildRoad(), CmdBuildTunnel(), CmdClearArea(), CmdConvertRail(), CmdDepotSellAllVehicles(), CmdFoundTown(), CmdGiveMoney(), CmdLevelLand(), CmdPlantTree(), CmdRailTrackHelper(), CmdRemoveLongRoad(), AIObject::DoCommand(), DoCommandP(), DoCommandPInternal(), RefitWindow::DrawWidget(), AIObject::GetDoCommandCosts(), Train::OnNewDay(), Ship::OnNewDay(), RoadVehicle::OnNewDay(), Aircraft::OnNewDay(), ReplaceChain(), and ShowBuildBridgeWindow().

StringID CommandCost::GetErrorMessage | ( |  | ) | const`[inline]`

Returns the error message of a command.

Returns:
  the error message, if succeeded INVALID_STRING_ID

Definition at line 116 of file command_type.h.

References INVALID_STRING_ID, message, and success.

FORCEINLINE ExpensesType CommandCost::GetExpensesType | ( |  | ) | const`[inline]`

The expense type of the cost.

Returns:
  the expense type

Definition at line 87 of file command_type.h.

References expense_type.

void CommandCost::MakeError | ( | StringID | message | ) | `[inline]`

Makes this CommandCost behave like an error command.

Parameters:

  | mesasge | the error message.

Definition at line 105 of file command_type.h.

References INVALID_STRING_ID, and success.

FORCEINLINE 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 69 of file command_type.h.

References cost.

Referenced by CmdBuildRoad(), and CmdFoundTown().

FORCEINLINE bool CommandCost::Succeeded | ( |  | ) | const`[inline]`

Did this command succeed?

Returns:
  true if and only if it succeeded

Definition at line 129 of file command_type.h.

References success.

Referenced by BuildReplacementVehicle(), CanBuildHouseHere(), CanBuildTramTrackOnTile(), CcBuildBridge(), CcBuildRailTunnel(), ClearMakeHouseTile(), CmdAutoreplaceVehicle(), CmdCloneVehicle(), CmdDepotMassAutoReplace(), CmdDepotSellAllVehicles(), CmdRemoveLongRoad(), CmdRemoveRoadStop(), CmdSignalTrackHelper(), CopyHeadSpecificThings(), DoCommandP(), RefitWindow::DrawWidget(), AIVehicle::GetRefitCapacity(), GrowTown(), GrowTownWithRoad(), ReplaceChain(), and SendAllVehiclesToDepot().

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

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