File diff r11916:e3a8d08bf479 → r11917:612c11f7ab47
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -44,13 +44,13 @@ bool CheckAutoreplaceValidity(EngineID f
 
	 * check that it's an engine that is in the engine array */
 
	if (!IsEngineIndex(from) || !IsEngineIndex(to)) return false;
 

	
 
	/* we can't replace an engine into itself (that would be autorenew) */
 
	if (from == to) return false;
 

	
 
	VehicleType type = GetEngine(from)->type;
 
	VehicleType type = Engine::Get(from)->type;
 

	
 
	/* check that the new vehicle type is available to the company and its type is the same as the original one */
 
	if (!IsEngineBuildable(to, type, company)) return false;
 

	
 
	switch (type) {
 
		case VEH_TRAIN: {
 
@@ -244,25 +244,25 @@ static EngineID GetNewEngineType(const V
 
 */
 
static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehicle, bool part_of_chain)
 
{
 
	*new_vehicle = NULL;
 

	
 
	/* Shall the vehicle be replaced? */
 
	const Company *c = GetCompany(_current_company);
 
	const Company *c = Company::Get(_current_company);
 
	EngineID e = GetNewEngineType(old_veh, c);
 
	if (e == INVALID_ENGINE) return CommandCost(); // neither autoreplace is set, nor autorenew is triggered
 

	
 
	/* Does it need to be refitted */
 
	CargoID refit_cargo = GetNewCargoTypeForReplace(old_veh, e, part_of_chain);
 
	if (refit_cargo == CT_INVALID) return CommandCost(); // incompatible cargos
 

	
 
	/* Build the new vehicle */
 
	CommandCost cost = DoCommand(old_veh->tile, e, 0, DC_EXEC | DC_AUTOREPLACE, GetCmdBuildVeh(old_veh));
 
	if (cost.Failed()) return cost;
 

	
 
	Vehicle *new_veh = GetVehicle(_new_vehicle_id);
 
	Vehicle *new_veh = Vehicle::Get(_new_vehicle_id);
 
	*new_vehicle = new_veh;
 

	
 
	/* Refit the vehicle if needed */
 
	if (refit_cargo != CT_NO_REFIT) {
 
		cost.AddCost(DoCommand(0, new_veh->index, refit_cargo, DC_EXEC, GetCmdRefitVeh(new_veh)));
 
		assert(cost.Succeeded()); // This should be ensured by GetNewCargoTypeForReplace()
 
@@ -606,13 +606,13 @@ static CommandCost ReplaceChain(Vehicle 
 
CommandCost CmdAutoreplaceVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES, 0);
 
	bool nothing_to_do = true;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
	Vehicle *v = GetVehicle(p1);
 
	Vehicle *v = Vehicle::Get(p1);
 
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 
	if (!v->IsInDepot()) return CMD_ERROR;
 
	if (HASBITS(v->vehstatus, VS_CRASHED)) return CMD_ERROR;
 

	
 
	bool free_wagon = false;
 
	if (v->type == VEH_TRAIN) {
 
@@ -620,13 +620,13 @@ CommandCost CmdAutoreplaceVehicle(TileIn
 
		free_wagon = !IsFrontEngine(v);
 
		if (free_wagon && IsFrontEngine(v->First())) return CMD_ERROR;
 
	} else {
 
		if (!v->IsPrimaryVehicle()) return CMD_ERROR;
 
	}
 

	
 
	const Company *c = GetCompany(_current_company);
 
	const Company *c = Company::Get(_current_company);
 
	bool wagon_removal = c->settings.renew_keep_length;
 

	
 
	/* Test whether any replacement is set, before issuing a whole lot of commands that would end in nothing changed */
 
	Vehicle *w = v;
 
	bool any_replacements = false;
 
	while (w != NULL && !any_replacements) {