Changeset - r14547:a4cc19b19cd3
[Not reviewed]
master
0 5 0
alberth - 14 years ago 2010-02-14 15:30:08
alberth@openttd.org
(svn r19128) -Codechange: CommandCost cost methods return void instead of a copy of *this.
5 files changed with 18 insertions and 19 deletions:
0 comments (0 inline, 0 general)
src/command.cpp
Show inline comments
 
@@ -682,12 +682,16 @@ CommandCost DoCommandPInternal(TileIndex
 
#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;
 
}
src/command_type.h
Show inline comments
 
@@ -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;
 
	}
 

	
 
	/**
src/rail_cmd.cpp
Show inline comments
 
@@ -493,7 +493,8 @@ CommandCost CmdBuildSingleRail(TileIndex
 
		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
 
		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,
src/road_cmd.cpp
Show inline comments
 
@@ -888,7 +888,8 @@ CommandCost CmdBuildRoadDepot(TileIndex 
 
		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)
src/unmovable_cmd.cpp
Show inline comments
 
@@ -159,7 +159,8 @@ CommandCost CmdPurchaseLandArea(TileInde
 
		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
0 comments (0 inline, 0 general)