projects
/
super-star-trek.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ad7e6b2
)
Avoid divide-by-zero error.
author
Eric S. Raymond
<esr@thyrsus.com>
Fri, 6 Oct 2006 01:19:43 +0000
(
01:19
+0000)
committer
Eric S. Raymond
<esr@thyrsus.com>
Fri, 6 Oct 2006 01:19:43 +0000
(
01:19
+0000)
src/sst.py
patch
|
blob
|
history
diff --git
a/src/sst.py
b/src/sst.py
index 41d6c0f5094de61f26dd4319c74070517f1bc5c1..9785eb7bf215d6a78450cddc52a3cc0713c79bbe 100644
(file)
--- a/
src/sst.py
+++ b/
src/sst.py
@@
-1992,7
+1992,7
@@
def hittem(hits):
else: # decide whether or not to emasculate klingon
if kpow > 0 and random.random() >= 0.9 and \
kpow <= ((0.4 + 0.4*random.random())*kpini):
else: # decide whether or not to emasculate klingon
if kpow > 0 and random.random() >= 0.9 and \
kpow <= ((0.4 + 0.4*random.random())*kpini):
- prout(_("***Mr. Spock- \"Captain, the vessel at Sector %s")
,
w)
+ prout(_("***Mr. Spock- \"Captain, the vessel at Sector %s")
%
w)
prout(_(" has just lost its firepower.\""))
game.kpower[kk] = -kpow
kk += 1
prout(_(" has just lost its firepower.\""))
game.kpower[kk] = -kpow
kk += 1
@@
-3089,7
+3089,13
@@
def kaboom():
def killrate():
"Compute our rate of kils over time."
def killrate():
"Compute our rate of kils over time."
- return ((game.inkling + game.incom + game.inscom) - (game.state.remkl + game.state.remcom + game.state.nscrem))/(game.state.date-game.indate)
+ elapsed = game.state.date - game.indate
+ if elapsed == 0: # Avoid divide-by-zero error if calculated on turn 0
+ return 0
+ else:
+ starting = (game.inkling + game.incom + game.inscom)
+ remaining = (game.state.remkl + game.state.remcom + game.state.nscrem)
+ return (starting - remaining)/elapsed
def badpoints():
"Compute demerits."
def badpoints():
"Compute demerits."
@@
-3490,7
+3496,7
@@
def iostart():
#textdomain(PACKAGE)
if atexit.register(outro):
sys.stderr.write("Unable to register outro(), exiting...\n")
#textdomain(PACKAGE)
if atexit.register(outro):
sys.stderr.write("Unable to register outro(), exiting...\n")
- os.exit(1)
+ raise SysExit,1
if not (game.options & OPTION_CURSES):
ln_env = os.getenv("LINES")
if ln_env:
if not (game.options & OPTION_CURSES):
ln_env = os.getenv("LINES")
if ln_env:
@@
-3925,7
+3931,7
@@
def imove(novapush):
# object encountered in flight path
stopegy = 50.0*game.dist/game.optime
game.dist = distance(game.sector, w) / (QUADSIZE * 1.0)
# object encountered in flight path
stopegy = 50.0*game.dist/game.optime
game.dist = distance(game.sector, w) / (QUADSIZE * 1.0)
- if iquad in (IHT, IHK,
O
HC, IHS, IHR, IHQUEST):
+ if iquad in (IHT, IHK,
I
HC, IHS, IHR, IHQUEST):
game.sector = w
ram(False, iquad, game.sector)
final = game.sector
game.sector = w
ram(False, iquad, game.sector)
final = game.sector
@@
-6590,7
+6596,7
@@
def makemoves():
elif cmd == "EMEXIT": # Emergency exit
clrscr() # Hide screen
freeze(True) # forced save
elif cmd == "EMEXIT": # Emergency exit
clrscr() # Hide screen
freeze(True) # forced save
-
os.exit(1)
# And quick exit
+
raise SysExit,1
# And quick exit
elif cmd == "PROBE":
probe() # Launch probe
if game.ididit:
elif cmd == "PROBE":
probe() # Launch probe
if game.ididit:
@@
-6880,16
+6886,17
@@
if __name__ == '__main__':
for (switch, val) in options:
if switch == '-r':
try:
for (switch, val) in options:
if switch == '-r':
try:
- replayfp = open(
optarg
, "r")
+ replayfp = open(
val
, "r")
except IOError:
except IOError:
- sys.stderr.write("sst: can't open replay file %s\n" %
optarg
)
- os.exit(1)
+ sys.stderr.write("sst: can't open replay file %s\n" %
val
)
+ raise SysExit, 1
line = replayfp.readline().strip()
try:
(key, seed) = line.split()
seed = int(seed)
line = replayfp.readline().strip()
try:
(key, seed) = line.split()
seed = int(seed)
+ sys.stderr.write("sst2k: seed set to %d\n" % seed)
except ValueError:
except ValueError:
- sys.stderr.write("sst: replay file %s is ill-formed\n"%
optarg
)
+ sys.stderr.write("sst: replay file %s is ill-formed\n"%
val
)
os.exit(1)
game.options |= OPTION_TTY
game.options &=~ OPTION_CURSES
os.exit(1)
game.options |= OPTION_TTY
game.options &=~ OPTION_CURSES
@@
-6933,6
+6940,7
@@
if __name__ == '__main__':
if ja() == True:
chew2()
freeze(False)
if ja() == True:
chew2()
freeze(False)
+ chew()
proutn(_("Do you want to play again? "))
if not ja():
break
proutn(_("Do you want to play again? "))
if not ja():
break