X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=sst.py;h=5200f24619fce2d5e8b677a872934df1baf050cb;hb=ab0063f536c6356a54b70887ce08ce047f96a298;hp=e3959641877d691bc70a221b06d04a0783537c3d;hpb=708a55633712f9981231e80360ac5e3fe81b1d3b;p=super-star-trek.git diff --git a/sst.py b/sst.py index e395964..5200f24 100755 --- a/sst.py +++ b/sst.py @@ -15,7 +15,7 @@ from __future__ import print_function, division # Runs under Python 2 an Python 3. Preserve this property! # SPDX-License-Identifier: BSD-2-clause -# pylint: disable=line-too-long,superfluous-parens,too-many-lines,invalid-name,missing-function-docstring,missing-class-docstring,multiple-statements,too-many-branches,too-many-statements,too-many-locals,too-many-nested-blocks,too-many-return-statements,too-many-instance-attributes,global-statement,no-else-break,no-else-return,no-else-continue,too-few-public-methods,too-many-boolean-expressions +# pylint: disable=line-too-long,superfluous-parens,too-many-lines,invalid-name,missing-function-docstring,missing-class-docstring,multiple-statements,too-many-branches,too-many-statements,too-many-locals,too-many-nested-blocks,too-many-return-statements,too-many-instance-attributes,global-statement,no-else-break,no-else-return,no-else-continue,too-few-public-methods,too-many-boolean-expressions,consider-using-f-string,consider-using-enumerate,consider-using-with,unspecified-encoding # pylint: disable=multiple-imports import os, sys, math, curses, time, pickle, copy, gettext, getpass @@ -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': @@ -677,10 +677,8 @@ def movebaddy(enemy): nsteps = abs(int(motion)) if motion > 0 and nsteps > mdist: nsteps = mdist # don't overshoot - if nsteps > QUADSIZE: - nsteps = QUADSIZE # This shouldn't be necessary - if nsteps < 1: - nsteps = 1 # This shouldn't be necessary + nsteps = min(nsteps, QUADSIZE) # This shouldn't be necessary + nsteps = max(nsteps, 1) # This shouldn't be necessary if game.idebug: proutn("NSTEPS = %d:" % nsteps) # Compute preferred values of delta X and Y @@ -726,7 +724,7 @@ def movebaddy(enemy): elif (game.options & OPTION_RAMMING) and game.quad[look.i][look.j] != '.': # See if enemy should ram ship if game.quad[look.i][look.j] == game.ship and \ - (enemy.type == 'C' or enemy.type == 'S'): + enemy.type in ('C', 'S'): collision(rammed=True, enemy=enemy) return [] if krawli != m.i and m.j != 0: @@ -1329,7 +1327,7 @@ 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(): @@ -1589,8 +1587,7 @@ def attack(torps_ok): propor = pfac * game.shield if game.condition == "docked": propor *= 2.1 - if propor < 0.1: - propor = 0.1 + propor = max(propor, 0.1) hitsh = propor*chgfac*hit+1.0 absorb = 0.8*hitsh if absorb > game.shield: @@ -2521,7 +2518,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 @@ -2567,7 +2564,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 @@ -3871,7 +3868,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" @@ -3915,7 +3912,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: @@ -4569,7 +4569,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 @@ -5517,8 +5518,7 @@ def eta(): prout(_("We'll never make it, sir.")) scanner.chew() return - if twarp < 1.0: - twarp = 1.0 + twarp = max(twarp, 1.0) break scanner.chew() proutn(_("Warp factor? ")) @@ -5797,13 +5797,11 @@ def setup(): # Position ordinary Klingon Battle Cruisers krem = game.inkling klumper = 0.25*game.skill*(9.0-game.length)+1.0 - if klumper > MAXKLQUAD: - klumper = MAXKLQUAD + klumper = min(klumper, MAXKLQUAD) while True: r = rnd.real() klump = int((1.0 - r*r)*klumper) - if klump > krem: - klump = krem + klump = min(klump, krem) krem -= klump while True: w = randplace(GALSIZE)