-
Notifications
You must be signed in to change notification settings - Fork 3
/
ship.py
403 lines (286 loc) · 12.7 KB
/
ship.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# -*- coding: utf-8 -*-
"""
Created on Fri Dec 13 21:26:00 2019
Ship Datastructure
@author: Nuke Bloodaxe
"""
import pygame, crew, items, random, global_constants as g
import weaponsAndShields
# The engineering repair teams, historically there are three.
class RepairTeam(object):
def __init__(self):
self.job = 0 # system in damage array being worked on.
self.timeLeft = 0
self.jobType = 0
self.extra = 0
# The ship our crew are haunting...
# At this level we use game start values. On game load all of this is expected
# to be overwritten with the conents of the save file.
class Ship(object):
def __init__(self):
self.name = "De Bug"
self.gunNodes = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
self.gunMax = 0
self.armed = False
self.cargo = {}
self.cargoMax = 0
self.maxFuel = 0
self.fuel = 0
self.battery = 0
self.mass = 0
self.acceleration = 0
self.accelerationMax = 0
self.hullDamage = 0
self.hullMax = 0
self.fittedShield = ""
self.shieldLevel = 0
self.shieldMax = 15
self.shieldOptions = [0, 0 ,0]
self.frontHull = 1
self.centerHull = 1
self.rearHull = 1
self.options = [1, 20, 1, 1, 2, 1, 0, 1, 64, 0] #New Game start values.
#self.Crew() # debating about storing this here...
# Planetary System related variables: initialised to New Game values.
self.orbiting = 2 # Icarus.
self.planetarySystem = "OBAN"
self.positionX = 16.6
self.positionY = 22.6
self.positionZ = 3.3
self.planet = object # placeholder for later planet pointer.
# Engineering related variables
self.systemDamage = [25, 15, 2, 3, 16, 55, 22]#New game start values.
# Power Supply, Shield Control, Weapons Control, Engine,
# Life Support, Communications, Computer AI.
self.engineeringTaskDescription = ["Idle", "Power Supply",
"Shield Control", "Weapons Control",
"Engine", "Life Support",
"Communications", "Computer AI",
"Hull Damage", "Shield", "Weapon",
"Device", "Component", "Material",
"Artifact", "Other"]
self.repairType = ["Power Supply", "Shield Control", "Weapons Control",
"Engine", "Life Support", "Communications",
"Computer AI", "Hull Damage"]
self.engineeringTeam = [RepairTeam(),RepairTeam(),RepairTeam()]
# Prepare initial engineering job after new game start.
self.engineeringTeam[0].timeLeft = self.systemDamage[6]*70+random.randrange(1,30)
self.engineeringTeam[0].job = 6 # Area we are working on.
self.engineeringTeam[0].jobType = 0 # Repairing
self.research = 0
# Populate Cargo with initial items.
self.cargo["Probot"] = ["Probot", 2]
self.cargo["Dirk"] = ["Dirk", 1]
self.cargo["Minebot"] = ["Minebot", 1]
self.cargo["Manufactory"] = ["Manufactory", 1]
# Ship messages that need printing, not role specific.
self.shipMessages = []
# Get our current position as x,y,z values.
def getPosition(self):
return self.positionX, self.positionY, self.positionZ
# Get our orbit.
def getOrbit(self):
return self.orbiting
# Get the name of the System we are in as a string.
def getSystem(self):
return self.planetarySystem
# Get the current planetary body object as a planet object.
def getPlanet(self):
return self.planet
# Add a message to the pending messages queue, these are printed onscreen
# later. CrewMember is the EGO Synth containment unit number.
def addMessage(self, message, crewMember):
self.shipMessages.append((message, crewMember))
# Get a message from the pending messages queue. Returns an empty string
# when no messages are pending.
def getMessage(self):
if len(self.shipMessages) == 0:
return ("", -1) # No message.
return self.shipMessages.pop()
# Add an item to cargo, different to original.
# I've dispensed with the item limit, and am looking at the possibility
# of having items left behind if the hold fills. This eliminates the
# random loss of a cargo type if we overfill the hold.
# Returns cargo added success as boolean, alongside the remainder.
def addCargo(self, itemName, quantity):
cargoAdded = False
itemWeight = int(items.itemDictionary[itemName][1]) # .cargoSize
totalWeight = itemWeight * quantity
usedCargo = self.totalCargoSize()
quantityLeft = quantity
# TODO: Force Artifacts to add regardless of size.
if usedCargo + totalWeight > self.cargoMax:
while usedCargo + itemWeight <= self.cargoMax:
# Try to add as many possible into cargo hold.
try:
self.cargo[itemName][1] += 1
except:
self.cargo[itemName] = [itemName, 1]
usedCargo = self.totalCargoSize()
quantityLeft -= 1
cargoAdded = True
else:
try:
self.cargo[itemName][1] += quantity
except:
self.cargo[itemName] = [itemName, quantity]
cargoAdded = True
quantityLeft = 0
if quantityLeft > 0:
quantity = quantityLeft # Experiment.
if cargoAdded == False:
self.addMessage("Cargo Full!", 2)
self.addMessage(str(usedCargo)+'/'+str(self.cargoMax)+' used.', 2)
else:
self.addMessage("Cargo Filled During Transfer!", 2)
self.addMessage(str(usedCargo)+'/'+str(self.cargoMax)+' used.', 2)
self.addMessage(str(quantity)+" units were left behind!", 2)
return cargoAdded, quantityLeft
# Remove a quantity of cargo, returning True and the quantity remaining on
# success, else False and quantity removed.
def removeCargo(self, itemName, quantity):
cargoRemoved = False
quantityLeft = quantity
items = 0
try:
items = self.cargo[itemName][1]
except:
self.cargo[itemName] = [itemName, 0]
items = 0
if items >= quantity:
quantityLeft = items - quantity
cargoRemoved = True
elif items == 0:
self.addMessage("No " + itemName + " found in cargo!", 2)
quantityLeft = 0
else:
quantityLeft -= self.cargo[itemName][1]
self.cargo[itemName][1] = 0
return cargoRemoved, quantityLeft
# Get Item Count for a given item possibly in cargo.
def getItemQuantity(self, itemName):
try:
return self.cargo[itemName][1]
except:
self.addMessage("No " + itemName + " found in cargo!", 2)
return 0
# Find total cubic meters of all cargo in hold.
def totalCargoSize(self):
totalSize = 0
for itemName in self.cargo:
if self.cargo[itemName][1] >= 1:
count = self.cargo[itemName][1]
while count > 0:
totalSize += items.itemDictionary[itemName][1] # .cargoSize
count -= 1
return totalSize # This function does not judge...
# Check to see if we are overweight. Background switch determines
# if this is in the lower left corner log window, or somewhere else.
def checkOverweight(self, background = False):
overweight = False
# Role 2 for messages.
weight = self.totalCargoSize()
# Print a big dialogue message if it happens in the background.
# As to how that would happen... Tribbles?
if weight > self.cargoMax:
# Big dialogue box!
if background:
# TODO: Big Box functionality.
pass
else:
self.addMessage("Cargo Full!", 2)
self.addMessage(str(weight)+'/'+str(self.cargoMax)+' used.', 2)
self.addMessage('Must Jettison cargo.', 2)
overweight = True
return overweight # This function does judge...
# Check to see if adding an item is possible.
def willThisFit(self, item):
estimate = self.totalCargoSize() + items.itemDictionary[item][1] # .cargoSize
possible = True
if estimate > self.cargoMax:
possible = False
return possible
# Apply damage to the ship, mitigating it with the shield first.
# if Life Support fails, you die there and then.
def receiveDamage(self, totalDamage, PsychiDamage, particleDamage,
inertialDamage, energyDamage):
# TODO: Everything.
# First, find out how much damage the shield can absorb.
pass
# Apply power drain to battery
# Note: Apply weapons first, then the shield.
# Enhancement Possible: Power allocation % could be added.
def dischargeBattery(self):
pass
# Setup the ship stats according to the selected ship type and variation.
# Note: used during generation at the start of game.
def initialiseShip(self):
self.cargoMax = 0
self.name = ""
self.gunMax = 0
self.mass = 0
self.maxFuel = 0
self.hullMax = 0
if self.frontHull == 1:
self.name = "Heavy "
self.gunMax = 2
self.mass = 334
self.maxFuel = 200
self.hullMax = 200
elif self.frontHull == 2:
self.name = "Light "
self.gunMax = 1
self.mass = 334
self.maxFuel = 250
self.cargoMax = 50
self.hullMax = 150
else:
self.name = "Strategic "
self.gunMax = 3
self.mass = 501
self.maxFuel = 200
self.hullMax = 100
self.cargoMax = 0
if self.centerHull == 1:
self.name += "Shuttle "
self.gunMax += 3
self.mass += 501
self.maxFuel += 350
self.cargoMax += 50
self.hullMax += 700
elif self.centerHull == 2:
self.name += "Assault "
self.gunMax += 4
self.mass += 668
self.maxFuel += 300
self.cargoMax += 100
self.hullMax += 600
else:
self.name += "Storm "
self.gunMax += 5
self.mass += 835
self.maxFuel += 300
self.cargoMax += 50
self.hullMax += 600
if self.rearHull == 1:
self.name += "Transport"
self.gunMax += 0 # ?
self.cargoMax += 100
self.hullMax += 100
elif self.rearHull == 2:
self.name += "Frigate"
self.gunMax += 1
self.mass += 167
self.cargoMax += 50
self.hullMax += 100
else:
self.name += "Cruiser"
self.gunMax += 2
self.mass += 330
self.cargoMax += 50
self.acceleration = 270000/self.mass
# Recalculate the ship stats, normally used when checking after mass
# changes or the application of upgrades.
def recalculateShipStats(self):
self.acceleration = 270000/self.mass
# TODO: Add more changes here, recalculate all?