X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=sst.py;h=94bc397b2c0f8e5df713a84398b8098e03c80dc6;hb=f2a1b1bdc40e06e1141fe0d1e6e108b0bf9715f8;hp=ddbe1baf1b2685592c7e01cb04528f02c87d728a;hpb=2fc3a5a9179d17c1a30a404a598029d57cfb554f;p=super-star-trek.git diff --git a/sst.py b/sst.py index ddbe1ba..94bc397 100755 --- a/sst.py +++ b/sst.py @@ -142,9 +142,9 @@ class Coord: self.i = x # Row self.j = y # Column def valid_quadrant(self): - return self.i >= 0 and self.i < GALSIZE and self.j >= 0 and self.j < GALSIZE + return (self.i is not None) and (self.j is not None) and (self.i >= 0) and (self.i < GALSIZE) and (self.j >= 0) and (self.j < GALSIZE) def valid_sector(self): - return self.i >= 0 and self.i < QUADSIZE and self.j >= 0 and self.j < QUADSIZE + return (self.i is not None) and (self.j is not None) and (self.i >= 0) and (self.i < QUADSIZE) and (self.j >= 0) and (self.j < QUADSIZE) def invalidate(self): self.i = self.j = None def __eq__(self, other): @@ -544,9 +544,9 @@ def tryexit(enemy, look, irun): iq.i = game.quadrant.i+(look.i+(QUADSIZE-1))//QUADSIZE - 1 iq.j = game.quadrant.j+(look.j+(QUADSIZE-1))//QUADSIZE - 1 if not welcoming(iq): - return False + return [] if enemy.type == 'R': - return False # Romulans cannot escape! + return [] # Romulans cannot escape! if not irun: # avoid intruding on another commander's territory if enemy.type == 'C': @@ -1327,15 +1327,16 @@ def torpedo(origin, bearing, dispersion, number, nburst): deadkl(w, iquad, w) return None proutn(crmena(True, iquad, "sector", w)) - displacement = course(track.bearing+rnd.real(-2.4, 2.4), distance=2**0.5) + displacement = course(track.bearing+rnd.real(-2.4, 2.4), distance=2**0.5, origin=w) displacement.nexttok() bumpto = displacement.sector() - if not bumpto.valid_sector(): - prout(_(" damaged but not destroyed.")) - return None if game.quad[bumpto.i][bumpto.j] == ' ': prout(_(" buffeted into black hole.")) deadkl(w, iquad, bumpto) + return None + if not bumpto.valid_sector(): + prout(_(" damaged but not destroyed.")) + return None if game.quad[bumpto.i][bumpto.j] != '.': prout(_(" damaged but not destroyed.")) else: @@ -2518,7 +2519,7 @@ def events(): elif evcode == FCDBAS: # Commander succeeds in destroying base if evcode == FCDBAS: unschedule(FCDBAS) - if not game.state.baseq() \ + if not game.state.baseq \ or not game.state.galaxy[game.battle.i][game.battle.j].starbase: game.battle.invalidate() continue @@ -2564,7 +2565,7 @@ def events(): pdest.charted = True game.probe.moves -= 1 # One less to travel if game.probe.arrived() and game.isarmed and pdest.stars: - supernova(game.probe) # fire in the hole! + supernova(game.probe.quadrant()) # fire in the hole! unschedule(FDSPROB) if game.state.galaxy[pquad.i][pquad.j].supernova: return @@ -3868,7 +3869,7 @@ def imove(icourse=None, noattack=False): if game.iscloaked: # We can't be tractor beamed if cloaked, # so move the event into the future - postpone(FTBEAM, game.optime + expran(1.5*game.intime/len(game.kcmdr))) + postpone(FTBEAM, game.optime + expran(1.5*game.intime/len(game.state.kcmdr))) else: trbeam = True game.condition = "red" @@ -3912,7 +3913,10 @@ def dock(verbose): if game.inorbit: prout(_("You must first leave standard orbit.")) return - if game.base is None or abs(game.sector.i-game.base.i) > 1 or abs(game.sector.j-game.base.j) > 1: + if game.base is None or not game.base.valid_sector(): + prout(_("No starbase available for docking in this quadrant.")) + return + if (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: @@ -4566,7 +4570,8 @@ def mayday(): break prout(_("fails.")) textcolor(DEFAULT) - curses.delay_output(500) + if game.options & OPTION_CURSES: + curses.delay_output(500) if m > 3: game.quad[game.sector.i][game.sector.j]='?' game.alive = False @@ -6768,7 +6773,7 @@ if __name__ == '__main__': logfp.write("# options %s\n" % " ".join(arguments)) logfp.write("# SST2K version %s\n" % version) logfp.write("# recorded by %s@%s on %s\n" % \ - (getpass.getuser(),socket.gethostname(),time.ctime())) + (getpass.getuser(),socket.getfqdn(),time.ctime())) rnd.seed(seed) scanner = sstscanner() for arg in arguments: