Address GitLab issue #1: Crash when issuing DOCK command next to inhabited planet
authorEric S. Raymond <esr@thyrsus.com>
Sun, 12 Aug 2018 15:59:55 +0000 (11:59 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 12 Aug 2018 16:00:15 +0000 (12:00 -0400)
Actually this would have happened anytime docking with no starbase in sector.

NEWS
sst.py

diff --git a/NEWS b/NEWS
index 47458c9e1f207fc5240375e3f59b8aa5f71ab48b..eac2608b70db6320a4d839f0083e91bfe26f96d2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
                        SST2K project news.
 
                        SST2K project news.
 
+Repository head:
+    Crash bug fix when docking with no starbase in sector.
+
 2.2 @ 2017-03-01
     Added color. Added BSD Trek 'CAPTURE' and 'CLOAK' (from Tom Almy's
     2013 changes).  Many bug fixes.
 2.2 @ 2017-03-01
     Added color. Added BSD Trek 'CAPTURE' and 'CLOAK' (from Tom Almy's
     2013 changes).  Many bug fixes.
diff --git a/sst.py b/sst.py
index 945017fed97d9a0c15ebc5e864c1b9ba92a8fbde..bd0582e9f370c18d768e22b93aecbda38c7a1472 100755 (executable)
--- a/sst.py
+++ b/sst.py
@@ -86,8 +86,6 @@ class Coord:
         return self.i >= 0 and self.i < QUADSIZE and self.j >= 0 and self.j < QUADSIZE
     def invalidate(self):
         self.i = self.j = None
         return self.i >= 0 and self.i < QUADSIZE and self.j >= 0 and self.j < QUADSIZE
     def invalidate(self):
         self.i = self.j = None
-    def is_valid(self):
-        return self.i != None and self.j != None
     def __eq__(self, other):
         return other != None and self.i == other.i and self.j == other.j
     def __ne__(self, other):
     def __eq__(self, other):
         return other != None and self.i == other.i and self.j == other.j
     def __ne__(self, other):
@@ -3855,7 +3853,7 @@ def dock(verbose):
     if game.inorbit:
         prout(_("You must first leave standard orbit."))
         return
     if game.inorbit:
         prout(_("You must first leave standard orbit."))
         return
-    if not game.base.is_valid() or abs(game.sector.i-game.base.i) > 1 or abs(game.sector.j-game.base.j) > 1:
+    if game.base is None or abs(game.sector.i-game.base.i) > 1 or abs(game.sector.j-game.base.j) > 1:
         prout(crmshp() + _(" not adjacent to base."))
         return
     if game.iscloaked:
         prout(crmshp() + _(" not adjacent to base."))
         return
     if game.iscloaked:
@@ -4491,7 +4489,7 @@ def mayday():
             # found one -- finish up
             game.sector = w
             break
             # found one -- finish up
             game.sector = w
             break
-    if not game.sector.is_valid():
+    if game.sector is None:
         prout(_("You have been lost in space..."))
         finish(FMATERIALIZE)
         return
         prout(_("You have been lost in space..."))
         finish(FMATERIALIZE)
         return
@@ -4671,7 +4669,7 @@ def orbit():
     if damaged(DWARPEN) and damaged(DIMPULS):
         prout(_("Both warp and impulse engines damaged."))
         return
     if damaged(DWARPEN) and damaged(DIMPULS):
         prout(_("Both warp and impulse engines damaged."))
         return
-    if not game.plnet.is_valid():
+    if game.plnet is None:
         prout("There is no planet in this sector.")
         return
     if abs(game.sector.i-game.plnet.i)>1 or abs(game.sector.j-game.plnet.j)>1:
         prout("There is no planet in this sector.")
         return
     if abs(game.sector.i-game.plnet.i)>1 or abs(game.sector.j-game.plnet.j)>1: