summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clear_cmd.c4
-rw-r--r--industry_cmd.c2
-rw-r--r--landscape.c4
-rw-r--r--map.h15
-rw-r--r--rail_cmd.c3
-rw-r--r--road_cmd.c3
-rw-r--r--station_cmd.c3
-rw-r--r--tree_cmd.c7
-rw-r--r--tunnelbridge_cmd.c6
-rw-r--r--unmovable_cmd.c4
10 files changed, 29 insertions, 22 deletions
diff --git a/clear_cmd.c b/clear_cmd.c
index bc6c89e84..110750041 100644
--- a/clear_cmd.c
+++ b/clear_cmd.c
@@ -303,9 +303,7 @@ int32 CmdTerraformLand(int x, int y, uint32 flags, uint32 p1, uint32 p2)
for(count = ts.modheight_count; count != 0; count--, mod++) {
til = mod->tile;
- // Change tile height
- _map_type_and_height[til] = (_map_type_and_height[til]&~0x0F)|mod->height;
-
+ SetTileHeight(til, mod->height);
TerraformAddDirtyTileAround(&ts, til);
}
}
diff --git a/industry_cmd.c b/industry_cmd.c
index de8bdffa9..41455b6b0 100644
--- a/industry_cmd.c
+++ b/industry_cmd.c
@@ -1479,7 +1479,7 @@ static void DoCreateNewIndustry(Industry *i, uint tile, int type, const Industry
DoCommandByTile(cur_tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
- _map_type_and_height[cur_tile] = (_map_type_and_height[cur_tile]&~0xF0) | (MP_INDUSTRY<<4);
+ SetTileType(cur_tile, MP_INDUSTRY);
_map5[cur_tile] = it->map5;
_map2[cur_tile] = i->index;
_map_owner[cur_tile] = _generating_world ? 0x1E : 0; /* maturity */
diff --git a/landscape.c b/landscape.c
index 1a490a897..39503a66f 100644
--- a/landscape.c
+++ b/landscape.c
@@ -400,7 +400,7 @@ void CDECL ModifyTile(uint tile, uint flags, ...)
va_start(va, flags);
if ((i = (flags >> 8) & 0xF) != 0) {
- _map_type_and_height[tile] = (_map_type_and_height[tile]&~0xF0)|((i-1) << 4);
+ SetTileType(tile, i - 1);
}
if (flags & (MP_MAP2_CLEAR | MP_MAP2)) {
@@ -510,7 +510,7 @@ void ConvertGroundTilesIntoWaterTiles()
while(true) {
if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h == 0) {
- _map_type_and_height[tile] = MP_WATER << 4;
+ SetTileType(tile, MP_WATER);
_map5[tile] = 0;
_map_owner[tile] = OWNER_WATER;
}
diff --git a/map.h b/map.h
index 126bdd0b3..1ff6109e6 100644
--- a/map.h
+++ b/map.h
@@ -79,6 +79,14 @@ static inline uint TileHeight(TileIndex tile)
return _map_type_and_height[tile] & 0xf;
}
+static inline void SetTileHeight(TileIndex tile, uint height)
+{
+ assert(tile < MapSize());
+ assert(height < 16);
+ _map_type_and_height[tile] &= ~0x0F;
+ _map_type_and_height[tile] |= height;
+}
+
static inline uint TilePixelHeight(TileIndex tile)
{
return TileHeight(tile) * 8;
@@ -90,6 +98,13 @@ static inline int TileType(TileIndex tile)
return _map_type_and_height[tile] >> 4;
}
+static inline void SetTileType(TileIndex tile, uint type)
+{
+ assert(tile < MapSize());
+ _map_type_and_height[tile] &= ~0xF0;
+ _map_type_and_height[tile] |= type << 4;
+}
+
static inline bool IsTileType(TileIndex tile, int type)
{
return TileType(tile) == type;
diff --git a/rail_cmd.c b/rail_cmd.c
index 76c14e2bb..9fa64e757 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -369,8 +369,7 @@ need_clear:;
}
if (flags & DC_EXEC) {
- _map_type_and_height[tile] &= 0xF;
- _map_type_and_height[tile] |= MP_RAILWAY << 4;
+ SetTileType(tile, MP_RAILWAY);
_map5[tile] |= rail_bit;
_map2[tile] &= ~RAIL_MAP2LO_GROUND_MASK;
diff --git a/road_cmd.c b/road_cmd.c
index 8d6afb4bc..725bc99bd 100644
--- a/road_cmd.c
+++ b/road_cmd.c
@@ -448,8 +448,7 @@ do_clear:;
if (flags & DC_EXEC) {
if (ti.type != MP_STREET) {
- _map_type_and_height[tile] &= 0xF;
- _map_type_and_height[tile] |= MP_STREET << 4;
+ SetTileType(tile, MP_STREET);
_map5[tile] = 0;
_map_owner[tile] = _current_player;
}
diff --git a/station_cmd.c b/station_cmd.c
index aeea6b9e6..cde11f1e9 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -2643,8 +2643,7 @@ void BuildOilRig(uint tile)
if (!GenerateStationName(st, tile, 2))
return;
- _map_type_and_height[tile] &= 0xF;
- _map_type_and_height[tile] |= MP_STATION << 4;
+ SetTileType(tile, MP_STATION);
_map5[tile] = 0x4B;
_map_owner[tile] = OWNER_NONE;
_map3_lo[tile] = 0;
diff --git a/tree_cmd.c b/tree_cmd.c
index 825166db7..259e5ea02 100644
--- a/tree_cmd.c
+++ b/tree_cmd.c
@@ -59,7 +59,7 @@ static void PlaceTree(uint tile, uint32 r, byte m5_or)
// make it tree class
- _map_type_and_height[tile] |= MP_TREES << 4;
+ SetTileType(tile, MP_TREES);
}
}
@@ -531,8 +531,7 @@ static void TileLoop_Trees(uint tile)
_map3_lo[tile] = m3;
_map3_hi[tile] = 0;
- _map_type_and_height[tile] &= 0xF;
- _map_type_and_height[tile] |= MP_TREES << 4;
+ SetTileType(tile, MP_TREES);
m5 = 0;
break;
@@ -549,7 +548,7 @@ static void TileLoop_Trees(uint tile)
m5 = ((m5 - 6) - 0x40) + 3;
} else {
/* just one tree, change type into MP_CLEAR */
- _map_type_and_height[tile] = (_map_type_and_height[tile]&~0xF0) | (MP_CLEAR<<4);
+ SetTileType(tile, MP_CLEAR);
m5 = 3;
m2 = _map2[tile];
diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c
index 1adcd902a..72df2304f 100644
--- a/tunnelbridge_cmd.c
+++ b/tunnelbridge_cmd.c
@@ -338,8 +338,7 @@ not_valid_below:;
/* do middle part of bridge */
if (flags & DC_EXEC) {
_map5[ti.tile] = (byte)(m5 | direction | rail_or_road);
- _map_type_and_height[ti.tile] &= ~0xF0;
- _map_type_and_height[ti.tile] |= MP_TUNNELBRIDGE << 4;
+ SetTileType(ti.tile, MP_TUNNELBRIDGE);
//bridges pieces sequence (middle parts)
// bridge len 1: 0
@@ -783,8 +782,7 @@ static int32 DoClearBridge(uint tile, uint32 flags)
new_data = 0x6000;
}
- _map_type_and_height[c] &= 0x0F;
- _map_type_and_height[c] |= new_data >> 8;
+ SetTileType(c, new_data >> 12);
_map5[c] = (byte)new_data;
_map2[c] = 0;
diff --git a/unmovable_cmd.c b/unmovable_cmd.c
index 9b6075c93..5274710c9 100644
--- a/unmovable_cmd.c
+++ b/unmovable_cmd.c
@@ -268,7 +268,7 @@ void GenerateUnmovables()
if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h >= 32) {
if(!checkRadioTowerNearby(tile))
continue;
- _map_type_and_height[tile] |= MP_UNMOVABLE << 4;
+ SetTileType(tile, MP_UNMOVABLE);
_map5[tile] = 0;
_map_owner[tile] = OWNER_NONE;
if (--j == 0)
@@ -300,7 +300,7 @@ restart:
assert(tile == TILE_MASK(tile));
- _map_type_and_height[tile] |= MP_UNMOVABLE << 4;
+ SetTileType(tile, MP_UNMOVABLE);
_map5[tile] = 1;
_map_owner[tile] = OWNER_NONE;
} while (--i);