From ff0030936e9ed7ae92d0a1fef2984b2eed608214 Mon Sep 17 00:00:00 2001 From: tron Date: Sat, 4 Jun 2005 12:13:24 +0000 Subject: (svn r2408) Introduce SetTileOwner() and use it --- landscape.c | 2 +- openttd.c | 8 +++----- rail_cmd.c | 12 ++++++------ road_cmd.c | 10 +++++----- station_cmd.c | 4 ++-- tile.h | 10 ++++++++++ town_cmd.c | 2 +- tree_cmd.c | 2 +- tunnelbridge_cmd.c | 8 ++++---- unmovable_cmd.c | 6 +++--- water_cmd.c | 2 +- 11 files changed, 37 insertions(+), 29 deletions(-) diff --git a/landscape.c b/landscape.c index 881ca67a1..1f5cffddb 100644 --- a/landscape.c +++ b/landscape.c @@ -451,7 +451,7 @@ void ConvertGroundTilesIntoWaterTiles(void) 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 index ffd159aa3..c1205eda3 100644 --- a/openttd.c +++ b/openttd.c @@ -1188,11 +1188,9 @@ static void ConvertTownOwner(void) 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 @@ bool AfterLoadGame(uint version) 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 index 7459b37ac..0b6a8fc92 100644 --- a/rail_cmd.c +++ b/rail_cmd.c @@ -316,7 +316,7 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2) 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 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2) )) { 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 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2) 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 @@ int32 CmdRemoveSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2) 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 @@ int32 CmdRemoveSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2) 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 @@ static void ChangeTileOwner_Track(uint tile, byte old_player, byte new_player) 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 index 26c96bade..f48fb4461 100644 --- a/road_cmd.c +++ b/road_cmd.c @@ -195,7 +195,7 @@ int32 CmdRemoveRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) 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 @@ do_clear:; 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 @@ static void ChangeTileOwner_Road(uint tile, byte old_player, byte new_player) 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 index 1721e38e0..4876b896f 100644 --- a/station_cmd.c +++ b/station_cmd.c @@ -2827,7 +2827,7 @@ void BuildOilRig(uint tile) 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 @@ static void ChangeTileOwner_Station(uint tile, byte old_player, byte new_player) 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 index e19a24b7f..1d8cd094a 100644 --- a/tile.h +++ b/tile.h @@ -88,6 +88,16 @@ static inline Owner GetTileOwner(TileIndex tile) 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 index cea348909..4b13be7b6 100644 --- a/town_cmd.c +++ b/town_cmd.c @@ -746,7 +746,7 @@ static int GrowTownAtRoad(Town *t, uint tile) 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 index e4fe68ffc..52856fe69 100644 --- a/tree_cmd.c +++ b/tree_cmd.c @@ -580,7 +580,7 @@ static void TileLoop_Trees(uint tile) 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 index 7460f7b6e..1aa5a4935 100644 --- a/tunnelbridge_cmd.c +++ b/tunnelbridge_cmd.c @@ -711,7 +711,7 @@ static int32 DoClearBridge(uint tile, uint32 flags) 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 @@ static int32 DoClearBridge(uint tile, uint32 flags) 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 @@ static void ChangeTileOwner_TunnelBridge(uint tile, byte old_player, byte new_pl 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 @@ static void ChangeTileOwner_TunnelBridge(uint tile, byte old_player, byte new_pl _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 index b1a94e167..e7673c599 100644 --- a/unmovable_cmd.c +++ b/unmovable_cmd.c @@ -358,7 +358,7 @@ void GenerateUnmovables(void) 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 @@ restart: SetTileType(tile, MP_UNMOVABLE); _map5[tile] = 1; - _map_owner[tile] = OWNER_NONE; + SetTileOwner(tile, OWNER_NONE); } while (--i); } @@ -399,7 +399,7 @@ static void ChangeTileOwner_Unmovable(uint tile, byte old_player, byte new_playe 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 index 5c476f8c6..31bbb70fa 100644 --- a/water_cmd.c +++ b/water_cmd.c @@ -689,7 +689,7 @@ static void ChangeTileOwner_Water(uint tile, byte old_player, byte new_player) 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); } -- cgit v1.2.3-70-g09d2