From c454a61b4129dbde942220235a585b09f9ef35ce Mon Sep 17 00:00:00 2001 From: alanwatsonforster <68709385+alanwatsonforster@users.noreply.github.com> Date: Fri, 29 Sep 2023 01:56:54 -0600 Subject: [PATCH] Rework messages. --- airpower/aircraft/__init__.py | 35 ++++++----------- airpower/aircraft/_departedflight.py | 4 +- airpower/aircraft/_normalflight.py | 56 ++++++++++++++++++++++------ airpower/aircraft/_stalledflight.py | 2 + 4 files changed, 61 insertions(+), 36 deletions(-) diff --git a/airpower/aircraft/__init__.py b/airpower/aircraft/__init__.py index b4280790..427a81db 100644 --- a/airpower/aircraft/__init__.py +++ b/airpower/aircraft/__init__.py @@ -19,7 +19,7 @@ class aircraft: from ._draw import _drawaircraft, _drawflightpath from ._log import _log, _logposition, _logevent, _logbreak from ._normalflight import \ - _startnormalflight, _continuenormalflight, \ + _startnormalflight, _continuenormalflight, _endnormalflight, \ _doaction, _doelements, _getelementdispatchlist, \ _doattack, _doclimb, _dodive, _dohorizontal, _dojettison, _dokilled, \ _dobank, _dodeclareturn, _doturn, _dospeedbrakes @@ -296,13 +296,11 @@ def startmove(self, flighttype, power, actions, flamedoutfraction=0): self._powersetting, \ self._powerap, \ self._speedap = self._startmovespeed(power, flamedoutfraction) - - if self._turnfp > 0: - turncarry = "%d %s%s" % (self._turnfp, self._bank, self._turnrate) - else: - turncarry = "0" - self._log("carrying %+.2f APs, %s altitude levels, and %s turn FPs." % ( - self._apcarry, apaltitude.formataltitudecarry(self._altitudecarry), turncarry + + self._log("configuration is %s." % self._configuration) + self._log("altitude band is %s." % self._altitudeband) + self._log("carrying %+.2f APs and %s altitude levels." % ( + self._apcarry, apaltitude.formataltitudecarry(self._altitudecarry) )) if self._flighttype == "ST": @@ -356,7 +354,6 @@ def _endmove(self): """ self._drawaircraft("end") - self._log("---") if self._destroyed: @@ -367,31 +364,21 @@ def _endmove(self): self._log("aircraft has left the map.") else: - - if self._flighttype != "ST" and self._flighttype != "DP": - self._log("used %d HFPs and %d VFPs (and %.1f FPs to speedbrakes)." % (self._hfp, self._vfp, self._spbrfp)) + + self._endmovespeed() if self._lastconfiguration != self._configuration: self._log("configuration changed from %s to %s." % (self._lastconfiguration, self._configuration)) else: self._log("configuration is unchanged at %s." % self._configuration) - + if self._lastaltitudeband != self._altitudeband: self._log("altitude band changed from %s to %s." % (self._lastaltitudeband, self._altitudeband)) else: self._log("altitude band is unchanged at %s." % self._altitudeband) - - if self._maxturnrate != None: - self._log("maximum turn rate was %s." % self._maxturnrate) - - self._endmovespeed() - if self._turnfp > 0: - turncarry = "%d %s%s" % (self._turnfp, self._bank, self._turnrate) - else: - turncarry = "0" - self._log("carrying %.1f FPs, %+.2f APs, %s altitude levels, and %s turn FPs." % ( - self._fpcarry, self._apcarry, apaltitude.formataltitudecarry(self._altitudecarry), turncarry + self._log("carrying %+.2f APs and %s altitude levels." % ( + self._apcarry, apaltitude.formataltitudecarry(self._altitudecarry) )) self._save(apturn.turn()) diff --git a/airpower/aircraft/_departedflight.py b/airpower/aircraft/_departedflight.py index 7080c99a..f45acebe 100644 --- a/airpower/aircraft/_departedflight.py +++ b/airpower/aircraft/_departedflight.py @@ -63,4 +63,6 @@ def _dodepartedflight(self, action): else: if aphex.isedgeposition(self._x, self._y): self._x, self._y = aphex.centertoleft(self._x, self._y, self._facing) - self._facing = (self._facing + facingchange) % 360 \ No newline at end of file + self._facing = (self._facing + facingchange) % 360 + + self._log("---") diff --git a/airpower/aircraft/_normalflight.py b/airpower/aircraft/_normalflight.py index 9b534f6f..f9f6e308 100644 --- a/airpower/aircraft/_normalflight.py +++ b/airpower/aircraft/_normalflight.py @@ -406,12 +406,17 @@ def _continuenormalflight(self, actions): fp = self._hfp + self._vfp + self._spbrfp assert fp <= self._fp - if fp + 1 > self._fp or self._destroyed or self._leftmap: + if self._destroyed or self._leftmap: + + self._log("---") + self._endmove() + + elif fp + 1 > self._fp: # See rule 5.4. self._fpcarry = self._fp - fp - self._endmove() + self._endnormalflight() else: @@ -424,13 +429,14 @@ def _startnormalflight(self, actions): """ Start to carry out normal flight. """ - - # See rule 5.4. - - self._fp = self._speed + self._fpcarry - self._fpcarry = 0 - self._log("%.1f FPs (including %.1f carry)." % (self._fp, self._fpcarry)) + if self._turnfp > 0 and self._turnrate != None: + self._log("- is turning %s at %s rate with %d FPs carried." % (self._bank, self._turnrate, self._turnfp)) + elif self._bank == None: + self._log("- has wings level.") + else: + self._log("- is banked %s." % self._bank) + # See rule 5.5. flighttype = self._flighttype @@ -451,17 +457,45 @@ def _startnormalflight(self, actions): self._log("- last flight type was %s so the first %d FPs must be HFPs." % (lastflighttype, requiredhfp)) self._requiredhfp = requiredhfp - self._log("---") - self._logposition("start", "") - + # See rule 5.4. + + self._fp = self._speed + self._fpcarry + self._fpcarry = 0 + self._log("- has %.1f FPs (including %.1f carry)." % (self._fp, self._fpcarry)) + self._hfp = 0 self._vfp = 0 self._spbrfp = 0 + self._log("---") + self._logposition("start", "") + self._continuenormalflight(actions) ################################################################################ +def _endnormalflight(self): + + self._log("---") + + self._log("- used %d HFPs and %d VFPs, lost %.1f FPs to speedbrakes, and is carrying %.1f FPs." % ( + self._hfp, self._vfp, self._spbrfp, self._fpcarry + )) + + if self._maxturnrate != None: + self._log("- turned at %s rate." % self._maxturnrate) + + if self._turnfp > 0 and self._turnrate != None: + self._log("- finished turning %s at %s rate with %d FPs carried." % (self._bank, self._turnrate, self._turnfp)) + elif self._bank == None: + self._log("- finished with wings level.") + else: + self._log("- finished banked %s." % self._bank) + + self._endmove() + +################################################################################ + def _isdiving(flighttype): """ diff --git a/airpower/aircraft/_stalledflight.py b/airpower/aircraft/_stalledflight.py index 1caedade..a489c80c 100644 --- a/airpower/aircraft/_stalledflight.py +++ b/airpower/aircraft/_stalledflight.py @@ -47,3 +47,5 @@ def _dostalledflight(self, action): self._dojettison("CL") elif action != "": raise RuntimeError("invalid action %r for stalled flight." % action) + + self._log("---")