Skip to content

Commit

Permalink
Limits on unloaded FHPs.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanwatsonforster committed Oct 1, 2023
1 parent 70587c1 commit f05bd7d
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions airpower/aircraft/_normalflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def checkaltitudechange():
elif flighttype == "VD":

# See rule 8.2.3.
if altitudechange != 2 or altitudechange != 3:
if altitudechange != 2 and altitudechange != 3:
raise RuntimeError("attempt to dive %d levels per VFP while the flight type is VD." % altitudechange)

elif flighttype == "LVL":
Expand Down Expand Up @@ -411,6 +411,12 @@ def _doaction(self, action):

self._turnfp += 1

if self._flighttype == "UD":
if self._firstunloadedfp == None and actionvertical:
self._firstunloadedfp = self._hfp
if actionvertical:
self._lastunloadedfp = self._hfp

self._doelements(action, "turn or bank", False)

assert aphex.isvalidposition(self._x, self._y)
Expand Down Expand Up @@ -550,13 +556,16 @@ def determinefp():
self._vfp = 0
self._spbrfp = 0

self._firstunloadedfp = None
self._lastunloadedfp = None

def determinemininitialhfp():

# See rule 5.5.

flighttype = self._flighttype
lastflighttype = self._lastflighttype

if lastflighttype == "LVL" and (_isclimbing(flighttype) or _isdiving(flighttype)):
mininitialhfp = 1
elif (_isclimbing(lastflighttype) and _isdiving(flighttype)) or (_isdiving(lastflighttype) and _isclimbing(flighttype)):
Expand Down Expand Up @@ -626,17 +635,18 @@ def determinerequiredhfpvfpmix():
else:
minhfp = math.ceil(onethird(fp))

elif flighttype == "UL":
elif flighttype == "UD":

# See rules 8.2.2 and 8.2.3.
maxunloadedhfp = fp
if lastflighttype == "VD":
minunloadedfp = math.floor(self._speed / 2)
minunloadedhfp = math.floor(self._speed / 2)
else:
minunloadedfp = 0
minunloadedhfp = 0

assert minvfp == 0
assert (minvfp == 0 and maxvfp == fp) or (minhfp == 0 and maxhfp == fp)
assert minhfp == 0 or maxhfp == fp
assert (minvfp == 0 and maxvfp == fp) or (minhfp == 0 and maxhfp == fp) or (minhfp == maxhfp)
assert minhfp == 0 or maxhfp == fp or (minhfp == maxhfp)

if maxvfp == 0:
self._log("- all FPs must be HFPs.")
Expand Down Expand Up @@ -699,7 +709,21 @@ def checkfp():
if self._vfp > self._maxvfp:
raise RuntimeError("too many VFPs.")

# TODO: check unloaded HFPs.
if self._flighttype == "UD":
# See rule 8.2.2.
unloadedhfp = self._lastaltitude - self._altitude
if self._firstunloadedfp == None:
n = 0
elif self._lastunloadedfp == None:
n = self._hfp - self._firstunloadedfp + 1
else:
n = self._lastunloadedfp - self._firstunloadedfp + 1
if n != unloadedhfp:
raise RuntimeError("unloaded HFPs must be continuous.")
if unloadedhfp < self._minunloadedhfp:
raise RuntimeError("too few unloaded HFPs.")
if unloadedhfp > self._maxunloadedhfp:
raise RuntimeError("too many unloaded HFPs.")

def checkfreedescent():

Expand Down

0 comments on commit f05bd7d

Please sign in to comment.