def parse(file, id=None): data = file.read(length) try: values = unpack(format, data) except: return -1 object = {} object["in flare id"] = values[0] object["out flare id"] = values[1] object["player body id"] = values[2] object["energy blob id"] = values[3] object["download url"] = values[5][: values[4]] object["title"] = values[7][: values[6]] object["author name"] = values[9][: values[8]] object["author url"] = values[11][: values[10]] object["version"] = values[12] object["min version"] = values[13] object["flags"] = decode.bitfield(values[14], flags) # discard checksum 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(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 = {} type = values[0] base = unpack(">3i", values[1]) tags = { "point": { "x": base[0], "y": base[1] }, "counter": { "player": base[0], "id": base[1], "amount": base[2], }, "signed": base[0], "unsigned": unpack("> I 8x", values[1])[0], } if type == 0: object["type"] = "none" elif type == 1: object["type"] = "location" object["location"] = tags["point"] elif type == 2: object["type"] = "counter" object["counter"] = tags["counter"] elif type == 3: object["type"] = "proximity" object["location"] = math.sqrt(tags["unsigned"]) elif type == 4: object["type"] = "owner" object["value"] = tags["signed"] elif type == 5: object["type"] = "destruction" object["value"] = tags["signed"] elif type == 6: object["type"] = "age" object["value"] = tags["signed"] elif type == 7: object["type"] = "time" object["value"] = tags["signed"] elif type == 8: object["type"] = "random" # object["value"] = tags["signed"] elif type == 9: object["type"] = "half health" # object["value"] = tags["signed"] elif type == 10: object["type"] = "is auxiliary" elif type == 11: object["type"] = "is target" elif type == 12: object["type"] = "counter greater" object["counter"] = tags["counter"] elif type == 13: object["type"] = "counter not" object["counter"] = tags["counter"] elif type == 14: object["type"] = "distance greater" object["value"] = tags["unsigned"] elif type == 15: object["type"] = "velocity less than or equal" object["value"] = tags["signed"] elif type == 16: object["type"] = "no ships left" object["player"] = tags["signed"] elif type == 17: object["type"] = "current message" object["id"] = tags["point"]["x"] object["page"] = tags["point"]["y"] elif type == 18: object["type"] = "current computer selection" object["screen"] = tags["point"]["x"] object["line"] = tags["point"]["y"] elif type == 19: object["type"] = "zoom level" object["value"] = tags["signed"] elif type == 20: object["type"] = "autopilot" elif type == 21: object["type"] = "not autopilot" elif type == 22: object["type"] = "object being built" elif type == 23: object["type"] = "direct is subject target" elif type == 24: object["type"] = "subject is player" object["subject"] = values[2] object["direct"] = values[3] object["actions"] = { "first": values[4], "count": values[5], } object["flags"] = decode.bitfield(values[6], flags) # object["direction"] = values[7] #UNUSED? return object