-
Notifications
You must be signed in to change notification settings - Fork 1
Aircraft
Instances of this class are created by AircraftController, one instance representing one aircraft. Each instance is responsible for: handling user input passed to it by AircraftController, updating the list of waypoints assigned to it when it reaches a target waypoint or when a diversion waypoint is assigned to it, determining whether it is still active in the airspace, and updating its velocity and altitude when necessary (e.g. changing heading towards next waypoint).
Travelling between waypoints: act()
→ vectorToWaypoint()
vectorToWaypoint()
is called by act()
, and returns the vector from its current location to its target waypoint (always waypoints[0]
). This vector is then used to determine if the aircraft needs to be rotated.
Determining if has arrived at next waypoint: act()
The length vectorToWaypoint()
of is used to determine whether the aircraft has reached the waypoint. When an aircraft arrives at its destination waypoint, waypoints[0]
is removed and so waypoints[1]
becomes the new waypoints[0]
.
Diverting aircraft to another waypoint: insertWaypoint()
Simply inserts the desired waypoint passed to it to the front of waypoints[].
Taking manual control of an aircraft: act()
, turnRight()
, turnLeft()
.
This occurs whenever the user changes the direction of the aircraft and either turnLeft()
or turnRight()
is called. This sets the ignorePath
flag to true, which 10 causes act()
to skip over all parts of the function that concerns, mainly the logic which removes target waypoints from waypoints[]
and updates the heading of the aircraft towards the target waypoint. In order to indicate to the user which exit an aircraft that is no longer following a flight plan is to take, a line is drawn between the aircraft and its exit point.
Changing altitude and speed of an aircraft: increaseAltitude()
decreaseAlitude()
,
These functions can be called without affecting the aircraft’s journey (i.e. it will still follow its flight plan). Aircraft altitude can be changed to one of three states dictated by Config.ALTITUDES
. The rate of change in altitude is determined by the aircraft’s maxClimbRate
.
Changing speed of an aircraft: increaseSpeed
, decreaseSpeed()
.
Within bounds, multiplies the current speed by a value from 0.5 to 1.3 in increments of 0.1. When the aircraft is generated, the multiplier is set to 1 and the default speed read out as 800km/h.
Determining if self is active: isActive()
Returns a boolean isActive
, which is used by AircraftController.Update()
in order to remove aircraft that have left the airspace (ie when isActive()
returns false). The conditions for this returning false are either by the aircraft having an empty array waypoints[] or by going out of bounds.