(svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.

-Fix: Before evaluating RoadOwner, check if the roadtype is present.
-Fix: Some places assumed that MP_ROAD means normal street.
This commit is contained in:
frosch 2008-05-24 19:36:20 +00:00
parent c34b458ace
commit 6e7a7412cd
6 changed files with 34 additions and 28 deletions

View File

@ -3763,11 +3763,11 @@ pos_3:
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
}
} else if (IsTileType(tile, MP_ROAD)) {
if (!IsTileOwner(tile, _current_player)) return;
if (IsLevelCrossing(tile)) goto is_rail_crossing;
if (IsRoadDepot(tile)) {
if (!IsTileOwner(tile, _current_player)) return;
DiagDirection dir;
TileIndex t;

View File

@ -173,11 +173,6 @@ bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, bool *ed
return true;
}
static bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, bool *edge_road, RoadType rt)
{
return CheckAllowRemoveRoad(tile, remove, GetRoadOwner(tile, rt), edge_road, rt);
}
/** Delete a piece of road.
* @param tile tile where to remove road from
@ -195,10 +190,14 @@ static CommandCost RemoveRoad(TileIndex tile, uint32 flags, RoadBits pieces, Roa
* false if it was a center piece. Affects town ratings drop */
bool edge_road;
RoadTypes rts = GetRoadTypes(tile);
/* The tile doesn't have the given road type */
if (!HasBit(rts, rt)) return CMD_ERROR;
Town *t = NULL;
switch (GetTileType(tile)) {
case MP_ROAD:
if (_game_mode != GM_EDITOR && GetRoadOwner(tile, rt) == OWNER_TOWN) t = GetTownByTile(tile);
if (_game_mode != GM_EDITOR && IsRoadOwner(tile, rt, OWNER_TOWN)) t = GetTownByTile(tile);
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
break;
@ -216,11 +215,7 @@ static CommandCost RemoveRoad(TileIndex tile, uint32 flags, RoadBits pieces, Roa
return CMD_ERROR;
}
RoadTypes rts = GetRoadTypes(tile);
/* The tile doesn't have the given road type */
if (!HasBit(rts, rt)) return CMD_ERROR;
if (!CheckAllowRemoveRoad(tile, pieces, &edge_road, rt)) return CMD_ERROR;
if (!CheckAllowRemoveRoad(tile, pieces, GetRoadOwner(tile, rt), &edge_road, rt)) return CMD_ERROR;
/* check if you're allowed to remove the street owned by a town
* removal allowance depends on difficulty setting */
@ -501,7 +496,7 @@ CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
}
if ((existing & pieces) == pieces) {
/* We only want to set the (dis)allowed road directions */
if (toggle_drd != DRD_NONE && rt != ROADTYPE_TRAM && GetRoadOwner(tile, ROADTYPE_ROAD) == _current_player) {
if (toggle_drd != DRD_NONE && rt != ROADTYPE_TRAM && IsRoadOwner(tile, ROADTYPE_ROAD, _current_player)) {
if (crossing) return_cmd_error(STR_ERR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
@ -894,7 +889,7 @@ static CommandCost ClearTile_Road(TileIndex tile, byte flags)
/* Clear the road if only one piece is on the tile OR the AI tries
* to clear town road OR we are not using the DC_AUTO flag */
if ((CountBits(b) == 1 && GetRoadBits(tile, ROADTYPE_TRAM) == ROAD_NONE) ||
((flags & DC_AI_BUILDING) && IsTileOwner(tile, OWNER_TOWN)) ||
((flags & DC_AI_BUILDING) && GetOtherRoadBits(tile, ROADTYPE_ROAD) == ROAD_NONE && IsRoadOwner(tile, ROADTYPE_ROAD, OWNER_TOWN)) ||
!(flags & DC_AUTO)
) {
RoadTypes rts = GetRoadTypes(tile);
@ -1549,9 +1544,7 @@ static void ChangeTileOwner_Road(TileIndex tile, PlayerID old_player, PlayerID n
}
for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
/* ROADTYPE_ROAD denotes the tile owner, so update it too */
if (rt != ROADTYPE_ROAD && !HasTileRoadType(tile, rt)) continue;
/* Update all roadtypes, no matter if they are present */
if (GetRoadOwner(tile, rt) == old_player) {
SetRoadOwner(tile, rt, new_player == PLAYER_SPECTATOR ? OWNER_NONE : new_player);
}

View File

@ -187,6 +187,12 @@ static inline void SetRoadOwner(TileIndex t, RoadType rt, Owner o)
}
}
static inline bool IsRoadOwner(TileIndex t, RoadType rt, Owner o)
{
assert(HasTileRoadType(t, rt));
return (GetRoadOwner(t, rt) == o);
}
/** Which directions are disallowed ? */
enum DisallowedRoadDirections {
DRD_NONE, ///< None of the directions are disallowed

View File

@ -490,6 +490,10 @@ static inline uint32 GetSmallMapOwnerPixels(TileIndex tile)
case MP_INDUSTRY: o = OWNER_END; break;
case MP_HOUSE: o = OWNER_TOWN; break;
default: o = GetTileOwner(tile); break;
/* FIXME: For MP_ROAD there are multiple owners.
* GetTileOwner returns the rail owner (level crossing) resp. the owner of ROADTYPE_ROAD (normal road),
* even if there are no ROADTYPE_ROAD bits on the tile.
*/
}
return _owner_colors[o];

View File

@ -1300,7 +1300,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
bool type = HasBit(p2, 0);
bool is_drive_through = HasBit(p2, 1);
bool build_over_road = is_drive_through && IsNormalRoadTile(tile);
bool town_owned_road = build_over_road && IsTileOwner(tile, OWNER_TOWN);
bool town_owned_road = false;
RoadTypes rts = (RoadTypes)GB(p2, 2, 3);
if (!AreValidRoadTypes(rts) || !HasRoadTypesAvail(_current_player, rts)) return CMD_ERROR;
@ -1319,14 +1319,17 @@ CommandCost CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
/* Not allowed to build over this road */
if (build_over_road) {
if (IsTileOwner(tile, OWNER_TOWN) && !_patches.road_stop_on_town_road) return_cmd_error(STR_DRIVE_THROUGH_ERROR_ON_TOWN_ROAD);
RoadTypes cur_rts = GetRoadTypes(tile);
/* there is a road, check if we can build road+tram stop over it */
if (HasBit(cur_rts, ROADTYPE_ROAD)) {
Owner road_owner = GetRoadOwner(tile, ROADTYPE_ROAD);
if (road_owner != OWNER_TOWN && road_owner != OWNER_NONE && !CheckOwnership(road_owner)) return CMD_ERROR;
if (road_owner == OWNER_TOWN) {
town_owned_road = true;
if (!_patches.road_stop_on_town_road) return_cmd_error(STR_DRIVE_THROUGH_ERROR_ON_TOWN_ROAD);
} else {
if (road_owner != OWNER_NONE && !CheckOwnership(road_owner)) return CMD_ERROR;
}
}
/* there is a tram, check if we can build road+tram stop over it */

View File

@ -1212,14 +1212,14 @@ static int GrowTownAtRoad(Town *t, TileIndex tile)
do target_dir = RandomDiagDir(); while (!(cur_rb & DiagDirToRoadBits(target_dir)));
tile = TileAddByDiagDir(tile, target_dir);
if (IsTileType(tile, MP_ROAD)) {
if (IsTileType(tile, MP_ROAD) && !IsRoadDepot(tile) && HasTileRoadType(tile, ROADTYPE_ROAD)) {
/* Don't allow building over roads of other cities */
if (IsTileOwner(tile, OWNER_TOWN) && GetTownByTile(tile) != t) {
if (IsRoadOwner(tile, ROADTYPE_ROAD, OWNER_TOWN) && GetTownByTile(tile) != t) {
_grow_town_result = GROWTH_SUCCEED;
} else if (IsTileOwner(tile, OWNER_NONE) && _game_mode == GM_EDITOR) {
} else if (IsRoadOwner(tile, ROADTYPE_ROAD, OWNER_NONE) && _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) */
SetTileOwner(tile, OWNER_TOWN);
SetRoadOwner(tile, ROADTYPE_ROAD, OWNER_TOWN);
SetTownIndex(tile, t->index);
}
}
@ -2438,8 +2438,8 @@ Town *CalcClosestTownFromTile(TileIndex tile, uint threshold)
Town *ClosestTownFromTile(TileIndex tile, uint threshold)
{
if (IsTileType(tile, MP_HOUSE) || (
IsTileType(tile, MP_ROAD) &&
GetRoadOwner(tile, ROADTYPE_ROAD) == OWNER_TOWN
IsTileType(tile, MP_ROAD) && HasTileRoadType(tile, ROADTYPE_ROAD) &&
IsRoadOwner(tile, ROADTYPE_ROAD, OWNER_TOWN)
)) {
return GetTownByTile(tile);
} else {