1
0
Fork 0

(svn r14383) -Fix [FS#2316](r14343): handle invalid 'v->u.air.targetairport' in the NewGRF code, too

release/0.7
smatz 2008-09-22 14:34:38 +00:00
parent 7ef5406946
commit abbc9cd9cb
2 changed files with 23 additions and 20 deletions

View File

@ -973,10 +973,8 @@ static bool AircraftController(Vehicle *v)
{ {
int count; int count;
StationID target = v->u.air.targetairport;
/* NULL if station is invalid */ /* 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 */ /* 0 if there is no station */
TileIndex tile = 0; TileIndex tile = 0;
if (st != NULL) { if (st != NULL) {

View File

@ -27,6 +27,7 @@
#include "rail_map.h" #include "rail_map.h"
#include "rail.h" #include "rail.h"
#include "settings_type.h" #include "settings_type.h"
#include "aircraft.h"
#include <map> #include <map>
@ -190,8 +191,8 @@ enum {
*/ */
static byte MapAircraftMovementState(const Vehicle *v) static byte MapAircraftMovementState(const Vehicle *v)
{ {
const Station *st = GetStation(v->u.air.targetairport); const Station *st = GetTargetAirportIfValid(v);
if (st->airport_tile == 0) return AMS_TTDP_FLIGHT_TO_TOWER; if (st == NULL) return AMS_TTDP_FLIGHT_TO_TOWER;
const AirportFTAClass *afc = st->Airport(); const AirportFTAClass *afc = st->Airport();
uint16 amdflag = afc->MovingData(v->u.air.pos)->flag; uint16 amdflag = afc->MovingData(v->u.air.pos)->flag;
@ -550,9 +551,12 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
{ {
const Vehicle *w = v->Next(); const Vehicle *w = v->Next();
uint16 altitude = v->z_pos - w->z_pos; // Aircraft height - shadow height uint16 altitude = v->z_pos - w->z_pos; // Aircraft height - shadow height
byte airporttype; byte airporttype = ATP_TTDP_LARGE;
switch (GetStation(v->u.air.targetairport)->airport_type) { const Station *st = GetTargetAirportIfValid(v);
if (st != NULL) {
switch (st->airport_type) {
/* Note, Helidepot and Helistation are treated as small airports /* Note, Helidepot and Helistation are treated as small airports
* as they are at ground level. */ * as they are at ground level. */
case AT_HELIDEPOT: case AT_HELIDEPOT:
@ -567,6 +571,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
case AT_OILRIG: airporttype = ATP_TTDP_OILRIG; break; case AT_OILRIG: airporttype = ATP_TTDP_OILRIG; break;
default: airporttype = ATP_TTDP_LARGE; break; default: airporttype = ATP_TTDP_LARGE; break;
} }
}
return (altitude << 8) | airporttype; return (altitude << 8) | airporttype;
} }