(svn r1560) Introduce SetTileType() and SetTileHeight()

Replace direct references to _map_type_and_height with these
This commit is contained in:
tron 2005-01-18 18:41:56 +00:00
parent 64b08311b9
commit 31d6f87d80
10 changed files with 29 additions and 22 deletions

View File

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

View File

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

View File

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

15
map.h
View File

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

View File

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

View File

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

View File

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

View File

@ -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];

View File

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

View File

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