Exemple #1
0
 def mark_hallway(self, mat):
     ''' Handy way to mark the location of a hall trap on the map. For
     debugging.'''
     for p in iterate_cube(
             self.position, self.position + self.dw * (self.size - 1) +
             self.dl * (self.length - 1)):
         self.parent.setblock(p, mat)
Exemple #2
0
 def mark_hallway(self, mat):
     ''' Handy way to mark the location of a hall trap on the map. For
     debugging.'''
     for p in iterate_cube(
         self.position,
         self.position + self.dw * (self.size - 1) + self.dl * (self.length - 1)
     ):
         self.parent.setblock(p, mat)
Exemple #3
0
 def render(self):
     pn = perlin.SimplexNoise(256)
     # Find all the valid halls. These are halls with a size > 0.
     # We'll store a random position within the range of the hall.
     halls = [0, 0, 0, 0]
     hallcount = 0
     wires = set()
     #wirehooks = set()
     for h in xrange(4):
         if (self.parent.halls[h].size > 0):
             halls[h] = \
                 self.parent.halls[h].offset + 1 + \
                 random.randint(0, self.parent.halls[h].size - 3)
             hallcount += 1
     # We won't draw just half a bridge, unless this is a sandpit. (yet)
     if (hallcount < 2 and self.sandpit is False):
         return
     midpoint = self.parent.parent.room_size / 2
     y = self.parent.canvasHeight()
     offset = self.parent.loc
     # Look for the X bounds between halls.
     if (halls[0] != 0 and halls[2] != 0):
         x1 = halls[0]
         x2 = halls[2]
     elif (halls[0] != 0):
         x1 = halls[0]
         x2 = x1
     elif (halls[2] != 0):
         x2 = halls[2]
         x1 = x2
     else:
         x1 = midpoint
         x2 = midpoint
     # Look for the Z bounds between halls.
     if (halls[1] != 0 and halls[3] != 0):
         z1 = halls[1]
         z2 = halls[3]
     elif (halls[1] != 0):
         z1 = halls[1]
         z2 = z1
     elif (halls[3] != 0):
         z2 = halls[3]
         z1 = z2
     else:
         z1 = midpoint
         z2 = midpoint
     # Now construct our points.
     # c1-4 are the corners of the connecting
     # box. h0-3 are the start points of the halls.
     c1 = Vec(x1, y, z1)
     c2 = Vec(x2, y, z1)
     c3 = Vec(x2, y, z2)
     c4 = Vec(x1, y, z2)
     h0 = Vec(x1, y, self.parent.hallLength[0])
     h1 = Vec(self.parent.parent.room_size - self.parent.hallLength[1] - 1,
              y, z1)
     h2 = Vec(x2, y,
              self.parent.parent.room_size - self.parent.hallLength[2] - 1)
     h3 = Vec(self.parent.hallLength[3], y, z2)
     # Sandpit?
     mat = random.choice(self.slabtypes)
     if (self.sandpit is True):
         # Draw the false sand floor
         mat = materials.Sand
         c = self.parent.canvasCenter()
         y = self.parent.canvasHeight()
         r = random.randint(1, 1000)
         maxd = max(1, self.parent.canvasWidth(),
                    self.parent.canvasLength())
         for x in utils.iterate_points_inside_flat_poly(
                 *self.parent.canvas):
             p = x + self.parent.loc
             d = ((Vec2f(x.x, x.z) - c).mag()) / maxd
             n = (pn.noise3(
                 (p.x + r) / 4.0, y / 4.0, p.z / 4.0) + 1.0) / 2.0
             if (n >= d + .10):
                 self.parent.parent.setblock(p, materials.Sand)
             elif (n >= d):
                 self.parent.parent.setblock(p, materials.Gravel)
             else:
                 self.parent.parent.setblock(p, materials._floor)
         # Find wire locations
         # h0
         # Cool fact: in 12w30c tripwires will trigger sand without hooks.
         if (halls[0] != 0):
             for x in xrange(1, self.parent.halls[0].size - 1):
                 p = Vec(self.parent.halls[0].offset + x, y - 1,
                         self.parent.hallLength[0])
                 # if x == 0:
                 #    wirehooks.add((p, 4+3))
                 # elif x == self.parent.halls[0].size-1:
                 #    wirehooks.add((p, 4+1))
                 # else:
                 #    wires.add(p)
                 wires.add(p)
         # h1
         if (halls[1] != 0):
             for x in xrange(1, self.parent.halls[1].size - 1):
                 wires.add(
                     Vec((self.parent.parent.room_size -
                          self.parent.hallLength[1] - 1), y - 1,
                         self.parent.halls[1].offset + x))
         # h2
         if (halls[2] != 0):
             for x in xrange(1, self.parent.halls[2].size - 1):
                 wires.add(
                     Vec(self.parent.halls[2].offset + x, y - 1,
                         (self.parent.parent.room_size -
                          self.parent.hallLength[2] - 1)))
         # h3
         if (halls[3] != 0):
             for x in xrange(1, self.parent.halls[3].size - 1):
                 wires.add(
                     Vec(self.parent.hallLength[3], y - 1,
                         self.parent.halls[3].offset + x))
         for p in wires:
             self.parent.parent.setblock(offset + p.down(1),
                                         materials.Gravel,
                                         lock=True)
             self.parent.parent.setblock(offset + p,
                                         materials.Tripwire,
                                         hide=True)
         # for p in wirehooks:
         #    self.parent.parent.setblock(offset+p[0].down(1), mat)
         #    self.parent.parent.setblock(offset+p[0],
         #                                materials.TripwireHook, p[1])
     # Draw the bridges, if a hallway exists.
     # h0 -> c1
     # h1 -> c2
     # h2 -> c3
     # h3 -> c4
     if (halls[0] != 0):
         for p in utils.iterate_cube(offset + h0, offset + c1):
             self.parent.parent.setblock(p, mat)
     if (halls[1] != 0):
         for p in utils.iterate_cube(offset + h1, offset + c2):
             self.parent.parent.setblock(p, mat)
     if (halls[2] != 0):
         for p in utils.iterate_cube(offset + h2, offset + c3):
             self.parent.parent.setblock(p, mat)
     if (halls[3] != 0):
         for p in utils.iterate_cube(offset + h3, offset + c4):
             self.parent.parent.setblock(p, mat)
     # Draw the connecting bridges.
     # c1 -> c2
     # c2 -> c3
     # c3 -> c4
     for p in utils.iterate_cube(offset + c1, offset + c2):
         self.parent.parent.setblock(p, mat)
     for p in utils.iterate_cube(offset + c2, offset + c3):
         self.parent.parent.setblock(p, mat)
     for p in utils.iterate_cube(offset + c3, offset + c4):
         self.parent.parent.setblock(p, mat)
Exemple #4
0
    def render(self):
        # Figure out what sort of thing will be fired
        name = weighted_choice(cfg.master_projectile_traps)
        data_tag = cfg.lookup_projectile_traps[name][2]
        name = cfg.lookup_projectile_traps[name][0]

        # Start position
        pos = self.position.down(5) + self.dl - self.dw

        # Materials lookup
        # Default is looking East
        mat = {
            'RW': [materials.RedstoneWire, 0],
            '*>': [materials.RedstoneRepeaterOff, 2],
            '<*': [materials.RedstoneRepeaterOff, 0],
            'C1': [materials.CommandBlock, 0],
            'C2': [materials.CommandBlock, 0],
            '[]': [materials.StoneBrick, 3],
            '~P': [materials.StonePressurePlate, 0],
            '~T': [materials.TNT, 0],
        }

        # Commands
        cmds = {
            'C1': '/summon {0} ~ ~3 ~1.8 {{Motion:{1},direction:{1},{2}}}'.format(
                name,
                '[0.0,0.2,1.0]',
                data_tag),
            'C2': '/summon {0} ~ ~3 ~-1.8 {{Motion:{1},direction:{1},{2}}}'.format(
                name,
                '[0.0,0.2,-1.0]',
                data_tag)}

        # If looking South, rotate some materials, and adjust the command
        # blocks.
        if self.direction == dirs.S:
            mat['*>'][1] = 1
            mat['<*'][1] = 3
            cmds = {
                'C1': '/summon {0} ~1.8 ~3 ~ {{Motion:{1},direction:{1},{2}}}'.format(
                    name,
                    '[1.0,0.2,0.0]',
                    data_tag),
                'C2': '/summon {0} ~-1.8 ~3 ~ {{Motion:{1},direction:{1},{2}}}'.format(
                    name,
                    '[-1.0,0.2,0.0]',
                    data_tag)}

        # Trap template.
        # tmpl[level][dl][dw]
        tmpl = [[
            ['C1', '<*', 'RW', '*>', 'C2'],
        ], [
            ['XX', 'XX', 'XX', 'XX', 'XX'],
        ], [
            ['XX', 'XX', '~P', 'XX', 'XX'],
        ], [
            ['XX', '[]', 'XX', '[]', 'XX'],
        ]]

        # Make boom!
        if self._explosions:
            tmpl[0][0][2] = '~T'
            tmpl[0][0][0] = '[]'
            tmpl[0][0][4] = '[]'

        # Repetitions for each template row and column.
        reps = {
            'w': [1, 1, self.size - 2, 1, 1],
            'l': [self.length - 2],
        }

        self.apply_template(tmpl, cmds, mat, reps, pos)

        # Vary the timing on the repeaters
        for p in iterate_cube(
            self.position.down(5),
            self.position.down(5) + self.dw * (self.size - 1) + self.dl * (self.length - 1)
        ):
            if (
                p in self.parent.blocks and
                self.parent.blocks[p].material == materials.RedstoneRepeaterOff
            ):
                self.parent.blocks[p].data += random.choice((4, 8, 12))
Exemple #5
0
 def render(self):
     pn = perlin.SimplexNoise(256)
     # Find all the valid halls. These are halls with a size > 0.
     # We'll store a random position within the range of the hall.
     halls = [0, 0, 0, 0]
     hallcount = 0
     wires = set()
     #wirehooks = set()
     for h in xrange(4):
         if (self.parent.halls[h].size > 0):
             halls[h] = \
                 self.parent.halls[h].offset + 1 + \
                 random.randint(0, self.parent.halls[h].size - 3)
             hallcount += 1
     # We won't draw just half a bridge, unless this is a sandpit. (yet)
     if (hallcount < 2 and self.sandpit is False):
         return
     midpoint = self.parent.parent.room_size / 2
     y = self.parent.canvasHeight()
     offset = self.parent.loc
     # Look for the X bounds between halls.
     if (halls[0] != 0 and halls[2] != 0):
         x1 = halls[0]
         x2 = halls[2]
     elif (halls[0] != 0):
         x1 = halls[0]
         x2 = x1
     elif (halls[2] != 0):
         x2 = halls[2]
         x1 = x2
     else:
         x1 = midpoint
         x2 = midpoint
     # Look for the Z bounds between halls.
     if (halls[1] != 0 and halls[3] != 0):
         z1 = halls[1]
         z2 = halls[3]
     elif (halls[1] != 0):
         z1 = halls[1]
         z2 = z1
     elif (halls[3] != 0):
         z2 = halls[3]
         z1 = z2
     else:
         z1 = midpoint
         z2 = midpoint
     # Now construct our points.
     # c1-4 are the corners of the connecting
     # box. h0-3 are the start points of the halls.
     c1 = Vec(x1, y, z1)
     c2 = Vec(x2, y, z1)
     c3 = Vec(x2, y, z2)
     c4 = Vec(x1, y, z2)
     h0 = Vec(x1,
              y,
              self.parent.hallLength[0])
     h1 = Vec(self.parent.parent.room_size - self.parent.hallLength[1] - 1,
              y,
              z1)
     h2 = Vec(x2,
              y,
              self.parent.parent.room_size - self.parent.hallLength[2] - 1)
     h3 = Vec(self.parent.hallLength[3],
              y,
              z2)
     # Sandpit?
     mat = random.choice(self.slabtypes)
     if (self.sandpit is True):
         # Draw the false sand floor
         mat = materials.Sand
         c = self.parent.canvasCenter()
         y = self.parent.canvasHeight()
         r = random.randint(1, 1000)
         maxd = max(1,
                    self.parent.canvasWidth(),
                    self.parent.canvasLength())
         for x in utils.iterate_points_inside_flat_poly(
             *self.parent.canvas
         ):
             p = x + self.parent.loc
             d = ((Vec2f(x.x, x.z) - c).mag()) / maxd
             n = (
                 pn.noise3(
                     (p.x + r) / 4.0,
                     y / 4.0,
                     p.z / 4.0) + 1.0) / 2.0
             if (n >= d + .10):
                 self.parent.parent.setblock(p, materials.Sand)
             elif (n >= d):
                 self.parent.parent.setblock(p, materials.Gravel)
             else:
                 self.parent.parent.setblock(p, materials._floor)
         # Find wire locations
         # h0
         # Cool fact: in 12w30c tripwires will trigger sand without hooks.
         if (halls[0] != 0):
             for x in xrange(1, self.parent.halls[0].size - 1):
                 p = Vec(self.parent.halls[0].offset + x,
                         y - 1,
                         self.parent.hallLength[0])
                 # if x == 0:
                 #    wirehooks.add((p, 4+3))
                 # elif x == self.parent.halls[0].size-1:
                 #    wirehooks.add((p, 4+1))
                 # else:
                 #    wires.add(p)
                 wires.add(p)
         # h1
         if (halls[1] != 0):
             for x in xrange(1, self.parent.halls[1].size - 1):
                 wires.add(
                     Vec(
                         (self.parent.parent.room_size -
                          self.parent.hallLength[1] - 1),
                         y - 1,
                         self.parent.halls[1].offset + x
                     )
                 )
         # h2
         if (halls[2] != 0):
             for x in xrange(1, self.parent.halls[2].size - 1):
                 wires.add(
                     Vec(
                         self.parent.halls[2].offset + x,
                         y - 1,
                         (self.parent.parent.room_size -
                          self.parent.hallLength[2] - 1)
                     )
                 )
         # h3
         if (halls[3] != 0):
             for x in xrange(1, self.parent.halls[3].size - 1):
                 wires.add(
                     Vec(
                         self.parent.hallLength[3],
                         y - 1,
                         self.parent.halls[3].offset + x
                     )
                 )
         for p in wires:
             self.parent.parent.setblock(
                 offset + p.down(1),
                 materials.Gravel,
                 lock=True
             )
             self.parent.parent.setblock(offset + p,
                                         materials.Tripwire, hide=True)
         # for p in wirehooks:
         #    self.parent.parent.setblock(offset+p[0].down(1), mat)
         #    self.parent.parent.setblock(offset+p[0],
         #                                materials.TripwireHook, p[1])
     # Draw the bridges, if a hallway exists.
     # h0 -> c1
     # h1 -> c2
     # h2 -> c3
     # h3 -> c4
     if (halls[0] != 0):
         for p in utils.iterate_cube(offset + h0, offset + c1):
             self.parent.parent.setblock(p, mat)
     if (halls[1] != 0):
         for p in utils.iterate_cube(offset + h1, offset + c2):
             self.parent.parent.setblock(p, mat)
     if (halls[2] != 0):
         for p in utils.iterate_cube(offset + h2, offset + c3):
             self.parent.parent.setblock(p, mat)
     if (halls[3] != 0):
         for p in utils.iterate_cube(offset + h3, offset + c4):
             self.parent.parent.setblock(p, mat)
     # Draw the connecting bridges.
     # c1 -> c2
     # c2 -> c3
     # c3 -> c4
     for p in utils.iterate_cube(offset + c1, offset + c2):
         self.parent.parent.setblock(p, mat)
     for p in utils.iterate_cube(offset + c2, offset + c3):
         self.parent.parent.setblock(p, mat)
     for p in utils.iterate_cube(offset + c3, offset + c4):
         self.parent.parent.setblock(p, mat)