def parse(file, id = None): data = file.read(length) try: values = unpack(format, data) except: return None object = {} object["id"] = values[0] #apparent color #illegal colors object["advantage"] = decode.fixed(values[3]) object["singular"] = strings.get(4201, 4*id + 0) object["plural"] = strings.get(4201, 4*id + 1) object["military"] = strings.get(4201, 4*id + 2) object["home world"] = strings.get(4201, 4*id + 3) return object
def parse(file, id): data = file.read(size) try: values = unpack(format, data) except: return None object = {} object["type"] = values[0] object["owner"] = values[1] #These do not seem to seem to be used in the scenario #so I have disabled them. #object["real object number"] = values[2] #object["real object id"] = values[3] object["position"] = { "x": values[4], "y": values[5], } object["earning"] = decode.fixed(values[6]) object["distance range"] = values[7] object["rotation"] = { "minumum": values[8], "range": values[9], } object["sprite id override"] = values[10] object["builds"] = {} for i in range(11,22): if values[i] >= 1: object["builds"][i-11] = values[i] object["initial destination"] = values[23] if values[24] >= 1: #and values[24] != 4400: #stupid try: object["name override"] = strings.db[str(values[24])][values[25] - 1] except: pass #I will deal with this later, only if it causes problems object["attributes"] = decode.bitfield(values[26], attributes) return object
def parse(file, id = None): data = file.read(size) try: values = unpack(format, data) except: return None object = {} object["reflexive"] = values[1] object["inclusive filter"] = values[2] object["exclusive filter"] = values[3] object["owner"] = values[4] object["delay"] = values[5] object["subject override"] = values[6] object["direct override"] = values[7] type = values[0] if type == 0: object["type"] = "none" elif type == 1 or type == 17: if type == 17: object["type"] = "create object set destination" else: object["type"] = "create object" sub = unpack(">iii??i 6x", values[8]) object["base type"] = sub[0] object["min"] = sub[1] object["range"] = sub[2] object["velocity relative"] = sub[3] object["direction relative"] = sub[4] object["distance range"] = sub[5] elif type == 2: object["type"] = "play sound" sub = unpack(">B x i? x iiii", values[8]) object["priority"] = sub[0] object["persistence"] = sub[1] object["is absolute"] = sub[2] object["volume"] = sub[3] object["volume range"] = sub[4] object["sound id"] = sub[5] object["sound range"] = sub[6] elif type == 3: object["type"] = "alter" stype, relative, min, range = unpack("> B?ii 14x", values[8]) if stype == 0: object["alter type"] = "health" object["value"] = min elif stype == 1: object["alter type"] = "velocity" object["relative"] = relative object["minimum"] = min object["range"] = range elif stype == 2: object["alter type"] = "thrust" object["relative"] = relative object["minimum"] = min object["range"] = range elif stype == 3: object["alter type"] = "max thrust" object["value"] = min elif stype == 4: object["alter type"] = "max velocity" object["value"] = min elif stype == 5: object["alter type"] = "max turn rate" object["value"] = min elif stype == 6: object["alter type"] = "location" object["relative"] = relative object["minimum"] = min object["range"] = range elif stype == 7: #I don't think this is used in the scenario so I can't really test it object["alter type"] = "scale" object["value"] = min elif stype == 8: object["alter type"] = "pulse weapon" object["id"] = min elif stype == 9: object["alter type"] = "beam weapon" object["id"] = min elif stype == 10: object["alter type"] = "special weapon" object["id"] = min elif stype == 11: object["alter type"] = "energy" object["value"] = min elif stype == 12: object["alter type"] = "owner" object["use objects owner"] = relative object["value"] = min elif stype == 13: object["alter type"] = "hidden" object["minimum"] = min object["range"] = range elif stype == 14: object["alter type"] = "cloak" elif stype == 15: object["alter type"] = "offline" object["minimum"] = min object["range"] = range elif stype == 16: object["alter type"] = "current turn rate" object["minimum"] = min object["range"] = range elif stype == 17: object["alter type"] = "base type" object["retain ammo count"] = relative object["id"] = min elif stype == 18: object["alter type"] = "active condition" object["condition true"] = relative #find better name object["minimum"] = min object["range"] = range elif stype == 19: object["alter type"] = "occupation" object["value"] = min elif stype == 20: object["alter type"] = "absolute cash" object["use objects owner"] = relative object["value"] = min object["player"] = range elif stype == 21: object["alter type"] = "age" object["relative"] = relative object["minimum"] = min object["range"] = range # elif stype == 22: # object["alter type"] = "attributes" # elif stype == 23: # object["alter type"] = "level key" # elif stype == 24: # object["alter type"] = "order key" # elif stype == 25: # object["alter type"] = "engage key" elif stype == 26: object["alter type"] = "absolute location" object["relative"] = relative object["x"] = min object["y"] = range elif type == 4: object["type"] = "make sparks" sub = unpack(">ii i B 11x", values[8]) object["count"] = sub[0] object["velocity"] = sub[1] object["velocity range"] = decode.fixed(sub[2]) object["color"] = sub[3] elif type == 5: object["type"] = "release energy" sub = unpack(">i 20x", values[8]) object["percent"] = decode.fixed(sub[0]) elif type == 6: object["type"] = "land at" sub = unpack(">i 20x", values[8]) object["speed"] = sub[0] elif type == 7: object["type"] = "enter warp" sub = unpack(">i 20x", values[8]) object["warp speed"] = sub[0] elif type == 8: object["type"] = "display message" sub = unpack(">hh 20x", values[8]) object["id"] = sub[0] object["page"] = sub[1] elif type == 9: object["type"] = "change score" sub = unpack("> iii 12x", values[8]) object["player"] = sub[0] object["score"] = sub[1] object["amount"] = sub[2] elif type == 10: object["type"] = "declare winner" sub = unpack("> iii 12x", values[8]) object["player"] = sub[0] object["next level"] = sub[1] object["text"] = sub[2] elif type == 11: object["type"] = "die" sub = unpack("> b 23x", values[8])[0] if sub == 0: object["how"] = "plain" elif sub == 1: object["how"] = "expire" elif sub == 2: object["how"] = "destroy" elif sub == 3: object["how"] = "both" elif type == 12: object["type"] = "set destination" elif type == 13: object["type"] = "activate special" elif type == 14: object["type"] = "activate pulse" elif type == 15: object["type"] = "activate beam" elif type == 16: object["type"] = "color flash" sub = unpack("> i BB 18x", values[8]) object["duration"] = sub[0] object["color"] = sub[1] object["shade"] = sub[2] elif type == 17: #see action #1 (create object action) pass elif type == 18: object["type"] = "nil target" elif type == 19: object["type"] = "disable keys" sub = unpack("> I 20x", values[8]) object["key mask"] = sub[0] elif type == 20: object["type"] = "enable keys" sub = unpack("> I 20x", values[8]) object["key mask"] = sub[0] elif type == 21: object["type"] = "set zoom level" sub = unpack("> i 20x", values[8]) object["value"] = sub[0] elif type == 22: object["type"] = "computer select" sub = unpack("> ii 16x", values[8]) object["screen"] = sub[0] object["line"] = sub[1] elif type == 23: object["type"] = "assume initial object" sub = unpack("> i 20x", values[8]) object["id"] = sub[0] return object
def parse(file, id = None): data = file.read(length) try: values = struct.unpack(format, data) except: return None object = {} object["attributes"] = decode.bitfield(values[0], attributes) object["class"] = values[1] object["race"] = values[2] object["price"] = values[3] object["offence"] = decode.fixed(values[4]) object["escort rank"] = values[5]#aka target, aka destination class object["max velocity"] = decode.fixed(values[6]) object["warp speed"] = decode.fixed(values[7]) object["warp out distance"] = values[8] object["initial velocity"] = decode.fixed(values[9]) object["initial velocity range"] = decode.fixed(values[10]) mass = decode.fixed(values[11]) if mass == 0: mass = 1.0 object["mass"] = mass object["thrust"] = decode.fixed(values[12]) object["health"] = values[13] object["damage"] = values[14] object["energy"] = values[15] object["initial age"] = values[16] object["initial age range"] = values[17] #add occuping force hack object["scale"] = values[18] #was natural scale object["layer"] = values[19] object["sprite id"] = values[20] object["icon size"] = 0x0f & values[21] try: object["icon shape"] = { 0x00: "square", 0x10: "triangle", 0x20: "diamond", 0x30: "plus", 0x40: "framed square" }[0x70 & values[21]] except KeyError: object["icon shape"] = None object["shield color"] = values[22] #**** compiler alignment object["initial direction"] = values[23] object["initial direction range"] = values[24] object["weapons"] = { "pulse": { "id": values[25], "count": values[28], "positions": {}, }, "beam": { "id": values[26], "count": values[29], "positions": {}, }, "special": { "id": values[27], "count": values[30], "positions": {}, }, } ct = 31 for weap in ["pulse", "beam", "special"]: for idx in range(0, object["weapons"][weap]["count"]): object["weapons"][weap]["positions"][idx + 1] = { "y": decode.fixed(values[ct+2*idx]), "x": decode.fixed(values[ct+2*idx+1]), } ct += 6 object["friend defecit"] = decode.fixed(values[49]) object["danger threshold"] = decode.fixed(values[50]) object["special direction"] = values[51] #unused? object["arrive action distance"] = values[52] object["actions"] = { "destroy": { "first": values[53], "count": values[54] & 0x7fffffff, "dont die on death": bool(values[54] & 0x80000000), }, "expire": { "first": values[55], "count": values[56], }, "create": { "first": values[57], "count": values[58], }, "collide": { "first": values[59], "count": values[60], }, "activate": { "first": values[61], "count": values[62] & 0x0000ffff, "interval": (values[62] & 0xff000000) >> 24, "interval range": (values[62] & 0x00ff0000) >> 16, }, "arrive": { "first": values[63], "count": values[64], }, } if object["attributes"]["shape from direction"] == True: frame = struct.unpack(">iiii 16x", values[65]) object["rotation"] = { "offset": frame[0], "resolution": frame[1], "turn rate": decode.fixed(frame[2]), "turn acceleration": decode.fixed(frame[3]), } elif object["attributes"]["is self animated"] == True: frame = struct.unpack(">8i", values[65]) object["animation"] = { "first shape": frame[0], "last shape": frame[1], "direction": frame[2], "direction range": frame[3], "speed": frame[4], "speed range": frame[5], "shape": frame[6], "shape range": frame[7], } elif object["attributes"]["is beam"] == True: frame = struct.unpack(">BBii 22x", values[65]) object if frame[1] == 0: object["beam"] = { "hex": 0x0, #000 "type": "kinetic", "mode": None, } elif frame[1] == 1: object["beam"] = { "hex": 0x2, #010 "type": "static", "mode": "direct", } elif frame[1] == 2: object["beam"] = { "hex": 0x3, #011 "type": "static", "mode": "relative", } elif frame[1] == 3: object["beam"] = { "hex": 0x4, #100 "type": "bolt", "mode": "direct", } elif frame[1] == 4: object["beam"] = { "hex": 0x5, #101 "type": "bolt", "mode": "relative", } object["beam"]["color"] = frame[0] object["beam"]["accuracy"] = frame[2] object["beam"]["range"] = math.sqrt(frame[3]) else: #device frame = struct.unpack(">Iiiiiii 4x", values[65]) object["device"] = { "uses": decode.bitfield(frame[0], deviceUses), "energy cost": frame[1], "reload": frame[2], "ammo": frame[3], "range": frame[4], "inverse speed": frame[5], "restock cost": frame[6], } object["build flags"] = decode.bitfield(values[66], buildFlags) object["order flags"] = decode.bitfield(values[67], orderFlags) object["build ratio"] = decode.fixed(values[68]) object["build time"] = values[69] object["skill num"] = values[70] object["skill den"] = values[71] object["skill num adj"] = values[72] object["skill den adj"] = values[73] object["portrait id"] = values[74] if id != None: object["name"] = strings.get(5000, id) object["short name"] = strings.get(5001, id) object["notes"] = strings.get(5002, id) object["static name"] = strings.get(5003, id) return object
def parse(file, id = None): data = file.read(size) try: values = unpack(format, data) except: return None object = {} object["net race flags"] = values[0] object["player num"] = values[1] object["players"] = {} for i in range(0, object["player num"]): player = {} type = values[2+6*i+0] if type == 0: player["type"] = "single" elif type == 1: player["type"] = "net" elif type == 2: player["type"] = "cpu" player["race"] = values[2+6*i+1] player["name"] = strings.get(values[2+6*i+2], values[2+6*i+3]- 1) #player["admiral number"] = values[2+8*i+4] #unused it seems player["earning power"] = decode.fixed(values[2+6*i+4]) player["net race flags"] = values[2+6*i+5] object["players"][i+1] = player if values[26] > 0: object["score string"] = strings.get(values[26], True) else: object["score string"] = [] object["initial objects"] = { "first": values[27], "count": values[29], } object["prologue"] = strings.get(values[28]) object["epilogue"] = strings.get(values[32]) object["song id"] = values[30] object["conditions"] = { "first": values[31], "count": values[33], } object["starmap"] = { "x": values[34], "y": values[36], } object["angle"] = values[37] object["briefing"] = { "first": values[35], "count": values[38], } object["par"] = { "time": values[39], "kills": values[41], "ratio": decode.fixed(values[43]), "losses": values[44], } if values[40] > -1: object["movie"] = strings.get(4500, values[40]) else: object["movie"] = None object["id"] = values[42] object["name"] = strings.get(4600, values[42]-1) object["start time"] = 0x7fff & values[45] object["is training"] = (0x8000 & values[45]) == True return object