(svn r13685) [0.6] -Backport from trunk: 0.6
authorrubidium
Wed, 09 Jul 2008 18:59:39 +0000
branch0.6
changeset 11127 5e9620220703
parent 10801 3ad9dfb5430d
child 11128 b62a7b45babf
(svn r13685) [0.6] -Backport from trunk:
- Fix: In the case that elrails and 'realistic' acceleration are disabled all electrified engines would have no power on load, until the vehicle got turned around, loaded or got into a depot [FS#2102] (r13681)
- Fix: Saving TTD imported games in recession failed due to wrong (and unneeded) type conversions in the saveload code [FS#2131] (r13679)
- Fix: Inactive companies from old (TTD) saves could be marked active in some cases, which then loads garbage in their statistics and such [FS#2126] (r13676)
- Fix: Desync when building electrified trains on a dedicated server that was started with electrification disabled [FS#2122] (r13673)
- Fix: Clear the memory for the new AI during the loading of a savegame so it does not try to execute commands generated in a different savegame, which could be resulting in the AI trying to give orders to stations that do not exist (r13505)
- Fix: Loading of very old OpenTTD savegames was broken (r13373)
src/economy.cpp
src/economy_type.h
src/elrail.cpp
src/oldloader.cpp
src/openttd.cpp
src/players.cpp
src/saveload.cpp
--- a/src/economy.cpp	Sun Jun 01 16:45:32 2008 +0000
+++ b/src/economy.cpp	Wed Jul 09 18:59:39 2008 +0000
@@ -2011,7 +2011,7 @@
 	SLE_CONDVAR(Economy, max_loan_unround, SLE_FILE_I32 | SLE_VAR_I64,  0, 64),
 	SLE_CONDVAR(Economy, max_loan_unround, SLE_INT64,                  65, SL_MAX_VERSION),
 	SLE_CONDVAR(Economy, max_loan_unround_fract, SLE_UINT16,           70, SL_MAX_VERSION),
-	    SLE_VAR(Economy, fluct,            SLE_FILE_I16 | SLE_VAR_I32),
+	    SLE_VAR(Economy, fluct,            SLE_INT16),
 	    SLE_VAR(Economy, interest_rate,    SLE_UINT8),
 	    SLE_VAR(Economy, infl_amount,      SLE_UINT8),
 	    SLE_VAR(Economy, infl_amount_pr,   SLE_UINT8),
--- a/src/economy_type.h	Sun Jun 01 16:45:32 2008 +0000
+++ b/src/economy_type.h	Wed Jul 09 18:59:39 2008 +0000
@@ -15,7 +15,7 @@
 	Money max_loan;         ///< Maximum possible loan
 	Money max_loan_unround; ///< Economy fluctuation status
 	uint16 max_loan_unround_fract; ///< Fraction of the unrounded max loan
-	int fluct;
+	int16 fluct;
 	byte interest_rate;     ///< Interest
 	byte infl_amount;       ///< inflation amount
 	byte infl_amount_pr;    ///< "floating" portion of inflation
--- a/src/elrail.cpp	Sun Jun 01 16:45:32 2008 +0000
+++ b/src/elrail.cpp	Wed Jul 09 18:59:39 2008 +0000
@@ -502,10 +502,13 @@
 		}
 	}
 
-	/* setup total power for trains */
+	/* Fix the total power and acceleration for trains */
 	FOR_ALL_VEHICLES(v) {
-		/* power is cached only for front engines */
-		if (v->type == VEH_TRAIN && IsFrontEngine(v)) TrainPowerChanged(v);
+		/* power and acceleration is cached only for front engines */
+		if (v->type == VEH_TRAIN && IsFrontEngine(v)) {
+			TrainPowerChanged(v);
+			UpdateTrainAcceleration(v);
+		}
 	}
 
 	FOR_ALL_PLAYERS(p) p->avail_railtypes = GetPlayerRailtypes(p->index);
--- a/src/oldloader.cpp	Sun Jun 01 16:45:32 2008 +0000
+++ b/src/oldloader.cpp	Wed Jul 09 18:59:39 2008 +0000
@@ -993,9 +993,13 @@
 
 	if (!LoadChunk(ls, p, player_chunk)) return false;
 
+	if (_old_string_id == 0) {
+		p->is_active = false;
+		return true;
+	}
+
 	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) {
@@ -1540,7 +1544,7 @@
 
 	OCL_VAR ( OC_FILE_U32 | OC_VAR_I64,   1, &_economy.max_loan ),
 	OCL_VAR ( OC_FILE_U32 | OC_VAR_I64,   1, &_economy.max_loan_unround ),
-	OCL_VAR ( OC_FILE_U16 | OC_VAR_U32,   1, &_economy.fluct ),
+	OCL_VAR (  OC_INT16,    1, &_economy.fluct ),
 
 	OCL_VAR ( OC_UINT16,    1, &_disaster_delay ),
 
--- a/src/openttd.cpp	Sun Jun 01 16:45:32 2008 +0000
+++ b/src/openttd.cpp	Wed Jul 09 18:59:39 2008 +0000
@@ -687,6 +687,8 @@
 
 static void MakeNewGameDone()
 {
+	SettingsDisableElrail(_patches.disable_elrails);
+
 	/* In a dedicated server, the server does not play */
 	if (_network_dedicated) {
 		SetLocalPlayer(PLAYER_SPECTATOR);
@@ -700,7 +702,6 @@
 	_current_player = _local_player;
 	DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
 
-	SettingsDisableElrail(_patches.disable_elrails);
 	SetDefaultRailGui();
 
 #ifdef ENABLE_NETWORK
--- a/src/players.cpp	Sun Jun 01 16:45:32 2008 +0000
+++ b/src/players.cpp	Wed Jul 09 18:59:39 2008 +0000
@@ -1243,8 +1243,11 @@
 		_player_colors[index] = p->player_color;
 
 		/* This is needed so an AI is attached to a loaded AI */
-		if (p->is_ai && (!_networking || _network_server) && _ai.enabled)
+		if (p->is_ai && (!_networking || _network_server) && _ai.enabled) {
+			/* Clear the memory of the new AI, otherwise we might be doing wrong things. */
+			memset(&_players_ainew[index], 0, sizeof(PlayerAiNew));
 			AI_StartNewAI(p->index);
+		}
 	}
 }
 
--- a/src/saveload.cpp	Sun Jun 01 16:45:32 2008 +0000
+++ b/src/saveload.cpp	Wed Jul 09 18:59:39 2008 +0000
@@ -620,10 +620,18 @@
 	/* NOTICE - handle some buggy stuff, in really old versions everything was saved
 	 * as a byte-type. So detect this, and adjust array size accordingly */
 	if (!_sl.save && _sl_version == 0) {
+		/* all arrays except difficulty settings */
 		if (conv == SLE_INT16 || conv == SLE_UINT16 || conv == SLE_STRINGID ||
 				conv == SLE_INT32 || conv == SLE_UINT32) {
-			length *= SlCalcConvFileLen(conv);
-			conv = SLE_INT8;
+			SlCopyBytes(array, length * SlCalcConvFileLen(conv));
+			return;
+		}
+		/* used for conversion of Money 32bit->64bit */
+		if (conv == (SLE_FILE_I32 | SLE_VAR_I64)) {
+			for (uint i = 0; i < length; i++) {
+				((int64*)array)[i] = (int32)BSWAP32(SlReadUint32());
+			}
+			return;
 		}
 	}