Skip to content

Commit

Permalink
Report altitude band changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanwatsonforster committed Sep 26, 2023
1 parent accd9e6 commit c57fbad
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions airpower/aircraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _formatposition(self):
hexcode = "----"
azimuth = apazimuth.fromfacing(self._facing)
altitude = self._altitude
return "%2s %-9s %-3s %2d" % (sheet, hexcode, azimuth, altitude)
return "%2s %-9s %-3s %2d %2s" % (sheet, hexcode, azimuth, altitude, apaltitude.altitudeband(altitude))

def _log(self, s):
aplog.log("%s: turn %-2d : %s" % (self._name, apturn.turn(), s))
Expand Down Expand Up @@ -368,6 +368,8 @@ def _doaction(self, action):

elementdispatchlist = self._getelementdispatchlist()

initialaltitudeband = apaltitude.altitudeband(self._altitude)

# Movement elements.
a = action
while a != "":
Expand All @@ -386,6 +388,10 @@ def _doaction(self, action):
self._logposition("FP %d" % (self._hfp + self._vfp), action)
self._drawflightpath(lastx, lasty)

altitudeband = apaltitude.altitudeband(self._altitude)
if initialaltitudeband != altitudeband:
self._logevent("altitude band changed from %s to %s." % (initialaltitudeband, altitudeband))

self.checkforterraincollision()
self.checkforleavingmap()
if self._destroyed or self._leftmap:
Expand All @@ -406,22 +412,32 @@ def _doaction(self, action):

def _dostalledflight(self, actions):

initialaltitudeband = apaltitude.altitudeband(self._altitude)

altitudechange = math.ceil(self._speed + self._turnsstalled)

initialaltitude = self._altitude
self._altitude, self._altitudecarry = apaltitude.adjustaltitude(self._altitude, self._altitudecarry, -altitudechange)
altitudechange = initialaltitude - self._altitude

self.checkforterraincollision()


if self._turnsstalled == 0:
self._altitudeap = 0.5 * altitudechange
else:
self._altitudeap = 1.0 * altitudechange

self._logposition("end", "")

altitudeband = apaltitude.altitudeband(self._altitude)
if initialaltitudeband != altitudeband:
self._logevent("altitude band changed from %s to %s." % (initialaltitudeband, altitudeband))

self.checkforterraincollision()

if actions == "J1/2":
self._J("1/2")
elif actions == "JCL":
self._J("CL")


##############################################################################

Expand Down Expand Up @@ -643,7 +659,6 @@ def startmove(self, flighttype, power, actions):
self._log("---")
self._logposition("start", "")
self._dostalledflight(actions)
self._logposition("end", "")
self._log("---")
self._endmove()

Expand Down

0 comments on commit c57fbad

Please sign in to comment.