summaryrefslogtreecommitdiff
path: root/vehicle.c
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2005-12-05 16:48:07 +0000
committerpeter1138 <peter1138@openttd.org>2005-12-05 16:48:07 +0000
commit414481cdd8732223fea40a9efd5e30463e7521a1 (patch)
treeb27915055e3c2ae58df0609bc2e9abc472b0562b /vehicle.c
parent0f2a0df16591a8f23b03b800b780090cf9b88c9a (diff)
downloadopenttd-414481cdd8732223fea40a9efd5e30463e7521a1.tar.xz
(svn r3261) - Autoreplace: If a replaced vehicle had a custom name, transfer it to the new vehicle. Fixes "[ 1370039 ] Autoreplaced vehicles lose their names"
Diffstat (limited to 'vehicle.c')
-rw-r--r--vehicle.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/vehicle.c b/vehicle.c
index dbf65f494..f87c075d4 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -1617,6 +1617,7 @@ static int32 ReplaceVehicle(Vehicle **w, byte flags)
const UnitID cached_unitnumber = old_v->unitnumber;
bool new_front = false;
Vehicle *new_v = NULL;
+ char vehicle_name[32];
new_engine_type = EngineReplacement(p, old_v->engine_type);
if (new_engine_type == INVALID_ENGINE) new_engine_type = old_v->engine_type;
@@ -1665,6 +1666,13 @@ static int32 ReplaceVehicle(Vehicle **w, byte flags)
}
/* We are done setting up the new vehicle. Now we move the cargo from the old one to the new one */
MoveVehicleCargo(new_v->type == VEH_Train ? GetFirstVehicleInChain(new_v) : new_v, old_v);
+
+ // Get the name of the old vehicle if it has a custom name.
+ if ((old_v->string_id & 0xF800) != 0x7800) {
+ vehicle_name[0] = '\0';
+ } else {
+ GetName(old_v->string_id & 0x7FF, vehicle_name);
+ }
}
// sell the engine/ find out how much you get for the old engine
@@ -1675,6 +1683,12 @@ static int32 ReplaceVehicle(Vehicle **w, byte flags)
new_v->unitnumber = cached_unitnumber;
}
+ // Transfer the name of the old vehicle.
+ if ((flags & DC_EXEC) && vehicle_name[0] != '\0') {
+ _cmd_text = vehicle_name;
+ DoCommand(0, 0, new_v->index, 0, DC_EXEC, CMD_NAME_VEHICLE);
+ }
+
return cost;
}