Skip to content

Commit

Permalink
Reworked turns and moves.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanwatsonforster committed Sep 25, 2023
1 parent 7ccf6cd commit 9778530
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 31 deletions.
5 changes: 2 additions & 3 deletions airpower/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from airpower.draw import *
from airpower.prolog import startprolog, endprolog
from airpower.turn import startturn, endturn
from airpower.aircraft import Aircraft
from airpower.azimuth import setnorth
from airpower.map import setmap, drawmap
54 changes: 26 additions & 28 deletions airpower/aircraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import airpower.hex as aphex
import airpower.hexcode as aphexcode
import airpower.map as apmap
import airpower.turn as apturn

import math

Expand All @@ -17,15 +18,14 @@ def __init__(self, name, hexcode, azimuth, altitude, speed):
apaltitude.checkisvalidaltitude(altitude)
aphex.checkisvalidfacing(x, y, facing)

self._turn = 0
self._name = name

self._x = x
self._y = y
self._facing = facing
self._altitude = altitude
self._altitudecarry = 0
self._speed = speed
self._flighttype = "LV"
self._fpcarry = 0
self._apcarry = 0

Expand All @@ -41,7 +41,6 @@ def __str__(self):
s = ""
for x in [
["name" , self._name],
["turn" , self._turn],
["sheet" , apmap.tosheet(self._x, self._y) if not self._leftmap else "-- "],
["hexcode" , aphexcode.fromxy(self._x, self._y) if not self._leftmap else "----"],
["facing" , apazimuth.fromfacing(self._facing)],
Expand Down Expand Up @@ -93,13 +92,10 @@ def _formatposition(self):
return "%2s %-9s %-3s %2d" % (sheet, hexcode, azimuth, altitude)

def _formatifp(self):
if self._turn == 0:
return ""
else:
return "FP %d" % (self._hfp + self._vfp)
return "FP %d" % (self._hfp + self._vfp)

def _report(self, s):
print("%s: turn %-2d : %s" % (self._name, self._turn, s))
print("%s: turn %-2d : %s" % (self._name, apturn.turn(), s))

def _reportbreak(self):
print()
Expand Down Expand Up @@ -374,6 +370,7 @@ def _restore(self, i):
self._altitude, \
self._altitudecarry, \
self._speed, \
self._flighttype, \
self._fpcarry, \
self._apcarry, \
self._destroyed, \
Expand All @@ -390,46 +387,47 @@ def _save(self, i):
self._altitude, \
self._altitudecarry, \
self._speed, \
self._flighttype, \
self._fpcarry, \
self._apcarry, \
self._destroyed, \
self._leftmap, \
)

def _maxprevturn(self):
return len(self._saved) - 1

def startturn(self, turn, powerap, actions):
def startmove(self, flighttype, powerap, actions):

if turn > self._maxprevturn() + 1:
raise ValueError("turn %d is out of sequence." % turn)
if flighttype not in ["LV", "SC", "ZC", "VC", "SD", "UD", "VD"]:
raise ValueError("invalid flight type %s." % flighttype)

self._restore(turn - 1)
self._restore(apturn.turn() - 1)

self._turn = turn
self._lastflighttype = self._flighttype
self._flighttype = flighttype
self._fp = self._speed + self._fpcarry
self._hfp = 0
self._vfp = 0
self._spbrfp = 0
self._fp = self._speed + self._fpcarry
self._fpcarry = 0
self._altitudeband = apaltitude.altitudeband(self._altitude)
self._turns = 0
self._turnrate = None
self._maxturnrate = None
self._powerap = powerap
self._spbrap = 0
self._sustainedturnap = 0
self._turnrate = None
self._maxturnrate = None

self._report("--- start of turn --")
self._report("--- start of move --")

if self._destroyed:
self._endturn()
self._endmove()
return

if self._leftmap:
self._endturn()
self._endmove()
return

self._report("flight type is %s." % self._flighttype)

self._report("carrying %.1f FPs, %.1f APs, and %s altitude levels." % (
self._fpcarry, self._apcarry, apaltitude.formataltitudecarry(self._altitudecarry)
))
Expand All @@ -448,9 +446,9 @@ def startturn(self, turn, powerap, actions):
self._report("---")
self._reportactionsandposition("")

self.continueturn(actions)
self.continuemove(actions)

def continueturn(self, actions):
def continuemove(self, actions):

if self._destroyed or self._leftmap:
return
Expand All @@ -467,13 +465,13 @@ def continueturn(self, actions):

self._drawaircraft("end")
self._report("---")
self._endturn()
self._endmove()

else:

self._drawaircraft("next")

def _endturn(self):
def _endmove(self):

if self._destroyed:

Expand Down Expand Up @@ -535,7 +533,7 @@ def _endturn(self):
self._fpcarry, self._apcarry, apaltitude.formataltitudecarry(self._altitudecarry)
))

self._save(self._turn)
self._save(apturn.turn())

self._report("--- end of turn -- ")
self._report("--- end of move -- ")
self._reportbreak()
15 changes: 15 additions & 0 deletions airpower/prolog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import airpower.map as apmap
import airpower.azimuth as apazimuth
import airpower.turn as apturn

def startprolog(sheets, compassrose, north="up"):
print("--- start prolog ---")
apazimuth.setnorth(north)
apmap.setmap(sheets, compassrose)
apmap.drawmap()
apturn.restart()
print()

def endprolog():
print("--- end prolog ---")
print()
36 changes: 36 additions & 0 deletions airpower/turn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import airpower.map as apmap

_turn = None
_maxturn = 0

def restart():
global _turn
_turn = 1

def startturn(turn):
global _turn
global _maxturn
if not isinstance(turn, int) or turn < 1:
raise ValueError("invalid turn %d." % turn)
if turn > _maxturn + 1:
raise ValueError("attempt to start turn %d out of sequence." % turn)
_turn = turn
_maxturn = max(_maxturn, _turn)
print("--- start of turn %d ---" % _turn)
print("")
apmap.drawmap()

def endturn():
global _turn
print("--- end of turn %d ---" % _turn)
print("")
_turn = None

def turn():
return _turn

def restart():
global _turn
global _maxturn
_turn = None
_maxturn = 0

0 comments on commit 9778530

Please sign in to comment.