mirror of https://github.com/OpenTTD/OpenTTD
(svn r19128) -Codechange: CommandCost cost methods return void instead of a copy of *this.
parent
151babee57
commit
e8d40d6a19
|
@ -682,12 +682,16 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd,
|
||||||
#undef return_dcpi
|
#undef return_dcpi
|
||||||
|
|
||||||
|
|
||||||
CommandCost CommandCost::AddCost(CommandCost ret)
|
/**
|
||||||
|
* Adds the cost of the given command return value to this cost.
|
||||||
|
* Also takes a possible error message when it is set.
|
||||||
|
* @param ret The command to add the cost of.
|
||||||
|
*/
|
||||||
|
void CommandCost::AddCost(CommandCost ret)
|
||||||
{
|
{
|
||||||
this->AddCost(ret.cost);
|
this->AddCost(ret.cost);
|
||||||
if (this->success && !ret.success) {
|
if (this->success && !ret.success) {
|
||||||
this->message = ret.message;
|
this->message = ret.message;
|
||||||
this->success = false;
|
this->success = false;
|
||||||
}
|
}
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,34 +50,25 @@ public:
|
||||||
*/
|
*/
|
||||||
CommandCost(ExpensesType ex_t, Money cst) : expense_type(ex_t), 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.
|
|
||||||
* Also takes a possible error message when it is set.
|
|
||||||
* @param ret the command to add the cost of.
|
|
||||||
* @return this class.
|
|
||||||
*/
|
|
||||||
CommandCost AddCost(CommandCost ret);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the given cost to the cost of the command.
|
* Adds the given cost to the cost of the command.
|
||||||
* @param cost the cost to add
|
* @param cost the cost to add
|
||||||
* @return this class.
|
|
||||||
*/
|
*/
|
||||||
CommandCost AddCost(Money cost)
|
void AddCost(Money cost)
|
||||||
{
|
{
|
||||||
this->cost += cost;
|
this->cost += cost;
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddCost(CommandCost ret);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Multiplies the cost of the command by the given factor.
|
* Multiplies the cost of the command by the given factor.
|
||||||
* @param factor factor to multiply the costs with
|
* @param factor factor to multiply the costs with
|
||||||
* @return this class
|
|
||||||
*/
|
*/
|
||||||
CommandCost MultiplyCost(int factor)
|
void MultiplyCost(int factor)
|
||||||
{
|
{
|
||||||
this->cost *= factor;
|
this->cost *= factor;
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -493,7 +493,8 @@ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
||||||
YapfNotifyTrackLayoutChange(tile, track);
|
YapfNotifyTrackLayoutChange(tile, track);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cost.AddCost(RailBuildCost(railtype));
|
cost.AddCost(RailBuildCost(railtype));
|
||||||
|
return cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Remove a single piece of track
|
/** Remove a single piece of track
|
||||||
|
@ -866,7 +867,8 @@ CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
||||||
YapfNotifyTrackLayoutChange(tile, DiagDirToDiagTrack(dir));
|
YapfNotifyTrackLayoutChange(tile, DiagDirToDiagTrack(dir));
|
||||||
}
|
}
|
||||||
|
|
||||||
return cost.AddCost(_price[PR_BUILD_DEPOT_TRAIN]);
|
cost.AddCost(_price[PR_BUILD_DEPOT_TRAIN]);
|
||||||
|
return cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Build signals, alternate between double/single, signal/semaphore,
|
/** Build signals, alternate between double/single, signal/semaphore,
|
||||||
|
|
|
@ -888,7 +888,8 @@ CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
|
||||||
MakeRoadDepot(tile, _current_company, dep->index, dir, rt);
|
MakeRoadDepot(tile, _current_company, dep->index, dir, rt);
|
||||||
MarkTileDirtyByTile(tile);
|
MarkTileDirtyByTile(tile);
|
||||||
}
|
}
|
||||||
return cost.AddCost(_price[PR_BUILD_DEPOT_ROAD]);
|
cost.AddCost(_price[PR_BUILD_DEPOT_ROAD]);
|
||||||
|
return cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CommandCost RemoveRoadDepot(TileIndex tile, DoCommandFlag flags)
|
static CommandCost RemoveRoadDepot(TileIndex tile, DoCommandFlag flags)
|
||||||
|
|
|
@ -159,7 +159,8 @@ CommandCost CmdPurchaseLandArea(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
||||||
MarkTileDirtyByTile(tile);
|
MarkTileDirtyByTile(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cost.AddCost(GetUnmovableSpec(UNMOVABLE_OWNED_LAND)->GetBuildingCost());
|
cost.AddCost(GetUnmovableSpec(UNMOVABLE_OWNED_LAND)->GetBuildingCost());
|
||||||
|
return cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sell a land area. Actually you only sell one tile, so
|
/** Sell a land area. Actually you only sell one tile, so
|
||||||
|
|
Loading…
Reference in New Issue