File diff r10570:e200b86ce378 → r10571:99cb9a95b4cf
src/aircraft_cmd.cpp
Show inline comments
 
@@ -73,27 +73,24 @@ void Aircraft::UpdateDeltaXY(Direction d
 
/** this maps the terminal to its corresponding state and block flag
 
 *  currently set for 10 terms, 4 helipads */
 
static const byte _airport_terminal_state[] = {2, 3, 4, 5, 6, 7, 19, 20, 0, 0, 8, 9, 21, 22};
 
static const byte _airport_terminal_flag[] =  {0, 1, 2, 3, 4, 5, 22, 23, 0, 0, 6, 7, 24, 25};
 

	
 
static bool AirportMove(Vehicle *v, const AirportFTAClass *apc);
 
static bool AirportSetBlocks(Vehicle *v, const AirportFTA *current_pos, const AirportFTAClass *apc);
 
static bool AirportHasBlock(Vehicle *v, const AirportFTA *current_pos, const AirportFTAClass *apc);
 
static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *apc);
 
static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *apc);
 
static void CrashAirplane(Vehicle *v);
 

	
 
void AircraftNextAirportPos_and_Order(Vehicle *v);
 
static byte GetAircraftFlyingAltitude(const Vehicle *v);
 

	
 
static const SpriteID _aircraft_sprite[] = {
 
	0x0EB5, 0x0EBD, 0x0EC5, 0x0ECD,
 
	0x0ED5, 0x0EDD, 0x0E9D, 0x0EA5,
 
	0x0EAD, 0x0EE5, 0x0F05, 0x0F0D,
 
	0x0F15, 0x0F1D, 0x0F25, 0x0F2D,
 
	0x0EED, 0x0EF5, 0x0EFD, 0x0F35,
 
	0x0E9D, 0x0EA5, 0x0EAD, 0x0EB5,
 
	0x0EBD, 0x0EC5
 
};
 

	
 
/** Helicopter rotor animation states */
 
enum HelicopterRotorStates {
 
@@ -718,25 +715,25 @@ static void HelicopterTickHandler(Vehicl
 
		img = GetRotorImage(v);
 
	} else {
 
		return;
 
	}
 

	
 
	u->cur_image = img;
 

	
 
	BeginVehicleMove(u);
 
	VehiclePositionChanged(u);
 
	EndVehicleMove(u);
 
}
 

	
 
static void SetAircraftPosition(Vehicle *v, int x, int y, int z)
 
void SetAircraftPosition(Vehicle *v, int x, int y, int z)
 
{
 
	v->x_pos = x;
 
	v->y_pos = y;
 
	v->z_pos = z;
 

	
 
	v->cur_image = v->GetImage(v->direction);
 
	if (v->subtype == AIR_HELICOPTER) v->Next()->Next()->cur_image = GetRotorImage(v);
 

	
 
	BeginVehicleMove(v);
 
	VehiclePositionChanged(v);
 
	EndVehicleMove(v);
 

	
 
@@ -874,25 +871,25 @@ static int UpdateAircraftSpeed(Vehicle *
 
	spd += v->progress;
 
	v->progress = (byte)spd;
 
	return spd >> 8;
 
}
 

	
 
/**
 
 * Gets the cruise altitude of an aircraft.
 
 * The cruise altitude is determined by the velocity of the vehicle
 
 * and the direction it is moving
 
 * @param v The vehicle. Should be an aircraft
 
 * @returns Altitude in pixel units
 
 */
 
static byte GetAircraftFlyingAltitude(const Vehicle *v)
 
byte GetAircraftFlyingAltitude(const Vehicle *v)
 
{
 
	/* Make sure Aircraft fly no lower so that they don't conduct
 
	 * CFITs (controlled flight into terrain)
 
	 */
 
	byte base_altitude = 150;
 

	
 
	/* Make sure eastbound and westbound planes do not "crash" into each
 
	 * other by providing them with vertical seperation
 
	 */
 
	switch (v->direction) {
 
		case DIR_N:
 
		case DIR_NE:
 
@@ -1424,25 +1421,25 @@ static void AircraftLandAirplane(Vehicle
 
/** set the right pos when heading to other airports after takeoff */
 
void AircraftNextAirportPos_and_Order(Vehicle *v)
 
{
 
	if (v->current_order.IsType(OT_GOTO_STATION) || v->current_order.IsType(OT_GOTO_DEPOT)) {
 
		v->u.air.targetairport = v->current_order.GetDestination();
 
	}
 

	
 
	const Station *st = GetTargetAirportIfValid(v);
 
	const AirportFTAClass *apc = st == NULL ? GetAirport(AT_DUMMY) : st->Airport();
 
	v->u.air.pos = v->u.air.previous_pos = AircraftGetEntryPoint(v, apc);
 
}
 

	
 
static void AircraftLeaveHangar(Vehicle *v)
 
void AircraftLeaveHangar(Vehicle *v)
 
{
 
	v->cur_speed = 0;
 
	v->subspeed = 0;
 
	v->progress = 0;
 
	v->direction = DIR_SE;
 
	v->vehstatus &= ~VS_HIDDEN;
 
	{
 
		Vehicle *u = v->Next();
 
		u->vehstatus &= ~VS_HIDDEN;
 

	
 
		/* Rotor blades */
 
		u = u->Next();
 
@@ -2087,60 +2084,24 @@ Station *GetTargetAirportIfValid(const V
 
{
 
	assert(v->type == VEH_AIRCRAFT);
 

	
 
	StationID sid = v->u.air.targetairport;
 

	
 
	if (!IsValidStationID(sid)) return NULL;
 

	
 
	Station *st = GetStation(sid);
 

	
 
	return st->airport_tile == INVALID_TILE ? NULL : st;
 
}
 

	
 
/** need to be called to load aircraft from old version */
 
void UpdateOldAircraft()
 
{
 
	/* set airport_flags to 0 for all airports just to be sure */
 
	Station *st;
 
	FOR_ALL_STATIONS(st) {
 
		st->airport_flags = 0; // reset airport
 
	}
 

	
 
	Vehicle *v_oldstyle;
 
	FOR_ALL_VEHICLES(v_oldstyle) {
 
	/* airplane has another vehicle with subtype 4 (shadow), helicopter also has 3 (rotor)
 
	 * skip those */
 
		if (v_oldstyle->type == VEH_AIRCRAFT && IsNormalAircraft(v_oldstyle)) {
 
			/* airplane in terminal stopped doesn't hurt anyone, so goto next */
 
			if (v_oldstyle->vehstatus & VS_STOPPED && v_oldstyle->u.air.state == 0) {
 
				v_oldstyle->u.air.state = HANGAR;
 
				continue;
 
			}
 

	
 
			AircraftLeaveHangar(v_oldstyle); // make airplane visible if it was in a depot for example
 
			v_oldstyle->vehstatus &= ~VS_STOPPED; // make airplane moving
 
			v_oldstyle->u.air.state = FLYING;
 
			AircraftNextAirportPos_and_Order(v_oldstyle); // move it to the entry point of the airport
 
			GetNewVehiclePosResult gp = GetNewVehiclePos(v_oldstyle);
 
			v_oldstyle->tile = 0; // aircraft in air is tile=0
 

	
 
			/* correct speed of helicopter-rotors */
 
			if (v_oldstyle->subtype == AIR_HELICOPTER) v_oldstyle->Next()->Next()->cur_speed = 32;
 

	
 
			/* set new position x,y,z */
 
			SetAircraftPosition(v_oldstyle, gp.x, gp.y, GetAircraftFlyingAltitude(v_oldstyle));
 
		}
 
	}
 
}
 

	
 
/**
 
 * Updates the status of the Aircraft heading or in the station
 
 * @param st Station been updated
 
 */
 
void UpdateAirplanesOnNewStation(const Station *st)
 
{
 
	/* only 1 station is updated per function call, so it is enough to get entry_point once */
 
	const AirportFTAClass *ap = st->Airport();
 

	
 
	Vehicle *v;
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_AIRCRAFT && IsNormalAircraft(v)) {