summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcelestar <celestar@openttd.org>2006-04-12 11:58:07 +0000
committercelestar <celestar@openttd.org>2006-04-12 11:58:07 +0000
commit7109274de438c06d7e30b9fc57a41c3bc8918ac0 (patch)
treefb4534a61881057170e33d730788aafffcf40aaa
parentce320ceb55ab150b4066d139c98241dc20e5ea0f (diff)
downloadopenttd-7109274de438c06d7e30b9fc57a41c3bc8918ac0.tar.xz
(svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
-rw-r--r--rail_cmd.c73
-rw-r--r--rail_map.h44
2 files changed, 66 insertions, 51 deletions
diff --git a/rail_cmd.c b/rail_cmd.c
index a3ca08a20..407b8a687 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -54,24 +54,6 @@ void ShowTrainDepotWindow(TileIndex tile);
*/
-// 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 @@ int32 CmdBuildSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
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 @@ static void DrawSpecialBuilding(
* @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 @@ static void DrawTile_Track(TileInfo *ti)
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 AnimateTile_Track(TileIndex tile)
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 @@ static void TileLoop_Track(TileIndex tile)
}
}
-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);
}
}
diff --git a/rail_map.h b/rail_map.h
index f3a7a4626..1fe1d71f4 100644
--- a/rail_map.h
+++ b/rail_map.h
@@ -202,6 +202,50 @@ static inline void SetSignalVariant(TileIndex t, SignalVariant v)
}
+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);