mirror of https://github.com/OpenTTD/OpenTTD.git
(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) {
|
if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h == 0) {
|
||||||
SetTileType(tile, MP_WATER);
|
SetTileType(tile, MP_WATER);
|
||||||
_map5[tile] = 0;
|
_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)
|
if ((_map5[tile] & 0xF0) == 0x10 && _map3_lo[tile] & 0x80)
|
||||||
_map3_lo[tile] = OWNER_TOWN;
|
_map3_lo[tile] = OWNER_TOWN;
|
||||||
|
|
||||||
if (_map_owner[tile] & 0x80)
|
if (_map_owner[tile] & 0x80) SetTileOwner(tile, OWNER_TOWN);
|
||||||
_map_owner[tile] = OWNER_TOWN;
|
|
||||||
} else if (IsTileType(tile, MP_TUNNELBRIDGE)) {
|
} else if (IsTileType(tile, MP_TUNNELBRIDGE)) {
|
||||||
if (_map_owner[tile] & 0x80)
|
if (_map_owner[tile] & 0x80) SetTileOwner(tile, OWNER_TOWN);
|
||||||
_map_owner[tile] = OWNER_TOWN;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1300,7 +1298,7 @@ bool AfterLoadGame(uint version)
|
||||||
|
|
||||||
BEGIN_TILE_LOOP(tile_cur, w, h, tile)
|
BEGIN_TILE_LOOP(tile_cur, w, h, tile)
|
||||||
if (IsTileType(tile_cur, MP_WATER) && GetTileOwner(tile_cur) >= MAX_PLAYERS)
|
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)
|
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;
|
cost += ret;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
_map_owner[tile] = _current_player;
|
SetTileOwner(tile, _current_player);
|
||||||
_map3_lo[tile] &= ~0x0F;
|
_map3_lo[tile] &= ~0x0F;
|
||||||
_map3_lo[tile] |= p1;
|
_map3_lo[tile] |= p1;
|
||||||
_map5[tile] = (m5 & 0xC7) | 0x20; // railroad under bridge
|
_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) {
|
if (flags & DC_EXEC) {
|
||||||
_map3_lo[tile] = GetTileOwner(tile);
|
_map3_lo[tile] = GetTileOwner(tile);
|
||||||
_map_owner[tile] = _current_player;
|
SetTileOwner(tile, _current_player);
|
||||||
_map3_hi[tile] = p1;
|
_map3_hi[tile] = p1;
|
||||||
_map5[tile] = 0x10 | (rail_bit == 1 ? 0x08 : 0x00); // level crossing
|
_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) {
|
if (flags & DC_EXEC) {
|
||||||
SetTileType(tile, MP_RAILWAY);
|
SetTileType(tile, MP_RAILWAY);
|
||||||
_map_owner[tile] = _current_player;
|
SetTileOwner(tile, _current_player);
|
||||||
_map2[tile] = 0; // Bare land
|
_map2[tile] = 0; // Bare land
|
||||||
_map3_lo[tile] = p1; // No signals, rail type
|
_map3_lo[tile] = p1; // No signals, rail type
|
||||||
_map5[tile] = rail_bit;
|
_map5[tile] = rail_bit;
|
||||||
|
@ -461,7 +461,7 @@ int32 CmdRemoveSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
if (!(flags & DC_EXEC))
|
if (!(flags & DC_EXEC))
|
||||||
return _price.remove_rail;
|
return _price.remove_rail;
|
||||||
|
|
||||||
_map_owner[tile] = OWNER_NONE;
|
SetTileOwner(tile, OWNER_NONE);
|
||||||
_map5[tile] = ti.map5 & 0xC7;
|
_map5[tile] = ti.map5 & 0xC7;
|
||||||
} else if (ti.type == MP_STREET) {
|
} else if (ti.type == MP_STREET) {
|
||||||
byte m5;
|
byte m5;
|
||||||
|
@ -485,7 +485,7 @@ int32 CmdRemoveSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
return _price.remove_rail;
|
return _price.remove_rail;
|
||||||
|
|
||||||
_map5[tile] = m5;
|
_map5[tile] = m5;
|
||||||
_map_owner[tile] = _map3_lo[tile];
|
SetTileOwner(tile, _map3_lo[tile]);
|
||||||
_map2[tile] = 0;
|
_map2[tile] = 0;
|
||||||
} else {
|
} else {
|
||||||
assert(ti.type == MP_RAILWAY);
|
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 (!IsTileOwner(tile, old_player)) return;
|
||||||
|
|
||||||
if (new_player != 255) {
|
if (new_player != 255) {
|
||||||
_map_owner[tile] = new_player;
|
SetTileOwner(tile, new_player);
|
||||||
} else {
|
} else {
|
||||||
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
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) {
|
if (flags & DC_EXEC) {
|
||||||
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
|
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
|
||||||
_map5[tile] = ti.map5 & 0xC7;
|
_map5[tile] = ti.map5 & 0xC7;
|
||||||
_map_owner[tile] = OWNER_NONE;
|
SetTileOwner(tile, OWNER_NONE);
|
||||||
MarkTileDirtyByTile(tile);
|
MarkTileDirtyByTile(tile);
|
||||||
}
|
}
|
||||||
return cost;
|
return cost;
|
||||||
|
@ -470,7 +470,7 @@ do_clear:;
|
||||||
SetTileType(tile, MP_STREET);
|
SetTileType(tile, MP_STREET);
|
||||||
_map5[tile] = 0;
|
_map5[tile] = 0;
|
||||||
_map2[tile] = p2;
|
_map2[tile] = p2;
|
||||||
_map_owner[tile] = _current_player;
|
SetTileOwner(tile, _current_player);
|
||||||
}
|
}
|
||||||
|
|
||||||
_map5[tile] |= (byte)pieces;
|
_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 (!IsTileOwner(tile, old_player)) return;
|
||||||
|
|
||||||
if (new_player != 255) {
|
if (new_player != 255) {
|
||||||
_map_owner[tile] = new_player;
|
SetTileOwner(tile, new_player);
|
||||||
} else {
|
} else {
|
||||||
b = _map5[tile]&0xF0;
|
b = _map5[tile]&0xF0;
|
||||||
if (b == 0) {
|
if (b == 0) {
|
||||||
_map_owner[tile] = OWNER_NONE;
|
SetTileOwner(tile, OWNER_NONE);
|
||||||
} else if (b == 0x10) {
|
} else if (b == 0x10) {
|
||||||
_map5[tile] = (_map5[tile]&8) ? 0x5 : 0xA;
|
_map5[tile] = (_map5[tile]&8) ? 0x5 : 0xA;
|
||||||
_map_owner[tile] = _map3_lo[tile];
|
SetTileOwner(tile, _map3_lo[tile]);
|
||||||
_map3_lo[tile] = 0;
|
_map3_lo[tile] = 0;
|
||||||
_map3_hi[tile] &= 0x80;
|
_map3_hi[tile] &= 0x80;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2827,7 +2827,7 @@ void BuildOilRig(uint tile)
|
||||||
|
|
||||||
SetTileType(tile, MP_STATION);
|
SetTileType(tile, MP_STATION);
|
||||||
_map5[tile] = 0x4B;
|
_map5[tile] = 0x4B;
|
||||||
_map_owner[tile] = OWNER_NONE;
|
SetTileOwner(tile, OWNER_NONE);
|
||||||
_map3_lo[tile] = 0;
|
_map3_lo[tile] = 0;
|
||||||
_map3_hi[tile] = 0;
|
_map3_hi[tile] = 0;
|
||||||
_map2[tile] = st->index;
|
_map2[tile] = st->index;
|
||||||
|
@ -2884,7 +2884,7 @@ static void ChangeTileOwner_Station(uint tile, byte old_player, byte new_player)
|
||||||
|
|
||||||
if (new_player != 255) {
|
if (new_player != 255) {
|
||||||
Station *st = GetStation(_map2[tile]);
|
Station *st = GetStation(_map2[tile]);
|
||||||
_map_owner[tile] = new_player;
|
SetTileOwner(tile, new_player);
|
||||||
st->owner = new_player;
|
st->owner = new_player;
|
||||||
_global_station_sort_dirty = true; // transfer ownership of station to another player
|
_global_station_sort_dirty = true; // transfer ownership of station to another player
|
||||||
InvalidateWindowClasses(WC_STATION_LIST);
|
InvalidateWindowClasses(WC_STATION_LIST);
|
||||||
|
|
10
tile.h
10
tile.h
|
@ -88,6 +88,16 @@ static inline Owner GetTileOwner(TileIndex tile)
|
||||||
return _map_owner[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)
|
static inline bool IsTileOwner(TileIndex tile, Owner owner)
|
||||||
{
|
{
|
||||||
return GetTileOwner(tile) == owner;
|
return GetTileOwner(tile) == owner;
|
||||||
|
|
|
@ -746,7 +746,7 @@ static int GrowTownAtRoad(Town *t, uint tile)
|
||||||
else if (_game_mode == GM_EDITOR) {
|
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
|
/* 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) */
|
* owner :) (happy happy happy road now) */
|
||||||
_map_owner[tile] = OWNER_TOWN;
|
SetTileOwner(tile, OWNER_TOWN);
|
||||||
_map2[tile] = t->index;
|
_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
|
if ((m2&0x30) != 0x20) // if not on snow/desert, then on rough land
|
||||||
m5 = 7;
|
m5 = 7;
|
||||||
}
|
}
|
||||||
_map_owner[tile] = OWNER_NONE;
|
SetTileOwner(tile, OWNER_NONE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* in the middle of a transition, change to next */
|
/* in the middle of a transition, change to next */
|
||||||
|
|
|
@ -711,7 +711,7 @@ static int32 DoClearBridge(uint tile, uint32 flags)
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
_map5[tile] = _map5[tile] & ~0x38;
|
_map5[tile] = _map5[tile] & ~0x38;
|
||||||
_map_owner[tile] = OWNER_NONE;
|
SetTileOwner(tile, OWNER_NONE);
|
||||||
MarkTileDirtyByTile(tile);
|
MarkTileDirtyByTile(tile);
|
||||||
}
|
}
|
||||||
return cost;
|
return cost;
|
||||||
|
@ -726,7 +726,7 @@ static int32 DoClearBridge(uint tile, uint32 flags)
|
||||||
cost = _price.clear_water;
|
cost = _price.clear_water;
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
_map5[tile] = _map5[tile] & ~0x38;
|
_map5[tile] = _map5[tile] & ~0x38;
|
||||||
_map_owner[tile] = OWNER_NONE;
|
SetTileOwner(tile, OWNER_NONE);
|
||||||
MarkTileDirtyByTile(tile);
|
MarkTileDirtyByTile(tile);
|
||||||
}
|
}
|
||||||
return cost;
|
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 (!IsTileOwner(tile, old_player)) return;
|
||||||
|
|
||||||
if (new_player != 255) {
|
if (new_player != 255) {
|
||||||
_map_owner[tile] = new_player;
|
SetTileOwner(tile, new_player);
|
||||||
} else {
|
} else {
|
||||||
if((_map5[tile] & 0xC0)==0xC0) {
|
if((_map5[tile] & 0xC0)==0xC0) {
|
||||||
// the stuff BELOW the middle part is owned by the deleted player.
|
// 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..
|
_map5[tile] &= ~(1 << 5 | 1 << 4 | 1 << 3); // no transport route under bridge anymore..
|
||||||
} else {
|
} else {
|
||||||
// for road, change the owner of the road to local authority
|
// for road, change the owner of the road to local authority
|
||||||
_map_owner[tile] = OWNER_NONE;
|
SetTileOwner(tile, OWNER_NONE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
||||||
|
|
|
@ -358,7 +358,7 @@ void GenerateUnmovables(void)
|
||||||
continue;
|
continue;
|
||||||
SetTileType(tile, MP_UNMOVABLE);
|
SetTileType(tile, MP_UNMOVABLE);
|
||||||
_map5[tile] = 0;
|
_map5[tile] = 0;
|
||||||
_map_owner[tile] = OWNER_NONE;
|
SetTileOwner(tile, OWNER_NONE);
|
||||||
if (--j == 0)
|
if (--j == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -390,7 +390,7 @@ restart:
|
||||||
|
|
||||||
SetTileType(tile, MP_UNMOVABLE);
|
SetTileType(tile, MP_UNMOVABLE);
|
||||||
_map5[tile] = 1;
|
_map5[tile] = 1;
|
||||||
_map_owner[tile] = OWNER_NONE;
|
SetTileOwner(tile, OWNER_NONE);
|
||||||
} while (--i);
|
} 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 (!IsTileOwner(tile, old_player)) return;
|
||||||
|
|
||||||
if (_map5[tile]==3 && new_player != 255) {
|
if (_map5[tile]==3 && new_player != 255) {
|
||||||
_map_owner[tile] = new_player;
|
SetTileOwner(tile, new_player);
|
||||||
} else {
|
} else {
|
||||||
DoClearSquare(tile);
|
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 (!IsTileOwner(tile, old_player)) return;
|
||||||
|
|
||||||
if (new_player != 255) {
|
if (new_player != 255) {
|
||||||
_map_owner[tile] = new_player;
|
SetTileOwner(tile, new_player);
|
||||||
} else {
|
} else {
|
||||||
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue