Make it possible to reset a course object.
authorEric S. Raymond <esr@thyrsus.com>
Fri, 13 Oct 2006 17:10:08 +0000 (17:10 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Fri, 13 Oct 2006 17:10:08 +0000 (17:10 +0000)
src/sst.py

index ddb1313f87c42d82ae46b486c5b29a971983b8ac..ed133629e9741e916ba61dea9a9d0c705af69b43 100644 (file)
@@ -2477,7 +2477,7 @@ def events():
                chp.stars = pdest.stars
                pdest.charted = True
            game.probe.moves -= 1 # One less to travel
                chp.stars = pdest.stars
                pdest.charted = True
            game.probe.moves -= 1 # One less to travel
-           if game.probe.moves == 0 and game.isarmed and pdest.stars:
+           if game.probe.arrived() and game.isarmed and pdest.stars:
                supernova(game.probe)           # fire in the hole!
                unschedule(FDSPROB)
                if game.state.galaxy[game.quadrant().i][game.quadrant().j].supernova: 
                supernova(game.probe)           # fire in the hole!
                unschedule(FDSPROB)
                if game.state.galaxy[game.quadrant().i][game.quadrant().j].supernova: 
@@ -3916,17 +3916,23 @@ class course:
             self.bearing += 12.0
         self.angle = ((15.0 - self.bearing) * 0.5235988)
         if origin is None:
             self.bearing += 12.0
         self.angle = ((15.0 - self.bearing) * 0.5235988)
         if origin is None:
-            self.location = cartesian(game.quadrant, game.sector)
+            self.origin = cartesian(game.quadrant, game.sector)
         else:
         else:
-            self.location = cartesian(game.quadrant, origin)
+            self.origin = cartesian(game.quadrant, origin)
         self.increment = coord(-math.sin(self.angle), math.cos(self.angle))
         bigger = max(abs(self.increment.i), abs(self.increment.j))
         self.increment /= bigger
         self.moves = int(round(10*self.distance*bigger))
         self.increment = coord(-math.sin(self.angle), math.cos(self.angle))
         bigger = max(abs(self.increment.i), abs(self.increment.j))
         self.increment /= bigger
         self.moves = int(round(10*self.distance*bigger))
+        self.reset()
         self.final = (self.location + self.moves*self.increment).roundtogrid()
         self.final = (self.location + self.moves*self.increment).roundtogrid()
+    def reset(self):
+        self.location = self.origin
+        self.step = 0
+    def arrived(self):
+        return self.location.roundtogrid() == self.final
     def next(self, grain=1):
         "Next step on course."
     def next(self, grain=1):
         "Next step on course."
-        self.moves -=1
+        self.step += 1
         self.nextlocation = self.location + self.increment
         oldloc = (self.location/grain).roundtogrid()
         newloc = (self.nextlocation/grain).roundtogrid()
         self.nextlocation = self.location + self.increment
         oldloc = (self.location/grain).roundtogrid()
         newloc = (self.nextlocation/grain).roundtogrid()
@@ -4077,6 +4083,7 @@ def warp(course, involuntary):
                if game.quad[w.x][w.y] != IHDOT:
                    blooey = False
                    twarp = False
                if game.quad[w.x][w.y] != IHDOT:
                    blooey = False
                    twarp = False
+            course.reset()
     # Activate Warp Engines and pay the cost 
     imove(course, novapush=False)
     if game.alldone:
     # Activate Warp Engines and pay the cost 
     imove(course, novapush=False)
     if game.alldone: