2 sst.py =-- Super Star Trek in Python
4 This code is a Python translation of a C translation of a FORTRAN original.
5 The FORTRANness still shows in many ways, notably the use of 1-origin index
6 an a lot of parallel arrays where a more modern language would use structures
9 import os, sys, math, curses, time
11 SSTDOC = "/usr/share/doc/sst/sst.doc"
14 def _(str): return str
18 NINHAB = (GALSIZE * GALSIZE / 2)
20 PLNETMAX = (NINHAB + MAXUNINHAB)
22 BASEMAX = (GALSIZE * GALSIZE / 12)
25 FULLCREW = 428 # BSD Trek was 387, that's wrong
28 # These functions hide the difference between 0-origin and 1-origin addressing.
29 def VALID_QUADRANT(x, y): return ((x)>=1 and (x)<=GALSIZE and (y)>=1 and (y)<=GALSIZE)
30 def VALID_SECTOR(x, y): return ((x)>=1 and (x)<=QUADSIZE and (y)>=1 and (y)<=QUADSIZE)
32 def square(i): return ((i)*(i))
33 def distance(c1, c2): return math.sqrt(square(c1.x - c2.x) + square(c1.y - c2.y))
34 def invalidate(w): w.x = w.y = 0
35 def is_valid(w): return (w.x != 0 and w.y != 0)
38 def __init(self, x=None, y=None):
42 self.x = self.y = None
44 return self.x != None and self.y != None
45 def __eq__(self, other):
46 return self.x == other.y and self.x == other.y
47 def __add__(self, other):
48 return coord(self.x+self.x, self.y+self.y)
49 def __sub__(self, other):
50 return coord(self.x-self.x, self.y-self.y)
51 def distance(self, other):
52 return math.sqrt((self.x - other.x)**2 + (self.y - other.y)**2)
54 return coord(self.x / abs(x), self.y / abs(y));
58 return "%d - %d" % (self.x, self.y)
62 self.name = None # string-valued if inhabited
63 self.w = coord() # quadrant located
64 self.pclass = None # could be ""M", "N", "O", or "destroyed"
65 self.crystals = None # could be "mined", "present", "absent"
66 self.known = None # could be "unknown", "known", "shuttle_down"
68 # How to represent features
98 self.status = None # Could be "secure", "distressed", "enslaved"
108 self.snap = False # snapshot taken
109 self.crew = None # crew complement
110 self.remkl = None # remaining klingons
111 self.remcom = None # remaining commanders
112 self.nscrem = None # remaining super commanders
113 self.rembase = None # remaining bases
114 self.starkl = None # destroyed stars
115 self.basekl = None # destroyed bases
116 self.nromrem = None # Romulans remaining
117 self.nplankl = None # destroyed uninhabited planets
118 self.nworldkl = None # destroyed inhabited planets
119 self.planets = [] # Planet information
120 for i in range(PLNETMAX):
121 self.planets.append(planet())
122 self.date = None # stardate
123 self.remres = None # remaining resources
124 self.remtime = None # remaining time
125 self.baseq = [] # Base quadrant coordinates
126 for i in range(BASEMAX+1):
127 self.baseq.append(coord())
128 self.kcmdr = [] # Commander quadrant coordinates
129 for i in range(QUADSIZE+1):
130 self.kcmdr.append(coord())
131 self.kscmdr = coord() # Supercommander quadrant coordinates
132 self.galaxy = [] # The Galaxy (subscript 0 not used)
133 for i in range(GALSIZE+1):
134 self.chart.append([])
135 for j in range(GALSIZE+1):
136 self.galaxy[i].append(quadrant())
137 self.chart = [] # the starchart (subscript 0 not used)
138 for i in range(GALSIZE+1):
139 self.chart.append([])
140 for j in range(GALSIZE+1):
141 self.chart[i].append(page())
145 self.date = None # A real number
146 self.quadrant = None # A coord structure
149 OPTION_ALL = 0xffffffff
150 OPTION_TTY = 0x00000001 # old interface
151 OPTION_CURSES = 0x00000002 # new interface
152 OPTION_IOMODES = 0x00000003 # cover both interfaces
153 OPTION_PLANETS = 0x00000004 # planets and mining
154 OPTION_THOLIAN = 0x00000008 # Tholians and their webs
155 OPTION_THINGY = 0x00000010 # Space Thingy can shoot back
156 OPTION_PROBE = 0x00000020 # deep-space probes
157 OPTION_SHOWME = 0x00000040 # bracket Enterprise in chart
158 OPTION_RAMMING = 0x00000080 # enemies may ram Enterprise
159 OPTION_MVBADDY = 0x00000100 # more enemies can move
160 OPTION_BLKHOLE = 0x00000200 # black hole may timewarp you
161 OPTION_BASE = 0x00000400 # bases have good shields
162 OPTION_WORLDS = 0x00000800 # logic for inhabited worlds
163 OPTION_PLAIN = 0x01000000 # user chose plain game
164 OPTION_ALMY = 0x02000000 # user chose Almy variant
183 NDEVICES= 16 # Number of devices
192 def damaged(dev): return (game.damage[dev] != 0.0)
194 # Define future events
195 FSPY = 0 # Spy event happens always (no future[] entry)
196 # can cause SC to tractor beam Enterprise
197 FSNOVA = 1 # Supernova
198 FTBEAM = 2 # Commander tractor beams Enterprise
199 FSNAP = 3 # Snapshot for time warp
200 FBATTAK = 4 # Commander attacks base
201 FCDBAS = 5 # Commander destroys base
202 FSCMOVE = 6 # Supercommander moves (might attack base)
203 FSCDBAS = 7 # Supercommander destroys base
204 FDSPROB = 8 # Move deep space probe
205 FDISTR = 9 # Emit distress call from an inhabited world
206 FENSLV = 10 # Inhabited word is enslaved */
207 FREPRO = 11 # Klingons build a ship in an enslaved system
211 # abstract out the event handling -- underlying data structures will change
212 # when we implement stateful events
214 def findevent(evtype): return game.future[evtype]
218 self.options = None # Game options
219 self.state = None # A snapshot structure
220 self.snapsht = None # Last snapshot taken for time-travel purposes
221 self.quad = [[IHDOT * (QUADSIZE+1)] * (QUADSIZE+1)] # contents of our quadrant
222 self.kpower = [[0 * (QUADSIZE+1)] * (QUADSIZE+1)] # enemy energy levels
223 self.kdist = [[0 * (QUADSIZE+1)] * (QUADSIZE+1)] # enemy distances
224 self.kavgd = [[0 * (QUADSIZE+1)] * (QUADSIZE+1)] # average distances
225 self.damage = [0] * NDEVICES # damage encountered
226 self.future = [0.0] * NEVENTS # future events
227 for i in range(NEVENTS):
228 self.future.append(event())
229 self.passwd = None; # Self Destruct password
230 self.ks = [[None * (QUADSIZE+1)] * (QUADSIZE+1)] # enemy sector locations
231 self.quadrant = None # where we are in the large
232 self.sector = None # where we are in the small
233 self.tholian = None # coordinates of Tholian
234 self.base = None # position of base in current quadrant
235 self.battle = None # base coordinates being attacked
236 self.plnet = None # location of planet in quadrant
237 self.probec = None # current probe quadrant
238 self.gamewon = False # Finished!
239 self.ididit = False # action taken -- allows enemy to attack
240 self.alive = False # we are alive (not killed)
241 self.justin = False # just entered quadrant
242 self.shldup = False # shields are up
243 self.shldchg = False # shield is changing (affects efficiency)
244 self.comhere = False # commander here
245 self.ishere = False # super-commander in quadrant
246 self.iscate = False # super commander is here
247 self.ientesc = False # attempted escape from supercommander
248 self.ithere = False # Tholian is here
249 self.resting = False # rest time
250 self.icraft = False # Kirk in Galileo
251 self.landed = False # party on planet (true), on ship (false)
252 self.alldone = False # game is now finished
253 self.neutz = False # Romulan Neutral Zone
254 self.isarmed = False # probe is armed
255 self.inorbit = False # orbiting a planet
256 self.imine = False # mining
257 self.icrystl = False # dilithium crystals aboard
258 self.iseenit = False # seen base attack report
259 self.thawed = False # thawed game
260 self.condition = None # "green", "yellow", "red", "docked", "dead"
261 self.iscraft = None # "onship", "offship", "removed"
262 self.skill = None # Player skill level
263 self.inkling = 0 # initial number of klingons
264 self.inbase = 0 # initial number of bases
265 self.incom = 0 # initial number of commanders
266 self.inscom = 0 # initial number of commanders
267 self.inrom = 0 # initial number of commanders
268 self.instar = 0 # initial stars
269 self.intorps = 0 # initial/max torpedoes
270 self.torps = 0 # number of torpedoes
271 self.ship = 0 # ship type -- 'E' is Enterprise
272 self.abandoned = 0 # count of crew abandoned in space
273 self.length = 0 # length of game
274 self.klhere = 0 # klingons here
275 self.casual = 0 # causalties
276 self.nhelp = 0 # calls for help
277 self.nkinks = 0 # count of energy-barrier crossings
278 self.iplnet = 0 # planet # in quadrant
279 self.inplan = 0 # initial planets
280 self.nenhere = 0 # number of enemies in quadrant
281 self.irhere = 0 # Romulans in quadrant
282 self.isatb = 0 # =1 if super commander is attacking base
283 self.tourn = 0 # tournament number
284 self.proben = 0 # number of moves for probe
285 self.nprobes = 0 # number of probes available
286 self.inresor = 0.0 # initial resources
287 self.intime = 0.0 # initial time
288 self.inenrg = 0.0 # initial/max energy
289 self.inshld = 0.0 # initial/max shield
290 self.inlsr = 0.0 # initial life support resources
291 self.indate = 0.0 # initial date
292 self.energy = 0.0 # energy level
293 self.shield = 0.0 # shield level
294 self.warpfac = 0.0 # warp speed
295 self.wfacsq = 0.0 # squared warp factor
296 self.lsupres = 0.0 # life support reserves
297 self.dist = 0.0 # movement distance
298 self.direc = 0.0 # movement direction
299 self.optime = 0.0 # time taken by current operation
300 self.docfac = 0.0 # repair factor when docking (constant?)
301 self.damfac = 0.0 # damage factor
302 self.lastchart = 0.0 # time star chart was last updated
303 self.cryprob = 0.0 # probability that crystal will work
304 self.probex = 0.0 # location of probe
306 self.probeinx = 0.0 # probe x,y increment
307 self.probeiny = 0.0 #
308 self.height = 0.0 # height of orbit around planet
310 # Stas thinks this should be (C expression):
311 # game.state.remkl + game.state.remcom > 0 ?
312 # game.state.remres/(game.state.remkl + 4*game.state.remcom) : 99
313 # He says the existing expression is prone to divide-by-zero errors
314 # after killing the last klingon when score is shown -- perhaps also
315 # if the only remaining klingon is SCOM.
316 game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom)
317 # From enumerated type 'feature'
338 # From enumerated type 'FINTYPE'
362 # From enumerated type 'COLORS'
381 # Code from ai.c begins here
383 def tryexit(look, ienm, loccom, irun):
384 # a bad guy attempts to bug out
386 iq.x = game.quadrant.x+(look.x+(QUADSIZE-1))/QUADSIZE - 1
387 iq.y = game.quadrant.y+(look.y+(QUADSIZE-1))/QUADSIZE - 1
388 if not VALID_QUADRANT(iq.x,iq.y) or \
389 game.state.galaxy[iq.x][iq.y].supernova or \
390 game.state.galaxy[iq.x][iq.y].klingons > MAXKLQUAD-1:
391 return False; # no can do -- neg energy, supernovae, or >MAXKLQUAD-1 Klingons
393 return False; # Romulans cannot escape!
395 # avoid intruding on another commander's territory
397 for n in range(1, game.state.remcom+1):
398 if same(game.state.kcmdr[n],iq):
400 # refuse to leave if currently attacking starbase
401 if same(game.battle, game.quadrant):
403 # don't leave if over 1000 units of energy
404 if game.kpower[loccom] > 1000.0:
406 # print escape message and move out of quadrant.
407 # we know this if either short or long range sensors are working
408 if not damaged(DSRSENS) or not damaged(DLRSENS) or \
409 game.condition == docked:
410 crmena(True, ienm, "sector", game.ks[loccom])
411 prout(_(" escapes to Quadrant %s (and regains strength).") % q)
412 # handle local matters related to escape
413 game.quad[game.ks[loccom].x][game.ks[loccom].y] = IHDOT
414 game.ks[loccom] = game.ks[game.nenhere]
415 game.kavgd[loccom] = game.kavgd[game.nenhere]
416 game.kpower[loccom] = game.kpower[game.nenhere]
417 game.kdist[loccom] = game.kdist[game.nenhere]
420 if game.condition != docked:
422 # Handle global matters related to escape
423 game.state.galaxy[game.quadrant.x][game.quadrant.y].klingons -= 1
424 game.state.galaxy[iq.x][iq.y].klingons += 1
430 schedule(FSCMOVE, 0.2777)
434 for n in range(1, game.state.remcom+1):
435 if same(game.state.kcmdr[n], game.quadrant):
436 game.state.kcmdr[n]=iq
439 return True; # success
442 # The bad-guy movement algorithm:
444 # 1. Enterprise has "force" based on condition of phaser and photon torpedoes.
445 # If both are operating full strength, force is 1000. If both are damaged,
446 # force is -1000. Having shields down subtracts an additional 1000.
448 # 2. Enemy has forces equal to the energy of the attacker plus
449 # 100*(K+R) + 500*(C+S) - 400 for novice through good levels OR
450 # 346*K + 400*R + 500*(C+S) - 400 for expert and emeritus.
452 # Attacker Initial energy levels (nominal):
453 # Klingon Romulan Commander Super-Commander
454 # Novice 400 700 1200
456 # Good 450 800 1300 1750
457 # Expert 475 850 1350 1875
458 # Emeritus 500 900 1400 2000
459 # VARIANCE 75 200 200 200
461 # Enemy vessels only move prior to their attack. In Novice - Good games
462 # only commanders move. In Expert games, all enemy vessels move if there
463 # is a commander present. In Emeritus games all enemy vessels move.
465 # 3. If Enterprise is not docked, an aggressive action is taken if enemy
466 # forces are 1000 greater than Enterprise.
468 # Agressive action on average cuts the distance between the ship and
469 # the enemy to 1/4 the original.
471 # 4. At lower energy advantage, movement units are proportional to the
472 # advantage with a 650 advantage being to hold ground, 800 to move forward
473 # 1, 950 for two, 150 for back 4, etc. Variance of 100.
475 # If docked, is reduced by roughly 1.75*game.skill, generally forcing a
476 # retreat, especially at high skill levels.
478 # 5. Motion is limited to skill level, except for SC hi-tailing it out.
481 def movebaddy(com, loccom, ienm):
482 # tactical movement for the bad guys
483 next = coord(); look = coord()
485 # This should probably be just game.comhere + game.ishere
486 if game.skill >= SKILL_EXPERT:
487 nbaddys = ((game.comhere*2 + game.ishere*2+game.klhere*1.23+game.irhere*1.5)/2.0)
489 nbaddys = game.comhere + game.ishere
491 dist1 = game.kdist[loccom]
492 mdist = int(dist1 + 0.5); # Nearest integer distance
494 # If SC, check with spy to see if should hi-tail it
496 (game.kpower[loccom] <= 500.0 or (game.condition=="docked" and not damaged(DPHOTON))):
500 # decide whether to advance, retreat, or hold position
501 forces = game.kpower[loccom]+100.0*game.nenhere+400*(nbaddys-1)
503 forces += 1000; # Good for enemy if shield is down!
504 if not damaged(DPHASER) or not damaged(DPHOTON):
505 if damaged(DPHASER): # phasers damaged
508 forces -= 0.2*(game.energy - 2500.0)
509 if damaged(DPHOTON): # photon torpedoes damaged
512 forces -= 50.0*game.torps
514 # phasers and photon tubes both out!
517 if forces <= 1000.0 and game.condition != "docked": # Typical situation
518 motion = ((forces+200.0*Rand())/150.0) - 5.0
520 if forces > 1000.0: # Very strong -- move in for kill
521 motion = (1.0-square(Rand()))*dist1 + 1.0
522 if game.condition=="docked" and (game.options & OPTION_BASE): # protected by base -- back off !
523 motion -= game.skill*(2.0-square(Rand()))
525 proutn("=== MOTION = %d, FORCES = %1.2f, " % (motion, forces))
526 # don't move if no motion
529 # Limit motion according to skill
530 if abs(motion) > game.skill:
535 # calculate preferred number of steps
540 if motion > 0 and nsteps > mdist:
541 nsteps = mdist; # don't overshoot
542 if nsteps > QUADSIZE:
543 nsteps = QUADSIZE; # This shouldn't be necessary
545 nsteps = 1; # This shouldn't be necessary
547 proutn("NSTEPS = %d:" % nsteps)
548 # Compute preferred values of delta X and Y
549 mx = game.sector.x - com.x
550 my = game.sector.y - com.y
551 if 2.0 * abs(mx) < abs(my):
553 if 2.0 * abs(my) < abs(game.sector.x-com.x):
567 for ll in range(nsteps):
569 proutn(" %d" % (ll+1))
570 # Check if preferred position available
582 attempts = 0; # Settle mysterious hang problem
583 while attempts < 20 and not success:
585 if look.x < 1 or look.x > QUADSIZE:
586 if motion < 0 and tryexit(look, ienm, loccom, irun):
588 if krawlx == mx or my == 0:
590 look.x = next.x + krawlx
592 elif look.y < 1 or look.y > QUADSIZE:
593 if motion < 0 and tryexit(look, ienm, loccom, irun):
595 if krawly == my or mx == 0:
597 look.y = next.y + krawly
599 elif (game.options & OPTION_RAMMING) and game.quad[look.x][look.y] != IHDOT:
600 # See if we should ram ship
601 if game.quad[look.x][look.y] == game.ship and \
602 (ienm == IHC or ienm == IHS):
605 if krawlx != mx and my != 0:
606 look.x = next.x + krawlx
608 elif krawly != my and mx != 0:
609 look.y = next.y + krawly
612 break; # we have failed
624 # Put commander in place within same quadrant
625 game.quad[com.x][com.y] = IHDOT
626 game.quad[next.x][next.y] = ienm
627 if not same(next, com):
629 game.ks[loccom] = next
630 game.kdist[loccom] = game.kavgd[loccom] = distance(game.sector, next)
631 if not damaged(DSRSENS) or game.condition == docked:
634 proutn(_(" from Sector %s") % com)
635 if game.kdist[loccom] < dist1:
636 proutn(_(" advances to "))
638 proutn(_(" retreats to "))
639 prout("Sector %s." % next)
642 # Klingon tactical movement
645 # Figure out which Klingon is the commander (or Supercommander)
648 for i in range(1, game.nenhere+1):
650 if game.quad[w.x][w.y] == IHC:
654 for i in range(1, game.nenhere+1):
656 if game.quad[w.x][w.y] == IHS:
659 # If skill level is high, move other Klingons and Romulans too!
660 # Move these last so they can base their actions on what the
662 if game.skill >= SKILL_EXPERT and (game.options & OPTION_MVBADDY):
663 for i in range(1, game.nenhere+1):
665 if game.quad[w.x][w.y] == IHK or game.quad[w.x][w.y] == IHR:
666 movebaddy(w, i, game.quad[w.x][w.y])
669 def movescom(iq, avoid):
670 # commander movement helper
671 if same(iq, game.quadrant) or not VALID_QUADRANT(iq.x, iq.y) or \
672 game.state.galaxy[iq.x][iq.y].supernova or \
673 game.state.galaxy[iq.x][iq.y].klingons > MAXKLQUAD-1:
676 # Avoid quadrants with bases if we want to avoid Enterprise
677 for i in range(1, game.state.rembase+1):
678 if same(game.state.baseq[i], iq):
680 if game.justin and not game.iscate:
683 game.state.galaxy[game.state.kscmdr.x][game.state.kscmdr.y].klingons -= 1
684 game.state.kscmdr = iq
685 game.state.galaxy[game.state.kscmdr.x][game.state.kscmdr.y].klingons += 1
687 # SC has scooted, Remove him from current quadrant
693 for i in range(1, game.nenhere+1):
694 if game.quad[game.ks[i].x][game.ks[i].y] == IHS:
696 game.quad[game.ks[i].x][game.ks[i].y] = IHDOT
697 game.ks[i] = game.ks[game.nenhere]
698 game.kdist[i] = game.kdist[game.nenhere]
699 game.kavgd[i] = game.kavgd[game.nenhere]
700 game.kpower[i] = game.kpower[game.nenhere]
703 if game.condition!=docked:
706 # check for a helpful planet
707 for i in range(game.inplan):
708 if same(game.state.planets[i].w, game.state.kscmdr) and \
709 game.state.planets[i].crystals == present:
711 game.state.planets[i].pclass = destroyed
712 game.state.galaxy[game.state.kscmdr.x][game.state.kscmdr.y].planet = NOPLANET
713 if not damaged(DRADIO) or game.condition == docked:
715 prout(_("Lt. Uhura- \"Captain, Starfleet Intelligence reports"))
716 proutn(_(" a planet in Quadrant %s has been destroyed") % game.state.kscmdr)
717 prout(_(" by the Super-commander.\""))
719 return False; # looks good!
721 def supercommander():
722 # move the Super Commander
723 iq = coord(); sc = coord(); ibq = coord(); idelta = coord()
726 prout("== SUPERCOMMANDER")
727 # Decide on being active or passive
728 avoid = ((game.incom - game.state.remcom + game.inkling - game.state.remkl)/(game.state.date+0.01-game.indate) < 0.1*game.skill*(game.skill+1.0) or \
729 (game.state.date-game.indate) < 3.0)
730 if not game.iscate and avoid:
731 # compute move away from Enterprise
732 idelta = game.state.kscmdr-game.quadrant
733 if math.sqrt(idelta.x*idelta.x+idelta.y*idelta.y) > 2.0:
735 idelta.x = game.state.kscmdr.y-game.quadrant.y
736 idelta.y = game.quadrant.x-game.state.kscmdr.x
738 # compute distances to starbases
739 if game.state.rembase <= 0:
743 sc = game.state.kscmdr
744 for i in range(1, game.state.rembase+1):
745 basetbl.append((i, distance(game.state.baseq[i], sc)))
746 if game.state.rembase > 1:
747 basetbl.sort(lambda x, y: cmp(x[1]. y[1]))
748 # look for nearest base without a commander, no Enterprise, and
749 # without too many Klingons, and not already under attack.
750 ifindit = iwhichb = 0
751 for i2 in range(1, game.state.rembase+1):
752 i = basetbl[i2][0]; # bug in original had it not finding nearest
753 ibq = game.state.baseq[i]
754 if same(ibq, game.quadrant) or same(ibq, game.battle) or \
755 game.state.galaxy[ibq.x][ibq.y].supernova or \
756 game.state.galaxy[ibq.x][ibq.y].klingons > MAXKLQUAD-1:
758 # if there is a commander, and no other base is appropriate,
759 # we will take the one with the commander
760 for j in range(1, game.state.remcom+1):
761 if same(ibq, game.state.kcmdr[j]) and ifindit!= 2:
765 if j > game.state.remcom: # no commander -- use this one
770 return; # Nothing suitable -- wait until next time
771 ibq = game.state.baseq[iwhichb]
772 # decide how to move toward base
773 idelta = ibq - game.state.kscmdr
774 # Maximum movement is 1 quadrant in either or both axes
775 idelta = idelta.sgn()
776 # try moving in both x and y directions
777 # there was what looked like a bug in the Almy C code here,
778 # but it might be this translation is just wrong.
779 iq = game.state.kscmdr + idelta
780 if movescom(iq, avoid):
781 # failed -- try some other maneuvers
782 if idelta.x==0 or idelta.y==0:
785 iq.y = game.state.kscmdr.y + 1
786 if movescom(iq, avoid):
787 iq.y = game.state.kscmdr.y - 1
790 iq.x = game.state.kscmdr.x + 1
791 if movescom(iq, avoid):
792 iq.x = game.state.kscmdr.x - 1
795 # try moving just in x or y
796 iq.y = game.state.kscmdr.y
797 if movescom(iq, avoid):
798 iq.y = game.state.kscmdr.y + idelta.y
799 iq.x = game.state.kscmdr.x
802 if game.state.rembase == 0:
805 for i in range(1, game.state.rembase+1):
806 ibq = game.state.baseq[i]
807 if same(ibq, game.state.kscmdr) and same(game.state.kscmdr, game.battle):
810 return; # no, don't attack base!
813 schedule(FSCDBAS, 1.0 +2.0*Rand())
814 if is_scheduled(FCDBAS):
815 postpone(FSCDBAS, scheduled(FCDBAS)-game.state.date)
816 if damaged(DRADIO) and game.condition != docked:
820 prout(_("Lt. Uhura- \"Captain, the starbase in Quadrant %s") \
822 prout(_(" reports that it is under attack from the Klingon Super-commander."))
823 proutn(_(" It can survive until stardate %d.\"") \
824 % int(scheduled(FSCDBAS)))
827 prout(_("Mr. Spock- \"Captain, shall we cancel the rest period?\""))
831 game.optime = 0.0; # actually finished
833 # Check for intelligence report
836 (damaged(DRADIO) and game.condition != docked) or \
837 not game.state.galaxy[game.state.kscmdr.x][game.state.kscmdr.y].charted):
840 prout(_("Lt. Uhura- \"Captain, Starfleet Intelligence reports"))
841 proutn(_(" the Super-commander is in Quadrant %s,") % game.state.kscmdr)
846 if not game.ithere or game.justin:
849 if game.tholian.x == 1 and game.tholian.y == 1:
850 idx = 1; idy = QUADSIZE
851 elif game.tholian.x == 1 and game.tholian.y == QUADSIZE:
852 idx = QUADSIZE; idy = QUADSIZE
853 elif game.tholian.x == QUADSIZE and game.tholian.y == QUADSIZE:
854 idx = QUADSIZE; idy = 1
855 elif game.tholian.x == QUADSIZE and game.tholian.y == 1:
858 # something is wrong!
862 # do nothing if we are blocked
863 if game.quad[idx][idy]!= IHDOT and game.quad[idx][idy]!= IHWEB:
865 game.quad[game.tholian.x][game.tholian.y] = IHWEB
867 if game.tholian.x != idx:
869 im = math.fabs(idx - game.tholian.x)*1.0/(idx - game.tholian.x)
870 while game.tholian.x != idx:
872 if game.quad[game.tholian.x][game.tholian.y]==IHDOT:
873 game.quad[game.tholian.x][game.tholian.y] = IHWEB
874 elif game.tholian.y != idy:
876 im = math.fabs(idy - game.tholian.y)*1.0/(idy - game.tholian.y)
877 while game.tholian.y != idy:
879 if game.quad[game.tholian.x][game.tholian.y]==IHDOT:
880 game.quad[game.tholian.x][game.tholian.y] = IHWEB
881 game.quad[game.tholian.x][game.tholian.y] = IHT
882 game.ks[game.nenhere] = game.tholian
884 # check to see if all holes plugged
885 for i in range(1, QUADSIZE+1):
886 if game.quad[1][i]!=IHWEB and game.quad[1][i]!=IHT:
888 if game.quad[QUADSIZE][i]!=IHWEB and game.quad[QUADSIZE][i]!=IHT:
890 if game.quad[i][1]!=IHWEB and game.quad[i][1]!=IHT:
892 if game.quad[i][QUADSIZE]!=IHWEB and game.quad[i][QUADSIZE]!=IHT:
894 # All plugged up -- Tholian splits
895 game.quad[game.tholian.x][game.tholian.y]=IHWEB
897 crmena(True, IHT, "sector", game.tholian)
898 prout(_(" completes web."))
903 # Code from battle.c begins here
905 def doshield(shraise):
906 # change shield status
919 prout(_("Shields damaged and down."))
926 proutn(_("Do you wish to change shield energy? "))
928 proutn(_("Energy to transfer to shields- "))
930 elif damaged(DSHIELD):
931 prout(_("Shields damaged and down."))
934 proutn(_("Shields are up. Do you want them down? "))
941 proutn(_("Shields are down. Do you want them up? "))
947 if action == "SHUP": # raise shields
949 prout(_("Shields already up."))
953 if game.condition != "docked":
955 prout(_("Shields raised."))
958 prout(_("Shields raising uses up last of energy."))
963 elif action == "SHDN":
965 prout(_("Shields already down."))
969 prout(_("Shields lowered."))
972 elif action == "NRG":
973 while scan() != IHREAL:
975 proutn(_("Energy to transfer to shields- "))
979 if aaitem > game.energy:
980 prout(_("Insufficient ship energy."))
983 if game.shield+aaitem >= game.inshld:
984 prout(_("Shield energy maximized."))
985 if game.shield+aaitem > game.inshld:
986 prout(_("Excess energy requested returned to ship energy"))
987 game.energy -= game.inshld-game.shield
988 game.shield = game.inshld
990 if aaitem < 0.0 and game.energy-aaitem > game.inenrg:
991 # Prevent shield drain loophole
993 prout(_("Engineering to bridge--"))
994 prout(_(" Scott here. Power circuit problem, Captain."))
995 prout(_(" I can't drain the shields."))
998 if game.shield+aaitem < 0:
999 prout(_("All shield energy transferred to ship."))
1000 game.energy += game.shield
1003 proutn(_("Scotty- \""))
1005 prout(_("Transferring energy to shields.\""))
1007 prout(_("Draining energy from shields.\""))
1008 game.shield += aaitem
1009 game.energy -= aaitem
1013 # choose a device to damage, at random.
1015 # Quoth Eric Allman in the code of BSD-Trek:
1016 # "Under certain conditions you can get a critical hit. This
1017 # sort of hit damages devices. The probability that a given
1018 # device is damaged depends on the device. Well protected
1019 # devices (such as the computer, which is in the core of the
1020 # ship and has considerable redundancy) almost never get
1021 # damaged, whereas devices which are exposed (such as the
1022 # warp engines) or which are particularly delicate (such as
1023 # the transporter) have a much higher probability of being
1026 # This is one place where OPTION_PLAIN does not restore the
1027 # original behavior, which was equiprobable damage across
1028 # all devices. If we wanted that, we'd return NDEVICES*Rand()
1029 # and have done with it. Also, in the original game, DNAVYS
1030 # and DCOMPTR were the same device.
1032 # Instead, we use a table of weights similar to the one from BSD Trek.
1033 # BSD doesn't have the shuttle, shield controller, death ray, or probes.
1034 # We don't have a cloaking device. The shuttle got the allocation
1035 # for the cloaking device, then we shaved a half-percent off
1036 # everything to have some weight to give DSHCTRL/DDRAY/DDSP.
1039 105, # DSRSENS: short range scanners 10.5%
1040 105, # DLRSENS: long range scanners 10.5%
1041 120, # DPHASER: phasers 12.0%
1042 120, # DPHOTON: photon torpedoes 12.0%
1043 25, # DLIFSUP: life support 2.5%
1044 65, # DWARPEN: warp drive 6.5%
1045 70, # DIMPULS: impulse engines 6.5%
1046 145, # DSHIELD: deflector shields 14.5%
1047 30, # DRADIO: subspace radio 3.0%
1048 45, # DSHUTTL: shuttle 4.5%
1049 15, # DCOMPTR: computer 1.5%
1050 20, # NAVCOMP: navigation system 2.0%
1051 75, # DTRANSP: transporter 7.5%
1052 20, # DSHCTRL: high-speed shield controller 2.0%
1053 10, # DDRAY: death ray 1.0%
1054 30, # DDSP: deep-space probes 3.0%
1056 idx = Rand() * 1000.0 # weights must sum to 1000
1058 for (i, w) in enumerate(weights):
1062 return None; # we should never get here
1064 def ram(ibumpd, ienm, w):
1065 # make our ship ram something
1066 prouts(_("***RED ALERT! RED ALERT!"))
1068 prout(_("***COLLISION IMMINENT."))
1072 hardness = {IHR:1.5, IHC:2.0, IHS:2.5, IHT:0.5, IHQUEST:4.0}.get(ienm, 1.0)
1074 proutn(_(" rammed by "))
1077 crmena(False, ienm, sector, w)
1079 proutn(_(" (original position)"))
1081 deadkl(w, ienm, game.sector)
1084 prout(_(" heavily damaged."))
1085 icas = 10.0+20.0*Rand()
1086 prout(_("***Sickbay reports %d casualties"), icas)
1088 game.state.crew -= icas
1090 # In the pre-SST2K version, all devices got equiprobably damaged,
1091 # which was silly. Instead, pick up to half the devices at
1092 # random according to our weighting table,
1094 ncrits = Rand() * (NDEVICES/2)
1095 for m in range(ncrits):
1097 if game.damage[dev] < 0:
1099 extradm = (10.0*hardness*Rand()+1.0)*game.damfac
1100 # Damage for at least time of travel!
1101 game.damage[dev] += game.optime + extradm
1103 prout(_("***Shields are down."))
1104 if game.state.remkl + game.state.remcom + game.state.nscrem:
1111 def torpedo(course, r, incoming, i, n):
1112 # let a photon torpedo fly
1115 ac = course + 0.25*r
1116 angle = (15.0-ac)*0.5235988
1117 bullseye = (15.0 - course)*0.5235988
1118 deltax = -math.sin(angle);
1119 deltay = math.cos(angle);
1120 x = incoming.x; y = incoming.y
1121 w = coord(); jw = coord()
1122 w.x = w.y = jw.x = jw.y = 0
1123 bigger = max(math.fabs(deltax), math.fabs(deltay))
1126 if not damaged(DSRSENS) or game.condition=="docked":
1127 setwnd(srscan_window)
1129 setwnd(message_window)
1130 # Loop to move a single torpedo
1131 for l in range(1, 15+1):
1136 if not VALID_SECTOR(w.x, w.y):
1138 iquad=game.quad[w.x][w.y]
1139 tracktorpedo(w, l, i, n, iquad)
1143 setwnd(message_window)
1144 if damaged(DSRSENS) and not game.condition=="docked":
1145 skip(1); # start new line after text track
1146 if iquad in (IHE, IHF): # Hit our ship
1148 proutn(_("Torpedo hits "))
1151 hit = 700.0 + 100.0*Rand() - \
1152 1000.0 * distance(w, incoming) * math.fabs(math.sin(bullseye-angle))
1153 newcnd(); # we're blown out of dock
1154 # We may be displaced.
1155 if game.landed or game.condition=="docked":
1156 return hit # Cheat if on a planet
1157 ang = angle + 2.5*(Rand()-0.5)
1158 temp = math.fabs(math.sin(ang))
1159 if math.fabs(math.cos(ang)) > temp:
1160 temp = math.fabs(math.cos(ang))
1161 xx = -math.sin(ang)/temp
1162 yy = math.cos(ang)/temp
1165 if not VALID_SECTOR(jw.x, jw.y):
1167 if game.quad[jw.x][jw.y]==IHBLANK:
1170 if game.quad[jw.x][jw.y]!=IHDOT:
1171 # can't move into object
1176 elif iquad in (IHC, IHS): # Hit a commander
1178 crmena(True, iquad, sector, w)
1179 prout(_(" uses anti-photon device;"))
1180 prout(_(" torpedo neutralized."))
1182 elif iquad in (IHR, IHK): # Hit a regular enemy
1184 for ll in range(1, game.nenhere+1):
1185 if same(w, game.ks[ll]):
1187 kp = math.fabs(game.kpower[ll])
1188 h1 = 700.0 + 100.0*Rand() - \
1189 1000.0 * distance(w, incoming) * math.fabs(math.sin(bullseye-angle))
1193 if game.kpower[ll] < 0:
1194 game.kpower[ll] -= -h1
1196 game.kpower[ll] -= h1
1197 if game.kpower[ll] == 0:
1200 crmena(True, iquad, "sector", w)
1201 # If enemy damaged but not destroyed, try to displace
1202 ang = angle + 2.5*(Rand()-0.5)
1203 temp = math.fabs(math.sin(ang))
1204 if math.fabs(math.cos(ang)) > temp:
1205 temp = math.fabs(math.cos(ang))
1206 xx = -math.sin(ang)/temp
1207 yy = math.cos(ang)/temp
1210 if not VALID_SECTOR(jw.x, jw.y):
1211 prout(_(" damaged but not destroyed."))
1213 if game.quad[jw.x][jw.y]==IHBLANK:
1214 prout(_(" buffeted into black hole."))
1215 deadkl(w, iquad, jw)
1217 if game.quad[jw.x][jw.y]!=IHDOT:
1218 # can't move into object
1219 prout(_(" damaged but not destroyed."))
1221 proutn(_(" damaged--"))
1225 elif iquad == IHB: # Hit a base
1227 prout(_("***STARBASE DESTROYED.."))
1228 for ll in range(1, game.state.rembase+1):
1229 if same(game.state.baseq[ll], game.quadrant):
1230 game.state.baseq[ll]=game.state.baseq[game.state.rembase]
1232 game.quad[w.x][w.y]=IHDOT
1233 game.state.rembase -= 1
1234 game.base.x=game.base.y=0
1235 game.state.galaxy[game.quadrant.x][game.quadrant.y].starbase -= 1
1236 game.state.chart[game.quadrant.x][game.quadrant.y].starbase -= 1
1237 game.state.basekl += 1
1240 elif iquad == IHP: # Hit a planet
1241 crmena(True, iquad, sector, w)
1242 prout(_(" destroyed."))
1243 game.state.nplankl += 1
1244 game.state.galaxy[game.quadrant.x][game.quadrant.y].planet = NOPLANET
1245 game.state.planets[game.iplnet].pclass = destroyed
1247 invalidate(game.plnet)
1248 game.quad[w.x][w.y] = IHDOT
1250 # captain perishes on planet
1253 elif iquad == IHW: # Hit an inhabited world -- very bad!
1254 crmena(True, iquad, sector, w)
1255 prout(_(" destroyed."))
1256 game.state.nworldkl += 1
1257 game.state.galaxy[game.quadrant.x][game.quadrant.y].planet = NOPLANET
1258 game.state.planets[game.iplnet].pclass = destroyed
1260 invalidate(game.plnet)
1261 game.quad[w.x][w.y] = IHDOT
1263 # captain perishes on planet
1265 prout(_("You have just destroyed an inhabited planet."))
1266 prout(_("Celebratory rallies are being held on the Klingon homeworld."))
1268 elif iquad == IHSTAR: # Hit a star
1272 crmena(True, IHSTAR, sector, w)
1273 prout(_(" unaffected by photon blast."))
1275 elif iquad == IHQUEST: # Hit a thingy
1276 if not (game.options & OPTION_THINGY) or Rand()>0.7:
1278 prouts(_("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!"))
1280 prouts(_(" HACK! HACK! HACK! *CHOKE!* "))
1282 proutn(_("Mr. Spock-"))
1283 prouts(_(" \"Fascinating!\""))
1288 # Stas Sergeev added the possibility that
1289 # you can shove the Thingy and piss it off.
1290 # It then becomes an enemy and may fire at you.
1295 elif iquad == IHBLANK: # Black hole
1297 crmena(True, IHBLANK, sector, w)
1298 prout(_(" swallows torpedo."))
1300 elif iquad == IHWEB: # hit the web
1302 prout(_("***Torpedo absorbed by Tholian web."))
1304 elif iquad == IHT: # Hit a Tholian
1305 h1 = 700.0 + 100.0*Rand() - \
1306 1000.0 * distance(w, incoming) * math.fabs(math.sin(bullseye-angle))
1309 game.quad[w.x][w.y] = IHDOT
1314 crmena(True, IHT, sector, w)
1316 prout(_(" survives photon blast."))
1318 prout(_(" disappears."))
1319 game.quad[w.x][w.y] = IHWEB
1326 proutn("Don't know how to handle torpedo collision with ")
1327 crmena(True, iquad, sector, w)
1331 if curwnd!=message_window:
1332 setwnd(message_window)
1334 game.quad[w.x][w.y]=IHDOT
1335 game.quad[jw.x][jw.y]=iquad
1336 prout(_(" displaced by blast to %s "), cramlc(sector, jw))
1337 for ll in range(1, game.nenhere+1):
1338 game.kdist[ll] = game.kavgd[ll] = distance(game.sector,game.ks[ll])
1342 prout(_("Torpedo missed."))
1346 # critical-hit resolution
1348 # a critical hit occured
1349 if hit < (275.0-25.0*game.skill)*(1.0+0.5*Rand()):
1352 ncrit = 1.0 + hit/(500.0+100.0*Rand())
1353 proutn(_("***CRITICAL HIT--"))
1354 # Select devices and cause damage
1356 for loop1 in range(ncrit):
1359 # Cheat to prevent shuttle damage unless on ship
1360 if not (game.damage[j]<0.0 or (j==DSHUTTL and game.iscraft != "onship")):
1363 extradm = (hit*game.damfac)/(ncrit*(75.0+25.0*Rand()))
1364 game.damage[j] += extradm
1366 for loop2 in range(loop1):
1367 if j == cdam[loop2]:
1376 prout(_(" damaged."))
1377 if damaged(DSHIELD) and game.shldup:
1378 prout(_("***Shields knocked down."))
1381 def attack(torps_ok):
1382 # bad guy attacks us
1383 # torps_ok == false forces use of phasers in an attack
1384 atackd = False; attempt = False; ihurt = False;
1385 hitmax=0.0; hittot=0.0; chgfac=1.0
1389 # game could be over at this point, check
1394 prout("=== ATTACK!")
1396 # Tholian gewts to move before attacking
1400 # if you have just entered the RNZ, you'll get a warning
1401 if game.neutz: # The one chance not to be attacked
1405 # commanders get a chance to tac-move towards you
1406 if (((game.comhere or game.ishere) and not game.justin) or game.skill == SKILL_EMERITUS) and torps_ok:
1409 # if no enemies remain after movement, we're done
1410 if game.nenhere==0 or (game.nenhere==1 and iqhere and not iqengry):
1413 # set up partial hits if attack happens during shield status change
1414 pfac = 1.0/game.inshld
1416 chgfac = 0.25+0.5*Rand()
1420 # message verbosity control
1421 if game.skill <= SKILL_FAIR:
1424 for loop in range(1, game.nenhere+1):
1425 if game.kpower[loop] < 0:
1426 continue; # too weak to attack
1427 # compute hit strength and diminish shield power
1429 # Increase chance of photon torpedos if docked or enemy energy low
1430 if game.condition == "docked":
1432 if game.kpower[loop] < 500:
1435 iquad = game.quad[jay.x][jay.y]
1436 if iquad==IHT or (iquad==IHQUEST and not iqengry):
1438 # different enemies have different probabilities of throwing a torp
1439 usephasers = not torps_ok or \
1440 (iquad == IHK and r > 0.0005) or \
1441 (iquad==IHC and r > 0.015) or \
1442 (iquad==IHR and r > 0.3) or \
1443 (iquad==IHS and r > 0.07) or \
1444 (iquad==IHQUEST and r > 0.05)
1445 if usephasers: # Enemy uses phasers
1446 if game.condition == "docked":
1447 continue; # Don't waste the effort!
1448 attempt = True; # Attempt to attack
1449 dustfac = 0.8+0.05*Rand()
1450 hit = game.kpower[loop]*math.pow(dustfac,game.kavgd[loop])
1451 game.kpower[loop] *= 0.75
1452 else: # Enemy uses photon torpedo
1453 course = 1.90985*math.atan2(game.sector.y-jay.y, jay.x-game.sector.x)
1455 proutn(_("***TORPEDO INCOMING"))
1456 if not damaged(DSRSENS):
1458 crmena(False, iquad, where, jay)
1461 r = (Rand()+Rand())*0.5 -0.5
1462 r += 0.002*game.kpower[loop]*r
1463 hit = torpedo(course, r, jay, 1, 1)
1464 if (game.state.remkl + game.state.remcom + game.state.nscrem)==0:
1465 finish(FWON); # Klingons did themselves in!
1466 if game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova or game.alldone:
1467 return; # Supernova or finished
1470 # incoming phaser or torpedo, shields may dissipate it
1471 if game.shldup or game.shldchg or game.condition=="docked":
1472 # shields will take hits
1473 propor = pfac * game.shield
1474 if game.condition =="docked":
1478 hitsh = propor*chgfac*hit+1.0
1480 if absorb > game.shield:
1481 absorb = game.shield
1482 game.shield -= absorb
1484 # taking a hit blasts us out of a starbase dock
1485 if game.condition == "docked":
1487 # but the shields may take care of it
1488 if propor > 0.1 and hit < 0.005*game.energy:
1490 # hit from this opponent got through shields, so take damage
1492 proutn(_("%d unit hit") % int(hit))
1493 if (damaged(DSRSENS) and usephasers) or game.skill<=SKILL_FAIR:
1494 proutn(_(" on the "))
1496 if not damaged(DSRSENS) and usephasers:
1498 crmena(False, iquad, where, jay)
1500 # Decide if hit is critical
1506 if game.energy <= 0:
1507 # Returning home upon your shield, not with it...
1510 if not attempt and game.condition == "docked":
1511 prout(_("***Enemies decide against attacking your ship."))
1514 percent = 100.0*pfac*game.shield+0.5
1516 # Shields fully protect ship
1517 proutn(_("Enemy attack reduces shield strength to "))
1519 # Print message if starship suffered hit(s)
1521 proutn(_("Energy left %2d shields ") % int(game.energy))
1524 elif not damaged(DSHIELD):
1527 proutn(_("damaged, "))
1528 prout(_("%d%%, torpedoes left %d"), percent, game.torps)
1529 # Check if anyone was hurt
1530 if hitmax >= 200 or hittot >= 500:
1531 icas= hittot*Rand()*0.015
1534 prout(_("Mc Coy- \"Sickbay to bridge. We suffered %d casualties") % icas)
1535 prout(_(" in that last attack.\""))
1537 game.state.crew -= icas
1538 # After attack, reset average distance to enemies
1539 for loop in range(1, game.nenhere+1):
1540 game.kavgd[loop] = game.kdist[loop]
1544 def deadkl(w, type, mv):
1545 # kill a Klingon, Tholian, Romulan, or Thingy
1546 # Added mv to allow enemy to "move" before dying
1548 crmena(True, type, sector, mv)
1549 # Decide what kind of enemy it is and update appropriately
1551 # chalk up a Romulan
1552 game.state.galaxy[game.quadrant.x][game.quadrant.y].romulans -= 1
1554 game.state.nromrem -= 1
1558 elif type == IHQUEST:
1560 iqhere = iqengry = False
1563 # Some type of a Klingon
1564 game.state.galaxy[game.quadrant.x][game.quadrant.y].klingons -= 1
1567 game.comhere = False
1568 for i in range(1, game.state.remcom+1):
1569 if same(game.state.kcmdr[i], game.quadrant):
1571 game.state.kcmdr[i] = game.state.kcmdr[game.state.remcom]
1572 game.state.kcmdr[game.state.remcom].x = 0
1573 game.state.kcmdr[game.state.remcom].y = 0
1574 game.state.remcom -= 1
1576 if game.state.remcom != 0:
1577 schedule(FTBEAM, expran(1.0*game.incom/game.state.remcom))
1579 game.state.remkl -= 1
1581 game.state.nscrem -= 1
1583 game.state.kscmdr.x = game.state.kscmdr.y = game.isatb = 0
1588 prout("*** Internal error, deadkl() called on %s\n" % type)
1590 # For each kind of enemy, finish message to player
1591 prout(_(" destroyed."))
1592 game.quad[w.x][w.y] = IHDOT
1593 if (game.state.remkl + game.state.remcom + game.state.nscrem)==0:
1596 # Remove enemy ship from arrays describing local conditions
1597 if is_scheduled(FCDBAS) and same(game.battle, game.quadrant) and type==IHC:
1599 for i in range(1, game.nenhere+1):
1600 if same(game.ks[i], w):
1603 if i <= game.nenhere:
1604 for j in range(i, game.nenhere+1):
1605 game.ks[j] = game.ks[j+1]
1606 game.kpower[j] = game.kpower[j+1]
1607 game.kavgd[j] = game.kdist[j] = game.kdist[j+1]
1608 game.ks[game.nenhere+1].x = 0
1609 game.ks[game.nenhere+1].x = 0
1610 game.kdist[game.nenhere+1] = 0
1611 game.kavgd[game.nenhere+1] = 0
1612 game.kpower[game.nenhere+1] = 0
1615 def targetcheck(x, y):
1616 # Return None if target is invalid
1617 if not VALID_SECTOR(x, y):
1620 deltx = 0.1*(y - game.sector.y)
1621 delty = 0.1*(x - game.sector.x)
1622 if deltx==0 and delty== 0:
1624 prout(_("Spock- \"Bridge to sickbay. Dr. McCoy,"))
1625 prout(_(" I recommend an immediate review of"))
1626 prout(_(" the Captain's psychological profile.\""))
1629 return 1.90985932*math.atan2(deltx, delty)
1632 # launch photon torpedo
1634 if damaged(DPHOTON):
1635 prout(_("Photon tubes damaged."))
1639 prout(_("No torpedoes left."))
1648 prout(_("%d torpedoes left."), game.torps)
1649 proutn(_("Number of torpedoes to fire- "))
1651 else: # key == IHREAL {
1653 if n <= 0: # abort command
1658 prout(_("Maximum of 3 torpedoes per burst."))
1665 for i in range(1, n+1):
1667 if i==1 and key == IHEOL:
1668 break; # we will try prompting
1669 if i==2 and key == IHEOL:
1670 # direct all torpedoes at one target
1672 targ[i][1] = targ[1][1]
1673 targ[i][2] = targ[1][2]
1674 course[i] = course[1]
1686 course[i] = targetcheck(targ[i][1], targ[i][2])
1687 if course[i] == None:
1690 if i == 1 and key == IHEOL:
1691 # prompt for each one
1692 for i in range(1, n+1):
1693 proutn(_("Target sector for torpedo number %d- "), i)
1705 course[i] = targetcheck(targ[i][1], targ[i][2])
1706 if course[i] == None:
1709 # Loop for moving <n> torpedoes
1710 for i in range(1, n+1):
1711 if game.condition != "docked":
1713 r = (Rand()+Rand())*0.5 -0.5
1714 if math.fabs(r) >= 0.47:
1716 r = (Rand()+1.2) * r
1718 prouts(_("***TORPEDO NUMBER %d MISFIRES"), i)
1720 prouts(_("***TORPEDO MISFIRES."))
1723 prout(_(" Remainder of burst aborted."))
1725 prout(_("***Photon tubes damaged by misfire."))
1726 game.damage[DPHOTON] = game.damfac*(1.0+2.0*Rand())
1728 if game.shldup or game.condition == "docked":
1729 r *= 1.0 + 0.0001*game.shield
1730 torpedo(course[i], r, game.sector, i, n)
1731 if game.alldone or game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova:
1733 if (game.state.remkl + game.state.remcom + game.state.nscrem)==0:
1737 # check for phasers overheating
1739 chekbrn = (rpow-1500.)*0.00038
1740 if Rand() <= chekbrn:
1741 prout(_("Weapons officer Sulu- \"Phasers overheated, sir.\""))
1742 game.damage[DPHASER] = game.damfac*(1.0 + Rand()) * (1.0+chekbrn)
1744 def checkshctrl(rpow):
1745 # check shield control
1749 prout(_("Shields lowered."))
1751 # Something bad has happened
1752 prouts(_("***RED ALERT! RED ALERT!"))
1754 hit = rpow*game.shield/game.inshld
1755 game.energy -= rpow+hit*0.8
1756 game.shield -= hit*0.2
1757 if game.energy <= 0.0:
1758 prouts(_("Sulu- \"Captain! Shield malf***********************\""))
1763 prouts(_("Sulu- \"Captain! Shield malfunction! Phaser fire contained!\""))
1765 prout(_("Lt. Uhura- \"Sir, all decks reporting damage.\""))
1766 icas = hit*Rand()*0.012
1771 prout(_("McCoy to bridge- \"Severe radiation burns, Jim."))
1772 prout(_(" %d casualties so far.\""), icas)
1774 game.state.crew -= icas
1776 prout(_("Phaser energy dispersed by shields."))
1777 prout(_("Enemy unaffected."))
1781 def hittem(doublehits):
1782 # register a phaser hit on Klingons and Romulans
1783 nenhr2=game.nenhere; kk=1
1786 for k in range(1, nenhr2+1):
1790 dustfac = 0.9 + 0.01*Rand()
1791 hit = wham*math.pow(dustfac,game.kdist[kk])
1792 kpini = game.kpower[kk]
1793 kp = math.fabs(kpini)
1794 if PHASEFAC*hit < kp:
1796 if game.kpower[kk] < 0:
1797 game.kpower[kk] -= -kp
1799 game.kpower[kk] -= kp
1800 kpow = game.kpower[kk]
1803 if not damaged(DSRSENS):
1805 proutn(_("%d unit hit on ") % int(hit))
1807 proutn(_("Very small hit on "))
1808 ienm = game.quad[w.x][w.y]
1811 crmena(False, ienm, "sector", w)
1815 if (game.state.remkl + game.state.remcom + game.state.nscrem)==0:
1819 kk -= 1; # don't do the increment
1820 else: # decide whether or not to emasculate klingon
1821 if kpow > 0 and Rand() >= 0.9 and \
1822 kpow <= ((0.4 + 0.4*Rand())*kpini):
1823 prout(_("***Mr. Spock- \"Captain, the vessel at %s"),
1825 prout(_(" has just lost its firepower.\""))
1826 game.kpower[kk] = -kpow
1833 kz = 0; k = 1; irec=0 # Cheating inhibitor
1834 ifast = False; no = False; itarg = True; msgflag = True
1839 # SR sensors and Computer are needed fopr automode
1840 if damaged(DSRSENS) or damaged(DCOMPTR):
1842 if game.condition == "docked":
1843 prout(_("Phasers can't be fired through base shields."))
1846 if damaged(DPHASER):
1847 prout(_("Phaser control damaged."))
1851 if damaged(DSHCTRL):
1852 prout(_("High speed shield control damaged."))
1855 if game.energy <= 200.0:
1856 prout(_("Insufficient energy to activate high-speed shield control."))
1859 prout(_("Weapons Officer Sulu- \"High-speed shield control enabled, sir.\""))
1862 # Original code so convoluted, I re-did it all
1863 while automode=="NOTSET":
1868 prout(_("There is no enemy present to select."))
1871 automode="AUTOMATIC"
1875 elif isit("automatic"):
1876 if (not itarg) and game.nenhere != 0:
1877 automode = "FORCEMAN"
1880 prout(_("Energy will be expended into space."))
1881 automode = "AUTOMATIC"
1890 prout(_("Energy will be expended into space."))
1891 automode = "AUTOMATIC"
1893 automode = "FORCEMAN"
1895 automode = "AUTOMATIC"
1899 prout(_("Energy will be expended into space."))
1900 automode = "AUTOMATIC"
1902 automode = "FORCEMAN"
1904 proutn(_("Manual or automatic? "))
1908 if automode == "AUTOMATIC":
1909 if key == IHALPHA and isit("no"):
1912 if key != IHREAL and game.nenhere != 0:
1913 prout(_("Phasers locked on target. Energy available: %.2f"),
1919 for i in range(1, game.nenhere+1):
1920 irec += math.fabs(game.kpower[i])/(PHASEFAC*math.pow(0.90,game.kdist[i]))*(1.01+0.05*Rand()) + 1.0
1922 proutn(_("%d units required. "), irec)
1924 proutn(_("Units to fire= "))
1930 proutn(_("Energy available= %.2f") % avail)
1933 if not rpow > avail:
1940 if key == IHALPHA and isit("no"):
1943 game.energy -= 200; # Go and do it!
1944 if checkshctrl(rpow):
1952 for i in range(1, game.nenhere+1):
1956 hits[i] = math.fabs(game.kpower[i])/(PHASEFAC*math.pow(0.90,game.kdist[i]))
1957 over = (0.01 + 0.05*Rand())*hits[i]
1959 powrem -= hits[i] + over
1960 if powrem <= 0 and temp < hits[i]:
1969 if extra > 0 and not game.alldone:
1971 proutn(_("*** Tholian web absorbs "))
1973 proutn(_("excess "))
1974 prout(_("phaser energy."))
1976 prout(_("%d expended on empty space."), int(extra))
1977 elif automode == "FORCEMAN":
1980 if damaged(DCOMPTR):
1981 prout(_("Battle computer damaged, manual fire only."))
1984 prouts(_("---WORKING---"))
1986 prout(_("Short-range-sensors-damaged"))
1987 prout(_("Insufficient-data-for-automatic-phaser-fire"))
1988 prout(_("Manual-fire-must-be-used"))
1990 elif automode == "MANUAL":
1992 for k in range(1, game.nenhere+1):
1994 ienm = game.quad[aim.x][aim.y]
1996 proutn(_("Energy available= %.2f") % avail-0.006)
2000 if damaged(DSRSENS) and not (abs(game.sector.x-aim.x) < 2 and abs(game.sector.y-aim.y) < 2) and \
2001 (ienm == IHC or ienm == IHS):
2003 prout(_(" can't be located without short range scan."))
2006 hits[k] = 0; # prevent overflow -- thanks to Alexei Voitenko
2011 if itarg and k > kz:
2012 irec=(abs(game.kpower[k])/(PHASEFAC*math.pow(0.9,game.kdist[k]))) * (1.01+0.05*Rand()) + 1.0
2015 if not damaged(DCOMPTR):
2020 proutn(_("units to fire at "))
2021 crmena(False, ienm, sector, aim)
2024 if key == IHALPHA and isit("no"):
2032 if k==1: # Let me say I'm baffled by this
2041 # If total requested is too much, inform and start over
2043 prout(_("Available energy exceeded -- try again."))
2046 key = scan(); # scan for next value
2049 # zero energy -- abort
2052 if key == IHALPHA and isit("no"):
2057 game.energy -= 200.0
2058 if checkshctrl(rpow):
2062 # Say shield raised or malfunction, if necessary
2069 prout(_("Sulu- \"Sir, the high-speed shield control has malfunctioned . . ."))
2070 prouts(_(" CLICK CLICK POP . . ."))
2071 prout(_(" No response, sir!"))
2074 prout(_("Shields raised."))
2079 # Code from events,c begins here.
2081 # This isn't a real event queue a la BSD Trek yet -- you can only have one
2082 # event of each type active at any given time. Mostly these means we can
2083 # only have one FDISTR/FENSLV/FREPRO sequence going at any given time
2084 # BSD Trek, from which we swiped the idea, can have up to 5.
2088 def unschedule(evtype):
2089 # remove an event from the schedule
2090 game.future[evtype].date = FOREVER
2091 return game.future[evtype]
2093 def is_scheduled(evtype):
2094 # is an event of specified type scheduled
2095 return game.future[evtype].date != FOREVER
2097 def scheduled(evtype):
2098 # when will this event happen?
2099 return game.future[evtype].date
2101 def schedule(evtype, offset):
2102 # schedule an event of specified type
2103 game.future[evtype].date = game.state.date + offset
2104 return game.future[evtype]
2106 def postpone(evtype, offset):
2107 # postpone a scheduled event
2108 game.future[evtype].date += offset
2111 # rest period is interrupted by event
2114 proutn(_("Mr. Spock- \"Captain, shall we cancel the rest period?\""))
2116 game.resting = False
2123 # run through the event queue looking for things to do
2125 fintim = game.state.date + game.optime; yank=0
2126 ictbeam = False; istract = False
2127 w = coord(); hold = coord()
2128 ev = event(); ev2 = event()
2131 # tractor beaming cases merge here
2132 yank = math.sqrt(yank)
2134 game.optime = (10.0/(7.5*7.5))*yank # 7.5 is yank rate (warp 7.5)
2138 prout(_(" caught in long range tractor beam--"))
2139 # If Kirk & Co. screwing around on planet, handle
2140 atover(True) # atover(true) is Grab
2143 if game.icraft: # Caught in Galileo?
2146 # Check to see if shuttle is aboard
2147 if game.iscraft == "offship":
2150 prout(_("Galileo, left on the planet surface, is captured"))
2151 prout(_("by aliens and made into a flying McDonald's."))
2152 game.damage[DSHUTTL] = -10
2153 game.iscraft = "removed"
2155 prout(_("Galileo, left on the planet surface, is well hidden."))
2157 game.quadrant = game.state.kscmdr
2159 game.quadrant = game.state.kcmdr[i]
2160 game.sector = randplace(QUADSIZE)
2162 proutn(_(" is pulled to "))
2163 proutn(cramlc(quadrant, game.quadrant))
2165 prout(cramlc(sector, game.sector))
2167 prout(_("(Remainder of rest/repair period cancelled.)"))
2168 game.resting = False
2170 if not damaged(DSHIELD) and game.shield > 0:
2171 doshield(True) # raise shields
2174 prout(_("(Shields not currently useable.)"))
2176 # Adjust finish time to time of tractor beaming
2177 fintim = game.state.date+game.optime
2179 if game.state.remcom <= 0:
2182 schedule(FTBEAM, game.optime+expran(1.5*game.intime/game.state.remcom))
2185 # Code merges here for any commander destroying base
2186 # Not perfect, but will have to do
2187 # Handle case where base is in same quadrant as starship
2188 if same(game.battle, game.quadrant):
2189 game.state.chart[game.battle.x][game.battle.y].starbase = False
2190 game.quad[game.base.x][game.base.y] = IHDOT
2191 game.base.x=game.base.y=0
2194 prout(_("Spock- \"Captain, I believe the starbase has been destroyed.\""))
2195 elif game.state.rembase != 1 and \
2196 (not damaged(DRADIO) or game.condition == "docked"):
2197 # Get word via subspace radio
2200 prout(_("Lt. Uhura- \"Captain, Starfleet Command reports that"))
2201 proutn(_(" the starbase in "))
2202 proutn(cramlc(quadrant, game.battle))
2203 prout(_(" has been destroyed by"))
2205 prout(_("the Klingon Super-Commander"))
2207 prout(_("a Klingon Commander"))
2208 game.state.chart[game.battle.x][game.battle.y].starbase = False
2209 # Remove Starbase from galaxy
2210 game.state.galaxy[game.battle.x][game.battle.y].starbase = False
2211 for i in range(1, game.state.rembase+1):
2212 if same(game.state.baseq[i], game.battle):
2213 game.state.baseq[i] = game.state.baseq[game.state.rembase]
2214 game.state.rembase -= 1
2216 # reinstate a commander's base attack
2220 invalidate(game.battle)
2223 prout("=== EVENTS from %.2f to %.2f:" % (game.state.date, fintim))
2224 for i in range(1, NEVENTS):
2225 if i == FSNOVA: proutn("=== Supernova ")
2226 elif i == FTBEAM: proutn("=== T Beam ")
2227 elif i == FSNAP: proutn("=== Snapshot ")
2228 elif i == FBATTAK: proutn("=== Base Attack ")
2229 elif i == FCDBAS: proutn("=== Base Destroy ")
2230 elif i == FSCMOVE: proutn("=== SC Move ")
2231 elif i == FSCDBAS: proutn("=== SC Base Destroy ")
2232 elif i == FDSPROB: proutn("=== Probe Move ")
2233 elif i == FDISTR: proutn("=== Distress Call ")
2234 elif i == FENSLV: proutn("=== Enslavement ")
2235 elif i == FREPRO: proutn("=== Klingon Build ")
2237 prout("%.2f" % (scheduled(i)))
2240 radio_was_broken = damaged(DRADIO)
2243 # Select earliest extraneous event, evcode==0 if no events
2248 for l in range(1, NEVENTS):
2249 if game.future[l].date < datemin:
2252 prout("== Event %d fires" % (evcode))
2253 datemin = game.future[l].date
2254 xtime = datemin-game.state.date
2255 game.state.date = datemin
2256 # Decrement Federation resources and recompute remaining time
2257 game.state.remres -= (game.state.remkl+4*game.state.remcom)*xtime
2259 if game.state.remtime <=0:
2262 # Any crew left alive?
2263 if game.state.crew <=0:
2266 # Is life support adequate?
2267 if damaged(DLIFSUP) and game.condition != "docked":
2268 if game.lsupres < xtime and game.damage[DLIFSUP] > game.lsupres:
2271 game.lsupres -= xtime
2272 if game.damage[DLIFSUP] <= xtime:
2273 game.lsupres = game.inlsr
2276 if game.condition == "docked":
2277 repair /= game.docfac
2278 # Don't fix Deathray here
2279 for l in range(0, NDEVICES):
2280 if game.damage[l] > 0.0 and l != DDRAY:
2281 if game.damage[l]-repair > 0.0:
2282 game.damage[l] -= repair
2284 game.damage[l] = 0.0
2285 # If radio repaired, update star chart and attack reports
2286 if radio_was_broken and not damaged(DRADIO):
2287 prout(_("Lt. Uhura- \"Captain, the sub-space radio is working and"))
2288 prout(_(" surveillance reports are coming in."))
2290 if not game.iseenit:
2294 prout(_(" The star chart is now up to date.\""))
2296 # Cause extraneous event EVCODE to occur
2297 game.optime -= xtime
2298 if evcode == FSNOVA: # Supernova
2301 schedule(FSNOVA, expran(0.5*game.intime))
2302 if game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova:
2304 elif evcode == FSPY: # Check with spy to see if SC should tractor beam
2305 if game.state.nscrem == 0 or \
2306 ictbeam or istract or \
2307 game.condition=="docked" or game.isatb==1 or game.iscate:
2309 if game.ientesc or \
2310 (game.energy<2000 and game.torps<4 and game.shield < 1250) or \
2311 (damaged(DPHASER) and (damaged(DPHOTON) or game.torps<4)) or \
2312 (damaged(DSHIELD) and \
2313 (game.energy < 2500 or damaged(DPHASER)) and \
2314 (game.torps < 5 or damaged(DPHOTON))):
2317 yank = distance(game.state.kscmdr, game.quadrant)
2322 elif evcode == FTBEAM: # Tractor beam
2323 if game.state.remcom == 0:
2326 i = Rand()*game.state.remcom+1.0
2327 yank = square(game.state.kcmdr[i].x-game.quadrant.x) + square(game.state.kcmdr[i].y-game.quadrant.y)
2328 if istract or game.condition == "docked" or yank == 0:
2329 # Drats! Have to reschedule
2331 game.optime + expran(1.5*game.intime/game.state.remcom))
2335 elif evcode == FSNAP: # Snapshot of the universe (for time warp)
2336 game.snapsht = game.state
2337 game.state.snap = True
2338 schedule(FSNAP, expran(0.5 * game.intime))
2339 elif evcode == FBATTAK: # Commander attacks starbase
2340 if game.state.remcom==0 or game.state.rembase==0:
2346 for j in range(1, game.state.rembase+1):
2347 for k in range(1, game.state.remcom+1):
2348 if same(game.state.baseq[j], game.state.kcmdr[k]) and \
2349 not same(game.state.baseq[j], game.quadrant) and \
2350 not same(game.state.baseq[j], game.state.kscmdr):
2354 if j>game.state.rembase:
2355 # no match found -- try later
2356 schedule(FBATTAK, expran(0.3*game.intime))
2359 # commander + starbase combination found -- launch attack
2360 game.battle = game.state.baseq[j]
2361 schedule(FCDBAS, 1.0+3.0*Rand())
2362 if game.isatb: # extra time if SC already attacking
2363 postpone(FCDBAS, scheduled(FSCDBAS)-game.state.date)
2364 game.future[FBATTAK].date = game.future[FCDBAS].date + expran(0.3*game.intime)
2365 game.iseenit = False
2366 if damaged(DRADIO) and game.condition != "docked":
2367 continue # No warning :-(
2371 proutn(_("Lt. Uhura- \"Captain, the starbase in Quadrant %s") % game.battle)
2372 prout(_(" reports that it is under attack and that it can"))
2373 proutn(_(" hold out only until stardate %d" % (int(scheduled(FCDBAS)))))
2377 elif evcode == FSCDBAS: # Supercommander destroys base
2380 if not game.state.galaxy[game.state.kscmdr.x][game.state.kscmdr.y].starbase:
2381 continue # WAS RETURN!
2383 game.battle = game.state.kscmdr
2385 elif evcode == FCDBAS: # Commander succeeds in destroying base
2388 # find the lucky pair
2389 for i in range(1, game.state.remcom+1):
2390 if same(game.state.kcmdr[i], game.battle):
2392 if i > game.state.remcom or game.state.rembase == 0 or \
2393 not game.state.galaxy[game.battle.x][game.battle.y].starbase:
2394 # No action to take after all
2395 invalidate(game.battle)
2398 elif evcode == FSCMOVE: # Supercommander moves
2399 schedule(FSCMOVE, 0.2777)
2400 if not game.ientesc and not istract and game.isatb != 1 and \
2401 (not game.iscate or not game.justin):
2403 elif evcode == FDSPROB: # Move deep space probe
2404 schedule(FDSPROB, 0.01)
2405 game.probex += game.probeinx
2406 game.probey += game.probeiny
2407 i = (int)(game.probex/QUADSIZE +0.05)
2408 j = (int)(game.probey/QUADSIZE + 0.05)
2409 if game.probec.x != i or game.probec.y != j:
2412 if not VALID_QUADRANT(i, j) or \
2413 game.state.galaxy[game.probec.x][game.probec.y].supernova:
2414 # Left galaxy or ran into supernova
2415 if not damaged(DRADIO) or game.condition == "docked":
2418 proutn(_("Lt. Uhura- \"The deep space probe "))
2419 if not VALID_QUADRANT(j, i):
2420 proutn(_("has left the galaxy"))
2422 proutn(_("is no longer transmitting"))
2426 if not damaged(DRADIO) or game.condition == "docked":
2429 proutn(_("Lt. Uhura- \"The deep space probe is now in "))
2430 proutn(cramlc(quadrant, game.probec))
2432 pdest = game.state.galaxy[game.probec.x][game.probec.y]
2433 # Update star chart if Radio is working or have access to radio
2434 if not damaged(DRADIO) or game.condition == "docked":
2435 chp = game.state.chart[game.probec.x][game.probec.y]
2436 chp.klingons = pdest.klingons
2437 chp.starbase = pdest.starbase
2438 chp.stars = pdest.stars
2439 pdest.charted = True
2440 game.proben -= 1 # One less to travel
2441 if game.proben == 0 and game.isarmed and pdest.stars:
2442 # lets blow the sucker!
2443 supernova(True, game.probec)
2445 if game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova:
2447 elif evcode == FDISTR: # inhabited system issues distress call
2449 # try a whole bunch of times to find something suitable
2450 for i in range(100):
2451 # need a quadrant which is not the current one,
2452 # which has some stars which are inhabited and
2453 # not already under attack, which is not
2454 # supernova'ed, and which has some Klingons in it
2455 w = randplace(GALSIZE)
2456 q = game.state.galaxy[w.x][w.y]
2457 if not (same(game.quadrant, w) or q.planet == NOPLANET or \
2458 game.state.planets[q.planet].inhabited == UNINHABITED or \
2459 q.supernova or q.status!=secure or q.klingons<=0):
2462 # can't seem to find one; ignore this call
2464 prout("=== Couldn't find location for distress event.")
2466 # got one!! Schedule its enslavement
2467 ev = schedule(FENSLV, expran(game.intime))
2469 q.status = distressed
2471 # tell the captain about it if we can
2472 if not damaged(DRADIO) or game.condition == "docked":
2473 prout(_("Uhura- Captain, %s in Quadrant %s reports it is under attack" \
2474 % (systnames[q.planet], `w`)))
2475 prout(_("by a Klingon invasion fleet."))
2478 elif evcode == FENSLV: # starsystem is enslaved
2479 ev = unschedule(FENSLV)
2480 # see if current distress call still active
2481 q = game.state.galaxy[ev.quadrant.x][ev.quadrant.y]
2485 q.status = "enslaved"
2487 # play stork and schedule the first baby
2488 ev2 = schedule(FREPRO, expran(2.0 * game.intime))
2489 ev2.quadrant = ev.quadrant
2491 # report the disaster if we can
2492 if not damaged(DRADIO) or game.condition == "docked":
2493 prout(_("Uhura- We've lost contact with starsystem %s" % \
2494 systnames[q.planet]))
2495 prout(_("in Quadrant %s.\n" % ev.quadrant))
2496 elif evcode == FREPRO: # Klingon reproduces
2497 # If we ever switch to a real event queue, we'll need to
2498 # explicitly retrieve and restore the x and y.
2499 ev = schedule(FREPRO, expran(1.0 * game.intime))
2500 # see if current distress call still active
2501 q = game.state.galaxy[ev.quadrant.x][ev.quadrant.y]
2505 if game.state.remkl >=MAXKLGAME:
2506 continue # full right now
2507 # reproduce one Klingon
2509 if game.klhere >= MAXKLQUAD:
2511 # this quadrant not ok, pick an adjacent one
2512 for i in range(w.x - 1, w.x + 2):
2513 for j in range(w.y - 1, w.y + 2):
2514 if not VALID_QUADRANT(i, j):
2516 q = game.state.galaxy[w.x][w.y]
2517 # check for this quad ok (not full & no snova)
2518 if q.klingons >= MAXKLQUAD or q.supernova:
2522 continue # search for eligible quadrant failed
2527 game.state.remkl += 1
2529 if same(game.quadrant, w):
2530 newkling(++game.klhere)
2532 # recompute time left
2534 # report the disaster if we can
2535 if not damaged(DRADIO) or game.condition == "docked":
2536 if same(game.quadrant, w):
2537 prout(_("Spock- sensors indicate the Klingons have"))
2538 prout(_("launched a warship from %s." \
2539 % systnames[q.planet]))
2541 prout(_("Uhura- Starfleet reports increased Klingon activity"))
2542 if q.planet != NOPLANET:
2543 proutn(_("near %s" % systnames[q.planet]))
2544 prout(_("in %s.\n" % cramlc(quadrant, w)))
2553 proutn(_("How long? "))
2558 origTime = delay = aaitem
2561 if delay >= game.state.remtime or game.nenhere != 0:
2562 proutn(_("Are you sure? "))
2566 # Alternate resting periods (events) with attacks
2571 game.resting = False
2572 if not game.resting:
2573 prout(_("%d stardates left." % int(game.state.remtime)))
2575 temp = game.optime = delay
2577 rtime = 1.0 + Rand()
2581 if game.optime < delay:
2590 # Repair Deathray if long rest at starbase
2591 if origTime-delay >= 9.99 and game.condition == "docked":
2592 game.damage[DDRAY] = 0.0
2593 # leave if quadrant supernovas
2594 if game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova:
2596 game.resting = False
2599 # A nova occurs. It is the result of having a star hit with a
2600 # photon torpedo, or possibly of a probe warhead going off.
2601 # Stars that go nova cause stars which surround them to undergo
2602 # the same probabilistic process. Klingons next to them are
2603 # destroyed. And if the starship is next to it, it gets zapped.
2604 # If the zap is too much, it gets destroyed.
2608 course = (0.0, 10.5, 12.0, 1.5, 9.0, 0.0, 3.0, 7.5, 6.0, 4.5)
2609 newc = coord(); scratch = coord()
2612 # Wow! We've supernova'ed
2613 supernova(False, nov)
2616 # handle initial nova
2617 game.quad[nov.x][nov.y] = IHDOT
2618 crmena(False, IHSTAR, sector, nov)
2620 game.state.galaxy[game.quadrant.x][game.quadrant.y].stars -= 1
2621 game.state.starkl += 1
2623 # Set up stack to recursively trigger adjacent stars
2624 bot = top = top2 = 1
2630 for mm in range(bot, top+1):
2631 for nn in range(1, 3+1): # nn,j represents coordinates around current
2632 for j in range(1, 3+1):
2635 scratch.x = hits[mm][1]+nn-2
2636 scratch.y = hits[mm][2]+j-2
2637 if not VALID_SECTOR(scratch.y, scratch.x):
2639 iquad = game.quad[scratch.x][scratch.y]
2640 # Empty space ends reaction
2641 if iquad in (IHDOT, IHQUEST, IHBLANK, IHT, IHWEB):
2643 elif iquad == IHSTAR: # Affect another star
2645 # This star supernovas
2646 scratch = supernova(False)
2649 hits[top2][1]=scratch.x
2650 hits[top2][2]=scratch.y
2651 game.state.galaxy[game.quadrant.x][game.quadrant.y].stars -= 1
2652 game.state.starkl += 1
2653 crmena(True, IHSTAR, sector, scratch)
2655 game.quad[scratch.x][scratch.y] = IHDOT
2656 elif iquad == IHP: # Destroy planet
2657 game.state.galaxy[game.quadrant.x][game.quadrant.y].planet = NOPLANET
2658 game.state.nplankl += 1
2659 crmena(True, IHP, sector, scratch)
2660 prout(_(" destroyed."))
2661 game.state.planets[game.iplnet].pclass = destroyed
2663 invalidate(game.plnet)
2667 game.quad[scratch.x][scratch.y] = IHDOT
2668 elif iquad == IHB: # Destroy base
2669 game.state.galaxy[game.quadrant.x][game.quadrant.y].starbase = False
2670 for i in range(1, game.state.rembase+1):
2671 if same(game.state.baseq[i], game.quadrant):
2673 game.state.baseq[i] = game.state.baseq[game.state.rembase]
2674 game.state.rembase -= 1
2675 invalidate(game.base)
2676 game.state.basekl += 1
2678 crmena(True, IHB, sector, scratch)
2679 prout(_(" destroyed."))
2680 game.quad[scratch.x][scratch.y] = IHDOT
2681 elif iquad in (IHE, IHF): # Buffet ship
2682 prout(_("***Starship buffeted by nova."))
2684 if game.shield >= 2000.0:
2685 game.shield -= 2000.0
2687 diff = 2000.0 - game.shield
2691 prout(_("***Shields knocked out."))
2692 game.damage[DSHIELD] += 0.005*game.damfac*Rand()*diff
2694 game.energy -= 2000.0
2695 if game.energy <= 0:
2698 # add in course nova contributes to kicking starship
2699 icx += game.sector.x-hits[mm][1]
2700 icy += game.sector.y-hits[mm][2]
2702 elif iquad == IHK: # kill klingon
2703 deadkl(scratch,iquad, scratch)
2704 elif iquad in (IHC,IHS,IHR): # Damage/destroy big enemies
2705 for ll in range(1, game.nenhere+1):
2706 if same(game.ks[ll], scratch):
2708 game.kpower[ll] -= 800.0 # If firepower is lost, die
2709 if game.kpower[ll] <= 0.0:
2710 deadkl(scratch, iquad, scratch)
2712 newc.x = scratch.x + scratch.x - hits[mm][1]
2713 newc.y = scratch.y + scratch.y - hits[mm][2]
2714 crmena(True, iquad, sector, scratch)
2715 proutn(_(" damaged"))
2716 if not VALID_SECTOR(newc.x, newc.y):
2717 # can't leave quadrant
2720 iquad1 = game.quad[newc.x][newc.y]
2721 if iquad1 == IHBLANK:
2722 proutn(_(", blasted into "))
2723 crmena(False, IHBLANK, sector, newc)
2725 deadkl(scratch, iquad, newc)
2728 # can't move into something else
2731 proutn(_(", buffeted to "))
2732 proutn(cramlc(sector, newc))
2733 game.quad[scratch.x][scratch.y] = IHDOT
2734 game.quad[newc.x][newc.y] = iquad
2736 game.kdist[ll] = game.kavgd[ll] = distance(game.sector, newc)
2745 # Starship affected by nova -- kick it away.
2746 game.dist = kount*0.1
2749 game.direc = course[3*(icx+1)+icy+2]
2750 if game.direc == 0.0:
2752 if game.dist == 0.0:
2754 game.optime = 10.0*game.dist/16.0
2756 prout(_("Force of nova displaces starship."))
2758 game.optime = 10.0*game.dist/16.0
2761 def supernova(induced, w=None):
2762 # star goes supernova
2770 # Scheduled supernova -- select star
2771 # logic changed here so that we won't favor quadrants in top
2773 for nq.x in range(1, GALSIZE+1):
2774 for nq.y in range(1, GALSIZE+1):
2775 stars += game.state.galaxy[nq.x][nq.y].stars
2777 return # nothing to supernova exists
2778 num = Rand()*stars + 1
2779 for nq.x in range(1, GALSIZE+1):
2780 for nq.y in range(1, GALSIZE+1):
2781 num -= game.state.galaxy[nq.x][nq.y].stars
2787 proutn("=== Super nova here?")
2791 if not same(nq, game.quadrant) or game.justin:
2792 # it isn't here, or we just entered (treat as enroute)
2793 if not damaged(DRADIO) or game.condition == "docked":
2795 prout(_("Message from Starfleet Command Stardate %.2f" % game.state.date))
2796 prout(_(" Supernova in Quadrant %s; caution advised." % nq))
2799 # we are in the quadrant!
2800 num = Rand()* game.state.galaxy[nq.x][nq.y].stars + 1
2801 for ns.x in range(1, QUADSIZE+1):
2802 for ns.y in range(1, QUADSIZE+1):
2803 if game.quad[ns.x][ns.y]==IHSTAR:
2811 prouts(_("***RED ALERT! RED ALERT!"))
2813 prout(_("***Incipient supernova detected at Sector %s" % ns))
2814 if square(ns.x-game.sector.x) + square(ns.y-game.sector.y) <= 2.1:
2815 proutn(_("Emergency override attempts t"))
2816 prouts("***************")
2821 # destroy any Klingons in supernovaed quadrant
2822 kldead = game.state.galaxy[nq.x][nq.y].klingons
2823 game.state.galaxy[nq.x][nq.y].klingons = 0
2824 if same(nq, game.state.kscmdr):
2825 # did in the Supercommander!
2826 game.state.nscrem = game.state.kscmdr.x = game.state.kscmdr.y = game.isatb = 0
2830 if game.state.remcom:
2831 maxloop = game.state.remcom
2832 for l in range(1, maxloop+1):
2833 if same(game.state.kcmdr[l], nq):
2834 game.state.kcmdr[l] = game.state.kcmdr[game.state.remcom]
2835 invalidate(game.state.kcmdr[game.state.remcom])
2836 game.state.remcom -= 1
2838 if game.state.remcom==0:
2841 game.state.remkl -= kldead
2842 # destroy Romulans and planets in supernovaed quadrant
2843 nrmdead = game.state.galaxy[nq.x][nq.y].romulans
2844 game.state.galaxy[nq.x][nq.y].romulans = 0
2845 game.state.nromrem -= nrmdead
2847 for loop in range(game.inplan):
2848 if same(game.state.planets[loop].w, nq):
2849 game.state.planets[loop].pclass = destroyed
2851 # Destroy any base in supernovaed quadrant
2852 if game.state.rembase:
2853 maxloop = game.state.rembase
2854 for loop in range(1, maxloop+1):
2855 if same(game.state.baseq[loop], nq):
2856 game.state.baseq[loop] = game.state.baseq[game.state.rembase]
2857 invalidate(game.state.baseq[game.state.rembase])
2858 game.state.rembase -= 1
2860 # If starship caused supernova, tally up destruction
2862 game.state.starkl += game.state.galaxy[nq.x][nq.y].stars
2863 game.state.basekl += game.state.galaxy[nq.x][nq.y].starbase
2864 game.state.nplankl += npdead
2865 # mark supernova in galaxy and in star chart
2866 if same(game.quadrant, nq) or not damaged(DRADIO) or game.condition == "docked":
2867 game.state.galaxy[nq.x][nq.y].supernova = True
2868 # If supernova destroys last Klingons give special message
2869 if (game.state.remkl + game.state.remcom + game.state.nscrem)==0 and not same(nq, game.quadrant):
2872 prout(_("Lucky you!"))
2873 proutn(_("A supernova in %s has just destroyed the last Klingons." % nq))
2876 # if some Klingons remain, continue or die in supernova
2881 # Code from finish.c ends here.
2884 # self-destruct maneuver
2885 # Finish with a BANG!
2887 if damaged(DCOMPTR):
2888 prout(_("Computer damaged; cannot execute destruct sequence."))
2890 prouts(_("---WORKING---")); skip(1)
2891 prouts(_("SELF-DESTRUCT-SEQUENCE-ACTIVATED")); skip(1)
2892 prouts(" 10"); skip(1)
2893 prouts(" 9"); skip(1)
2894 prouts(" 8"); skip(1)
2895 prouts(" 7"); skip(1)
2896 prouts(" 6"); skip(1)
2898 prout(_("ENTER-CORRECT-PASSWORD-TO-CONTINUE-"))
2900 prout(_("SELF-DESTRUCT-SEQUENCE-OTHERWISE-"))
2902 prout(_("SELF-DESTRUCT-SEQUENCE-WILL-BE-ABORTED"))
2906 if game.passwd != citem:
2907 prouts(_("PASSWORD-REJECTED;"))
2909 prouts(_("CONTINUITY-EFFECTED"))
2912 prouts(_("PASSWORD-ACCEPTED")); skip(1)
2913 prouts(" 5"); skip(1)
2914 prouts(" 4"); skip(1)
2915 prouts(" 3"); skip(1)
2916 prouts(" 2"); skip(1)
2917 prouts(" 1"); skip(1)
2919 prouts(_("GOODBYE-CRUEL-WORLD"))
2927 prouts(_("********* Entropy of "))
2929 prouts(_(" maximized *********"))
2933 if game.nenhere != 0:
2934 whammo = 25.0 * game.energy
2936 while l <= game.nenhere:
2937 if game.kpower[l]*game.kdist[l] <= whammo:
2938 deadkl(game.ks[l], game.quad[game.ks[l].x][game.ks[l].y], game.ks[l])
2943 "Compute our rate of kils over time."
2944 return ((game.inkling + game.incom + game.inscom) - (game.state.remkl + game.state.remcom + game.state.nscrem))/(game.state.date-game.indate)
2948 badpt = 5.0*game.state.starkl + \
2950 10.0*game.state.nplankl + \
2951 300*game.state.nworldkl + \
2953 100.0*game.state.basekl +\
2955 if game.ship == IHF:
2957 elif game.ship == None:
2963 # end the game, with appropriate notfications
2967 prout(_("It is stardate %.1f." % (game.state.date)))
2969 if ifin == FWON: # Game has been won
2970 if game.state.nromrem != 0:
2971 prout(_("The remaining %d Romulans surrender to Starfleet Command.") %
2974 prout(_("You have smashed the Klingon invasion fleet and saved"))
2975 prout(_("the Federation."))
2980 badpt = 0.0 # Close enough!
2981 # killsPerDate >= RateMax
2982 if game.state.date-game.indate < 5.0 or \
2983 killrate() >= 0.1*game.skill*(game.skill+1.0) + 0.1 + 0.008*badpt:
2985 prout(_("In fact, you have done so well that Starfleet Command"))
2986 if game.skill == SKILL_NOVICE:
2987 prout(_("promotes you one step in rank from \"Novice\" to \"Fair\"."))
2988 elif game.skill == SKILL_FAIR:
2989 prout(_("promotes you one step in rank from \"Fair\" to \"Good\"."))
2990 elif game.skill == SKILL_GOOD:
2991 prout(_("promotes you one step in rank from \"Good\" to \"Expert\"."))
2992 elif game.skill == SKILL_EXPERT:
2993 prout(_("promotes you to Commodore Emeritus."))
2995 prout(_("Now that you think you're really good, try playing"))
2996 prout(_("the \"Emeritus\" game. It will splatter your ego."))
2997 elif game.skill == SKILL_EMERITUS:
2999 proutn(_("Computer- "))
3000 prouts(_("ERROR-ERROR-ERROR-ERROR"))
3002 prouts(_(" YOUR-SKILL-HAS-EXCEEDED-THE-CAPACITY-OF-THIS-PROGRAM"))
3004 prouts(_(" THIS-PROGRAM-MUST-SURVIVE"))
3006 prouts(_(" THIS-PROGRAM-MUST-SURVIVE"))
3008 prouts(_(" THIS-PROGRAM-MUST-SURVIVE"))
3010 prouts(_(" THIS-PROGRAM-MUST?- MUST ? - SUR? ? -? VI"))
3012 prout(_("Now you can retire and write your own Star Trek game!"))
3014 elif game.skill >= SKILL_EXPERT:
3015 if game.thawed and not idebug:
3016 prout(_("You cannot get a citation, so..."))
3018 proutn(_("Do you want your Commodore Emeritus Citation printed? "))
3022 # Only grant long life if alive (original didn't!)
3024 prout(_("LIVE LONG AND PROSPER."))
3029 elif ifin == FDEPLETE: # Federation Resources Depleted
3030 prout(_("Your time has run out and the Federation has been"))
3031 prout(_("conquered. Your starship is now Klingon property,"))
3032 prout(_("and you are put on trial as a war criminal. On the"))
3033 proutn(_("basis of your record, you are "))
3034 if (game.state.remkl + game.state.remcom + game.state.nscrem)*3.0 > (game.inkling + game.incom + game.inscom):
3035 prout(_("acquitted."))
3037 prout(_("LIVE LONG AND PROSPER."))
3039 prout(_("found guilty and"))
3040 prout(_("sentenced to death by slow torture."))
3044 elif ifin == FLIFESUP:
3045 prout(_("Your life support reserves have run out, and"))
3046 prout(_("you die of thirst, starvation, and asphyxiation."))
3047 prout(_("Your starship is a derelict in space."))
3049 prout(_("Your energy supply is exhausted."))
3051 prout(_("Your starship is a derelict in space."))
3052 elif ifin == FBATTLE:
3055 prout(_("has been destroyed in battle."))
3057 prout(_("Dulce et decorum est pro patria mori."))
3059 prout(_("You have made three attempts to cross the negative energy"))
3060 prout(_("barrier which surrounds the galaxy."))
3062 prout(_("Your navigation is abominable."))
3065 prout(_("Your starship has been destroyed by a nova."))
3066 prout(_("That was a great shot."))
3068 elif ifin == FSNOVAED:
3071 prout(_(" has been fried by a supernova."))
3072 prout(_("...Not even cinders remain..."))
3073 elif ifin == FABANDN:
3074 prout(_("You have been captured by the Klingons. If you still"))
3075 prout(_("had a starbase to be returned to, you would have been"))
3076 prout(_("repatriated and given another chance. Since you have"))
3077 prout(_("no starbases, you will be mercilessly tortured to death."))
3078 elif ifin == FDILITHIUM:
3079 prout(_("Your starship is now an expanding cloud of subatomic particles"))
3080 elif ifin == FMATERIALIZE:
3081 prout(_("Starbase was unable to re-materialize your starship."))
3082 prout(_("Sic transit gloria mundi"))
3083 elif ifin == FPHASER:
3086 prout(_(" has been cremated by its own phasers."))
3088 prout(_("You and your landing party have been"))
3089 prout(_("converted to energy, disipating through space."))
3090 elif ifin == FMINING:
3091 prout(_("You are left with your landing party on"))
3092 prout(_("a wild jungle planet inhabited by primitive cannibals."))
3094 prout(_("They are very fond of \"Captain Kirk\" soup."))
3096 proutn(_("Without your leadership, the "))
3098 prout(_(" is destroyed."))
3099 elif ifin == FDPLANET:
3100 prout(_("You and your mining party perish."))
3102 prout(_("That was a great shot."))
3105 prout(_("The Galileo is instantly annihilated by the supernova."))
3106 prout(_("You and your mining party are atomized."))
3108 proutn(_("Mr. Spock takes command of the "))
3111 prout(_("joins the Romulans, reigning terror on the Federation."))
3112 elif ifin == FPNOVA:
3113 prout(_("You and your mining party are atomized."))
3115 proutn(_("Mr. Spock takes command of the "))
3118 prout(_("joins the Romulans, reigning terror on the Federation."))
3119 elif ifin == FSTRACTOR:
3120 prout(_("The shuttle craft Galileo is also caught,"))
3121 prout(_("and breaks up under the strain."))
3123 prout(_("Your debris is scattered for millions of miles."))
3124 proutn(_("Without your leadership, the "))
3126 prout(_(" is destroyed."))
3128 prout(_("The mutants attack and kill Spock."))
3129 prout(_("Your ship is captured by Klingons, and"))
3130 prout(_("your crew is put on display in a Klingon zoo."))
3131 elif ifin == FTRIBBLE:
3132 prout(_("Tribbles consume all remaining water,"))
3133 prout(_("food, and oxygen on your ship."))
3135 prout(_("You die of thirst, starvation, and asphyxiation."))
3136 prout(_("Your starship is a derelict in space."))
3138 prout(_("Your ship is drawn to the center of the black hole."))
3139 prout(_("You are crushed into extremely dense matter."))
3141 prout(_("Your last crew member has died."))
3142 if game.ship == IHF:
3144 elif game.ship == IHE:
3147 if (game.state.remkl + game.state.remcom + game.state.nscrem) != 0:
3148 goodies = game.state.remres/game.inresor
3149 baddies = (game.state.remkl + 2.0*game.state.remcom)/(game.inkling+2.0*game.incom)
3150 if goodies/baddies >= 1.0+0.5*Rand():
3151 prout(_("As a result of your actions, a treaty with the Klingon"))
3152 prout(_("Empire has been signed. The terms of the treaty are"))
3153 if goodies/baddies >= 3.0+Rand():
3154 prout(_("favorable to the Federation."))
3156 prout(_("Congratulations!"))
3158 prout(_("highly unfavorable to the Federation."))
3160 prout(_("The Federation will be destroyed."))
3162 prout(_("Since you took the last Klingon with you, you are a"))
3163 prout(_("martyr and a hero. Someday maybe they'll erect a"))
3164 prout(_("statue in your memory. Rest in peace, and try not"))
3165 prout(_("to think about pigeons."))
3170 # compute player's score
3171 timused = game.state.date - game.indate
3174 if (timused == 0 or (game.state.remkl + game.state.remcom + game.state.nscrem) != 0) and timused < 5.0:
3176 perdate = killrate()
3177 ithperd = 500*perdate + 0.5
3180 iwon = 100*game.skill
3181 if game.ship == IHE:
3183 elif game.ship == IHF:
3187 if not game.gamewon:
3188 game.state.nromrem = 0 # None captured if no win
3189 iscore = 10*(game.inkling - game.state.remkl) \
3190 + 50*(game.incom - game.state.remcom) \
3192 + 20*(game.inrom - game.state.nromrem) \
3193 + 200*(game.inscom - game.state.nscrem) \
3194 - game.state.nromrem \
3199 prout(_("Your score --"))
3200 if game.inrom - game.state.nromrem:
3201 prout(_("%6d Romulans destroyed %5d" %
3202 (game.inrom - game.state.nromrem, 20*(game.inrom - game.state.nromrem))))
3203 if game.state.nromrem:
3204 prout(_("%6d Romulans captured %5d" %
3205 (game.state.nromrem, game.state.nromrem)))
3206 if game.inkling - game.state.remkl:
3207 prout(_("%6d ordinary Klingons destroyed %5d" %
3208 (game.inkling - game.state.remkl, 10*(game.inkling - game.state.remkl))))
3209 if game.incom - game.state.remcom:
3210 prout(_("%6d Klingon commanders destroyed %5d" %
3211 (game.incom - game.state.remcom, 50*(game.incom - game.state.remcom))))
3212 if game.inscom - game.state.nscrem:
3213 prout(_("%6d Super-Commander destroyed %5d" %
3214 (game.inscom - game.state.nscrem, 200*(game.inscom - game.state.nscrem))))
3216 prout(_("%6.2f Klingons per stardate %5d" %
3217 (perdate, ithperd)))
3218 if game.state.starkl:
3219 prout(_("%6d stars destroyed by your action %5d" %
3220 (game.state.starkl, -5*game.state.starkl)))
3221 if game.state.nplankl:
3222 prout(_("%6d planets destroyed by your action %5d" %
3223 (game.state.nplankl, -10*game.state.nplankl)))
3224 if (game.options & OPTION_WORLDS) and game.state.nworldkl:
3225 prout(_("%6d inhabited planets destroyed by your action %5d" %
3226 (game.state.nplankl, -300*game.state.nworldkl)))
3227 if game.state.basekl:
3228 prout(_("%6d bases destroyed by your action %5d" %
3229 (game.state.basekl, -100*game.state.basekl)))
3231 prout(_("%6d calls for help from starbase %5d" %
3232 (game.nhelp, -45*game.nhelp)))
3234 prout(_("%6d casualties incurred %5d" %
3235 (game.casual, -game.casual)))
3237 prout(_("%6d crew abandoned in space %5d" %
3238 (game.abandoned, -3*game.abandoned)))
3240 prout(_("%6d ship(s) lost or destroyed %5d" %
3241 (klship, -100*klship)))
3243 prout(_("Penalty for getting yourself killed -200"))
3245 proutn(_("Bonus for winning "))
3246 if game.skill == SKILL_NOVICE: proutn(_("Novice game "))
3247 elif game.skill == SKILL_FAIR: proutn(_("Fair game "))
3248 elif game.skill == SKILL_GOOD: proutn(_("Good game "))
3249 elif game.skill == SKILL_EXPERT: proutn(_("Expert game "))
3250 elif game.skill == SKILL_EMERITUS: proutn(_("Emeritus game"))
3251 prout(" %5d" % (iwon))
3253 prout(_("TOTAL SCORE %5d" % iscore))
3256 # emit winner's commemmorative plaque
3259 proutn(_("File or device name for your plaque: "))
3260 cgetline(winner, sizeof(winner))
3262 fp = open(winner, "w")
3265 prout(_("Invalid name."))
3267 proutn(_("Enter name to go on plaque (up to 30 characters): "))
3268 cgetline(winner, sizeof(winner))
3269 # The 38 below must be 64 for 132-column paper
3270 nskip = 38 - len(winner)/2
3272 fp.write("\n\n\n\n")
3273 # --------DRAW ENTERPRISE PICTURE.
3274 fp.write(" EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n" )
3275 fp.write(" EEE E : : : E\n" )
3276 fp.write(" EE EEE E : : NCC-1701 : E\n")
3277 fp.write("EEEEEEEEEEEEEEEE EEEEEEEEEEEEEEE : : : E\n")
3278 fp.write(" E EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n")
3279 fp.write(" EEEEEEEEE EEEEEEEEEEEEE E E\n")
3280 fp.write(" EEEEEEE EEEEE E E E E\n")
3281 fp.write(" EEE E E E E\n")
3282 fp.write(" E E E E\n")
3283 fp.write(" EEEEEEEEEEEEE E E\n")
3284 fp.write(" EEE : EEEEEEE EEEEEEEE\n")
3285 fp.write(" :E : EEEE E\n")
3286 fp.write(" .-E -:----- E\n")
3287 fp.write(" :E : E\n")
3288 fp.write(" EE : EEEEEEEE\n")
3289 fp.write(" EEEEEEEEEEEEEEEEEEEEEEE\n")
3291 fp.write(_(" U. S. S. ENTERPRISE\n"))
3292 fp.write("\n\n\n\n")
3293 fp.write(_(" For demonstrating outstanding ability as a starship captain\n"))
3295 fp.write(_(" Starfleet Command bestows to you\n"))
3297 fp.write("%*s%s\n\n" % (nskip, "", winner))
3298 fp.write(_(" the rank of\n\n"))
3299 fp.write(_(" \"Commodore Emeritus\"\n\n"))
3301 if game.skill == SKILL_EXPERT:
3302 fp.write(_(" Expert level\n\n"))
3303 elif game.skill == SKILL_EMERITUS:
3304 fp.write(_("Emeritus level\n\n"))
3306 fp.write(_(" Cheat level\n\n"))
3307 timestring = ctime()
3308 fp.write(_(" This day of %.6s %.4s, %.8s\n\n" %
3309 (timestring+4, timestring+20, timestring+11)))
3310 fp.write(_(" Your score: %d\n\n" % iscore))
3311 fp.write(_(" Klingons per stardate: %.2f\n" % perdate))