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 \
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):
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:
"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('*')