(svn r13884) -Fix (r11822): custom vehicle names from TTD(Patch) games were lost
authorsmatz
Wed, 30 Jul 2008 17:41:02 +0000
changeset 9749 ad943e548576
parent 9748 9b3dd7b52b29
child 9750 7114408dd1fa
(svn r13884) -Fix (r11822): custom vehicle names from TTD(Patch) games were lost
src/oldloader.cpp
--- a/src/oldloader.cpp	Wed Jul 30 17:39:26 2008 +0000
+++ b/src/oldloader.cpp	Wed Jul 30 17:41:02 2008 +0000
@@ -337,6 +337,8 @@
 	}
 }
 
+static StringID *_old_vehicle_names = NULL;
+
 static void FixOldVehicles()
 {
 	/* Check for shared orders, and link them correctly */
@@ -345,6 +347,8 @@
 	FOR_ALL_VEHICLES(v) {
 		Vehicle *u;
 
+		v->name = CopyFromOldName(_old_vehicle_names[v->index]);
+
 		/* We haven't used this bit for stations for ages */
 		if (v->type == VEH_ROAD &&
 				v->u.road.state != RVSB_IN_DEPOT &&
@@ -427,6 +431,8 @@
 	and 1 becomes 2. The rest of the values are okay */
 	if (_old_vehicle_multiplier < 2) _old_vehicle_multiplier++;
 
+	_old_vehicle_names = MallocT<StringID>(_old_vehicle_multiplier * 850);
+
 	/* TTDPatch increases the Vehicle-part in the middle of the game,
 	so if the multipler is anything else but 1, the assert fails..
 	bump the assert value so it doesn't!
@@ -1279,8 +1285,8 @@
 
 		if (_old_next_ptr != 0xFFFF) v->next = GetVehiclePoolSize() <= _old_next_ptr ? new (_old_next_ptr) InvalidVehicle() : GetVehicle(_old_next_ptr);
 
-		_old_string_id = RemapOldStringID(_old_string_id);
-		v->name = CopyFromOldName(_old_string_id);
+		_old_vehicle_names[_current_vehicle_id] = RemapOldStringID(_old_string_id);
+		v->name = NULL;
 
 		/* Vehicle-subtype is different in TTD(Patch) */
 		if (v->type == VEH_EFFECT) v->subtype = v->subtype >> 1;
@@ -1626,9 +1632,11 @@
 	DEBUG(oldloader, 3, "Reading main chunk...");
 	/* Load the biggest chunk */
 	_old_map3 = MallocT<byte>(OLD_MAP_SIZE * 2);
+	_old_vehicle_names = NULL;
 	if (!LoadChunk(ls, NULL, main_chunk)) {
 		DEBUG(oldloader, 0, "Loading failed");
 		free(_old_map3);
+		free(_old_vehicle_names);
 		return false;
 	}
 	DEBUG(oldloader, 3, "Done, converting game data...");
@@ -1702,6 +1710,7 @@
 	DEBUG(oldloader, 1, "TTD(Patch) savegame successfully converted");
 
 	free(_old_map3);
+	free(_old_vehicle_names);
 
 	return true;
 }