From ad15b47f723f4c0ee1d6d9a2fd8029cff8112b64 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 5 Mar 2017 14:06:34 +0000 Subject: [PATCH] Chunnel: Fix setting of tunnel ID in load conversion, add method to set ID. --- src/saveload/afterload.cpp | 5 +++-- src/tunnel_map.h | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 5066c55598..94529fc456 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -58,6 +58,7 @@ #include "../error.h" #include "../disaster_vehicle.h" #include "../tracerestrict.h" +#include "../tunnel_map.h" #include "saveload_internal.h" @@ -2047,8 +2048,8 @@ bool AfterLoadGame() const Tunnel *t = new Tunnel(start_tile, end_tile, false); - _m[start_tile].m2 = t->index; - _m[end_tile].m2 = t->index; + SetTunnelIndex(start_tile, t->index); + SetTunnelIndex(end_tile, t->index); } } } diff --git a/src/tunnel_map.h b/src/tunnel_map.h index 55f6ce7eea..41102cb27e 100644 --- a/src/tunnel_map.h +++ b/src/tunnel_map.h @@ -58,6 +58,18 @@ static inline TunnelID GetTunnelIndex(TileIndex t) TileIndex GetOtherTunnelEnd(TileIndex); bool IsTunnelInWay(TileIndex, int z, bool chunnel_allowed = false); +/** + * Set the index of tunnel tile. + * @param t the tile + * @param id the tunnel ID + * @pre IsTunnelTile(t) + */ +static inline void SetTunnelIndex(TileIndex t, TunnelID id) +{ + assert(IsTunnelTile(t)); + _m[t].m2 = (id >= TUNNEL_ID_MAP_LOOKUP) ? TUNNEL_ID_MAP_LOOKUP : id; +} + /** * Makes a road tunnel entrance * @param t the entrance of the tunnel @@ -70,12 +82,12 @@ static inline void MakeRoadTunnel(TileIndex t, Owner o, TunnelID id, DiagDirecti { SetTileType(t, MP_TUNNELBRIDGE); SetTileOwner(t, o); - _m[t].m2 = (id >= TUNNEL_ID_MAP_LOOKUP) ? TUNNEL_ID_MAP_LOOKUP : id; _m[t].m3 = 0; _m[t].m4 = 0; _m[t].m5 = TRANSPORT_ROAD << 2 | d; SB(_me[t].m6, 2, 4, 0); _me[t].m7 = 0; + SetTunnelIndex(t, id); SetRoadOwner(t, ROADTYPE_ROAD, o); if (o != OWNER_TOWN) SetRoadOwner(t, ROADTYPE_TRAM, o); SetRoadTypes(t, r); @@ -93,7 +105,6 @@ static inline void MakeRailTunnel(TileIndex t, Owner o, TunnelID id, DiagDirecti { SetTileType(t, MP_TUNNELBRIDGE); SetTileOwner(t, o); - _m[t].m2 = (id >= TUNNEL_ID_MAP_LOOKUP) ? TUNNEL_ID_MAP_LOOKUP : id; SB(_m[t].m1, 7, 1, GB(r, 4, 1)); SB(_m[t].m3, 0, 4, GB(r, 0, 4)); SB(_m[t].m3, 4, 4, 0); @@ -101,6 +112,7 @@ static inline void MakeRailTunnel(TileIndex t, Owner o, TunnelID id, DiagDirecti _m[t].m5 = TRANSPORT_RAIL << 2 | d; SB(_me[t].m6, 2, 4, 0); _me[t].m7 = 0; + SetTunnelIndex(t, id); } #endif /* TUNNEL_MAP_H */