diff options
-rw-r--r-- | ai/default/default.c | 3 | ||||
-rw-r--r-- | ai/trolly/pathfinder.c | 11 | ||||
-rw-r--r-- | npf.c | 17 | ||||
-rw-r--r-- | pathfind.c | 30 | ||||
-rw-r--r-- | rail.c | 6 | ||||
-rw-r--r-- | rail_cmd.c | 2 | ||||
-rw-r--r-- | roadveh_cmd.c | 4 | ||||
-rw-r--r-- | smallmap_gui.c | 6 | ||||
-rw-r--r-- | tile.h | 4 | ||||
-rw-r--r-- | town_cmd.c | 4 | ||||
-rw-r--r-- | train_cmd.c | 3 | ||||
-rw-r--r-- | tunnel_map.c | 6 | ||||
-rw-r--r-- | tunnel_map.h | 12 | ||||
-rw-r--r-- | tunnelbridge_cmd.c | 21 |
14 files changed, 61 insertions, 68 deletions
diff --git a/ai/default/default.c b/ai/default/default.c index f6e6cdbde..41580720c 100644 --- a/ai/default/default.c +++ b/ai/default/default.c @@ -7,6 +7,7 @@ #include "../../road_map.h" #include "../../tile.h" #include "../../player.h" +#include "../../tunnel_map.h" #include "../../vehicle.h" #include "../../engine.h" #include "../../command.h" @@ -2147,7 +2148,7 @@ static bool AiRemoveTileAndGoForward(Player *p) TileIndex tilenew; if (IsTileType(tile, MP_TUNNELBRIDGE)) { - if (!(_m[tile].m5 & 0x80)) { + if (IsTunnel(tile)) { // Clear the tunnel and continue at the other side of it. if (CmdFailed(DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) return false; diff --git a/ai/trolly/pathfinder.c b/ai/trolly/pathfinder.c index 17fc15b66..128351f32 100644 --- a/ai/trolly/pathfinder.c +++ b/ai/trolly/pathfinder.c @@ -43,8 +43,7 @@ static bool IsRoad(TileIndex tile) // MP_STREET, but not a road depot? (IsTileType(tile, MP_STREET) && !IsTileDepotType(tile, TRANSPORT_ROAD)) || (IsTileType(tile, MP_TUNNELBRIDGE) && ( - // road tunnel? - ((_m[tile].m5 & 0x80) == 0 && (_m[tile].m5 & 0x4) == 0x4) || + (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_ROAD) || // road bridge? ((_m[tile].m5 & 0x80) != 0 && (_m[tile].m5 & 0x2) == 0x2) )); @@ -232,12 +231,10 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr // If the next step is a bridge, we have to enter it the right way if (!PathFinderInfo->rail_or_road && IsRoad(atile)) { if (IsTileType(atile, MP_TUNNELBRIDGE)) { - // An existing bridge... let's test the direction ;) - if ((_m[atile].m5 & 1U) != (i & 1)) continue; - // This problem only is valid for tunnels: - // When the last tile was not yet a tunnel, check if we enter from the right side.. - if ((_m[atile].m5 & 0x80) == 0) { + if (IsTunnel(atile)) { if (GetTunnelDirection(atile) != i) continue; + } else { + if ((_m[atile].m5 & 1U) != DiagDirToAxis(i)) continue; } } } @@ -260,11 +260,11 @@ static int32 NPFRoadPathCost(AyStar* as, AyStarNode* current, OpenListNode* pare /* Determine base length */ switch (GetTileType(tile)) { case MP_TUNNELBRIDGE: - if (GB(_m[tile].m5, 4, 4) == 0) { + if (IsTunnel(tile)) { cost = NPFTunnelCost(current); - break; + } else { + cost = NPF_TILE_LENGTH; } - cost = NPF_TILE_LENGTH; break; case MP_STREET: @@ -306,7 +306,7 @@ static int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* pare /* Determine base length */ switch (GetTileType(tile)) { case MP_TUNNELBRIDGE: - if (GB(_m[tile].m5, 4, 4) == 0) { + if (IsTunnel(tile)) { cost = NPFTunnelCost(current); break; } @@ -483,7 +483,7 @@ static bool VehicleMayEnterTile(Owner owner, TileIndex tile, DiagDirection enter } /* if we were on a railway middle part, we are now at a railway bridge ending */ #endif - if ((_m[tile].m5 & 0xFC) == 0 || /* railway tunnel */ + if ((IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) || (_m[tile].m5 & 0xC6) == 0x80 || /* railway bridge ending */ ((_m[tile].m5 & 0xF8) == 0xE0 && GB(_m[tile].m5, 0, 1) != (enterdir & 0x1))) { /* railway under bridge */ return IsTileOwner(tile, owner); @@ -517,9 +517,7 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current) DEBUG(npf, 4)("Expanding: (%d, %d, %d) [%d]", TileX(src_tile), TileY(src_tile), src_trackdir, src_tile); /* Find dest tile */ - if (IsTileType(src_tile, MP_TUNNELBRIDGE) && - GB(_m[src_tile].m5, 4, 4) == 0 && - GetTunnelDirection(src_tile) == src_exitdir) { + if (IsTunnelTile(src_tile) && GetTunnelDirection(src_tile) == src_exitdir) { /* This is a tunnel. We know this tunnel is our type, * otherwise we wouldn't have got here. It is also facing us, * so we should skip it's body */ @@ -565,8 +563,7 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current) /* I can't enter a tunnel entry/exit tile from a tile above the tunnel. Note * that I can enter the tunnel from a tile below the tunnel entrance. This * solves the problem of vehicles wanting to drive off a tunnel entrance */ - if (IsTileType(dst_tile, MP_TUNNELBRIDGE) && GB(_m[dst_tile].m5, 4, 4) == 0 && - GetTileZ(dst_tile) < GetTileZ(src_tile)) { + if (IsTunnelTile(dst_tile) && GetTileZ(dst_tile) < GetTileZ(src_tile)) { return; } diff --git a/pathfind.c b/pathfind.c index 2cdf1884a..6c89c5d48 100644 --- a/pathfind.c +++ b/pathfind.c @@ -231,8 +231,7 @@ FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, DiagDirection direct tile = TileVirtXY(x, y); - if (IsTileType(tile, MP_TUNNELBRIDGE) && - GB(_m[tile].m5, 4, 4) == 0 && // tunnel entrance/exit + if (IsTunnelTile(tile) && // GetTunnelTransportType(tile) == type && // rail/road-tunnel <-- This is not necesary to check, right? ReverseDiagDir(GetTunnelDirection(tile)) == direction && GetSlopeZ(x + 8, y + 8) == z) { @@ -283,7 +282,7 @@ static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection directi RememberData rd; TileIndex tile_org = tile; - if (IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0) { + if (IsTunnelTile(tile)) { if (GetTunnelDirection(tile) != direction || GetTunnelTransportType(tile) != tpf->tracktype) { return; @@ -716,21 +715,18 @@ callback_and_continue: start_at: // If the tile is the entry tile of a tunnel, and we're not going out of the tunnel, // need to find the exit of the tunnel. - if (IsTileType(tile, MP_TUNNELBRIDGE)) { - if (GB(_m[tile].m5, 4, 4) == 0 && - GetTunnelDirection(tile) != ReverseDiagDir(direction)) { - /* This is a tunnel tile */ - /* We are not just driving out of the tunnel */ - if (GetTunnelDirection(tile) != direction || - GetTunnelTransportType(tile) != tpf->tracktype) { - // We are not driving into the tunnel, or it is an invalid tunnel - continue; - } - flotr = FindLengthOfTunnel(tile, direction); - si.cur_length += flotr.length * DIAG_FACTOR; - tile = flotr.tile; - // tile now points to the exit tile of the tunnel + if (IsTunnelTile(tile) && + GetTunnelDirection(tile) != ReverseDiagDir(direction)) { + /* We are not just driving out of the tunnel */ + if (GetTunnelDirection(tile) != direction || + GetTunnelTransportType(tile) != tpf->tracktype) { + // We are not driving into the tunnel, or it is an invalid tunnel + continue; } + flotr = FindLengthOfTunnel(tile, direction); + si.cur_length += flotr.length * DIAG_FACTOR; + tile = flotr.tile; + // tile now points to the exit tile of the tunnel } // This is a special loop used to go through @@ -4,6 +4,7 @@ #include "openttd.h" #include "rail.h" #include "station.h" +#include "tunnel_map.h" /* XXX: Below 3 tables store duplicate data. Maybe remove some? */ /* Maps a trackdir to the bit that stores its status in the map arrays, in the @@ -123,8 +124,9 @@ RailType GetTileRailType(TileIndex tile, Trackdir trackdir) type = _m[tile].m3 & RAILTYPE_MASK; break; case MP_TUNNELBRIDGE: - /* railway tunnel */ - if ((_m[tile].m5 & 0xFC) == 0) type = _m[tile].m3 & RAILTYPE_MASK; + if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) { + return _m[tile].m3 & RAILTYPE_MASK; + } /* railway bridge ending */ if ((_m[tile].m5 & 0xC6) == 0x80) type = _m[tile].m3 & RAILTYPE_MASK; /* on railway bridge */ diff --git a/rail_cmd.c b/rail_cmd.c index 72c4de698..8dc36a59d 100644 --- a/rail_cmd.c +++ b/rail_cmd.c @@ -1625,7 +1625,7 @@ static bool SignalVehicleCheck(TileIndex tile, uint track) * is some kind of invisible black hole, and there is some special magic going * on in there. This 'workaround' can be removed once the maprewrite is done. */ - if (IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0) { + if (IsTunnelTile(tile)) { // It is a tunnel we're checking, we need to do some special stuff // because VehicleFromPos will not find the vihicle otherwise TileIndex end = GetOtherTunnelEnd(tile); diff --git a/roadveh_cmd.c b/roadveh_cmd.c index b8dc3f928..9bd462072 100644 --- a/roadveh_cmd.c +++ b/roadveh_cmd.c @@ -18,6 +18,7 @@ #include "player.h" #include "sound.h" #include "depot.h" +#include "tunnel_map.h" #include "vehicle_gui.h" #include "newgrf_engine.h" @@ -1254,8 +1255,7 @@ static void RoadVehController(Vehicle *v) return; } - if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) && - GB(_m[gp.new_tile].m5, 4, 4) == 0 && + if (IsTunnelTile(gp.new_tile) && VehicleEnterTile(v, gp.new_tile, gp.x, gp.y) & 4) { //new_dir = RoadGetNewDirection(v, gp.x, gp.y) v->cur_image = GetRoadVehImage(v, v->direction); diff --git a/smallmap_gui.c b/smallmap_gui.c index cfd3cf737..89732cb95 100644 --- a/smallmap_gui.c +++ b/smallmap_gui.c @@ -348,10 +348,10 @@ static inline TileType GetEffectiveTileType(TileIndex tile) if (t == MP_TUNNELBRIDGE) { TransportType tt; - if (_m[tile].m5 & 0x80) { - tt = GB(_m[tile].m5, 1, 2); - } else { + if (IsTunnel(tile)) { tt = GetTunnelTransportType(tile); + } else { + tt = GB(_m[tile].m5, 1, 2); } switch (tt) { case TRANSPORT_RAIL: t = MP_RAILWAY; break; @@ -79,10 +79,6 @@ static inline bool IsTileType(TileIndex tile, TileType type) return GetTileType(tile) == type; } -static inline bool IsTunnelTile(TileIndex tile) -{ - return IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0; -} static inline Owner GetTileOwner(TileIndex tile) { diff --git a/town_cmd.c b/town_cmd.c index 9813f5312..ce4498f5f 100644 --- a/town_cmd.c +++ b/town_cmd.c @@ -624,9 +624,7 @@ static void GrowTownInTile(TileIndex* tile_ptr, RoadBits mask, int block, Town* int i; // Reached a tunnel? Then continue at the other side of it. - if (IsTileType(tile, MP_TUNNELBRIDGE) && - GB(_m[tile].m5, 4, 4) == 0 && - GetTunnelTransportType(tile) == TRANSPORT_ROAD) { + if (IsTunnelTile(tile) && GetTunnelTransportType(tile) == TRANSPORT_ROAD) { *tile_ptr = GetOtherTunnelEnd(tile); return; } diff --git a/train_cmd.c b/train_cmd.c index fa24f4cbd..bc2f28c57 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -2481,8 +2481,9 @@ static byte AfterSetTrainPos(Vehicle *v, bool new_tile) TileIndex tile = TileVirtXY(v->x_pos, v->y_pos); // XXX workaround, whole UP/DOWN detection needs overhaul - if (!IsTileType(tile, MP_TUNNELBRIDGE) || (_m[tile].m5 & 0x80) != 0) + if (!IsTunnelTile(tile)) { SETBIT(v->u.rail.flags, (new_z > old_z) ? VRF_GOINGUP : VRF_GOINGDOWN); + } } } diff --git a/tunnel_map.c b/tunnel_map.c index 8752d8107..435d62f20 100644 --- a/tunnel_map.c +++ b/tunnel_map.c @@ -15,8 +15,7 @@ TileIndex GetOtherTunnelEnd(TileIndex tile) do { tile += delta; } while ( - !IsTileType(tile, MP_TUNNELBRIDGE) || - GB(_m[tile].m5, 4, 4) != 0 || + !IsTunnelTile(tile) || GetTunnelDirection(tile) != dir || GetTileZ(tile) != z ); @@ -37,8 +36,7 @@ static bool IsTunnelInWayDir(TileIndex tile, uint z, DiagDirection dir) return z == height && - IsTileType(tile, MP_TUNNELBRIDGE) && - GB(_m[tile].m5, 4, 4) == 0 && + IsTunnelTile(tile) && GetTunnelDirection(tile) == dir; } diff --git a/tunnel_map.h b/tunnel_map.h index 047f631f9..6ac6cb44b 100644 --- a/tunnel_map.h +++ b/tunnel_map.h @@ -9,6 +9,18 @@ #include "rail.h" +static inline bool IsTunnel(TileIndex t) +{ + return !HASBIT(_m[t].m5, 7); +} + + +static inline bool IsTunnelTile(TileIndex t) +{ + return IsTileType(t, MP_TUNNELBRIDGE) && IsTunnel(t); +} + + static inline DiagDirection GetTunnelDirection(TileIndex t) { return (DiagDirection)GB(_m[t].m5, 0, 2); diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c index f43728695..fe2a379ca 100644 --- a/tunnelbridge_cmd.c +++ b/tunnelbridge_cmd.c @@ -525,8 +525,7 @@ TileIndex CheckTunnelBusy(TileIndex tile, uint *length) tile += delta; len++; } while ( - !IsTileType(tile, MP_TUNNELBRIDGE) || - GB(_m[tile].m5, 4, 4) != 0 || + !IsTunnelTile(tile) || ReverseDiagDir(GetTunnelDirection(tile)) != dir || GetTileZ(tile) != z ); @@ -742,7 +741,7 @@ static int32 ClearTile_TunnelBridge(TileIndex tile, byte flags) { byte m5 = _m[tile].m5; - if ((m5 & 0xF0) == 0) { + if (IsTunnel(tile)) { if (flags & DC_AUTO) return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST); return DoClearTunnel(tile, flags); } else if (m5 & 0x80) { @@ -759,8 +758,7 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec) uint length; Vehicle *v; - if ((_m[tile].m5 & 0xFC) == 0x00) { - // railway tunnel + if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) { if (!CheckTileOwnership(tile)) return CMD_ERROR; if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR; @@ -962,7 +960,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti) bool ice = _m[ti->tile].m4 & 0x80; // draw tunnel? - if ((ti->map5 & 0xF0) == 0) { + if (IsTunnel(ti->tile)) { if (GetTunnelTransportType(ti->tile) == TRANSPORT_RAIL) { image = GetRailTypeInfo(GB(_m[ti->tile].m3, 0, 4))->base_sprites.tunnel; } else { @@ -1229,7 +1227,7 @@ static const StringID _bridge_tile_str[(MAX_BRIDGES + 3) + (MAX_BRIDGES + 3)] = static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td) { - if ((_m[tile].m5 & 0x80) == 0) { + if (IsTunnel(tile)) { td->str = (GetTunnelTransportType(tile) == TRANSPORT_RAIL) ? STR_5017_RAILROAD_TUNNEL : STR_5018_ROAD_TUNNEL; } else { @@ -1291,8 +1289,7 @@ static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode uint32 result; byte m5 = _m[tile].m5; - if ((m5 & 0xF0) == 0) { - /* This is a tunnel */ + if (IsTunnel(tile)) { if (GetTunnelTransportType(tile) == mode) { return DiagDirToAxis(GetTunnelDirection(tile)) == AXIS_X ? 0x101 : 0x202; } @@ -1371,7 +1368,7 @@ static const byte _tunnel_fractcoord_7[4] = {0x52, 0x85, 0x96, 0x49}; static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y) { - if (GB(_m[tile].m5, 4, 4) == 0) { + if (IsTunnel(tile)) { int z = GetSlopeZ(x, y) - v->z_pos; byte fc; DiagDirection dir; @@ -1463,9 +1460,7 @@ TileIndex GetVehicleOutOfTunnelTile(const Vehicle *v) byte z = v->z_pos; for (tile = v->tile;; tile += delta) { - if (IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0 && - GetTileZ(tile) == z) - break; + if (IsTunnelTile(tile) && GetTileZ(tile) == z) break; } return tile; } |