class PositionState(object): """ Keeps track of the collider's current test state. """ def __init__(self): # Current position. self.pos = Vector3() # Current bounding box to test. self.bbox = Rectangle() self.reset(self.pos, 0, 0) def reset(self, pos, radius, height): # Size to test. self.radius = radius self.height = height # Outermost z coordinates. self.floorz = -0x8000 self.ceilz = 0x8000 # Blocked by a linedef. self.blockline = False # Blocked by a thing. self.blockthing = False # Blocked by a steep slope. self.steep = False # The element's sector's ceiling or floor can move during gameplay. self.floor_moves = False self.ceiling_moves = False # This position's special sector index. self.special_sector = None # This position's floor plane. self.floor_plane = None self.pos.copy_from(pos) self.bbox.set( pos.x - radius, pos.y - radius, pos.x + radius, pos.y + radius )
def connect_teleporters(self): """ Creates area connections for teleporter line types. """ count = 0 rect = Rectangle() for teleporter in self.map_data.teleporters: target_area = None # Get the area that the teleporter target is in. if teleporter.kind == Teleporter.TELEPORTER_THING: floorz = self.map_data.get_floor_z(teleporter.dest.x, teleporter.dest.y) target_area = self.get_area_at(teleporter.dest, floorz) if teleporter.kind == Teleporter.TELEPORTER_LINE: dest = Vector2() dest.x, dest.y = self.map_data.get_line_center(teleporter.dest_line) floorz = self.map_data.get_floor_z(teleporter.dest.x, teleporter.dest.y) target_area = self.get_area_at(dest, floorz) # Ignore missing teleport targets. if target_area is None: print 'Teleporter linedef {} does not point to a place on the map with navigation areas.'.format(teleporter.source_line) continue # Create the teleport connection line from the linedef vertices. linedef = self.map_data.linedefs[teleporter.source_line] rect.set( linedef.vertex1.x, linedef.vertex1.y, linedef.vertex2.x, linedef.vertex2.y ) # Place a teleporter connection in all intersecting source areas. areas = self.get_areas_intersecting(rect) for area in areas: connection = Connection() connection.rect.copy_from(rect) connection.area_a = area connection.area_b = target_area connection.linedef = teleporter.source_line connection.flags = Connection.FLAG_AB | Connection.FLAG_TELEPORTER area.connections.append(connection) count += 1 print 'Connected {} teleporters.'.format(count)
class Node(MapObject): """ A Doom node map object. """ __slots__ = ( 'x', 'y', 'delta_x', 'delta_y', 'bb_right', 'bb_left', 'children' ) STRUCT_DOOM = struct.Struct('<hhhhhhhhhhhhHH') STRUCT_HEXEN = struct.Struct('<hhhhhhhhhhhhHH') WAD_INDEX = 7 # Indicates that the node index is actually a subsector index. FLAG_SUBSECTOR = 0x8000 # Child node index. CHILD_RIGHT = 0 CHILD_LEFT = 1 def __init__(self, x=0, y=0): self.x = 0 self.y = 0 self.delta_x = 0 self.delta_y = 0 self.bb_right = Rectangle() self.bb_left = Rectangle() self.children = [0, 0] def unpack_from(self, data, is_hexen): self.x = data[0] self.y = data[1] self.delta_x = data[2] self.delta_y = data[3] self.bb_right.set(data[4], data[5], data[6], data[7]) self.bb_left.set(data[8], data[9], data[10], data[11]) self.children[0] = data[12] self.children[1] = data[13] def set_references(self, map_data): pass def __repr__(self): return 'Node: x {}, y {}, right {}, left {}'.format(self.x, self.y, self.bb_right, self.bb_left)