src/oldloader.cpp
changeset 9749 ad943e548576
parent 9659 187142ff9b6c
child 9941 8549448b55fa
equal deleted inserted replaced
9748:9b3dd7b52b29 9749:ad943e548576
   335 			Swap(st->trainst_w, st->trainst_h);
   335 			Swap(st->trainst_w, st->trainst_h);
   336 		}
   336 		}
   337 	}
   337 	}
   338 }
   338 }
   339 
   339 
       
   340 static StringID *_old_vehicle_names = NULL;
       
   341 
   340 static void FixOldVehicles()
   342 static void FixOldVehicles()
   341 {
   343 {
   342 	/* Check for shared orders, and link them correctly */
   344 	/* Check for shared orders, and link them correctly */
   343 	Vehicle* v;
   345 	Vehicle* v;
   344 
   346 
   345 	FOR_ALL_VEHICLES(v) {
   347 	FOR_ALL_VEHICLES(v) {
   346 		Vehicle *u;
   348 		Vehicle *u;
       
   349 
       
   350 		v->name = CopyFromOldName(_old_vehicle_names[v->index]);
   347 
   351 
   348 		/* We haven't used this bit for stations for ages */
   352 		/* We haven't used this bit for stations for ages */
   349 		if (v->type == VEH_ROAD &&
   353 		if (v->type == VEH_ROAD &&
   350 				v->u.road.state != RVSB_IN_DEPOT &&
   354 				v->u.road.state != RVSB_IN_DEPOT &&
   351 				v->u.road.state != RVSB_WORMHOLE) {
   355 				v->u.road.state != RVSB_WORMHOLE) {
   424 	/* TTDPatch misuses _old_map3 for flags.. read them! */
   428 	/* TTDPatch misuses _old_map3 for flags.. read them! */
   425 	_old_vehicle_multiplier = _old_map3[0];
   429 	_old_vehicle_multiplier = _old_map3[0];
   426 	/* Somehow.... there was an error in some savegames, so 0 becomes 1
   430 	/* Somehow.... there was an error in some savegames, so 0 becomes 1
   427 	and 1 becomes 2. The rest of the values are okay */
   431 	and 1 becomes 2. The rest of the values are okay */
   428 	if (_old_vehicle_multiplier < 2) _old_vehicle_multiplier++;
   432 	if (_old_vehicle_multiplier < 2) _old_vehicle_multiplier++;
       
   433 
       
   434 	_old_vehicle_names = MallocT<StringID>(_old_vehicle_multiplier * 850);
   429 
   435 
   430 	/* TTDPatch increases the Vehicle-part in the middle of the game,
   436 	/* TTDPatch increases the Vehicle-part in the middle of the game,
   431 	so if the multipler is anything else but 1, the assert fails..
   437 	so if the multipler is anything else but 1, the assert fails..
   432 	bump the assert value so it doesn't!
   438 	bump the assert value so it doesn't!
   433 	(1 multipler == 850 vehicles
   439 	(1 multipler == 850 vehicles
  1277 			default:   v->spritenum >>= 1; break;
  1283 			default:   v->spritenum >>= 1; break;
  1278 		}
  1284 		}
  1279 
  1285 
  1280 		if (_old_next_ptr != 0xFFFF) v->next = GetVehiclePoolSize() <= _old_next_ptr ? new (_old_next_ptr) InvalidVehicle() : GetVehicle(_old_next_ptr);
  1286 		if (_old_next_ptr != 0xFFFF) v->next = GetVehiclePoolSize() <= _old_next_ptr ? new (_old_next_ptr) InvalidVehicle() : GetVehicle(_old_next_ptr);
  1281 
  1287 
  1282 		_old_string_id = RemapOldStringID(_old_string_id);
  1288 		_old_vehicle_names[_current_vehicle_id] = RemapOldStringID(_old_string_id);
  1283 		v->name = CopyFromOldName(_old_string_id);
  1289 		v->name = NULL;
  1284 
  1290 
  1285 		/* Vehicle-subtype is different in TTD(Patch) */
  1291 		/* Vehicle-subtype is different in TTD(Patch) */
  1286 		if (v->type == VEH_EFFECT) v->subtype = v->subtype >> 1;
  1292 		if (v->type == VEH_EFFECT) v->subtype = v->subtype >> 1;
  1287 
  1293 
  1288 		if (_cargo_count != 0) {
  1294 		if (_cargo_count != 0) {
  1624 	fseek(ls->file, HEADER_SIZE, SEEK_SET);
  1630 	fseek(ls->file, HEADER_SIZE, SEEK_SET);
  1625 
  1631 
  1626 	DEBUG(oldloader, 3, "Reading main chunk...");
  1632 	DEBUG(oldloader, 3, "Reading main chunk...");
  1627 	/* Load the biggest chunk */
  1633 	/* Load the biggest chunk */
  1628 	_old_map3 = MallocT<byte>(OLD_MAP_SIZE * 2);
  1634 	_old_map3 = MallocT<byte>(OLD_MAP_SIZE * 2);
       
  1635 	_old_vehicle_names = NULL;
  1629 	if (!LoadChunk(ls, NULL, main_chunk)) {
  1636 	if (!LoadChunk(ls, NULL, main_chunk)) {
  1630 		DEBUG(oldloader, 0, "Loading failed");
  1637 		DEBUG(oldloader, 0, "Loading failed");
  1631 		free(_old_map3);
  1638 		free(_old_map3);
       
  1639 		free(_old_vehicle_names);
  1632 		return false;
  1640 		return false;
  1633 	}
  1641 	}
  1634 	DEBUG(oldloader, 3, "Done, converting game data...");
  1642 	DEBUG(oldloader, 3, "Done, converting game data...");
  1635 
  1643 
  1636 	/* Fix some general stuff */
  1644 	/* Fix some general stuff */
  1700 
  1708 
  1701 	DEBUG(oldloader, 3, "Finished converting game data");
  1709 	DEBUG(oldloader, 3, "Finished converting game data");
  1702 	DEBUG(oldloader, 1, "TTD(Patch) savegame successfully converted");
  1710 	DEBUG(oldloader, 1, "TTD(Patch) savegame successfully converted");
  1703 
  1711 
  1704 	free(_old_map3);
  1712 	free(_old_map3);
       
  1713 	free(_old_vehicle_names);
  1705 
  1714 
  1706 	return true;
  1715 	return true;
  1707 }
  1716 }
  1708 
  1717 
  1709 bool LoadOldSaveGame(const char *file)
  1718 bool LoadOldSaveGame(const char *file)