From e8d40d6a1987220137e386b1f505947de8d8b514 Mon Sep 17 00:00:00 2001 From: alberth Date: Sun, 14 Feb 2010 15:30:08 +0000 Subject: (svn r19128) -Codechange: CommandCost cost methods return void instead of a copy of *this. --- src/command.cpp | 8 ++++++-- src/command_type.h | 17 ++++------------- src/rail_cmd.cpp | 6 ++++-- src/road_cmd.cpp | 3 ++- src/unmovable_cmd.cpp | 3 ++- 5 files changed, 18 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/command.cpp b/src/command.cpp index 3a20b7e82..1e422a777 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -682,12 +682,16 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, #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); if (this->success && !ret.success) { this->message = ret.message; this->success = false; } - return *this; } diff --git a/src/command_type.h b/src/command_type.h index a02ac750f..100a96bc9 100644 --- a/src/command_type.h +++ b/src/command_type.h @@ -50,34 +50,25 @@ public: */ 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. * @param cost the cost to add - * @return this class. */ - CommandCost AddCost(Money cost) + void AddCost(Money cost) { this->cost += cost; - return *this; } + void AddCost(CommandCost ret); + /** * Multiplies the cost of the command by the given factor. * @param factor factor to multiply the costs with - * @return this class */ - CommandCost MultiplyCost(int factor) + void MultiplyCost(int factor) { this->cost *= factor; - return *this; } /** diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 199adc666..56827b8ef 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -493,7 +493,8 @@ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, u YapfNotifyTrackLayoutChange(tile, track); } - return cost.AddCost(RailBuildCost(railtype)); + cost.AddCost(RailBuildCost(railtype)); + return cost; } /** Remove a single piece of track @@ -866,7 +867,8 @@ CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, u 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, diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index c877bf0ef..8ee878745 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -888,7 +888,8 @@ CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, ui MakeRoadDepot(tile, _current_company, dep->index, dir, rt); 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) diff --git a/src/unmovable_cmd.cpp b/src/unmovable_cmd.cpp index c48263abd..6f2359d28 100644 --- a/src/unmovable_cmd.cpp +++ b/src/unmovable_cmd.cpp @@ -159,7 +159,8 @@ CommandCost CmdPurchaseLandArea(TileIndex tile, DoCommandFlag flags, uint32 p1, 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 -- cgit v1.2.3-54-g00ecf