diff options
author | Darkvater <darkvater@openttd.org> | 2006-04-15 20:07:42 +0000 |
---|---|---|
committer | Darkvater <darkvater@openttd.org> | 2006-04-15 20:07:42 +0000 |
commit | d63fad7a7b7e0ff6bc6c32f119042a0317961255 (patch) | |
tree | e8d20cb7ee880010ebaa9d3fe99190d489a7abb4 | |
parent | f69fcf400e242d119498c0a4b99d7ec6d69d07b0 (diff) | |
download | openttd-d63fad7a7b7e0ff6bc6c32f119042a0317961255.tar.xz |
(svn r4435) - Fix: an assertion triggered when trying to remove a bridge with the remove-tool (r4348 surfaced this). In CmdRemoveRoad tiletype was not checked for ownership. Intorudce IsLevelCrossingTile() which checks if a tile is a crossing without knowing the type. Suggested by peter1138 and Tron.
-rw-r--r-- | road_cmd.c | 9 | ||||
-rw-r--r-- | road_map.h | 4 | ||||
-rw-r--r-- | roadveh_cmd.c | 2 | ||||
-rw-r--r-- | train_cmd.c | 7 |
4 files changed, 11 insertions, 11 deletions
diff --git a/road_cmd.c b/road_cmd.c index 154968421..4948bd7bc 100644 --- a/road_cmd.c +++ b/road_cmd.c @@ -47,11 +47,8 @@ static bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, bool* edge_roa // Only do the special processing for actual players. if (_current_player >= MAX_PLAYERS) return true; - if (IsTileType(tile, MP_STREET) && IsLevelCrossing(tile)) { - owner = GetCrossingRoadOwner(tile); - } else { - owner = GetTileOwner(tile); - } + owner = IsLevelCrossingTile(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile); + // Only do the special processing if the road is owned // by a town if (owner != OWNER_TOWN) { @@ -112,7 +109,7 @@ int32 CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) if (!IsTileType(tile, MP_STREET) && !IsTileType(tile, MP_TUNNELBRIDGE)) return CMD_ERROR; - owner = IsLevelCrossing(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile); + owner = IsLevelCrossingTile(tile) ? GetCrossingRoadOwner(tile) : 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) diff --git a/road_map.h b/road_map.h index e6b692620..f623b227e 100644 --- a/road_map.h +++ b/road_map.h @@ -26,6 +26,10 @@ static inline bool IsLevelCrossing(TileIndex t) return GetRoadType(t) == ROAD_CROSSING; } +static inline bool IsLevelCrossingTile(TileIndex t) +{ + return IsTileType(t, MP_STREET) && IsLevelCrossing(t); +} static inline RoadBits GetRoadBits(TileIndex t) { diff --git a/roadveh_cmd.c b/roadveh_cmd.c index 4c91e4ab9..574d4afb5 100644 --- a/roadveh_cmd.c +++ b/roadveh_cmd.c @@ -568,7 +568,7 @@ static void RoadVehCheckTrainCrash(Vehicle *v) tile = v->tile; - if (!IsTileType(tile, MP_STREET) || !IsLevelCrossing(tile)) return; + if (!IsLevelCrossingTile(tile)) return; if (VehicleFromPos(tile, v, EnumCheckRoadVehCrashTrain) != NULL) RoadVehCrash(v); diff --git a/train_cmd.c b/train_cmd.c index 05cd05aa4..c85fe7ee0 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -92,7 +92,7 @@ void TrainPowerChanged(Vehicle* v) if (IsBridgeTile(u->tile) && IsBridgeMiddle(u->tile) && DiagDirToAxis(DirToDiagDir(u->direction)) == GetBridgeAxis(u->tile)) { if (!HasPowerOnRail(u->u.rail.railtype, GetRailTypeOnBridge(u->tile))) engine_has_power = false; if (!HasPowerOnRail(v->u.rail.railtype, GetRailTypeOnBridge(u->tile))) wagon_has_power = false; - } else if (IsTileType(u->tile, MP_STREET) && IsLevelCrossing(u->tile)) { + } else if (IsLevelCrossingTile(u->tile)) { if (!HasPowerOnRail(u->u.rail.railtype, GetRailTypeCrossing(u->tile))) engine_has_power = false; if (!HasPowerOnRail(v->u.rail.railtype, GetRailTypeCrossing(u->tile))) wagon_has_power = false; } else { @@ -1529,8 +1529,7 @@ static void *TestTrainOnCrossing(Vehicle *v, void *data) static void DisableTrainCrossing(TileIndex tile) { - if (IsTileType(tile, MP_STREET) && - IsLevelCrossing(tile) && + if (IsLevelCrossingTile(tile) && VehicleFromPos(tile, &tile, TestTrainOnCrossing) == NULL && // empty? IsCrossingBarred(tile)) { UnbarCrossing(tile); @@ -3235,7 +3234,7 @@ static bool TrainCheckIfLineEnds(Vehicle *v) } if ((ts &= (ts >> 16)) == 0) { // make a rail/road crossing red - if (IsTileType(tile, MP_STREET) && IsLevelCrossing(tile)) { + if (IsLevelCrossingTile(tile)) { if (!IsCrossingBarred(tile)) { BarCrossing(tile); SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v); |