Make it possible to reset a course object.
[super-star-trek.git] / src / sst.py
index 3cfffb7209734ef84e10a9c94e4cfb597fc63d42..ed133629e9741e916ba61dea9a9d0c705af69b43 100644 (file)
@@ -2477,7 +2477,7 @@ def events():
                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: 
@@ -3916,17 +3916,23 @@ class course:
             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:
-            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.reset()
         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."
-        self.moves -=1
+        self.step += 1
         self.nextlocation = self.location + self.increment
         oldloc = (self.location/grain).roundtogrid()
         newloc = (self.nextlocation/grain).roundtogrid()
@@ -4069,28 +4075,15 @@ def warp(course, involuntary):
        if blooey or twarp:
            # If time warp or engine damage, check path 
            # If it is obstructed, don't do warp or damage 
-           angle = ((15.0-course.bearing)*0.5235998)
-           deltax = -math.sin(angle)
-           deltay = math.cos(angle)
-           if math.fabs(deltax) > math.fabs(deltay):
-               bigger = math.fabs(deltax)
-           else:
-               bigger = math.fabs(deltay)
-           deltax /= bigger
-           deltay /= bigger
-           n = 10.0 * course.distance * bigger +0.5
-           x = game.sector.i
-           y = game.sector.j
-           for l in range(1, n+1):
-               x += deltax
-               ix = x + 0.5
-               y += deltay
-               iy = y +0.5
-               if not coord(ix, iy).valid_sector():
-                   break
-               if game.quad[ix][iy] != IHDOT:
+            for m in range(course.moves):
+                course.next()
+                w = course.sector()
+                if not w.valid_sector():
+                    break
+               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: