(svn r8870) [0.5] -Backport from trunk (r8684, r8709, r8738, r8777, r8828): 0.5
authorDarkvater
Sat, 24 Feb 2007 01:02:15 +0000
branch0.5
changeset 5442 427c81cfd6f6
parent 5441 3b4236f6925e
child 5443 4ef33c0ddab7
(svn r8870) [0.5] -Backport from trunk (r8684, r8709, r8738, r8777, r8828):
- Bool (uint32 in PPC) was written to as a uint8 (r8684)
- Fix a problem where loading times for overhanging trains are miscomputed (r8709)
- Load newer TTDP games (update coastal tiles) (r8738)
- Cloning unaware of articulated locomotives that could refit without refitting the front unit (r8777)
- Load station rectangle for all savegames, not only after version 27 (r8828)
oldloader.c
openttd.c
settings.c
station_cmd.c
vehicle.c
--- a/oldloader.c	Fri Feb 23 18:25:11 2007 +0000
+++ b/oldloader.c	Sat Feb 24 01:02:15 2007 +0000
@@ -1510,16 +1510,28 @@
 	}
 
 	for (i = 0; i < OLD_MAP_SIZE; i ++) {
-		if (IsTileType(i, MP_RAILWAY)) {
-			/* We save presignals different from TTDPatch, convert them */
-			if (GetRailTileType(i) == RAIL_TILE_SIGNALS) {
-				/* This byte is always zero in TTD for this type of tile */
-				if (_m[i].m4) /* Convert the presignals to our own format */
-					_m[i].m4 = (_m[i].m4 >> 1) & 7;
-			}
-			/* TTDPatch stores PBS things in L6 and all elsewhere; so we'll just
-			 * clear it for ourselves and let OTTD's rebuild PBS itself */
-			_m[i].m4 &= 0xF; /* Only keep the lower four bits; upper four is PBS */
+		switch (GetTileType(i)) {
+			case MP_RAILWAY:
+				/* We save presignals different from TTDPatch, convert them */
+				if (GetRailTileType(i) == RAIL_TILE_SIGNALS) {
+					/* This byte is always zero in TTD for this type of tile */
+					if (_m[i].m4) /* Convert the presignals to our own format */
+						_m[i].m4 = (_m[i].m4 >> 1) & 7;
+				}
+				/* TTDPatch stores PBS things in L6 and all elsewhere; so we'll just
+				 * clear it for ourselves and let OTTD's rebuild PBS itself */
+				_m[i].m4 &= 0xF; /* Only keep the lower four bits; upper four is PBS */
+				break;
+			case MP_WATER: {
+				/* TTDPatch has all tiles touching water as coast (water)-type, we don't.
+				 * This is only true from a certain TTDP version, but there is no harm
+				 * in checking all the time */
+				Slope s = GetTileSlope(i, NULL);
+				if (s == SLOPE_ENW || s == SLOPE_NWS || s == SLOPE_SEN || s == SLOPE_WSE || IsSteepSlope(s)) {
+					SetTileType(i, MP_CLEAR);
+					SetTileOwner(i, OWNER_NONE);
+				}
+			} break;
 		}
 	}
 
--- a/openttd.c	Fri Feb 23 18:25:11 2007 +0000
+++ b/openttd.c	Sat Feb 24 01:02:15 2007 +0000
@@ -1119,7 +1119,7 @@
 
 extern void UpdateOldAircraft( void );
 extern void UpdateOilRig( void );
-
+extern bool StationRect_BeforeAddTile(Station *st, TileIndex tile, int mode);
 
 static inline RailType UpdateRailType(RailType rt, RailType min)
 {
@@ -1490,6 +1490,13 @@
 
 	if (!CheckSavegameVersion(27)) AfterLoadStations();
 
+	BEGIN_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0) {
+		if (GetTileType(tile) == MP_STATION) {
+			Station *st = GetStationByTile(tile);
+			StationRect_BeforeAddTile(st, tile, 2 /* RECT_MODE_FORCE */);
+		}
+	} END_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0);
+
 	{
 		/* Set up the engine count for all players */
 		Player *players[MAX_PLAYERS];
--- a/settings.c	Fri Feb 23 18:25:11 2007 +0000
+++ b/settings.c	Sat Feb 24 01:02:15 2007 +0000
@@ -958,7 +958,7 @@
 	SDTG_CONDVAR(name, type, flags, guiflags, var, def, min, max, interval, str, proc, 0, SL_MAX_VERSION)
 
 #define SDTG_CONDBOOL(name, flags, guiflags, var, def, str, proc, from, to)\
-	SDTG_GENERAL(name, SDT_BOOLX, SL_VAR, SLE_UINT8, flags, guiflags, var, 0, def, 0, 1, 0, NULL, str, proc, from, to)
+	SDTG_GENERAL(name, SDT_BOOLX, SL_VAR, SLE_BOOL, flags, guiflags, var, 0, def, 0, 1, 0, NULL, str, proc, from, to)
 #define SDTG_BOOL(name, flags, guiflags, var, def, str, proc)\
 	SDTG_CONDBOOL(name, flags, guiflags, var, def, str, proc, 0, SL_MAX_VERSION)
 
--- a/station_cmd.c	Fri Feb 23 18:25:11 2007 +0000
+++ b/station_cmd.c	Sat Feb 24 01:02:15 2007 +0000
@@ -42,7 +42,7 @@
 
 static void StationRect_Init(Station *st);
 static bool StationRect_IsEmpty(Station *st);
-static bool StationRect_BeforeAddTile(Station *st, TileIndex tile, StationRectMode mode);
+bool StationRect_BeforeAddTile(Station *st, TileIndex tile, StationRectMode mode);
 static bool StationRect_BeforeAddRect(Station *st, TileIndex tile, int w, int h, StationRectMode mode);
 static bool StationRect_AfterRemoveTile(Station *st, TileIndex tile);
 static bool StationRect_AfterRemoveRect(Station *st, TileIndex tile, int w, int h);
@@ -1249,14 +1249,14 @@
 	do {
 		t -= delta;
 		len++;
-	} while (TileBelongsToRailStation(st, t) && GetRailStationAxis(t) == axis);
+	} while (IsCompatibleTrainStationTile(t, tile));
 
 	// find ending tile
 	t = tile;
 	do {
 		t += delta;
 		len++;
-	} while (TileBelongsToRailStation(st, t) && GetRailStationAxis(t) == axis);
+	} while (IsCompatibleTrainStationTile(t, tile));
 
 	return len - 1;
 }
@@ -2929,7 +2929,6 @@
 {
 	Station *st;
 	uint i;
-	TileIndex tile;
 
 	/* Update the speclists of all stations to point to the currently loaded custom stations. */
 	FOR_ALL_STATIONS(st) {
@@ -2939,12 +2938,6 @@
 			st->speclist[i].spec = GetCustomStationSpecByGrf(st->speclist[i].grfid, st->speclist[i].localidx);
 		}
 	}
-
-	for (tile = 0; tile < MapSize(); tile++) {
-		if (GetTileType(tile) != MP_STATION) continue;
-		st = GetStationByTile(tile);
-		StationRect_BeforeAddTile(st, tile, RECT_MODE_FORCE);
-	}
 }
 
 
@@ -3188,7 +3181,7 @@
 	return (st->rect.left == 0 || st->rect.left > st->rect.right || st->rect.top > st->rect.bottom);
 }
 
-static bool StationRect_BeforeAddTile(Station *st, TileIndex tile, StationRectMode mode)
+bool StationRect_BeforeAddTile(Station *st, TileIndex tile, StationRectMode mode)
 {
 	Rect *r = &st->rect;
 	int x = TileX(tile);
--- a/vehicle.c	Fri Feb 23 18:25:11 2007 +0000
+++ b/vehicle.c	Sat Feb 24 01:02:15 2007 +0000
@@ -1839,13 +1839,22 @@
 		total_cost += cost;
 
 		if (flags & DC_EXEC) {
+			Vehicle *v2, *w2;
 			w = GetVehicle(_new_vehicle_id);
-
-			if (v->cargo_type != w->cargo_type || v->cargo_subtype != w->cargo_subtype) {
-				// we can't pay for refitting because we can't estimate refitting costs for a vehicle before it's build
-				// if we pay for it anyway, the cost and the estimated cost will not be the same and we will have an assert
-				DoCommand(0, w->index, v->cargo_type | (v->cargo_subtype << 8), flags, CMD_REFIT_VEH(v->type));
-			}
+			w2 = w;
+			v2 = v;
+
+			do {
+				if (v->cargo_type != w->cargo_type || v->cargo_subtype != w->cargo_subtype) {
+					/* We can't pay for refitting because we can't estimate refitting costs for a vehicle before it's build.
+					 * If we pay for it anyway, the cost and the estimated cost will not be the same and we will have an assert.
+					 * We need to check the whole chain if it is a train because some newgrf articulated engines can refit some
+					 * units only (and not the front) */
+					DoCommand(0, w->index, v2->cargo_type | (v2->cargo_subtype << 8), flags, CMD_REFIT_VEH(v->type));
+					break; // We learned that the engine in question needed a refit. No need to check anymore
+				}
+			} while (v->type == VEH_Train && (w2 = w2->next) != NULL && (v2 = v2->next) != NULL);
+
 			if (v->type == VEH_Train && HASBIT(v->u.rail.flags, VRF_REVERSE_DIRECTION)) {
 				SETBIT(w->u.rail.flags, VRF_REVERSE_DIRECTION);
 			}