mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-18 09:57:40 +03:00
Updates generation of ships.p and modules.p
In doing so also fixes up outfitting.py for Int_DroneControl_ResourceSiphon
This commit is contained in:
parent
2c26216e13
commit
074cf8a119
20
coriolis.py
20
coriolis.py
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/env python
|
||||||
#
|
#
|
||||||
# build ship and module databases from https://github.com/EDCD/coriolis-data/
|
# build ship and module databases from https://github.com/EDCD/coriolis-data/
|
||||||
#
|
#
|
||||||
@ -6,7 +6,7 @@
|
|||||||
import csv
|
import csv
|
||||||
import base64
|
import base64
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
import cPickle
|
import pickle
|
||||||
import json
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
@ -39,15 +39,15 @@ if __name__ == "__main__":
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Symbolic name from in-game name
|
# Symbolic name from in-game name
|
||||||
reverse_ship_map = {v: k for k, v in companion.ship_map.items()}
|
reverse_ship_map = {v: k for k, v in list(companion.ship_map.items())}
|
||||||
|
|
||||||
bulkheads = outfitting.armour_map.keys()
|
bulkheads = list(outfitting.armour_map.keys())
|
||||||
|
|
||||||
ships = {}
|
ships = {}
|
||||||
modules = {}
|
modules = {}
|
||||||
|
|
||||||
# Ship and armour masses
|
# Ship and armour masses
|
||||||
for m in data['Ships'].values():
|
for m in list(data['Ships'].values()):
|
||||||
name = coriolis_ship_map.get(m['properties']['name'], str(m['properties']['name']))
|
name = coriolis_ship_map.get(m['properties']['name'], str(m['properties']['name']))
|
||||||
assert name in reverse_ship_map, name
|
assert name in reverse_ship_map, name
|
||||||
ships[name] = { 'hullMass' : m['properties']['hullMass'] }
|
ships[name] = { 'hullMass' : m['properties']['hullMass'] }
|
||||||
@ -55,11 +55,11 @@ if __name__ == "__main__":
|
|||||||
modules['_'.join([reverse_ship_map[name], 'armour', bulkheads[i]])] = { 'mass': m['bulkheads'][i]['mass'] }
|
modules['_'.join([reverse_ship_map[name], 'armour', bulkheads[i]])] = { 'mass': m['bulkheads'][i]['mass'] }
|
||||||
|
|
||||||
ships = OrderedDict([(k,ships[k]) for k in sorted(ships)]) # sort for easier diffing
|
ships = OrderedDict([(k,ships[k]) for k in sorted(ships)]) # sort for easier diffing
|
||||||
cPickle.dump(ships, open('ships.p', 'wb'))
|
pickle.dump(ships, open('ships.p', 'wb'))
|
||||||
|
|
||||||
# Module masses
|
# Module masses
|
||||||
for cat in data['Modules'].values():
|
for cat in list(data['Modules'].values()):
|
||||||
for grp, mlist in cat.items():
|
for grp, mlist in list(cat.items()):
|
||||||
for m in mlist:
|
for m in mlist:
|
||||||
assert 'symbol' in m, m
|
assert 'symbol' in m, m
|
||||||
key = str(m['symbol'].lower())
|
key = str(m['symbol'].lower())
|
||||||
@ -91,7 +91,7 @@ if __name__ == "__main__":
|
|||||||
add(modules, 'hpt_multicannon_fixed_medium_advanced', { 'mass': 4 })
|
add(modules, 'hpt_multicannon_fixed_medium_advanced', { 'mass': 4 })
|
||||||
|
|
||||||
modules = OrderedDict([(k,modules[k]) for k in sorted(modules)]) # sort for easier diffing
|
modules = OrderedDict([(k,modules[k]) for k in sorted(modules)]) # sort for easier diffing
|
||||||
cPickle.dump(modules, open('modules.p', 'wb'))
|
pickle.dump(modules, open('modules.p', 'wb'))
|
||||||
|
|
||||||
# Check data is present for all modules
|
# Check data is present for all modules
|
||||||
with open('outfitting.csv') as csvfile:
|
with open('outfitting.csv') as csvfile:
|
||||||
@ -100,5 +100,5 @@ if __name__ == "__main__":
|
|||||||
try:
|
try:
|
||||||
module = outfitting.lookup({ 'id': row['id'], 'name': row['symbol'] }, companion.ship_map)
|
module = outfitting.lookup({ 'id': row['id'], 'name': row['symbol'] }, companion.ship_map)
|
||||||
except:
|
except:
|
||||||
print row['symbol']
|
print(row['symbol'])
|
||||||
print_exc()
|
print_exc()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
import cPickle
|
import pickle
|
||||||
from os.path import join
|
from os.path import join
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -350,7 +350,7 @@ def lookup(module, ship_map, entitled=False):
|
|||||||
|
|
||||||
# Lazily populate
|
# Lazily populate
|
||||||
if not moduledata:
|
if not moduledata:
|
||||||
moduledata.update(cPickle.load(open(join(config.respath, 'modules.p'), 'rb')))
|
moduledata.update(pickle.load(open(join(config.respath, 'modules.p'), 'rb')))
|
||||||
|
|
||||||
# if not module.get('category'): raise AssertionError('%s: Missing category' % module['id']) # only present post 1.3, and not present in ship loadout
|
# if not module.get('category'): raise AssertionError('%s: Missing category' % module['id']) # only present post 1.3, and not present in ship loadout
|
||||||
if not module.get('name'): raise AssertionError('%s: Missing name' % module['id'])
|
if not module.get('name'): raise AssertionError('%s: Missing name' % module['id'])
|
||||||
@ -464,7 +464,12 @@ def lookup(module, ship_map, entitled=False):
|
|||||||
(new['class'], new['rating']) = (str(name[2][4:]), 'A')
|
(new['class'], new['rating']) = (str(name[2][4:]), 'A')
|
||||||
elif len(name) < 4 and name[1] in ['guardianfsdbooster']: # Hack! No class.
|
elif len(name) < 4 and name[1] in ['guardianfsdbooster']: # Hack! No class.
|
||||||
(new['class'], new['rating']) = (str(name[2][4:]), 'H')
|
(new['class'], new['rating']) = (str(name[2][4:]), 'H')
|
||||||
|
elif len(name) < 4 and name[0] == 'dronecontrol' and name[1] == 'resourcesiphon':
|
||||||
|
# 128066402,Int_DroneControl_ResourceSiphon,internal,Limpet Control,,,,1,I,
|
||||||
|
(new['class'], new['rating']) = (1, 'I')
|
||||||
else:
|
else:
|
||||||
|
if len(name) < 3:
|
||||||
|
raise AssertionError('%s: length < 3]' % (name))
|
||||||
if not name[2].startswith('size') or not name[3].startswith('class'): raise AssertionError('%s: Unknown class/rating "%s/%s"' % (module['id'], name[2], name[3]))
|
if not name[2].startswith('size') or not name[3].startswith('class'): raise AssertionError('%s: Unknown class/rating "%s/%s"' % (module['id'], name[2], name[3]))
|
||||||
new['class'] = str(name[2][4:])
|
new['class'] = str(name[2][4:])
|
||||||
new['rating'] = (name[1]=='buggybay' and planet_rating_map or
|
new['rating'] = (name[1]=='buggybay' and planet_rating_map or
|
||||||
@ -490,7 +495,7 @@ def lookup(module, ship_map, entitled=False):
|
|||||||
if __debug__:
|
if __debug__:
|
||||||
m = moduledata.get(key, {})
|
m = moduledata.get(key, {})
|
||||||
if not m:
|
if not m:
|
||||||
print 'No data for module %s' % key
|
print('No data for module %s' % key)
|
||||||
elif new['name'] == 'Frame Shift Drive':
|
elif new['name'] == 'Frame Shift Drive':
|
||||||
assert 'mass' in m and 'optmass' in m and 'maxfuel' in m and 'fuelmul' in m and 'fuelpower' in m, m
|
assert 'mass' in m and 'optmass' in m and 'maxfuel' in m and 'fuelmul' in m and 'fuelpower' in m, m
|
||||||
else:
|
else:
|
||||||
@ -518,13 +523,13 @@ def export(data, filename):
|
|||||||
|
|
||||||
h = open(filename, 'wt')
|
h = open(filename, 'wt')
|
||||||
h.write(header)
|
h.write(header)
|
||||||
for v in data['lastStarport'].get('modules', {}).itervalues():
|
for v in list(data['lastStarport'].get('modules', {}).values()):
|
||||||
try:
|
try:
|
||||||
m = lookup(v, companion.ship_map)
|
m = lookup(v, companion.ship_map)
|
||||||
if m:
|
if m:
|
||||||
h.write('%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n' % (rowheader, m['category'], m['name'], m.get('mount',''), m.get('guidance',''), m.get('ship',''), m['class'], m['rating'], m['id'], data['timestamp']))
|
h.write('%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n' % (rowheader, m['category'], m['name'], m.get('mount',''), m.get('guidance',''), m.get('ship',''), m['class'], m['rating'], m['id'], data['timestamp']))
|
||||||
except AssertionError as e:
|
except AssertionError as e:
|
||||||
if __debug__: print 'Outfitting: %s' % e # Silently skip unrecognized modules
|
if __debug__: print('Outfitting: %s' % e) # Silently skip unrecognized modules
|
||||||
except:
|
except:
|
||||||
if __debug__: raise
|
if __debug__: raise
|
||||||
h.close()
|
h.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user