(svn r18498) -Fix [FS#2616]: cloning of vehicles could create vehicles with invalid cargo sub types for the build year of the vehicle. Fall back to another cargo sub type with the exact same name, otherwise fallback to cargo sub type 0.

This commit is contained in:
rubidium
2009-12-14 19:17:18 +00:00
parent 620ca5e6c1
commit a190ae9a71
3 changed files with 68 additions and 2 deletions

View File

@@ -536,8 +536,10 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
if (flags & DC_EXEC) {
assert(w != NULL);
if (w->cargo_type != v->cargo_type || w->cargo_subtype != v->cargo_subtype) {
CommandCost cost = DoCommand(0, w->index, v->cargo_type | (v->cargo_subtype << 8) | 1U << 16, flags, GetCmdRefitVeh(v));
/* Find out what's the best sub type */
byte subtype = GetBestFittingSubType(v, w);
if (w->cargo_type != v->cargo_type || w->cargo_subtype != subtype) {
CommandCost cost = DoCommand(0, w->index, v->cargo_type | (subtype << 8) | 1U << 16, flags, GetCmdRefitVeh(v));
if (CmdSucceeded(cost)) total_cost.AddCost(cost);
}