Skip to content

Commit

Permalink
Fix speed calculation.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanwatsonforster committed Sep 24, 2023
1 parent 8d48376 commit 85ee3fa
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions airpower/aircraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ def __init__(self, name, hexcode, azimuth, altitude, speed):

self._drawaircraft("end")

self._reportstartofturn()
self._reportendofturn()

def __str__(self):
return "[name: %s]" % self._name

Expand All @@ -53,7 +50,7 @@ def _drawflightpath(self, lastx, lasty):
def _drawaircraft(self, when):
apdraw.drawaircraft(self._x, self._y, self._facing, self._name, self._altitude, when)

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

# Reporting

Expand Down Expand Up @@ -101,32 +98,34 @@ def _reportstartofturn(self):
self._report("aircraft has left the map.")
return

if self._turn == 0:

self._report("speed is %.1f." % (self._speed))

else:

self._report("speed is %.1f and %.1f FPs available." % (self._speed, self._nfp))
self._report("--- ")
self._report("speed is %.1f." % (self._speed, self._m1()))
self._report("%.1f FPs available." % self._nfp)
self._report("--- ")

self._reportactionsandposition("")

def _reportendofturn(self):

if self._turn > 0 and not self._destroyed and not self._leftmap:
if not self._destroyed and not self._leftmap:

self._report("--- ")

self._report("%d HFPs, %d VFPs, %.1f SFPs, and %+.1f APs." % (self._hfp, self._vfp, self._sfp, self._ap))

initialspeed = self._speed
if self._ap <= 0:
aprate = 2.0
aprate = -2.0
elif initialspeed >= self._m1():
aprate = +3.0
else:
aprate = +2.0
if self._ap >= 0:
self._speed += 0.5 * (self._ap // aprate)
self._apcarry = self._ap % aprate
else:
aprate = 2.0
self._speed += self._ap // aprate
self._apcarry = self._ap % aprate
self._speed -= 0.5 * (self._ap // aprate)
self._apcarry = self._ap % aprate

if self._speed != initialspeed:
self._report("speed changed from %.1f to %.1f." % (initialspeed, self._speed))
else:
Expand Down Expand Up @@ -331,13 +330,13 @@ def start(self, turn, ap, actions):

self._restore(turn - 1)

self._turn = turn
self._hfp = 0
self._vfp = 0
self._sfp = 0
self._nfp = self._speed + self._fpcarry
self._turn = turn
self._hfp = 0
self._vfp = 0
self._sfp = 0
self._nfp = self._speed + self._fpcarry
self._altitudeband = apaltitude.altitudeband(self._altitude)
self._ap = ap + self._apcarry
self._ap = ap + self._apcarry

self._reportstartofturn()

Expand Down

0 comments on commit 85ee3fa

Please sign in to comment.