diff --git a/airpower/aircraft/__init__.py b/airpower/aircraft/__init__.py index 0176be11..5e0dbed2 100644 --- a/airpower/aircraft/__init__.py +++ b/airpower/aircraft/__init__.py @@ -61,7 +61,7 @@ class aircraft: _startflightpath, _continueflightpath, _drawflightpath from ._log import \ - _log, _logposition, _logevent, _logbreak + _log, _logaction, _logevent, _logbreak ############################################################################# diff --git a/airpower/aircraft/_departedflight.py b/airpower/aircraft/_departedflight.py index 42e656ee..f089970f 100644 --- a/airpower/aircraft/_departedflight.py +++ b/airpower/aircraft/_departedflight.py @@ -23,7 +23,7 @@ def _dodepartedflight(self, action): """ self._log("---") - self._logposition("start", "") + self._logaction("start", "", self.position()) # See rule 6.4 "Abnormal FLight (Stalls and Departures)" and rule 7.7 # "Manuevering Departures". @@ -74,7 +74,7 @@ def _dodepartedflight(self, action): self._altitude, self._altitudecarry = apaltitude.adjustaltitude(self._altitude, self._altitudecarry, -altitudechange) self._altitudeband = apaltitude.altitudeband(self._altitude) - self._logposition("end", action) + self._logaction("end", action, self.position()) if initialaltitudeband != self._altitudeband: self._logevent("altitude band changed from %s to %s." % (initialaltitudeband, self._altitudeband)) self.checkforterraincollision() diff --git a/airpower/aircraft/_log.py b/airpower/aircraft/_log.py index 4a31cd6c..eab32b7f 100644 --- a/airpower/aircraft/_log.py +++ b/airpower/aircraft/_log.py @@ -2,10 +2,7 @@ Logging for the aircraft class. """ -import airpower.azimuth as apazimuth -import airpower.hexcode as aphexcode import airpower.log as aplog -import airpower.map as apmap import airpower as ap def _log(self, s): @@ -14,9 +11,8 @@ def _log(self, s): def _logbreak(self): aplog.logbreak() -def _logposition(self, s, t): - - self._log("%-5s : %-16s : %s" % (s, t, self.position())) +def _logaction(self, s, t, u): + self._log("%-5s : %-16s : %s" % (s, t, u)) def _logevent(self, s): self._log("%-5s : %s" % ("", s)) diff --git a/airpower/aircraft/_normalflight.py b/airpower/aircraft/_normalflight.py index 3a41cfcb..4bd51c5f 100644 --- a/airpower/aircraft/_normalflight.py +++ b/airpower/aircraft/_normalflight.py @@ -771,93 +771,99 @@ def doaction(action): Carry out an action for normal flight. """ - # Check we have at least one FP remaining. - if self._fp + 1 > self._maxfp: - raise RuntimeError("only %.1f FPs are available." % self._maxfp) + try: - # Determine if this FP is the last FP of the move. - self._lastfp = (self._fp + 2 > self._maxfp) + # Check we have at least one FP remaining. + if self._fp + 1 > self._maxfp: + raise RuntimeError("only %.1f FPs are available." % self._maxfp) + + # Determine if this FP is the last FP of the move. + self._lastfp = (self._fp + 2 > self._maxfp) - initialaltitude = self._altitude - initialaltitudeband = self._altitudeband + initialaltitude = self._altitude + initialaltitudeband = self._altitudeband - if doelements(action, "maneuvering departure", False): + if doelements(action, "maneuvering departure", False): - self._maneuveringdeparture = True + self._maneuveringdeparture = True - assert aphex.isvalid(self._x, self._y, facing=self._facing) - assert apaltitude.isvalidaltitude(self._altitude) + assert aphex.isvalid(self._x, self._y, facing=self._facing) + assert apaltitude.isvalidaltitude(self._altitude) - self._logposition("FP %d" % (self._hfp + self._vfp), action) - self._continueflightpath() + self._logaction("end", action, self.position()) + self._continueflightpath() - return + return - doelements(action, "turn declaration or bank", False) + doelements(action, "turn declaration or bank", False) - self._horizontal = doelements(action, "H", False) - self._vertical = doelements(action, "C or D", False) + self._horizontal = doelements(action, "H", False) + self._vertical = doelements(action, "C or D", False) - if not self._horizontal and not self._vertical: - raise RuntimeError("%r is not a valid action." % action) - elif self._horizontal and self._vertical: - if not flighttype == "UD" and not flighttype == "LVL": - raise RuntimeError("%r is not a valid action when the flight type is %s." % (action, flighttype)) + if not self._horizontal and not self._vertical: + raise RuntimeError("%r is not a valid action." % action) + elif self._horizontal and self._vertical: + if not flighttype == "UD" and not flighttype == "LVL": + raise RuntimeError("%r is not a valid action when the flight type is %s." % (action, flighttype)) - self._fp += 1 - if self._horizontal: - self._hfp += 1 - elif self._hfp < self._mininitialhfp: - raise RuntimeError("insufficient initial HFPs.") - else: - self._vfp += 1 + self._fp += 1 + if self._horizontal: + self._hfp += 1 + elif self._hfp < self._mininitialhfp: + raise RuntimeError("insufficient initial HFPs.") + else: + self._vfp += 1 - self._unloaded = (self._flighttype == "UD" and self._vertical) - if self._unloaded: - if self._firstunloadedfp == None: - self._firstunloadedfp = self._hfp - self._lastunloadedfp = self._hfp - - # See rule 8.2.2. - if not self._unloaded: - self._turnfp += 1 - - turn = doelements(action, "turn" , False) - roll = doelements(action, "roll" , False) - slide = doelements(action, "slide", False) - prep = doelements(action, "prep" , False) - if roll and slide: - raise RuntimeError("an aircraft cannot roll and slide on the same FP.") - if turn and (roll or slide): - raise RuntimeError("an aircraft cannot turn and maneuver on the same FP.") - if prep and (roll or slide): - raise RuntimeError("an aircraft cannot maneuver and prepare for a maneuver on the same FP.") - if turn and prep: - raise RuntimeError("an aircraft cannot turn and prepare for a maneuver on the same FP.") - - # See rule 13.1. - if prep and not self._horizontal: - raise RuntimeError("an aircraft can only prepare for a maneuver during an HFP.") - # See rule 8.2.2. - if prep and self._unloaded: - raise RuntimeError("an aircraft may not prepare for a maneuver during an unloaded HFP.") - - if slide and not self._horizontal: - raise RuntimeError("an aircraft can only slide on a HFP.") - - # See rule 13.1. - if prep: - self._prepfp += 1 - self._turnrate = None - self._turnfp = 0 - elif turn or slide or roll: - self._prepfp = 0 - self._turnfp = 0 + self._unloaded = (self._flighttype == "UD" and self._vertical) + if self._unloaded: + if self._firstunloadedfp == None: + self._firstunloadedfp = self._hfp + self._lastunloadedfp = self._hfp + + # See rule 8.2.2. + if not self._unloaded: + self._turnfp += 1 + + turn = doelements(action, "turn" , False) + roll = doelements(action, "roll" , False) + slide = doelements(action, "slide", False) + prep = doelements(action, "prep" , False) + if roll and slide: + raise RuntimeError("an aircraft cannot roll and slide on the same FP.") + if turn and (roll or slide): + raise RuntimeError("an aircraft cannot turn and maneuver on the same FP.") + if prep and (roll or slide): + raise RuntimeError("an aircraft cannot maneuver and prepare for a maneuver on the same FP.") + if turn and prep: + raise RuntimeError("an aircraft cannot turn and prepare for a maneuver on the same FP.") + + # See rule 13.1. + if prep and not self._horizontal: + raise RuntimeError("an aircraft can only prepare for a maneuver during an HFP.") + # See rule 8.2.2. + if prep and self._unloaded: + raise RuntimeError("an aircraft may not prepare for a maneuver during an unloaded HFP.") + + if slide and not self._horizontal: + raise RuntimeError("an aircraft can only slide on a HFP.") + + # See rule 13.1. + if prep: + self._prepfp += 1 + self._turnrate = None + self._turnfp = 0 + elif turn or slide or roll: + self._prepfp = 0 + self._turnfp = 0 - assert aphex.isvalid(self._x, self._y, facing=self._facing) - assert apaltitude.isvalidaltitude(self._altitude) + assert aphex.isvalid(self._x, self._y, facing=self._facing) + assert apaltitude.isvalidaltitude(self._altitude) + + except RuntimeError as e: + self._logaction("FP %d" % self._fp, action, "") + raise e - self._logposition("FP %d" % (self._hfp + self._vfp), action) + self._logaction("FP %d" % self._fp, action, self.position()) self._continueflightpath() # See rules 7.7 and 8.5. @@ -1192,7 +1198,7 @@ def determinerequiredhfpvfpmix(): determinerequiredhfpvfpmix() self._log("---") - self._logposition("start", "") + self._logaction("start", "", self.position()) self._continuenormalflight(actions) diff --git a/airpower/aircraft/_stalledflight.py b/airpower/aircraft/_stalledflight.py index 31ed4c21..18f6adcc 100644 --- a/airpower/aircraft/_stalledflight.py +++ b/airpower/aircraft/_stalledflight.py @@ -42,7 +42,7 @@ def dojettison(configuration): self._log("- carrying %+.2f APs." % self._apcarry) self._log("---") - self._logposition("start", "") + self._logaction("start", "", self.position()) altitudechange = math.ceil(self._speed + self._turnsstalled) @@ -57,7 +57,7 @@ def dojettison(configuration): else: self._altitudeap = 1.0 * altitudechange - self._logposition("end", action) + self._logaction("end", action, self.position()) if initialaltitudeband != self._altitudeband: self._logevent("altitude band changed from %s to %s." % (initialaltitudeband, self._altitudeband))