X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=src%2Fsst.py;h=f2b0bd0ec2bf70eb6ae6e6c6eb65013a58cff59c;hp=e21ced85e69601deffac756ad3361ba2f82165e0;hb=ec0c6c4b54b2eac3f1de1768dd342d2ed1390f6f;hpb=847413ccb3ee4a023ad79bc6d5370e3396ac0714 diff --git a/src/sst.py b/src/sst.py index e21ced8..f2b0bd0 100644 --- a/src/sst.py +++ b/src/sst.py @@ -201,10 +201,6 @@ FOREVER = 1e30 MAXBURST = 3 MINCMDR = 10 -# These functions hide the difference between 0-origin and 1-origin addressing. -def VALID_QUADRANT(x, y): return ((x)>=0 and (x)=0 and (y)=0 and (x)=0 and (y)=0 and self.i=0 and self.j=0 and self.i=0 and self.j= MAXKLQUAD: try: # this quadrant not ok, pick an adjacent one - for i in range(w.i - 1, w.i + 2): - for j in range(w.j - 1, w.j + 2): - if not VALID_QUADRANT(i, j): + for m.i in range(w.i - 1, w.i + 2): + for m.j in range(w.j - 1, w.j + 2): + if not m.valid_quadrant(): continue - q = game.state.galaxy[w.i][w.j] + q = game.state.galaxy[m.i][m.j] # check for this quad ok (not full & no snova) if q.klingons >= MAXKLQUAD or q.supernova: continue @@ -2561,7 +2560,7 @@ def events(): else: continue # search for eligible quadrant failed except "FOUNDIT": - w.i = i; w.j = j + w = m # deliver the child game.state.remkl += 1 q.klingons += 1 @@ -2570,7 +2569,6 @@ def events(): game.enemies.append(newkling()) # recompute time left game.recompute() - # report the disaster if we can if communicating(): if game.quadrant == w: prout(_("Spock- sensors indicate the Klingons have")) @@ -2656,7 +2654,7 @@ def nova(nov): if offset.j==0 and offset.i==0: continue neighbor = start + offset - if not VALID_SECTOR(neighbor.j, neighbor.i): + if not neighbor.valid_sector(): continue iquad = game.quad[neighbor.i][neighbor.j] # Empty space ends reaction @@ -2728,7 +2726,7 @@ def nova(nov): break newc = neighbor + neighbor - hits[mm] proutn(crmena(True, iquad, "sector", neighbor) + _(" damaged")) - if not VALID_SECTOR(newc.i, newc.j): + if not newc.valid_sector(): # can't leave quadrant skip(1) break @@ -3632,7 +3630,7 @@ def imove(course=None, novapush=False): y += deltay w.i = int(round(x)) w.j = int(round(y)) - if not VALID_SECTOR(w.i, w.j): + if not w.valid_sector(): # Leaving quadrant -- allow final enemy attack # Don't do it if being pushed by Nova if len(game.enemies) != 0 and not novapush: @@ -3892,7 +3890,7 @@ def getcourse(isprobe): dsect.i = xi dsect.j = xj itemp = "normal" - if not VALID_QUADRANT(dquad.i,dquad.j) or not VALID_SECTOR(dsect.i,dsect.j): + if not dquad.valid_quadrant() or not dsect.valid_sector(): huh() raise TrekError skip(1) @@ -3942,6 +3940,8 @@ class course: self.angle = ((15.0 - self.bearing) * 0.5235988) if origin is None: self.location = cartesian(game.quadrant, game.sector) + else: + self.location = 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 @@ -3960,7 +3960,7 @@ class course: def quadrant(self): return (self.location / QUADSIZE).roundtogrid() def sector(self): - return coord(self.location.i % QUADSIZE, self.location.j % QUADSIZE) + return coord(int(round(self.location.i)) % QUADSIZE, int(round(self.location.j)) % QUADSIZE) def power(self, warp): return self.distance*(warp**3)*(game.shldup+1) def time(self, warp): @@ -4108,7 +4108,7 @@ def warp(course, involuntary): ix = x + 0.5 y += deltay iy = y +0.5 - if not VALID_SECTOR(ix, iy): + if not coord(ix, iy).valid_sector(): break if game.quad[ix][iy] != IHDOT: blooey = False @@ -4390,7 +4390,7 @@ def mayday(): game.sector.invalidate() for m in range(1, 5+1): w = game.base.scatter() - if VALID_SECTOR(w.i,w.j) and game.quad[w.i][w.j]==IHDOT: + if w.valid_sector() and game.quad[w.i][w.j]==IHDOT: # found one -- finish up game.sector = w break @@ -4493,7 +4493,7 @@ def abandon(): game.quad[game.sector.i][game.sector.j] = IHDOT for l in range(QUADSIZE): game.sector = game.base.scatter() - if VALID_SECTOR(game.sector.i, game.sector.j) and \ + if game.sector.valid_sector() and \ game.quad[game.sector.i][game.sector.j] == IHDOT: break if l < QUADSIZE+1: @@ -5089,7 +5089,7 @@ def lrscan(silent): if not silent: proutn(" ") for y in range(game.quadrant.j-1, game.quadrant.j+2): - if not VALID_QUADRANT(x, y): + if not coord(x, y).valid_quadrant(): if not silent: proutn(" -1") else: @@ -5314,7 +5314,7 @@ def eta(): w2.j = 0 else: w2.j=QUADSIZE-1 - if not VALID_QUADRANT(w1.i, w1.j) or not VALID_SECTOR(w2.i, w2.j): + if not w1.valid_quadrant() or not w2.valid_sector(): huh() return dist = math.sqrt((w1.j-game.quadrant.j+(w2.j-game.sector.j)/(QUADSIZE*1.0))**2+