summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2008-05-24 19:36:20 +0000
committerfrosch <frosch@openttd.org>2008-05-24 19:36:20 +0000
commit6e7a7412cdb824dd53ca8470dcfbba1d07f891b8 (patch)
treec397ff33001e474f450c64ea28b740db9fd01e81
parentc34b458ace0695fd89116dc29de4e1bec5fca89b (diff)
downloadopenttd-6e7a7412cdb824dd53ca8470dcfbba1d07f891b8.tar.xz
(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.
-rw-r--r--src/ai/default/default.cpp4
-rw-r--r--src/road_cmd.cpp25
-rw-r--r--src/road_map.h6
-rw-r--r--src/smallmap_gui.cpp4
-rw-r--r--src/station_cmd.cpp11
-rw-r--r--src/town_cmd.cpp12
6 files changed, 34 insertions, 28 deletions
diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp
index fc874f322..2843d0dc7 100644
--- a/src/ai/default/default.cpp
+++ b/src/ai/default/default.cpp
@@ -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;
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index edcff7cf5..5b75b15c8 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -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);
}
diff --git a/src/road_map.h b/src/road_map.h
index 305a1ab25..756e3fcb7 100644
--- a/src/road_map.h
+++ b/src/road_map.h
@@ -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
diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp
index 2094397ed..b6ba2037a 100644
--- a/src/smallmap_gui.cpp
+++ b/src/smallmap_gui.cpp
@@ -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];
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 0fe4bebf2..302d36c19 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -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 */
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index e0033155f..f6e0eadca 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -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 {