Beginning of experimental Python translation.
[super-star-trek.git] / src / sst.py
1 """
2 sst.py =-- Super Star Trek in Python
3 """
4 import math
5
6 PHASEFAC        = 2.0
7 GALSIZE         = 8
8 NINHAB          = GALSIZE * GALSIZE / 2
9 MAXUNINHAB      = 10
10 PLNETMAB        = NINHAB + MAXUNINHAB
11 QUADSIZE        = 10
12 BASEMAX         = 5
13 FULLCREW        = 428    # BSD Trek was 387, that's wrong
14 MAXKLGAME       = 127
15 MAXKLQUAD       = 9
16 FOREVER         = 1e30
17
18 # Feature vakues
19 IHR = 'R',
20 IHK = 'K',
21 IHC = 'C',
22 IHS = 'S',
23 IHSTAR = '*',
24 IHP = 'P',
25 IHW = '@',
26 IHB = 'B',
27 IHBLANK = ' ',
28 IHDOT = '.',
29 IHQUEST = '?',
30 IHE = 'E',
31 IHF = 'F',
32 IHT = 'T',
33 IHWEB = '#',
34 IHMATER0 = '-',
35 IHMATER1 = 'o',
36 IHMATER2 = '0',
37
38 class coord:
39     def __init(self, x=None, y=None):
40         self.x = x
41         self.y = y
42     def invalidate(self):
43         self.x = self.y = None
44     def is_valid(self):
45         return self.x != None and self.y != None
46     def __eq__(self, other):
47         return self.x == other.y and self.x == other.y
48     def distance(self, other):
49         return math.sqrt((self.x - other.x)**2 + (self.y - other.y)**2)
50
51 class planet:
52     def __init(self):
53         self.w = coord()
54         self.name = None
55         self.crystals = None    # "absent", "present", or "mined"
56         self.known = "unknown"  # Other values: "known" and "shuttle down"
57
58 class quadrant:
59     def __init__(self):
60         self.stars = None
61         self.planet = None
62         self.starbase = None
63         self.klingons = None
64         self.romulans = None
65         self.supernova = None
66         self.charted = None
67         self.status = "secure"  # Other valuues: "distressed", "enslaved"
68
69 class page:
70     "A chart page.  The starchart is a 2D array of these."
71     def __init__(self):
72         self.stars = None       # Will hold a number
73         self.starbase = None    # Will hold a bool
74         self.klingons = None    # Will hold a number
75
76 class snapshot:
77     "State of the universe.  The galaxy is a 2D array of these."
78     def __init__(self):
79         self.crew = None        # crew complement
80         self.remkl = None       # remaining klingons
81         self.remcom = None      # remaining commanders
82         self.nscrem = None      # remaining super commanders
83         self.rembase = None     # remaining bases
84         self.starkl = None      # destroyed stars
85         self.basekl = None      # destroyed bases
86         self.nromrem = None     # Romulans remaining
87         self.nplankl = None     # destroyed uninhabited planets
88         self.nworldkl = None    # destroyed inhabited planets
89         self.plnets = [];       # List of planets known
90         self.date = None        # stardate
91         self.remres = None      # remaining resources
92         self. remtime = None    # remaining time
93         self.bases = []         # Base quadrant coordinates
94         self.kcmdr = []         # Commander quadrant coordinates
95         self.kscmdr = None      # Supercommander quadrant coordinates
96         self.galaxy = {}        # Dictionary of quadrant objects
97         self.chart = {}         # Dictionary of page objects
98
99 def damaged(dev):
100     return game.damage[dev] != 0.0
101
102 class event:
103     def __init__(self):
104         self.date = None        # The only mandatory attribute
105
106 class game:
107     def __init__(self):
108         self.options = []               # List of option strings
109         self.state = snapshot()         # State of the universe
110         self.snapsht = snapshot()       # For backwards timetravel
111         self.quad = {}                  # contents of our quadrant
112         self.kpower = {}                # enemy energy levels
113         self.kdist = {}                 # enemy distances
114         self.kavgd = {}                 # average distances
115         self.damage = {}                # damage encountered
116         self.future = []                # future events
117         self.passwd = None              # Self Destruct password
118         # Coordinate members start here
119         self.ks = {}                    # enemy sector locations
120         self.quadrant = None            # where we are
121         self.sector = None
122         self.tholian = None             # coordinates of Tholian
123         self.base = None                # position of base in current quadrant
124         self.battle = None              # base coordinates being attacked
125         self.plnet = None               # location of planet in quadrant
126         self.probec = None              # current probe quadrant
127         # Flag members start here
128         self.gamewon = None             # Finished!
129         self.ididit = None              # action taken -- allows enemy to attack
130         self.alive = None               # we are alive (not killed)
131         self.justin = None              # just entered quadrant
132         self.shldup = None              # shields are up
133         self.shldchg = None             # shield changing (affects efficiency)
134         self.comhere = None             # commander here
135         self.ishere = None              # super-commander in quadrant
136         self.iscate = None              # super commander is here
137         self.ientesc = None             # attempted escape from supercommander
138         self.ithere = None              # Tholian is here 
139         self.resting = None             # rest time
140         self.icraft = None              # Kirk in Galileo
141         self.landed = None              # party on planet or on ship
142         self.alldone = None             # game is now finished
143         self.neutz = None               # Romulan Neutral Zone
144         self.isarmed = None             # probe is armed
145         self.inorbit = None             # orbiting a planet
146         self.imine = None               # mining
147         self.icrystl = None             # dilithium crystals aboard
148         self.iseenit = None             # seen base attack report
149         self.thawed = None              # thawed game
150         # String members start here
151         self.condition = None           # green, yellow, red, docked, dead,
152         self.iscraft = None             # onship, offship, removed
153         self.skill = None               # levels: none, novice, fair, good,
154                                         # expert, emeritus
155         # Integer nembers sart here
156         self.inkling = None             # initial number of klingons
157         self.inbase = None              # initial number of bases
158         self.incom = None               # initial number of commanders
159         self.inscom = None              # initial number of commanders
160         self.inrom = None               # initial number of commanders
161         self.instar = None              # initial stars
162         self.intorps = None             # initial/max torpedoes
163         self.torps = None               # number of torpedoes
164         self.ship = None                # ship type -- 'E' is Enterprise
165         self.abandoned = None           # count of crew abandoned in space
166         self.length = None              # length of game
167         self.klhere = None              # klingons here
168         self.casual = None              # causalties
169         self.nhelp = None               # calls for help
170         self.nkinks = None              # count of energy-barrier crossings
171         self.iplnet = None              # planet # in quadrant
172         self.inplan = None              # initial planets
173         self.nenhere = None             # number of enemies in quadrant
174         self.irhere = None              # Romulans in quadrant
175         self.isatb = None               # =1 if super commander is attacking base
176         self.tourn = None               # tournament number
177         self.proben = None              # number of moves for probe
178         self.nprobes = None             # number of probes available
179         # Float members start here
180         self.inresor = None             # initial resources
181         self.intime = None              # initial time
182         self.inenrg = None              # initial/max energy
183         self.inshld = None              # initial/max shield
184         self.inlsr = None               # initial life support resources
185         self.indate = None              # initial date
186         self.energy = None              # energy level
187         self.shield = None              # shield level
188         self.warpfac = None             # warp speed
189         self.wfacsq = None              # squared warp factor
190         self.lsupres = None             # life support reserves
191         self.dist = None                # movement distance
192         self.direc = None               # movement direction
193         self.optime = None              # time taken by current operation
194         self.docfac = None              # repair factor when docking (constant?)
195         self.damfac = None              # damage factor
196         self.lastchart = None           # time star chart was last updated
197         self.cryprob = None             # probability that crystal will work
198         self.probex = None              # location of probe
199         self.probey = None              #
200         self.probeinx = None            # probe x,y increment
201         self.probeiny = None            #
202         self.height = None              # height of orbit around planet
203
204