mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
(svn r2408) Introduce SetTileOwner() and use it
This commit is contained in:
parent
0c4ecbe9ec
commit
74541c1dcc
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
12
rail_cmd.c
12
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);
|
||||
}
|
||||
|
10
road_cmd.c
10
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 {
|
||||
|
@ -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);
|
||||
|
10
tile.h
10
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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user