diff --git a/oldloader.c b/oldloader.c index 8921ea096d..94f252df70 100644 --- a/oldloader.c +++ b/oldloader.c @@ -1510,16 +1510,28 @@ static bool LoadOldMain(LoadgameState *ls) } 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; } } diff --git a/openttd.c b/openttd.c index 10dc031cef..4e9b3f9536 100644 --- a/openttd.c +++ b/openttd.c @@ -1119,7 +1119,7 @@ static void UpdateSignOwner(void) 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 @@ bool AfterLoadGame(void) 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]; diff --git a/settings.c b/settings.c index 20a2155735..5df543d3b7 100644 --- a/settings.c +++ b/settings.c @@ -958,7 +958,7 @@ static void ini_save_setting_list(IniFile *ini, const char *grpname, char **list 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) diff --git a/station_cmd.c b/station_cmd.c index 4186d30bf4..c70f426752 100644 --- a/station_cmd.c +++ b/station_cmd.c @@ -42,7 +42,7 @@ typedef enum StationRectModes 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 @@ uint GetStationPlatforms(const Station *st, TileIndex tile) 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 @@ void AfterLoadStations(void) { 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 @@ void AfterLoadStations(void) 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 @@ static bool StationRect_IsEmpty(Station *st) 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); diff --git a/vehicle.c b/vehicle.c index 54f7b54f8b..ae0690a3b4 100644 --- a/vehicle.c +++ b/vehicle.c @@ -1839,13 +1839,22 @@ int32 CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) total_cost += cost; if (flags & DC_EXEC) { + Vehicle *v2, *w2; w = GetVehicle(_new_vehicle_id); + 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->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)); - } if (v->type == VEH_Train && HASBIT(v->u.rail.flags, VRF_REVERSE_DIRECTION)) { SETBIT(w->u.rail.flags, VRF_REVERSE_DIRECTION); }