(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner

This commit is contained in:
tron 2005-06-04 11:56:32 +00:00
parent 19e2b40a78
commit 0c4ecbe9ec
25 changed files with 118 additions and 122 deletions

17
ai.c
View File

@ -3637,8 +3637,8 @@ static void AiRemovePlayerRailOrRoad(Player *p, TileIndex tile)
byte m5;
if (IsTileType(tile, MP_RAILWAY)) {
if (_map_owner[tile] != _current_player)
return;
if (!IsTileOwner(tile, _current_player)) return;
m5 = _map5[tile];
if ((m5&~0x3) != 0xC0) {
is_rail_crossing:;
@ -3696,8 +3696,7 @@ pos_3:
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
}
} else if (IsTileType(tile, MP_STREET)) {
if (_map_owner[tile] != _current_player)
return;
if (!IsTileOwner(tile, _current_player)) return;
if ( (_map5[tile]&0xF0) == 0x10)
goto is_rail_crossing;
@ -3707,19 +3706,19 @@ pos_3:
// Check if there are any stations around.
if (IsTileType(tile + TILE_XY(-1,0), MP_STATION) &&
_map_owner[tile + TILE_XY(-1,0)] == _current_player)
IsTileOwner(tile + TILE_XY(-1, 0), _current_player))
return;
if (IsTileType(tile + TILE_XY(1,0), MP_STATION) &&
_map_owner[tile + TILE_XY(1,0)] == _current_player)
IsTileOwner(tile + TILE_XY(1, 0), _current_player))
return;
if (IsTileType(tile + TILE_XY(0,-1), MP_STATION) &&
_map_owner[tile + TILE_XY(0,-1)] == _current_player)
IsTileOwner(tile + TILE_XY(0, -1), _current_player))
return;
if (IsTileType(tile + TILE_XY(0,1), MP_STATION) &&
_map_owner[tile + TILE_XY(0,1)] == _current_player)
IsTileOwner(tile + TILE_XY(0, 1), _current_player))
return;
dir = _map5[tile] & 3;
@ -3735,7 +3734,7 @@ pos_3:
} else if (IsTileType(tile, MP_TUNNELBRIDGE)) {
byte b;
if (_map_owner[tile] != _current_player || (_map5[tile] & 0xC6) != 0x80)
if (!IsTileOwner(tile, _current_player) || (_map5[tile] & 0xC6) != 0x80)
return;
m5 = 0;

View File

@ -763,7 +763,7 @@ static void AiNew_State_FindDepot(Player *p) {
// Its a street, test if it is a depot
if (_map5[tile + TileOffsByDir(j)] & 0x20) {
// We found a depot, is it ours? (TELL ME!!!)
if (_map_owner[tile + TileOffsByDir(j)] == _current_player) {
if (IsTileOwner(tile + TileOffsByDir(j), _current_player)) {
// Now, is it pointing to the right direction.........
if ((_map5[tile + TileOffsByDir(j)] & 3) == (j ^ 2)) {
// Yeah!!!
@ -1062,7 +1062,7 @@ static void AiNew_State_BuildDepot(Player *p) {
assert(p->ainew.state == AI_STATE_BUILD_DEPOT);
if (IsTileType(p->ainew.depot_tile, MP_STREET) && _map5[p->ainew.depot_tile] & 0x20) {
if (_map_owner[p->ainew.depot_tile] == _current_player) {
if (IsTileOwner(p->ainew.depot_tile, _current_player)) {
// The depot is already builded!
p->ainew.state = AI_STATE_BUILD_VEHICLE;
return;

View File

@ -178,7 +178,7 @@ int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
// Workaround: TODO: make AI players try to build planes in a hangar instead of just an airport tile.
if (!IsAircraftHangarTile(tile) && IS_HUMAN_PLAYER(_current_player)) return CMD_ERROR;
if (_map_owner[tile] != _current_player && IS_HUMAN_PLAYER(_current_player)) return CMD_ERROR;
if (!IsTileOwner(tile, _current_player) && IS_HUMAN_PLAYER(_current_player)) return CMD_ERROR;
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);

View File

@ -199,7 +199,7 @@ static void ShowBuildAircraftWindow(uint tile)
w->resize.step_height = 24;
if (tile != 0) {
w->caption_color = _map_owner[tile];
w->caption_color = GetTileOwner(tile);
} else {
w->caption_color = _local_player;
}
@ -612,7 +612,8 @@ static void DrawAircraftDepotWindow(Window *w)
tile = w->window_number;
/* setup disabled buttons */
w->disabled_state = (_map_owner[tile]==_local_player) ? 0 : ((1<<4)|(1<<7));
w->disabled_state =
IsTileOwner(tile, _local_player) ? 0 : ((1 << 4) | (1 << 7));
/* determine amount of items for scroller */
num = 0;
@ -828,7 +829,7 @@ void ShowAircraftDepotWindow(uint tile)
w = AllocateWindowDescFront(&_aircraft_depot_desc, tile);
if (w) {
w->caption_color = _map_owner[tile];
w->caption_color = GetTileOwner(tile);
w->vscroll.cap = 2;
w->hscroll.cap = 4;
w->resize.step_width = 74;
@ -1013,7 +1014,7 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e)
tile = _last_built_aircraft_depot_tile;
do {
if (_map_owner[tile] == _local_player && IsAircraftHangarTile(tile)) {
if (IsTileOwner(tile, _local_player) && IsAircraftHangarTile(tile)) {
ShowAircraftDepotWindow(tile);
ShowBuildAircraftWindow(tile);
return;

View File

@ -399,7 +399,8 @@ int32 CmdPurchaseLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
if (IsTileType(tile, MP_UNMOVABLE) && _map5[tile] == 3 && _map_owner[tile] == _current_player)
if (IsTileType(tile, MP_UNMOVABLE) && _map5[tile] == 3 &&
IsTileOwner(tile, _current_player))
return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT);
cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
@ -837,7 +838,7 @@ static void GetTileDesc_Clear(uint tile, TileDesc *td)
if (i == 0)
i = (_map5[tile] & 3) + 8;
td->str = _clear_land_str[i - 1];
td->owner = _map_owner[tile];
td->owner = GetTileOwner(tile);
}
static void ChangeTileOwner_Clear(uint tile, byte old_player, byte new_player)

View File

@ -21,7 +21,7 @@ static void DisasterClearSquare(TileIndex tile)
switch (GetTileType(tile)) {
case MP_RAILWAY:
if (IS_HUMAN_PLAYER(_map_owner[tile])) DoClearSquare(tile);
if (IS_HUMAN_PLAYER(GetTileOwner(tile))) DoClearSquare(tile);
break;
case MP_HOUSE: {
@ -173,9 +173,8 @@ static void DisasterTick_Zeppeliner(Vehicle *v)
if (IsValidTile(tile) &&
IsTileType(tile, MP_STATION) &&
IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
IS_HUMAN_PLAYER(_map_owner[tile])) {
IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
IS_HUMAN_PLAYER(GetTileOwner(tile))) {
v->current_order.station = 1;
v->age = 0;
@ -199,9 +198,8 @@ static void DisasterTick_Zeppeliner(Vehicle *v)
if (IsValidTile(tile) &&
IsTileType(tile, MP_STATION) &&
IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
IS_HUMAN_PLAYER(_map_owner[tile])) {
IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
IS_HUMAN_PLAYER(GetTileOwner(tile))) {
st = GetStation(_map2[tile]);
CLRBITS(st->airport_flags, RUNWAY_IN_block);
}
@ -242,8 +240,8 @@ static void DisasterTick_Zeppeliner(Vehicle *v)
tile = v->tile;/**/
if (IsValidTile(tile) &&
IsTileType(tile, MP_STATION) &&
IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
IS_HUMAN_PLAYER(_map_owner[tile])) {
IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
IS_HUMAN_PLAYER(GetTileOwner(tile))) {
st = GetStation(_map2[tile]);
SETBITS(st->airport_flags, RUNWAY_IN_block);
@ -581,8 +579,8 @@ static void DisasterTick_4(Vehicle *v)
tile_org = tile = TILE_MASK(Random());
do {
if (IsTileType(tile, MP_RAILWAY) &&
(_map5[tile]&~3)!=0xC0 && IS_HUMAN_PLAYER(_map_owner[tile]))
break;
(_map5[tile] & ~3) != 0xC0 && IS_HUMAN_PLAYER(GetTileOwner(tile)))
break;
tile = TILE_MASK(tile+1);
} while (tile != tile_org);
v->dest_tile = tile;

View File

@ -1299,7 +1299,7 @@ bool AfterLoadGame(uint version)
uint h = MapSizeY();
BEGIN_TILE_LOOP(tile_cur, w, h, tile)
if (IsTileType(tile_cur, MP_WATER) && _map_owner[tile_cur] >= MAX_PLAYERS)
if (IsTileType(tile_cur, MP_WATER) && GetTileOwner(tile_cur) >= MAX_PLAYERS)
_map_owner[tile_cur] = OWNER_WATER;
END_TILE_LOOP(tile_cur, w, h, tile)
}
@ -1393,13 +1393,14 @@ bool AfterLoadGame(uint version)
SetTileType(tile, MP_HOUSE);
} else if (IsTileType(tile, MP_STREET)) {
//XXX magic
SetTileType(tile, MP_VOID);
_map3_hi[tile] |= (_map2[tile] << 4);
if ( _map_owner[tile] == OWNER_TOWN)
if (IsTileOwner(tile, OWNER_TOWN)) {
SetTileType(tile, MP_VOID);
_map2[tile] = ClosestTownFromTile(tile,(uint)-1)->index;
else
SetTileType(tile, MP_STREET);
} else {
_map2[tile] = 0;
SetTileType(tile, MP_STREET);
}
}
} END_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0);
}

View File

@ -167,7 +167,7 @@ static Order GetOrderCmdFromTile(Vehicle *v, uint tile)
if (_patches.gotodepot) {
switch (GetTileType(tile)) {
case MP_RAILWAY:
if (v->type == VEH_Train && _map_owner[tile] == _local_player) {
if (v->type == VEH_Train && IsTileOwner(tile, _local_player)) {
if ((_map5[tile]&0xFC)==0xC0) {
order.type = OT_GOTO_DEPOT;
order.flags = OF_PART_OF_ORDERS;
@ -178,7 +178,7 @@ static Order GetOrderCmdFromTile(Vehicle *v, uint tile)
break;
case MP_STREET:
if ((_map5[tile] & 0xF0) == 0x20 && v->type == VEH_Road && _map_owner[tile] == _local_player) {
if ((_map5[tile] & 0xF0) == 0x20 && v->type == VEH_Road && IsTileOwner(tile, _local_player)) {
order.type = OT_GOTO_DEPOT;
order.flags = OF_PART_OF_ORDERS;
order.station = GetDepotByTile(tile)->index;
@ -188,7 +188,7 @@ static Order GetOrderCmdFromTile(Vehicle *v, uint tile)
case MP_STATION:
if (v->type != VEH_Aircraft) break;
if ( IsAircraftHangarTile(tile) && _map_owner[tile] == _local_player) {
if (IsAircraftHangarTile(tile) && IsTileOwner(tile, _local_player)) {
order.type = OT_GOTO_DEPOT;
order.flags = OF_PART_OF_ORDERS | OF_NON_STOP; //XXX - whats the nonstop stuff doing here?
order.station = _map2[tile];
@ -216,10 +216,10 @@ static Order GetOrderCmdFromTile(Vehicle *v, uint tile)
}
// check waypoint
if (IsTileType(tile, MP_RAILWAY)
&& v->type == VEH_Train
&& _map_owner[tile] == _local_player
&& (_map5[tile]&0xFE)==0xC4) {
if (IsTileType(tile, MP_RAILWAY) &&
v->type == VEH_Train &&
IsTileOwner(tile, _local_player) &&
(_map5[tile] & 0xFE) == 0xC4) {
order.type = OT_GOTO_WAYPOINT;
order.flags = 0;
order.station = GetWaypointByTile(tile)->index;

View File

@ -133,7 +133,7 @@ static void TPFMode2(TrackPathFinder *tpf, uint tile, int direction)
if (tpf->tracktype == TRANSPORT_RAIL) {
if (IsTileType(tile, MP_RAILWAY) || IsTileType(tile, MP_STATION) || IsTileType(tile, MP_TUNNELBRIDGE)) {
owner = _map_owner[tile];
owner = GetTileOwner(tile);
/* Check if we are on the middle of a bridge (has no owner) */
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xC0) == 0xC0)
owner = -1;
@ -150,7 +150,7 @@ static void TPFMode2(TrackPathFinder *tpf, uint tile, int direction)
if (IsTileType(tile, MP_RAILWAY) || IsTileType(tile, MP_STATION) || IsTileType(tile, MP_TUNNELBRIDGE))
/* Check if we are on the middle of a bridge (has no owner) */
if (!IsTileType(tile, MP_TUNNELBRIDGE) || (_map5[tile] & 0xC0) != 0xC0)
if (owner != -1 && _map_owner[tile] != owner)
if (owner != -1 && !IsTileOwner(tile, owner))
return;
}
@ -296,7 +296,7 @@ static void TPFMode1(TrackPathFinder *tpf, uint tile, int direction)
/* Check if we are on a bridge (middle parts don't have an owner */
if (!IsTileType(tile, MP_TUNNELBRIDGE) || (_map5[tile] & 0xC0) != 0xC0)
if (!IsTileType(tile_org, MP_TUNNELBRIDGE) || (_map5[tile_org] & 0xC0) != 0xC0)
if (_map_owner[tile_org] != _map_owner[tile])
if (GetTileOwner(tile_org) != GetTileOwner(tile))
return;
}

View File

@ -281,8 +281,10 @@ bool CheckOwnership(byte owner)
bool CheckTileOwnership(uint tile)
{
byte owner = _map_owner[tile];
byte owner = GetTileOwner(tile);
assert(owner <= OWNER_WATER);
if (owner == _current_player)
return true;
_error_message = STR_013B_OWNED_BY;

View File

@ -364,7 +364,7 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
(rail_bit == 2 && m5 == 0x0A) // correct direction?
)) {
if (flags & DC_EXEC) {
_map3_lo[tile] = _map_owner[tile];
_map3_lo[tile] = GetTileOwner(tile);
_map_owner[tile] = _current_player;
_map3_hi[tile] = p1;
_map5[tile] = 0x10 | (rail_bit == 1 ? 0x08 : 0x00); // level crossing
@ -1067,7 +1067,7 @@ static int32 ClearTile_Track(TileIndex tile, byte flags)
if (m5 & RAIL_TYPE_SPECIAL)
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
if (_map_owner[tile] != _current_player)
if (!IsTileOwner(tile, _current_player))
return_cmd_error(STR_1024_AREA_IS_OWNED_BY_ANOTHER);
return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK);
@ -1324,7 +1324,7 @@ static void DrawTile_Track(TileInfo *ti)
uint32 tracktype_offs, image;
byte m5;
_drawtile_track_palette = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_map_owner[ti->tile]));
_drawtile_track_palette = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)));
tracktype_offs = (_map3_lo[ti->tile] & 0xF) * TRACKTYPE_SPRITE_PITCH;
@ -1900,32 +1900,32 @@ static void TileLoop_Track(uint tile)
} else if (rail == RAIL_BIT_RIGHT) {
a2 = RAIL_GROUND_FENCE_VERT2;
} else {
owner = _map_owner[tile];
owner = GetTileOwner(tile);
if ( (!(rail&(RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LEFT)) && (rail&RAIL_BIT_DIAG1)) || rail==(RAIL_BIT_LOWER|RAIL_BIT_RIGHT)) {
if (!IsTileType(tile + TILE_XY(0,-1), MP_RAILWAY) ||
owner != _map_owner[tile + TILE_XY(0,-1)] ||
!IsTileOwner(tile + TILE_XY(0, -1), owner) ||
(_map5[tile + TILE_XY(0,-1)]==RAIL_BIT_UPPER || _map5[tile + TILE_XY(0,-1)]==RAIL_BIT_LEFT))
a2 = RAIL_GROUND_FENCE_NW;
}
if ( (!(rail&(RAIL_BIT_DIAG2|RAIL_BIT_LOWER|RAIL_BIT_RIGHT)) && (rail&RAIL_BIT_DIAG1)) || rail==(RAIL_BIT_UPPER|RAIL_BIT_LEFT)) {
if (!IsTileType(tile + TILE_XY(0,1), MP_RAILWAY) ||
owner != _map_owner[tile + TILE_XY(0,1)] ||
!IsTileOwner(tile + TILE_XY(0, 1), owner) ||
(_map5[tile + TILE_XY(0,1)]==RAIL_BIT_LOWER || _map5[tile + TILE_XY(0,1)]==RAIL_BIT_RIGHT))
a2 = (a2 == RAIL_GROUND_FENCE_NW) ? RAIL_GROUND_FENCE_SENW : RAIL_GROUND_FENCE_SE;
}
if ( (!(rail&(RAIL_BIT_DIAG1|RAIL_BIT_UPPER|RAIL_BIT_RIGHT)) && (rail&RAIL_BIT_DIAG2)) || rail==(RAIL_BIT_LOWER|RAIL_BIT_LEFT)) {
if (!IsTileType(tile + TILE_XY(-1,0), MP_RAILWAY) ||
owner != _map_owner[tile + TILE_XY(-1,0)] ||
!IsTileOwner(tile + TILE_XY(-1, 0), owner) ||
(_map5[tile + TILE_XY(-1,0)]==RAIL_BIT_UPPER || _map5[tile + TILE_XY(-1,0)]==RAIL_BIT_RIGHT))
a2 = RAIL_GROUND_FENCE_NE;
}
if ( (!(rail&(RAIL_BIT_DIAG1|RAIL_BIT_LOWER|RAIL_BIT_LEFT)) && (rail&RAIL_BIT_DIAG2)) || rail==(RAIL_BIT_UPPER|RAIL_BIT_RIGHT)) {
if (!IsTileType(tile + TILE_XY(1,0), MP_RAILWAY) ||
owner != _map_owner[tile + TILE_XY(1,0)] ||
!IsTileOwner(tile + TILE_XY(1, 0), owner) ||
(_map5[tile + TILE_XY(1,0)]==RAIL_BIT_LOWER || _map5[tile + TILE_XY(1,0)]==RAIL_BIT_LEFT))
a2 = (a2 == RAIL_GROUND_FENCE_NE) ? RAIL_GROUND_FENCE_NESW : RAIL_GROUND_FENCE_SW;
}
@ -1997,7 +1997,7 @@ static void ClickTile_Track(uint tile)
static void GetTileDesc_Track(TileIndex tile, TileDesc *td)
{
td->owner = _map_owner[tile];
td->owner = GetTileOwner(tile);
switch (_map5[tile] & RAIL_TYPE_MASK) {
case RAIL_TYPE_NORMAL:
td->str = STR_1021_RAILROAD_TRACK;
@ -2025,8 +2025,7 @@ static void GetTileDesc_Track(TileIndex tile, TileDesc *td)
static void ChangeTileOwner_Track(uint tile, byte old_player, byte new_player)
{
if (_map_owner[tile] != old_player)
return;
if (!IsTileOwner(tile, old_player)) return;
if (new_player != 255) {
_map_owner[tile] = new_player;

View File

@ -81,7 +81,7 @@ static bool CheckAllowRemoveRoad(uint tile, uint br, bool *edge_road)
if (IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x10) {
owner = _map3_lo[tile];
} else {
owner = _map_owner[tile];
owner = GetTileOwner(tile);
}
// Only do the special processing if the road is owned
// by a town
@ -157,7 +157,7 @@ int32 CmdRemoveRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x10) {
owner = _map3_lo[tile];
} else
owner = _map_owner[tile];
owner = GetTileOwner(tile);
if (owner == OWNER_TOWN && _game_mode != GM_EDITOR) {
if (IsTileType(tile, MP_TUNNELBRIDGE)) { // index of town is not saved for bridge (no space)
@ -686,7 +686,7 @@ static int32 ClearTile_Road(uint tile, byte flags) {
byte b = m5 & 0xF;
if (! ((1 << b) & (M(1)|M(2)|M(4)|M(8))) ) {
if ( (!(flags & DC_AI_BUILDING) || _map_owner[tile]!=OWNER_TOWN) && flags&DC_AUTO)
if ((!(flags & DC_AI_BUILDING) || !IsTileOwner(tile, OWNER_TOWN)) && flags & DC_AUTO)
return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
}
return DoCommandByTile(tile, b, 0, flags, CMD_REMOVE_ROAD);
@ -835,7 +835,7 @@ static void DrawTile_Road(TileInfo *ti)
if (ti->tileh != 0) { DrawFoundation(ti, ti->tileh); }
ormod = 0x315;
player = _map_owner[ti->tile];
player = GetTileOwner(ti->tile);
if (player < MAX_PLAYERS)
ormod = PLAYER_SPRITE_COLOR(player);
@ -1101,7 +1101,7 @@ static void GetTileDesc_Road(uint tile, TileDesc *td)
if (i == 0)
i = ((_map3_hi[tile] & 0x70) >> 4) + 3;
td->str = _road_tile_strings[i - 1];
td->owner = _map_owner[tile];
td->owner = GetTileOwner(tile);
}
static const byte _roadveh_enter_depot_unk0[4] = {
@ -1145,8 +1145,7 @@ static void ChangeTileOwner_Road(uint tile, byte old_player, byte new_player)
_map3_lo[tile] = (new_player == 0xFF) ? OWNER_NONE : new_player;
}
if (_map_owner[tile] != old_player)
return;
if (!IsTileOwner(tile, old_player)) return;
if (new_player != 255) {
_map_owner[tile] = new_player;

View File

@ -133,7 +133,7 @@ int32 CmdBuildRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
/* The ai_new queries the vehicle cost before building the route,
* so we must check against cheaters no sooner than now. --pasky */
if (!IsTileDepotType(tile, TRANSPORT_ROAD)) return CMD_ERROR;
if (_map_owner[tile] != _current_player) return CMD_ERROR;
if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
v = AllocateVehicle();
if (v == NULL || IsOrderPoolFull())
@ -297,7 +297,7 @@ static bool EnumRoadSignalFindDepot(uint tile, RoadFindDepotData *rfdd, int trac
if (IsTileType(tile, MP_STREET) &&
(_map5[tile] & 0xF0) == 0x20 &&
_map_owner[tile] == rfdd->owner) {
IsTileOwner(tile, rfdd->owner)) {
if (length < rfdd->best_length) {
rfdd->best_length = length;
@ -1048,11 +1048,11 @@ static int RoadFindPathToDest(Vehicle *v, uint tile, int enterdir)
}
if (IsTileType(tile, MP_STREET)) {
if ((_map5[tile]&0xF0) == 0x20 && v->owner == _map_owner[tile])
if ((_map5[tile]&0xF0) == 0x20 && IsTileOwner(tile, v->owner))
/* Road crossing */
bitmask |= _road_veh_fp_ax_or[_map5[tile]&3];
} else if (IsTileType(tile, MP_STATION)) {
if (_map_owner[tile] == OWNER_NONE || _map_owner[tile] == v->owner) {
if (IsTileOwner(tile, OWNER_NONE) || IsTileOwner(tile, v->owner)) {
/* Our station */
Station *st = GetStation(_map2[tile]);
byte val = _map5[tile];

View File

@ -494,7 +494,7 @@ static void ShowBuildRoadVehWindow(TileIndex tile)
w->resize.height = w->height - 14 * 4; /* Minimum of 4 vehicles in the display */
if (tile != 0) {
w->caption_color = _map_owner[tile];
w->caption_color = GetTileOwner(tile);
} else {
w->caption_color = _local_player;
}
@ -510,7 +510,8 @@ static void DrawRoadDepotWindow(Window *w)
tile = w->window_number;
/* setup disabled buttons */
w->disabled_state = (_map_owner[tile]==_local_player) ? 0 : ((1<<4)|(1<<7));
w->disabled_state =
IsTileOwner(tile, _local_player) ? 0 : ((1 << 4) | (1 << 7));
/* determine amount of items for scroller */
num = 0;
@ -734,7 +735,7 @@ void ShowRoadDepotWindow(uint tile)
w = AllocateWindowDescFront(&_road_depot_desc, tile);
if (w) {
w->caption_color = _map_owner[w->window_number];
w->caption_color = GetTileOwner(w->window_number);
w->hscroll.cap = 5;
w->vscroll.cap = 3;
w->resize.step_width = 56;

View File

@ -876,7 +876,7 @@ int32 CmdBuildShip(int x, int y, uint32 flags, uint32 p1, uint32 p2)
/* The ai_new queries the vehicle cost before building the route,
* so we must check against cheaters no sooner than now. --pasky */
if (!IsTileDepotType(tile, TRANSPORT_WATER)) return CMD_ERROR;
if (_map_owner[tile] != _current_player) return CMD_ERROR;
if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
v = AllocateVehicle();
if (v == NULL || IsOrderPoolFull() ||

View File

@ -428,7 +428,7 @@ static void ShowBuildShipWindow(TileIndex tile)
w->resize.step_height = 24;
if (tile != 0) {
w->caption_color = _map_owner[tile];
w->caption_color = GetTileOwner(tile);
} else {
w->caption_color = _local_player;
}
@ -588,7 +588,8 @@ static void DrawShipDepotWindow(Window *w)
tile = w->window_number;
/* setup disabled buttons */
w->disabled_state = (_map_owner[tile]==_local_player) ? 0 : ((1<<4)|(1<<7));
w->disabled_state =
IsTileOwner(tile, _local_player) ? 0 : ((1 << 4) | (1 << 7));
/* determine amount of items for scroller */
num = 0;
@ -808,7 +809,7 @@ void ShowShipDepotWindow(uint tile)
w = AllocateWindowDescFront(&_ship_depot_desc,tile);
if (w) {
w->caption_color = _map_owner[w->window_number];
w->caption_color = GetTileOwner(w->window_number);
w->vscroll.cap = 2;
w->hscroll.cap = 3;
w->resize.step_width = 90;
@ -995,7 +996,7 @@ static void PlayerShipsWndProc(Window *w, WindowEvent *e)
tile = _last_built_ship_depot_tile;
do {
if (_map_owner[tile] == _local_player && IsTileDepotType(tile, TRANSPORT_WATER)) {
if (IsTileOwner(tile, _local_player) && IsTileDepotType(tile, TRANSPORT_WATER)) {
ShowShipDepotWindow(tile);
ShowBuildShipWindow(tile);
return;

View File

@ -496,12 +496,12 @@ static inline uint32 GetSmallMapOwnerPixels(TileIndex tile)
{
TileType t = GetTileType(tile);
if (t == MP_HOUSE || _map_owner[tile] == OWNER_TOWN) {
t = 0x80;
} else if (t == MP_INDUSTRY) {
if (t == MP_INDUSTRY) {
t = 0xff;
} else if (t == MP_HOUSE || IsTileOwner(tile, OWNER_TOWN)) {
t = 0x80;
} else {
t = _map_owner[tile];
t = GetTileOwner(tile);
}
return _owner_colors[t];

View File

@ -2103,7 +2103,7 @@ static void DrawTile_Station(TileInfo *ti)
uint32 relocation = 0;
{
uint owner = _map_owner[ti->tile];
uint owner = GetTileOwner(ti->tile);
image_or_modificator = 0x315 << 16; /* NOTE: possible bug in ttd here? */
if (owner < MAX_PLAYERS)
image_or_modificator = PLAYER_SPRITE_COLOR(owner);
@ -2204,7 +2204,7 @@ static void GetTileDesc_Station(uint tile, TileDesc *td)
byte m5;
StringID str;
td->owner = _map_owner[tile];
td->owner = GetTileOwner(tile);
td->build_date = GetStation(_map2[tile])->build_date;
m5 = _map5[tile];
@ -2880,8 +2880,7 @@ void DeleteOilRig(uint tile)
static void ChangeTileOwner_Station(uint tile, byte old_player, byte new_player)
{
if (_map_owner[tile] != old_player)
return;
if (!IsTileOwner(tile, old_player)) return;
if (new_player != 255) {
Station *st = GetStation(_map2[tile]);

View File

@ -741,7 +741,7 @@ static int GrowTownAtRoad(Town *t, uint tile)
if (IsTileType(tile, MP_STREET)) {
/* Don't allow building over roads of other cities */
if (_map_owner[tile] == OWNER_TOWN && GetTown(_map2[tile]) != t)
if (IsTileOwner(tile, OWNER_TOWN) && GetTown(_map2[tile]) != t)
_grow_town_result = -1;
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
@ -1495,7 +1495,7 @@ void DeleteTown(Town *t)
case MP_STREET:
case MP_TUNNELBRIDGE:
if (_map_owner[tile] == OWNER_TOWN &&
if (IsTileOwner(tile, OWNER_TOWN) &&
ClosestTownFromTile(tile, (uint)-1) == t)
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
break;
@ -1837,15 +1837,12 @@ Town *ClosestTownFromTile(uint tile, uint threshold)
Town *t;
uint dist, best = threshold;
Town *best_town = NULL;
byte owner;
// XXX - Fix this so for a given tiletype the owner of the type is in the same variable
if (IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x10) { // rail crossing
owner = _map3_lo[tile];
} else
owner = _map_owner[tile];
if ((IsTileType(tile, MP_STREET) && owner == OWNER_TOWN) || IsTileType(tile, MP_HOUSE))
if (IsTileType(tile, MP_HOUSE) || (
IsTileType(tile, MP_STREET) &&
((_map5[tile] & 0xF0) != 0x10 ? GetTileOwner(tile) : _map3_lo[tile]) == OWNER_TOWN
))
return GetTown(_map2[tile]);
FOR_ALL_TOWNS(t) {

View File

@ -538,7 +538,7 @@ int32 CmdBuildRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
* to the player. Doesn't matter if only the cost is queried */
if (!(flags & DC_QUERY_COST)) {
if (!IsTileDepotType(tile, TRANSPORT_RAIL)) return CMD_ERROR;
if (_map_owner[tile] != _current_player) return CMD_ERROR;
if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
}
_cmd_build_rail_veh_var1 = 0;
@ -1387,7 +1387,7 @@ typedef struct TrainFindDepotData {
static bool TrainFindDepotEnumProc(uint tile, TrainFindDepotData *tfdd, int track, uint length, byte *state)
{
if (IsTileType(tile, MP_RAILWAY) && _map_owner[tile] == tfdd->owner) {
if (IsTileType(tile, MP_RAILWAY) && IsTileOwner(tile, tfdd->owner)) {
if ((_map5[tile] & ~0x3) == 0xC0) {
if (length < tfdd->best_length) {
tfdd->best_length = length;
@ -2314,7 +2314,7 @@ static bool CheckCompatibleRail(const Vehicle *v, TileIndex tile)
case MP_STREET:
// tracks over roads, do owner check of tracks (_map_owner[tile])
return
_map_owner[tile] == v->owner &&
IsTileOwner(tile, v->owner) &&
(v->subtype != TS_Front_Engine || (_map3_hi[tile] & 0xF) == v->u.rail.railtype);
default:
@ -2322,7 +2322,7 @@ static bool CheckCompatibleRail(const Vehicle *v, TileIndex tile)
}
return
_map_owner[tile] == v->owner &&
IsTileOwner(tile, v->owner) &&
(v->subtype != TS_Front_Engine || (_map3_lo[tile] & 0xF) == v->u.rail.railtype);
}

View File

@ -271,7 +271,7 @@ static void ShowBuildTrainWindow(uint tile)
w->resize.height = w->height - 14 * 4; /* Minimum of 4 vehicles in the display */
if (tile != 0) {
w->caption_color = _map_owner[tile];
w->caption_color = GetTileOwner(tile);
WP(w,buildtrain_d).railtype = _map3_lo[tile] & 0xF;
} else {
w->caption_color = _local_player;
@ -307,7 +307,8 @@ static void DrawTrainDepotWindow(Window *w)
tile = w->window_number;
/* setup disabled buttons */
w->disabled_state = (_map_owner[tile]==_local_player) ? 0 : ((1<<4)|(1<<5)|(1<<8));
w->disabled_state =
IsTileOwner(tile, _local_player) ? 0 : ((1 << 4) | (1 << 5) | (1 << 8));
/* determine amount of items for scroller */
num = 0;
@ -651,7 +652,7 @@ void ShowTrainDepotWindow(uint tile)
w = AllocateWindowDescFront(&_train_depot_desc, tile);
if (w) {
w->caption_color = _map_owner[w->window_number];
w->caption_color = GetTileOwner(w->window_number);
w->vscroll.cap = 6;
w->hscroll.cap = 10;
w->resize.step_width = 29;
@ -1345,7 +1346,7 @@ static void PlayerTrainsWndProc(Window *w, WindowEvent *e)
tile = _last_built_train_depot_tile;
do {
if (_map_owner[tile] == _local_player && IsTileDepotType(tile, TRANSPORT_RAIL)) {
if (IsTileOwner(tile, _local_player) && IsTileDepotType(tile, TRANSPORT_RAIL)) {
ShowTrainDepotWindow(tile);
ShowBuildTrainWindow(tile);
return;

View File

@ -195,7 +195,7 @@ int32 CmdPlantTree(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
break;
case MP_CLEAR:
if (_map_owner[ti.tile] != OWNER_NONE) {
if (!IsTileOwner(ti.tile, OWNER_NONE)) {
_error_message = STR_2804_SITE_UNSUITABLE;
continue;
}
@ -396,7 +396,7 @@ static void GetTileDesc_Trees(uint tile, TileDesc *td)
byte b;
StringID str;
td->owner = _map_owner[tile];
td->owner = GetTileOwner(tile);
b = _map3_lo[tile];
(str=STR_2810_CACTUS_PLANTS, b==0x1B) ||

View File

@ -628,7 +628,7 @@ static int32 DoClearTunnel(uint tile, uint32 flags)
// in scenario editor you can always destroy tunnels
if (_game_mode != GM_EDITOR && !CheckTileOwnership(tile)) {
if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || _map_owner[tile] != OWNER_TOWN)
if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || !IsTileOwner(tile, OWNER_TOWN))
return CMD_ERROR;
}
@ -640,7 +640,7 @@ static int32 DoClearTunnel(uint tile, uint32 flags)
t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty
// check if you're allowed to remove the tunnel owned by a town
// removal allowal depends on difficulty settings
if(_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR ) {
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
if (!CheckforTownRating(tile, flags, t, TUNNELBRIDGE_REMOVE)) {
SetDParam(0, t->index);
return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES);
@ -656,7 +656,7 @@ static int32 DoClearTunnel(uint tile, uint32 flags)
DoClearSquare(endtile);
UpdateSignalsOnSegment(tile, _updsignals_tunnel_dir[tile_dir]);
UpdateSignalsOnSegment(endtile, _updsignals_tunnel_dir[endtile_dir]);
if (_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR)
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR)
ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
}
return _price.clear_tunnel * (length + 1);
@ -736,7 +736,7 @@ static int32 DoClearBridge(uint tile, uint32 flags)
// floods, scenario editor can always destroy bridges
if (_current_player != OWNER_WATER && _game_mode != GM_EDITOR && !CheckTileOwnership(tile)) {
if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || _map_owner[tile] != OWNER_TOWN)
if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || !IsTileOwner(tile, OWNER_TOWN))
return CMD_ERROR;
}
@ -763,7 +763,7 @@ static int32 DoClearBridge(uint tile, uint32 flags)
t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty
// check if you're allowed to remove the bridge owned by a town.
// removal allowal depends on difficulty settings
if(_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR) {
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
if (!CheckforTownRating(tile, flags, t, TUNNELBRIDGE_REMOVE))
return CMD_ERROR;
}
@ -775,7 +775,7 @@ static int32 DoClearBridge(uint tile, uint32 flags)
//checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
// you have a "Poor" (0) town rating
if (_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR)
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR)
ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
do {
@ -1281,7 +1281,7 @@ static void GetTileDesc_TunnelBridge(uint tile, TileDesc *td)
do tile += delta; while (_map5[tile] & 0x40);
}
}
td->owner = _map_owner[tile];
td->owner = GetTileOwner(tile);
}
@ -1370,8 +1370,7 @@ static uint32 GetTileTrackStatus_TunnelBridge(uint tile, TransportType mode)
static void ChangeTileOwner_TunnelBridge(uint tile, byte old_player, byte new_player)
{
if (_map_owner[tile] != old_player)
return;
if (!IsTileOwner(tile, old_player)) return;
if (new_player != 255) {
_map_owner[tile] = new_player;

View File

@ -122,7 +122,7 @@ static void DrawTile_Unmovable(TileInfo *ti)
// statue
DrawGroundSprite(0x58C);
image = PLAYER_SPRITE_COLOR(_map_owner[ti->tile]);
image = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
image += 0x8A48;
if (_display_opt & DO_TRANS_BUILDINGS)
image = (image & 0x3FFF) | 0x3224000;
@ -133,7 +133,7 @@ static void DrawTile_Unmovable(TileInfo *ti)
DrawClearLandTile(ti, 0);
AddSortableSpriteToDraw(
PLAYER_SPRITE_COLOR(_map_owner[ti->tile]) + 0x92B6,
PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)) + 0x92B6,
ti->x+8, ti->y+8,
1, 1,
10,
@ -165,7 +165,7 @@ static void DrawTile_Unmovable(TileInfo *ti)
if (ti->tileh) DrawFoundation(ti, ti->tileh);
ormod = PLAYER_SPRITE_COLOR(_map_owner[ti->tile]);
ormod = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
t = &_unmovable_display_datas[ti->map5 & 0x7F];
DrawGroundSprite(t->ground_sprite | ormod);
@ -255,7 +255,7 @@ static void GetTileDesc_Unmovable(uint tile, TileDesc *td)
int i = _map5[tile];
if (i & 0x80) i = -1;
td->str = _unmovable_tile_str[i + 1];
td->owner = _map_owner[tile];
td->owner = GetTileOwner(tile);
}
static void AnimateTile_Unmovable(uint tile)
@ -308,7 +308,7 @@ static uint32 GetTileTrackStatus_Unmovable(uint tile, TransportType mode)
static void ClickTile_Unmovable(uint tile)
{
if (_map5[tile] & 0x80) {
ShowPlayerCompany(_map_owner[tile]);
ShowPlayerCompany(GetTileOwner(tile));
}
}
@ -396,8 +396,7 @@ restart:
static void ChangeTileOwner_Unmovable(uint tile, byte old_player, byte new_player)
{
if (_map_owner[tile] != old_player)
return;
if (!IsTileOwner(tile, old_player)) return;
if (_map5[tile]==3 && new_player != 255) {
_map_owner[tile] = new_player;

View File

@ -421,7 +421,7 @@ static void DrawTile_Water(TileInfo *ti)
return;
}
DrawWaterStuff(ti, _shipdepot_display_seq[ti->map5 & 0x7F], PLAYER_SPRITE_COLOR(_map_owner[ti->tile]), 0);
DrawWaterStuff(ti, _shipdepot_display_seq[ti->map5 & 0x7F], PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)), 0);
}
void DrawShipDepotSprite(int x, int y, int image)
@ -465,7 +465,7 @@ static void GetTileDesc_Water(uint tile, TileDesc *td)
else
td->str = STR_3806_SHIP_DEPOT;
td->owner = _map_owner[tile];
td->owner = GetTileOwner(tile);
}
static void AnimateTile_Water(uint tile)
@ -686,8 +686,7 @@ static void ClickTile_Water(uint tile)
static void ChangeTileOwner_Water(uint tile, byte old_player, byte new_player)
{
if (_map_owner[tile] != old_player)
return;
if (!IsTileOwner(tile, old_player)) return;
if (new_player != 255) {
_map_owner[tile] = new_player;