def macro_plat(self, bi, si):
        '''Make a plat

		Note that we don't specify the size of plat here as
		later we need to make it either at the top or the bottom of the larger
		brush.'''
        origin = utils.getPoint(bi['origin'])
        size = utils.getPoint(bi['extent'])
        if 'texture' in bi:
            texture = 'texture=\'' + bi['texture'] + '\' '
        else:
            texture = ''
        if 'position' in si:
            pos = si['position']  # dcp.UP or dcp.DOWN (top or bottomw
        else:
            utils.error('plat given without a position (up or down)')

        super().startElement(
            'solid', {
                'origin': str(origin),
                'extent': str(size),
                'texture': texture,
                'type': 'plat',
                'position': pos
            })
        super().endElement('solid')
Esempio n. 2
0
def processHollow(doc, parent, worldtype, worldspawn, s, offset, hollow):
    o = utils.getPoint(hollow.getAttribute('origin')) + offset
    e = utils.getPoint(hollow.getAttribute('extent'))
    style = hollow.getAttribute('style')
    holes = {}
    absentwalls = []
    # FIXME the following is where we see if this hollow contains an
    # absentwalls element and a holes element before proceeding.  It's
    # implemented in a bit of a hacky way; we ought to be using SAX but then it
    # would be a *lot* more work to create the output XML.  This way we can
    # just change what's there a bit.
    for hollowChild in hollow.childNodes:
        if hollowChild.localName == 'absentwalls':
            # Get absent walls info...
            for absentwall in hollowChild.childNodes:
                wall = absentwall.getAttribute('value')
                absentwalls.append(wall)
            utils.insertPlaceholder(doc, hollow, hollowChild)
        elif hollowChild.localName == 'holes':
            # Get holes info...
            for hole in hollowChild.childNodes:
                wall = hole.getAttribute('wall')
                # If we've not added a hole to this wall yet then set up an empty array...
                if wall not in holes:
                    holes[wall] = []
                o_x, o_y = hole.getAttribute('origin').split()
                e_x, e_y = hole.getAttribute('extent').split()
                type = hole.getAttribute('type')
                if type == connector.DOOR:
                    key = hole.getAttribute('key')
                    button = hole.getAttribute('button')  # FIXME test real map
                else:
                    key = button = None  # FIXME test real map
                # FIXME deal with other types
                holes[wall].append(
                    utils.Hole2D(utils.Point2D(float(o_x), float(o_y)),
                                 utils.Point2D(float(e_x), float(e_y)), type,
                                 {'key': key}))
            # FIXME we shouldn't need to detect overlapping holes here because
            # they'll be detected higher up (by overlapping connected hollows)
            utils.insertPlaceholder(doc, hollow, hollowChild)

    # Now we have the required structural info (absent walls and holes), we can
    # turn this hollow into a series of textured brushes...
    io, ie = utils.makeHollow(doc, worldtype, worldspawn, s, o, e, absentwalls,
                              holes, style)
    # Contained solids, hollows and entities...
    for node in hollow.childNodes:
        processNode(doc, hollow, worldtype, worldspawn, s, io, node)
    # We can't remove the child or we screw over tree traversal (urgh)...
    utils.insertPlaceholder(doc, parent, hollow)
Esempio n. 3
0
def processEntity(doc, parent, offset, entity):
    # Adjust coords...
    for property in entity.childNodes:  # assume all children are property nodes
        if property.getAttribute('name') == 'origin':
            o = utils.getPoint(property.getAttribute('value')) + offset
            property.setAttribute('value', str(o))
    # Clone node (inc properties) and add to map...
    doc.documentElement.appendChild(entity.cloneNode(True))
Esempio n. 4
0
 def _get_bounds(self, hollow_attrs):
     '''Work out the internal cube of the hollow.'''
     extent = utils.getPoint(hollow_attrs['extent'])
     return extent - Point(prog.lip * 2, prog.lip * 2, prog.lip * 2)
    def macro_stairs(self, bi, si):
        '''Make some stairs

		we see this as a 2D problem then add the missing dimension later
		(width/depth) dir tells us in which dir the steps go up length is the
		distance from start of lowest to end of heighest step height is the
		height of the highest step'''
        # FIXME cope with being able to make a hole through (under) the stairs
        origin = utils.getPoint(bi['origin'])
        size = utils.getPoint(bi['extent'])
        dir = si['dir']
        texture = ''
        if 'texture' in bi:
            texture = bi['texture']
        slength = 0
        sheight = float(si['stepheight'])
        parts = []
        parts3d = []

        # FIXME repeated code: n/e == s/w -- collapse into 2?

        # Work out which dimension is which
        if dir == dcp.NORTH:
            # use X and Y; Z rising with increasing Y
            length = size.y
            height = size.z
            width = size.x
            flip = False
            parts = self._macro_stairs_core(length, height, width, flip,
                                            slength, sheight, texture)
            for part in parts:
                part3d = utils.Region3D(
                    Point(0, part.origin.x, part.origin.y) + origin,
                    Point(width, part.extent.x, part.extent.y))
                parts3d.append(part3d)
        elif dir == dcp.SOUTH:
            # use X and Y; Z falling with increasing Y
            length = size.y
            height = size.z
            width = size.x
            flip = True
            parts = self._macro_stairs_core(length, height, width, flip,
                                            slength, sheight, texture)
            for part in parts:
                part3d = utils.Region3D(
                    Point(0, part.origin.x, part.origin.y) + origin,
                    Point(width, part.extent.x, part.extent.y))
                parts3d.append(part3d)
        elif dir == dcp.EAST:
            # use X and Y; Z rising with increasing X
            length = size.x
            height = size.z
            width = size.y
            flip = False
            parts = self._macro_stairs_core(length, height, width, flip,
                                            slength, sheight, texture)
            for part in parts:
                part3d = utils.Region3D(
                    Point(part.origin.x, 0, part.origin.y) + origin,
                    Point(part.extent.x, width, part.extent.y))
                parts3d.append(part3d)
        elif dir == dcp.WEST:
            # use X and y; Z falling with increasing X
            length = size.x
            height = size.z
            width = size.y
            flip = True
            parts = self._macro_stairs_core(length, height, width, flip,
                                            slength, sheight, texture)
            for part in parts:
                part3d = utils.Region3D(
                    Point(part.origin.x, 0, part.origin.y) + origin,
                    Point(part.extent.x, width, part.extent.y))
                parts3d.append(part3d)
        else:
            utils.error(
                'invalid direction specified for stairs (up and down are currently '
                'unsupported)')

        for part3d in parts3d:
            super().startElement(
                'solid', {
                    'origin': str(part3d.origin),
                    'extent': str(part3d.extent),
                    'texture': texture,
                    'type': 'step'
                })
            super().endElement('solid')
Esempio n. 6
0
def processSolid(doc, parent, worldtype, worldspawn, sf, offset, solid):
    style = parent.getAttribute('style')
    o = utils.getPoint(solid.getAttribute('origin')) + offset
    e = utils.getPoint(solid.getAttribute('extent'))
    type = solid.getAttribute('type')
    if not type:
        utils.error('solid with no type')
    f = solid.getAttribute('holeface')
    # Get holes info...
    # FIXME this is repeated code from the hollow one -- any way we can
    # refactor it?
    props = {}
    holes = []
    # Check if the solid has children (holes).
    # If so, split it up.
    # If not, just add it.
    if solid.hasChildNodes():
        for hole in solid.childNodes:
            ho_x, ho_y = hole.getAttribute('origin').split()
            he_x, he_y = hole.getAttribute('extent').split()
            type = hole.getAttribute('type')
            if not type:
                pass
            elif type == connector.DOOR:
                props['key'] = hole.getAttribute('key')
            else:
                utils.warning(
                    'only doors allowed as hole types; not plats or others.')
            # FIXME deal with other types
            holes.append(
                utils.Hole2D(utils.Point2D(float(ho_x), float(ho_y)),
                             utils.Point2D(float(he_x), float(he_y)), type,
                             props))
        # Built split (2D) parts into 3D brushes; mapping of coords to 3D
        # depends on which direction/face the hole was constructed in.
        if f == dcp.NORTH:
            parts = split.splitWall(
                utils.Region2D(utils.Point2D(o.x, o.z),
                               utils.Point2D(e.x, e.z)), holes)
            for part in parts:
                part3d = utils.addDim(part, dims.Y, o.y, e.y)
                utils.makeBrush(doc, worldtype, worldspawn, sf, style, part3d,
                                f)
        elif f == dcp.UP:
            parts = split.splitWall(
                utils.Region2D(utils.Point2D(o.x, o.y),
                               utils.Point2D(e.x, e.y)), holes)
            for part in parts:
                part3d = utils.addDim(part, dims.Z, o.z + prog.lip_small,
                                      e.z - prog.lip_small * 2)
                utils.makeBrush(doc, worldtype, worldspawn, sf, style, part3d,
                                f)
            else:
                utils.error('Unsupported holeface ' + f +
                            ' requested for hole in solid.')
    else:
        # Doesn't have child nodes...
        if not type or type == connector.STEP:
            pass  # no properties to set
        elif type == connector.DOOR:
            props['key'] = solid.getAttribute('key')
        elif type == connector.PLAT:
            props['position'] = solid.getAttribute('position')
        else:
            utils.warning('unknown type ' + type + ' specifed.')

        brush = utils.Region3D(Point(o.x, o.y, o.z), Point(e.x, e.y, e.z),
                               type, props)
        utils.makeBrush(doc, worldtype, worldspawn, sf, style, brush, type)
    # We can't remove the child or we screw over tree traversal (urgh)...
    utils.insertPlaceholder(doc, parent, solid)