@@ -1616,7 +1616,7 @@ static bool AiCheckTrackResources(TileIn
static CommandCost AiDoBuildDefaultRailTrack(TileIndex tile, const AiDefaultBlockData* p, RailType railtype, byte flag)
{
CommandCost ret;
CommandCost total_cost;
CommandCost total_cost(EXPENSES_CONSTRUCTION);
Town *t = NULL;
int rating = 0;
int i, j, k;
@@ -2605,7 +2605,7 @@ static int AiFindBestDefaultRoadBlock(Ti
static CommandCost AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag)
int roadflag = 0;
@@ -3366,7 +3366,7 @@ static void AiStateAirportStuff(Player *
static CommandCost AiDoBuildDefaultAirportBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag)
uint32 avail_airports = GetValidAirports();
CommandCost total_cost, ret;
CommandCost ret,total_cost(EXPENSES_CONSTRUCTION);
for (; p->mode == 0; p++) {
if (!HasBit(avail_airports, p->attr)) return CMD_ERROR;
@@ -234,7 +234,7 @@ void GetAircraftSpriteSize(EngineID engi
static CommandCost EstimateAircraftCost(EngineID engine, const AircraftVehicleInfo *avi)
return CommandCost(GetEngineProperty(engine, 0x0B, avi->base_cost) * (_price.aircraft_base >> 3) >> 5);
return CommandCost(EXPENSES_NEW_VEHICLES, GetEngineProperty(engine, 0x0B, avi->base_cost) * (_price.aircraft_base >> 3) >> 5);
}
@@ -282,8 +282,6 @@ CommandCost CmdBuildAircraft(TileIndex t
if (!IsHangarTile(tile) || !IsTileOwner(tile, _current_player)) return CMD_ERROR;
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
/* Prevent building aircraft types at places which can't handle them */
if (!CanAircraftUseStation(p1, tile)) return CMD_ERROR;
@@ -492,9 +490,7 @@ CommandCost CmdSellAircraft(TileIndex ti
if (HASBITS(v->vehstatus, VS_CRASHED)) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE);
CommandCost ret(-v->value);
CommandCost ret(EXPENSES_NEW_VEHICLES, -v->value);
if (flags & DC_EXEC) {
// Invalidate depot
@@ -650,8 +646,6 @@ CommandCost CmdRefitAircraft(TileIndex t
CargoID new_cid = GB(p2, 0, 8);
if (new_cid >= NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR;
SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_RUN);
/* Check the refit capacity callback */
uint16 callback = CALLBACK_FAILED;
if (HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_REFIT_CAPACITY)) {
@@ -741,11 +735,10 @@ void OnNewDay_Aircraft(Vehicle *v)
if (v->vehstatus & VS_STOPPED) return;
CommandCost cost = CommandCost(GetVehicleProperty(v, 0x0E, AircraftVehInfo(v->engine_type)->running_cost) * _price.aircraft_running / 364);
CommandCost cost = CommandCost(EXPENSES_AIRCRAFT_RUN, GetVehicleProperty(v, 0x0E, AircraftVehInfo(v->engine_type)->running_cost) * _price.aircraft_running / 364);
v->profit_this_year -= cost.GetCost() >> 8;
SubtractMoneyFromPlayerFract(v->owner, cost);
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
@@ -161,12 +161,10 @@ static CommandCost ReplaceVehicle(Vehicl
/* We give the player a loan of the same amount as the sell value.
* This is needed in case he needs the income from the sale to build the new vehicle.
* We take it back if building fails or when we really sell the old engine */
SubtractMoneyFromPlayer(sell_value);
cost = DoCommand(old_v->tile, new_engine_type, 3, flags, GetCmdBuildVeh(old_v));
if (CmdFailed(cost)) {
/* Take back the money we just gave the player */
sell_value.MultiplyCost(-1);
@@ -266,7 +264,6 @@ static CommandCost ReplaceVehicle(Vehicl
/* Ensure that the player will not end up having negative money while autoreplacing
* This is needed because the only other check is done after the income from selling the old vehicle is substracted from the cost */
if (CmdFailed(tmp_move) || p->player_money < (cost.GetCost() + total_cost)) {
/* Pay back the loan */
@@ -276,7 +273,6 @@ static CommandCost ReplaceVehicle(Vehicl
/* Take back the money we just gave the player just before building the vehicle
* The player will get the same amount now that the sale actually takes place */
@@ -336,7 +332,7 @@ CommandCost MaybeReplaceVehicle(Vehicle
v->leave_depot_instantly = false;
for (;;) {
cost = CommandCost();
cost = CommandCost(EXPENSES_NEW_VEHICLES);
w = v;
do {
if (w->type == VEH_TRAIN && IsRearDualheaded(w)) {
@@ -32,7 +32,7 @@ static CommandCost ClearTile_Clear(TileI
&_price.clear_roughland,
};
CommandCost price;
CommandCost price(EXPENSES_CONSTRUCTION);
if (!IsClearGround(tile, CLEAR_GRASS) || GetClearDensity(tile) != 0) {
price.AddCost(*clear_price_table[GetClearGround(tile)]);
@@ -441,7 +441,7 @@ CommandCost DoCommand(TileIndex tile, ui
/* Execute the command here. All cost-relevant functions set the expenses type
* themselves with "SET_EXPENSES_TYPE(...);" at the beginning of the function */
* themselves to the cost object at some point */
res = proc(tile, flags, p1, p2);
if (CmdFailed(res)) {
res.SetGlobalErrorMessage();
@@ -622,7 +622,6 @@ bool DoCommandP(TileIndex tile, uint32 p
/* Actually try and execute the command. If no cost-type is given
* use the construction one */
_yearly_expenses_type = EXPENSES_CONSTRUCTION;
res2 = proc(tile, flags | DC_EXEC, p1, p2);
/* If notest is on, it means the result of the test can be different than
@@ -697,6 +696,11 @@ Money CommandCost::GetCost() const
return this->cost;
ExpensesType CommandCost::GetExpensesType() const
return this->expense_type;
void CommandCost::SetGlobalErrorMessage() const
extern StringID _error_message;
@@ -14,6 +14,7 @@
* a possible error message/state together.
*/
class CommandCost {
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
@@ -22,18 +23,25 @@ public:
/**
* Creates a command cost return with no cost and no error
CommandCost() : cost(0), message(INVALID_STRING_ID), success(true) {}
CommandCost() : expense_type(INVALID_EXPENSES), cost(0), message(INVALID_STRING_ID), success(true) {}
* Creates a command return value the is failed with the given message
CommandCost(StringID msg) : cost(0), message(msg), success(false) {}
CommandCost(StringID msg) : expense_type(INVALID_EXPENSES), cost(0), message(msg), success(false) {}
* Creates a command return value with the given start cost
* Creates a command cost with given expense type and start cost of 0
* @param ex_t the expense type
CommandCost(ExpensesType ex_t) : expense_type(ex_t), cost(0), message(INVALID_STRING_ID), success(true) {}
* Creates a command return value with the given start cost and expense type
* @param cst the initial cost of this command
CommandCost(Money cst) : cost(cst), message(INVALID_STRING_ID), success(true) {}
CommandCost(ExpensesType ex_t, Money cst) : expense_type(ex_t), cost(cst), message(INVALID_STRING_ID), success(true) {}
* Adds the cost of the given command return value to this cost.
@@ -64,6 +72,12 @@ public:
Money GetCost() const;
* The expense type of the cost
* @return the expense type
ExpensesType GetExpensesType() const;
* Sets the global error message *if* this class has one.
void SetGlobalErrorMessage() const;
@@ -103,7 +103,6 @@ Money _additional_cash_required;
Money CalculateCompanyValue(const Player* p)
PlayerID owner = p->index;
/* Do a little nasty by using CommandCost, so we can use the "overflow" protection of CommandCost */
Money value = 0;
Station *st;
@@ -662,8 +661,8 @@ static void PlayersGenStatistics()
FOR_ALL_STATIONS(st) {
_current_player = st->owner;
SET_EXPENSES_TYPE(EXPENSES_PROPERTY);
SubtractMoneyFromPlayer(_price.station_value >> 1);
CommandCost cost(EXPENSES_PROPERTY, _price.station_value >> 1);
SubtractMoneyFromPlayer(cost);
if (!HasBit(1<<0|1<<3|1<<6|1<<9, _cur_month))
@@ -763,12 +762,10 @@ static void PlayersPayInterest()
if (!p->is_active) continue;
_current_player = p->index;
SET_EXPENSES_TYPE(EXPENSES_LOAN_INT);
SubtractMoneyFromPlayer(CommandCost((Money)BigMulSU(p->current_loan, interest, 16)));
SubtractMoneyFromPlayer(CommandCost(EXPENSES_LOAN_INT, (Money)BigMulSU(p->current_loan, interest, 16)));
SET_EXPENSES_TYPE(EXPENSES_OTHER);
SubtractMoneyFromPlayer(_price.station_value >> 2);
SubtractMoneyFromPlayer(CommandCost(EXPENSES_OTHER, _price.station_value >> 2));
@@ -1516,7 +1513,7 @@ void VehiclePayment(Vehicle *front_v)
if (route_profit != 0) {
front_v->profit_this_year += vehicle_profit;
SubtractMoneyFromPlayer(-route_profit);
SubtractMoneyFromPlayer(CommandCost(front_v->GetExpenseType(true), -route_profit));
if (IsLocalPlayer() && !PlayVehicleSound(front_v, VSE_LOAD_UNLOAD)) {
SndPlayVehicleFx(SND_14_CASHTILL, front_v);
@@ -1825,9 +1822,8 @@ static void DoAcquireCompany(Player *p)
PlayerID old_player = _current_player;
for (i = 0; i != 4; i++) {
if (p->share_owners[i] != PLAYER_SPECTATOR) {
_current_player = p->share_owners[i];
SubtractMoneyFromPlayer(CommandCost(-value));
SubtractMoneyFromPlayer(CommandCost(EXPENSES_OTHER, -value));
_current_player = old_player;
@@ -1849,7 +1845,7 @@ extern int GetAmountOwnedBy(const Player
CommandCost CmdBuyShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
Player *p;
CommandCost cost;
CommandCost cost(EXPENSES_OTHER);
/* Check if buying shares is allowed (protection against modified clients) */
/* Cannot buy own shares */
@@ -1860,8 +1856,6 @@ CommandCost CmdBuyShareInCompany(TileInd
/* Cannot buy shares of non-existent nor bankrupted company */
if (!p->is_active) return CMD_ERROR;
/* Protect new companies from hostile takeovers */
if (_cur_year - p->inaugurated_year < 6) return_cmd_error(STR_7080_PROTECTED);
@@ -1911,8 +1905,6 @@ CommandCost CmdSellShareInCompany(TileIn
/* Cannot sell shares of non-existent nor bankrupted company */
/* Those lines are here for network-protection (clients can be slow) */
if (GetAmountOwnedBy(p, _current_player) == 0) return CommandCost();
@@ -1926,7 +1918,7 @@ CommandCost CmdSellShareInCompany(TileIn
*b = PLAYER_SPECTATOR;
InvalidateWindow(WC_COMPANY, p1);
return CommandCost(cost);
return CommandCost(EXPENSES_OTHER, cost);
/** Buy up another company.
@@ -1949,7 +1941,6 @@ CommandCost CmdBuyCompany(TileIndex tile
/* Do not allow players to take over themselves */
if (pid == _current_player) return CMD_ERROR;
p = GetPlayer(pid);
if (!p->is_ai) return CMD_ERROR;
@@ -1957,7 +1948,7 @@ CommandCost CmdBuyCompany(TileIndex tile
DoAcquireCompany(p);
return CommandCost(p->bankrupt_value);
return CommandCost(EXPENSES_OTHER, p->bankrupt_value);
/** Prices */
@@ -124,6 +124,7 @@ enum ExpensesType {
EXPENSES_SHIP_INC = 10,
EXPENSES_LOAN_INT = 11,
EXPENSES_OTHER = 12,
INVALID_EXPENSES = 0xFF,
#endif /* ECONOMY_TYPE_H */
@@ -400,7 +400,7 @@ static CommandCost ClearTile_Industry(Ti
if (flags & DC_EXEC) delete i;
return CommandCost(indspec->GetRemovalCost());
return CommandCost(EXPENSES_CONSTRUCTION, indspec->GetRemovalCost());
static void TransportIndustryGoods(TileIndex tile)
@@ -1590,8 +1590,6 @@ CommandCost CmdBuildIndustry(TileIndex t
const IndustrySpec *indspec;
indspec = GetIndustrySpec(p1);
/* Check if the to-be built/founded industry is available for this climate. */
@@ -1646,7 +1644,7 @@ CommandCost CmdBuildIndustry(TileIndex t
if (CreateNewIndustryHelper(tile, p1, flags, indspec, num) == NULL) return CMD_ERROR;
return CommandCost(indspec->GetConstructionCost());
return CommandCost(EXPENSES_OTHER, indspec->GetConstructionCost());
@@ -2263,10 +2261,10 @@ static CommandCost TerraformTile_Industr
if (HasBit(itspec->callback_flags, CBM_INDT_AUTOSLOPE)) {
/* If the callback fails, allow autoslope. */
uint16 res = GetIndustryTileCallback(CBID_INDUSTRY_AUTOSLOPE, 0, 0, gfx, GetIndustryByTile(tile), tile);
if ((res == 0) || (res == CALLBACK_FAILED)) return _price.terraform;
if ((res == 0) || (res == CALLBACK_FAILED)) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
} else {
/* allow autoslope */
return _price.terraform;
return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
@@ -524,8 +524,6 @@ void ClearSnowLine(void)
CommandCost CmdLandscapeClear(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
return _tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags);
@@ -537,7 +535,8 @@ CommandCost CmdLandscapeClear(TileIndex
CommandCost CmdClearArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
CommandCost cost, ret, money;
CommandCost ret, money;
CommandCost cost(EXPENSES_CONSTRUCTION);
int ex;
int ey;
int sx, sy;
@@ -546,8 +545,6 @@ CommandCost CmdClearArea(TileIndex tile,
if (p1 >= MapSize()) return CMD_ERROR;
/* make sure sx,sy are smaller than ex,ey */
ex = TileX(tile);
ey = TileY(tile);
@@ -157,7 +157,7 @@ CommandCost CmdIncreaseLoan(TileIndex ti
InvalidatePlayerWindows(p);
return CommandCost();
return CommandCost(EXPENSES_OTHER);
/** Decrease the loan of your company.
@@ -357,8 +357,7 @@ CommandCost CmdMoneyCheat(TileIndex tile
#ifndef _DEBUG
if (_networking) return CMD_ERROR;
#endif
return CommandCost(-(Money)p1);
return CommandCost(EXPENSES_OTHER, -(Money)p1);
/** Transfer funds (money) from one player to another.
@@ -375,9 +374,7 @@ CommandCost CmdGiveMoney(TileIndex tile,
if (!_patches.give_money) return CMD_ERROR;
const Player *p = GetPlayer(_current_player);
CommandCost amount(min((Money)p1, (Money)20000000LL));
CommandCost amount(EXPENSES_OTHER, min((Money)p1, (Money)20000000LL));
/* You can only transfer funds that is in excess of your loan */
if (p->player_money - p->current_loan < amount.GetCost() || amount.GetCost() <= 0) return CMD_ERROR;
@@ -387,7 +384,7 @@ CommandCost CmdGiveMoney(TileIndex tile,
/* Add money to player */
PlayerID old_cp = _current_player;
_current_player = (PlayerID)p2;
SubtractMoneyFromPlayer(CommandCost(-amount.GetCost()));
SubtractMoneyFromPlayer(CommandCost(EXPENSES_OTHER, -amount.GetCost()));
_current_player = old_cp;
@@ -192,30 +192,24 @@ bool CheckPlayerHasMoney(CommandCost cos
static void SubtractMoneyFromAnyPlayer(Player *p, CommandCost cost)
CommandCost tmp(p->player_money);
tmp.AddCost(-cost.GetCost());
p->player_money = tmp.GetCost();
if (cost.GetCost() == 0) return;
assert(cost.GetExpensesType() != INVALID_EXPENSES);
tmp = CommandCost(p->yearly_expenses[0][_yearly_expenses_type]);
tmp.AddCost(cost);
p->yearly_expenses[0][_yearly_expenses_type] = tmp.GetCost();
p->player_money -= cost.GetCost();
p->yearly_expenses[0][cost.GetExpensesType()] += cost.GetCost();
if (HasBit(1 << EXPENSES_TRAIN_INC |
1 << EXPENSES_ROADVEH_INC |
1 << EXPENSES_AIRCRAFT_INC |
1 << EXPENSES_SHIP_INC, _yearly_expenses_type)) {
tmp = CommandCost(p->cur_economy.income);
p->cur_economy.income = tmp.GetCost();
1 << EXPENSES_SHIP_INC, cost.GetExpensesType())) {
p->cur_economy.income += cost.GetCost();
} else if (HasBit(1 << EXPENSES_TRAIN_RUN |
1 << EXPENSES_ROADVEH_RUN |
1 << EXPENSES_AIRCRAFT_RUN |
1 << EXPENSES_SHIP_RUN |
1 << EXPENSES_PROPERTY |
1 << EXPENSES_LOAN_INT, _yearly_expenses_type)) {
tmp = CommandCost(p->cur_economy.expenses);
p->cur_economy.expenses = tmp.GetCost();
1 << EXPENSES_LOAN_INT, cost.GetExpensesType())) {
p->cur_economy.expenses += cost.GetCost();
@@ -237,7 +231,7 @@ void SubtractMoneyFromPlayerFract(Player
p->player_money_fraction = m - (byte)cost;
cost >>= 8;
if (p->player_money_fraction > m) cost++;
if (cost != 0) SubtractMoneyFromAnyPlayer(p, CommandCost(cost));
if (cost != 0) SubtractMoneyFromAnyPlayer(p, CommandCost(cst.GetExpensesType(), cost));
void GetNameOfOwner(Owner owner, TileIndex tile)
@@ -288,7 +288,7 @@ static CommandCost CheckRailSlope(Slope
) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
Foundation f_old = GetRailFoundation(tileh, existing);
return CommandCost(f_new != f_old ? _price.terraform : (Money)0);
return CommandCost(EXPENSES_CONSTRUCTION, f_new != f_old ? _price.terraform : (Money)0);
/* Validate functions for rail building */
@@ -306,7 +306,7 @@ CommandCost CmdBuildSingleRail(TileIndex
RailType railtype;
Track track;
TrackBits trackbit;
if (!ValParamRailtype(p1) || !ValParamTrackOrientation((Track)p2)) return CMD_ERROR;
@@ -316,8 +316,6 @@ CommandCost CmdBuildSingleRail(TileIndex
tileh = GetTileSlope(tile, NULL);
trackbit = TrackToTrackBits(track);
switch (GetTileType(tile)) {
case MP_RAILWAY:
if (!CheckTrackCombination(tile, trackbit, flags) ||
@@ -438,14 +436,12 @@ CommandCost CmdRemoveSingleRail(TileInde
Track track = (Track)p2;
CommandCost cost(_price.remove_rail);
CommandCost cost(EXPENSES_CONSTRUCTION, _price.remove_rail );
bool crossing = false;
if (!ValParamTrackOrientation((Track)p2)) return CMD_ERROR;
case MP_ROAD: {
if (!IsLevelCrossing(tile) ||
@@ -624,7 +620,7 @@ static CommandCost ValidateAutoDrag(Trac
static CommandCost CmdRailTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
CommandCost ret, total_cost;
CommandCost ret, total_cost(EXPENSES_CONSTRUCTION);
Track track = (Track)GB(p2, 4, 3);
Trackdir trackdir;
byte mode = HasBit(p2, 7);
@@ -636,8 +632,6 @@ static CommandCost CmdRailTrackHelper(Ti
end_tile = p1;
trackdir = TrackToTrackdir(track);
if (CmdFailed(ValidateAutoDrag(&trackdir, tile, end_tile))) return CMD_ERROR;
if (flags & DC_EXEC) SndPlayTileFx(SND_20_SPLAT_2, tile);
@@ -706,11 +700,8 @@ CommandCost CmdRemoveRailroadTrack(TileI
CommandCost CmdBuildTrainDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
Slope tileh;
/* check railtype and valid direction for depot (0 through 3), 4 in total */
if (!ValParamRailtype(p1)) return CMD_ERROR;
@@ -735,7 +726,7 @@ CommandCost CmdBuildTrainDepot(TileIndex
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
CommandCost cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (CmdFailed(cost)) return CMD_ERROR;
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
@@ -806,21 +797,19 @@ CommandCost CmdBuildSingleSignal(TileInd
/* you can not convert a signal if no signal is on track */
if (convert_signal && !HasSignalOnTrack(tile, track)) return CMD_ERROR;
if (!HasSignalOnTrack(tile, track)) {
/* build new signals */
cost = CommandCost(_price.build_signals);
cost = CommandCost(EXPENSES_CONSTRUCTION, _price.build_signals);
if (p2 != 0 && sigvar != GetSignalVariant(tile, track)) {
/* convert signals <-> semaphores */
cost = CommandCost(_price.build_signals + _price.remove_signals);
cost = CommandCost(EXPENSES_CONSTRUCTION, _price.build_signals + _price.remove_signals);
} else if (convert_signal) {
/* convert button pressed */
if (ctrl_pressed || GetSignalVariant(tile, track) != sigvar) {
/* convert electric <-> semaphore */
/* it is free to change signal type: normal-pre-exit-combo */
@@ -956,7 +945,7 @@ static bool CheckSignalAutoFill(TileInde
static CommandCost CmdSignalTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
int signal_ctr;
byte signals;
bool error = true;
@@ -977,8 +966,6 @@ static CommandCost CmdSignalTrackHelper(
if (!IsTileType(tile, MP_RAILWAY)) return CMD_ERROR;
/* for vertical/horizontal tracks, double the given signals density
* since the original amount will be too dense (shorter tracks) */
signal_density *= 2;
@@ -1101,8 +1088,6 @@ CommandCost CmdRemoveSingleSignal(TileIn
/* Only water can remove signals from anyone */
if (_current_player != OWNER_WATER && !CheckTileOwnership(tile)) return CMD_ERROR;
/* Do it? */
SetPresentSignals(tile, GetPresentSignals(tile) & ~SignalOnTrack(track));
@@ -1120,7 +1105,7 @@ CommandCost CmdRemoveSingleSignal(TileIn
MarkTileDirtyByTile(tile);
return CommandCost(_price.remove_signals);
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_signals);
/** Remove signals on a stretch of track.
@@ -1164,7 +1149,7 @@ void *UpdateTrainPowerProc(Vehicle *v, v
CommandCost CmdConvertRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (!ValParamRailtype(p2)) return CMD_ERROR;
@@ -1180,8 +1165,6 @@ CommandCost CmdConvertRail(TileIndex til
if (ex < sx) Swap(ex, sx);
if (ey < sy) Swap(ey, sy);
_error_message = STR_1005_NO_SUITABLE_RAILROAD_TRACK; // by default, there is no track to convert
for (uint x = sx; x <= ex; ++x) {
@@ -1331,12 +1314,12 @@ static CommandCost RemoveTrainDepot(Tile
YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir)));
return CommandCost(_price.remove_train_depot);
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_train_depot);
static CommandCost ClearTile_Track(TileIndex tile, byte flags)
if (flags & DC_AUTO) {
@@ -2433,7 +2416,7 @@ static CommandCost TestAutoslopeOnRailTi
case TRACK_BIT_UPPER: track_corner = CORNER_N; break;
/* Surface slope must not be changed */
default: return (((z_old != z_new) || (tileh_old != tileh_new)) ? CMD_ERROR : _price.terraform);
default: return (((z_old != z_new) || (tileh_old != tileh_new)) ? CMD_ERROR : CommandCost(EXPENSES_CONSTRUCTION, _price.terraform));
/* The height of the track_corner must not be changed. The rest ensures GetRailFoundation() already. */
@@ -2441,7 +2424,7 @@ static CommandCost TestAutoslopeOnRailTi
z_new += GetSlopeZInCorner((Slope)(tileh_new & ~SLOPE_HALFTILE_MASK), track_corner);
if (z_old != z_new) return CMD_ERROR;
CommandCost cost = CommandCost(_price.terraform);
CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
/* Make the ground dirty, if surface slope has changed */
if (tileh_old != tileh_new) {
if (GetRailGroundType(tile) == RAIL_GROUND_WATER) cost.AddCost(_price.clear_water);
@@ -2488,7 +2471,7 @@ static CommandCost TerraformTile_Track(T
if ((flags & DC_EXEC) != 0) SetRailGroundType(tile, RAIL_GROUND_BARREN);
/* allow terraforming */
return (was_water ? CommandCost(_price.clear_water) : CommandCost());
return CommandCost(EXPENSES_CONSTRUCTION, was_water ? _price.clear_water : (Money)0);
if (_patches.build_on_slopes && AutoslopeEnabled()) {
switch (GetRailTileType(tile)) {
@@ -2499,7 +2482,7 @@ static CommandCost TerraformTile_Track(T
case RAIL_TILE_DEPOT:
if (AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRailDepotDirection(tile))) return _price.terraform;
if (AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRailDepotDirection(tile))) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
break;
default: NOT_REACHED();
@@ -114,8 +114,6 @@ CommandCost CmdRemoveRoad(TileIndex tile
* false if it was a center piece. Affects town ratings drop */
bool edge_road;
RoadType rt = (RoadType)GB(p1, 4, 2);
if (!IsValidRoadType(rt)) return CMD_ERROR;
@@ -156,7 +154,7 @@ CommandCost CmdRemoveRoad(TileIndex tile
/* If it's the last roadtype, just clear the whole tile */
if (rts == RoadTypeToRoadTypes(rt)) return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
/* Pay for *every* tile of the bridge or tunnel */
@@ -181,7 +179,7 @@ CommandCost CmdRemoveRoad(TileIndex tile
return cost;
switch (GetRoadTileType(tile)) {
@@ -224,7 +222,7 @@ CommandCost CmdRemoveRoad(TileIndex tile
return CommandCost(CountBits(c) * _price.remove_road);
return CommandCost(EXPENSES_CONSTRUCTION, CountBits(c) * _price.remove_road);
case ROAD_TILE_CROSSING: {
@@ -250,7 +248,7 @@ CommandCost CmdRemoveRoad(TileIndex tile
YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile)));
return CommandCost(_price.remove_road * 2);
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_road * 2);
default:
@@ -346,7 +344,7 @@ static CommandCost CheckRoadSlope(Slope
*pieces |= MirrorRoadBits(*pieces);
if (existing == ROAD_NONE || existing == *pieces) {
if (*pieces == ROAD_X || *pieces == ROAD_Y) return _price.terraform;
if (*pieces == ROAD_X || *pieces == ROAD_Y) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
return CMD_ERROR;
@@ -358,7 +356,7 @@ static CommandCost CheckRoadSlope(Slope
if (_patches.build_on_slopes && !_is_old_ai_player &&
existing == ROAD_NONE && CountBits(*pieces) == 1 &&
(_valid_tileh_slopes_road[2][tileh] & *pieces) == ROAD_NONE) {
return CommandCost(_price.terraform);
/* no special foundation */
@@ -370,7 +368,7 @@ static CommandCost CheckRoadSlope(Slope
/* foundation is used. Whole tile is leveled up */
if ((~_valid_tileh_slopes_road[1][tileh] & road_bits) == ROAD_NONE) {
return CommandCost(existing != ROAD_NONE ? (Money)0 : _price.terraform);
return CommandCost(EXPENSES_CONSTRUCTION, existing != ROAD_NONE ? (Money)0 : _price.terraform);
/* Force straight roads. */
@@ -378,7 +376,7 @@ static CommandCost CheckRoadSlope(Slope
/* partly leveled up tile, only if there's no road on that tile */
if ((existing == ROAD_NONE || existing == *pieces) && (tileh == SLOPE_W || tileh == SLOPE_S || tileh == SLOPE_E || tileh == SLOPE_N)) {
@@ -393,14 +391,12 @@ static CommandCost CheckRoadSlope(Slope
CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
RoadBits existing = ROAD_NONE;
RoadBits all_bits = ROAD_NONE;
/* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero
* if a non-player is building the road */
if ((IsValidPlayer(_current_player) && p2 != 0) || (_current_player == OWNER_TOWN && !IsValidTownID(p2))) return CMD_ERROR;
@@ -494,7 +490,7 @@ CommandCost CmdBuildRoad(TileIndex tile,
MakeRoadCrossing(tile, _current_player, _current_player, _current_player, GetTileOwner(tile), roaddir, GetRailType(tile), RoadTypeToRoadTypes(rt) | ROADTYPES_ROAD, p2);
return CommandCost(_price.build_road * (rt == ROADTYPE_ROAD ? 2 : 4));
return CommandCost(EXPENSES_CONSTRUCTION, _price.build_road * (rt == ROADTYPE_ROAD ? 2 : 4));
case MP_STATION:
@@ -604,14 +600,12 @@ do_clear:;
CommandCost CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
TileIndex start_tile, tile;
CommandCost cost, ret;
CommandCost ret, cost(EXPENSES_CONSTRUCTION);
bool had_bridge = false;
bool had_tunnel = false;
bool had_success = false;
DisallowedRoadDirections drd = DRD_NORTHBOUND;
start_tile = p1;
@@ -691,9 +685,8 @@ CommandCost CmdBuildLongRoad(TileIndex e
CommandCost CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
Money money;
@@ -713,7 +706,7 @@ CommandCost CmdRemoveLongRoad(TileIndex
p2 ^= IsInsideMM(p2 & 3, 1, 3) ? 3 : 0;
money.AddCost(GetAvailableMoneyForCommand());
money = GetAvailableMoneyForCommand();
tile = start_tile;
/* Start tile is the small number. */
@@ -727,8 +720,8 @@ CommandCost CmdRemoveLongRoad(TileIndex
ret = DoCommand(tile, rt << 4 | bits, 0, flags & ~DC_EXEC, CMD_REMOVE_ROAD);
if (CmdSucceeded(ret)) {
money.AddCost(-ret.GetCost());
if (money.GetCost() < 0) {
money -= ret.GetCost();
if (money < 0) {
_additional_cash_required = DoCommand(end_tile, start_tile, p2, flags & ~DC_EXEC, CMD_REMOVE_LONG_ROAD).GetCost();
@@ -761,8 +754,6 @@ CommandCost CmdBuildRoadDepot(TileIndex
DiagDirection dir = Extract<DiagDirection, 0>(p1);
RoadType rt = (RoadType)GB(p1, 2, 2);
@@ -808,7 +799,7 @@ static CommandCost RemoveRoadDepot(TileI
delete GetDepotByTile(tile);
return CommandCost(_price.remove_road_depot);
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_road_depot);
static CommandCost ClearTile_Road(TileIndex tile, byte flags)
@@ -824,7 +815,7 @@ static CommandCost ClearTile_Road(TileIn
!(flags & DC_AUTO)
) {
RoadTypes rts = GetRoadTypes(tile);
CommandCost ret(EXPENSES_CONSTRUCTION);
for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
if (HasBit(rts, rt)) {
CommandCost tmp_ret = DoCommand(tile, rt << 4 | GetRoadBits(tile, rt), 0, flags, CMD_REMOVE_ROAD);
@@ -839,7 +830,7 @@ static CommandCost ClearTile_Road(TileIn
if (flags & DC_AUTO) return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
@@ -1420,11 +1411,11 @@ static CommandCost TerraformTile_Road(Ti
case ROAD_TILE_CROSSING:
if (!IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new)) && HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh_new)) return _price.terraform;
if (!IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new)) && HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
case ROAD_TILE_DEPOT:
if (AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRoadDepotDirection(tile))) return _price.terraform;
if (AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRoadDepotDirection(tile))) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
case ROAD_TILE_NORMAL: {
@@ -1442,7 +1433,7 @@ static CommandCost TerraformTile_Road(Ti
z_new += ApplyFoundationToSlope(GetRoadFoundation(tileh_new, bits), &tileh_new);
/* The surface slope must not be changed */
if ((z_old == z_new) && (tileh_old == tileh_new)) return _price.terraform;
if ((z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
@@ -125,7 +125,7 @@ void DrawRoadVehEngine(int x, int y, Eng
static CommandCost EstimateRoadVehCost(EngineID engine_type)
return CommandCost(((_price.roadveh_base >> 3) * GetEngineProperty(engine_type, 0x11, RoadVehInfo(engine_type)->base_cost)) >> 5);
return CommandCost(EXPENSES_NEW_VEHICLES, ((_price.roadveh_base >> 3) * GetEngineProperty(engine_type, 0x11, RoadVehInfo(engine_type)->base_cost)) >> 5);
byte GetRoadVehLength(const Vehicle *v)
@@ -172,8 +172,6 @@ CommandCost CmdBuildRoadVeh(TileIndex ti
if (!IsEngineBuildable(p1, VEH_ROAD, _current_player)) return_cmd_error(STR_ROAD_VEHICLE_NOT_AVAILABLE);
cost = EstimateRoadVehCost(p1);
if (flags & DC_QUERY_COST) return cost;
@@ -279,7 +277,7 @@ CommandCost CmdBuildRoadVeh(TileIndex ti
GetPlayer(_current_player)->num_engines[p1]++;
/** Start/Stop a road vehicle.
@@ -366,13 +364,11 @@ CommandCost CmdSellRoadVeh(TileIndex til
if (!CheckRoadVehInDepotStopped(v)) {
return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE);
@@ -2006,7 +2002,7 @@ static void CheckIfRoadVehNeedsService(V
void OnNewDay_RoadVeh(Vehicle *v)
CommandCost cost(EXPENSES_ROADVEH_RUN);
if (!IsRoadVehFront(v)) return;
@@ -2086,12 +2082,11 @@ void OnNewDay_RoadVeh(Vehicle *v)
cost = RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running / 364;
cost = CommandCost(EXPENSES_ROADVEH_RUN, RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running / 364);
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN);
SubtractMoneyFromPlayerFract(v->owner, CommandCost(cost));
InvalidateWindowClasses(WC_ROADVEH_LIST);
@@ -2124,7 +2119,7 @@ void RoadVehiclesYearlyLoop()
CommandCost CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
Vehicle *v;
byte new_subtype = GB(p2, 8, 8);
bool only_this = HasBit(p2, 16);
@@ -2141,8 +2136,6 @@ CommandCost CmdRefitRoadVeh(TileIndex ti
if (new_cid >= NUM_CARGO) return CMD_ERROR;
for (; v != NULL; v = v->Next()) {
/* XXX: We refit all the attached wagons en-masse if they can be
* refitted. This is how TTDPatch does it. TODO: Have some nice
@@ -170,7 +170,7 @@ static void CheckIfShipNeedsService(Vehi
void OnNewDay_Ship(Vehicle *v)
CommandCost cost(EXPENSES_SHIP_RUN);
if ((++v->day_counter & 7) == 0)
DecreaseVehicleValue(v);
@@ -186,8 +186,7 @@ void OnNewDay_Ship(Vehicle *v)
cost.AddCost(GetVehicleProperty(v, 0x0F, ShipVehInfo(v->engine_type)->running_cost) * _price.ship_running / 364);
SET_EXPENSES_TYPE(EXPENSES_SHIP_RUN);
/* we need this for the profit */
@@ -401,7 +400,7 @@ static bool ShipAccelerate(Vehicle *v)
static CommandCost EstimateShipCost(EngineID engine_type)
return CommandCost(GetEngineProperty(engine_type, 0x0A, ShipVehInfo(engine_type)->base_cost) * (_price.ship_base >> 3) >> 5);
return CommandCost(EXPENSES_NEW_VEHICLES, GetEngineProperty(engine_type, 0x0A, ShipVehInfo(engine_type)->base_cost) * (_price.ship_base >> 3) >> 5);
static void ShipArrivesAt(const Vehicle* v, Station* st)
@@ -815,8 +814,6 @@ CommandCost CmdBuildShip(TileIndex tile,
if (!IsEngineBuildable(p1, VEH_SHIP, _current_player)) return_cmd_error(STR_SHIP_NOT_AVAILABLE);
value = EstimateShipCost(p1);
if (flags & DC_QUERY_COST) return value;
@@ -912,13 +909,11 @@ CommandCost CmdSellShip(TileIndex tile,
if (!v->IsStoppedInDepot()) {
return_cmd_error(STR_980B_SHIP_MUST_BE_STOPPED_IN);
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
@@ -1061,7 +1056,7 @@ CommandCost CmdSendShipToDepot(TileIndex
CommandCost CmdRefitShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
CargoID new_cid = GB(p2, 0, 8); //gets the cargo number
uint16 capacity = CALLBACK_FAILED;
@@ -1078,8 +1073,6 @@ CommandCost CmdRefitShip(TileIndex tile,
if (!ShipVehInfo(v->engine_type)->refittable) return CMD_ERROR;
/* Back up the existing cargo type */
@@ -706,7 +706,7 @@ static CommandCost ClearTile_Station(Til
CommandCost CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID *station, bool check_clear = true)
int allowed_z = -1;
BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
@@ -903,8 +903,6 @@ CommandCost CmdBuildRailroadStation(Tile
int w_org, h_org;
/* Does the authority allow this? */
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile_org)) return CMD_ERROR;
if (!ValParamRailtype(p2 & 0xF)) return CMD_ERROR;
@@ -936,7 +934,7 @@ CommandCost CmdBuildRailroadStation(Tile
* https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365 */
ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags & ~DC_EXEC, 5 << axis, _patches.nonuniform_stations ? &est : NULL);
if (CmdFailed(ret)) return ret;
CommandCost cost(ret.GetCost() + (numtracks * _price.train_station_track + _price.train_station_length) * plat_len);
CommandCost cost(EXPENSES_CONSTRUCTION, ret.GetCost() + (numtracks * _price.train_station_track + _price.train_station_length) * plat_len);
Station *st = NULL;
bool check_surrounding = true;
@@ -1176,8 +1174,6 @@ CommandCost CmdRemoveFromRailroadStation
int size_x = ex - sx + 1;
int size_y = ey - sy + 1;
/* Do the action for every tile into the area */
BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) {
/* Make sure the specified tile is a railroad station */
@@ -1234,7 +1230,7 @@ CommandCost CmdRemoveFromRailroadStation
/* If we've not removed any tiles, give an error */
if (quantity == 0) return CMD_ERROR;
return CommandCost(_price.remove_rail_station * quantity);
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_rail_station * quantity);
@@ -1255,7 +1251,7 @@ static CommandCost RemoveRailroadStation
assert(w != 0 && h != 0);
/* clear all areas of the station */
int w_bak = w;
@@ -1346,8 +1342,6 @@ CommandCost CmdBuildRoadStop(TileIndex t
/* Road bits in the wrong direction */
if (build_over_road && (GetAllRoadBits(tile) & ((Axis)p1 == AXIS_X ? ROAD_Y : ROAD_X)) != 0) return_cmd_error(STR_DRIVE_THROUGH_ERROR_DIRECTION);
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) return CMD_ERROR;
@@ -1506,7 +1500,7 @@ static CommandCost RemoveRoadStop(Statio
DeleteStationIfEmpty(st);
return CommandCost((is_truck) ? _price.remove_truck_station : _price.remove_bus_station);
return CommandCost(EXPENSES_CONSTRUCTION, (is_truck) ? _price.remove_truck_station : _price.remove_bus_station);
/** Remove a bus or truck stop
@@ -1645,8 +1639,6 @@ CommandCost CmdBuildAirport(TileIndex ti
bool airport_upgrade = true;
/* Check if a valid, buildable airport was chosen for construction */
if (p1 > lengthof(_airport_sections) || !HasBit(GetValidAirports(), p1)) return CMD_ERROR;
@@ -1673,9 +1665,8 @@ CommandCost CmdBuildAirport(TileIndex ti
int w = afc->size_x;
int h = afc->size_y;
CommandCost ret = CheckFlatLandBelow(tile, w, h, flags, 0, NULL);
CommandCost cost(ret.GetCost());
CommandCost cost = CheckFlatLandBelow(tile, w, h, flags, 0, NULL);
if (CmdFailed(cost)) return cost;
@@ -1780,7 +1771,7 @@ static CommandCost RemoveAirport(Station
CommandCost cost(w * h * _price.remove_airport);
CommandCost cost(EXPENSES_CONSTRUCTION, w * h * _price.remove_airport);
FOR_ALL_VEHICLES(v) {
@@ -1826,8 +1817,6 @@ static CommandCost RemoveAirport(Station
CommandCost CmdBuildBuoy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (!IsWaterTile(tile) || tile == 0) return_cmd_error(STR_304B_SITE_UNSUITABLE);
@@ -1864,7 +1853,7 @@ CommandCost CmdBuildBuoy(TileIndex tile,
st_auto_delete.Detach();
return CommandCost(_price.build_dock);
return CommandCost(EXPENSES_CONSTRUCTION, _price.build_dock);
@@ -1918,7 +1907,7 @@ static CommandCost RemoveBuoy(Station *s
return CommandCost(_price.remove_truck_station);
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_truck_station);
static const TileIndexDiffC _dock_tileoffs_chkaround[] = {
@@ -1940,8 +1929,6 @@ CommandCost CmdBuildDock(TileIndex tile,
DiagDirection direction;
switch (GetTileSlope(tile, NULL)) {
case SLOPE_SW: direction = DIAGDIR_NE; break;
@@ -2033,7 +2020,7 @@ CommandCost CmdBuildDock(TileIndex tile,
/* success, so don't delete the new station */
static CommandCost RemoveDock(Station *st, uint32 flags)
@@ -2063,7 +2050,7 @@ static CommandCost RemoveDock(Station *s
return CommandCost(_price.remove_dock);
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_dock);
#include "table/station_land.h"
@@ -2981,11 +2968,11 @@ static CommandCost TerraformTile_Station
DiagDirection direction = AxisToDiagDir(GetRailStationAxis(tile));
if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, direction)) break;
if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, ReverseDiagDir(direction))) break;
case STATION_AIRPORT:
case STATION_TRUCK:
case STATION_BUS: {
@@ -2994,7 +2981,7 @@ static CommandCost TerraformTile_Station
if (IsDriveThroughStopTile(tile)) {
default: break;
@@ -148,7 +148,7 @@ static void TerraformAddDirtyTileAround(
static CommandCost TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height)
CommandCost total_cost = CommandCost();
assert(tile < MapSize());
@@ -228,11 +228,9 @@ static CommandCost TerraformTileHeight(T
CommandCost CmdTerraformLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
TerraformerState ts;
int direction = (p2 != 0 ? 1 : -1);
_terraform_err_tile = 0;
ts.modheight_count = ts.tile_table_count = 0;
@@ -358,12 +356,10 @@ CommandCost CmdLevelLand(TileIndex tile,
uint h, oldh, curh;
CommandCost money;
/* remember level height */
oldh = TileHeight(p1);
@@ -502,7 +502,7 @@ static void ClickTile_Town(TileIndex til
static CommandCost ClearTile_Town(TileIndex tile, byte flags)
int rating;
Town *t;
HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
@@ -1496,8 +1496,6 @@ CommandCost CmdBuildTown(TileIndex tile,
if (_game_mode != GM_EDITOR) return CMD_ERROR;
if (p2 > TSM_CITY) return CMD_ERROR;
/* Check if too close to the edge of map */
if (DistanceFromEdge(tile) < 12)
return_cmd_error(STR_0237_TOO_CLOSE_TO_EDGE_OF_MAP);
@@ -2097,7 +2095,6 @@ extern uint GetMaskOfTownActions(int *nu
CommandCost CmdDoTownAction(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (!IsValidTownID(p1) || p2 > lengthof(_town_action_proc)) return CMD_ERROR;
@@ -2106,9 +2103,7 @@ CommandCost CmdDoTownAction(TileIndex ti
if (!HasBit(GetMaskOfTownActions(NULL, _current_player, t), p2)) return CMD_ERROR;
cost.AddCost((_price.build_industry >> 8) * _town_action_costs[p2]);
CommandCost cost(EXPENSES_OTHER, (_price.build_industry >> 8) * _town_action_costs[p2]);
_town_action_proc[p2](t);
@@ -2364,7 +2359,7 @@ static CommandCost TerraformTile_Town(Ti
/* Here we differ from TTDP by checking TILE_NOT_SLOPED */
if (((hs->building_flags & TILE_NOT_SLOPED) == 0) && !IsSteepSlope(tileh_new) &&
(GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) return _price.terraform;
(GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
@@ -511,10 +511,8 @@ void DrawTrainEngine(int x, int y, Engin
static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 flags)
const RailVehicleInfo *rvi = RailVehInfo(engine);
CommandCost value((GetEngineProperty(engine, 0x17, rvi->base_cost) * _price.build_railwagon) >> 8);
CommandCost value(EXPENSES_NEW_VEHICLES, (GetEngineProperty(engine, 0x17, rvi->base_cost) * _price.build_railwagon) >> 8);
uint num_vehicles = 1 + CountArticulatedParts(engine, false);
@@ -600,7 +598,7 @@ static CommandCost CmdBuildRailWagon(Eng
return CommandCost(value);
return value;
/** Move all free vehicles in the depot to the train */
@@ -621,7 +619,7 @@ static void NormalizeTrainVehInDepot(con
static CommandCost EstimateTrainCost(EngineID engine, const RailVehicleInfo* rvi)
return CommandCost(GetEngineProperty(engine, 0x17, rvi->base_cost) * (_price.build_railvehicle >> 3) >> 5);
return CommandCost(EXPENSES_NEW_VEHICLES, GetEngineProperty(engine, 0x17, rvi->base_cost) * (_price.build_railvehicle >> 3) >> 5);
static void AddRearEngineToMultiheadedTrain(Vehicle* v, Vehicle* u, bool building)
@@ -671,8 +669,6 @@ CommandCost CmdBuildRailVehicle(TileInde
if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
const RailVehicleInfo *rvi = RailVehInfo(p1);
/* Check if depot and new engine uses the same kind of tracks */
@@ -1313,8 +1309,6 @@ CommandCost CmdSellRailWagon(TileIndex t
while (IsArticulatedPart(v)) v = v->Previous();
Vehicle *first = v->First();
@@ -1334,7 +1328,7 @@ CommandCost CmdSellRailWagon(TileIndex t
RebuildVehicleLists();
CommandCost cost(EXPENSES_NEW_VEHICLES);
switch (p2) {
case 0: case 2: { /* Delete given wagon */
bool switch_engine = false; // update second wagon to engine?
@@ -1804,9 +1798,7 @@ CommandCost CmdRefitRailVehicle(TileInde
/* Check cargo */
SET_EXPENSES_TYPE(EXPENSES_TRAIN_RUN);
CommandCost cost(EXPENSES_TRAIN_RUN);
uint num = 0;
@@ -3481,11 +3473,10 @@ void OnNewDay_Train(Vehicle *v)
if ((v->vehstatus & VS_STOPPED) == 0) {
/* running costs */
CommandCost cost(v->GetRunningCost() / 364);
CommandCost cost(EXPENSES_TRAIN_RUN, v->GetRunningCost() / 364);
@@ -273,7 +273,7 @@ void GenerateTrees()
CommandCost CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
StringID msg = INVALID_STRING_ID;
int sx, sy, x, y;
@@ -282,8 +282,6 @@ CommandCost CmdPlantTree(TileIndex tile,
/* Check the tree type. It can be random or some valid value within the current climate */
if (p1 != (uint)-1 && p1 - _tree_base_by_landscape[_opt.landscape] >= _tree_count_by_landscape[_opt.landscape]) return CMD_ERROR;
// make sure sx,sy are smaller than ex,ey
@@ -499,7 +497,7 @@ static CommandCost ClearTile_Trees(TileI
if (flags & DC_EXEC) DoClearSquare(tile);
return CommandCost(num * _price.remove_trees);
return CommandCost(EXPENSES_CONSTRUCTION, num * _price.remove_trees);
static void GetAcceptedCargo_Trees(TileIndex tile, AcceptedCargo ac)
@@ -123,7 +123,7 @@ static CommandCost CheckBridgeSlopeNorth
valid =
BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_N) | M(SLOPE_STEEP_N) |
(axis == AXIS_X ? M(SLOPE_E) | M(SLOPE_STEEP_E) : M(SLOPE_W) | M(SLOPE_STEEP_W));
if (HasBit(valid, tileh)) return CommandCost(_price.terraform);
if (HasBit(valid, tileh)) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
@@ -138,7 +138,7 @@ static CommandCost CheckBridgeSlopeSouth
BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_S) | M(SLOPE_STEEP_S) |
(axis == AXIS_X ? M(SLOPE_W) | M(SLOPE_STEEP_W) : M(SLOPE_E) | M(SLOPE_STEEP_E));
@@ -197,13 +197,12 @@ CommandCost CmdBuildBridge(TileIndex end
TileIndexDiff delta;
uint bridge_len;
Axis direction;
CommandCost cost, terraformcost, ret;
CommandCost terraformcost, ret;
bool allow_on_slopes;
bool replace_bridge = false;
uint replaced_bridge_type;
/* unpack parameters */
bridge_type = GB(p2, 0, 8);
@@ -458,7 +457,7 @@ CommandCost CmdBuildTunnel(TileIndex sta
Slope end_tileh;
uint start_z;
uint end_z;
_build_tunnel_endtile = 0;
@@ -578,8 +577,6 @@ static CommandCost DoClearTunnel(TileInd
TileIndex endtile;
if (!CheckAllowRemoveTunnelBridge(tile)) return CMD_ERROR;
endtile = GetOtherTunnelEnd(tile);
@@ -617,7 +614,7 @@ static CommandCost DoClearTunnel(TileInd
YapfNotifyTrackLayoutChange(tile, track);
YapfNotifyTrackLayoutChange(endtile, track);
return CommandCost(_price.clear_tunnel * (DistanceManhattan(tile, endtile) + 1));
return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_tunnel * (DistanceManhattan(tile, endtile) + 1));
@@ -628,8 +625,6 @@ static CommandCost DoClearBridge(TileInd
endtile = GetOtherBridgeEnd(tile);
@@ -673,7 +668,7 @@ static CommandCost DoClearBridge(TileInd
return CommandCost((DistanceManhattan(tile, endtile) + 1) * _price.clear_bridge);
return CommandCost(EXPENSES_CONSTRUCTION, (DistanceManhattan(tile, endtile) + 1) * _price.clear_bridge);
static CommandCost ClearTile_TunnelBridge(TileIndex tile, byte flags)
@@ -1398,7 +1393,7 @@ static CommandCost TerraformTile_TunnelB
z_new += ApplyFoundationToSlope(GetBridgeFoundation(tileh_new, axis), &tileh_new);
/* Surface slope remains unchanged? */
@@ -38,8 +38,6 @@ static CommandCost DestroyCompanyHQ(Play
Player* p = GetPlayer(pid);
TileIndex t = p->location_of_house;
@@ -52,7 +50,7 @@ static CommandCost DestroyCompanyHQ(Play
/* cost of relocating company is 1% of company value */
return CommandCost(CalculateCompanyValue(p) / 100);
return CommandCost(EXPENSES_PROPERTY, CalculateCompanyValue(p) / 100);
void UpdateCompanyHQ(Player *p, uint score)
@@ -87,9 +85,7 @@ extern CommandCost CheckFlatLandBelow(Ti
CommandCost CmdBuildCompanyHQ(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
Player *p = GetPlayer(_current_player);
CommandCost cost(EXPENSES_PROPERTY);
cost = CheckFlatLandBelow(tile, 2, 2, flags, 0, NULL);
@@ -122,9 +118,7 @@ CommandCost CmdBuildCompanyHQ(TileIndex
CommandCost CmdPurchaseLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (IsOwnedLandTile(tile) && IsTileOwner(tile, _current_player)) {
return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT);
@@ -151,8 +145,6 @@ CommandCost CmdPurchaseLandArea(TileInde
CommandCost CmdSellLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (!IsOwnedLandTile(tile)) return CMD_ERROR;
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR;
@@ -161,7 +153,7 @@ CommandCost CmdSellLandArea(TileIndex ti
return CommandCost(- _price.clear_roughland * 2);
return CommandCost(EXPENSES_CONSTRUCTION,- _price.clear_roughland * 2);
static Foundation GetFoundation_Unmovable(TileIndex tile, Slope tileh);
@@ -463,7 +455,7 @@ static CommandCost TerraformTile_Unmovab
if (IsOwnedLand(tile) && CheckTileOwnership(tile)) return CommandCost();
if (AutoslopeEnabled() && (IsStatue(tile) || IsCompanyHQ(tile))) {
if (!IsSteepSlope(tileh_new) && (z_new + GetSlopeMaxZ(tileh_new) == GetTileMaxZ(tile))) return _price.terraform;
if (!IsSteepSlope(tileh_new) && (z_new + GetSlopeMaxZ(tileh_new) == GetTileMaxZ(tile))) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
@@ -89,7 +89,6 @@ VARDEF bool _rightclick_emulate;
VARDEF PlayerFace _player_face; ///< for player face storage in openttd.cfg
/* IN/OUT parameters to commands */
VARDEF byte _yearly_expenses_type;
VARDEF TileIndex _build_tunnel_endtile;
VARDEF bool _generating_world;
@@ -110,8 +109,6 @@ VARDEF char *_highscore_file;
VARDEF char *_log_file;
#define SET_EXPENSES_TYPE(x) _yearly_expenses_type = x;
/* landscape.cpp */
extern const byte _tileh_to_sprite[32];
@@ -706,19 +706,33 @@ CargoID FindFirstRefittableCargo(EngineI
CommandCost GetRefitCost(EngineID engine_type)
CommandCost base_cost;
Money base_cost;
ExpensesType expense_type;
switch (GetEngine(engine_type)->type) {
case VEH_SHIP: base_cost.AddCost(_price.ship_base); break;
case VEH_ROAD: base_cost.AddCost(_price.roadveh_base); break;
case VEH_AIRCRAFT: base_cost.AddCost(_price.aircraft_base); break;
case VEH_SHIP:
base_cost = _price.ship_base;
expense_type = EXPENSES_SHIP_RUN;
case VEH_ROAD:
base_cost = _price.roadveh_base;
expense_type = EXPENSES_ROADVEH_RUN;
case VEH_AIRCRAFT:
base_cost = _price.aircraft_base;
expense_type = EXPENSES_AIRCRAFT_RUN;
case VEH_TRAIN:
base_cost.AddCost(2 * ((RailVehInfo(engine_type)->railveh_type == RAILVEH_WAGON) ?
_price.build_railwagon : _price.build_railvehicle));
base_cost = 2 * ((RailVehInfo(engine_type)->railveh_type == RAILVEH_WAGON) ?
_price.build_railwagon : _price.build_railvehicle);
expense_type = EXPENSES_TRAIN_RUN;
default: NOT_REACHED(); break;
return CommandCost((EngInfo(engine_type)->refit_cost * base_cost.GetCost()) >> 10);
return CommandCost(expense_type, (EngInfo(engine_type)->refit_cost * base_cost) >> 10);
static void DoDrawVehicle(const Vehicle *v)
@@ -1697,7 +1711,6 @@ CommandCost CmdDepotMassAutoReplace(Tile
* Because of this, we can't estimate costs due to wagon removal and we will have to always return 0 and pay manually
* Since we pay after each vehicle is replaced and MaybeReplaceVehicle() check if the player got enough money
* we should never reach a condition where the player will end up with negative money from doing this */
SubtractMoneyFromPlayer(ret);
@@ -1726,7 +1739,7 @@ CommandCost CmdCloneVehicle(TileIndex ti
Vehicle *v_front, *v;
Vehicle *w_front, *w, *w_rear;
CommandCost cost, total_cost;
CommandCost cost, total_cost(EXPENSES_NEW_VEHICLES);
uint32 build_argument = 2;
if (!IsValidVehicleID(p1)) return CMD_ERROR;
@@ -1880,9 +1893,6 @@ CommandCost CmdCloneVehicle(TileIndex ti
/* Set the expense type last as refitting will make the cost go towards
* running costs... */
return total_cost;
@@ -3105,7 +3115,6 @@ void Vehicle::BeginLoading()
current_order.type = OT_LOADING;
GetStation(this->last_station_visited)->loading_vehicles.push_back(this);
SET_EXPENSES_TYPE(this->GetExpenseType(true));
VehiclePayment(this);
InvalidateWindow(this->GetVehicleListWindowClass(), this->owner);
@@ -86,9 +86,7 @@ CommandCost CmdBuildShipDepot(TileIndex
TileIndex tile2;
Axis axis = Extract<Axis, 0>(p1);
@@ -120,7 +118,7 @@ CommandCost CmdBuildShipDepot(TileIndex
d_auto_delete.Detach();
return cost.AddCost(_price.build_ship_depot);
return CommandCost(EXPENSES_CONSTRUCTION, _price.build_ship_depot);
void MakeWaterOrCanalDependingOnOwner(TileIndex tile, Owner o)
@@ -154,7 +152,7 @@ static CommandCost RemoveShipDepot(TileI
MarkTileDirtyByTile(tile2);
return CommandCost(_price.remove_ship_depot);
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_ship_depot);
/** build a shiplift */
@@ -195,7 +193,7 @@ static CommandCost DoBuildShiplift(TileI
MarkTileDirtyByTile(tile + delta);
return CommandCost(_price.clear_water * 22 >> 3);
return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water * 22 >> 3);
static CommandCost RemoveShiplift(TileIndex tile, uint32 flags)
@@ -214,7 +212,7 @@ static CommandCost RemoveShiplift(TileIn
MakeWaterOrCanalDependingOnSurroundings(tile - delta, _current_player);
return CommandCost(_price.clear_water * 2);
return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water * 2);
@@ -244,8 +242,6 @@ CommandCost CmdBuildLock(TileIndex tile,
DiagDirection dir;
case SLOPE_SW: dir = DIAGDIR_SW; break;
case SLOPE_SE: dir = DIAGDIR_SE; break;
@@ -264,7 +260,7 @@ CommandCost CmdBuildLock(TileIndex tile,
CommandCost CmdBuildCanal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
int size_x, size_y;
int x;
int y;
@@ -279,8 +275,6 @@ CommandCost CmdBuildCanal(TileIndex tile
sx = TileX(p1);
sy = TileY(p1);
if (x < sx) Swap(x, sx);
if (y < sy) Swap(y, sy);
size_x = (x - sx) + 1;
@@ -341,7 +335,7 @@ static CommandCost ClearTile_Water(TileI
if (GetTileOwner(tile) != OWNER_WATER && GetTileOwner(tile) != OWNER_NONE && !CheckTileOwnership(tile)) return CMD_ERROR;
return CommandCost(_price.clear_water);
return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water);
case WATER_TILE_COAST: {
Slope slope = GetTileSlope(tile, NULL);
@@ -351,9 +345,9 @@ static CommandCost ClearTile_Water(TileI
if (slope == SLOPE_N || slope == SLOPE_E || slope == SLOPE_S || slope == SLOPE_W) {
return CommandCost(_price.clear_roughland);
return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_roughland);
@@ -163,8 +163,6 @@ CommandCost CmdBuildTrainWaypoint(TileIn
Axis axis;
/* if custom gfx are used, make sure it is within bounds */
if (p1 >= GetNumCustomStations(STAT_CLASS_WAYP)) return CMD_ERROR;
@@ -247,7 +245,7 @@ CommandCost CmdBuildTrainWaypoint(TileIn
wp_auto_delete.Detach();
return CommandCost(_price.build_train_depot);
return CommandCost(EXPENSES_CONSTRUCTION, _price.build_train_depot);
@@ -299,7 +297,7 @@ CommandCost RemoveTrainWaypoint(TileInde
@@ -312,7 +310,6 @@ CommandCost RemoveTrainWaypoint(TileInde
CommandCost CmdRemoveTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
return RemoveTrainWaypoint(tile, flags, true);
Status change: