-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathitems.py
367 lines (273 loc) · 12.6 KB
/
items.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
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 25 19:32:51 2019
Item Datastructures
@author: Nuke Bloodaxe
"""
import io, os, random
import global_constants as g
itemDictionary = {}
itemConstructionDictionary = {}
# Items are divided into the following types:
# Weapons, Shields, Devices, Components, Materials, Elements, Artifacts.
# Artifacts will be implmented later, they are a special case.
# Base object parameters.
# Note: The dictionary is working so well I might dispense with this.
class Item(object):
def __init__(self, name, cargoSize, worth, levels, itemType):
self.name = name
self.cargoSize = cargoSize
self.worth = worth
self.levels = levels # These appear to be the level requirements
# for each type of crew member. [6 crew, 6 levels.]
# [psychometry, engineering, science, security, astrogation, medical]
self.description # Item description.
self.itemType # The item type.
# This data should be added to a dictionary, by name, on load.
# By tradition, the Iron Seed three items requirement is used.
class createItem(Item):
def __init__(self, name, cargoSize, worth, levels, part1, part2, part3):
self.part1 = part1
self.part2 = part2
self.part3 = part3
Item.__init__(self,name,cargoSize,worth,levels)
# Find a random item of a given "type" category at the limit in items.
# Returns the item's name.
def getRandomItem(itemType, limit):
rando = random.randint(1, limit)
foundTypeCount = 0
for item in itemDictionary:
if itemDictionary[item][2] == itemType:
foundTypeCount += 1
if foundTypeCount == rando:
return item
# Get the item name of "type" at "count" position, this effectively acts as
# primative array traversal.
def getItemOfType(itemType, count):
foundTypeCount = 0
for item in itemDictionary:
if itemDictionary[item][2] == itemType:
foundTypeCount += 1
if foundTypeCount == count:
return item
# We look for the item and return the position as though the dictionary was an
# array. We are assuming the item exists.
def findItemInPseudoArray(item):
itemType = itemDictionary[item][2]
foundTypeCount = 0
for searchItem in itemDictionary:
if itemDictionary[searchItem][2] == itemType:
foundTypeCount += 1
if searchItem == item:
return foundTypeCount - 1
# Find the item and return a valid random alternate name for the item.
# If there is no alternate name, return normal item name.
# We assume the item exists in dictionary.
def getAlternateName(item):
name = ""
#print("Item: ", item)
try:
alternateNames = itemDictionary[item][6]
name = random.choice(alternateNames)
except IndexError:
name = itemDictionary[item][0]
except KeyError:
name = "" # Unknown Item.
return name
# Generate all artifacts from the names Given in an array.
# Also generate fixed special artifacts.
def generateArtifacts(names):
for count in range(900): # IronSeed has 900 generated elements.
#print(count)
if count > 500:
name = names[int((((count-501)/10))%19+41)]+' '+names[int(((count-501)%10)+50)]
else:
name = names[int((count/20)+1)]+' '+names[int(count%20+21)]
size = int(count%40)+1
#print(name)
try:
itemDictionary[name] = [name,
size,
"ARTIFACT",
0,[1,1,1,1,1,1]]
except:
print("Tried Key: ", name)
# Usually indicates the file we are loading is incorrectly
# formatted. If you are modding, double-check your tabs.
print("Absolutely fatal error on creating Artifacts")
# Append hard-coded artifacts, these are special plot items.
itemDictionary["Shunt Drive"] = ["Shunt Drive",
0,
"ARTIFACT",
0,[1,1,1,1,1,1]]
itemDictionary["Channeler"] = ["Channeler",
0,
"ARTIFACT",
0,[1,1,1,1,1,1]]
itemDictionary["Iron Seed"] = ["Iron Seed",
0,
"ARTIFACT",
0,[1,1,1,1,1,1]]
itemDictionary["Homing Device"] = ["Homing Device",
0,
"ARTIFACT",
0,[1,1,1,1,1,1]]
itemDictionary["Detonator"] = ["Detonator",
0,
"ARTIFACT",
0,[1,1,1,1,1,1]]
itemDictionary["Thermal Plating"] = ["Thermal Plating",
0,
"ARTIFACT",
0,[1,1,1,1,1,1]]
itemDictionary["Ermigen Data Tapes"] = ["Ermigen Data Tapes",
0,
"ARTIFACT",
0,[1,1,1,1,1,1]]
itemDictionary["Glyptic Scythe"] = ["Glyptic Scythe",
0,
"ARTIFACT",
0,[1,1,1,1,1,1]]
itemDictionary["Multi-Imager"] = ["Multi-Imager",
0,
"ARTIFACT",
0,[1,1,1,1,1,1]]
itemDictionary["Ylinth Mutagenics"] = ["Ylinth Mutagenics",
0,
"ARTIFACT",
0,[1,1,1,1,1,1]]
itemDictionary["Goolas"] = ["Goolas",
0,
"ARTIFACT",
0,[1,1,1,1,1,1]]
# End of get random item functions. These exist to make things easier.
# Populate the item and item construction dictionaries.
# we load from two different data files to do this, tab delimited.
# Data Order: Name, cargosize, worth, part1, part2, part3, levels
def loadItemData(loadAndSetup,
file1=os.path.join('Data_Generators', 'Other', 'IronPy_items.tab'),
file2=os.path.join('Data_Generators', 'Other', 'IronPy_itemdata.tab'),
file3=os.path.join('Data_Generators', 'Other', 'IronPy_iteminfo.tab'),
file4=os.path.join('Data_Generators', 'Other', 'IronPy_alternateItemNames.tab'),
file5=os.path.join('Data_Generators', 'Other', 'IronPy_anomalyNames.tab')):
itemFile = io.open(file1, "r")
itemString = itemFile.readline() # title line
itemString = itemFile.readline() # spacer line
itemString = itemFile.readline() # real data
constructFile = io.open(file2, "r")
constString = constructFile.readline() # title line
constString = constructFile.readline() # spacer line
constString = constructFile.readline() # real data
iteminfoFile = io.open(file3, "r")
iteminfoString = iteminfoFile.readline() # immediate real data
alternateNamesFile = io.open(file4, "r")
alternateNamesString = alternateNamesFile.readline() # immediate real data.
anomalyNamesFile = io.open(file5, "r")
anomalyNamesFileString = anomalyNamesFile.readline() # immediate real data.
S1 = itemString # used plenty, so must be short, is read string from file.
S2 = constString # Used plenty, so must be short, is read string from file.
S3 = iteminfoString # Used plenty, so must be short, is read string from file.
S4 = alternateNamesString # Used plenty, so must be short, is read string from file.
S5 = anomalyNamesFileString
# 20% increments on progress bar.
progress = 0
loadAndSetup.setProcessStep(0)
while S2 != "":
decodedConst = S2.split('\t')
requiredCrewLevels = [] # remove the \n and make elements ints.
for integer in decodedConst[5:]:
if integer != '\n':
requiredCrewLevels.append(int(integer))
# Item to create, Part 1, Part 2, Part 3, Worth, Required crew levels.
itemConstructionDictionary[decodedConst[0]] = [decodedConst[0],
decodedConst[1],
decodedConst[2],
decodedConst[3],
int(decodedConst[4]),
requiredCrewLevels]
S2 = constructFile.readline()
loadAndSetup.update(progress)
progress = 20
while S1 != "":
decodedItem = S1.split('\t')
dump = decodedItem[2].split('\n') # removing newline
decodedItem[2] = dump[0]
# Name, Cargo Size, Item Type, Item Worth, Required Crew Levels.
try:
itemDictionary[decodedItem[0]] = [decodedItem[0],
int(decodedItem[1]),
decodedItem[2],
itemConstructionDictionary[decodedItem[0]][4],
itemConstructionDictionary[decodedItem[0]][5]]
except KeyError:
# We don't care about missing items.
# We set these up as singular instances.
try:
itemDictionary[decodedItem[0]] = [decodedItem[0],
int(decodedItem[1]),
decodedItem[2],
0,[1,1,1,1,1,1]]
except:
print("Tried Key: ", decodedItem[0])
# Usually indicates the file we are loading is incorrectly
# formatted. If you are modding, double-check your tabs.
print("Absolutely fatal error on creating items")
S1 = itemFile.readline()
loadAndSetup.update(progress)
progress = 40
# Add item descriptions.
while S3 != "ENDF":
itemName = S3.split('\n')[0]
S3 = iteminfoFile.readline().split('\n')[0]
itemDescription = []
while S3 != "EOD" and S3 != "ENDF":
itemDescription.append(S3)
S3 = iteminfoFile.readline().split('\n')[0]
try:
itemDictionary[itemName].append(itemDescription)
except KeyError:
print("Tried Key: ", itemName)
# Usually indicates the file we are loading is incorrectly
# formatted. If you are modding, double-check your item
# files, as you may have a spelling mistake in the key names.
print("Absolutely fatal error on adding item description.")
# An Item Description has now been loaded.
S3 = iteminfoFile.readline()
loadAndSetup.update(progress)
progress = 60
# Add alternate item names.
while S4 != "ENDF":
itemName, alternateName = "", ""
alternateNames = []
while S4 != "EOD" and S4 != "ENDF":
#print(S4)
itemName, alternateName = S4.split('\n')[0].split('\t', 1)
#print("Item Name: ", itemName, "Alternate Name: ", alternateName)
alternateNames.append(alternateName)
S4 = alternateNamesFile.readline().split('\n')[0]
try:
itemDictionary[itemName].append(alternateNames)
except KeyError:
print("Tried Key: ", itemName)
# Usually indicates the file we are loading is incorrectly
# formatted. If you are modding, double-check your item
# files, as you may have a spelling mistake in the key names.
print("Absolutely fatal error on adding item alternate Names.")
# An Item Description has now been loaded.
S4 = alternateNamesFile.readline().split('\n')[0]
loadAndSetup.update(progress)
# Add Artifact names.
artifactSubNamesArray = []
progress = 80
while S5 != "ENDF":
artifactSubNamesArray.append(S5)
S5 = anomalyNamesFile.readline().split('\n')[0]
loadAndSetup.update(progress)
progress = 100
loadAndSetup.update(progress)
generateArtifacts(artifactSubNamesArray)
itemFile.close()
constructFile.close()
iteminfoFile.close()
alternateNamesFile.close()
anomalyNamesFile.close()