Chunnel: Fix setting of tunnel ID in load conversion, add method to set ID.

pull/16/head
Jonathan G Rennison 7 years ago
parent afd8c6b867
commit ad15b47f72

@ -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);
}
}
}

@ -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 */

Loading…
Cancel
Save