src/oldloader.cpp
branchNewGRF_ports
changeset 6872 1c4a4a609f85
parent 6871 5a9dc001e1ad
child 6877 889301acc299
--- a/src/oldloader.cpp	Mon Dec 03 23:39:38 2007 +0000
+++ b/src/oldloader.cpp	Tue Jan 22 21:00:30 2008 +0000
@@ -5,16 +5,12 @@
 #include "stdafx.h"
 #include "openttd.h"
 #include "station_map.h"
-#include "table/strings.h"
-#include "functions.h"
-#include "map.h"
 #include "town.h"
 #include "industry.h"
 #include "station.h"
-#include "economy.h"
-#include "player.h"
+#include "player_func.h"
+#include "player_base.h"
 #include "engine.h"
-#include "vehicle.h"
 #include "aircraft.h"
 #include "roadveh.h"
 #include "ship.h"
@@ -24,7 +20,14 @@
 #include "depot.h"
 #include "newgrf_config.h"
 #include "ai/ai.h"
-#include "date.h"
+#include "ai/default/default.h"
+#include "zoom_func.h"
+#include "functions.h"
+#include "date_func.h"
+#include "vehicle_func.h"
+#include "variables.h"
+
+#include "table/strings.h"
 
 enum {
 	HEADER_SIZE = 49,
@@ -811,10 +814,10 @@
 	Player *p = GetPlayer(_current_player_id);
 
 	switch (num) {
-		case 0: return LoadChunk(ls, &p->ai.src, player_ai_build_rec_chunk);
-		case 1: return LoadChunk(ls, &p->ai.dst, player_ai_build_rec_chunk);
-		case 2: return LoadChunk(ls, &p->ai.mid1, player_ai_build_rec_chunk);
-		case 3: return LoadChunk(ls, &p->ai.mid2, player_ai_build_rec_chunk);
+		case 0: return LoadChunk(ls, &_players_ai[p->index].src, player_ai_build_rec_chunk);
+		case 1: return LoadChunk(ls, &_players_ai[p->index].dst, player_ai_build_rec_chunk);
+		case 2: return LoadChunk(ls, &_players_ai[p->index].mid1, player_ai_build_rec_chunk);
+		case 3: return LoadChunk(ls, &_players_ai[p->index].mid2, player_ai_build_rec_chunk);
 	}
 
 	return false;
@@ -924,11 +927,10 @@
 
 static bool OldPlayerAI(LoadgameState *ls, int num)
 {
-	Player *p = GetPlayer(_current_player_id);
-
-	return LoadChunk(ls, &p->ai, player_ai_chunk);
+	return LoadChunk(ls, &_players_ai[_current_player_id], player_ai_chunk);
 }
 
+uint8 ai_tick;
 static const OldChunks player_chunk[] = {
 	OCL_VAR ( OC_UINT16,   1, &_old_string_id ),
 	OCL_SVAR( OC_UINT32, Player, name_2 ),
@@ -958,7 +960,7 @@
 	OCL_CHUNK( 1, OldPlayerAI ),
 
 	OCL_SVAR(  OC_UINT8, Player, block_preview ),
-	OCL_SVAR(  OC_UINT8, Player, ai.tick ),
+	 OCL_VAR(  OC_UINT8,   1, &ai_tick ),
 	OCL_SVAR(  OC_UINT8, Player, avail_railtypes ),
 	OCL_SVAR(   OC_TILE, Player, location_of_house ),
 	OCL_SVAR(  OC_UINT8, Player, share_owners[0] ),
@@ -982,6 +984,7 @@
 	p->name_1 = RemapOldStringID(_old_string_id);
 	p->president_name_1 = RemapOldStringID(_old_string_id_2);
 	p->player_money = p->player_money;
+	_players_ai[_current_player_id].tick = ai_tick;
 
 	if (num == 0) {
 		/* If the first player has no name, make sure we call it UNNAMED */
@@ -1007,10 +1010,10 @@
 		p->location_of_house = 0;
 
 	/* State 20 for AI players is sell vehicle. Since the AI struct is not
-	 * really figured out as of now, p->ai.cur_veh; needed for 'sell vehicle'
+	 * really figured out as of now, _players_ai[p->index].cur_veh; needed for 'sell vehicle'
 	 * is NULL and the function will crash. To fix this, just change the state
 	 * to some harmless state, like 'loop vehicle'; 1 */
-	if (!IsHumanPlayer((PlayerID)num) && p->ai.state == 20) p->ai.state = 1;
+	if (!IsHumanPlayer((PlayerID)num) && _players_ai[p->index].state == 20) _players_ai[p->index].state = 1;
 
 	if (p->is_ai && (!_networking || _network_server) && _ai.enabled)
 		AI_StartNewAI(p->index);
@@ -1233,7 +1236,8 @@
 
 		if (_old_next_ptr != 0xFFFF) v->next = GetVehiclePoolSize() <= _old_next_ptr ? new (_old_next_ptr) InvalidVehicle() : GetVehicle(_old_next_ptr);
 
-		v->string_id = RemapOldStringID(_old_string_id);
+		_old_string_id = RemapOldStringID(_old_string_id);
+		v->name = CopyFromOldName(_old_string_id);
 
 		/* Vehicle-subtype is different in TTD(Patch) */
 		if (v->type == VEH_SPECIAL) v->subtype = v->subtype >> 1;
@@ -1249,7 +1253,7 @@
 }
 
 static const OldChunks sign_chunk[] = {
-	OCL_SVAR( OC_UINT16, Sign, str ),
+	OCL_VAR ( OC_UINT16, 1, &_old_string_id ),
 	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Sign, x ),
 	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Sign, y ),
 	OCL_SVAR( OC_FILE_U16 | OC_VAR_I8, Sign, z ),
@@ -1261,7 +1265,13 @@
 
 static bool LoadOldSign(LoadgameState *ls, int num)
 {
-	return LoadChunk(ls, new (num) Sign(), sign_chunk);
+	Sign *si = new (num) Sign();
+	if (!LoadChunk(ls, si, sign_chunk)) return false;
+
+	_old_string_id = RemapOldStringID(_old_string_id);
+	si->name = CopyFromOldName(_old_string_id);
+
+	return true;
 }
 
 static const OldChunks engine_chunk[] = {
@@ -1298,6 +1308,13 @@
 	return true;
 }
 
+static bool LoadOldEngineName(LoadgameState *ls, int num)
+{
+	Engine *e = GetEngine(num);
+	e->name = CopyFromOldName(RemapOldStringID(ReadUint16(ls)));
+	return true;
+}
+
 static const OldChunks subsidy_chunk[] = {
 	OCL_SVAR(  OC_UINT8, Subsidy, cargo_type ),
 	OCL_SVAR(  OC_UINT8, Subsidy, age ),
@@ -1504,7 +1521,7 @@
 
 	OCL_NULL( 144 ),             ///< cargo-stuff, calculated in InitializeLandscapeVariables
 
-	OCL_VAR ( OC_UINT16,  256, &_engine_name_strings[0] ),
+	OCL_CHUNK(256, LoadOldEngineName ),
 
 	OCL_NULL( 144 ),             ///< AI cargo-stuff, calculated in InitializeLandscapeVariables
 	OCL_NULL( 2 ),               ///< Company indexes of players, no longer in use
@@ -1622,7 +1639,6 @@
 	for (Engine *e = _engines; e != endof(_engines); e++) {
 		if (_date >= (e->intro_date + 365)) {
 			e->flags = (e->flags & ~ENGINE_EXCLUSIVE_PREVIEW) | ENGINE_AVAILABLE;
-			AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
 			e->player_avail = (byte)-1;
 		}
 	}
@@ -1632,8 +1648,6 @@
 	FixOldStations();
 	FixOldVehicles();
 
-	AddTypeToEngines();
-
 	/* We have a new difficulty setting */
 	_opt.diff.town_council_tolerance = Clamp(_opt.diff_level, 0, 2);