Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #6676: Prevent helicopters from stopping in midair during landing #6962

Merged
merged 1 commit into from
Nov 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/aircraft.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ enum AirVehicleFlags {
* landscape at a fixed altitude. This only has effect when there are more than 15 height levels. */
VAF_IN_MAX_HEIGHT_CORRECTION = 1, ///< The vehicle is currently lowering its altitude because it hit the upper bound.
VAF_IN_MIN_HEIGHT_CORRECTION = 2, ///< The vehicle is currently raising its altitude because it hit the lower bound.

VAF_HELI_DIRECT_DESCENT = 3, ///< The helicopter is descending directly at its destination (helipad or in front of hangar)
};

static const int ROTOR_Z_OFFSET = 5; ///< Z Offset between helicopter- and rotorsprite.
Expand Down
8 changes: 7 additions & 1 deletion src/aircraft_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,8 @@ static bool AircraftController(Aircraft *v)

/* Helicopter landing. */
if (amd.flag & AMED_HELI_LOWER) {
SetBit(v->flags, VAF_HELI_DIRECT_DESCENT);

if (st == NULL) {
/* FIXME - AircraftController -> if station no longer exists, do not land
* helicopter will circle until sign disappears, then go to next order
Expand All @@ -938,7 +940,10 @@ static bool AircraftController(Aircraft *v)
Vehicle *u = v->Next()->Next();

/* Increase speed of rotors. When speed is 80, we've landed. */
if (u->cur_speed >= 80) return true;
if (u->cur_speed >= 80) {
ClrBit(v->flags, VAF_HELI_DIRECT_DESCENT);
return true;
}
u->cur_speed += 4;
} else {
count = UpdateAircraftSpeed(v);
Expand Down Expand Up @@ -1603,6 +1608,7 @@ static void AircraftEventHandler_Flying(Aircraft *v, const AirportFTAClass *apc)
uint16 tsubspeed = v->subspeed;
if (!AirportHasBlock(v, current, apc)) {
v->state = landingtype; // LANDING / HELILANDING
if (v->state == HELILANDING) SetBit(v->flags, VAF_HELI_DIRECT_DESCENT);
/* it's a bit dirty, but I need to set position to next position, otherwise
* if there are multiple runways, plane won't know which one it took (because
* they all have heading LANDING). And also occupy that block! */
Expand Down
3 changes: 2 additions & 1 deletion src/vehicle_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,8 @@ CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
case VEH_AIRCRAFT: {
Aircraft *a = Aircraft::From(v);
/* cannot stop airplane when in flight, or when taking off / landing */
if (!(v->vehstatus & VS_CRASHED) && a->state >= STARTTAKEOFF && a->state < TERM7) return_cmd_error(STR_ERROR_AIRCRAFT_IS_IN_FLIGHT);
if (a->state >= STARTTAKEOFF && a->state < TERM7) return_cmd_error(STR_ERROR_AIRCRAFT_IS_IN_FLIGHT);
if (HasBit(a->flags, VAF_HELI_DIRECT_DESCENT)) return_cmd_error(STR_ERROR_AIRCRAFT_IS_IN_FLIGHT);
break;
}

Expand Down