See the doc/HACKING file in the distribution for designers notes and advice
on how to modify (and how not to modify!) this code.
"""
-import os, sys, math, curses, time, readline, cPickle, random, copy, gettext, getpass
+import os, sys, math, curses, time, readline, pickle, random, copy, gettext, getpass
version = "2.1"
break
else:
prout("Internal error, no enemy where expected!")
- raise SystemExit, 1
+ raise SystemExit(1)
return None
elif iquad == 'B': # Hit a base
skip(1)
prout(_("***STARBASE DESTROYED.."))
- game.state.baseq = filter(lambda x: x != game.quadrant, game.state.baseq)
+ game.state.baseq = [x for x in game.state.baseq if x != game.quadrant]
game.quad[w.i][w.j] = '.'
game.base.invalidate()
game.state.galaxy[game.quadrant.i][game.quadrant.j].starbase = False
game.state.chart[game.battle.i][game.battle.j].starbase = False
# Remove Starbase from galaxy
game.state.galaxy[game.battle.i][game.battle.j].starbase = False
- game.state.baseq = filter(lambda x: x != game.battle, game.state.baseq)
+ game.state.baseq = [x for x in game.state.baseq if x != game.battle]
if game.isatb == 2:
# reinstate a commander's base attack
game.battle = hold
game.quad[neighbor.i][neighbor.j] = '.'
elif iquad == 'B': # Destroy base
game.state.galaxy[game.quadrant.i][game.quadrant.j].starbase = False
- game.state.baseq = filter(lambda x: x!= game.quadrant, game.state.baseq)
+ game.state.baseq = [x for x in game.state.baseq if x!= game.quadrant]
game.base.invalidate()
game.state.basekl += 1
newcnd()
game.state.planets[loop].pclass = "destroyed"
npdead += 1
# Destroy any base in supernovaed quadrant
- game.state.baseq = filter(lambda x: x != nq, game.state.baseq)
+ game.state.baseq = [x for x in game.state.baseq if x != nq]
# If starship caused supernova, tally up destruction
if w != None:
game.state.starkl += game.state.galaxy[nq.i][nq.j].stars
sys.stdout.write('\n')
proutn(prompt)
if not replayfp:
- raw_input()
+ input()
sys.stdout.write('\n' * rows)
linecount = 0
elif line[0] != "#":
break
else:
- line = raw_input() + "\n"
+ line = eval(input()) + "\n"
if logfp:
logfp.write(line)
return line
newquadrant(noattack)
break
elif check_collision(w):
- print "Collision detected"
+ print("Collision detected")
break
else:
game.sector = w
if game.condition != "docked":
newcnd()
prstat(_("Condition"), _("%s, %i DAMAGES") % \
- (game.condition.upper(), sum(map(lambda x: x > 0, game.damage))))
+ (game.condition.upper(), sum([x > 0 for x in game.damage])))
if not req or req == 3:
prstat(_("Position"), "%s , %s" % (game.quadrant, game.sector))
if not req or req == 4:
except IOError:
prout(_("Can't freeze game as file %s") % scanner.token)
return
- cPickle.dump(game, fp)
+ pickle.dump(game, fp)
fp.close()
scanner.chew()
except IOError:
prout(_("Can't thaw game in %s") % scanner.token)
return
- game = cPickle.load(fp)
+ game = pickle.load(fp)
fp.close()
scanner.chew()
return False
prout(_("%d stardates.") % int(game.intime))
proutn(_("%d starbases in ") % game.inbase)
for i in range(game.inbase):
- proutn(`game.state.baseq[i]`)
+ proutn(repr(game.state.baseq[i]))
proutn(" ")
skip(2)
proutn(_("The Enterprise is currently in Quadrant %s") % game.quadrant)
setwnd(message_window)
if key == "IHEOL":
return
- cmds = map(lambda x: x[0], commands)
+ cmds = [x[0] for x in commands]
if scanner.token.upper() in cmds or scanner.token.upper() == "ABBREV":
break
skip(1)
elif cmd == "EMEXIT": # Emergency exit
clrscr() # Hide screen
freeze(True) # forced save
- raise SystemExit,1 # And quick exit
+ raise SystemExit(1) # And quick exit
elif cmd == "PROBE":
probe() # Launch probe
if game.ididit:
buf += _("Quadrant ")
elif loctype == "sector":
buf += _("Sector ")
- return buf + `w`
+ return buf + repr(w)
def crmshp():
"Emit our ship name."
replayfp = open(val, "r")
except IOError:
sys.stderr.write("sst: can't open replay file %s\n" % val)
- raise SystemExit, 1
+ raise SystemExit(1)
try:
line = replayfp.readline().strip()
(leader, __, seed) = line.split()
elif switch == '-x':
game.idebug = True
elif switch == '-V':
- print "SST2K", version
- raise SystemExit, 0
+ print("SST2K", version)
+ raise SystemExit(0)
else:
sys.stderr.write("usage: sst [-t] [-x] [startcommand...].\n")
- raise SystemExit, 1
+ raise SystemExit(1)
# where to save the input in case of bugs
if "TMPDIR" in os.environ:
tmpdir = os.environ['TMPDIR']
(getpass.getuser(),socket.gethostname(),time.ctime()))
random.seed(seed)
scanner = sstscanner()
- map(scanner.append, arguments)
+ for arg in arguments:
+ scanner.append(arg)
try:
iostart()
while True: # Play a game
prout(_("May the Great Bird of the Galaxy roost upon your home planet."))
finally:
ioend()
- raise SystemExit, 0
+ raise SystemExit(0)
except KeyboardInterrupt:
if logfp:
logfp.close()
- print ""
+ print("")
# End.