# HG changeset patch # User tron # Date 1117887204 0 # Node ID 8088638e7d4f2021cd02c9d0575836ab26d4ab4f # Parent 74e0d3101dfb48c4b1cd90240adba12b2ed04adb (svn r2408) Introduce SetTileOwner() and use it diff --git a/landscape.c b/landscape.c --- a/landscape.c +++ b/landscape.c @@ -451,7 +451,7 @@ if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h == 0) { SetTileType(tile, MP_WATER); _map5[tile] = 0; - _map_owner[tile] = OWNER_WATER; + SetTileOwner(tile, OWNER_WATER); } } } diff --git a/openttd.c b/openttd.c --- a/openttd.c +++ b/openttd.c @@ -1188,11 +1188,9 @@ if ((_map5[tile] & 0xF0) == 0x10 && _map3_lo[tile] & 0x80) _map3_lo[tile] = OWNER_TOWN; - if (_map_owner[tile] & 0x80) - _map_owner[tile] = OWNER_TOWN; + if (_map_owner[tile] & 0x80) SetTileOwner(tile, OWNER_TOWN); } else if (IsTileType(tile, MP_TUNNELBRIDGE)) { - if (_map_owner[tile] & 0x80) - _map_owner[tile] = OWNER_TOWN; + if (_map_owner[tile] & 0x80) SetTileOwner(tile, OWNER_TOWN); } } } @@ -1300,7 +1298,7 @@ BEGIN_TILE_LOOP(tile_cur, w, h, tile) if (IsTileType(tile_cur, MP_WATER) && GetTileOwner(tile_cur) >= MAX_PLAYERS) - _map_owner[tile_cur] = OWNER_WATER; + SetTileOwner(tile_cur, OWNER_WATER); END_TILE_LOOP(tile_cur, w, h, tile) } diff --git a/rail_cmd.c b/rail_cmd.c --- a/rail_cmd.c +++ b/rail_cmd.c @@ -316,7 +316,7 @@ cost += ret; if (flags & DC_EXEC) { - _map_owner[tile] = _current_player; + SetTileOwner(tile, _current_player); _map3_lo[tile] &= ~0x0F; _map3_lo[tile] |= p1; _map5[tile] = (m5 & 0xC7) | 0x20; // railroad under bridge @@ -365,7 +365,7 @@ )) { if (flags & DC_EXEC) { _map3_lo[tile] = GetTileOwner(tile); - _map_owner[tile] = _current_player; + SetTileOwner(tile, _current_player); _map3_hi[tile] = p1; _map5[tile] = 0x10 | (rail_bit == 1 ? 0x08 : 0x00); // level crossing } @@ -387,7 +387,7 @@ if (flags & DC_EXEC) { SetTileType(tile, MP_RAILWAY); - _map_owner[tile] = _current_player; + SetTileOwner(tile, _current_player); _map2[tile] = 0; // Bare land _map3_lo[tile] = p1; // No signals, rail type _map5[tile] = rail_bit; @@ -461,7 +461,7 @@ if (!(flags & DC_EXEC)) return _price.remove_rail; - _map_owner[tile] = OWNER_NONE; + SetTileOwner(tile, OWNER_NONE); _map5[tile] = ti.map5 & 0xC7; } else if (ti.type == MP_STREET) { byte m5; @@ -485,7 +485,7 @@ return _price.remove_rail; _map5[tile] = m5; - _map_owner[tile] = _map3_lo[tile]; + SetTileOwner(tile, _map3_lo[tile]); _map2[tile] = 0; } else { assert(ti.type == MP_RAILWAY); @@ -2028,7 +2028,7 @@ if (!IsTileOwner(tile, old_player)) return; if (new_player != 255) { - _map_owner[tile] = new_player; + SetTileOwner(tile, new_player); } else { DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); } diff --git a/road_cmd.c b/road_cmd.c --- a/road_cmd.c +++ b/road_cmd.c @@ -195,7 +195,7 @@ if (flags & DC_EXEC) { ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); _map5[tile] = ti.map5 & 0xC7; - _map_owner[tile] = OWNER_NONE; + SetTileOwner(tile, OWNER_NONE); MarkTileDirtyByTile(tile); } return cost; @@ -470,7 +470,7 @@ SetTileType(tile, MP_STREET); _map5[tile] = 0; _map2[tile] = p2; - _map_owner[tile] = _current_player; + SetTileOwner(tile, _current_player); } _map5[tile] |= (byte)pieces; @@ -1148,14 +1148,14 @@ if (!IsTileOwner(tile, old_player)) return; if (new_player != 255) { - _map_owner[tile] = new_player; + SetTileOwner(tile, new_player); } else { b = _map5[tile]&0xF0; if (b == 0) { - _map_owner[tile] = OWNER_NONE; + SetTileOwner(tile, OWNER_NONE); } else if (b == 0x10) { _map5[tile] = (_map5[tile]&8) ? 0x5 : 0xA; - _map_owner[tile] = _map3_lo[tile]; + SetTileOwner(tile, _map3_lo[tile]); _map3_lo[tile] = 0; _map3_hi[tile] &= 0x80; } else { diff --git a/station_cmd.c b/station_cmd.c --- a/station_cmd.c +++ b/station_cmd.c @@ -2827,7 +2827,7 @@ SetTileType(tile, MP_STATION); _map5[tile] = 0x4B; - _map_owner[tile] = OWNER_NONE; + SetTileOwner(tile, OWNER_NONE); _map3_lo[tile] = 0; _map3_hi[tile] = 0; _map2[tile] = st->index; @@ -2884,7 +2884,7 @@ if (new_player != 255) { Station *st = GetStation(_map2[tile]); - _map_owner[tile] = new_player; + SetTileOwner(tile, new_player); st->owner = new_player; _global_station_sort_dirty = true; // transfer ownership of station to another player InvalidateWindowClasses(WC_STATION_LIST); diff --git a/tile.h b/tile.h --- a/tile.h +++ b/tile.h @@ -88,6 +88,16 @@ return _map_owner[tile]; } +static inline void SetTileOwner(TileIndex tile, Owner owner) +{ + assert(tile < MapSize()); + assert(!IsTileType(tile, MP_HOUSE)); + assert(!IsTileType(tile, MP_VOID)); + assert(!IsTileType(tile, MP_INDUSTRY)); + + _map_owner[tile] = owner; +} + static inline bool IsTileOwner(TileIndex tile, Owner owner) { return GetTileOwner(tile) == owner; diff --git a/town_cmd.c b/town_cmd.c --- a/town_cmd.c +++ b/town_cmd.c @@ -746,7 +746,7 @@ else if (_game_mode == GM_EDITOR) { /* If we are in the SE, and this road-piece has no town owner yet, it just found an * owner :) (happy happy happy road now) */ - _map_owner[tile] = OWNER_TOWN; + SetTileOwner(tile, OWNER_TOWN); _map2[tile] = t->index; } } diff --git a/tree_cmd.c b/tree_cmd.c --- a/tree_cmd.c +++ b/tree_cmd.c @@ -580,7 +580,7 @@ if ((m2&0x30) != 0x20) // if not on snow/desert, then on rough land m5 = 7; } - _map_owner[tile] = OWNER_NONE; + SetTileOwner(tile, OWNER_NONE); } } else { /* in the middle of a transition, change to next */ diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c --- a/tunnelbridge_cmd.c +++ b/tunnelbridge_cmd.c @@ -711,7 +711,7 @@ if (flags & DC_EXEC) { _map5[tile] = _map5[tile] & ~0x38; - _map_owner[tile] = OWNER_NONE; + SetTileOwner(tile, OWNER_NONE); MarkTileDirtyByTile(tile); } return cost; @@ -726,7 +726,7 @@ cost = _price.clear_water; if (flags & DC_EXEC) { _map5[tile] = _map5[tile] & ~0x38; - _map_owner[tile] = OWNER_NONE; + SetTileOwner(tile, OWNER_NONE); MarkTileDirtyByTile(tile); } return cost; @@ -1373,7 +1373,7 @@ if (!IsTileOwner(tile, old_player)) return; if (new_player != 255) { - _map_owner[tile] = new_player; + SetTileOwner(tile, new_player); } else { if((_map5[tile] & 0xC0)==0xC0) { // the stuff BELOW the middle part is owned by the deleted player. @@ -1382,7 +1382,7 @@ _map5[tile] &= ~(1 << 5 | 1 << 4 | 1 << 3); // no transport route under bridge anymore.. } else { // for road, change the owner of the road to local authority - _map_owner[tile] = OWNER_NONE; + SetTileOwner(tile, OWNER_NONE); } } else { DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); diff --git a/unmovable_cmd.c b/unmovable_cmd.c --- a/unmovable_cmd.c +++ b/unmovable_cmd.c @@ -358,7 +358,7 @@ continue; SetTileType(tile, MP_UNMOVABLE); _map5[tile] = 0; - _map_owner[tile] = OWNER_NONE; + SetTileOwner(tile, OWNER_NONE); if (--j == 0) break; } @@ -390,7 +390,7 @@ SetTileType(tile, MP_UNMOVABLE); _map5[tile] = 1; - _map_owner[tile] = OWNER_NONE; + SetTileOwner(tile, OWNER_NONE); } while (--i); } @@ -399,7 +399,7 @@ if (!IsTileOwner(tile, old_player)) return; if (_map5[tile]==3 && new_player != 255) { - _map_owner[tile] = new_player; + SetTileOwner(tile, new_player); } else { DoClearSquare(tile); } diff --git a/water_cmd.c b/water_cmd.c --- a/water_cmd.c +++ b/water_cmd.c @@ -689,7 +689,7 @@ if (!IsTileOwner(tile, old_player)) return; if (new_player != 255) { - _map_owner[tile] = new_player; + SetTileOwner(tile, new_player); } else { DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); }