Complete repair of Thingy code.
[super-star-trek.git] / sst
diff --git a/sst b/sst
index 32299535f3ada075a1f758e73bfa3b195098a444..d34a396759aaed7ca6b677c2f8b9a839f7b066cb 100755 (executable)
--- a/sst
+++ b/sst
@@ -88,6 +88,14 @@ class randomizer:
         #    logfp.write("#seed(%d)\n" % n)
         game.lcg_x = n % randomizer.LCG_M
 
+    @staticmethod
+    def getrngstate():
+        return game.lcg_x
+
+    @staticmethod
+    def setrngstate(n):
+        game.lcg_x = n
+
 GALSIZE        = 8             # Galaxy size in quadrants
 NINHAB         = (GALSIZE * GALSIZE // 2)      # Number of inhabited worlds
 MAXUNINHAB     = 10            # Maximum uninhabited worlds
@@ -5930,13 +5938,17 @@ def setup():
     # Place thing (in tournament game, we don't want one!)
     # New in SST2K: never place the Thing near a starbase.
     # This makes sense and avoids a special case in the old code.
-    #global thing
-    #if game.tourn is None:
-    #    while True:
-    #        thing.location = randplace(GALSIZE)
-    #        # Put it somewhere a starbase is not
-    #        if thing.location not in game.state.baseq:
-    #            break
+    if game.tourn is None:
+        # Avoid distrubing the RNG chain.  This code
+        # was a late fix and we don't want to mess up
+        # all the regression tests.
+        state = randomizer.getrngstate()
+        while True:
+            thing.location = randplace(GALSIZE)
+            # Put it somewhere a starbase is not
+            if thing.location not in game.state.baseq:
+                break
+        randomizer.setrngstate(state)
     skip(2)
     game.state.snap = False
     if game.skill == SKILL_NOVICE: