Skip to content

Commit

Permalink
Rework messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanwatsonforster committed Sep 29, 2023
1 parent 26356bc commit c454a61
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 36 deletions.
35 changes: 11 additions & 24 deletions airpower/aircraft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -356,7 +354,6 @@ def _endmove(self):
"""

self._drawaircraft("end")
self._log("---")

if self._destroyed:

Expand All @@ -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())
Expand Down
4 changes: 3 additions & 1 deletion airpower/aircraft/_departedflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
self._facing = (self._facing + facingchange) % 360

self._log("---")
56 changes: 45 additions & 11 deletions airpower/aircraft/_normalflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
Expand All @@ -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):

"""
Expand Down
2 changes: 2 additions & 0 deletions airpower/aircraft/_stalledflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ def _dostalledflight(self, action):
self._dojettison("CL")
elif action != "":
raise RuntimeError("invalid action %r for stalled flight." % action)

self._log("---")

0 comments on commit c454a61

Please sign in to comment.