projects
/
super-star-trek.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add fix and regression test for capture and cloak.
[super-star-trek.git]
/
sst.py
diff --git
a/sst.py
b/sst.py
index a4ed80e97f5d5b29f23421e7846f9b4fa0816ee2..c36f13771ac008df35b5ae4aefd8c968e7711247 100755
(executable)
--- a/
sst.py
+++ b/
sst.py
@@
-21,6
+21,13
@@
try:
except ImportError:
pass
except ImportError:
pass
+# Prevent lossage under Python 3
+try:
+ my_input = raw_input
+except NameError:
+ my_input = input
+
+
version = "2.1"
docpath = (".", "doc/", "/usr/share/doc/sst/")
version = "2.1"
docpath = (".", "doc/", "/usr/share/doc/sst/")
@@
-943,12
+950,12
@@
def cloak():
return
else:
if not game.iscloaked:
return
else:
if not game.iscloaked:
- proutn(_("Switch cloaking device on?"))
+ proutn(_("Switch cloaking device on?
"))
if not ja():
return
action = "CLON"
else:
if not ja():
return
action = "CLON"
else:
- proutn(_("Switch cloaking device off?"))
+ proutn(_("Switch cloaking device off?
"))
if not ja():
return
action = "CLOFF"
if not ja():
return
action = "CLOFF"
@@
-961,7
+968,7
@@
def cloak():
if not ja():
return;
prout("Engineer Scott- \"Aye, Sir.\"");
if not ja():
return;
prout("Engineer Scott- \"Aye, Sir.\"");
- game.iscloaked = F
ALSE
;
+ game.iscloaked = F
alse
;
if game.irhere and game.state.date >= ALGERON and not game.isviolreported:
prout(_("The Romulan ship discovers you are breaking the Treaty of Algeron!"))
game.ncviol += 1
if game.irhere and game.state.date >= ALGERON and not game.isviolreported:
prout(_("The Romulan ship discovers you are breaking the Treaty of Algeron!"))
game.ncviol += 1
@@
-971,7
+978,7
@@
def cloak():
return;
if action == "CLON":
return;
if action == "CLON":
- if damage(DCLOAK):
+ if damage
d
(DCLOAK):
prout(_("Engineer Scott- \"The cloaking device is damaged, Sir.\""))
return;
prout(_("Engineer Scott- \"The cloaking device is damaged, Sir.\""))
return;
@@
-979,9
+986,9
@@
def cloak():
prout(_("You cannot cloak while docked."))
if game.state.date >= ALGERON and not game.isviolreported:
prout(_("You cannot cloak while docked."))
if game.state.date >= ALGERON and not game.isviolreported:
- prout(_("Spock- \"Captain, using the cloaking device is
be
a violation"))
+ prout(_("Spock- \"Captain, using the cloaking device is a violation"))
prout(_(" of the Treaty of Algeron. Considering the alternatives,"))
prout(_(" of the Treaty of Algeron. Considering the alternatives,"))
- proutn(
" are you sure this is wise?");
+ proutn(
_(" are you sure this is wise? "))
if not ja():
return
prout(_("Engineer Scott- \"Cloaking device has engaging, Sir...\""))
if not ja():
return
prout(_("Engineer Scott- \"Cloaking device has engaging, Sir...\""))
@@
-2111,7
+2118,7
@@
def capture():
# Nah, just select the weakest one since it is most likely to
# surrender (Tom Almy mod)
klingons = [e for e in game.enemies if e.type == 'K']
# Nah, just select the weakest one since it is most likely to
# surrender (Tom Almy mod)
klingons = [e for e in game.enemies if e.type == 'K']
- weakest = sorted(klingons, key=lambda e: e.power)
+ weakest = sorted(klingons, key=lambda e: e.power)
[0]
game.optime = 0.05 # This action will take some time
game.ididit = True # So any others can strike back
game.optime = 0.05 # This action will take some time
game.ididit = True # So any others can strike back
@@
-2120,20
+2127,22
@@
def capture():
# intelligent design
# x = 300 + 25*skill;
x = game.energy / (weakest.power * len(klingons))
# intelligent design
# x = 300 + 25*skill;
x = game.energy / (weakest.power * len(klingons))
- x *= 2.5; # would originally have been equivalent of 1.4,
+ #prout(_("Stats: energy = %s, kpower = %s, klingons = %s")
+ # % (game.energy, weakest.power, len(klingons)))
+ x *= 2.5 # would originally have been equivalent of 1.4,
# but we want command to work more often, more humanely */
# but we want command to work more often, more humanely */
- #prout(_("Prob = %
d (%.4f)\n", i,
x))
+ #prout(_("Prob = %
.4f" %
x))
# x = 100; // For testing, of course!
# x = 100; // For testing, of course!
- if x
>
randreal(100):
+ if x
<
randreal(100):
# guess what, he surrendered!!! */
prout(_("Klingon captain at %s surrenders.") % weakest.location)
i = randreal(200)
if i > 0:
# guess what, he surrendered!!! */
prout(_("Klingon captain at %s surrenders.") % weakest.location)
i = randreal(200)
if i > 0:
- prout(_("%d Klingons commit suicide rather than be taken captive.") %
200 - i
)
- if i > brigfree:
- prout(_("%d Klingons die because there is no room for them in the brig.") %
i-brigfree
)
- i = brigfree
- brigfree -= i
+ prout(_("%d Klingons commit suicide rather than be taken captive.") %
(200 - i)
)
+ if i >
game.
brigfree:
+ prout(_("%d Klingons die because there is no room for them in the brig.") %
(i-brigfree)
)
+ i =
game.
brigfree
+
game.
brigfree -= i
prout(_("%d captives taken") % i)
deadkl(weakest.location, weakest.type, game.sector)
if (game.state.remkl + len(game.state.kcmdr) + game.state.nscrem)<=0:
prout(_("%d captives taken") % i)
deadkl(weakest.location, weakest.type, game.sector)
if (game.state.remkl + len(game.state.kcmdr) + game.state.nscrem)<=0:
@@
-2141,7
+2150,7
@@
def capture():
return
# big surprise, he refuses to surrender */
return
# big surprise, he refuses to surrender */
-
prout(_("Fat chance, captain!"))
+ prout(_("Fat chance, captain!"))
# Code from events.c begins here.
# Code from events.c begins here.
@@
-2362,7
+2371,7
@@
def events():
if game.state.galaxy[game.quadrant.i][game.quadrant.j].supernova:
return
elif evcode == FSPY: # Check with spy to see if SC should tractor beam
if game.state.galaxy[game.quadrant.i][game.quadrant.j].supernova:
return
elif evcode == FSPY: # Check with spy to see if SC should tractor beam
- if game.state.nscrem == 0 or game.
state.
iscloaked or \
+ if game.state.nscrem == 0 or game.iscloaked or \
ictbeam or istract or \
game.condition == "docked" or game.isatb == 1 or game.iscate:
return
ictbeam or istract or \
game.condition == "docked" or game.isatb == 1 or game.iscate:
return
@@
-3156,6
+3165,7
@@
def finish(ifin):
prout(_("to think about pigeons."))
game.gamewon = True
score()
prout(_("to think about pigeons."))
game.gamewon = True
score()
+ scanner.chew() # Clean up leftovers
def score():
"Compute player's score."
def score():
"Compute player's score."
@@
-3403,7
+3413,7
@@
def pause_game():
sys.stdout.write('\n')
proutn(prompt)
if not replayfp:
sys.stdout.write('\n')
proutn(prompt)
if not replayfp:
- input()
+
my_
input()
sys.stdout.write('\n' * rows)
linecount = 0
sys.stdout.write('\n' * rows)
linecount = 0
@@
-3475,7
+3485,11
@@
def cgetline():
elif linein[0] != "#":
break
else:
elif linein[0] != "#":
break
else:
- linein = eval(input()) + "\n"
+ try:
+ linein = my_input() + "\n"
+ except EOFError:
+ prout("")
+ sys.exit(0)
if logfp:
logfp.write(linein)
return linein
if logfp:
logfp.write(linein)
return linein
@@
-3526,7
+3540,7
@@
def clrscr():
linecount = 0
def textcolor(color=DEFAULT):
linecount = 0
def textcolor(color=DEFAULT):
- if
game.options & OPTION_COLOR
:
+ if
(game.options & OPTION_COLOR) and (game.options & OPTION_CURSES)
:
if color == DEFAULT:
curwnd.attrset(0)
elif color == BLACK:
if color == DEFAULT:
curwnd.attrset(0)
elif color == BLACK:
@@
-3563,7
+3577,7
@@
def textcolor(color=DEFAULT):
curwnd.attron(curses.color_pair(curses.COLOR_WHITE) | curses.A_BOLD)
def highvideo():
curwnd.attron(curses.color_pair(curses.COLOR_WHITE) | curses.A_BOLD)
def highvideo():
- if
game.options & OPTION_COLOR
:
+ if
(game.options & OPTION_COLOR) and (game.options & OPTION_CURSES)
:
curwnd.attron(curses.A_REVERSE)
#
curwnd.attron(curses.A_REVERSE)
#
@@
-5273,6
+5287,8
@@
def sectscan(goodScan, i, j):
"Light up an individual dot in a sector."
if goodScan or (abs(i-game.sector.i)<= 1 and abs(j-game.sector.j) <= 1):
if game.quad[i][j] in ('E', 'F'):
"Light up an individual dot in a sector."
if goodScan or (abs(i-game.sector.i)<= 1 and abs(j-game.sector.j) <= 1):
if game.quad[i][j] in ('E', 'F'):
+ if game.iscloaked:
+ highvideo()
textcolor({"green":GREEN,
"yellow":YELLOW,
"red":RED,
textcolor({"green":GREEN,
"yellow":YELLOW,
"red":RED,
@@
-5286,8
+5302,6
@@
def sectscan(goodScan, i, j):
'R':LIGHTRED,
'T':LIGHTRED,
}.get(game.quad[i][j], DEFAULT))
'R':LIGHTRED,
'T':LIGHTRED,
}.get(game.quad[i][j], DEFAULT))
- if game.iscloaked:
- highvideo()
proutn("%c " % game.quad[i][j])
textcolor(DEFAULT)
else:
proutn("%c " % game.quad[i][j])
textcolor(DEFAULT)
else:
@@
-5856,9
+5870,9
@@
def choose():
game.tourn = game.length = 0
game.thawed = False
game.skill = SKILL_NONE
game.tourn = game.length = 0
game.thawed = False
game.skill = SKILL_NONE
- scanner.chew()
-
#
if not scanner.inqueue: # Can start with command line options
- proutn(_("Would you like a regular, tournament, or saved game? "))
+ # Do not chew here, we want to use command-line tokens
+ if not scanner.inqueue: # Can start with command line options
+
proutn(_("Would you like a regular, tournament, or saved game? "))
scanner.nexttok()
if scanner.sees("tournament"):
while scanner.nexttok() == "IHEOL":
scanner.nexttok()
if scanner.sees("tournament"):
while scanner.nexttok() == "IHEOL":
@@
-6359,6
+6373,8
@@
def makemoves():
hitme = True
elif cmd == "CAPTURE":
capture()
hitme = True
elif cmd == "CAPTURE":
capture()
+ elif cmd == "CLOAK":
+ cloak()
elif cmd == "DEBUGCMD": # What do we want for debug???
debugme()
elif cmd == "MAYDAY": # Call for help
elif cmd == "DEBUGCMD": # What do we want for debug???
debugme()
elif cmd == "MAYDAY": # Call for help