(svn r16925) -Fix (r16909): guard commands more against using waypoints as stations and/or accidentally reusing waypoints for stations or vice versa.

This commit is contained in:
rubidium 2009-07-23 12:02:09 +00:00
parent fefc880971
commit 16ad8df175
2 changed files with 8 additions and 8 deletions

View File

@ -81,7 +81,7 @@ static Station *GetStationAround(TileIndex tile, int w, int h, StationID closest
StationID t = GetStationIndex(tile_cur); StationID t = GetStationIndex(tile_cur);
if (closest_station == INVALID_STATION) { if (closest_station == INVALID_STATION) {
closest_station = t; if (Station::IsValidID(closest_station)) closest_station = t;
} else if (closest_station != t) { } else if (closest_station != t) {
_error_message = STR_ERROR_ADJOINS_MORE_THAN_ONE_EXISTING; _error_message = STR_ERROR_ADJOINS_MORE_THAN_ONE_EXISTING;
return CHECK_STATIONS_ERR; return CHECK_STATIONS_ERR;
@ -898,8 +898,8 @@ CommandCost CmdBuildRailroadStation(TileIndex tile_org, DoCommandFlag flags, uin
} else { } else {
/* Extend the current station, and don't check whether it will /* Extend the current station, and don't check whether it will
* be near any other stations. */ * be near any other stations. */
st = Station::Get(est); st = Station::GetIfValid(est);
check_surrounding = false; check_surrounding = (st == NULL);
} }
} else { } else {
/* There's no station here. Don't check the tiles surrounding this /* There's no station here. Don't check the tiles surrounding this
@ -915,7 +915,7 @@ CommandCost CmdBuildRailroadStation(TileIndex tile_org, DoCommandFlag flags, uin
} }
/* Distant join */ /* Distant join */
if (st == NULL && distant_join) st = Station::Get(station_to_join); if (st == NULL && distant_join) st = Station::GetIfValid(station_to_join);
/* See if there is a deleted station close to us. */ /* See if there is a deleted station close to us. */
if (st == NULL && reuse) st = GetClosestDeletedStation(tile_org); if (st == NULL && reuse) st = GetClosestDeletedStation(tile_org);
@ -1435,7 +1435,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
} }
/* Distant join */ /* Distant join */
if (st == NULL && distant_join) st = Station::Get(station_to_join); if (st == NULL && distant_join) st = Station::GetIfValid(station_to_join);
/* Find a deleted station close to us */ /* Find a deleted station close to us */
if (st == NULL && reuse) st = GetClosestDeletedStation(tile); if (st == NULL && reuse) st = GetClosestDeletedStation(tile);
@ -1795,7 +1795,7 @@ CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
} }
/* Distant join */ /* Distant join */
if (st == NULL && distant_join) st = Station::Get(station_to_join); if (st == NULL && distant_join) st = Station::GetIfValid(station_to_join);
/* Find a deleted station close to us */ /* Find a deleted station close to us */
if (st == NULL && reuse) st = GetClosestDeletedStation(tile); if (st == NULL && reuse) st = GetClosestDeletedStation(tile);
@ -2031,7 +2031,7 @@ CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
} }
/* Distant join */ /* Distant join */
if (st == NULL && distant_join) st = Station::Get(station_to_join); if (st == NULL && distant_join) st = Station::GetIfValid(station_to_join);
/* Find a deleted station close to us */ /* Find a deleted station close to us */
if (st == NULL && reuse) st = GetClosestDeletedStation(tile); if (st == NULL && reuse) st = GetClosestDeletedStation(tile);

View File

@ -60,7 +60,7 @@ void MakeDefaultWaypointName(Waypoint *wp)
WaypointID cid = 0; // current index, goes to Waypoint::GetPoolSize()-1, then wraps to 0 WaypointID cid = 0; // current index, goes to Waypoint::GetPoolSize()-1, then wraps to 0
do { do {
Waypoint *lwp = Waypoint::Get(cid); Waypoint *lwp = Waypoint::GetIfValid(cid);
/* check only valid waypoints... */ /* check only valid waypoints... */
if (lwp != NULL && wp != lwp) { if (lwp != NULL && wp != lwp) {