def welcoming(iq):
"Would this quadrant welcome another Klingon?"
- return iq.valid_Quadrant() and \
+ return iq.valid_quadrant() and \
not game.state.galaxy[iq.i][iq.j].supernova and \
game.state.galaxy[iq.i][iq.j].klingons < MAXKLQUAD
for enemy in game.enemies:
if enemy.type in ('K', 'R'):
movebaddy(enemy)
- game.enemies.sort(lambda x, y: cmp(x.kdist, y.kdist))
+ sortenemies()
def movescom(iq, avoid):
"Commander movement helper."
game.klhere -= 1
if game.condition != "docked":
newcnd()
- game.enemies.sort(lambda x, y: cmp(x.kdist, y.kdist))
+ sortenemies()
# check for a helpful planet
for i in range(game.inplan):
if game.state.planets[i].quadrant == game.state.kscmdr and \
action = "SHUP"
else:
scanner.chew()
- return
+ return
if action == "SHUP": # raise shields
if game.shldup:
prout(_("Shields already up."))
prout(_(" displaced by blast to Sector %s ") % bumpto)
for enemy in game.enemies:
enemy.kdist = enemy.kavgd = (game.sector-enemy.location).distance()
- game.enemies.sort(lambda x, y: cmp(x.kdist, y.kdist))
+ sortenemies()
return None
elif iquad in ('C', 'S', 'R', 'K'): # Hit a regular enemy
# find the enemy
game.quad[bumpto.i][bumpto.j]=iquad
for enemy in game.enemies:
enemy.kdist = enemy.kavgd = (game.sector-enemy.location).distance()
- game.enemies.sort(lambda x, y: cmp(x.kdist, y.kdist))
+ sortenemies()
return None
elif iquad == 'B': # Hit a base
skip(1)
# After attack, reset average distance to enemies
for enemy in game.enemies:
enemy.kavgd = enemy.kdist
- game.enemies.sort(lambda x, y: cmp(x.kdist, y.kdist))
+ sortenemies()
return
def deadkl(w, type, mv):
prout(_("SELF-DESTRUCT-SEQUENCE-WILL-BE-ABORTED"))
skip(1)
scanner.next()
- scanner.chew()
if game.passwd != scanner.token:
prouts(_("PASSWORD-REJECTED;"))
skip(1)
skip(1)
if len(game.enemies) != 0:
whammo = 25.0 * game.energy
- l=1
- while l <= len(game.enemies):
+ for l in range(len(game.enemies)):
if game.enemies[l].power*game.enemies[l].kdist <= whammo:
deadkl(game.enemies[l].location, game.quad[game.enemies[l].location.i][game.enemies[l].location.j], game.enemies[l].location)
- l += 1
finish(FDILITHIUM)
def killrate():
"Skip i lines. Pause game if this would cause a scrolling event."
for dummy in range(i):
if game.options & OPTION_CURSES:
- (y, x) = curwnd.getyx()
- (my, mx) = curwnd.getmaxyx()
- if curwnd == message_window and y >= my - 2:
- pause_game()
- clrscr()
- else:
- try:
- curwnd.move(y+1, 0)
- except curses.error:
- pass
+ (y, x) = curwnd.getyx()
+ try:
+ curwnd.move(y+1, 0)
+ except curses.error:
+ pass
else:
global linecount
linecount += 1
def proutn(line):
"Utter a line with no following line feed."
if game.options & OPTION_CURSES:
+ (y, x) = curwnd.getyx()
+ (my, mx) = curwnd.getmaxyx()
+ if curwnd == message_window and y >= my - 2:
+ pause_game()
+ clrscr()
curwnd.addstr(line)
curwnd.refresh()
else:
finald = (w-enemy.location).distance()
enemy.kavgd = 0.5 * (finald + enemy.kdist)
enemy.kdist = finald
- game.enemies.sort(lambda x, y: cmp(x.kdist, y.kdist))
+ sortenemies()
if not game.state.galaxy[game.quadrant.i][game.quadrant.j].supernova:
attack(torps_ok=False)
for enemy in game.enemies:
if game.state.nscrem:
prout(_(" YOU'LL NEED IT."))
waitfor()
+ clrscr()
+ setwnd(message_window)
newqad()
if len(game.enemies) - (thing == game.quadrant) - (game.tholian != None):
game.shldup = True
game.tourn = game.length = 0
game.thawed = False
game.skill = SKILL_NONE
- if not scanner.inqueue: # Can start with command line options
- proutn(_("Would you like a regular, tournament, or saved game? "))
+ scanner.chew()
+# if not scanner.inqueue: # Can start with command line options
+ proutn(_("Would you like a regular, tournament, or saved game? "))
scanner.next()
if scanner.sees("tournament"):
while scanner.next() == "IHEOL":
"Drop new Klingon into current quadrant."
return Enemy('K', loc=dropin(), power=randreal(300,450)+25.0*game.skill)
+def sortenemies():
+ "Sort enemies by distance so 'nearest' is meaningful."
+ game.enemies.sort(lambda x, y: cmp(x.kdist, y.kdist))
+
def newqad():
"Set up a new state of quadrant, for when we enter or re-enter it."
game.justin = True
game.quad[QUADSIZE-1][0] = 'X'
if game.quad[QUADSIZE-1][QUADSIZE-1]=='.':
game.quad[QUADSIZE-1][QUADSIZE-1] = 'X'
- # Sort enemies by distance so 'nearest' is meaningful
- game.enemies.sort(lambda x, y: cmp(x.kdist, y.kdist))
+ sortenemies()
# And finally the stars
for i in range(q.stars):
dropin('*')
def makemoves():
"Command-interpretation loop."
- clrscr()
- setwnd(message_window)
while True: # command loop
drawmaps(1)
while True: # get a command