projects
/
super-star-trek.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix array index overrun
[super-star-trek.git]
/
sst.py
diff --git
a/sst.py
b/sst.py
index 4e65748dd6f7b35f195c3129e9cb1a36891b5bde..4b3fdfa8a44aadc33df2243abc2cfc38b201da06 100755
(executable)
--- a/
sst.py
+++ b/
sst.py
@@
-416,7
+416,7
@@
def randreal(*args):
def welcoming(iq):
"Would this quadrant welcome another Klingon?"
def welcoming(iq):
"Would this quadrant welcome another Klingon?"
- return iq.valid_
Q
uadrant() and \
+ return iq.valid_
q
uadrant() and \
not game.state.galaxy[iq.i][iq.j].supernova and \
game.state.galaxy[iq.i][iq.j].klingons < MAXKLQUAD
not game.state.galaxy[iq.i][iq.j].supernova and \
game.state.galaxy[iq.i][iq.j].klingons < MAXKLQUAD
@@
-663,7
+663,7
@@
def moveklings():
for enemy in game.enemies:
if enemy.type in ('K', 'R'):
movebaddy(enemy)
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."
def movescom(iq, avoid):
"Commander movement helper."
@@
-689,7
+689,7
@@
def movescom(iq, avoid):
game.klhere -= 1
if game.condition != "docked":
newcnd()
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 \
# check for a helpful planet
for i in range(game.inplan):
if game.state.planets[i].quadrant == game.state.kscmdr and \
@@
-1107,7
+1107,7
@@
def torpedo(origin, bearing, dispersion, number, nburst):
prout(_(" displaced by blast to Sector %s ") % bumpto)
for enemy in game.enemies:
enemy.kdist = enemy.kavgd = (game.sector-enemy.location).distance()
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
return None
elif iquad in ('C', 'S', 'R', 'K'): # Hit a regular enemy
# find the enemy
@@
-1150,7
+1150,7
@@
def torpedo(origin, bearing, dispersion, number, nburst):
game.quad[bumpto.i][bumpto.j]=iquad
for enemy in game.enemies:
enemy.kdist = enemy.kavgd = (game.sector-enemy.location).distance()
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)
return None
elif iquad == 'B': # Hit a base
skip(1)
@@
-1423,7
+1423,7
@@
def attack(torps_ok):
# After attack, reset average distance to enemies
for enemy in game.enemies:
enemy.kavgd = enemy.kdist
# 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):
return
def deadkl(w, type, mv):
@@
-2692,11
+2692,9
@@
def kaboom():
skip(1)
if len(game.enemies) != 0:
whammo = 25.0 * game.energy
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)
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():
finish(FDILITHIUM)
def killrate():
@@
-3161,16
+3159,11
@@
def skip(i):
"Skip i lines. Pause game if this would cause a scrolling event."
for dummy in range(i):
if game.options & OPTION_CURSES:
"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
else:
global linecount
linecount += 1
@@
-3182,6
+3175,11
@@
def skip(i):
def proutn(line):
"Utter a line with no following line feed."
if game.options & OPTION_CURSES:
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:
curwnd.addstr(line)
curwnd.refresh()
else:
@@
-3545,7
+3543,7
@@
def imove(icourse=None, noattack=False):
finald = (w-enemy.location).distance()
enemy.kavgd = 0.5 * (finald + enemy.kdist)
enemy.kdist = finald
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 not game.state.galaxy[game.quadrant.i][game.quadrant.j].supernova:
attack(torps_ok=False)
for enemy in game.enemies:
@@
-5634,6
+5632,10
@@
def newkling():
"Drop new Klingon into current quadrant."
return Enemy('K', loc=dropin(), power=randreal(300,450)+25.0*game.skill)
"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
def newqad():
"Set up a new state of quadrant, for when we enter or re-enter it."
game.justin = True
@@
-5727,8
+5729,7
@@
def newqad():
game.quad[QUADSIZE-1][0] = 'X'
if game.quad[QUADSIZE-1][QUADSIZE-1]=='.':
game.quad[QUADSIZE-1][QUADSIZE-1] = 'X'
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('*')
# And finally the stars
for i in range(q.stars):
dropin('*')