def read_exit(version, infileobj): new_exit = Exit() if version >= 041: new_exit.exitFlags = exitflags.bits_to_flag_set(read_uint16(infileobj)) else: new_exit.exitFlags = exitflags.bits_to_flag_set(read_uint8(infileobj)) if version >= 040: new_exit.doorFlags = doorflags.bits_to_flag_set(read_uint16(infileobj)) else: new_exit.doorFlags = doorflags.bits_to_flag_set(read_uint8(infileobj)) new_exit.door = read_qstring(infileobj) if "door" in new_exit.exitFlags: new_exit.exitFlags.add("exit") if not new_exit.door: new_exit.door = "exit" # Inbound connections are unneeded. connection = read_uint32(infileobj) while connection != UINT32_MAX: connection = read_uint32(infileobj) outConnections = [] connection = read_uint32(infileobj) while connection != UINT32_MAX: outConnections.append(str(connection)) connection = read_uint32(infileobj) if not outConnections: new_exit.to = "undefined" else: # We want the last outbound connection. new_exit.to = outConnections[-1] return new_exit
def __init__(self, fileName): # iterate through the rooms in the database, creating an object for each room. self.rooms = {} for element in self.getElements(fileName, "room"): obj = Room() obj.id = element.get("id") obj.x = element.get("x") obj.y = element.get("y") obj.z = element.get("z") obj.region = element.get("region") obj.terrain = element.get("terrain", "UNDEFINED") obj.name = element.findtext("roomname") obj.desc = element.findtext("desc") obj.note = element.findtext("note") obj.exits = [] for x in element.findall("./exits/exit"): newExit = Exit() newExit.dir = self.directionNames[x.get("dir")] newExit.to = x.get("to") newExit.door = x.get("door") obj.exits.append(newExit) obj.exits.sort(key=lambda k:self.directionNames.values().index(k.dir)) obj.setCost(obj.terrain) # Add a reference to the room object to our self.rooms dict, using the room ID as the key. self.rooms[obj.id] = obj
def __init__(self, fileName): # iterate through the rooms in the database, creating an object for each room. self.rooms = {} for element in self.getElements(fileName, "room"): obj = Room() obj.id = element.get("id") obj.x = element.get("x") obj.y = element.get("y") obj.z = element.get("z") obj.region = element.get("region") obj.terrain = element.get("terrain", "UNDEFINED") obj.name = element.findtext("roomname") obj.desc = element.findtext("desc") obj.note = element.findtext("note") obj.exits = [] for x in element.findall("./exits/exit"): newExit = Exit() newExit.dir = self.directionNames[x.get("dir")] newExit.to = x.get("to") newExit.door = x.get("door") obj.exits.append(newExit) obj.exits.sort( key=lambda k: self.directionNames.values().index(k.dir)) obj.setCost(obj.terrain) # Add a reference to the room object to our self.rooms dict, using the room ID as the key. self.rooms[obj.id] = obj
def read_exit(infileobj): new_exit = Exit() new_exit.exitFlags = exitflags.bits_to_flag_set(read_uint8(infileobj)) new_exit.doorFlags = doorflags.bits_to_flag_set(read_uint8(infileobj)) new_exit.door = read_qstring(infileobj) if "door" in new_exit.exitFlags: new_exit.exitFlags.add("exit") if not new_exit.door: new_exit.door = "exit" # Inbound connections are unneeded. connection = read_uint32(infileobj) while connection != UINT_MAX: connection = read_uint32(infileobj) outConnections = [] connection = read_uint32(infileobj) while connection != UINT_MAX: outConnections.append(str(connection)) connection = read_uint32(infileobj) if not outConnections: new_exit.to = "UNDEFINED" else: # We want the last outbound connection. new_exit.to = outConnections[-1] return new_exit