diff options
author | smatz <smatz@openttd.org> | 2008-09-22 14:34:38 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2008-09-22 14:34:38 +0000 |
commit | abbc9cd9cbdfbc2e0fb294f1664b59cf9fab5ae6 (patch) | |
tree | 164aa2e2e1b217e6e796a3327ee75999b2e01ed8 /src | |
parent | 7ef54069462d5aca6a995c84bcdb115fb5ad66bb (diff) | |
download | openttd-abbc9cd9cbdfbc2e0fb294f1664b59cf9fab5ae6.tar.xz |
(svn r14383) -Fix [FS#2316](r14343): handle invalid 'v->u.air.targetairport' in the NewGRF code, too
Diffstat (limited to 'src')
-rw-r--r-- | src/aircraft_cmd.cpp | 4 | ||||
-rw-r--r-- | src/newgrf_engine.cpp | 41 |
2 files changed, 24 insertions, 21 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 4e76992d6..ebabe544d 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -973,10 +973,8 @@ static bool AircraftController(Vehicle *v) { int count; - StationID target = v->u.air.targetairport; - /* NULL if station is invalid */ - const Station *st = IsValidStationID(target) ? GetStation(target) : NULL; + const Station *st = IsValidStationID(v->u.air.targetairport) ? GetStation(v->u.air.targetairport) : NULL; /* 0 if there is no station */ TileIndex tile = 0; if (st != NULL) { diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index 80c963ed7..c42f24674 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -27,6 +27,7 @@ #include "rail_map.h" #include "rail.h" #include "settings_type.h" +#include "aircraft.h" #include <map> @@ -190,8 +191,8 @@ enum { */ static byte MapAircraftMovementState(const Vehicle *v) { - const Station *st = GetStation(v->u.air.targetairport); - if (st->airport_tile == 0) return AMS_TTDP_FLIGHT_TO_TOWER; + const Station *st = GetTargetAirportIfValid(v); + if (st == NULL) return AMS_TTDP_FLIGHT_TO_TOWER; const AirportFTAClass *afc = st->Airport(); uint16 amdflag = afc->MovingData(v->u.air.pos)->flag; @@ -550,22 +551,26 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by { const Vehicle *w = v->Next(); uint16 altitude = v->z_pos - w->z_pos; // Aircraft height - shadow height - byte airporttype; - - switch (GetStation(v->u.air.targetairport)->airport_type) { - /* Note, Helidepot and Helistation are treated as small airports - * as they are at ground level. */ - case AT_HELIDEPOT: - case AT_HELISTATION: - case AT_COMMUTER: - case AT_SMALL: airporttype = ATP_TTDP_SMALL; break; - case AT_METROPOLITAN: - case AT_INTERNATIONAL: - case AT_INTERCON: - case AT_LARGE: airporttype = ATP_TTDP_LARGE; break; - case AT_HELIPORT: airporttype = ATP_TTDP_HELIPORT; break; - case AT_OILRIG: airporttype = ATP_TTDP_OILRIG; break; - default: airporttype = ATP_TTDP_LARGE; break; + byte airporttype = ATP_TTDP_LARGE; + + const Station *st = GetTargetAirportIfValid(v); + + if (st != NULL) { + switch (st->airport_type) { + /* Note, Helidepot and Helistation are treated as small airports + * as they are at ground level. */ + case AT_HELIDEPOT: + case AT_HELISTATION: + case AT_COMMUTER: + case AT_SMALL: airporttype = ATP_TTDP_SMALL; break; + case AT_METROPOLITAN: + case AT_INTERNATIONAL: + case AT_INTERCON: + case AT_LARGE: airporttype = ATP_TTDP_LARGE; break; + case AT_HELIPORT: airporttype = ATP_TTDP_HELIPORT; break; + case AT_OILRIG: airporttype = ATP_TTDP_OILRIG; break; + default: airporttype = ATP_TTDP_LARGE; break; + } } return (altitude << 8) | airporttype; |