Mercurial > hg > openttd
changeset 3523:ca4aa6c713e9 draft
(svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
author | celestar <celestar@openttd.org> |
---|---|
date | Wed, 12 Apr 2006 11:58:07 +0000 |
parents | 284cd96c8794 |
children | ab8dc818d880 |
files | rail_cmd.c rail_map.h |
diffstat | 2 files changed, 66 insertions(+), 51 deletions(-) [+] |
line wrap: on
line diff
--- a/rail_cmd.c +++ b/rail_cmd.c @@ -54,24 +54,6 @@ */ -// Constants for lower part of Map2 byte. -enum RailMap2Lower4 { - RAIL_MAP2LO_GROUND_MASK = 0xF, - RAIL_GROUND_BROWN = 0, - RAIL_GROUND_GREEN = 1, - RAIL_GROUND_FENCE_NW = 2, - RAIL_GROUND_FENCE_SE = 3, - RAIL_GROUND_FENCE_SENW = 4, - RAIL_GROUND_FENCE_NE = 5, - RAIL_GROUND_FENCE_SW = 6, - RAIL_GROUND_FENCE_NESW = 7, - RAIL_GROUND_FENCE_VERT1 = 8, - RAIL_GROUND_FENCE_VERT2 = 9, - RAIL_GROUND_FENCE_HORIZ1 = 10, - RAIL_GROUND_FENCE_HORIZ2 = 11, - RAIL_GROUND_ICE_DESERT = 12, -}; - /* MAP2 byte: abcd???? => Signal On? Same coding as map3lo * MAP3LO byte: abcd???? => Signal Exists? @@ -290,7 +272,7 @@ cost += ret; if (flags & DC_EXEC) { - _m[tile].m2 &= ~RAIL_MAP2LO_GROUND_MASK; // Bare land + SetRailGroundType(tile, RAIL_GROUND_BARREN); _m[tile].m5 |= trackbit; } break; @@ -1197,11 +1179,13 @@ * @param snow Draw as snow * @param flat Always draw foundation */ -static void DrawTrackBits(TileInfo* ti, TrackBits track, bool earth, bool snow, bool flat) +static void DrawTrackBits(TileInfo* ti, TrackBits track, bool flat) { const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile)); PalSpriteID image; bool junction = false; + bool earth = IsBarrenRailGround(ti->tile); + bool snow = IsSnowRailGround(ti->tile); // Select the sprite to use. (image = rti->base_sprites.track_y, track == TRACK_BIT_Y) || @@ -1309,14 +1293,10 @@ if (GetRailTileType(ti->tile) != RAIL_TYPE_DEPOT_WAYPOINT) { TrackBits rails = GetTrackBits(ti->tile); - bool earth = (_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_BROWN; - bool snow = (_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_ICE_DESERT; - DrawTrackBits(ti, rails, earth, snow, false); + DrawTrackBits(ti, rails, false); - if (_display_opt & DO_FULL_DETAIL) { - _detailed_track_proc[_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK](ti); - } + if (_display_opt & DO_FULL_DETAIL) _detailed_track_proc[GetRailGroundType(ti->tile)](ti); /* draw signals also? */ if (GetRailTileType(ti->tile) == RAIL_TYPE_SIGNALS) DrawSignals(ti->tile, rails); @@ -1756,37 +1736,34 @@ static void TileLoop_Track(TileIndex tile) { - byte old_ground; - byte new_ground; - - if (GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT) { - old_ground = GB(_m[tile].m4, 0, 4); - } else { - old_ground = GB(_m[tile].m2, 0, 4); - } + RailGroundType old_ground = GetRailGroundType(tile); + RailGroundType new_ground = old_ground; switch (_opt.landscape) { case LT_HILLY: - if (GetTileZ(tile) > _opt.snow_line) { /* convert into snow? */ - new_ground = RAIL_GROUND_ICE_DESERT; - goto modify_me; - } + if (GetTileZ(tile) > _opt.snow_line) new_ground = RAIL_GROUND_ICE_DESERT; break; case LT_DESERT: - if (GetTropicZone(tile) == TROPICZONE_DESERT) { /* convert into desert? */ - new_ground = RAIL_GROUND_ICE_DESERT; - goto modify_me; - } + if (GetTropicZone(tile) == TROPICZONE_DESERT) new_ground = RAIL_GROUND_ICE_DESERT; + break; + + default: break; } + if (new_ground != old_ground) { + SetRailGroundType(tile, new_ground); + MarkTileDirtyByTile(tile); + return; + } + // Don't continue tile loop for depots if (GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT) return; - new_ground = RAIL_GROUND_GREEN; + new_ground = RAIL_GROUND_GRASS; - if (old_ground != RAIL_GROUND_BROWN) { /* wait until bottom is green */ + if (old_ground != RAIL_GROUND_BARREN) { /* wait until bottom is green */ /* determine direction of fence */ TrackBits rail = GetTrackBits(tile); @@ -1861,14 +1838,8 @@ } } -modify_me:; - /* tile changed? */ if (old_ground != new_ground) { - if (GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT) { - SB(_m[tile].m4, 0, 4, new_ground); - } else { - SB(_m[tile].m2, 0, 4, new_ground); - } + SetRailGroundType(tile, new_ground); MarkTileDirtyByTile(tile); } }
--- a/rail_map.h +++ b/rail_map.h @@ -202,6 +202,50 @@ } +typedef enum RailGroundType { + RAIL_MAP2LO_GROUND_MASK = 0xF, + RAIL_GROUND_BARREN = 0, + RAIL_GROUND_GRASS = 1, + RAIL_GROUND_FENCE_NW = 2, + RAIL_GROUND_FENCE_SE = 3, + RAIL_GROUND_FENCE_SENW = 4, + RAIL_GROUND_FENCE_NE = 5, + RAIL_GROUND_FENCE_SW = 6, + RAIL_GROUND_FENCE_NESW = 7, + RAIL_GROUND_FENCE_VERT1 = 8, + RAIL_GROUND_FENCE_VERT2 = 9, + RAIL_GROUND_FENCE_HORIZ1 = 10, + RAIL_GROUND_FENCE_HORIZ2 = 11, + RAIL_GROUND_ICE_DESERT = 12, +} RailGroundType; + +static inline void SetRailGroundType(TileIndex t, RailGroundType rgt) +{ + if (GetRailTileType(t) == RAIL_TYPE_DEPOT_WAYPOINT) { + SB(_m[t].m4, 0, 4, rgt); + return; + } + SB(_m[t].m2, 0, 4, rgt); +} + +static inline RailGroundType GetRailGroundType(TileIndex t) +{ + /* TODO Unify this */ + if (GetRailTileType(t) == RAIL_TYPE_DEPOT_WAYPOINT) return GB(_m[t].m4, 0, 4); + return GB(_m[t].m2, 0, 4); +} + +static inline bool IsBarrenRailGround(TileIndex t) +{ + return GetRailGroundType(t) == RAIL_GROUND_BARREN; +} + +static inline bool IsSnowRailGround(TileIndex t) +{ + return GetRailGroundType(t) == RAIL_GROUND_ICE_DESERT; +} + + static inline void MakeRailNormal(TileIndex t, Owner o, TrackBits b, RailType r) { SetTileType(t, MP_RAILWAY);