From 2dcea2d086811c5b6f5ffa06862348077cf6cc48 Mon Sep 17 00:00:00 2001 From: orphu Date: Thu, 24 Apr 2014 17:56:02 -0400 Subject: [PATCH] Code cleanup via autopep8. To everyone merging this commit, I am truly sorry. I'll keep this kind of thing to a minimum in the future. --- cave_demo.py | 30 +- cave_factory.py | 67 +- cfg.py | 14 +- doors.py | 1 + dungeon.py | 1199 +++++++++--------- dungeon_name_test.py | 4 +- features.py | 1843 +++++++++++++-------------- floors.py | 158 +-- hall_traps.py | 143 +-- halls.py | 78 +- items.py | 53 +- loottable.py | 244 ++-- mapstore.py | 191 +-- materials.py | 14 +- mcdungeon.py | 76 +- namegenerator.py | 38 +- perlin.py | 646 +++++----- perlin_test.py | 3 +- pmeter.py | 15 +- rooms.py | 2833 ++++++++++++++++++++++-------------------- ruins.py | 813 ++++++------ utils.py | 258 ++-- 22 files changed, 4520 insertions(+), 4201 deletions(-) diff --git a/cave_demo.py b/cave_demo.py index a35d0ef9..7164d79f 100755 --- a/cave_demo.py +++ b/cave_demo.py @@ -7,12 +7,12 @@ cave = cave_factory.new(16, 16) # North width = randrange(1, 5) -offset = randrange(1, 16-width) -cave.add_exit((0, offset), (0, offset+width)) +offset = randrange(1, 16 - width) +cave.add_exit((0, offset), (0, offset + width)) # South width = randrange(1, 5) -offset = randrange(1, 16-width) -cave.add_exit((15, offset), (15, offset+width)) +offset = randrange(1, 16 - width) +cave.add_exit((15, offset), (15, offset + width)) # Cave! cave.gen_map() cave.print_map() @@ -33,15 +33,15 @@ cave = cave_factory.new(32, 32) # East width = randrange(1, 5) -offset = randrange(1, 16-width) -cave.add_exit((31, offset), (31, offset+width)) +offset = randrange(1, 16 - width) +cave.add_exit((31, offset), (31, offset + width)) width = randrange(1, 5) -offset = randrange(16, 32-width) -cave.add_exit((31, offset), (31, offset+width)) +offset = randrange(16, 32 - width) +cave.add_exit((31, offset), (31, offset + width)) # South width = randrange(1, 5) -offset = randrange(1, 32-width) -cave.add_exit((offset, 31), (offset+width, 31)) +offset = randrange(1, 32 - width) +cave.add_exit((offset, 31), (offset + width, 31)) # Cave! cave.gen_map(mode='room') cave.print_map() @@ -49,14 +49,14 @@ cave.resize_map(48, 48) cave.print_map() -#del(cave) +# del(cave) #cave = cave_factory.new(32, 32) #cave.add_exit((offset, 0), (offset+width, 0)) -#cave.gen_map() -#cave.print_map() +# cave.gen_map() +# cave.print_map() -#for p in cave.iterate_map(cave_factory.FLOOR): +# for p in cave.iterate_map(cave_factory.FLOOR): # print p -#for p in cave.iterate_map(cave_factory.WALL): +# for p in cave.iterate_map(cave_factory.WALL): # print p diff --git a/cave_factory.py b/cave_factory.py index 1a5376fe..8b4f5456 100644 --- a/cave_factory.py +++ b/cave_factory.py @@ -22,6 +22,7 @@ class new: + def __init__(self, length, width, walls=0.40): self.__length = length self.__width = width @@ -30,13 +31,13 @@ def __init__(self, length, width, walls=0.40): self.__buf_map = [] self.__gen_initial_map(walls) self.__ds = DisjointSet() - self.__cpt = (int(self.__length/2), int(self.__width/2)) + self.__cpt = (int(self.__length / 2), int(self.__width / 2)) def resize_map(self, new_length, new_width, center=True): new_map = [[WALL for i in xrange(new_width)] for j in xrange(new_length)] - ox = int(new_width/2.0-self.__width/2.0+0.5) - oy = int(new_length/2.0-self.__length/2.0+0.5) + ox = int(new_width / 2.0 - self.__width / 2.0 + 0.5) + oy = int(new_length / 2.0 - self.__length / 2.0 + 0.5) for i in xrange(self.__width): for j in xrange(self.__length): x2 = ox + i @@ -52,7 +53,7 @@ def resize_map(self, new_length, new_width, center=True): self.__length = new_length self.__width = new_width self.__exits = [] - self.__cpt = (int(self.__length/2), int(self.__width/2)) + self.__cpt = (int(self.__length / 2), int(self.__width / 2)) def print_map(self): for c in xrange(0, self.__width): @@ -98,8 +99,8 @@ def purge_exits(self): for c in xrange(0, self.__width): for r in xrange(0, self.__length): if ( - c == 0 or c == self.__width-1 or - r == 0 or r == self.__length-1 + c == 0 or c == self.__width - 1 or + r == 0 or r == self.__length - 1 ): self.__map[r][c] == WALL @@ -117,8 +118,8 @@ def gen_map(self, mode='default'): self.__generation(1, 5, -1) else: # Windey passages. - #Repeat 4: W?(p) = R1(p) ? 5 || R2(p) ? 2 - #Repeat 3: W?(p) = R1(p) ? 5 + # Repeat 4: W?(p) = R1(p) ? 5 || R2(p) ? 2 + # Repeat 3: W?(p) = R1(p) ? 5 # We do the above, with a cave join pass right before the final # iteration. This helps smooth out any sharp edges after the join # pass. @@ -133,8 +134,8 @@ def __generation(self, count, r1_cutoff, r2_cutoff): for j in xrange(self.__length)] self.__gen_walls(self.__buf_map) self.__gen_walls(self.__map) - for r in xrange(1, self.__length-1): - for c in xrange(1, self.__width-1): + for r in xrange(1, self.__length - 1): + for c in xrange(1, self.__width - 1): adjcount_r1 = self.__adj_wall_count(r, c, 1) adjcount_r2 = self.__adj_wall_count(r, c, 2) if(adjcount_r1 >= r1_cutoff or @@ -158,11 +159,11 @@ def rwall(fillprob): def __gen_walls(self, a_map): for j in range(0, self.__length): a_map[j][0] = WALL - a_map[j][self.__width-1] = WALL + a_map[j][self.__width - 1] = WALL for j in range(0, self.__width): a_map[0][j] = WALL - a_map[self.__length-1][j] = WALL + a_map[self.__length - 1][j] = WALL # Force the exits to be floor. We grow them out from the edge a bit to # make sure they don't get sealed off. @@ -170,12 +171,12 @@ def __gen_walls(self, a_map): a_map[pos[0]][pos[1]] = FLOOR for pos2 in ((-1, 0), (1, 0), (0, -1), (0, 1), (-2, 0), (2, 0), (0, -2), (0, 2)): - p = (pos[0]+pos2[0], pos[1]+pos2[1]) + p = (pos[0] + pos2[0], pos[1] + pos2[1]) if (p[0] < 1 or p[1] < 1): continue if ( - p[0] >= self.__width-1 or - p[1] >= self.__length-1 + p[0] >= self.__width - 1 or + p[1] >= self.__length - 1 ): continue a_map[p[0]][p[1]] = FLOOR @@ -183,12 +184,12 @@ def __gen_walls(self, a_map): def __adj_flr_count(self, sr, sc): count = 0 for pos in ((-1, 0), (1, 0), (0, -1), (0, 1)): - p = (sr+pos[0], sc+pos[1]) + p = (sr + pos[0], sc + pos[1]) if (p[0] < 0 or p[1] < 0): continue if ( - p[0] > self.__width-1 or - p[1] > self.__length-1 + p[0] > self.__width - 1 or + p[1] > self.__length - 1 ): continue if (self.__map[p[0]][p[1]] == FLOOR): @@ -198,9 +199,9 @@ def __adj_flr_count(self, sr, sc): def __adj_wall_count(self, sr, sc, rng=1): count = 0 - for r in xrange(-rng, rng+1): - for c in xrange(-rng, rng+1): - #if (r == 0 and c == 0): + for r in xrange(-rng, rng + 1): + for c in xrange(-rng, rng + 1): + # if (r == 0 and c == 0): # continue if (abs(r) == 2 and abs(c) == 2): continue @@ -232,14 +233,14 @@ def __union_adj_sqr(self, sr, sc): # A cell is connected to other cells only in cardinal directions. # (diagonals don't count for movement). for pos in ((-1, 0), (1, 0), (0, -1), (0, 1)): - if (sr+pos[0] < 0 or sc+pos[1] < 0): + if (sr + pos[0] < 0 or sc + pos[1] < 0): continue if ( - sr+pos[0] >= self.__length or - sc+pos[1] >= self.__width + sr + pos[0] >= self.__length or + sc + pos[1] >= self.__width ): continue - nloc = (sr+pos[0], sc+pos[1]) + nloc = (sr + pos[0], sc + pos[1]) if self.__map[nloc[0]][nloc[1]] == FLOOR: root2 = self.__ds.find(nloc) if root1 != root2: @@ -247,7 +248,7 @@ def __union_adj_sqr(self, sr, sc): def __join_points(self, pt1): next_pt = pt1 - while 1: + while True: dir = self.__get_tunnel_dir(pt1, self.__cpt) move = randrange(0, 3) @@ -266,13 +267,17 @@ def __join_points(self, pt1): for pos in ((0, 0), (-1, 0), (1, 0), (0, -1), (0, 1)): if ( - next_pt[0]+pos[0] < 0 or next_pt[1]+pos[1] < 0 or - next_pt[0]+pos[0] >= self.__length or - next_pt[1]+pos[1] >= self.__width + next_pt[0] + pos[0] < 0 or next_pt[1] + pos[1] < 0 or + next_pt[0] + pos[0] >= self.__length or + next_pt[1] + pos[1] >= self.__width ): continue - if (self.__map[next_pt[0]+pos[0]][next_pt[1]+pos[1]] == WALL): - self.__map[next_pt[0]+pos[0]][next_pt[1]+pos[1]] = TUNNEL + if (self.__map[next_pt[0] + pos[0]][next_pt[1] + pos[1]] == WALL): + self.__map[ + next_pt[0] + + pos[0]][ + next_pt[1] + + pos[1]] = TUNNEL if self.__stop_drawing(pt1, next_pt, self.__cpt): return diff --git a/cfg.py b/cfg.py index e5d76146..1bc72c7d 100644 --- a/cfg.py +++ b/cfg.py @@ -190,7 +190,7 @@ def Load(filename='default.cfg'): print 'Reading config from', filename, '...' try: parser.readfp(open(filename)) - except Exception, e: + except Exception as e: print "Failed to read config file!" sys.exit(e.message) @@ -214,11 +214,11 @@ def Load(filename='default.cfg'): # These are not used until actual generation begins, so check they are # good now. if isFile(file_fortunes) is False: - print "Warning: fortune file '"+file_fortunes+"' not found." + print "Warning: fortune file '" + file_fortunes + "' not found." if isDir(dir_paintings) is False: - print "Warning: paintings directory '"+dir_paintings+"' not found." + print "Warning: paintings directory '" + dir_paintings + "' not found." if isDir(dir_books) is False: - print "Warning: books directory '"+dir_books+"' not found." + print "Warning: books directory '" + dir_books + "' not found." if dir_extra_spawners != '': if isDir(dir_extra_spawners) is False: print "Warning: extra spawners directory '" +\ @@ -253,7 +253,7 @@ def Load(filename='default.cfg'): master_hall_traps = parser.items('hall traps') except: print 'WARNING: No hall traps section found in config. Using default.' - master_hall_traps = [['Blank',100]] + master_hall_traps = [['Blank', 100]] master_rooms = parser.items('rooms') master_srooms = parser.items('secret rooms') @@ -310,7 +310,7 @@ def Load(filename='default.cfg'): master_mobs[max_mob_tier].append((mob_name, mob[1])) max_mob_tier += 1 try: - temp_mobs = parser.items('mobs.'+str(max_mob_tier)) + temp_mobs = parser.items('mobs.' + str(max_mob_tier)) except: temp_mobs = [] max_mob_tier -= 1 @@ -450,7 +450,7 @@ def Load(filename='default.cfg'): if (v >= 0): structure_values.append(v) else: - sys.exit('Unable to find structure material: '+str(a)) + sys.exit('Unable to find structure material: ' + str(a)) # Load river biomes try: diff --git a/doors.py b/doors.py index da327e5e..4d5a6308 100644 --- a/doors.py +++ b/doors.py @@ -2,6 +2,7 @@ class Door(object): + def __init__(self): self.loc = Vec(0, 0, 0) self.material = None diff --git a/dungeon.py b/dungeon.py index a02d9559..fae41520 100644 --- a/dungeon.py +++ b/dungeon.py @@ -24,7 +24,9 @@ from overviewer_core import cache from overviewer_core import world as ov_world + class Block(object): + def __init__(self, loc): self.loc = loc self.material = None @@ -36,16 +38,20 @@ def __init__(self, loc): # Soft blocks are only rendered in the world block is air self.soft = False + class MazeCell(object): states = enum('BLANK', 'USED', 'CONNECTED', 'RESTRICTED') + def __init__(self, loc): self.loc = loc self.depth = 0 self.state = 0 + class RelightHandler(object): _curr = 28 _count = 0 + def __init__(self): self.pm = pmeter.ProgressMeter() self.pm.init(self._curr, label='Relighting chunks:') @@ -61,7 +67,9 @@ def flush(self): def done(self): self.pm.set_complete() + class Dungeon (object): + def __init__(self, args, world, @@ -90,19 +98,18 @@ def __init__(self, self.torches = {} self.doors = {} self.entrance = None - self.entrance_pos = Vec(0,0,0) + self.entrance_pos = Vec(0, 0, 0) self.maze = {} self.stairwells = [] self.room_size = 16 self.room_height = 6 - self.position = Vec(0,0,0) + self.position = Vec(0, 0, 0) self.args = args self.dinfo = {} self.dinfo['fill_caves'] = cfg.fill_caves self.dinfo['portal_exit'] = cfg.portal_exit self.dinfo['dungeon_name'] = cfg.dungeon_name - def generate(self, cache_path, version): '''Generate a dungeon''' # Pick a starting size. @@ -120,10 +127,10 @@ def generate(self, cache_path, version): self.levels) self.position = str2Vec(cfg.offset) - self.position.x = self.position.x &~15 - self.position.z = self.position.z &~15 + self.position.x = self.position.x & ~15 + self.position.z = self.position.z & ~15 # Bury it if we need to - located = self.bury(manual=bool(cfg.bury==False)) + located = self.bury(manual=bool(cfg.bury == False)) if (located == False): print 'Unable to bury a dungeon of requested depth at', self.position print 'Try fewer levels, or a smaller size, or another location.' @@ -239,21 +246,21 @@ def generate(self, cache_path, version): if (located is True): # We have a final size, so let's initialize some things. for x in xrange(self.xsize): - for y in xrange(self.levels): - for z in xrange(self.zsize): - self.maze[Vec(x,y,z)] = MazeCell(Vec(x,y,z)) - self.halls = [ [ [ [None, None, None, None] for z in - xrange(self.zsize) ] for y in - xrange(self.levels) ] for x in - xrange(self.xsize) ] + for y in xrange(self.levels): + for z in xrange(self.zsize): + self.maze[Vec(x, y, z)] = MazeCell(Vec(x, y, z)) + self.halls = [[[[None, None, None, None] for z in + xrange(self.zsize)] for y in + xrange(self.levels)] for x in + xrange(self.xsize)] - self.heightmap = numpy.zeros((self.xsize*self.room_size, - self.zsize*self.room_size)) + self.heightmap = numpy.zeros((self.xsize * self.room_size, + self.zsize * self.room_size)) # Set the seed if requested. if (self.args.seed is not None): seed(self.args.seed) - print 'Seed:',self.args.seed + print 'Seed:', self.args.seed # Now we know the biome, we can setup a name generator self.namegen = namegenerator.namegenerator(self.biome) @@ -277,11 +284,12 @@ def generate(self, cache_path, version): self.entrance.height = self.args.entrance_height # Name this place if self.owner.endswith("s"): - owners = self.owner+"'" + owners = self.owner + "'" else: - owners = self.owner+"'s" - self.dungeon_name = self.dinfo['dungeon_name'].format(owner=self.owner, - owners=owners) + owners = self.owner + "'s" + self.dungeon_name = self.dinfo['dungeon_name'].format( + owner=self.owner, + owners=owners) self.dinfo['full_name'] = self.dungeon_name print "Dungeon name:", self.dungeon_name print "Finding secret rooms..." @@ -305,9 +313,9 @@ def generate(self, cache_path, version): self.placespawners() # Signature - self.setblock(Vec(0,0,0), materials.Chest, 0, hide=True) - self.tile_ents[Vec(0,0,0)]=encodeDungeonInfo(self, - version) + self.setblock(Vec(0, 0, 0), materials.Chest, 0, hide=True) + self.tile_ents[Vec(0, 0, 0)] = encodeDungeonInfo(self, + version) # Add to the dungeon cache. key = key = '%s,%s' % ( self.position.x, @@ -347,7 +355,8 @@ def generate(self, cache_path, version): saveChunkCache(cache_path, self.chunk_cache) # make sure commandBlockOutput is false. root_tag = nbt.load(self.world.filename) - root_tag['Data']['GameRules']['commandBlockOutput'].value = 'false' + root_tag['Data']['GameRules'][ + 'commandBlockOutput'].value = 'false' root_tag.save(self.world.filename) else: print "Skipping save! (--write disabled)" @@ -366,74 +375,80 @@ def printmaze(self, y, cursor=None): for z in xrange(self.zsize): line = u'' for x in xrange(self.xsize): - p = Vec(x,y,z) + p = Vec(x, y, z) if p in self.rooms: if self.halls[x][y][z][0] == 1: - line += ( u'\u2554\u2569\u2557') + line += (u'\u2554\u2569\u2557') else: - line += ( u'\u2554\u2550\u2557') + line += (u'\u2554\u2550\u2557') else: - line += ( u'\u2591\u2591\u2591') + line += (u'\u2591\u2591\u2591') print line line = u'' for x in xrange(self.xsize): - p = Vec(x,y,z) + p = Vec(x, y, z) if p in self.rooms: if self.halls[x][y][z][3] == 1: - line += ( u'\u2563') + line += (u'\u2563') else: - line += ( u'\u2551') + line += (u'\u2551') if (cursor == p): - line += ( u'X') + line += (u'X') elif self.maze[p].state == MazeCell.states.CONNECTED: - line += ( u' ') + line += (u' ') elif self.maze[p].state == MazeCell.states.USED: - line += ( u'U') + line += (u'U') else: - line += ( u'R') + line += (u'R') if self.halls[x][y][z][1] == 1: - line += ( u'\u2560') + line += (u'\u2560') else: - line += ( u'\u2551') + line += (u'\u2551') else: - line += ( u'\u2591\u2591\u2591') + line += (u'\u2591\u2591\u2591') print line line = u'' for x in xrange(self.xsize): - p = Vec(x,y,z) + p = Vec(x, y, z) if p in self.rooms: if self.halls[x][y][z][2] == 1: - line += ( u'\u255a\u2566\u255d') + line += (u'\u255a\u2566\u255d') else: - line += ( u'\u255a\u2550\u255d') + line += (u'\u255a\u2550\u255d') else: - line += ( u'\u2591\u2591\u2591') + line += (u'\u2591\u2591\u2591') print line line = u'' raw_input('continue...') - - def setblock(self, loc, material, data=0, hide=False, lock=False, soft=False): + def setblock( + self, + loc, + material, + data=0, + hide=False, + lock=False, + soft=False): # If material is None, remove this block - if material == None: + if material is None: if loc in self.blocks: del(self.blocks[loc]) return - # Build a block if we need to + # Build a block if we need to if loc not in self.blocks: self.blocks[loc] = Block(loc) if (loc.x >= 0 and - loc.z >= 0 and - loc.x < self.xsize*self.room_size and - loc.z < self.zsize*self.room_size): + loc.z >= 0 and + loc.x < self.xsize * self.room_size and + loc.z < self.zsize * self.room_size): self.heightmap[loc.x][loc.z] = min(loc.y, self.heightmap[loc.x][loc.z]) # If the existing block is locked, abort # Unless we are requesting a locked block - if self.blocks[loc].lock == True and lock == False: + if self.blocks[loc].lock and lock == False: return # Setup the material @@ -463,57 +478,62 @@ def getblock(self, loc): return self.blocks[loc].material return False - def findlocation(self): positions = {} sorted_p = [] world = self.world - if self.args.debug: print 'Filtering for depth...' + if self.args.debug: + print 'Filtering for depth...' for key, value in self.good_chunks.iteritems(): - if value >= (self.levels+1)*self.room_height: + if value >= (self.levels + 1) * self.room_height: positions[key] = value - if (cfg.maximize_distance == True and len(self.dungeon_cache) > 0): - if self.args.debug: print 'Marking distances...' + if (cfg.maximize_distance and len(self.dungeon_cache) > 0): + if self.args.debug: + print 'Marking distances...' for key in positions.keys(): - d = 2^64 + d = 2 ^ 64 chunk = Vec(key[0], 0, key[1]) for dungeon in self.dungeon_cache: (x, z) = dungeon.split(",") - dpos = Vec(int(x)>>4, 0, int(z)>>4) + dpos = Vec(int(x) >> 4, 0, int(z) >> 4) d = min(d, (dpos - chunk).mag2d()) positions[key] = d sorted_p = sorted(positions.iteritems(), - reverse=True, - key=operator.itemgetter(1)) + reverse=True, + key=operator.itemgetter(1)) else: sorted_p = positions.items() random.shuffle(sorted_p) - if self.args.debug: print 'Selecting a location...' + if self.args.debug: + print 'Selecting a location...' all_chunks = set(positions.keys()) # Offset is fill caves. Expand the size of the dungeon if fill_caves is # set. When recording the position, we'll center the dungeon in this # area. offset = 0 - if self.dinfo['fill_caves'] == True: + if self.dinfo['fill_caves']: offset = 10 for p, d in sorted_p: d_chunks = set() - for x in xrange(self.xsize+offset): - for z in xrange(self.zsize+offset): - d_chunks.add((p[0]+x, p[1]+z)) + for x in xrange(self.xsize + offset): + for z in xrange(self.zsize + offset): + d_chunks.add((p[0] + x, p[1] + z)) if d_chunks.issubset(all_chunks): - if self.args.debug: print 'Found: ', p - self.position = Vec((p[0]+(offset/2))*self.room_size, + if self.args.debug: + print 'Found: ', p + self.position = Vec((p[0] + (offset / 2)) * self.room_size, 0, - (p[1]+(offset/2))*self.room_size) - if self.args.debug: print 'Final: ', self.position + (p[1] + (offset / 2)) * self.room_size) + if self.args.debug: + print 'Final: ', self.position if self.bury(): self.worldmap(world, positions) return True - if self.args.debug: print 'No positions', p + if self.args.debug: + print 'No positions', p return False def worldmap(self, world, positions): @@ -521,8 +541,8 @@ def worldmap(self, world, positions): columns = 39 bounds = world.bounds if self.args.spawn is None: - scx = world.playerSpawnPosition()[0]>>4 - scz = world.playerSpawnPosition()[2]>>4 + scx = world.playerSpawnPosition()[0] >> 4 + scz = world.playerSpawnPosition()[2] >> 4 else: scx = self.args.spawn[0] scz = self.args.spawn[1] @@ -533,10 +553,10 @@ def worldmap(self, world, positions): map_min_z = bounds.maxcz map_max_z = bounds.mincz for p in self.good_chunks: - map_min_x = min(map_min_x, p[0]+1) - map_max_x = max(map_max_x, p[0]-1) - map_min_z = min(map_min_z, p[1]+1) - map_max_z = max(map_max_z, p[1]-1) + map_min_x = min(map_min_x, p[0] + 1) + map_max_x = max(map_max_x, p[0] - 1) + map_min_z = min(map_min_z, p[1] + 1) + map_max_z = max(map_max_z, p[1] - 1) # Include spawn map_min_x = min(map_min_x, spawn_chunk.x) @@ -544,57 +564,59 @@ def worldmap(self, world, positions): map_min_z = min(map_min_z, spawn_chunk.z) map_max_z = max(map_max_z, spawn_chunk.z) - if map_max_x-map_min_x+1 >= int(columns): - print 'Map too wide for terminal:', map_max_x-map_min_x + if map_max_x - map_min_x + 1 >= int(columns): + print 'Map too wide for terminal:', map_max_x - map_min_x return - sx = self.position.x/self.room_size - sz = self.position.z/self.room_size - if self.args.debug: print 'spos:', Vec(sx, 0, sz) + sx = self.position.x / self.room_size + sz = self.position.z / self.room_size + if self.args.debug: + print 'spos:', Vec(sx, 0, sz) d_box = Box(Vec(sx, 0, sz), self.xsize, world.Height, self.zsize) - for z in xrange(map_min_z-1, map_max_z+2): - for x in xrange(map_min_x-1, map_max_x+2): - if (Vec(x,0,z) == spawn_chunk): + for z in xrange(map_min_z - 1, map_max_z + 2): + for x in xrange(map_min_x - 1, map_max_x + 2): + if (Vec(x, 0, z) == spawn_chunk): sys.stdout.write('SS') elif (x == 0 and z == 0): sys.stdout.write('00') - elif (Vec(x,0,z) == Vec(sx, 0, sz)): + elif (Vec(x, 0, z) == Vec(sx, 0, sz)): sys.stdout.write('XX') - elif (d_box.containsPoint(Vec(x,64,z))): + elif (d_box.containsPoint(Vec(x, 64, z))): sys.stdout.write('##') - elif ((x,z) in positions.keys()): + elif ((x, z) in positions.keys()): sys.stdout.write('++') - elif ((x,z) in self.good_chunks.keys()): + elif ((x, z) in self.good_chunks.keys()): sys.stdout.write('--') else: sys.stdout.write('``') print - def bury(self, manual=False): - if self.args.debug: print 'Burying dungeon...' - min_depth = (self.levels+1)*self.room_height + if self.args.debug: + print 'Burying dungeon...' + min_depth = (self.levels + 1) * self.room_height d_chunks = set() - p = (self.position.x/self.room_size, - self.position.z/self.room_size) + p = (self.position.x / self.room_size, + self.position.z / self.room_size) for x in xrange(self.xsize): for z in xrange(self.zsize): - d_chunks.add((p[0]+x, p[1]+z)) + d_chunks.add((p[0] + x, p[1] + z)) # Calaculate the biome biomes = {} rset = self.oworld.get_regionset(None) for chunk in d_chunks: - cdata = rset.get_chunk(chunk[0],chunk[1]) + cdata = rset.get_chunk(chunk[0], chunk[1]) key = numpy.argmax(numpy.bincount((cdata['Biomes'].flatten()))) if key in biomes: biomes[key] += 1 else: biomes[key] = 1 self.biome = max(biomes, key=lambda k: biomes[k]) - if self.args.debug: print 'Biome: ', self.biome + if self.args.debug: + print 'Biome: ', self.biome depth = self.world.Height for chunk in d_chunks: @@ -604,7 +626,7 @@ def bury(self, manual=False): else: d1 = self.good_chunks[chunk] d1 -= 2 - if manual == False: + if not manual: # Too shallow if (d1 < min_depth): return False @@ -614,7 +636,7 @@ def bury(self, manual=False): depth = min(depth, d1) - if manual == False: + if not manual: self.position = Vec(self.position.x, depth, self.position.z) @@ -622,7 +644,7 @@ def bury(self, manual=False): def snow(self, pos, limit=16): b = self.getblock(pos) - if (b != False and b != materials.Air): + if (b and b != materials.Air): return count = 1 @@ -634,13 +656,13 @@ def snow(self, pos, limit=16): if count > limit: return - if b == False: + if not b: soft = True else: soft = False if self.getblock(pos.down(count)).val in materials.heightmap_solids: - self.setblock(pos.down(count-1), materials.Snow, soft=soft) - #print 'snow placed: ',pos.down(count-1), soft + self.setblock(pos.down(count - 1), materials.Snow, soft=soft) + # print 'snow placed: ',pos.down(count-1), soft def vines(self, pos, grow=False): # Data values (1.9p5) @@ -650,10 +672,10 @@ def vines(self, pos, grow=False): # 8 - East b = self.getblock(pos) # Something here already - if (b != False and b != materials.Air): + if (b and b != materials.Air): return - if b == False: + if not b: soft = True else: soft = False @@ -661,27 +683,27 @@ def vines(self, pos, grow=False): # Look around for something to attach to data = 0 b = self.getblock(pos.s(1)) - if (b != False and b.val in materials.vine_solids): + if (b and b.val in materials.vine_solids): data += 1 b = self.getblock(pos.w(1)) - if (b != False and b.val in materials.vine_solids): + if (b and b.val in materials.vine_solids): data += 2 b = self.getblock(pos.n(1)) - if (b != False and b.val in materials.vine_solids): + if (b and b.val in materials.vine_solids): data += 4 b = self.getblock(pos.e(1)) - if (b != False and b.val in materials.vine_solids): + if (b and b.val in materials.vine_solids): data += 8 # Nothing to attach to if data == 0: return self.setblock(pos, materials.Vines, data, soft=soft) - if grow == False: + if not grow: return pos = pos.down(1) b = self.getblock(pos) - while ((b == False or b == materials.Air) and random.randint(1,100)<75): - if b == False: + while ((b == False or b == materials.Air) and random.randint(1, 100) < 75): + if not b: soft = True else: soft = False @@ -696,20 +718,20 @@ def cobwebs(self, c1, c3): top = min(c1.y, c3.y) for p in iterate_cube(c1, c3): if (p not in self.blocks or - self.blocks[p].material != materials.Air): + self.blocks[p].material != materials.Air): continue count = 0 chance = 80 - (p.y - top) * 14 - for q in (Vec(1,0,0), Vec(-1,0,0), - Vec(0,1,0), Vec(0,-1,0), - Vec(0,0,1), Vec(0,0,-1)): - if (p+q in self.blocks and - self.blocks[p+q].material != materials.Air and - random.randint(1,100) <= chance): + for q in (Vec(1, 0, 0), Vec(-1, 0, 0), + Vec(0, 1, 0), Vec(0, -1, 0), + Vec(0, 0, 1), Vec(0, 0, -1)): + if (p + q in self.blocks and + self.blocks[p + q].material != materials.Air and + random.randint(1, 100) <= chance): count += 1 if count >= 3: webs[p] = True - for p,q in webs.items(): + for p, q in webs.items(): self.setblock(p, materials.Cobweb) def processBiomes(self): @@ -717,17 +739,17 @@ def processBiomes(self): rset = self.oworld.get_regionset(None) r = ov_world.CachedRegionSet(rset, self.caches) wp = Vec(self.position.x, 0, self.position.z) - count = self.xsize*16*self.zsize*16 + count = self.xsize * 16 * self.zsize * 16 self.pm.init(count, label='Processing biomes:') - for p in iterate_cube(Vec(0,0,0), - Vec(self.xsize*16-1,0,self.zsize*16-1)): + for p in iterate_cube(Vec(0, 0, 0), + Vec(self.xsize * 16 - 1, 0, self.zsize * 16 - 1)): self.pm.update_left(count) count -= 1 - cx = (p.x+wp.x)//16 - cz = (p.z+wp.z)//16 - chunk = r.get_chunk(cx,cz) - biome = chunk['Biomes'][p.x%16][p.z%16] - # Vines + cx = (p.x + wp.x) // 16 + cz = (p.z + wp.z) // 16 + chunk = r.get_chunk(cx, cz) + biome = chunk['Biomes'][p.x % 16][p.z % 16] + # Vines if biome in (6, # Swampland 134, # Swampland M 21, # Jungle @@ -735,32 +757,32 @@ def processBiomes(self): 22, # Jungle Hills 23, # Jungle Edge 151, # Jungle Edge M - ): + ): h = 0 try: - h = min(self.heightmap[p.x-1][p.z], h) + h = min(self.heightmap[p.x - 1][p.z], h) except IndexError: pass try: - h = min(self.heightmap[p.x+1][p.z], h) + h = min(self.heightmap[p.x + 1][p.z], h) except IndexError: pass try: - h = min(self.heightmap[p.x][p.z-1], h) + h = min(self.heightmap[p.x][p.z - 1], h) except IndexError: pass try: - h = min(self.heightmap[p.x][p.z+1], h) + h = min(self.heightmap[p.x][p.z + 1], h) except IndexError: pass if h == 0: continue - for q in iterate_cube(Vec(p.x,h,p.z), - Vec(p.x,0,p.z)): - if random.randint(1,100)<20: + for q in iterate_cube(Vec(p.x, h, p.z), + Vec(p.x, 0, p.z)): + if random.randint(1, 100) < 20: self.vines(q, grow=True) - # Snow - if biome in (10, # Frozen Ocean + # Snow + if biome in (10, # Frozen Ocean 11, # Frozen River 12, # Ice Plains 140, # Ice Plains Spikes @@ -769,14 +791,13 @@ def processBiomes(self): 30, # Cold Taiga 158, # Cold Taiga M 31, # Cold Taiga Hills - ): + ): h = self.heightmap[p.x][p.z] if (h < 0): - self.snow(Vec(p.x, h-1, p.z), limit=abs(h-1)) + self.snow(Vec(p.x, h - 1, p.z), limit=abs(h - 1)) self.pm.set_complete() - def getspawnertags(self, entity): # See if we have a custom spawner match if entity.lower() in cfg.custom_spawners.keys(): @@ -802,7 +823,6 @@ def getspawnertags(self, entity): return root_tag - def addsign(self, loc, text1, text2, text3, text4): root_tag = nbt.TAG_Compound() root_tag['id'] = nbt.TAG_String('Sign') @@ -815,30 +835,31 @@ def addsign(self, loc, text1, text2, text3, text4): root_tag['Text4'] = nbt.TAG_String(text4) self.tile_ents[loc] = root_tag - def addspawner(self, loc, entity='', tier=-1): if (entity == ''): - level = loc.y/self.room_height + level = loc.y / self.room_height if (cfg.max_mob_tier == 0 or level < 0): tier = 0 elif tier == -1: if (self.levels > 1): tier = (float(level) / - float(self.levels-1) * - float(cfg.max_mob_tier-2))+1.5 - tier = int(min(cfg.max_mob_tier-1, tier)) + float(self.levels - 1) * + float(cfg.max_mob_tier - 2)) + 1.5 + tier = int(min(cfg.max_mob_tier - 1, tier)) else: - tier = cfg.max_mob_tier-1 + tier = cfg.max_mob_tier - 1 entity = weighted_choice(cfg.master_mobs[tier]) - #print 'Spawner: lev=%d, tier=%d, ent=%s' % (level, tier, entity) + # print 'Spawner: lev=%d, tier=%d, ent=%s' % (level, tier, entity) root_tag = self.getspawnertags(entity) # Do generic spawner setup root_tag['id'] = nbt.TAG_String('MobSpawner') root_tag['x'] = nbt.TAG_Int(loc.x) root_tag['y'] = nbt.TAG_Int(loc.y) root_tag['z'] = nbt.TAG_Int(loc.z) - try: root_tag['Delay'] - except: root_tag['Delay'] = nbt.TAG_Short(0) + try: + root_tag['Delay'] + except: + root_tag['Delay'] = nbt.TAG_Short(0) # Calculate spawner tags from config if tier == cfg.max_mob_tier: SpawnCount = cfg.treasure_SpawnCount @@ -854,24 +875,35 @@ def addspawner(self, loc, entity='', tier=-1): SpawnRequiredPlayerRange = cfg.SpawnRequiredPlayerRange # But don't overwrite tags from NBT files if (SpawnCount != 0): - try: root_tag['SpawnCount'] - except: root_tag['SpawnCount'] = nbt.TAG_Short(SpawnCount) + try: + root_tag['SpawnCount'] + except: + root_tag['SpawnCount'] = nbt.TAG_Short(SpawnCount) if (SpawnMaxNearbyEntities != 0): - try: root_tag['MaxNearbyEntities'] - except: root_tag['MaxNearbyEntities'] = nbt.TAG_Short(SpawnMaxNearbyEntities) + try: + root_tag['MaxNearbyEntities'] + except: + root_tag['MaxNearbyEntities'] = nbt.TAG_Short( + SpawnMaxNearbyEntities) if (SpawnMinDelay != 0): - try: root_tag['MinSpawnDelay'] - except: root_tag['MinSpawnDelay'] = nbt.TAG_Short(SpawnMinDelay) + try: + root_tag['MinSpawnDelay'] + except: + root_tag['MinSpawnDelay'] = nbt.TAG_Short(SpawnMinDelay) if (SpawnMaxDelay != 0): - try: root_tag['MaxSpawnDelay'] - except: root_tag['MaxSpawnDelay'] = nbt.TAG_Short(SpawnMaxDelay) + try: + root_tag['MaxSpawnDelay'] + except: + root_tag['MaxSpawnDelay'] = nbt.TAG_Short(SpawnMaxDelay) if (SpawnRequiredPlayerRange != 0): - try: root_tag['RequiredPlayerRange'] - except: root_tag['RequiredPlayerRange'] = nbt.TAG_Short(SpawnRequiredPlayerRange) + try: + root_tag['RequiredPlayerRange'] + except: + root_tag['RequiredPlayerRange'] = nbt.TAG_Short( + SpawnRequiredPlayerRange) # Finally give the tag to the entity self.tile_ents[loc] = root_tag - def addnoteblock(self, loc, clicks=0): root_tag = nbt.TAG_Compound() root_tag['id'] = nbt.TAG_String('Music') @@ -881,24 +913,33 @@ def addnoteblock(self, loc, clicks=0): root_tag['note'] = nbt.TAG_Byte(clicks) self.tile_ents[loc] = root_tag - def loadrandbooktext(self): - if os.path.isdir(os.path.join(sys.path[0],cfg.dir_books)): - book_path = os.path.join(sys.path[0],cfg.dir_books) + if os.path.isdir(os.path.join(sys.path[0], cfg.dir_books)): + book_path = os.path.join(sys.path[0], cfg.dir_books) elif os.path.isdir(cfg.dir_books): book_path = cfg.dir_books else: book_path = '' - #Make a list of all the txt files in the books directory + # Make a list of all the txt files in the books directory booklist = [] if book_path != '': for file in os.listdir(book_path): if (str(file.lower()).endswith(".txt") and - file.lower() is not "readme.txt"): + file.lower() is not "readme.txt"): booklist.append(file) # Book 'editions' - ed_dict = ['1st','2nd','3rd','4th','5th','6th','7th','8th','9th','10th'] - + ed_dict = [ + '1st', + '2nd', + '3rd', + '4th', + '5th', + '6th', + '7th', + '8th', + '9th', + '10th'] + item = nbt.TAG_Compound() item['id'] = nbt.TAG_Short(387) item['Count'] = nbt.TAG_Byte(1) @@ -914,18 +955,28 @@ def loadrandbooktext(self): bookfile.close() # Create NBT tag item['tag'] = nbt.TAG_Compound() - item['tag']['author'] = nbt.TAG_String(filter(lambda x: x in valid_characters, bookdata.pop(0))) - item['tag']['title'] = nbt.TAG_String(filter(lambda x: x in valid_characters, bookdata.pop(0))) + item['tag']['author'] = nbt.TAG_String( + filter( + lambda x: x in valid_characters, + bookdata.pop(0))) + item['tag']['title'] = nbt.TAG_String( + filter( + lambda x: x in valid_characters, + bookdata.pop(0))) item['tag']["pages"] = nbt.TAG_List() - # Slice the pages at 50 and the page text at 256 to match minecraft limits + # Slice the pages at 50 and the page text at 256 to match minecraft + # limits for p in bookdata[:50]: page = filter(lambda x: x in valid_characters, p) item['tag']["pages"].append(nbt.TAG_String(page[:256])) # Give the book an edition - ed = topheavy_random(0,9) + ed = topheavy_random(0, 9) item['tag']['display'] = nbt.TAG_Compound() item['tag']['display']['Lore'] = nbt.TAG_List() - item['tag']['display']['Lore'].append(nbt.TAG_String(ed_dict[ed]+' Edition')) + item['tag']['display']['Lore'].append( + nbt.TAG_String( + ed_dict[ed] + + ' Edition')) if (ed == 0): item['tag']['generation'] = nbt.TAG_Int(0) elif (ed == 1): @@ -935,20 +986,20 @@ def loadrandbooktext(self): return item - def loadrandpainting(self): - if os.path.isdir(os.path.join(sys.path[0],cfg.dir_paintings)): - paint_path = os.path.join(sys.path[0],cfg.dir_paintings) + if os.path.isdir(os.path.join(sys.path[0], cfg.dir_paintings)): + paint_path = os.path.join(sys.path[0], cfg.dir_paintings) elif os.path.isdir(cfg.dir_paintings): paint_path = cfg.dir_paintings else: paint_path = '' - # Make a list of all the pairs of dat and txt files in the paintings directory + # Make a list of all the pairs of dat and txt files in the paintings + # directory paintlist = [] if paint_path != '': for file in os.listdir(paint_path): if str(file.lower()).endswith(".dat"): - if os.path.isfile(os.path.join(paint_path,file[:-3]+'txt')): + if os.path.isfile(os.path.join(paint_path, file[:-3] + 'txt')): paintlist.append(file[:-4]) # No paintings? Give a blank map (ID: 395) if len(paintlist) == 0: @@ -959,20 +1010,19 @@ def loadrandpainting(self): return self.mapstore.add_painting(random.choice(paintlist)) - def loadrandfortune(self): - if os.path.isfile(os.path.join(sys.path[0],cfg.file_fortunes)): - forune_path = os.path.join(sys.path[0],cfg.file_fortunes) + if os.path.isfile(os.path.join(sys.path[0], cfg.file_fortunes)): + forune_path = os.path.join(sys.path[0], cfg.file_fortunes) elif os.path.isfile(cfg.file_fortunes): forune_path = cfg.file_fortunes else: - return '...in bed.' #Fortune file not found + return '...in bed.' # Fortune file not found # Retrieve a random line from a file, reading through the file once # Prevents us from having to load the whole file in to memory forune_file = open(forune_path) lineNum = 0 - while 1: + while True: aLine = forune_file.readline() if not aLine: break @@ -980,12 +1030,11 @@ def loadrandfortune(self): continue lineNum = lineNum + 1 # How likely is it that this is the last line of the file? - if random.uniform(0,lineNum)<1: + if random.uniform(0, lineNum) < 1: fortune = aLine.rstrip() forune_file.close() return fortune - def buildItemTag(self, i): item_tag = nbt.TAG_Compound() # Standard stuff @@ -1007,7 +1056,8 @@ def buildItemTag(self, i): elist.append(e_tag) # Custom Potion Effects if i.p_effect != '': - try: item_tag['tag'] + try: + item_tag['tag'] except: item_tag['tag'] = nbt.TAG_Compound() item_tag['tag']['CustomPotionEffects'] = nbt.TAG_List() @@ -1021,40 +1071,53 @@ def buildItemTag(self, i): elist.append(e_tag) # Naming if i.customname != '': - try: item_tag['tag'] + try: + item_tag['tag'] except: item_tag['tag'] = nbt.TAG_Compound() item_tag['tag']['display'] = nbt.TAG_Compound() item_tag['tag']['display']['Name'] = nbt.TAG_String(i.customname) # Lore Text if i.lore != '' or i.flag == 'FORTUNE': - try: item_tag['tag'] + try: + item_tag['tag'] except: item_tag['tag'] = nbt.TAG_Compound() - try: item_tag['tag']['display'] + try: + item_tag['tag']['display'] except: item_tag['tag']['display'] = nbt.TAG_Compound() item_tag['tag']['display']['Lore'] = nbt.TAG_List() if i.flag == 'FORTUNE': - item_tag['tag']['display']['Name'] = nbt.TAG_String('Fortune Cookie') + item_tag['tag']['display'][ + 'Name'] = nbt.TAG_String('Fortune Cookie') i.lore = self.loadrandfortune() - loredata = textwrap.wrap(i.lore,40) + loredata = textwrap.wrap(i.lore, 40) for loretext in loredata[:10]: - item_tag['tag']['display']['Lore'].append(nbt.TAG_String(loretext)) + item_tag['tag']['display']['Lore'].append( + nbt.TAG_String(loretext)) else: loredata = i.lore.split(':') for loretext in loredata[:10]: - item_tag['tag']['display']['Lore'].append(nbt.TAG_String(loretext[:50])) + item_tag['tag']['display']['Lore'].append( + nbt.TAG_String( + loretext[ + :50])) # Dyed if (i.flag == 'DYED'): - try: item_tag['tag'] + try: + item_tag['tag'] except: item_tag['tag'] = nbt.TAG_Compound() - try: item_tag['tag']['display'] + try: + item_tag['tag']['display'] except: item_tag['tag']['display'] = nbt.TAG_Compound() if i.flagparam == '': - item_tag['tag']['display']['color'] = nbt.TAG_Int(random.randint(0, 16777215)) + item_tag['tag']['display']['color'] = nbt.TAG_Int( + random.randint( + 0, + 16777215)) else: item_tag['tag']['display']['color'] = nbt.TAG_Int(i.flagparam) # special cases for written books and paintings @@ -1064,19 +1127,18 @@ def buildItemTag(self, i): item_tag = self.loadrandpainting() return item_tag - def addchest(self, loc, tier=-1, loot=[], name=''): - level = loc.y/self.room_height + level = loc.y / self.room_height if (tier < 0): if (self.levels > 1): tierf = (float(level) / - float(self.levels-1) * - float(loottable._maxtier-2))+1.5 - tierf = min(loottable._maxtier-1, tierf) + float(self.levels - 1) * + float(loottable._maxtier - 2)) + 1.5 + tierf = min(loottable._maxtier - 1, tierf) else: - tierf = loottable._maxtier-1 + tierf = loottable._maxtier - 1 tier = max(1, int(tierf)) - #print 'Adding chest: level',level+1,'tier',tier + # print 'Adding chest: level',level+1,'tier',tier root_tag = nbt.TAG_Compound() root_tag['id'] = nbt.TAG_String('Chest') root_tag['x'] = nbt.TAG_Int(loc.x) @@ -1087,7 +1149,7 @@ def addchest(self, loc, tier=-1, loot=[], name=''): inv_tag = nbt.TAG_List() root_tag['Items'] = inv_tag if len(loot) == 0: - loot = list(loottable.rollLoot(tier, level+1)) + loot = list(loottable.rollLoot(tier, level + 1)) for i in loot: if i.file != '': item_tag = item_tag = nbt.load(i.file) @@ -1099,12 +1161,11 @@ def addchest(self, loc, tier=-1, loot=[], name=''): inv_tag.append(item_tag) self.tile_ents[loc] = root_tag - def addchestitem_tag(self, loc, item_tag): '''Add an item to an existing chest''' # No chest here! if (loc not in self.tile_ents or - self.tile_ents[loc]['id'].value != 'Chest'): + self.tile_ents[loc]['id'].value != 'Chest'): return False root_tag = self.tile_ents[loc] slot = len(root_tag['Items']) @@ -1121,12 +1182,12 @@ def addchesttrap(self, loc, name=None, count=None): self.addtrap(loc, name=name, count=count) def addtrap(self, loc, name=None, count=None): - if name == None: + if name is None: name = weighted_choice(cfg.master_chest_traps) - if count == None: + if count is None: count = int(cfg.lookup_chest_traps[name][1]) # sanity check for count - if count > 9*64: + if count > 9 * 64: print '\nFATAL: Item count for dispenser trap too large! Max number of items is 9x64 = 576! Check config file.' print 'Item name:', name print 'Count:', count @@ -1149,7 +1210,8 @@ def addtrap(self, loc, name=None, count=None): item_tag['Count'] = nbt.TAG_Byte(count) count -= 64 item_tag['id'] = nbt.TAG_Short(loottable.items.byName(name).value) - item_tag['Damage'] = nbt.TAG_Short(loottable.items.byName(name).data) + item_tag['Damage'] = nbt.TAG_Short( + loottable.items.byName(name).data) inv_tag.append(item_tag) slot += 1 self.tile_ents[loc] = root_tag @@ -1168,7 +1230,7 @@ def addtileentity(self, root_tag): def setroom(self, coord, room): if coord not in self.rooms: self.rooms[coord] = room - #print 'setroom:', coord + # print 'setroom:', coord return room.placed() print 'FATAL: Tried to place a room in a filled location!' print coord @@ -1179,26 +1241,26 @@ def setroom(self, coord, room): def genrooms(self): # Generate the maze used for room and hall placement. - # stairwells contains the lower half of a stairwell. + # stairwells contains the lower half of a stairwell. self.stairwells = [] entrance_pos = None exit_pos = None # The size of our dungeon. Note this is once less in the depth # dimension, because for most of the dungeon we don't want multilevel - # rooms to extend to the last level. - dsize = Vec(self.xsize, self.levels-1, self.zsize) + # rooms to extend to the last level. + dsize = Vec(self.xsize, self.levels - 1, self.zsize) # Some convenient lookups. # dirs holds vectors for moving in a cardinal direction. - dirs = {'N': Vec(0,0,-1), - 'E': Vec(1,0,0), - 'S': Vec(0,0,1), - 'W': Vec(-1,0,0)} + dirs = {'N': Vec(0, 0, -1), + 'E': Vec(1, 0, 0), + 'S': Vec(0, 0, 1), + 'W': Vec(-1, 0, 0)} # sides maps a dir to a room side for hall placement. sides = {'N': 0, 'E': 1, 'S': 2, 'W': 3} - # opposite sides for setting the matching hall in the adjacent room. + # opposite sides for setting the matching hall in the adjacent room. osides = {'N': 2, 'E': 3, 'S': 0, @@ -1209,38 +1271,38 @@ def genrooms(self): state = MazeCell.states # Start in a random location on level 1, unless the -e - # options was used. + # options was used. if (self.args.entrance is not None): x = self.args.entrance[0] z = self.args.entrance[1] else: - x = random.randint(0, self.xsize-1) - z = random.randint(0, self.zsize-1) + x = random.randint(0, self.xsize - 1) + z = random.randint(0, self.zsize - 1) # A maximum "depth" value. (depth being distance from the level - # entrance) No one room can be this deep on a single # level. + # entrance) No one room can be this deep on a single # level. maxdepth = self.xsize * self.zsize * self.levels + 1 - # A disjoint set in which to keep our room sets. + # A disjoint set in which to keep our room sets. ds = DisjointSet() - # Generate a maze for each level. + # Generate a maze for each level. for y in xrange(self.levels): # If we are on the last level, allow rooms on this level. Normally # we don't allow rooms to extend to the last level to prevent multi - # level rooms from crossing the treasure chamber. - if (y == self.levels-1): + # level rooms from crossing the treasure chamber. + if (y == self.levels - 1): dsize = dsize.down(1) # The level starts here. - level_start = Vec(x,y,z) + level_start = Vec(x, y, z) # The first cell contains an entrance. This is a tower if we are on - # level 1, otherwise it's a stairwell. + # level 1, otherwise it's a stairwell. if (y == 0): # Add the entrance cell to the stairwells list. - self.stairwells.append(Vec(x,y,z)) + self.stairwells.append(Vec(x, y, z)) # For all levels except the last level, rooms can be as big as # they want. For the last level it has to be 1x1x1. - maxsize = Vec(10,18,10) - if (y == self.levels-1): - maxsize = Vec(1,1,1) + maxsize = Vec(10, 18, 10) + if (y == self.levels - 1): + maxsize = Vec(1, 1, 1) # Pick an entrance capable room, place it, find the room that # contains the actual entrance (for multi-tile rooms) and place # the entrance feature there. Record the entrance feature for @@ -1254,12 +1316,12 @@ def genrooms(self): eroom.features.append(feature) feature.placed() self.entrance = feature - # Mark cell as connected or used. + # Mark cell as connected or used. # Cells on this level are marked as connected so we can branch # off of them as needed. Cells on other levels are marked as # used, so they can be connected to later. Each set of cells on # other levels is its own set in the disjoint set so we can - # mange connections to them later. + # mange connections to them later. roots = {} for p in ps: if p.y == y: @@ -1278,11 +1340,11 @@ def genrooms(self): x = p.x z = p.z else: - #Any other start cell on a lower level is a stairwell - self.stairwells.append(Vec(x,y,z)) - maxsize = Vec(10,18,10) - if (y == self.levels-1): - maxsize = Vec(1,1,1) + # Any other start cell on a lower level is a stairwell + self.stairwells.append(Vec(x, y, z)) + maxsize = Vec(10, 18, 10) + if (y == self.levels - 1): + maxsize = Vec(1, 1, 1) room, pos = rooms.pickRoom(self, dsize, level_start, stairwell=True, maxsize=maxsize) ps = self.setroom(pos, room) @@ -1309,25 +1371,25 @@ def genrooms(self): x = p.x z = p.z # Upstairs. Override the feature of the room above to blank so - # it can hold the stairwell. + # it can hold the stairwell. posup = level_start.up(1) room = self.rooms[posup] feature = features.new('blank', room) room.features.append(feature) feature.placed() - # If we are on the last level, place a treasure room. - if (y == self.levels-1): + # If we are on the last level, place a treasure room. + if (y == self.levels - 1): # Try to find a location as far away from the level_start as # possible. - pos = Vec(0,y,0) - if (level_start.x < self.xsize/2): - pos.x = self.xsize-1 - if (level_start.z < self.zsize/2): - pos.z = self.zsize-1 + pos = Vec(0, y, 0) + if (level_start.x < self.xsize / 2): + pos.x = self.xsize - 1 + if (level_start.z < self.zsize / 2): + pos.z = self.zsize - 1 exit_pos = pos # Pick a treasure capable room room, pos = rooms.pickRoom(self, dsize, pos, treasure=True, - room_list = cfg.master_treasure, + room_list=cfg.master_treasure, default='pitwitharchers') ps = self.setroom(pos, room) feature = features.new('blank', room) @@ -1337,7 +1399,7 @@ def genrooms(self): # Place all these cells into a RESTRICTED set for connection # later. These have a depth of zero, since we don't want to # count them in the depth calculation. This helps keep shortcuts - # to the treasure room to a minimum. + # to the treasure room to a minimum. root1 = ds.find(pos) for p in ps: root2 = ds.find(p) @@ -1346,32 +1408,34 @@ def genrooms(self): self.maze[p].state = state.RESTRICTED if self.maze[p].depth >= 0: self.maze[p].depth = 0 - while 1: + while True: # Walk the maze. - if self.args.debug == True: - self.printmaze(y, cursor=Vec(x,y,z)) + if self.args.debug: + self.printmaze(y, cursor=Vec(x, y, z)) # Shuffle the directions. random.shuffle(dkeys) - # Store the last known cell. + # Store the last known cell. lx = x lz = z # Work through all possible directions, looking for a valid - # one. + # one. for d in dkeys: - # (nx, nz) is the next cell to consider. + # (nx, nz) is the next cell to consider. nx = x + dirs[d].x nz = z + dirs[d].z # Check to see if the next cell is valid. It must - # be within the bounds of the level, and not yet connected. + # be within the bounds of the level, and not yet connected. if (nx >= 0 and nz >= 0 and nx < self.xsize and nz < self.zsize and - (self.maze[Vec(nx,y,nz)].state == state.BLANK or - self.maze[Vec(nx,y,nz)].state == state.USED)): + (self.maze[Vec(nx, y, nz)].state == state.BLANK or + self.maze[Vec(nx, y, nz)].state == state.USED)): # For blank cells, we generate a new room - if self.maze[Vec(nx,y,nz)].state == state.BLANK: - room, pos = rooms.pickRoom(self, dsize, Vec(nx,y,nz)) + if self.maze[Vec(nx, y, nz)].state == state.BLANK: + room, pos = rooms.pickRoom( + self, dsize, Vec( + nx, y, nz)) ps = self.setroom(pos, room) roots = {} for p in ps: @@ -1391,17 +1455,17 @@ def genrooms(self): # For used rooms, we grab the set of rooms and pick a # random one. Reset all the room to connected. else: - root = ds.find(Vec(nx,y,nz)) + root = ds.find(Vec(nx, y, nz)) sets = ds.split_sets() ps = sets[root] for p in ps: self.maze[p].state = state.CONNECTED # Mark the halls leaving the current cell and the # next cell as connected. We'll set the hall class - # later. + # later. self.halls[x][y][z][sides[d]] = 1 self.halls[nx][y][nz][osides[d]] = 1 - # Set the current cell. + # Set the current cell. p = choice(ps) x = p.x z = p.z @@ -1411,42 +1475,44 @@ def genrooms(self): # If we're stuck, hunt for a new starting cell. If # the above loop found a direction to move then we skip # this. Otherwise we start at (0,0) and try to find an - # disconnected cell that has a connected neighbor we can - # connect to. + # disconnected cell that has a connected neighbor we can + # connect to. if (lx == x and lz == z): - #print 'Hunting...' - for p in iterate_plane(Vec(0,y,0), - Vec(self.xsize-1,y,self.zsize-1)): + # print 'Hunting...' + for p in iterate_plane(Vec(0, y, 0), + Vec(self.xsize - 1, y, self.zsize - 1)): # Cell was connected, keep looking. - if (self.maze[Vec(p.x,y,p.z)].state == - state.CONNECTED - or - self.maze[Vec(p.x,y,p.z)].state == - state.RESTRICTED): + if (self.maze[Vec(p.x, y, p.z)].state == + state.CONNECTED + or + self.maze[Vec(p.x, y, p.z)].state == + state.RESTRICTED): continue # Cell is disconnected. Let's try to connect it to a # neighbor. First, catalog which directions have a - # connected neighbor. + # connected neighbor. neighbors = [] for d in dkeys: - key = Vec(p.x,y,p.z)+dirs[d] + key = Vec(p.x, y, p.z) + dirs[d] if(key in self.maze and self.maze[key].state == state.CONNECTED): neighbors.append(d) - # If there are no connected neighbors, keep looking. + # If there are no connected neighbors, keep looking. if (len(neighbors) == 0): continue # We found one! Pick a random connected neighbor cell # and connect the halls. Set our current cell and move - # on like nothing is wrong. + # on like nothing is wrong. d = random.choice(neighbors) x = p.x z = p.z ox = x + dirs[d].x oz = z + dirs[d].z # If this is a BLANK cell, generate a new room. - if (self.maze[Vec(x,y,z)].state == state.BLANK): - room, pos = rooms.pickRoom(self, dsize, Vec(x,y,z)) + if (self.maze[Vec(x, y, z)].state == state.BLANK): + room, pos = rooms.pickRoom( + self, dsize, Vec( + x, y, z)) ps = self.setroom(pos, room) roots = {} for p in ps: @@ -1464,7 +1530,7 @@ def genrooms(self): # For used rooms, we grab the set of rooms and pick a # random one. Set all the rooms to connected. else: - root = ds.find(Vec(x,y,z)) + root = ds.find(Vec(x, y, z)) sets = ds.split_sets() ps = sets[root] for p in ps: @@ -1477,133 +1543,135 @@ def genrooms(self): break # If the last cell and current cell are still the same (we could - # not move, and the hunt failed) then we've filled the level. + # not move, and the hunt failed) then we've filled the level. # Recalculate the depth tree, find the deepest cell on # this level, and use it for the stairwell (starting point) # on the next. if (lx == x and lz == z): # Sprinkle some extra hallways into the dungeon using the - # loops config parameter. - for p in iterate_plane(Vec(0,y,0), - Vec(self.xsize-1,y,self.zsize-1)): + # loops config parameter. + for p in iterate_plane(Vec(0, y, 0), + Vec(self.xsize - 1, y, self.zsize - 1)): for d in dirs.keys(): nx = p.x + dirs[d].x nz = p.z + dirs[d].z if (nx >= 0 and - nz >= 0 and - nx < self.xsize and - nz < self.zsize): + nz >= 0 and + nx < self.xsize and + nz < self.zsize): if (self.halls[p.x][y][p.z][sides[d]] is not 1 and - self.halls[nx][y][nz][osides[d]] is not 1 and - random.randint(1,100) <= cfg.loops): + self.halls[nx][y][nz][osides[d]] is not 1 and + random.randint(1, 100) <= cfg.loops): self.halls[p.x][y][p.z][sides[d]] = 1 self.halls[nx][y][nz][osides[d]] = 1 - if self.args.debug == True: + if self.args.debug: print 'Post loops:' - self.printmaze(y, cursor=Vec(x,y,z)) + self.printmaze(y, cursor=Vec(x, y, z)) # Rebuild the depth tree. # The first room on this level has a depth of 1 self.maze[level_start].depth = 1 recurse = True - while (recurse == True): + while (recurse): recurse = False - for p in iterate_plane(Vec(0,y,0), - Vec(self.xsize-1,y,self.zsize-1)): - if (self.maze[Vec(p.x,y,p.z)].depth == maxdepth): + for p in iterate_plane(Vec(0, y, 0), + Vec(self.xsize - 1, y, self.zsize - 1)): + if (self.maze[Vec(p.x, y, p.z)].depth == maxdepth): recurse = True depth = maxdepth for d in dirs.keys(): - if (self.halls[p.x][y][p.z][sides[d]]==1): + if (self.halls[p.x][y][p.z][sides[d]] == 1): depth = min( - self.maze[Vec(p.x,y,p.z)+dirs[d]].depth+1, - self.maze[Vec(p.x,y,p.z)].depth) - self.maze[Vec(p.x,y,p.z)].depth = depth + self.maze[Vec(p.x, y, p.z) + dirs[d]].depth + 1, + self.maze[Vec(p.x, y, p.z)].depth) + self.maze[ + Vec(p.x, y, p.z)].depth = depth # Find the deepest cell on this level that can contain a # stairwell. depth = 0 - for p in iterate_plane(Vec(0,y,0), - Vec(self.xsize-1,y,self.zsize-1)): - if (self.maze[Vec(p.x,y,p.z)].depth > depth and - self.rooms[Vec(p.x,y,p.z)]._is_stairwell == True): - depth = self.maze[Vec(p.x,y,p.z)].depth + for p in iterate_plane(Vec(0, y, 0), + Vec(self.xsize - 1, y, self.zsize - 1)): + if (self.maze[Vec(p.x, y, p.z)].depth > depth and + self.rooms[Vec(p.x, y, p.z)]._is_stairwell): + depth = self.maze[Vec(p.x, y, p.z)].depth x = p.x z = p.z break # Connect the treasure room. Find the deepest cell that has a neighbor - # with a depth of zero and connect it. + # with a depth of zero and connect it. depth = 0 - point = Vec(0,0,0) - opoint = Vec(0,0,0) + point = Vec(0, 0, 0) + opoint = Vec(0, 0, 0) dr = 'N' - for p in iterate_plane(Vec(0,y,0), Vec(self.xsize-1,y,self.zsize-1)): - if (self.maze[Vec(p.x,y,p.z)].depth > depth): - for d,v in dirs.items(): - if (p+v in self.maze and self.maze[p+v].depth == 0): + for p in iterate_plane(Vec(0, y, 0), Vec(self.xsize - 1, y, self.zsize - 1)): + if (self.maze[Vec(p.x, y, p.z)].depth > depth): + for d, v in dirs.items(): + if (p + v in self.maze and self.maze[p + v].depth == 0): point = p - opoint = p+v - depth = self.maze[Vec(p.x,y,p.z)].depth + opoint = p + v + depth = self.maze[Vec(p.x, y, p.z)].depth dr = d self.halls[point.x][y][point.z][sides[dr]] = 1 self.halls[opoint.x][y][opoint.z][osides[dr]] = 1 - if self.args.debug == True: + if self.args.debug: print 'Post treasure:' - self.printmaze(y, cursor=Vec(x,y,z)) + self.printmaze(y, cursor=Vec(x, y, z)) self.entrance_pos = entrance_pos if self.args.debug: print 'Entrance:', entrance_pos print 'Exit:', exit_pos - def genhalls(self): '''Step through all rooms and generate halls where possible''' for y in xrange(self.levels): for x in xrange(self.xsize): for z in xrange(self.zsize): - pos = Vec(x,y,z) + pos = Vec(x, y, z) if (pos not in self.rooms): continue for d in xrange(4): if (self.halls[x][y][z][d] == 1 and - self.rooms[pos].hallLength[d] > 0): - hall_list = weighted_shuffle(cfg.master_halls) - hall_list.insert(0, 'Blank') - while (len(hall_list)): - newhall = hall_list.pop() - newsize = halls.sizeByName(newhall) - nextpos = pos+pos.d(d) - nextd = (d+2)%4 - # Get valid offsets for this room - # and the adjoining room. - # First test the current room. - result1 = self.rooms[pos].testHall( - d, - newsize, - self.rooms[nextpos].hallSize[nextd][0], - self.rooms[nextpos].hallSize[nextd][1]) - result2 = self.rooms[nextpos].testHall( - nextd, - newsize, - self.rooms[pos].hallSize[d][0], - self.rooms[pos].hallSize[d][1]) - if (result1 is not False and - result2 is not False): - offset = randint(min(result1[0], - result2[0]), - max(result1[1], - result2[1])) - self.rooms[pos].halls[d] = \ - halls.new(newhall, self.rooms[pos], d, - offset) - self.rooms[nextpos].halls[nextd] = \ - halls.new(newhall, self.rooms[nextpos], - nextd, offset) - hall_list = [] + self.rooms[pos].hallLength[d] > 0): + hall_list = weighted_shuffle(cfg.master_halls) + hall_list.insert(0, 'Blank') + while (len(hall_list)): + newhall = hall_list.pop() + newsize = halls.sizeByName(newhall) + nextpos = pos + pos.d(d) + nextd = (d + 2) % 4 + # Get valid offsets for this room + # and the adjoining room. + # First test the current room. + result1 = self.rooms[pos].testHall( + d, + newsize, + self.rooms[nextpos].hallSize[nextd][0], + self.rooms[nextpos].hallSize[nextd][1]) + result2 = self.rooms[nextpos].testHall( + nextd, + newsize, + self.rooms[pos].hallSize[d][0], + self.rooms[pos].hallSize[d][1]) + if (result1 is not False and + result2 is not False): + offset = randint(min(result1[0], + result2[0]), + max(result1[1], + result2[1])) + self.rooms[pos].halls[d] = \ + halls.new(newhall, self.rooms[pos], d, + offset) + self.rooms[nextpos].halls[nextd] = \ + halls.new(newhall, self.rooms[nextpos], + nextd, offset) + hall_list = [] else: - self.rooms[pos].halls[d] = halls.new('blank', - self.rooms[pos], - d, 6) + self.rooms[pos].halls[d] = halls.new( + 'blank', + self.rooms[pos], + d, + 6) def genhalltraps(self): '''Place hallway traps''' @@ -1626,7 +1694,7 @@ def genhalltraps(self): r1 = self.rooms[p1] # W-E hall if (r1.halls[d.E]._name is not 'blank'): - r2 = self.rooms[p1+dv[d.E]] + r2 = self.rooms[p1 + dv[d.E]] if ( r1.features[0]._is_secret is not True and r2.features[0]._is_secret is not True @@ -1634,11 +1702,11 @@ def genhalltraps(self): offset = r1.halls[d.E].offset size = r1.halls[d.E].size pos = Vec( - p1.x*16, - p1.y*6, - p1.z*16 - ) +Vec( - 16-r1.hallLength[d.E], + p1.x * 16, + p1.y * 6, + p1.z * 16 + ) + Vec( + 16 - r1.hallLength[d.E], 0, offset ) @@ -1651,7 +1719,7 @@ def genhalltraps(self): }) # N-S hall if (r1.halls[d.S]._name is not 'blank'): - r2 = self.rooms[p1+dv[d.S]] + r2 = self.rooms[p1 + dv[d.S]] if ( r1.features[0]._is_secret is not True and r2.features[0]._is_secret is not True @@ -1659,13 +1727,13 @@ def genhalltraps(self): offset = r1.halls[d.S].offset size = r1.halls[d.S].size pos = Vec( - p1.x*16, - p1.y*6, - p1.z*16 - ) +Vec( + p1.x * 16, + p1.y * 6, + p1.z * 16 + ) + Vec( offset, 0, - 16-r1.hallLength[d.S] + 16 - r1.hallLength[d.S] ) length = r1.hallLength[d.S] + r2.hallLength[d.N] halls.append({ @@ -1675,7 +1743,6 @@ def genhalltraps(self): 'direction': d.S, }) - # Assign a hall trap class to each hall. for hall in halls: # Weighted shuffle the traps, and default to Blank. @@ -1699,7 +1766,6 @@ def genhalltraps(self): self.hall_traps.append(trap) trap_list = [] - def genfloors(self): for pos in self.rooms: if (len(self.rooms[pos].floors) == 0): @@ -1718,54 +1784,59 @@ def genfeatures(self): def genruins(self): for pos in self.rooms: if (pos.y == 0 and - len(self.rooms[pos].ruins) == 0): + len(self.rooms[pos].ruins) == 0): if pos == self.entrance.parent.pos: try: - ruin = ruins.new(weighted_choice(cfg.master_entrances[self.biome]), - self.rooms[pos]) + ruin = ruins.new( + weighted_choice( + cfg.master_entrances[ + self.biome]), + self.rooms[pos]) except KeyError: - ruin = ruins.new(weighted_choice(cfg.default_entrances), - self.rooms[pos]) + ruin = ruins.new( + weighted_choice( + cfg.default_entrances), + self.rooms[pos]) self.dinfo['dungeon_name'] = ruin.nameDungeon() else: ruin = ruins.new(weighted_choice(cfg.master_ruins), - self.rooms[pos]) + self.rooms[pos]) self.rooms[pos].ruins.append(ruin) ruin.placed(self.world) def placetorches(self, level=0): '''Place a proportion of the torches where possible''' if (self.levels > 1): - perc = int(float(level) / float(self.levels-1) * - (cfg.torches_bottom-cfg.torches_top) + - cfg.torches_top) + perc = int(float(level) / float(self.levels - 1) * + (cfg.torches_bottom - cfg.torches_top) + + cfg.torches_top) else: perc = cfg.torches_top count = 0 maxcount = 0 for pos, val in self.torches.items(): - if (pos.up(1).y/self.room_height == level): + if (pos.up(1).y / self.room_height == level): maxcount += 1 maxcount = perc * maxcount / 100 offset = 3 - cfg.torches_position dirs = { - '1': Vec(-1,0,0), - '2': Vec(1,0,0), - '3': Vec(0,0,-1), - '4': Vec(0,0,1) + '1': Vec(-1, 0, 0), + '2': Vec(1, 0, 0), + '3': Vec(0, 0, -1), + '4': Vec(0, 0, 1) } for pos, val in self.torches.items(): attach_pos = pos.down(offset) + dirs[str(val)] if (count < maxcount and - pos in self.blocks and - self.blocks[pos.down(offset)].material == materials.Air and - self.blocks[attach_pos].material == materials._wall and - pos.up(1).y/self.room_height == level): + pos in self.blocks and + self.blocks[pos.down(offset)].material == materials.Air and + self.blocks[attach_pos].material == materials._wall and + pos.up(1).y / self.room_height == level): #self.blocks[pos.down(offset)].material = materials.Torch self.setblock(pos.down(offset), materials.Torch, val) count += 1 - if (level < self.levels-1): - self.placetorches(level+1) + if (level < self.levels - 1): + self.placetorches(level + 1) def placedoors(self, perc): '''Place a proportion of the doors where possible''' @@ -1774,19 +1845,23 @@ def placedoors(self, perc): # doors are populated N->S and W->E # This holds direction and starting hinge side # N E S W - doordat = ((1,1), (2,1), (3,0), (0,0)) + doordat = ((1, 1), (2, 1), (3, 0), (0, 0)) maxcount = perc * len(self.doors) / 100 for pos, door in self.doors.items(): if (count < maxcount): x = doordat[door.direction][1] for dpos in door.doors: - if(dpos in self.blocks and self.blocks[dpos].material == materials.Air): + if(dpos in self.blocks and self.blocks[dpos].material == materials.Air): self.setblock(dpos, materials._wall, hide=True) self.blocks[dpos.down(1)].material = door.material - #self.blocks[dpos.down(1)].data = doordat[door.direction][x] | 8 # Top door - self.blocks[dpos.down(1)].data = 8+x # Top door & hinge + # self.blocks[dpos.down(1)].data = + # doordat[door.direction][x] | 8 # Top door + self.blocks[ + dpos.down(1)].data = 8 + x # Top door & hinge self.blocks[dpos.down(2)].material = door.material - self.blocks[dpos.down(2)].data = doordat[door.direction][0] + self.blocks[ + dpos.down(2)].data = doordat[ + door.direction][0] x = 1 - x count += 1 @@ -1807,10 +1882,10 @@ def placechests(self, level=0): hcount += 1 # If the canvas is too small, don't bother. if (self.rooms[room].canvasWidth() < 2 or - self.rooms[room].canvasLength() < 2): + self.rooms[room].canvasLength() < 2): hcount = 0 # The weight is exponential. Base 20 seems to work well. - candidates.append((room, 20**hcount-1)) + candidates.append((room, 20 ** hcount - 1)) # Shuffle potential locations. locations = weighted_shuffle(candidates) while (len(locations) > 0 and chests > 0): @@ -1821,9 +1896,9 @@ def placechests(self, level=0): for point in iterate_points_inside_flat_poly(*room.canvas): point += room.loc if (point not in self.blocks or - point.up(1) not in self.blocks or - point.up(2) not in self.blocks or - point.down(1) not in self.blocks): + point.up(1) not in self.blocks or + point.up(2) not in self.blocks or + point.down(1) not in self.blocks): continue if( self.blocks[point].material.val in materials.vine_solids and @@ -1841,7 +1916,7 @@ def placechests(self, level=0): if (len(points) > 0): point = random.choice(points) # Decide if we are a trap - if randint(1,100) <= cfg.chest_traps: + if randint(1, 100) <= cfg.chest_traps: self.setblock(point.up(1), materials.TrappedChest) self.setblock(point, materials.Dispenser, 1) self.addchesttrap(point) @@ -1850,9 +1925,8 @@ def placechests(self, level=0): # Add the chest entity either way self.addchest(point.up(1)) chests -= 1 - if (level < self.levels-1): - self.placechests(level+1) - + if (level < self.levels - 1): + self.placechests(level + 1) def placespawners(self, level=0): '''Place spawners in the dungeon. This is called with no arguments, @@ -1871,10 +1945,10 @@ def placespawners(self, level=0): hcount += 1 # If the canvas is too small, don't bother. if (self.rooms[room].canvasWidth() < 2 or - self.rooms[room].canvasLength() < 2): + self.rooms[room].canvasLength() < 2): hcount = 0 # The weight is exponential. Base 20 seems to work well. - candidates.append((room, 20**hcount-1)) + candidates.append((room, 20 ** hcount - 1)) # Shuffle potential locations. locations = weighted_shuffle(candidates) while (len(locations) > 0 and spawners > 0): @@ -1887,9 +1961,9 @@ def placespawners(self, level=0): for point in iterate_points_inside_flat_poly(*room.canvas): point += room.loc if (point not in self.blocks or - point.up(1) not in self.blocks or - point.up(2) not in self.blocks or - point.down(1) not in self.blocks): + point.up(1) not in self.blocks or + point.up(2) not in self.blocks or + point.down(1) not in self.blocks): continue if( self.blocks[point].material.val in materials.vine_solids and @@ -1901,16 +1975,16 @@ def placespawners(self, level=0): y = room.canvasHeight() for x in xrange(self.room_size): for z in xrange(self.room_size): - p = room.loc+Vec(x,y,z) - adj = [Vec(1,0,0), Vec(0,0,1), - Vec(-1,0,0), Vec(0,0,-1)] + p = room.loc + Vec(x, y, z) + adj = [Vec(1, 0, 0), Vec(0, 0, 1), + Vec(-1, 0, 0), Vec(0, 0, -1)] walls = 0 for q in adj: - if (p+q in self.blocks and - self.getblock(p+q) == materials._wall): + if (p + q in self.blocks and + self.getblock(p + q) == materials._wall): walls += 1 if (p.up(1) not in self.blocks and - walls > 0): + walls > 0): points.append(p) # Pick a spot, if one exists. @@ -1919,8 +1993,8 @@ def placespawners(self, level=0): self.setblock(point, materials.Spawner) self.addspawner(point) spawners -= 1 - if (level < self.levels-1): - self.placespawners(level+1) + if (level < self.levels - 1): + self.placespawners(level + 1) def renderhalltraps(self): '''Render hallway traps''' @@ -1944,12 +2018,12 @@ def renderrooms(self): def renderhalls(self): ''' Call render() on all halls''' - count = len(self.rooms)*4 + count = len(self.rooms) * 4 self.pm.init(count, label='Rendering halls:') for pos in self.rooms: self.pm.update_left(count) count -= 4 - for x in xrange(0,4): + for x in xrange(0, 4): if (self.rooms[pos].halls[x]): self.rooms[pos].halls[x].render() self.pm.set_complete() @@ -1957,7 +2031,7 @@ def renderhalls(self): def renderfloors(self): ''' Call render() on all floors''' count = len(self.rooms) - self.pm.init(count,label='Rendering floors:') + self.pm.init(count, label='Rendering floors:') for pos in self.rooms: self.pm.update_left(count) count -= 1 @@ -1991,30 +2065,29 @@ def outputterminal(self): '''Print a slice (or layer) of the dungeon block buffer to the termial. We "look-through" any air blocks to blocks underneath''' floor = self.args.term - layer = (floor-1)*self.room_height - for z in xrange(self.zsize*self.room_size): - for x in xrange(self.xsize*self.room_size): + layer = (floor - 1) * self.room_height + for z in xrange(self.zsize * self.room_size): + for x in xrange(self.xsize * self.room_size): y = layer while (y < layer + self.room_height - 1 and - Vec(x,y,z) in self.blocks and - (self.blocks[Vec(x,y,z)].hide == True or - self.blocks[Vec(x,y,z)].material == materials.Air or - self.blocks[Vec(x,y,z)].material == materials._ceiling)): + Vec(x, y, z) in self.blocks and + (self.blocks[Vec(x, y, z)].hide or + self.blocks[Vec(x, y, z)].material == materials.Air or + self.blocks[Vec(x, y, z)].material == materials._ceiling)): y += 1 - if (Vec(x,y,z) in self.blocks and - self.blocks[Vec(x,y,z)].hide == False): - mat = self.blocks[Vec(x,y,z)].material - if (mat._meta == True): - mat.update(x,y,z, - self.xsize*self.room_size, - self.levels*self.room_height, - self.zsize*self.room_size) + if (Vec(x, y, z) in self.blocks and + self.blocks[Vec(x, y, z)].hide == False): + mat = self.blocks[Vec(x, y, z)].material + if (mat._meta): + mat.update(x, y, z, + self.xsize * self.room_size, + self.levels * self.room_height, + self.zsize * self.room_size) sys.stdout.write(mat.c) else: sys.stdout.write(materials.NOBLOCK) print - def outputhtml(self): '''Print all levels of the dungeon block buffer to html. We "look-through" any air blocks to blocks underneath''' @@ -2023,7 +2096,7 @@ def outputhtml(self): # First search for existing files if (force == False): for floor in xrange(self.levels): - filename = basename+'-'+str(floor+1)+'.html' + filename = basename + '-' + str(floor + 1) + '.html' if (os.path.isfile(filename)): sys.exit('File %s exists. Use --force to overwrite.' % (filename)) @@ -2045,52 +2118,52 @@ def outputhtml(self): footer = '''''' # Output each level file. for floor in xrange(self.levels): - layer = floor*self.room_height + layer = floor * self.room_height # Build the form. form = '''

' # Write the floor file. - filename = basename+'-'+str(floor+1)+'.html' - print 'Writing:',filename + filename = basename + '-' + str(floor + 1) + '.html' + print 'Writing:', filename f = open(filename, 'w') - f.write(header+form) + f.write(header + form) f.write('') - for z in xrange(self.zsize*self.room_size): + for z in xrange(self.zsize * self.room_size): f.write('') - for x in xrange(self.xsize*self.room_size): + for x in xrange(self.xsize * self.room_size): y = layer - while (Vec(x,y,z) in self.blocks and - (self.blocks[Vec(x,y,z)].hide == True or - self.blocks[Vec(x,y,z)].material == + while (Vec(x, y, z) in self.blocks and + (self.blocks[Vec(x, y, z)].hide or + self.blocks[Vec(x, y, z)].material == materials.Air or - self.blocks[Vec(x,y,z)].material == + self.blocks[Vec(x, y, z)].material == materials._ceiling)): y += 1 - if (Vec(x,y,z) in self.blocks): - mat = self.blocks[Vec(x,y,z)].material - if (mat._meta == True): - mat.update(x,y,z, - self.xsize*self.room_size, - self.levels*self.room_height, - self.zsize*self.room_size) - self.blocks[Vec(x,y,z)].data = mat.data - dat = self.blocks[Vec(x,y,z)].data + if (Vec(x, y, z) in self.blocks): + mat = self.blocks[Vec(x, y, z)].material + if (mat._meta): + mat.update(x, y, z, + self.xsize * self.room_size, + self.levels * self.room_height, + self.zsize * self.room_size) + self.blocks[Vec(x, y, z)].data = mat.data + dat = self.blocks[Vec(x, y, z)].data # Doors are ... different if (mat == materials.WoodenDoor or - mat == materials.IronDoor): - dat2 = self.blocks[Vec(x,y+1,z)].data + mat == materials.IronDoor): + dat2 = self.blocks[Vec(x, y + 1, z)].data dat = ((dat & 1) << 3) + dat2 f.write('
' % @@ -2104,21 +2177,21 @@ def outputhtml(self): def findsecretrooms(self): # Secret rooms must satisfy the following... # 1. The room cannot be an entrance, stairwell, or above a stairwell - # 2. Must be a 1x1x1 room. + # 2. Must be a 1x1x1 room. # 3. Must not be a blank room. # 4. Must have exactly one hallway. # 5. Must not connect to a corridor. - # 6. ... That's it. + # 6. ... That's it. # # If found, the room will have its feature overridden with SecretRoom - # the hallway will be reduced to 1 and move away from the edge if - # required. + # the hallway will be reduced to 1 and move away from the edge if + # required. # hall positions to grid direction - dirs = {3: Vec(-1,0,0), - 1: Vec(1,0,0), - 2: Vec(0,0,1), - 0: Vec(0,0,-1)} + dirs = {3: Vec(-1, 0, 0), + 1: Vec(1, 0, 0), + 2: Vec(0, 0, 1), + 0: Vec(0, 0, -1)} # Find them for p in self.rooms: @@ -2127,22 +2200,22 @@ def findsecretrooms(self): continue if room.features[0]._is_stairwell: continue - if p.y < self.levels-1: + if p.y < self.levels - 1: droom = self.rooms[p.down(1)] if droom.features[0]._is_stairwell: continue - if room.size != Vec(1,1,1): + if room.size != Vec(1, 1, 1): continue if (room._name == 'blank' or - room._name == 'cblank' or - room._name == 'blankstairwell' or - room._name == 'circularpit' or - room._name == 'circularpitmid' or - room._name == 'circularpitbottom' or - room._name == 'pit' or - room._name == 'pitmid' or - room._name == 'pitbottom' - ): + room._name == 'cblank' or + room._name == 'blankstairwell' or + room._name == 'circularpit' or + room._name == 'circularpitmid' or + room._name == 'circularpitbottom' or + room._name == 'pit' or + room._name == 'pitmid' or + room._name == 'pitbottom' + ): continue hallsum = 0 d = 0 @@ -2152,25 +2225,29 @@ def findsecretrooms(self): hallsum += 1 if hallsum != 1: continue - room2 = self.rooms[p+dirs[d]] + room2 = self.rooms[p + dirs[d]] if (room2._name == 'corridor' or - room2._name == 'cblank' or - room2._name == 'sandstonecavern' or - room2._name == 'sandstonecavernlarge' or - room2._name == 'cavern' or - room2._name == 'cavernlarge' or - room2._name == 'naturalcavern' or - room2._name == 'naturalcavernlarge' - ): + room2._name == 'cblank' or + room2._name == 'sandstonecavern' or + room2._name == 'sandstonecavernlarge' or + room2._name == 'cavern' or + room2._name == 'cavernlarge' or + room2._name == 'naturalcavern' or + room2._name == 'naturalcavernlarge' + ): continue - if random.randint(1,100) > cfg.secret_rooms: + if random.randint(1, 100) > cfg.secret_rooms: continue - if self.args.debug == True: - print 'Secret room from',room._name, 'to', room2._name + if self.args.debug: + print 'Secret room from', room._name, 'to', room2._name # Override this room's feature room.features = [] - room.features.append(features.new(weighted_choice(cfg.master_srooms), room)) + room.features.append( + features.new( + weighted_choice( + cfg.master_srooms), + room)) room.features[0].placed() # override this room's hallway offset = room.halls[d].offset @@ -2181,7 +2258,7 @@ def findsecretrooms(self): room.halls[d] = halls.new('single', room, d, offset) room.hallLength[d] = 3 # override the other room's hallway - od = (d+2)%4 + od = (d + 2) % 4 offset = room2.halls[od].offset if offset < 4: offset = 4 @@ -2189,62 +2266,64 @@ def findsecretrooms(self): offset = 9 room2.halls[od] = halls.new('single', room2, od, offset) - def setentrance(self): - if self.args.debug: print 'Extending entrance to the surface...' - wcoord=Vec(self.entrance.parent.loc.x + self.position.x, - self.position.y - self.entrance.parent.loc.y, - self.entrance.parent.loc.z + self.position.z) - if self.args.debug: print ' World coord:',wcoord - baseheight = wcoord.y + 2 # plenum + floor + if self.args.debug: + print 'Extending entrance to the surface...' + wcoord = Vec(self.entrance.parent.loc.x + self.position.x, + self.position.y - self.entrance.parent.loc.y, + self.entrance.parent.loc.z + self.position.z) + if self.args.debug: + print ' World coord:', wcoord + baseheight = wcoord.y + 2 # plenum + floor #newheight = baseheight low_height = self.world.Height high_height = baseheight - if self.args.debug: print ' Base height:',baseheight - chunk = self.world.getChunk(wcoord.x>>4, wcoord.z>>4) - for x in xrange(wcoord.x+4, wcoord.x+12): - for z in xrange(wcoord.z+4, wcoord.z+12): + if self.args.debug: + print ' Base height:', baseheight + chunk = self.world.getChunk(wcoord.x >> 4, wcoord.z >> 4) + for x in xrange(wcoord.x + 4, wcoord.x + 12): + for z in xrange(wcoord.z + 4, wcoord.z + 12): xInChunk = x & 0xf zInChunk = z & 0xf # Heightmap is a good starting place, but I need to look # down through foliage. - y = chunk.HeightMap[zInChunk, xInChunk]-1 + y = chunk.HeightMap[zInChunk, xInChunk] - 1 while ( chunk.Blocks[xInChunk, zInChunk, y] not in materials.heightmap_solids ): y -= 1 if (chunk.Blocks[xInChunk, zInChunk, y] == 9 or - chunk.Blocks[xInChunk, zInChunk, y] == 79): + chunk.Blocks[xInChunk, zInChunk, y] == 79): self.entrance.inwater = True high_height = max(y, high_height) low_height = min(y, low_height) if self.args.debug: - print " Low height:",low_height - print " High height:",high_height - if (self.entrance.inwater == True): + print " Low height:", low_height + print " High height:", high_height + if (self.entrance.inwater): print " Entrance is in water." if (low_height - baseheight > 0): self.entrance.height += low_height - baseheight self.entrance.low_height += low_height - baseheight if (high_height - baseheight > 0): self.entrance.high_height += high_height - baseheight - self.entrance.u = int(cfg.tower*self.entrance.u) + self.entrance.u = int(cfg.tower * self.entrance.u) # Check the upper bounds of the tower if (high_height + self.entrance.u >= self.world.Height): self.entrance.u = self.world.Height - 3 - high_height def generatemaps(self): - for level in xrange(1, self.levels+1): + for level in xrange(1, self.levels + 1): if randint(1, 100) > cfg.maps: next m = self.mapstore.generate_map(self, level) - self.addplaceditem(m, max_lev=level-1) + self.addplaceditem(m, max_lev=level - 1) def addplaceditem(self, item_tags, min_lev=-100, max_lev=100): self.placed_items.append({ 'item': item_tags, 'min_lev': min_lev, - 'max_lev': max_lev + 'max_lev': max_lev }) def placeitems(self): @@ -2253,11 +2332,11 @@ def placeitems(self): random.shuffle(ents) for loc in ents: ent = self.tile_ents[loc] - if (repr(loc) == repr(Vec(0,0,0)) or - ent['id'].value != 'Chest'): + if (repr(loc) == repr(Vec(0, 0, 0)) or + ent['id'].value != 'Chest'): next - if (loc.y//self.room_height >= item['min_lev']-1 and - loc.y//self.room_height <= item['max_lev']-1): + if (loc.y // self.room_height >= item['min_lev'] - 1 and + loc.y // self.room_height <= item['max_lev'] - 1): if self.addchestitem_tag(loc, item['item']): break @@ -2268,41 +2347,41 @@ def applychanges(self): num_blocks = len(self.blocks) # Fill caves if (self.dinfo['fill_caves'] is True): - num = (self.zsize+10) * (self.xsize+10) + num = (self.zsize + 10) * (self.xsize + 10) pm = pmeter.ProgressMeter() pm.init(num, label='Filling in caves:') - for z in xrange((self.position.z>>4)-5, - (self.position.z>>4)+self.zsize+5): - for x in xrange((self.position.x>>4)-5, - (self.position.x>>4)+self.xsize+5): + for z in xrange((self.position.z >> 4) - 5, + (self.position.z >> 4) + self.zsize + 5): + for x in xrange((self.position.x >> 4) - 5, + (self.position.x >> 4) + self.xsize + 5): pm.update_left(num) num -= 1 - if ((x,z) in self.good_chunks): - p = Vec(x,0,z) + if ((x, z) in self.good_chunks): + p = Vec(x, 0, z) chunk = world.getChunk(x, z) - miny = self.good_chunks[(x,z)] - air = ( chunk.Blocks[:,:,0:miny] == 0) + miny = self.good_chunks[(x, z)] + air = (chunk.Blocks[:, :, 0:miny] == 0) chunk.Blocks[air] = materials._floor.val changed_chunks.add(chunk) - del(self.good_chunks[(x,z)]) + del(self.good_chunks[(x, z)]) pm.set_complete() # Regeneration if self.args.command == 'regenerate': num = (self.zsize) * (self.xsize) pm = pmeter.ProgressMeter() pm.init(num, label='Regenerating resources/chests:') - for z in xrange((self.position.z>>4), - (self.position.z>>4)+self.zsize): - for x in xrange(self.position.x>>4, - (self.position.x>>4)+self.xsize): + for z in xrange((self.position.z >> 4), + (self.position.z >> 4) + self.zsize): + for x in xrange(self.position.x >> 4, + (self.position.x >> 4) + self.xsize): pm.update_left(num) num -= 1 - p = Vec(x,0,z) + p = Vec(x, 0, z) chunk = world.getChunk(x, z) # Repopulate any above ground chests for tileEntity in chunk.TileEntities: if (tileEntity["id"].value == "Chest"): - p = Vec(0,0,0) + p = Vec(0, 0, 0) for name, tag in tileEntity.items(): if (name == 'x'): p.x = int(tag.value) - self.position.x @@ -2320,26 +2399,26 @@ def applychanges(self): # some random ones based on known ore distributions to fill # in ores. # Stone - chunk.Blocks[:,:,0:self.position.y] = materials.Stone.val + chunk.Blocks[:, :, 0:self.position.y] = materials.Stone.val # Coal. 1% between 5 and 60 distribute(chunk, 5, min(self.position.y, 60), 1, materials.CoalOre) - ## Iron. .6% between 5 and 55 + # Iron. .6% between 5 and 55 distribute(chunk, 5, min(self.position.y, 55), .6, materials.IronOre) - ## Redstone. .8% between 5 and 20 + # Redstone. .8% between 5 and 20 distribute(chunk, 5, min(self.position.y, 20), .8, materials.RedstoneOre) - ## Gold. .1% between 5 and 35 + # Gold. .1% between 5 and 35 distribute(chunk, 5, min(self.position.y, 35), .1, materials.GoldOre) - ## Lapis. .1% between 5 and 35 + # Lapis. .1% between 5 and 35 distribute(chunk, 5, min(self.position.y, 35), .1, materials.LapisLazuliOre) - ## Diamond. .1% between 5 and 20 + # Diamond. .1% between 5 and 20 distribute(chunk, 5, min(self.position.y, 20), .1, materials.DiamondOre) - ## Bedrock. 60% between 0 and 4 + # Bedrock. 60% between 0 and 4 distribute(chunk, 0, min(self.position.y, 4), 60, materials.Bedrock) pm.set_complete() @@ -2362,8 +2441,8 @@ def applychanges(self): print 'WARN: Block outside height bounds. y =', y continue # Figure out the chunk and chunk offset - chunk_z = z>>4 - chunk_x = x>>4 + chunk_z = z >> 4 + chunk_x = x >> 4 xInChunk = x & 0xf zInChunk = z & 0xf # get the chunk @@ -2377,45 +2456,45 @@ def applychanges(self): continue # Don't render soft blocks if there is something there already if (block.soft is True and - chunk.Blocks[xInChunk, zInChunk, y] > 0): + chunk.Blocks[xInChunk, zInChunk, y] > 0): continue mat = block.material dat = block.data # Update meta materials - if (mat._meta == True): - mat.update(block.loc.x,block.loc.y,block.loc.z, - self.xsize*self.room_size, - self.levels*self.room_height, - self.zsize*self.room_size) + if (mat._meta): + mat.update(block.loc.x, block.loc.y, block.loc.z, + self.xsize * self.room_size, + self.levels * self.room_height, + self.zsize * self.room_size) dat = mat.data # Sandbars only render over water if (mat == materials._sandbar and - chunk.Blocks[xInChunk, zInChunk, y] != materials.Water.val and - chunk.Blocks[xInChunk, zInChunk, y] != materials.StillWater.val and - chunk.Blocks[xInChunk, zInChunk, y] != materials.Ice.val): + chunk.Blocks[xInChunk, zInChunk, y] != materials.Water.val and + chunk.Blocks[xInChunk, zInChunk, y] != materials.StillWater.val and + chunk.Blocks[xInChunk, zInChunk, y] != materials.Ice.val): continue # Natural just looks like the existing world block if (mat == materials._natural): continue val = mat.val - #Silverfish egg pass + # Silverfish egg pass if (cfg.silverfish > 0 and - (val == 1 or val == 4 or val == 98) and - random.randint(1,100) <= cfg.silverfish): + (val == 1 or val == 4 or val == 98) and + random.randint(1, 100) <= cfg.silverfish): if (val == 4): - dat = 1 # Cobblestone + dat = 1 # Cobblestone elif (val == 1): - dat = 0 # Smooth Stone + dat = 0 # Smooth Stone elif (val == 98): if (dat == 0): - dat = 2 # Bricks + dat = 2 # Bricks elif (dat == 1): - dat = 3 # Mossy Bricks + dat = 3 # Mossy Bricks elif (dat == 2): - dat = 4 # Cracked Bricks + dat = 4 # Cracked Bricks elif (dat == 3): - dat = 5 # Chiseled Bricks + dat = 5 # Chiseled Bricks val = 97 # Switch to egg brick # Write the block. @@ -2423,9 +2502,9 @@ def applychanges(self): chunk.Data[xInChunk, zInChunk, y] = dat # Add this to the list we want to relight later. changed_chunks.add(chunk) - # Make sure we don't overwrite this chunk in the future. + # Make sure we don't overwrite this chunk in the future. if ((chunk_x, chunk_z) in self.good_chunks and - mat != materials._sandbar): + mat != materials._sandbar): del(self.good_chunks[(chunk_x, chunk_z)]) pm.set_complete() # Copy over tile entities diff --git a/dungeon_name_test.py b/dungeon_name_test.py index f4691b1b..8c1882dc 100755 --- a/dungeon_name_test.py +++ b/dungeon_name_test.py @@ -10,9 +10,9 @@ n = namegenerator.namegenerator(random.randint(0, 39)) o = n.genroyalname() if o.endswith("s"): - os = o+"'" + os = o + "'" else: - os = o+"'s" + os = o + "'s" print random.choice([ ruins.Blank.nameDungeon().format( owner=o, diff --git a/features.py b/features.py index 404fcf94..45d162c9 100644 --- a/features.py +++ b/features.py @@ -14,73 +14,77 @@ class Blank(object): _is_stairwell = False _is_secret = False - def __init__ (self, parent): + def __init__(self, parent): self.parent = parent - def placed (self): + def placed(self): pass - def render (self): + def render(self): pass class Entrance(Blank): _name = 'entrance' - def placed (self): + def placed(self): # Default height of the doors into the entrance. self.height = self.parent.parent.room_height self.high_height = self.parent.parent.room_height self.low_height = self.parent.parent.room_height # Height of the tower above entry. - self.u = self.parent.parent.room_height*2 + self.u = self.parent.parent.room_height * 2 self.inwater = False - def render (self): - start = self.parent.loc.trans(6,self.parent.parent.room_height-3,6) - wstart = start.trans(-1,0,-1) + def render(self): + start = self.parent.loc.trans(6, self.parent.parent.room_height - 3, 6) + wstart = start.trans(-1, 0, -1) # Clear air space for p in iterate_cube(wstart, - wstart.trans(5,-self.height,5)): + wstart.trans(5, -self.height, 5)): self.parent.parent.setblock(p, materials.Air) # Walls for p in iterate_four_walls(wstart, - wstart.trans(5,0,5), + wstart.trans(5, 0, 5), self.height): self.parent.parent.setblock(p, materials._wall) # Lower level openings # W side - for p in iterate_cube(wstart.trans(1,0,0), wstart.trans(4,-3,0)): + for p in iterate_cube(wstart.trans(1, 0, 0), wstart.trans(4, -3, 0)): self.parent.parent.setblock(p, materials.Air) # E side - for p in iterate_cube(wstart.trans(1,0,5), wstart.trans(4,-3,5)): + for p in iterate_cube(wstart.trans(1, 0, 5), wstart.trans(4, -3, 5)): self.parent.parent.setblock(p, materials.Air) # N side - for p in iterate_cube(wstart.trans(0,0,1), wstart.trans(0,-3,4)): + for p in iterate_cube(wstart.trans(0, 0, 1), wstart.trans(0, -3, 4)): self.parent.parent.setblock(p, materials.Air) # S side - for p in iterate_cube(wstart.trans(5,0,1), wstart.trans(5,-3,4)): + for p in iterate_cube(wstart.trans(5, 0, 1), wstart.trans(5, -3, 4)): self.parent.parent.setblock(p, materials.Air) # Draw the staircase mat = materials.StoneSlab - for p in iterate_spiral(Vec(0,0,0), - Vec(4,0,4), - self.height*2+2): + for p in iterate_spiral(Vec(0, 0, 0), + Vec(4, 0, 4), + self.height * 2 + 2): self.parent.parent.setblock(start.trans(p.x, - floor(float(p.y)/2.0), + floor(float(p.y) / 2.0), p.z), - mat, mat.data+(p.y%2)*8) + mat, mat.data + (p.y % 2) * 8) class Stairwell(Blank): _name = 'stairwell' _is_stairwell = True - def render (self): + def render(self): if (sum_points_inside_flat_poly(*self.parent.canvas) > 0): - start = self.parent.loc.trans(5,self.parent.parent.room_height-3,5) + start = self.parent.loc.trans( + 5, + self.parent.parent.room_height - + 3, + 5) # Clear a stairwell - for x in iterate_cube(start.trans(0,0,1), start.trans(5,-5,4)): + for x in iterate_cube(start.trans(0, 0, 1), start.trans(5, -5, 4)): self.parent.parent.setblock(x, materials.Air) mat = random.choice([ (materials.StoneStairs, materials.meta_mossycobble), @@ -89,11 +93,11 @@ def render (self): ]) # Draw the steps for x in xrange(6): - for p in iterate_cube(start.trans(x,-x,1), - start.trans(x,-x,4)): + for p in iterate_cube(start.trans(x, -x, 1), + start.trans(x, -x, 4)): self.parent.parent.setblock(p, mat[0]) - self.parent.parent.setblock(p.trans(0,1,0), + self.parent.parent.setblock(p.trans(0, 1, 0), mat[1]) @@ -101,239 +105,239 @@ class TripleStairs(Blank): _name = 'triplestairs' _is_stairwell = True - def render (self): - #create a shortcut to the set block fN + def render(self): + # create a shortcut to the set block fN sb = self.parent.parent.setblock center = self.parent.canvasCenter() - start = self.parent.loc.trans(5,self.parent.parent.room_height-2,5) - start = start.trans(0,-6,0) + start = self.parent.loc.trans(5, self.parent.parent.room_height - 2, 5) + start = start.trans(0, -6, 0) - #handrail - for x in iterate_four_walls(start.trans(-1,-1,-1),start.trans(6,-1,6),0): + # handrail + for x in iterate_four_walls(start.trans(-1, -1, -1), start.trans(6, -1, 6), 0): sb(x, materials.IronBars, 0) - sb( start.trans(2,-1,-1) , materials.Air, 0 ) - sb( start.trans(3,-1,-1) , materials.Air, 0 ) + sb(start.trans(2, -1, -1), materials.Air, 0) + sb(start.trans(3, -1, -1), materials.Air, 0) - #add a random deco object at the top - decos = ( (materials.Cauldron, 2) , - (materials.Torch, 0), - (materials.FlowerPot, 10), - (materials.StoneDoubleSlab, 0), - (materials.Air, 0) ) + # add a random deco object at the top + decos = ((materials.Cauldron, 2), + (materials.Torch, 0), + (materials.FlowerPot, 10), + (materials.StoneDoubleSlab, 0), + (materials.Air, 0)) deco = random.choice(decos) - sb( start.trans(1,-1,1) , deco[0], deco[1] ) - sb( start.trans(4,-1,1) , deco[0], deco[1] ) + sb(start.trans(1, -1, 1), deco[0], deco[1]) + sb(start.trans(4, -1, 1), deco[0], deco[1]) - #using the following materials... + # using the following materials... mats = [ - (materials.Air,0), #0 - (materials.StoneBrick,0), #1 - (materials.StoneBrickStairs, 6 ), #2 upside down ascending south - (materials.StoneBrickStairs, 0 ), #3 ascending east - (materials.StoneBrickStairs, 1 ), #4 ascending west - (materials.StoneBrickStairs, 3 ), #5 ascending north - (materials.StoneBrickStairs, 7 ), #6 upside down ascending north - (materials.Torch, 3) #7 - ] + (materials.Air, 0), # 0 + (materials.StoneBrick, 0), # 1 + (materials.StoneBrickStairs, 6), # 2 upside down ascending south + (materials.StoneBrickStairs, 0), # 3 ascending east + (materials.StoneBrickStairs, 1), # 4 ascending west + (materials.StoneBrickStairs, 3), # 5 ascending north + (materials.StoneBrickStairs, 7), # 6 upside down ascending north + (materials.Torch, 3) # 7 + ] #...create the stairs template = [ - [[ 0, 3, 1, 1, 4, 0], - [ 0, 1, 5, 5, 1, 0], - [ 0, 7, 0, 0, 7, 0], - [ 0, 0, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0], - [ 2, 2, 2, 2, 2, 2]], - - [[ 1, 1, 1, 1, 1, 1], - [ 5, 6, 1, 1, 6, 5], - [ 0, 0, 5, 5, 0, 0], - [ 0, 0, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0]], - - [[ 1, 1, 1, 1, 1, 1], - [ 1, 0, 1, 1, 0, 1], - [ 5, 0, 1, 1, 0, 5], - [ 0, 0, 5, 5, 0, 0], - [ 0, 0, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0]], - - [[ 1, 1, 1, 1, 1, 1], - [ 1, 0, 1, 1, 0, 1], - [ 1, 0, 1, 1, 0, 1], - [ 5, 0, 1, 1, 0, 5], - [ 0, 0, 5, 5, 0, 0], - [ 0, 0, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0]], - - [[ 1, 1, 1, 1, 1, 1], - [ 1, 5, 1, 1, 5, 1], - [ 1, 0, 1, 1, 0, 1], - [ 1, 0, 1, 1, 0, 1], - [ 5, 0, 1, 1, 0, 5], - [ 0, 0, 5, 5, 0, 0], - [ 0, 0, 0, 0, 0, 0]], - - [[ 1, 1, 1, 1, 1, 1], - [ 1, 1, 1, 1, 1, 1], - [ 1, 0, 1, 1, 0, 1], - [ 1, 0, 1, 1, 0, 1], - [ 1, 0, 1, 1, 0, 1], - [ 5, 0, 1, 1, 0, 5], - [ 0, 0, 5, 5, 0, 0]] - ] - #place the stuff + [[0, 3, 1, 1, 4, 0], + [0, 1, 5, 5, 1, 0], + [0, 7, 0, 0, 7, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [2, 2, 2, 2, 2, 2]], + + [[1, 1, 1, 1, 1, 1], + [5, 6, 1, 1, 6, 5], + [0, 0, 5, 5, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0]], + + [[1, 1, 1, 1, 1, 1], + [1, 0, 1, 1, 0, 1], + [5, 0, 1, 1, 0, 5], + [0, 0, 5, 5, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0]], + + [[1, 1, 1, 1, 1, 1], + [1, 0, 1, 1, 0, 1], + [1, 0, 1, 1, 0, 1], + [5, 0, 1, 1, 0, 5], + [0, 0, 5, 5, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0]], + + [[1, 1, 1, 1, 1, 1], + [1, 5, 1, 1, 5, 1], + [1, 0, 1, 1, 0, 1], + [1, 0, 1, 1, 0, 1], + [5, 0, 1, 1, 0, 5], + [0, 0, 5, 5, 0, 0], + [0, 0, 0, 0, 0, 0]], + + [[1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1], + [1, 0, 1, 1, 0, 1], + [1, 0, 1, 1, 0, 1], + [1, 0, 1, 1, 0, 1], + [5, 0, 1, 1, 0, 5], + [0, 0, 5, 5, 0, 0]] + ] + # place the stuff for y in xrange(6): for x in xrange(6): for z in xrange(7): - sb(start.trans(x,y,z), - mats[ template[y][z][x] ][0], - mats[ template[y][z][x] ][1] ) + sb(start.trans(x, y, z), + mats[template[y][z][x]][0], + mats[template[y][z][x]][1]) class TowerWithLadder(Blank): _name = 'towerwithladder' _is_stairwell = True - def render (self): - #create a shortcut to the set block fN + def render(self): + # create a shortcut to the set block fN sb = self.parent.parent.setblock center = self.parent.canvasCenter() - start = self.parent.loc.trans(5,self.parent.parent.room_height-2,5) - start = start.trans(0,-6,0) + start = self.parent.loc.trans(5, self.parent.parent.room_height - 2, 5) + start = start.trans(0, -6, 0) mats = [ - (materials.Air,0), #0 - (materials.StoneBrick,0), #1 - (materials.Ladder, 3 ), #2 facing south - (materials.Ladder, 2 ), #3 facing north - (materials.StoneBrickStairs, 6 ), #4 upside down ascending south - (materials.StoneBrickStairs, 7 ), #5 upside down ascending north - (materials.IronBars, 0 ) #6 - ] + (materials.Air, 0), # 0 + (materials.StoneBrick, 0), # 1 + (materials.Ladder, 3), # 2 facing south + (materials.Ladder, 2), # 3 facing north + (materials.StoneBrickStairs, 6), # 4 upside down ascending south + (materials.StoneBrickStairs, 7), # 5 upside down ascending north + (materials.IronBars, 0) # 6 + ] template = [ - [ 0, 1, 1, 1, 1, 0], - [ 1, 0, 2, 2, 0, 1], - [ 0, 0, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0], - [ 1, 0, 0, 0, 0, 1], - [ 0, 1, 6, 6, 1, 0]] + [0, 1, 1, 1, 1, 0], + [1, 0, 2, 2, 0, 1], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [1, 0, 0, 0, 0, 1], + [0, 1, 6, 6, 1, 0]] top = [ - [ 0, 1, 1, 1, 1, 0], - [ 1, 0, 2, 2, 0, 1], - [ 5, 0, 0, 0, 0, 5], - [ 4, 0, 0, 0, 0, 4], - [ 1, 0, 0, 0, 0, 1], - [ 0, 1, 1, 1, 1, 0]] - - #place the stuff + [0, 1, 1, 1, 1, 0], + [1, 0, 2, 2, 0, 1], + [5, 0, 0, 0, 0, 5], + [4, 0, 0, 0, 0, 4], + [1, 0, 0, 0, 0, 1], + [0, 1, 1, 1, 1, 0]] + + # place the stuff for y in xrange(2): for x in xrange(6): for z in xrange(6): - sb(start.trans(x,y*6-1,z), - mats[ template[z][x] ][0], - mats[ template[z][x] ][1] ) - sb(start.trans(x,y*6-2,z), - mats[ template[z][x] ][0], - mats[ template[z][x] ][1] ) - sb(start.trans(x,y*6-3,z), - mats[ top[z][x] ][0], - mats[ top[z][x] ][1] ) + sb(start.trans(x, y * 6 - 1, z), + mats[template[z][x]][0], + mats[template[z][x]][1]) + sb(start.trans(x, y * 6 - 2, z), + mats[template[z][x]][0], + mats[template[z][x]][1]) + sb(start.trans(x, y * 6 - 3, z), + mats[top[z][x]][0], + mats[top[z][x]][1]) - #finish ladder - for x in iterate_cube(start.trans(2,0,1), start.trans(3,2,1)): - sb(x, materials.Ladder, 3 ) + # finish ladder + for x in iterate_cube(start.trans(2, 0, 1), start.trans(3, 2, 1)): + sb(x, materials.Ladder, 3) class Scaffolding(Blank): _name = 'scaffolding' _is_stairwell = True - def render (self): - #create a shortcut to the set block fN + def render(self): + # create a shortcut to the set block fN sb = self.parent.parent.setblock - start = self.parent.loc.trans(5,self.parent.parent.room_height-2,5) - start = start.trans(0,-7,0) + start = self.parent.loc.trans(5, self.parent.parent.room_height - 2, 5) + start = start.trans(0, -7, 0) mats = [ - (materials.Air,0), #0 - (materials.Fence,0), #1 - (materials.OakWoodSlab, 0 ), #2 - (materials.OakWoodStairs, 0 ),#3 Acending East - (materials.OakWoodStairs, 3 ) #4 Ascending North - ] + (materials.Air, 0), # 0 + (materials.Fence, 0), # 1 + (materials.OakWoodSlab, 0), # 2 + (materials.OakWoodStairs, 0), # 3 Acending East + (materials.OakWoodStairs, 3) # 4 Ascending North + ] template = [ - [[ 0, 0, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 1], - [ 1, 0, 0, 0, 0, 1], - [ 1, 0, 0, 0, 0, 1], - [ 1, 1, 1, 1, 1, 1]], - - [[ 0, 0, 0, 0, 2, 2], - [ 0, 0, 0, 0, 2, 2], - [ 0, 0, 0, 0, 0, 1], - [ 1, 0, 0, 0, 0, 1], - [ 1, 0, 0, 0, 0, 1], - [ 1, 1, 1, 1, 1, 1]], - - [[ 0, 0, 0, 3, 1, 1], - [ 0, 0, 0, 3, 1, 1], - [ 0, 0, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0], - [ 0, 0, 1, 0, 0, 1]], - - [[ 2, 2, 3, 1, 1, 1], - [ 2, 2, 3, 1, 1, 1], - [ 0, 0, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0], - [ 0, 0, 1, 0, 0, 1]], - - [[ 1, 1, 1, 0, 0, 0], - [ 1, 1, 1, 0, 0, 0], - [ 4, 4, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0], - [ 0, 0, 1, 0, 0, 1]], - - [[ 1, 1, 1, 0, 0, 0], - [ 1, 1, 1, 0, 0, 0], - [ 1, 1, 0, 0, 0, 0], - [ 4, 4, 0, 0, 0, 0], - [ 0, 0, 0, 0, 0, 0], - [ 0, 0, 1, 0, 0, 1]], - - [[ 1, 1, 1, 0, 0, 0], - [ 1, 1, 1, 0, 0, 0], - [ 1, 1, 0, 0, 0, 0], - [ 1, 1, 0, 0, 0, 0], - [ 4, 4, 0, 0, 0, 0], - [ 0, 0, 1, 0, 0, 1]], + [[0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 1], + [1, 0, 0, 0, 0, 1], + [1, 0, 0, 0, 0, 1], + [1, 1, 1, 1, 1, 1]], + + [[0, 0, 0, 0, 2, 2], + [0, 0, 0, 0, 2, 2], + [0, 0, 0, 0, 0, 1], + [1, 0, 0, 0, 0, 1], + [1, 0, 0, 0, 0, 1], + [1, 1, 1, 1, 1, 1]], + + [[0, 0, 0, 3, 1, 1], + [0, 0, 0, 3, 1, 1], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 0, 1]], + + [[2, 2, 3, 1, 1, 1], + [2, 2, 3, 1, 1, 1], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 0, 1]], + + [[1, 1, 1, 0, 0, 0], + [1, 1, 1, 0, 0, 0], + [4, 4, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 0, 1]], + + [[1, 1, 1, 0, 0, 0], + [1, 1, 1, 0, 0, 0], + [1, 1, 0, 0, 0, 0], + [4, 4, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 0, 1]], + + [[1, 1, 1, 0, 0, 0], + [1, 1, 1, 0, 0, 0], + [1, 1, 0, 0, 0, 0], + [1, 1, 0, 0, 0, 0], + [4, 4, 0, 0, 0, 0], + [0, 0, 1, 0, 0, 1]], ] - #place the stuff + # place the stuff for y in xrange(7): for x in xrange(6): for z in xrange(6): - sb(start.trans(x,y,z), - mats[ template[y][z][x] ][0], - mats[ template[y][z][x] ][1] ) + sb(start.trans(x, y, z), + mats[template[y][z][x]][0], + mats[template[y][z][x]][1]) class Chasm(Blank): @@ -341,35 +345,35 @@ class Chasm(Blank): material = materials.Air depth = 2 - def render (self): + def render(self): if (self.parent.canvasWidth() < 4 or - self.parent.canvasLength() < 4): + self.parent.canvasLength() < 4): return # We'll render across the whole block, since that will look cool y = self.parent.canvasHeight() - flip = random.randint(0,1) - for x in xrange(2, self.parent.parent.room_size*self.parent.size.x-2): + flip = random.randint(0, 1) + for x in xrange(2, self.parent.parent.room_size * self.parent.size.x - 2): if (flip == 1): for p in iterate_cube(self.parent.loc + - Vec(self.parent.parent.room_size*self.parent.size.x-x-1, + Vec(self.parent.parent.room_size * self.parent.size.x - x - 1, y, - x+random.randint(-1,0)), + x + random.randint(-1, 0)), self.parent.loc + - Vec(self.parent.parent.room_size*self.parent.size.x-x-1, + Vec(self.parent.parent.room_size * self.parent.size.x - x - 1, y + self.depth, - x+random.randint(1,2)) - ): + x + random.randint(1, 2)) + ): self.parent.parent.setblock(p, self.material) else: for p in iterate_cube(self.parent.loc + Vec(x, y, - x+random.randint(-1,0)), + x + random.randint(-1, 0)), self.parent.loc + Vec(x, y + self.depth, - x+random.randint(1,2)) - ): + x + random.randint(1, 2)) + ): self.parent.parent.setblock(p, self.material) @@ -410,99 +414,100 @@ class Columns(Blank): materials.Glowstone ) - def render (self): + def render(self): limit = int(min(self.parent.canvasWidth(), self.parent.canvasLength())) if (limit < 6): return c = self.parent.canvasCenter() - height = self.parent.canvasHeight()-1 - start = random.randint(0, limit/2-1) - stop = limit/2 + height = self.parent.canvasHeight() - 1 + start = random.randint(0, limit / 2 - 1) + stop = limit / 2 step = random.randint(2, 3) mat = random.choice(self.mats) for x in xrange(start, stop, step): - for p in iterate_cube(Vec(c.x-x, 1, c.z-x), - Vec(c.x-x, height, c.z-x)): - self.parent.parent.setblock(self.parent.loc+p, mat) - for p in iterate_cube(Vec(c.x+x+1, 1, c.z-x), - Vec(c.x+x+1, height, c.z-x)): - self.parent.parent.setblock(self.parent.loc+p, mat) - for p in iterate_cube(Vec(c.x-x, 1, c.z+x+1), - Vec(c.x-x, height, c.z+x+1)): - self.parent.parent.setblock(self.parent.loc+p, mat) - for p in iterate_cube(Vec(c.x+x+1, 1, c.z+x+1), - Vec(c.x+x+1, height, c.z+x+1)): - self.parent.parent.setblock(self.parent.loc+p, mat) + for p in iterate_cube(Vec(c.x - x, 1, c.z - x), + Vec(c.x - x, height, c.z - x)): + self.parent.parent.setblock(self.parent.loc + p, mat) + for p in iterate_cube(Vec(c.x + x + 1, 1, c.z - x), + Vec(c.x + x + 1, height, c.z - x)): + self.parent.parent.setblock(self.parent.loc + p, mat) + for p in iterate_cube(Vec(c.x - x, 1, c.z + x + 1), + Vec(c.x - x, height, c.z + x + 1)): + self.parent.parent.setblock(self.parent.loc + p, mat) + for p in iterate_cube(Vec(c.x + x + 1, 1, c.z + x + 1), + Vec(c.x + x + 1, height, c.z + x + 1)): + self.parent.parent.setblock(self.parent.loc + p, mat) class Arcane(Blank): _name = 'arcane' - def render (self): + def render(self): if (self.parent.canvasWidth() < 8 or self.parent.canvasLength() < 8): return # Custom block placer. Don't place stuff where things already exist, # also check for things we aren't alowed to place stuff on. dun = self.parent.parent + def sb(p, mat): if (p in dun.blocks and - dun.blocks[p].material == materials.Air and - dun.blocks[p.down(1)].material != materials.Farmland and - dun.blocks[p.down(1)].material != materials.SoulSand and - dun.blocks[p.down(1)].material != materials.Water and - dun.blocks[p.down(1)].material != materials.Lava and - dun.blocks[p.down(1)].material != materials.CobblestoneSlab and - dun.blocks[p.down(1)].material != materials.StillWater): + dun.blocks[p].material == materials.Air and + dun.blocks[p.down(1)].material != materials.Farmland and + dun.blocks[p.down(1)].material != materials.SoulSand and + dun.blocks[p.down(1)].material != materials.Water and + dun.blocks[p.down(1)].material != materials.Lava and + dun.blocks[p.down(1)].material != materials.CobblestoneSlab and + dun.blocks[p.down(1)].material != materials.StillWater): dun.setblock(p, mat) - mode = random.choice(['one','boxes', 'conc']) + mode = random.choice(['one', 'boxes', 'conc']) if mode == 'boxes': center = self.parent.canvasCenter() o = self.parent.loc + Vec(center.x, - self.parent.canvasHeight()-1, + self.parent.canvasHeight() - 1, center.z) - o = o+Vec(-self.parent.canvasWidth()/2, - 0, - -self.parent.canvasLength()/2) - for x in xrange(self.parent.canvasWidth()/3+1): - for z in xrange(self.parent.canvasLength()/3+1): + o = o + Vec(-self.parent.canvasWidth() / 2, + 0, + -self.parent.canvasLength() / 2) + for x in xrange(self.parent.canvasWidth() / 3 + 1): + for z in xrange(self.parent.canvasLength() / 3 + 1): if random.random() < 0.5: - q = Vec(o.x+x*3, o.y, o.z+z*3) + q = Vec(o.x + x * 3, o.y, o.z + z * 3) sb(q, materials.RedstoneWire) - sb(q.trans(1,0,0), materials.RedstoneWire) - sb(q.trans(0,0,1), materials.RedstoneWire) - sb(q.trans(1,0,1), materials.RedstoneWire) + sb(q.trans(1, 0, 0), materials.RedstoneWire) + sb(q.trans(0, 0, 1), materials.RedstoneWire) + sb(q.trans(1, 0, 1), materials.RedstoneWire) return if mode == 'conc': center = self.parent.canvasCenter() c = self.parent.loc + Vec(center.x, - self.parent.canvasHeight()-1, + self.parent.canvasHeight() - 1, center.z) sb(c, materials.RedstoneWire) - for p in iterate_ellipse(c.trans(-2,0,-2), c.trans(2,0,2)): + for p in iterate_ellipse(c.trans(-2, 0, -2), c.trans(2, 0, 2)): sb(p, materials.RedstoneWire) - for p in iterate_ellipse(c.trans(-4,0,-4), c.trans(4,0,4)): + for p in iterate_ellipse(c.trans(-4, 0, -4), c.trans(4, 0, 4)): sb(p, materials.RedstoneWire) return center = self.parent.canvasCenter() c = self.parent.loc + Vec(center.x, - self.parent.canvasHeight()-1, + self.parent.canvasHeight() - 1, center.z) for p in iterate_cube(c.n(4), c.s(4)): sb(p, materials.RedstoneWire) for p in iterate_cube(c.e(4), c.w(4)): sb(p, materials.RedstoneWire) - for p in iterate_four_walls(c.trans(-2,0,-2), c.trans(2,0,2),0): + for p in iterate_four_walls(c.trans(-2, 0, -2), c.trans(2, 0, 2), 0): sb(p, materials.RedstoneWire) class Mushrooms(Blank): _name = 'mushrooms' - def render (self): + def render(self): if (self.parent.canvasWidth() < 2 or self.parent.canvasLength() < 2): return @@ -510,13 +515,14 @@ def render (self): # also check for things we aren't alowed to place stuff on. # Picks red or brown mushrooms randomly if no material is supplied. dun = self.parent.parent + def sb(p, mat=''): if (p in dun.blocks and - dun.blocks[p].material == materials.Air and - dun.blocks[p.down(1)].material != materials.Farmland and - dun.blocks[p.down(1)].material != materials.SoulSand and - dun.blocks[p.down(1)].material != materials.Water and - dun.blocks[p.down(1)].material != materials.StillWater): + dun.blocks[p].material == materials.Air and + dun.blocks[p.down(1)].material != materials.Farmland and + dun.blocks[p.down(1)].material != materials.SoulSand and + dun.blocks[p.down(1)].material != materials.Water and + dun.blocks[p.down(1)].material != materials.StillWater): if mat == '': mat = random.choice([materials.RedMushroom, materials.BrownMushroom, @@ -526,24 +532,24 @@ def sb(p, mat=''): mode = random.choice(['perlin', 'fairyring']) if mode == 'perlin': pn = perlin.SimplexNoise(256) - r = random.randint(1,1000) + r = random.randint(1, 1000) for p in iterate_points_inside_flat_poly(*self.parent.canvas): - if (pn.noise3(p.x/4.0, r/4.0, p.z/4.0) > .8): + if (pn.noise3(p.x / 4.0, r / 4.0, p.z / 4.0) > .8): q = p + self.parent.loc - sb(q.trans( 1,-1, 0)) - sb(q.trans(-1,-1, 0)) - sb(q.trans( 0,-1,-1)) - sb(q.trans( 0,-1, 1)) + sb(q.trans(1, -1, 0)) + sb(q.trans(-1, -1, 0)) + sb(q.trans(0, -1, -1)) + sb(q.trans(0, -1, 1)) return if mode == 'fairyring': center = self.parent.canvasCenter() c = self.parent.loc + Vec(center.x, - self.parent.canvasHeight()-1, + self.parent.canvasHeight() - 1, center.z) - radius = random.randint(2,5) - for p in iterate_ellipse(c.trans(-radius,0,-radius), - c.trans(radius,0,radius)): + radius = random.randint(2, 5) + for p in iterate_ellipse(c.trans(-radius, 0, -radius), + c.trans(radius, 0, radius)): sb(p) return @@ -558,27 +564,27 @@ def render(self): # Draw tables. cram several in the room if it is large enough. for x in xrange(self.parent.size.x): for z in xrange(self.parent.size.z): - rp = self.parent.pos + Vec(x,0,z) + rp = self.parent.pos + Vec(x, 0, z) if (self.parent.parent.rooms[rp].features[0]._is_stairwell is False and - self.parent.parent.rooms[rp].features[0]._name is not 'blank'): + self.parent.parent.rooms[rp].features[0]._name is not 'blank'): p = self.parent.loc + Vec( x * self.parent.parent.room_size, - self.parent.canvasHeight()-1, + self.parent.canvasHeight() - 1, z * self.parent.parent.room_size) - for q in iterate_cube(p+Vec(5,0,7), p+Vec(10,0,8)): + for q in iterate_cube(p + Vec(5, 0, 7), p + Vec(10, 0, 8)): sb(q, materials.Fence) sb(q.up(1), materials.WoodenPressurePlate) # Seating - q = p+Vec(5,0,6) - o = random.randint(0,1) + q = p + Vec(5, 0, 6) + o = random.randint(0, 1) while o <= 5: - sb(q.e(o), materials.OakWoodStairs, 3) - o += random.randint(2,3) - q = p+Vec(5,0,9) - o = random.randint(0,1) + sb(q.e(o), materials.OakWoodStairs, 3) + o += random.randint(2, 3) + q = p + Vec(5, 0, 9) + o = random.randint(0, 1) while o <= 5: - sb(q.e(o), materials.OakWoodStairs, 2) - o += random.randint(2,3) + sb(q.e(o), materials.OakWoodStairs, 2) + o += random.randint(2, 3) # If the room is 1x1, stop here. if (self.parent.size.x < 2 and self.parent.size.z < 2): @@ -586,11 +592,11 @@ def render(self): # Draw a fire pit in the middle center = self.parent.canvasCenter() size = 2 - p0 = Vec(center.x - size/2 + 1, + p0 = Vec(center.x - size / 2 + 1, self.parent.canvasHeight(), - center.z - size/2 + 1) + self.parent.loc - p1 = p0.trans(size-1, 0, size-1) - for p in iterate_disc(p0+Vec(-2,0,-2), p1+Vec(2,0,2)): + center.z - size / 2 + 1) + self.parent.loc + p1 = p0.trans(size - 1, 0, size - 1) + for p in iterate_disc(p0 + Vec(-2, 0, -2), p1 + Vec(2, 0, 2)): sb(p, materials._floor) sb(p.up(1), materials.IronBars) for p in iterate_disc(p0, p1): @@ -598,17 +604,16 @@ def render(self): sb(p.up(1), materials.Fire) - class Dais(Blank): _name = 'dais' - def render (self): + def render(self): if (self.parent.canvasWidth() < 8 or self.parent.canvasLength() < 8): return center = self.parent.canvasCenter() size = random.randint(4, - min(self.parent.canvasWidth(), - self.parent.canvasLength()) - 4) + min(self.parent.canvasWidth(), + self.parent.canvasLength()) - 4) torches = (random.random() < .5) platform = random.choice([materials.meta_mossycobble, materials.meta_mossystonebrick, @@ -624,14 +629,14 @@ def render (self): pfunc = iterate_disc sfunc = iterate_tube - p0 = Vec(center.x - size/2 + 1, + p0 = Vec(center.x - size / 2 + 1, self.parent.canvasHeight(), - center.z - size/2 + 1) + self.parent.loc - p1 = p0.trans(size-1, 0, size-1) + center.z - size / 2 + 1) + self.parent.loc + p1 = p0.trans(size - 1, 0, size - 1) if torches: - for p in (Vec(p0.x+1,p0.y-1,p0.z+1), Vec(p1.x-1,p0.y-1,p1.z-1), - Vec(p0.x+1,p0.y-1,p1.z-1), Vec(p1.x-1,p0.y-1,p0.z+1)): + for p in (Vec(p0.x + 1, p0.y - 1, p0.z + 1), Vec(p1.x - 1, p0.y - 1, p1.z - 1), + Vec(p0.x + 1, p0.y - 1, p1.z - 1), Vec(p1.x - 1, p0.y - 1, p0.z + 1)): self.parent.parent.setblock(p, materials.Fence) self.parent.parent.setblock(p.up(1), materials.Fence) self.parent.parent.setblock(p.up(2), materials.Torch) @@ -657,9 +662,9 @@ def render(self): # Reform the basic room shape. for p in iterate_cube(self.parent.loc, - self.parent.loc+Vec(self.parent.parent.room_size-1, - self.parent.parent.room_height-2, - self.parent.parent.room_size-1)): + self.parent.loc + Vec(self.parent.parent.room_size - 1, + self.parent.parent.room_height - 2, + self.parent.parent.room_size - 1)): # Remove all blocks. sb(p, None) # Clear out any doors or extra torches. @@ -669,11 +674,11 @@ def render(self): del(self.parent.parent.torches[p]) self.c1 = self.parent.loc + Vec(3, - self.parent.parent.room_height-2, - 3) - self.c3 = self.parent.loc + Vec(self.parent.parent.room_size-4, - self.parent.parent.room_height-2, - self.parent.parent.room_size-4) + self.parent.parent.room_height - 2, + 3) + self.c3 = self.parent.loc + Vec(self.parent.parent.room_size - 4, + self.parent.parent.room_height - 2, + self.parent.parent.room_size - 4) for q in iterate_cube(self.c1.up(1), self.c3.up(3)): sb(q, materials.Air) @@ -681,7 +686,7 @@ def render(self): sb(q, materials._ceiling) for q in iterate_cube(self.c1, self.c3): sb(q, materials._floor) - for q in iterate_four_walls(self.c1, self.c3, self.parent.parent.room_height-2): + for q in iterate_four_walls(self.c1, self.c3, self.parent.parent.room_height - 2): sb(q, materials._wall) # Fix the hallway and create the secret door mechansm. @@ -693,12 +698,12 @@ def render(self): # od = direction out of the connecting room # length = legth of the opposite hall - o = self.parent.loc.trans(2,0,2) + o = self.parent.loc.trans(2, 0, 2) # hall positions to grid direction - dirs = {3: Vec(-1,0,0), - 1: Vec(1,0,0), - 2: Vec(0,0,1), - 0: Vec(0,0,-1)} + dirs = {3: Vec(-1, 0, 0), + 1: Vec(1, 0, 0), + 2: Vec(0, 0, 1), + 0: Vec(0, 0, -1)} room = self.parent d = 0 @@ -706,48 +711,48 @@ def render(self): if room.halls[x]._name != 'blank': d = x offset = room.halls[d].offset - oroom = self.parent.parent.rooms[room.pos+dirs[d]] - od = (d+2)%4 - length = oroom.hallLength[od]-2 + oroom = self.parent.parent.rooms[room.pos + dirs[d]] + od = (d + 2) % 4 + length = oroom.hallLength[od] - 2 # Save d for any inherited secret rooms. self.direction = d # Figure our our deltas. There are 8 possibilities based on direction - # and offset. Offset will basically mirror across width. + # and offset. Offset will basically mirror across width. # dw = delta width # dl = delta length # spos = start pos for the mechanism # d = 0 (West) if d == 0: - dw = Vec(1,0,0) - dl = Vec(0,0,-1) - spos = o.trans(offset,0,0) + dw = Vec(1, 0, 0) + dl = Vec(0, 0, -1) + spos = o.trans(offset, 0, 0) # d = 1 (South) elif d == 1: - dw = Vec(0,0,1) - dl = Vec(1,0,0) - spos = o.trans(11,0,offset) + dw = Vec(0, 0, 1) + dl = Vec(1, 0, 0) + spos = o.trans(11, 0, offset) # d = 2 (East) elif d == 2: - dw = Vec(1,0,0) - dl = Vec(0,0,1) - spos = o.trans(offset,0,11) + dw = Vec(1, 0, 0) + dl = Vec(0, 0, 1) + spos = o.trans(offset, 0, 11) # d = 3 (North) else: - dw = Vec(0,0,1) - dl = Vec(-1,0,0) - spos = o.trans(0,0,offset) + dw = Vec(0, 0, 1) + dl = Vec(-1, 0, 0) + spos = o.trans(0, 0, offset) if offset >= 7: - dw = dw*-1 + dw = dw * -1 if (d == 0 or d == 2): - spos = spos.trans(-2,0,0) + spos = spos.trans(-2, 0, 0) elif (d == 1 or d == 3): - spos = spos.trans(0,0,-2) + spos = spos.trans(0, 0, -2) # Position the start block for the mechanism - spos = spos + dl*length - dw*2 + spos = spos + dl * length - dw * 2 if self.parent.parent.args.debug: print @@ -759,66 +764,66 @@ def render(self): print mats = [ - [materials.Air,0], # 0 (ignore these) - [materials.Air,0], # 1 - [materials._wall,0], # 2 - [materials.Stone,0], # 3 - [materials._wall,0], # 4 - [materials.RedstoneWire,0], # 5 - [materials.StickyPiston,3], # 6 - toggle piston - [materials.RedstoneTorchOn,2],# 7 + [materials.Air, 0], # 0 (ignore these) + [materials.Air, 0], # 1 + [materials._wall, 0], # 2 + [materials.Stone, 0], # 3 + [materials._wall, 0], # 4 + [materials.RedstoneWire, 0], # 5 + [materials.StickyPiston, 3], # 6 - toggle piston + [materials.RedstoneTorchOn, 2], # 7 [materials._ceiling, 0], # 8 - [materials.StickyPiston, 4],# 9 - pusher piston - [materials.RedstoneRepeaterOff, 3],# 10 - piston repeater - [materials.RedstoneRepeaterOff, 7],# 11 - toggle repeater + [materials.StickyPiston, 4], # 9 - pusher piston + [materials.RedstoneRepeaterOff, 3], # 10 - piston repeater + [materials.RedstoneRepeaterOff, 7], # 11 - toggle repeater [materials.Torch, 0], # 12 - [materials._secret_door, 0],# 13 + [materials._secret_door, 0], # 13 [materials._floor, 0], # 14 [materials._subfloor, 0] # 15 ] template = [ - [[ 8, 8, 8, 8, 8], - [ 8, 8, 8, 8, 8], - [ 8, 8, 8, 8, 8], - [ 8, 8, 8, 8, 8], - [ 8, 8, 8, 8, 8], - [ 8, 8, 8, 8, 8]], - [[ 2, 4, 4, 4, 4], - [ 1, 1, 1,12, 4], - [ 2, 4, 4, 4, 4], - [ 2, 1, 1, 1, 4], - [ 2, 1, 1, 1, 4], - [ 2, 1, 1, 1, 4]], - [[ 2, 4, 4, 4, 4], - [ 1, 7, 1 ,1,13], - [ 2, 4, 6, 1, 4], - [ 2,11, 9, 9, 4], - [ 2, 5,10,10, 4], - [ 2, 5, 5, 5, 4]], - [[ 2, 4, 4, 4, 4], - [ 1, 1, 1, 1,13], - [ 2, 4, 6, 1, 4], - [ 2, 3, 9, 9, 4], - [ 2, 3, 3, 3, 4], - [ 2, 3, 3, 3, 4]], - [[14,14,14,14,14], - [14,14,14,14,14], - [14,14,14,14,14], - [14,14,14,14,14], - [14,14,14,14,14], - [14,14,14,14,14]], - [[15,15,15,15,15], - [15,15,15,15,15], - [15,15,15,15,15], - [15,15,15,15,15], - [15,15,15,15,15], - [15,15,15,15,15]], + [[8, 8, 8, 8, 8], + [8, 8, 8, 8, 8], + [8, 8, 8, 8, 8], + [8, 8, 8, 8, 8], + [8, 8, 8, 8, 8], + [8, 8, 8, 8, 8]], + [[2, 4, 4, 4, 4], + [1, 1, 1, 12, 4], + [2, 4, 4, 4, 4], + [2, 1, 1, 1, 4], + [2, 1, 1, 1, 4], + [2, 1, 1, 1, 4]], + [[2, 4, 4, 4, 4], + [1, 7, 1, 1, 13], + [2, 4, 6, 1, 4], + [2, 11, 9, 9, 4], + [2, 5, 10, 10, 4], + [2, 5, 5, 5, 4]], + [[2, 4, 4, 4, 4], + [1, 1, 1, 1, 13], + [2, 4, 6, 1, 4], + [2, 3, 9, 9, 4], + [2, 3, 3, 3, 4], + [2, 3, 3, 3, 4]], + [[14, 14, 14, 14, 14], + [14, 14, 14, 14, 14], + [14, 14, 14, 14, 14], + [14, 14, 14, 14, 14], + [14, 14, 14, 14, 14], + [14, 14, 14, 14, 14]], + [[15, 15, 15, 15, 15], + [15, 15, 15, 15, 15], + [15, 15, 15, 15, 15], + [15, 15, 15, 15, 15], + [15, 15, 15, 15, 15], + [15, 15, 15, 15, 15]], ] bdata = 3 # Data adjustments for directions. There are 8, but the defaults are - # for East, low offset. + # for East, low offset. # West if d == 0: @@ -876,36 +881,36 @@ def render(self): for y in xrange(6): for w in xrange(6): for l in xrange(5): - p = spos+dl*l+dw*w+Vec(0,1,0)*y + p = spos + dl * l + dw * w + Vec(0, 1, 0) * y sb(p, mats[template[y][w][l]][0], - mats[template[y][w][l]][1]) + mats[template[y][w][l]][1]) # The button. - p = spos+dl*3+dw*5+Vec(0,1,0)*2 + p = spos + dl * 3 + dw * 5 + Vec(0, 1, 0) * 2 blocks = self.parent.parent.blocks - while blocks[p+dl].material != materials.Air: + while blocks[p + dl].material != materials.Air: sb(p.up(1), materials.Air) sb(p, materials.RedstoneWire) sb(p.down(1), materials.Stone) p = p + dl - sb(p+dl, materials.StoneButton, bdata) + sb(p + dl, materials.StoneButton, bdata) # Extend the hallway into the room. - o = spos+dw - p = o-dl*(length+1)+Vec(0,4,0) + o = spos + dw + p = o - dl * (length + 1) + Vec(0, 4, 0) for q in iterate_cube(o, p): - sb(q-dw, materials._wall, lock=True) + sb(q - dw, materials._wall, lock=True) if q.y == o.y: sb(q, materials._ceiling) elif q.y == p.y: sb(q, materials._floor) else: sb(q, materials.Air, lock=True) - sb(q-dl, materials.Air, lock=True) - sb(q+dw, materials._wall, lock=True) + sb(q - dl, materials.Air, lock=True) + sb(q + dw, materials._wall, lock=True) # Clear out any additional doors or extra torches in the hall. - for q in iterate_cube(o+dw*2+dl*5, p-dw-dl): + for q in iterate_cube(o + dw * 2 + dl * 5, p - dw - dl): if q in self.parent.parent.doors: del(self.parent.parent.doors[q]) if q in self.parent.parent.torches: @@ -913,9 +918,9 @@ def render(self): # Kill the canvas to prevent spawners and chests from appearing self.parent.canvas = ( - Vec(0,0,0), - Vec(0,0,0), - Vec(0,0,0)) + Vec(0, 0, 0), + Vec(0, 0, 0), + Vec(0, 0, 0)) # Call the room post-renderer. self.renderSecretPost() @@ -929,65 +934,64 @@ def renderSecretPost(self): blocks = self.parent.parent.blocks # Bookshelves - for p in iterate_four_walls(Vec(1,-1,1), Vec(8,-1,8),2): + for p in iterate_four_walls(Vec(1, -1, 1), Vec(8, -1, 8), 2): if (p.x not in (3, 6) and - p.z not in (3, 6)): - sb(self.c1+p, materials.Bookshelf) + p.z not in (3, 6)): + sb(self.c1 + p, materials.Bookshelf) else: - sb(self.c1+p, materials.Air) + sb(self.c1 + p, materials.Air) # A Clock! - sb(self.c1+Vec(2,-3,1), materials._wall) + sb(self.c1 + Vec(2, -3, 1), materials._wall) self.parent.parent.addentity( get_entity_other_tags("ItemFrame", - Pos=self.c1+Vec(2,-3,1), + Pos=self.c1 + Vec(2, -3, 1), Direction="S", ItemInfo=items.byName("clock") - ) + ) ) # Lighting - for p in (Vec(2,-1,2), Vec(2,-1,7), - Vec(7,-1,2), Vec(7,-1,7)): - sb(self.c1+p, materials.Fence) - sb(self.c1+p.up(1), materials.Torch, 5) + for p in (Vec(2, -1, 2), Vec(2, -1, 7), + Vec(7, -1, 2), Vec(7, -1, 7)): + sb(self.c1 + p, materials.Fence) + sb(self.c1 + p.up(1), materials.Torch, 5) # Desk mats = [ - (materials.Air,0), # 0 - (materials.OakWoodStairs,7), # 1 - (materials.Chest,0), # 2 - (materials.CraftingTable,0),# 3 - (materials.WallSign,0), # 4 - (materials.OakWoodStairs,0), # 5 - (materials.OakWoodStairs,6), # 6 + (materials.Air, 0), # 0 + (materials.OakWoodStairs, 7), # 1 + (materials.Chest, 0), # 2 + (materials.CraftingTable, 0), # 3 + (materials.WallSign, 0), # 4 + (materials.OakWoodStairs, 0), # 5 + (materials.OakWoodStairs, 6), # 6 ] template = [ - [3,1,6,2], - [0,4,5,4] + [3, 1, 6, 2], + [0, 4, 5, 4] ] - oo = self.c1.trans(4,-1,3) + oo = self.c1.trans(4, -1, 3) for x in xrange(2): for z in xrange(4): - p = oo.trans(x,0,z) + p = oo.trans(x, 0, z) sb(p, mats[template[x][z]][0], mats[template[x][z]][1]) - self.parent.parent.blocks[self.c1+Vec(5,-1,4)].data = 2 - self.parent.parent.blocks[self.c1+Vec(5,-1,5)].data = 0 - self.parent.parent.blocks[self.c1+Vec(5,-1,6)].data = 3 - + self.parent.parent.blocks[self.c1 + Vec(5, -1, 4)].data = 2 + self.parent.parent.blocks[self.c1 + Vec(5, -1, 5)].data = 0 + self.parent.parent.blocks[self.c1 + Vec(5, -1, 6)].data = 3 + if (random.random() < 0.1): - sb(self.c1.trans(4,-2,4), materials.Cake, random.randrange(0,6)) + sb(self.c1.trans(4, -2, 4), materials.Cake, random.randrange(0, 6)) elif (random.random() < 0.4): - sb(self.c1.trans(4,-2,4), materials.FlowerPot, random.randrange(1,12)) + sb(self.c1.trans(4, -2, 4), + materials.FlowerPot, random.randrange(1, 12)) else: - sb(self.c1.trans(4,-2,4), materials.Torch) - - + sb(self.c1.trans(4, -2, 4), materials.Torch) # A chest in a study should have writing supplies :) - #item, probability, max stack amount + # item, probability, max stack amount writing_items = [(items.byName('written book'), 1, 1), (items.byName('written book'), 0.3, 1), (items.byName('written book'), 0.2, 1), @@ -1001,9 +1005,16 @@ def renderSecretPost(self): deskloot = [] for s in writing_items: if (random.random() < s[1]): - amount = random.randint(1,min(s[2],s[0].maxstack)) - deskloot.append(loottable.Loot(len(deskloot),amount,s[0].value,s[0].data,'',flag=s[0].flag)) - self.parent.parent.addchest(self.c1.trans(4,-1,6), loot=deskloot) + amount = random.randint(1, min(s[2], s[0].maxstack)) + deskloot.append( + loottable.Loot( + len(deskloot), + amount, + s[0].value, + s[0].data, + '', + flag=s[0].flag)) + self.parent.parent.addchest(self.c1.trans(4, -1, 6), loot=deskloot) self.parent.parent.cobwebs(self.c1.up(4), self.c3) @@ -1016,68 +1027,68 @@ def renderSecretPost(self): blocks = self.parent.parent.blocks # Bookshelves - for p in iterate_four_walls(Vec(1,-1,1), Vec(8,-1,8),2): + for p in iterate_four_walls(Vec(1, -1, 1), Vec(8, -1, 8), 2): if (p.x not in (3, 6) and - p.z not in (3, 6)): - sb(self.c1+p, materials.Bookshelf) + p.z not in (3, 6)): + sb(self.c1 + p, materials.Bookshelf) else: - sb(self.c1+p, materials.Air) + sb(self.c1 + p, materials.Air) # Lighting - for p in (Vec(2,-1,2), Vec(2,-1,7), - Vec(7,-1,2), Vec(7,-1,7)): - sb(self.c1+p, materials.Fence) - sb(self.c1+p.up(1), materials.Torch, 5) + for p in (Vec(2, -1, 2), Vec(2, -1, 7), + Vec(7, -1, 2), Vec(7, -1, 7)): + sb(self.c1 + p, materials.Fence) + sb(self.c1 + p.up(1), materials.Torch, 5) # Desk mats = [ - (materials.Air,0), # 0 - (materials.OakWoodStairs,7), # 1 - (materials.Chest,0), # 2 - (materials.CraftingTable,0),# 3 - (materials.WallSign,0), # 4 - (materials.OakWoodStairs,0), # 5 - (materials.OakWoodStairs,6), # 6 - (materials.OakWoodSlab,8) # 7 + (materials.Air, 0), # 0 + (materials.OakWoodStairs, 7), # 1 + (materials.Chest, 0), # 2 + (materials.CraftingTable, 0), # 3 + (materials.WallSign, 0), # 4 + (materials.OakWoodStairs, 0), # 5 + (materials.OakWoodStairs, 6), # 6 + (materials.OakWoodSlab, 8) # 7 ] template = [ - [1,7,6,2], - [4,5,4,0] + [1, 7, 6, 2], + [4, 5, 4, 0] ] - oo = self.c1.trans(4,-1,3) + oo = self.c1.trans(4, -1, 3) for x in xrange(2): for z in xrange(4): - p = oo.trans(x,0,z) + p = oo.trans(x, 0, z) sb(p, mats[template[x][z]][0], mats[template[x][z]][1]) - self.parent.parent.blocks[self.c1+Vec(5,-1,3)].data = 2 - self.parent.parent.blocks[self.c1+Vec(5,-1,4)].data = 0 - self.parent.parent.blocks[self.c1+Vec(5,-1,5)].data = 3 - sb(self.c1.trans(4,-2,5), materials.Torch) + self.parent.parent.blocks[self.c1 + Vec(5, -1, 3)].data = 2 + self.parent.parent.blocks[self.c1 + Vec(5, -1, 4)].data = 0 + self.parent.parent.blocks[self.c1 + Vec(5, -1, 5)].data = 3 + sb(self.c1.trans(4, -2, 5), materials.Torch) # Wither skulls are rare - SkullType = weighted_choice(((0,30),(1,1))) - sb(self.c1.trans(4,-2,3), materials.MobHead, 1) + SkullType = weighted_choice(((0, 30), (1, 1))) + sb(self.c1.trans(4, -2, 3), materials.MobHead, 1) root_tag = nbt.TAG_Compound() root_tag['id'] = nbt.TAG_String('Skull') - root_tag['x'] = nbt.TAG_Int(self.c1.trans(4,-2,3).x) - root_tag['y'] = nbt.TAG_Int(self.c1.trans(4,-2,3).y) - root_tag['z'] = nbt.TAG_Int(self.c1.trans(4,-2,3).z) + root_tag['x'] = nbt.TAG_Int(self.c1.trans(4, -2, 3).x) + root_tag['y'] = nbt.TAG_Int(self.c1.trans(4, -2, 3).y) + root_tag['z'] = nbt.TAG_Int(self.c1.trans(4, -2, 3).z) root_tag['SkullType'] = nbt.TAG_Byte(SkullType) - root_tag['Rot'] = nbt.TAG_Byte(random.randint(0,15)) - self.parent.parent.tile_ents[self.c1.trans(4,-2,3)] = root_tag + root_tag['Rot'] = nbt.TAG_Byte(random.randint(0, 15)) + self.parent.parent.tile_ents[self.c1.trans(4, -2, 3)] = root_tag # - sb(self.c1.trans(4,-2,4), materials.BrewingStand) + sb(self.c1.trans(4, -2, 4), materials.BrewingStand) root_tag = nbt.TAG_Compound() root_tag['id'] = nbt.TAG_String('Cauldron') - root_tag['x'] = nbt.TAG_Int(self.c1.trans(4,-2,4).x) - root_tag['y'] = nbt.TAG_Int(self.c1.trans(4,-2,4).y) - root_tag['z'] = nbt.TAG_Int(self.c1.trans(4,-2,4).z) - self.parent.parent.tile_ents[self.c1.trans(4,-2,4)] = root_tag + root_tag['x'] = nbt.TAG_Int(self.c1.trans(4, -2, 4).x) + root_tag['y'] = nbt.TAG_Int(self.c1.trans(4, -2, 4).y) + root_tag['z'] = nbt.TAG_Int(self.c1.trans(4, -2, 4).z) + self.parent.parent.tile_ents[self.c1.trans(4, -2, 4)] = root_tag # A chest in an alchemy lab should have brewing supplies :) - #item, probability, max stack amount + # item, probability, max stack amount writing_items = [(items.byName('glass bottle'), 1, 5), (items.byName('book'), 0.7, 5), (items.byName('paper'), 0.8, 10), @@ -1097,9 +1108,16 @@ def renderSecretPost(self): deskloot = [] for s in writing_items: if (random.random() < s[1]): - amount = random.randint(1,min(s[2],s[0].maxstack)) - deskloot.append(loottable.Loot(len(deskloot),amount,s[0].value,s[0].data,'',flag=s[0].flag)) - self.parent.parent.addchest(self.c1.trans(4,-1,6), loot=deskloot) + amount = random.randint(1, min(s[2], s[0].maxstack)) + deskloot.append( + loottable.Loot( + len(deskloot), + amount, + s[0].value, + s[0].data, + '', + flag=s[0].flag)) + self.parent.parent.addchest(self.c1.trans(4, -1, 6), loot=deskloot) self.parent.parent.cobwebs(self.c1.up(4), self.c3) @@ -1118,51 +1136,51 @@ def renderSecretPost(self): # Hall on North side if self.direction == 0: bl = self.c3 - rt = Vec(-1,0,0) - fw = Vec(0,0,-1) + rt = Vec(-1, 0, 0) + fw = Vec(0, 0, -1) st_d = (1, 0, 3, 2) chest = 2 gems = ('W', 'E') # Hall on East side if self.direction == 1: bl = Vec(self.c1.x, self.c1.y, self.c3.z) - rt = Vec(0,0,-1) - fw = Vec(1,0,0) + rt = Vec(0, 0, -1) + fw = Vec(1, 0, 0) st_d = (3, 2, 0, 1) chest = 5 gems = ('N', 'S') # Hall on South side if self.direction == 2: bl = self.c1 - rt = Vec(1,0,0) - fw = Vec(0,0,1) + rt = Vec(1, 0, 0) + fw = Vec(0, 0, 1) st_d = (0, 1, 2, 3) chest = 3 gems = ('E', 'W') # Hall on West Side if self.direction == 3: bl = Vec(self.c3.x, self.c1.y, self.c1.z) - rt = Vec(0,0,1) - fw = Vec(-1,0,0) + rt = Vec(0, 0, 1) + fw = Vec(-1, 0, 0) st_d = (2, 3, 1, 0) chest = 4 gems = ('S', 'N') # Different walls - for q in iterate_four_walls(self.c1, self.c3, self.parent.parent.room_height-2): + for q in iterate_four_walls(self.c1, self.c3, self.parent.parent.room_height - 2): sb(q, materials.meta_mossystonebrick) # Loot for the sarcophagus. loota = [] lootb = [] bone = items.byName('bone') - for slot in xrange(11,15,1): - loota.append(loottable.Loot(slot,1,bone.value,bone.data,'')) - lootb.append(loottable.Loot(slot,1,bone.value,bone.data,'')) - for slot in xrange(18,27,1): - loota.append(loottable.Loot(slot,1,bone.value,bone.data,'')) - for slot in xrange(0,9,1): - lootb.append(loottable.Loot(slot,1,bone.value,bone.data,'')) + for slot in xrange(11, 15, 1): + loota.append(loottable.Loot(slot, 1, bone.value, bone.data, '')) + lootb.append(loottable.Loot(slot, 1, bone.value, bone.data, '')) + for slot in xrange(18, 27, 1): + loota.append(loottable.Loot(slot, 1, bone.value, bone.data, '')) + for slot in xrange(0, 9, 1): + lootb.append(loottable.Loot(slot, 1, bone.value, bone.data, '')) # Random stuff to be buried with. Like Crypt, but not as good. lootc = [(items.byName('iron ingot'), 5), @@ -1201,7 +1219,7 @@ def renderSecretPost(self): lootb[7].id = i.value lootb[7].damage = i.data # Swap the contents if East or South - if self.direction in (0,1): + if self.direction in (0, 1): loota, lootb = lootb, loota # Sarcophagus @@ -1215,20 +1233,21 @@ def renderSecretPost(self): (materials.StoneBrickSlab, 0), ) template = (( - (2,1,1,2), - (1,4,4,1), - (2,1,1,2) - ),( - (0,0,0,0), - (3,6,6,5), - (0,0,0,0) - ) + (2, 1, 1, 2), + (1, 4, 4, 1), + (2, 1, 1, 2) + ), ( + (0, 0, 0, 0), + (3, 6, 6, 5), + (0, 0, 0, 0) + ) ) - tomb_name = 'Here lies '+self.parent.parent.namegen.genname() + tomb_name = 'Here lies ' + self.parent.parent.namegen.genname() for y in xrange(2): for x in xrange(4): for z in xrange(3): - p = bl+rt*(x+3)+fw*(z+2)+Vec(0,-1,0)*(y+1) + p = bl + rt * (x + 3) + fw * (z + 2) + \ + Vec(0, -1, 0) * (y + 1) sb(p, mats[template[y][z][x]][0], mats[template[y][z][x]][1]) @@ -1245,30 +1264,30 @@ def renderSecretPost(self): (materials.Sandstone, 2), (materials.SandstoneStairs, st_d[2]), (materials.SandstoneStairs, st_d[3]), - (materials.SandstoneStairs, st_d[2]+4), - (materials.SandstoneStairs, st_d[3]+4), + (materials.SandstoneStairs, st_d[2] + 4), + (materials.SandstoneStairs, st_d[3] + 4), (materials.SandstoneSlab, 0), ) template = ( - (1,0,6,5,2), - (6,0,5,0,0), - (4,7,3,0,0), + (1, 0, 6, 5, 2), + (6, 0, 5, 0, 0), + (4, 7, 3, 0, 0), ) for y in xrange(3): for z in xrange(5): - p = bl+rt+fw*(z+1)+Vec(0,1,0)*(-3+y) + p = bl + rt + fw * (z + 1) + Vec(0, 1, 0) * (-3 + y) sb(p, mats[template[y][z]][0], mats[template[y][z]][1]) - sb(p+rt*7, + sb(p + rt * 7, mats[template[y][z]][0], mats[template[y][z]][1]) # Lootable gems for eyes loot = weighted_choice((("emerald", 10), ("diamond", 1))) - for p in (Vec(1,-3,5), Vec(8,-3,5)): - q =bl+rt*p.x+fw*p.z+Vec(0,1,0)*p.y + for p in (Vec(1, -3, 5), Vec(8, -3, 5)): + q = bl + rt * p.x + fw * p.z + Vec(0, 1, 0) * p.y if p.x <= 5: d = gems[0] else: @@ -1279,9 +1298,9 @@ def renderSecretPost(self): Direction=d) dungeon.addentity(tags) - #Vines + # Vines for p in iterate_cube(self.c1.up(4), self.c3): - if random.randint(1,100) <= 20: + if random.randint(1, 100) <= 20: self.parent.parent.vines(p, grow=True) # Cobwebs @@ -1303,24 +1322,24 @@ def renderSecretPost(self): for q in iterate_cube(self.c1, self.c3): sb(q, materials.meta_mossystonebrick) # Different walls - for q in iterate_four_walls(self.c1, self.c3, self.parent.parent.room_height-2): + for q in iterate_four_walls(self.c1, self.c3, self.parent.parent.room_height - 2): sb(q, materials.meta_mossystonebrick) # Fancy wall coverings - for p in iterate_four_walls(Vec(1,-1,1), Vec(8,-1,8),3): - sb(self.c1+p, materials.meta_mossycobblewall) - for p in iterate_four_walls(Vec(1,-4,1), Vec(8,-4,8),0): - sb(self.c1+p, materials.meta_mossystonebrick) + for p in iterate_four_walls(Vec(1, -1, 1), Vec(8, -1, 8), 3): + sb(self.c1 + p, materials.meta_mossycobblewall) + for p in iterate_four_walls(Vec(1, -4, 1), Vec(8, -4, 8), 0): + sb(self.c1 + p, materials.meta_mossystonebrick) # Lighting - for p in (Vec(1,-2,1), Vec(1,-2,8), - Vec(8,-2,1), Vec(8,-2,8)): - sb(self.c1+p, materials.Torch, 5) + for p in (Vec(1, -2, 1), Vec(1, -2, 8), + Vec(8, -2, 1), Vec(8, -2, 8)): + sb(self.c1 + p, materials.Torch, 5) # Thing in the middle - for p in iterate_cube(Vec(4,-1,4), Vec(5,-1,5)): - sb(self.c1+p, materials.meta_mossycobblewall) - sb(self.c1+p.up(3), materials.BlockOfQuartz, 1, hide=True) + for p in iterate_cube(Vec(4, -1, 4), Vec(5, -1, 5)): + sb(self.c1 + p, materials.meta_mossycobblewall) + sb(self.c1 + p.up(3), materials.BlockOfQuartz, 1, hide=True) # Armory alcoves. We want to leave out the ones on the wall with the # hallway. Each entry here stores: @@ -1328,20 +1347,20 @@ def renderSecretPost(self): alcoves = [] # North Side if self.direction != 0: - alcoves.append([Vec(3,-1,1), 3, Vec(3,-2,0), 'S']) - alcoves.append([Vec(6,-1,1), 3, Vec(6,-2,0), 'S']) + alcoves.append([Vec(3, -1, 1), 3, Vec(3, -2, 0), 'S']) + alcoves.append([Vec(6, -1, 1), 3, Vec(6, -2, 0), 'S']) # East Side if self.direction != 1: - alcoves.append([Vec(8,-1,3), 4, Vec(9,-2,3), 'W']) - alcoves.append([Vec(8,-1,6), 4, Vec(9,-2,6), 'W']) + alcoves.append([Vec(8, -1, 3), 4, Vec(9, -2, 3), 'W']) + alcoves.append([Vec(8, -1, 6), 4, Vec(9, -2, 6), 'W']) # South Side if self.direction != 2: - alcoves.append([Vec(3,-1,8), 2, Vec(3,-2,9), 'N']) - alcoves.append([Vec(6,-1,8), 2, Vec(6,-2,9), 'N']) + alcoves.append([Vec(3, -1, 8), 2, Vec(3, -2, 9), 'N']) + alcoves.append([Vec(6, -1, 8), 2, Vec(6, -2, 9), 'N']) # West Side if self.direction != 3: - alcoves.append([Vec(1,-1,3), 5, Vec(0,-2,3), 'E']) - alcoves.append([Vec(1,-1,6), 5, Vec(0,-2,6), 'E']) + alcoves.append([Vec(1, -1, 3), 5, Vec(0, -2, 3), 'E']) + alcoves.append([Vec(1, -1, 6), 5, Vec(0, -2, 6), 'E']) # Now, add a random item to each frame. gear = ( @@ -1387,76 +1406,81 @@ def renderSecretPost(self): item = weighted_choice(gear) if 'sword' in item: - ItemRotation = random.randint(0,3) + ItemRotation = random.randint(0, 3) elif 'axe' in item: - ItemRotation = random.choice((0,3)) + ItemRotation = random.choice((0, 3)) else: ItemRotation = 0 # Spice things up with some synonyms if 'sword' in item: - item_name = random.choice(('sword','blade','claymore', - 'cutlass','sabre','scimitar')) + item_name = random.choice(('sword', 'blade', 'claymore', + 'cutlass', 'sabre', 'scimitar')) elif 'pickaxe' in item: - item_name = random.choice(('pickaxe','pickax','pick')) + item_name = random.choice(('pickaxe', 'pickax', 'pick')) elif 'axe' in item: - item_name = random.choice(('ax','axe','hatchet')) + item_name = random.choice(('ax', 'axe', 'hatchet')) elif 'shears' in item: - item_name = random.choice(('shears','clippers','scissors')) + item_name = random.choice(('shears', 'clippers', 'scissors')) elif 'fishing rod' in item: - item_name = random.choice(('fishing rod','fishing pole','rod')) + item_name = random.choice( + ('fishing rod', 'fishing pole', 'rod')) elif 'chestplate' in item: - item_name = random.choice(('chestplate','tunic','vest', - 'mail','plate')) + item_name = random.choice(('chestplate', 'tunic', 'vest', + 'mail', 'plate')) elif 'helmet' in item: - item_name = random.choice(('helmet','hat','helm','headgear')) + item_name = random.choice( + ('helmet', 'hat', 'helm', 'headgear')) elif 'boots' in item: - item_name = random.choice(('boots','shoes')) + item_name = random.choice(('boots', 'shoes')) elif "name tag" in item: - item_name = random.choice(('name tag','tag','dog tags')) + item_name = random.choice(('name tag', 'tag', 'dog tags')) elif "horse armor" in item: - item_name = random.choice(('horse armor','barding')) + item_name = random.choice(('horse armor', 'barding')) else: item_name = item.split()[-1] # Owner's name name = dungeon.namegen.genname() # The plaque - sb(self.c1+p[0], materials.WallSign, p[1]) - sb(self.c1+p[0].up(1), materials.Air) + sb(self.c1 + p[0], materials.WallSign, p[1]) + sb(self.c1 + p[0].up(1), materials.Air) if name.endswith("s"): - dungeon.addsign(self.c1+p[0], + dungeon.addsign(self.c1 + p[0], '', item_name.capitalize(), - 'of '+name, + 'of ' + name, '' - ) + ) else: - dungeon.addsign(self.c1+p[0], + dungeon.addsign(self.c1 + p[0], '', - name+"'s", + name + "'s", item_name, '' - ) + ) # Build the frame tags tags = get_entity_other_tags("ItemFrame", - Pos=self.c1+p[2], + Pos=self.c1 + p[2], Direction=p[3], ItemRotation=ItemRotation, ItemInfo=items.byName(item)) # Name the item tags['Item']['tag'] = nbt.TAG_Compound() tags['Item']['tag']['display'] = nbt.TAG_Compound() - if (item == 'name tag'): # Special case, tags should just have the name + # Special case, tags should just have the name + if (item == 'name tag'): displayname = name elif name.endswith("s"): - displayname = item_name.capitalize()+' of '+name + displayname = item_name.capitalize() + ' of ' + name else: - displayname = name+"'s "+item_name - tags['Item']['tag']['display']['Name'] = nbt.TAG_String(displayname) + displayname = name + "'s " + item_name + tags['Item']['tag']['display'][ + 'Name'] = nbt.TAG_String(displayname) # Color leather things. if 'leather' in item and 'horse' not in item: - tags['Item']['tag']['display']['color'] = nbt.TAG_Int(random.randrange(16777215)) + tags['Item']['tag']['display']['color'] = nbt.TAG_Int( + random.randrange(16777215)) # Place the item frame. dungeon.addentity(tags) @@ -1465,24 +1489,24 @@ def renderSecretPost(self): # DEATH KNIGHT! RRRRRAGH! if random.random() < .80: - pos = Vec(3,-2,3) + pos = Vec(3, -2, 3) # Always get a weapon while True: item = weighted_choice(gear) if ('bow' in item or - 'sword' in item or - 'axe' in item): + 'sword' in item or + 'axe' in item): break # Place some lore words = random.choice([ - "...some say the corpse of {name} still wanders these halls "\ + "...some say the corpse of {name} still wanders these halls " "clutching his enchanted {item} in his moldering hands...", "...Beware! For {name} cheats death to this day...", - "...I can feel the presence of the {item}... So close. It "\ + "...I can feel the presence of the {item}... So close. It " "calls my name! {name}! {name}!", - "...They shall never hold the {item}. I will carry it with "\ + "...They shall never hold the {item}. I will carry it with " "me, even in death! -{name}", - "...My guide, {name}, seems strangely calm in this horrible "\ + "...My guide, {name}, seems strangely calm in this horrible " "place. As if he has been here before..." ]) words = words.format(name=name, item=item.split()[-1]) @@ -1495,7 +1519,7 @@ def renderSecretPost(self): note['tag']['author'] = nbt.TAG_String("Unknown") note['tag']['pages'] = nbt.TAG_List() note['tag']['pages'].append(nbt.TAG_String(words)) - max_lev = (self.c1.y//dungeon.room_height)+1 + max_lev = (self.c1.y // dungeon.room_height) + 1 dungeon.addplaceditem(note, max_lev=max_lev) # helmet @@ -1528,12 +1552,12 @@ def renderSecretPost(self): boots_tags['id'] = nbt.TAG_Short(items.byName(boots).value) tags = get_entity_mob_tags("Skeleton", - Pos=self.c1+pos, + Pos=self.c1 + pos, CanPickUpLoot=1, - SkeletonType=random.randint(0,1), + SkeletonType=random.randint(0, 1), PersistenceRequired=1, CustomName=name - ) + ) tags['Equipment'][1] = boots_tags tags['Equipment'][2] = leggings_tags tags['Equipment'][3] = chest_tags @@ -1546,25 +1570,26 @@ def renderSecretPost(self): tags['DropChances'][4].value = 0.0 dungeon.addentity(tags) else: - pos = Vec(5,-2,5) + pos = Vec(5, -2, 5) item = weighted_choice(gear) # Centerpiece if name.endswith("s"): - displayname = item.split()[-1].capitalize()+' of '+name + displayname = item.split()[-1].capitalize() + ' of ' + name else: - displayname = name+"'s "+item.split()[-1] + displayname = name + "'s " + item.split()[-1] - xplevel = (int( self.c1.y/dungeon.room_height)+1)*5 + xplevel = (int(self.c1.y / dungeon.room_height) + 1) * 5 tags = get_entity_item_tags("Item", - Pos=self.c1+pos.up(1), - Age=-32768, - ItemInfo=items.byName(item)) + Pos=self.c1 + pos.up(1), + Age=-32768, + ItemInfo=items.byName(item)) tags['Item']['tag'] = nbt.TAG_Compound() tags['Item']['tag']['display'] = nbt.TAG_Compound() tags['Item']['tag']['display']['Name'] = nbt.TAG_String(displayname) if 'leather' in item and 'horse' not in item: - tags['Item']['tag']['display']['color'] = nbt.TAG_Int(random.randrange(16777215)) + tags['Item']['tag']['display']['color'] = nbt.TAG_Int( + random.randrange(16777215)) tags['Item']['tag']['ench'] = loottable.enchant_tags(item, xplevel) dungeon.addentity(tags) @@ -1588,32 +1613,32 @@ def renderSecretPost(self): self.c1 = self.c1.w(1) self.c3 = self.c3.s(1) bl = self.c3 - rt = Vec(-1,0,0) - fw = Vec(0,0,-1) + rt = Vec(-1, 0, 0) + fw = Vec(0, 0, -1) chests = (4, 2, 5) # Hall on East side if self.direction == 1: self.c1 = self.c1.n(1) self.c1 = self.c1.w(1) bl = Vec(self.c1.x, self.c1.y, self.c3.z) - rt = Vec(0,0,-1) - fw = Vec(1,0,0) + rt = Vec(0, 0, -1) + fw = Vec(1, 0, 0) chests = (4, 1, 3) # Hall on South side if self.direction == 2: self.c1 = self.c1.n(1) self.c3 = self.c3.e(1) bl = self.c1 - rt = Vec(1,0,0) - fw = Vec(0,0,1) + rt = Vec(1, 0, 0) + fw = Vec(0, 0, 1) chests = (5, 3, 4) # Hall on West Side if self.direction == 3: self.c3 = self.c3.e(1) self.c3 = self.c3.s(1) bl = Vec(self.c3.x, self.c1.y, self.c1.z) - rt = Vec(0,0,1) - fw = Vec(-1,0,0) + rt = Vec(0, 0, 1) + fw = Vec(-1, 0, 0) chests = (3, 4, 2) # Reform the room (again) @@ -1623,7 +1648,7 @@ def renderSecretPost(self): sb(q, materials.StoneBrickSlab, 13, hide=True) for q in iterate_cube(self.c1, self.c3): sb(q, materials.ChiseledStoneBrick) - for q in iterate_four_walls(self.c1, self.c3, self.parent.parent.room_height-2): + for q in iterate_four_walls(self.c1, self.c3, self.parent.parent.room_height - 2): sb(q, materials.meta_mossystonebrick) # Fancy carpet @@ -1634,49 +1659,49 @@ def renderSecretPost(self): materials.OrangeWool.data, ] # Random stripe color (skip white, grays, and black) - mats[3] = random.randint(1,6) + random.randint(0,1)*8 + mats[3] = random.randint(1, 6) + random.randint(0, 1) * 8 template = ( - (1,3,3,1,3,1,3,3,1), - (3,3,2,0,2,0,2,3,3), - (3,2,0,2,0,2,0,2,3), - (1,0,2,0,2,0,2,0,1), - (3,2,0,2,0,2,0,2,3), - (1,0,2,0,2,0,2,0,1), - (3,2,0,2,0,2,0,2,3), - (3,3,2,0,2,0,2,3,3), - (1,3,3,3,3,3,3,3,1) + (1, 3, 3, 1, 3, 1, 3, 3, 1), + (3, 3, 2, 0, 2, 0, 2, 3, 3), + (3, 2, 0, 2, 0, 2, 0, 2, 3), + (1, 0, 2, 0, 2, 0, 2, 0, 1), + (3, 2, 0, 2, 0, 2, 0, 2, 3), + (1, 0, 2, 0, 2, 0, 2, 0, 1), + (3, 2, 0, 2, 0, 2, 0, 2, 3), + (3, 3, 2, 0, 2, 0, 2, 3, 3), + (1, 3, 3, 3, 3, 3, 3, 3, 1) ) for x in xrange(9): for z in xrange(9): if template[z][x] != 1: - p = bl+rt*(x+1)+fw*(z+1) + p = bl + rt * (x + 1) + fw * (z + 1) sb(p, materials.PinkWool, mats[template[z][x]]) # Columns else: - p = bl+rt*(x+1)+fw*(z+1) + p = bl + rt * (x + 1) + fw * (z + 1) sb(p.up(1), materials.CobblestoneWall) sb(p.up(2), materials.CobblestoneWall) sb(p.up(3), materials.CobblestoneWall) sb(p.up(4), materials.meta_mossystonebrick) # Lighting - for p in (Vec(1,-4,1), Vec(1,-4,9), - Vec(9,-4,1), Vec(9,-4,9), + for p in (Vec(1, -4, 1), Vec(1, -4, 9), + Vec(9, -4, 1), Vec(9, -4, 9), Vec(5, -4, 5)): - sb(self.c1+p, materials.RedstoneLampOn, hide=True) - sb(self.c1+p.up(1), materials.BlockOfRedstone, hide=True) + sb(self.c1 + p, materials.RedstoneLampOn, hide=True) + sb(self.c1 + p.up(1), materials.BlockOfRedstone, hide=True) # The book cases - levs = int( self.c1.y/dungeon.room_height)+1 + levs = int(self.c1.y / dungeon.room_height) + 1 spots = [ - Vec(5,2,3), Vec(5,1,3), - Vec(3,2,6), Vec(3,1,6), - Vec(4,2,3), Vec(4,1,3), - Vec(3,2,4), Vec(3,1,4), - Vec(3,2,5), Vec(3,1,5) + Vec(5, 2, 3), Vec(5, 1, 3), + Vec(3, 2, 6), Vec(3, 1, 6), + Vec(4, 2, 3), Vec(4, 1, 3), + Vec(3, 2, 4), Vec(3, 1, 4), + Vec(3, 2, 5), Vec(3, 1, 5) ] mat = materials.Bookshelf while len(spots) > 0: @@ -1684,13 +1709,13 @@ def renderSecretPost(self): mat = materials.OakWoodPlanks levs -= 1 s = spots.pop() - p = (bl+rt*s.x+fw*s.z).up(s.y) + p = (bl + rt * s.x + fw * s.z).up(s.y) sb(p, mat) - p = (bl+rt*10-rt*s.x+fw*s.z).up(s.y) + p = (bl + rt * 10 - rt * s.x + fw * s.z).up(s.y) sb(p, mat) # Enchanting table - p = self.c1+Vec(5,-1,5) + p = self.c1 + Vec(5, -1, 5) sb(p, materials.EnchantmentTable) tags = nbt.TAG_Compound() tags['id'] = nbt.TAG_String('EnchantTable') @@ -1700,17 +1725,17 @@ def renderSecretPost(self): dungeon.tile_ents[p] = tags # Loot chests - p = (bl+rt*1+fw*5).up(1) + p = (bl + rt * 1 + fw * 5).up(1) sb(p, materials.Chest, chests[0]) tags = nbt.TAG_Compound() dungeon.addchest(p) - p = (bl+rt*9+fw*5).up(1) + p = (bl + rt * 9 + fw * 5).up(1) sb(p, materials.Chest, chests[2]) tags = nbt.TAG_Compound() dungeon.addchest(p) # Ender chest - p = (bl+rt*5+fw*1).up(1) + p = (bl + rt * 5 + fw * 1).up(1) sb(p, materials.EnderChest, chests[1]) tags = nbt.TAG_Compound() tags['id'] = nbt.TAG_String('EnderChest') @@ -1721,11 +1746,11 @@ def renderSecretPost(self): # She's a witch! tags = get_entity_mob_tags("Witch", - Pos=self.c1+Vec(5,-2,5)+fw*2, + Pos=self.c1 + Vec(5, -2, 5) + fw * 2, PersistenceRequired=1, CustomName=self.parent.parent.namegen.genname(), CanPickUpLoot=1 - ) + ) dungeon.addentity(tags) @@ -1751,7 +1776,7 @@ def render(self): (materials.Chest, 0), # 7 (materials.CraftingTable, 0), # 8 (materials.Anvil, 0), # 9 - (materials.AnvilSlightlyDmg, 4),# 10 + (materials.AnvilSlightlyDmg, 4), # 10 (materials.AnvilVeryDmg, 8), # 11 (materials.Cauldron, 0), # 12 (materials.Cauldron, 1), # 13 @@ -1760,60 +1785,60 @@ def render(self): ] template = [ - [0,2,5,2,2,7], - [2,3,4,6,6,2], - [2,3,4,6,6,2], - [1,2,5,2,2,8] + [0, 2, 5, 2, 2, 7], + [2, 3, 4, 6, 6, 2], + [2, 3, 4, 6, 6, 2], + [1, 2, 5, 2, 2, 8] ] - #random anvil (or other...) - anvil_options = ((9,1), #New anvil - (10,15), #Slightly Damged - (11,30), #Very Damaged - (12,30), #Empty cauldron - (13,30), #1/3 cauldron - (14,30), #2/3 cauldron - (15,30), #Full cauldron - (1,50)) #Furnace! + # random anvil (or other...) + anvil_options = ((9, 1), # New anvil + (10, 15), # Slightly Damged + (11, 30), # Very Damaged + (12, 30), # Empty cauldron + (13, 30), # 1/3 cauldron + (14, 30), # 2/3 cauldron + (15, 30), # Full cauldron + (1, 50)) # Furnace! template[0][0] = weighted_choice(anvil_options) center = self.parent.canvasCenter() - o = self.parent.loc.trans(center.x-1, - self.parent.canvasHeight()-1, - center.z-2) + o = self.parent.loc.trans(center.x - 1, + self.parent.canvasHeight() - 1, + center.z - 2) for x in xrange(4): for z in xrange(6): - p = o.trans(x,0,z) + p = o.trans(x, 0, z) sb(p, mats[template[x][z]][0], mats[template[x][z]][1]) - sb (o.trans(0,0,3), materials.StoneStairs, 0) - sb (o.trans(0,0,4), materials.StoneStairs, 0) - sb (o.trans(3,0,3), materials.StoneStairs, 1) - sb (o.trans(3,0,4), materials.StoneStairs, 1) - sb (o.trans(1,0,5), materials.StoneStairs, 3) - sb (o.trans(2,0,5), materials.StoneStairs, 3) + sb(o.trans(0, 0, 3), materials.StoneStairs, 0) + sb(o.trans(0, 0, 4), materials.StoneStairs, 0) + sb(o.trans(3, 0, 3), materials.StoneStairs, 1) + sb(o.trans(3, 0, 4), materials.StoneStairs, 1) + sb(o.trans(1, 0, 5), materials.StoneStairs, 3) + sb(o.trans(2, 0, 5), materials.StoneStairs, 3) # Tall rooms won't have a flume if self.parent.canvasHeight() > 4: return - sb (o.trans(0,-2,3), materials.StoneStairs, 0) - sb (o.trans(0,-2,4), materials.StoneStairs, 0) - sb (o.trans(3,-2,3), materials.StoneStairs, 1) - sb (o.trans(3,-2,4), materials.StoneStairs, 1) - sb (o.trans(1,-2,5), materials.StoneStairs, 3) - sb (o.trans(2,-2,5), materials.StoneStairs, 3) - sb (o.trans(1,-2,2), materials.StoneStairs, 2) - sb (o.trans(2,-2,2), materials.StoneStairs, 2) + sb(o.trans(0, -2, 3), materials.StoneStairs, 0) + sb(o.trans(0, -2, 4), materials.StoneStairs, 0) + sb(o.trans(3, -2, 3), materials.StoneStairs, 1) + sb(o.trans(3, -2, 4), materials.StoneStairs, 1) + sb(o.trans(1, -2, 5), materials.StoneStairs, 3) + sb(o.trans(2, -2, 5), materials.StoneStairs, 3) + sb(o.trans(1, -2, 2), materials.StoneStairs, 2) + sb(o.trans(2, -2, 2), materials.StoneStairs, 2) class Pool(Blank): _name = 'pool' - def render (self): + def render(self): if (self.parent.canvasWidth() < 8 or self.parent.canvasLength() < 8): return mat = random.choice(( @@ -1824,65 +1849,66 @@ def render (self): )) center = self.parent.canvasCenter() size = random.randint(4, - min(self.parent.canvasWidth(), - self.parent.canvasLength()) - 2) - p0 = Vec(center.x - size/2 + 1, + min(self.parent.canvasWidth(), + self.parent.canvasLength()) - 2) + p0 = Vec(center.x - size / 2 + 1, self.parent.canvasHeight(), - center.z - size/2 + 1) + self.parent.loc - p1 = p0.trans(size-1, 0, size-1) + center.z - size / 2 + 1) + self.parent.loc + p1 = p0.trans(size - 1, 0, size - 1) for p in iterate_disc(p0, p1): self.parent.parent.setblock(p, materials.Water) for p in iterate_ellipse(p0, p1): self.parent.parent.setblock(p, materials._floor) self.parent.parent.setblock(p.up(1), mat) + class CircleOfSkulls(Blank): _name = 'circleofskulls' - def render (self): + def render(self): if (self.parent.canvasWidth() < 8 or self.parent.canvasLength() < 8): return center = self.parent.canvasCenter() size = random.randint(6, - min(self.parent.canvasWidth(), - self.parent.canvasLength()) - 1) - p0 = Vec(center.x - size/2 + 1, + min(self.parent.canvasWidth(), + self.parent.canvasLength()) - 1) + p0 = Vec(center.x - size / 2 + 1, self.parent.canvasHeight(), - center.z - size/2 + 1) + self.parent.loc - p1 = p0.trans(size-1, 0, size-1) + center.z - size / 2 + 1) + self.parent.loc + p1 = p0.trans(size - 1, 0, size - 1) skulls = ( - (0, 50), # Plain Skull + (0, 50), # Plain Skull (1, 1), # Wither Skull ) counter = 0 for p in iterate_ellipse(p0, p1): - if( (p.x + p.z) % 2 == 0 ): + if((p.x + p.z) % 2 == 0): self.parent.parent.setblock(p, materials._floor) self.parent.parent.setblock(p.up(1), materials.Fence) # Abort if there is no skull here - if (random.randint(0,100) < 33): + if (random.randint(0, 100) < 33): continue SkullType = weighted_choice(skulls) self.parent.parent.setblock(p.up(2), materials.MobHead, 1) root_tag = nbt.TAG_Compound() root_tag['id'] = nbt.TAG_String('Skull') root_tag['x'] = nbt.TAG_Int(p.x) - root_tag['y'] = nbt.TAG_Int(p.y-2) + root_tag['y'] = nbt.TAG_Int(p.y - 2) root_tag['z'] = nbt.TAG_Int(p.z) root_tag['SkullType'] = nbt.TAG_Byte(SkullType) - root_tag['Rot'] = nbt.TAG_Byte(random.randint(0,15)) + root_tag['Rot'] = nbt.TAG_Byte(random.randint(0, 15)) self.parent.parent.tile_ents[p.up(2)] = root_tag - elif( random.randint(0,100) < 33 ): + elif(random.randint(0, 100) < 33): self.parent.parent.setblock(p, materials._floor) self.parent.parent.setblock(p.up(1), materials.Torch) + class Cell(Blank): _name = 'cell' - def render(self): if (self.parent.canvasWidth() < 8 or self.parent.canvasLength() < 8): return @@ -1890,63 +1916,62 @@ def render(self): sb = self.parent.parent.setblock mats = [ - (materials.Air, 0), # 0 - (materials._wall, 0), # 1 - (materials.IronBars, 0) # 2 + (materials.Air, 0), # 0 + (materials._wall, 0), # 1 + (materials.IronBars, 0) # 2 ] center = self.parent.canvasCenter() - o = self.parent.loc.trans(center.x-2, - self.parent.canvasHeight()-1, - center.z-2) + o = self.parent.loc.trans(center.x - 2, + self.parent.canvasHeight() - 1, + center.z - 2) - locs = [ o ] + locs = [o] # If it's a bigroom, add more cells. - # 2x2 rooms have no conflicts. + # 2x2 rooms have no conflicts. if (self.parent.size.x == 2 and self.parent.size.z == 2): - locs.extend( [ o.trans(5,0,0), o.trans(-5,0,0) ] ) - locs.extend( [ o.trans(0,0,5), o.trans(0,0,-5) ] ) + locs.extend([o.trans(5, 0, 0), o.trans(-5, 0, 0)]) + locs.extend([o.trans(0, 0, 5), o.trans(0, 0, -5)]) # 2x1 rooms need to check for stairwells. elif (self.parent.size.x == 2): - if(self.parent.pos + Vec(0,self.parent.size.y,0) not in + if(self.parent.pos + Vec(0, self.parent.size.y, 0) not in self.parent.parent.stairwells): - locs.extend( [ o.trans(-5,0,0) ] ) - if(self.parent.pos + Vec(1,self.parent.size.y,0) not in + locs.extend([o.trans(-5, 0, 0)]) + if(self.parent.pos + Vec(1, self.parent.size.y, 0) not in self.parent.parent.stairwells): - locs.extend( [ o.trans(5,0,0) ] ) + locs.extend([o.trans(5, 0, 0)]) # 1x2 rooms need to check for stairwells. elif (self.parent.size.z == 2): - if(self.parent.pos + Vec(0,self.parent.size.y,0) not in + if(self.parent.pos + Vec(0, self.parent.size.y, 0) not in self.parent.parent.stairwells): - locs.extend( [ o.trans(0,0,-5) ] ) - if(self.parent.pos + Vec(0,self.parent.size.y,1) not in + locs.extend([o.trans(0, 0, -5)]) + if(self.parent.pos + Vec(0, self.parent.size.y, 1) not in self.parent.parent.stairwells): - locs.extend( [ o.trans(0,0,5) ] ) + locs.extend([o.trans(0, 0, 5)]) for loc in locs: - #each side has a random chance of being a space, wall, or bars - n = random.choice( (0,0,2,2,2,2,1) ) - e = random.choice( (0,0,2,2,2,2,1) ) - s = random.choice( (0,0,2,2,2,2,1) ) - w = random.choice( (0,0,2,2,2,2,1) ) + # each side has a random chance of being a space, wall, or bars + n = random.choice((0, 0, 2, 2, 2, 2, 1)) + e = random.choice((0, 0, 2, 2, 2, 2, 1)) + s = random.choice((0, 0, 2, 2, 2, 2, 1)) + w = random.choice((0, 0, 2, 2, 2, 2, 1)) template = [ - [1,1,n,n,1,1], - [1,0,0,0,0,1], - [w,0,0,0,0,e], - [w,0,0,0,0,e], - [1,0,0,0,0,1], - [1,1,s,s,1,1] + [1, 1, n, n, 1, 1], + [1, 0, 0, 0, 0, 1], + [w, 0, 0, 0, 0, e], + [w, 0, 0, 0, 0, e], + [1, 0, 0, 0, 0, 1], + [1, 1, s, s, 1, 1] ] - for x in xrange(6): for z in xrange(6): - p = loc.trans(x,0,z) + p = loc.trans(x, 0, z) sb(p, mats[template[x][z]][0], mats[template[x][z]][1]) @@ -1967,60 +1992,60 @@ def render(self): center = self.parent.canvasCenter() - o = self.parent.loc.trans(center.x-2, - self.parent.canvasHeight()-1, - center.z-2) + o = self.parent.loc.trans(center.x - 2, + self.parent.canvasHeight() - 1, + center.z - 2) - locs = [ o ] + locs = [o] # If it's a bigroom, add more cells. stairs = self.parent.parent.stairwells p = self.parent.pos - y = self.parent.size.y-1 + y = self.parent.size.y - 1 # 2x2 rooms N,S,E,W are fine, need to check diagonals. if (self.parent.size.x == 2 and self.parent.size.z == 2): - locs.extend( [ o.trans(0,0,-5), o.trans(0,0,5), - o.trans(5,0,0), o.trans(-5,0,0)] ) + locs.extend([o.trans(0, 0, -5), o.trans(0, 0, 5), + o.trans(5, 0, 0), o.trans(-5, 0, 0)]) # NW - if(p+Vec(0,y,0) not in stairs and - p+Vec(0,y+1,0) not in stairs): - locs.extend( [ o.trans(-5,0,-5) ] ) + if(p + Vec(0, y, 0) not in stairs and + p + Vec(0, y + 1, 0) not in stairs): + locs.extend([o.trans(-5, 0, -5)]) # NE - if(p+Vec(1,y,0) not in stairs and - p+Vec(1,y+1,0) not in stairs): - locs.extend( [ o.trans(5,0,-5) ] ) + if(p + Vec(1, y, 0) not in stairs and + p + Vec(1, y + 1, 0) not in stairs): + locs.extend([o.trans(5, 0, -5)]) # SW - if(p+Vec(0,y,1) not in stairs and - p+Vec(0,y+1,1) not in stairs): - locs.extend( [ o.trans(-5,0,5) ] ) + if(p + Vec(0, y, 1) not in stairs and + p + Vec(0, y + 1, 1) not in stairs): + locs.extend([o.trans(-5, 0, 5)]) # SE - if(p+Vec(1,y,1) not in stairs and - p+Vec(1,y+1,1) not in stairs): - locs.extend( [ o.trans(5,0,5) ] ) + if(p + Vec(1, y, 1) not in stairs and + p + Vec(1, y + 1, 1) not in stairs): + locs.extend([o.trans(5, 0, 5)]) # 2x1 rooms need to check for stairwells. elif (self.parent.size.x == 2): - if(p+Vec(0,y,0) not in stairs and - p+Vec(0,y+1,0) not in stairs): - locs.extend( [ o.trans(-5,0,0) ] ) - if(p+Vec(1,y,0) not in stairs and - p+Vec(1,y+1,0) not in stairs): - locs.extend( [ o.trans(5,0,0) ] ) + if(p + Vec(0, y, 0) not in stairs and + p + Vec(0, y + 1, 0) not in stairs): + locs.extend([o.trans(-5, 0, 0)]) + if(p + Vec(1, y, 0) not in stairs and + p + Vec(1, y + 1, 0) not in stairs): + locs.extend([o.trans(5, 0, 0)]) # 1x2 rooms need to check for stairwells. elif (self.parent.size.z == 2): - if(p+Vec(0,y,0) not in stairs and - p+Vec(0,y+1,0) not in stairs): - locs.extend( [ o.trans(0,0,-5) ] ) - if(p+Vec(0,y,1) not in stairs and - p+Vec(0,y+1,1) not in stairs): - locs.extend( [ o.trans(0,0,5) ] ) - + if(p + Vec(0, y, 0) not in stairs and + p + Vec(0, y + 1, 0) not in stairs): + locs.extend([o.trans(0, 0, -5)]) + if(p + Vec(0, y, 1) not in stairs and + p + Vec(0, y + 1, 1) not in stairs): + locs.extend([o.trans(0, 0, 5)]) + self.plant(locs) - + def plant(self, locs): sb = self.parent.parent.setblock - + crops = [ (materials.Fern, 2), (materials.TallGrass, 1), @@ -2031,45 +2056,44 @@ def plant(self, locs): ] for loc in locs: - #choose a random crop. there's a 33% change it'll be a dead bush - #i mean good lord, it's in an UNDERGROUND ABANDONED dungeon (: - if( random.randint(0, 100) < 34 ): + # choose a random crop. there's a 33% change it'll be a dead bush + # i mean good lord, it's in an UNDERGROUND ABANDONED dungeon (: + if(random.randint(0, 100) < 34): crop = (materials.DeadBush, 0) else: crop = random.choice(crops) - #choose an appropriate soil - soil = ( materials.Dirt, 0 ) - if( crop[0] == materials.NetherWart ): - soil = (materials.SoulSand,0) + # choose an appropriate soil + soil = (materials.Dirt, 0) + if(crop[0] == materials.NetherWart): + soil = (materials.SoulSand, 0) - #torches if it needs it to survive + # torches if it needs it to survive needsLight = 0 - if( crop[0] == materials.Fern or crop[0] == materials.DeadBush - or crop[0] == materials.TallGrass ): + if(crop[0] == materials.Fern or crop[0] == materials.DeadBush + or crop[0] == materials.TallGrass): needsLight = 1 - for x in xrange(6): for z in xrange(6): - p = loc.trans(x,0,z) - if( random.randint(0, 100) < 40 ): + p = loc.trans(x, 0, z) + if(random.randint(0, 100) < 40): sb(p, crop[0], crop[1]) sb(p.down(1), soil[0], soil[1]) - if( x == 0 or x == 5 or z == 0 or z == 5 ): - sb(p, materials.Fence, 0 ) + if(x == 0 or x == 5 or z == 0 or z == 5): + sb(p, materials.Fence, 0) - if( needsLight == 1 ): - sb( loc.trans(0,-1,5), materials.Torch, 5) - sb( loc.trans(5,-1,5), materials.Torch, 5) - sb( loc.trans(5,-1,0), materials.Torch, 5) - sb( loc.trans(0,-1,0), materials.Torch, 5) + if(needsLight == 1): + sb(loc.trans(0, -1, 5), materials.Torch, 5) + sb(loc.trans(5, -1, 5), materials.Torch, 5) + sb(loc.trans(5, -1, 0), materials.Torch, 5) + sb(loc.trans(0, -1, 0), materials.Torch, 5) # Add some gates - sb(loc.trans(2,0,0), materials.FenceGate, 0) - sb(loc.trans(2,0,5), materials.FenceGate, 0) + sb(loc.trans(2, 0, 0), materials.FenceGate, 0) + sb(loc.trans(2, 0, 5), materials.FenceGate, 0) class WildGrowth(Farm): @@ -2078,26 +2102,26 @@ class WildGrowth(Farm): grassPercentage = 15 # format: mat, block val, top block val (tall flowers only) flowers = [ - ((materials.Air, 0) ,80), - ((materials.Poppy, 0) ,4), - ((materials.BlueOrchid, 1) ,4), - ((materials.Allium, 2) ,4), - ((materials.AzureBluet, 3) ,4), - ((materials.RedTulip, 4) ,1), - ((materials.OrangeTulip, 5) ,1), - ((materials.WhiteTulip, 6) ,1), - ((materials.PinkTulip, 7) ,1), - ((materials.OxeyeDaisy, 8) ,4), - ((materials.Dandelion, 0) ,4), - ((materials.Lilac, 1, 10) ,4), - ((materials.RoseBush, 4, 11) ,4), - ((materials.Peony, 5, 8) ,4), - ((materials.Fern, 2) ,40), - ((materials.DeadBush, 0) ,40), - ((materials.TallGrass, 1) ,40), - ((materials.DoubleTallGrass, 3, 8) ,40), - ((materials.DoubleFern, 2, 11) ,40) - #(materials.Sunflower, 0, 10), #Doesn't look right underground + ((materials.Air, 0), 80), + ((materials.Poppy, 0), 4), + ((materials.BlueOrchid, 1), 4), + ((materials.Allium, 2), 4), + ((materials.AzureBluet, 3), 4), + ((materials.RedTulip, 4), 1), + ((materials.OrangeTulip, 5), 1), + ((materials.WhiteTulip, 6), 1), + ((materials.PinkTulip, 7), 1), + ((materials.OxeyeDaisy, 8), 4), + ((materials.Dandelion, 0), 4), + ((materials.Lilac, 1, 10), 4), + ((materials.RoseBush, 4, 11), 4), + ((materials.Peony, 5, 8), 4), + ((materials.Fern, 2), 40), + ((materials.DeadBush, 0), 40), + ((materials.TallGrass, 1), 40), + ((materials.DoubleTallGrass, 3, 8), 40), + ((materials.DoubleFern, 2, 11), 40) + # (materials.Sunflower, 0, 10), #Doesn't look right underground ] def plant(self, locs): @@ -2106,14 +2130,14 @@ def plant(self, locs): for loc in locs: for x in xrange(6): for z in xrange(6): - p = loc.trans(x,0,z) - if( random.randint(0, 100) < 45 ): + p = loc.trans(x, 0, z) + if(random.randint(0, 100) < 45): flower = weighted_choice(self.flowers) sb(p, flower[0], flower[1]) if (len(flower) > 2): # tall flower sb(p.up(1), flower[0], flower[2]) # Place dirt/grass only under flowers - if( random.randint(0, 100) < self.grassPercentage ): + if(random.randint(0, 100) < self.grassPercentage): sb(p.down(1), materials.Grass, 0) else: sb(p.down(1), materials.Dirt, 1) # No grass dirt @@ -2122,51 +2146,51 @@ def plant(self, locs): sz = self.parent.size.z * self.parent.parent.room_size sy = self.parent.size.y * self.parent.parent.room_height - c1 = self.parent.loc + Vec(0,0,0) - c3 = c1 + Vec(sx-1, sy-2, sz-1) + c1 = self.parent.loc + Vec(0, 0, 0) + c3 = c1 + Vec(sx - 1, sy - 2, sz - 1) for p in iterate_cube(c1, c3): - if random.randint(1,100) <= 20: + if random.randint(1, 100) <= 20: self.parent.parent.vines(p, grow=True) class WildGarden(WildGrowth): _name = 'wildgarden' - + grassPercentage = 45 # format: mat, block val, top block val (tall flowers only) flowers = [ - ((materials.Air, 0) ,20), - ((materials.Poppy, 0) ,4), - ((materials.BlueOrchid, 1) ,4), - ((materials.Allium, 2) ,4), - ((materials.AzureBluet, 3) ,4), - ((materials.RedTulip, 4) ,1), - ((materials.OrangeTulip, 5) ,1), - ((materials.WhiteTulip, 6) ,1), - ((materials.PinkTulip, 7) ,1), - ((materials.OxeyeDaisy, 8) ,4), - ((materials.Dandelion, 0) ,4), - ((materials.Lilac, 1, 10) ,4), - ((materials.RoseBush, 4, 11) ,4), - ((materials.Peony, 5, 8) ,4), - ((materials.Fern, 2) ,2), - ((materials.TallGrass, 1) ,2), - ((materials.DoubleTallGrass, 3, 8) ,2), - ((materials.DoubleFern, 2, 11) ,2) - #(materials.Sunflower, 0, 10), #Doesn't look right underground + ((materials.Air, 0), 20), + ((materials.Poppy, 0), 4), + ((materials.BlueOrchid, 1), 4), + ((materials.Allium, 2), 4), + ((materials.AzureBluet, 3), 4), + ((materials.RedTulip, 4), 1), + ((materials.OrangeTulip, 5), 1), + ((materials.WhiteTulip, 6), 1), + ((materials.PinkTulip, 7), 1), + ((materials.OxeyeDaisy, 8), 4), + ((materials.Dandelion, 0), 4), + ((materials.Lilac, 1, 10), 4), + ((materials.RoseBush, 4, 11), 4), + ((materials.Peony, 5, 8), 4), + ((materials.Fern, 2), 2), + ((materials.TallGrass, 1), 2), + ((materials.DoubleTallGrass, 3, 8), 2), + ((materials.DoubleFern, 2, 11), 2) + # (materials.Sunflower, 0, 10), #Doesn't look right underground ] class Chapel(Blank): _name = 'chapel' - decos = ( (materials.Cauldron, 2) , - (materials.BlockOfRedstone, 0), - (materials.Torch, 0), - (materials.Chest, 5), - (materials.CraftingTable, 0) ) + decos = ((materials.Cauldron, 2), + (materials.BlockOfRedstone, 0), + (materials.Torch, 0), + (materials.Chest, 5), + (materials.CraftingTable, 0)) def render(self): if (self.parent.canvasWidth() < 8 or self.parent.canvasLength() < 8): @@ -2174,20 +2198,20 @@ def render(self): # Choose a carpet color # (Exclude some of the gaudier colours, e.g. pinks) - carpetColor = random.choice([0,1,3,7,8,9,10,11,12,13,14,15]) + carpetColor = random.choice([0, 1, 3, 7, 8, 9, 10, 11, 12, 13, 14, 15]) sb = self.parent.parent.setblock center = self.parent.canvasCenter() o = self.parent.loc.trans(center.x, - self.parent.canvasHeight()-1, - center.z+1) + self.parent.canvasHeight() - 1, + center.z + 1) # Adjust size for stairs and entrances. # If it's a bigroom, add more cells. stairs = self.parent.parent.stairwells p = self.parent.pos - y = self.parent.size.y-1 + y = self.parent.size.y - 1 N_margin = 1 S_margin = 1 E_margin = 3 @@ -2195,78 +2219,85 @@ def render(self): carpet_pos = -1 # 2x1 rooms we may shrink on X if (self.parent.size.x == 2 and self.parent.size.z == 1): - if(p+Vec(0,y,0) in stairs or - p+Vec(0,y+1,0) in stairs): + if(p + Vec(0, y, 0) in stairs or + p + Vec(0, y + 1, 0) in stairs): W_margin += 8 - if(p+Vec(1,y,0) in stairs or - p+Vec(1,y+1,0) in stairs): + if(p + Vec(1, y, 0) in stairs or + p + Vec(1, y + 1, 0) in stairs): E_margin += 8 # 1x2 rooms may shrink on Z elif (self.parent.size.x == 1 and self.parent.size.z == 2): - if(p+Vec(0,y,0) in stairs or - p+Vec(0,y+1,0) in stairs): + if(p + Vec(0, y, 0) in stairs or + p + Vec(0, y + 1, 0) in stairs): N_margin += 8 carpet_pos += 4 - if(p+Vec(0,y,1) in stairs or - p+Vec(0,y+1,1) in stairs): + if(p + Vec(0, y, 1) in stairs or + p + Vec(0, y + 1, 1) in stairs): S_margin += 8 carpet_pos -= 4 # 2x2 rooms may shrink on Z elif (self.parent.size.z == 2): - if(p+Vec(0,y,0) in stairs or - p+Vec(0,y+1,0) in stairs or - p+Vec(1,y,0) in stairs or - p+Vec(1,y+1,0) in stairs): + if(p + Vec(0, y, 0) in stairs or + p + Vec(0, y + 1, 0) in stairs or + p + Vec(1, y, 0) in stairs or + p + Vec(1, y + 1, 0) in stairs): N_margin += 8 carpet_pos += 4 - if(p+Vec(0,y,1) in stairs or - p+Vec(0,y+1,1) in stairs or - p+Vec(1,y,1) in stairs or - p+Vec(1,y+1,1) in stairs): + if(p + Vec(0, y, 1) in stairs or + p + Vec(0, y + 1, 1) in stairs or + p + Vec(1, y, 1) in stairs or + p + Vec(1, y + 1, 1) in stairs): S_margin += 8 carpet_pos -= 4 - #pews - for x in xrange( -1 * self.parent.canvasWidth()/2 + W_margin , - self.parent.canvasWidth()/2 - E_margin, 1): - for z in xrange( -1 * self.parent.canvasLength()/2 + N_margin , - self.parent.canvasLength()/2 - S_margin , 1): - p = o.trans(x,0,z) - if( z == carpet_pos or z == carpet_pos+1 ): + # pews + for x in xrange(-1 * self.parent.canvasWidth() / 2 + W_margin, + self.parent.canvasWidth() / 2 - E_margin, 1): + for z in xrange(-1 * self.parent.canvasLength() / 2 + N_margin, + self.parent.canvasLength() / 2 - S_margin, 1): + p = o.trans(x, 0, z) + if(z == carpet_pos or z == carpet_pos + 1): sb(p.down(1), materials.Wool, carpetColor) sb(p, materials.WhiteCarpet, carpetColor) - elif( x % 2 == 0): + elif(x % 2 == 0): sb(p, - materials.OakWoodStairs, 1) + materials.OakWoodStairs, 1) - #carpet continues in front of pews - for x in xrange( self.parent.canvasWidth()/2 - E_margin, - self.parent.canvasWidth()/2 - E_margin + 3, 1): - for z in xrange( carpet_pos, carpet_pos+2 , 1): - p = o.trans(x,0,z) + # carpet continues in front of pews + for x in xrange(self.parent.canvasWidth() / 2 - E_margin, + self.parent.canvasWidth() / 2 - E_margin + 3, 1): + for z in xrange(carpet_pos, carpet_pos + 2, 1): + p = o.trans(x, 0, z) sb(p.down(1), materials.Wool, carpetColor) sb(p, materials.WhiteCarpet, carpetColor) - #altar and deco deco = random.choice(self.decos) mats = [ - (materials.Air, 0), # 0 - deco, # 1 - (materials.StoneBrickStairs, 6), # 2 - (materials.StoneBrickStairs, 7) # 3 + (materials.Air, 0), # 0 + deco, # 1 + (materials.StoneBrickStairs, 6), # 2 + (materials.StoneBrickStairs, 7) # 3 ] - template = [1,0,2,3,0,1] + template = [1, 0, 2, 3, 0, 1] for z in xrange(6): - p = o.trans(self.parent.canvasWidth()/2 -1,0, z+carpet_pos-2) - sb(p, - mats[template[z]][0], - mats[template[z]][1]) + p = o.trans( + self.parent.canvasWidth() / + 2 - + 1, + 0, + z + + carpet_pos - + 2) + sb(p, + mats[template[z]][0], + mats[template[z]][1]) + class ConstructionArea(Blank): _name = 'constructionarea' @@ -2278,15 +2309,15 @@ def render(self): sb = self.parent.parent.setblock gb = self.parent.parent.getblock pn = perlin.SimplexNoise(256) - loc = self.parent.loc+Vec(0,-1,0) + loc = self.parent.loc + Vec(0, -1, 0) # Replace some wall sections with wooden "rebar" - for x in xrange(self.parent.parent.room_size*self.parent.size.x): - for z in xrange(self.parent.parent.room_size*self.parent.size.z): - for y in xrange(self.parent.parent.room_height*self.parent.size.y-3): - p = self.parent.loc.trans(x,y,z) + Vec(0,1,0) + for x in xrange(self.parent.parent.room_size * self.parent.size.x): + for z in xrange(self.parent.parent.room_size * self.parent.size.z): + for y in xrange(self.parent.parent.room_height * self.parent.size.y - 3): + p = self.parent.loc.trans(x, y, z) + Vec(0, 1, 0) if (gb(p) == materials._wall and - pn.noise3(p.x/4.0, (p.y+1337)/4.0, p.z/4.0) < 0): + pn.noise3(p.x / 4.0, (p.y + 1337) / 4.0, p.z / 4.0) < 0): sb(p, materials.Fence) elif (gb(p) == materials.Torch): sb(p, materials.Air) @@ -2299,30 +2330,30 @@ def render(self): # If it's a big room we may need to mask off areas. stairs = self.parent.parent.stairwells p = self.parent.pos - y = self.parent.size.y-1 + y = self.parent.size.y - 1 # NW - if(p+Vec(0,y,0) in stairs or - p+Vec(0,y+1,0) in stairs): - canvas = canvas - set(iterate_cube(Vec(0,y_level,0), - Vec(15,y_level,15))) + if(p + Vec(0, y, 0) in stairs or + p + Vec(0, y + 1, 0) in stairs): + canvas = canvas - set(iterate_cube(Vec(0, y_level, 0), + Vec(15, y_level, 15))) if(self.parent.size.x == 2): - if(p+Vec(1,y,0) in stairs or - p+Vec(1,y+1,0) in stairs): - canvas = canvas - set(iterate_cube(Vec(16,y_level,0), - Vec(32,y_level,15))) + if(p + Vec(1, y, 0) in stairs or + p + Vec(1, y + 1, 0) in stairs): + canvas = canvas - set(iterate_cube(Vec(16, y_level, 0), + Vec(32, y_level, 15))) if(self.parent.size.z == 2): - if(p+Vec(0,y,1) in stairs or - p+Vec(0,y+1,1) in stairs): - canvas = canvas - set(iterate_cube(Vec(0,y_level,16), - Vec(15,y_level,32))) + if(p + Vec(0, y, 1) in stairs or + p + Vec(0, y + 1, 1) in stairs): + canvas = canvas - set(iterate_cube(Vec(0, y_level, 16), + Vec(15, y_level, 32))) if(self.parent.size.x == 2 and self.parent.size.z == 2): - if(p+Vec(1,y,1) in stairs or - p+Vec(1,y+1,1) in stairs): - canvas = canvas - set(iterate_cube(Vec(16,y_level,32), - Vec(16,y_level,32))) + if(p + Vec(1, y, 1) in stairs or + p + Vec(1, y + 1, 1) in stairs): + canvas = canvas - set(iterate_cube(Vec(16, y_level, 32), + Vec(16, y_level, 32))) # A few crafting tables - num = int(area / 128)+1 + num = int(area / 128) + 1 if num > 0: for x in xrange(num): p = random.choice(list(canvas)) @@ -2331,7 +2362,7 @@ def render(self): sb(p.down(1) + loc, materials._floor) # Some piles of wall blocks - num = int(area / 128)+2 + num = int(area / 128) + 2 if num > 0: for x in xrange(num): p = random.choice(list(canvas)) @@ -2340,7 +2371,7 @@ def render(self): sb(p.down(1) + loc, materials._floor) # Some supply chests - num = int(area / 256)+1 + num = int(area / 256) + 1 if num > 0: for x in xrange(num): p = random.choice(list(canvas)) @@ -2348,7 +2379,7 @@ def render(self): sb(p + loc, materials.Chest) sb(p.down(1) + loc, materials._floor) - #item, probability, max stack amount + # item, probability, max stack amount supply_items = [(items.byName('wooden pickaxe'), 1, 1), (items.byName('stone pickaxe'), .5, 1), (items.byName('iron pickaxe'), .1, 1), @@ -2371,8 +2402,15 @@ def render(self): supplyloot = [] for s in supply_items: if (random.random() < s[1]): - amount = random.randint(1,min(s[2],s[0].maxstack)) - supplyloot.append(loottable.Loot(len(supplyloot),amount,s[0].value,s[0].data,'',flag=s[0].flag)) + amount = random.randint(1, min(s[2], s[0].maxstack)) + supplyloot.append( + loottable.Loot( + len(supplyloot), + amount, + s[0].value, + s[0].data, + '', + flag=s[0].flag)) self.parent.parent.addchest(p + loc, loot=supplyloot) # Rarely, a damaged anvil @@ -2383,85 +2421,85 @@ def render(self): sb(p.down(1) + loc, materials._floor) # Some random lumber - num = int(area / 128)+2 + num = int(area / 128) + 2 trys = 0 while (num > 0 and trys < 100): trys += 1 p = random.choice(list(canvas)) - d = random.choice([Vec(1,0,0), Vec(0,0,1)]) + d = random.choice([Vec(1, 0, 0), Vec(0, 0, 1)]) # Make sure we have room for this log - if (p+d not in canvas or - p+d*2 not in canvas): + if (p + d not in canvas or + p + d * 2 not in canvas): continue data = 4 - if d == Vec(0,0,1): + if d == Vec(0, 0, 1): data = 8 num -= 1 canvas.remove(p) - canvas.remove(p+d) - canvas.remove(p+d*2) + canvas.remove(p + d) + canvas.remove(p + d * 2) sb(p + loc, materials.Wood, data) sb(p.down(1) + loc, materials._floor) sb(p + d + loc, materials.Wood, data) sb(p.down(1) + d + loc, materials._floor) - sb(p + d*2 + loc, materials.Wood, data) - sb(p.down(1) + d*2 + loc, materials._floor) + sb(p + d * 2 + loc, materials.Wood, data) + sb(p.down(1) + d * 2 + loc, materials._floor) # maybe stack them if (random.random() < .5): - p += Vec(0,-1,0) + p += Vec(0, -1, 0) sb(p + loc, materials.Wood, data) sb(p + d + loc, materials.Wood, data) - sb(p + d*2 + loc, materials.Wood, data) + sb(p + d * 2 + loc, materials.Wood, data) # Scaffolding - num = int(area / 128)+1 + num = int(area / 128) + 1 trys = 0 while (num > 0 and trys < 100): trys += 1 p = random.choice(list(canvas)) - d = [Vec(1,0,0), Vec(0,0,1), Vec(1,0,1), - Vec(0,0,-1), Vec(1,0,-1), - Vec(0,0,2), Vec(1,0,2), - Vec(2,0,0), Vec(2,0,1), - Vec(-1,0,0), Vec(-1,0,1), - Vec(0,0,0)] + d = [Vec(1, 0, 0), Vec(0, 0, 1), Vec(1, 0, 1), + Vec(0, 0, -1), Vec(1, 0, -1), + Vec(0, 0, 2), Vec(1, 0, 2), + Vec(2, 0, 0), Vec(2, 0, 1), + Vec(-1, 0, 0), Vec(-1, 0, 1), + Vec(0, 0, 0)] # Make sure we have room for this scaffold # Check that all offsets are a subset of the remaining canvas. # The extra offsets are to allow for a one block space near the # scaffold so the fence blocks don't try to connect to anything. - # Plus it just looks better to have some spacing. - if (set([p+x for x in d]) <= canvas) is False: + # Plus it just looks better to have some spacing. + if (set([p + x for x in d]) <= canvas) is False: continue num -= 1 canvas.remove(p) - canvas.remove(p+d[0]) - canvas.remove(p+d[1]) - canvas.remove(p+d[2]) - p += Vec(0,1,0) + canvas.remove(p + d[0]) + canvas.remove(p + d[1]) + canvas.remove(p + d[2]) + p += Vec(0, 1, 0) sb(p + loc, materials._floor) sb(p + d[0] + loc, materials._floor) sb(p + d[1] + loc, materials._floor) sb(p + d[2] + loc, materials._floor) - p += Vec(0,-1,0) + p += Vec(0, -1, 0) sb(p + loc, materials.Fence) sb(p + d[0] + loc, materials.Fence) sb(p + d[1] + loc, materials.Fence) sb(p + d[2] + loc, materials.Fence) - p += Vec(0,-1,0) + p += Vec(0, -1, 0) sb(p + loc, materials.Fence) sb(p + d[0] + loc, materials.Fence) sb(p + d[1] + loc, materials.Fence) sb(p + d[2] + loc, materials.Fence) - p += Vec(0,-1,0) + p += Vec(0, -1, 0) sb(p + loc, materials.OakWoodSlab) sb(p + d[0] + loc, materials.OakWoodSlab) sb(p + d[1] + loc, materials.OakWoodSlab) sb(p + d[2] + loc, materials.OakWoodSlab) -# Catalog the features we know about. +# Catalog the features we know about. _features = {} # List of classes in this module. for name, obj in inspect.getmembers(sys.modules[__name__], inspect.isclass): @@ -2469,7 +2507,8 @@ def render(self): if issubclass(obj, Blank): _features[obj._name] = obj -def new (name, parent): + +def new(name, parent): '''Return a new instance of the feature of a given name. Supply the parent dungeon object.''' if name in _features.keys(): diff --git a/floors.py b/floors.py index 899a0ad1..cf30bf25 100644 --- a/floors.py +++ b/floors.py @@ -27,7 +27,7 @@ def render(self): if (utils.sum_points_inside_flat_poly(*self.parent.canvas) <= 4): return for x in utils.iterate_points_inside_flat_poly(*self.parent.canvas): - self.parent.parent.setblock(x+self.parent.loc, self.mat) + self.parent.parent.setblock(x + self.parent.loc, self.mat) # Ruined if (self.ruin is False): return @@ -37,9 +37,9 @@ def render(self): maxd = max(1, self.parent.canvasWidth(), self.parent.canvasLength()) pn = perlin.SimplexNoise(256) for x in utils.iterate_points_inside_flat_poly(*self.parent.canvas): - p = x+self.parent.loc + 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 + n = (pn.noise3((p.x + r) / 4.0, y / 4.0, p.z / 4.0) + 1.0) / 2.0 if (n < d): self.parent.parent.setblock(p, materials._floor) self.parent.parent.blocks[p].data = 0 @@ -70,7 +70,7 @@ class StoneTile(Blank): (materials.Granite, materials.PolishedGranite), (materials.Diorite, materials.PolishedDiorite), (materials.Andesite, materials.PolishedAndesite) - ) + ) def render(self): mat = random.choice(self.stonetypes) @@ -78,10 +78,10 @@ def render(self): for x in utils.iterate_points_inside_flat_poly( *self.parent.canvas ): - if ((x.x+x.z) & 1 == 1): - self.parent.parent.setblock(x+self.parent.loc, mat[0]) + if ((x.x + x.z) & 1 == 1): + self.parent.parent.setblock(x + self.parent.loc, mat[0]) else: - self.parent.parent.setblock(x+self.parent.loc, mat[1]) + self.parent.parent.setblock(x + self.parent.loc, mat[1]) # Ruined if (self.ruin is False): return @@ -91,9 +91,9 @@ def render(self): maxd = max(1, self.parent.canvasWidth(), self.parent.canvasLength()) pn = perlin.SimplexNoise(256) for x in utils.iterate_points_inside_flat_poly(*self.parent.canvas): - p = x+self.parent.loc + 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 + n = (pn.noise3((p.x + r) / 4.0, y / 4.0, p.z / 4.0) + 1.0) / 2.0 if (n < d): self.parent.parent.setblock(p, materials._floor) self.parent.parent.blocks[p].data = 0 @@ -112,11 +112,11 @@ def render(self): for x in utils.iterate_points_inside_flat_poly( *self.parent.canvas ): - if ((x.x+x.z) & 1 == 1): - self.parent.parent.setblock(x+self.parent.loc, + if ((x.x + x.z) & 1 == 1): + self.parent.parent.setblock(x + self.parent.loc, materials.Wood) else: - self.parent.parent.setblock(x+self.parent.loc, + self.parent.parent.setblock(x + self.parent.loc, materials.OakWoodPlanks) @@ -129,7 +129,7 @@ class MixedWoodTile(Blank): materials.JungleWoodPlanks, materials.AcaciaWoodPlanks, materials.DarkOakWoodPlanks - ) + ) def render(self): wood = random.sample(self.woodtypes, 2) @@ -137,10 +137,10 @@ def render(self): for x in utils.iterate_points_inside_flat_poly( *self.parent.canvas ): - if ((x.x+x.z) & 1 == 1): - self.parent.parent.setblock(x+self.parent.loc, wood[0]) + if ((x.x + x.z) & 1 == 1): + self.parent.parent.setblock(x + self.parent.loc, wood[0]) else: - self.parent.parent.setblock(x+self.parent.loc, wood[1]) + self.parent.parent.setblock(x + self.parent.loc, wood[1]) class RadialRug(Blank): @@ -192,7 +192,7 @@ def render(self): next_dir = random.randint(0, 3) while len(points_left) > 0: # pick random starting point and walk around the matrix - point_index = random.randint(0, len(points_left)-1) + point_index = random.randint(0, len(points_left) - 1) p = Vec(points_left[point_index][0], 0, points_left[point_index][1]) @@ -223,16 +223,16 @@ def render(self): for j in xrange(max_z - min_z + 1): for i in xrange(max_x - min_x + 1): - p = self.parent.loc + Vec(min_x+i, min_y, min_z+j) + p = self.parent.loc + Vec(min_x + i, min_y, min_z + j) self.parent.parent.setblock(p, self.mat) if i < width: i_adj = i else: - i_adj = 2*width - 1 - i + i_adj = 2 * width - 1 - i if j < depth: j_adj = j else: - j_adj = 2*depth - 1 - j + j_adj = 2 * depth - 1 - j self.parent.parent.blocks[p].data = \ color_profile[points[i_adj][j_adj]] @@ -245,9 +245,9 @@ def render(self): 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 + 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 + n = (pn.noise3((p.x + r) / 4.0, y / 4.0, p.z / 4.0) + 1.0) / 2.0 if (n < d): self.parent.parent.setblock(p, materials._floor) self.parent.parent.blocks[p].data = 0 @@ -275,15 +275,15 @@ class CheckerRug(Blank): colors = ( (7, 8), # dark grey / light grey (9, 3), # cyan / light blue - #(14, 10), # red / purple + # (14, 10), # red / purple (11, 9), # dark blue / cyan (1, 14), # red / orange (7, 15), # dark grey / black - #(3, 4), # light blue / yellow + # (3, 4), # light blue / yellow (11, 10), # dark blue / purple (12, 13), # brown / dark green (15, 13), # black / dark green - ) + ) mat = materials.Wool def render(self): @@ -291,12 +291,12 @@ def render(self): return color = random.choice(self.colors) for x in utils.iterate_points_inside_flat_poly(*self.parent.canvas): - self.parent.parent.setblock(x+self.parent.loc, + self.parent.parent.setblock(x + self.parent.loc, self.mat) - if ((x.x+x.z) & 1 == 1): - self.parent.parent.blocks[x+self.parent.loc].data = color[0] + if ((x.x + x.z) & 1 == 1): + self.parent.parent.blocks[x + self.parent.loc].data = color[0] else: - self.parent.parent.blocks[x+self.parent.loc].data = color[1] + self.parent.parent.blocks[x + self.parent.loc].data = color[1] # Runined if (self.ruin is False): return @@ -306,9 +306,9 @@ def render(self): 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 + 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 + n = (pn.noise3((p.x + r) / 4.0, y / 4.0, p.z / 4.0) + 1.0) / 2.0 if (n < d): self.parent.parent.setblock(p, materials._floor) self.parent.parent.blocks[p].data = 0 @@ -338,7 +338,7 @@ def render(self): if (utils.sum_points_inside_flat_poly(*self.parent.canvas) <= 4): return for x in utils.iterate_points_inside_flat_poly(*self.parent.canvas): - self.parent.parent.setblock(x+self.parent.loc, + self.parent.parent.setblock(x + self.parent.loc, materials.StoneDoubleSlab) # Runined pn = perlin.SimplexNoise(256) @@ -349,9 +349,9 @@ def render(self): 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 + 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 + n = (pn.noise3((p.x + r) / 4.0, y / 4.0, p.z / 4.0) + 1.0) / 2.0 if (n < d): self.parent.parent.setblock(p, materials._floor) self.parent.parent.blocks[p].data = 0 @@ -374,17 +374,17 @@ def render(self): 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 + 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+.50): + n = (pn.noise3((p.x + r) / 4.0, y / 4.0, p.z / 4.0) + 1.0) / 2.0 + if (n >= d + .50): self.parent.parent.setblock(p, materials.Water) - elif (n >= d+.30): + elif (n >= d + .30): self.parent.parent.setblock(p, materials.SoulSand) - elif (n >= d+.20): + elif (n >= d + .20): self.parent.parent.setblock(p, materials.Farmland) self.parent.parent.blocks[p].data = random.randint(0, 1) - elif (n >= d+.10): + elif (n >= d + .10): self.parent.parent.setblock(p, materials.Podzol) self.parent.parent.blocks[p].data = 2 # Podzol data val elif (n >= d): @@ -403,12 +403,12 @@ def render(self): 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 + 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+.20): + n = (pn.noise3((p.x + r) / 4.0, y / 4.0, p.z / 4.0) + 1.0) / 2.0 + if (n >= d + .20): self.parent.parent.setblock(p, materials.Sand) - elif (n >= d+.10): + elif (n >= d + .10): self.parent.parent.setblock(p, materials.Sandstone) elif (n >= d): self.parent.parent.setblock(p, materials.Gravel) @@ -424,7 +424,7 @@ class Bridges(Blank): materials.JungleWoodSlab, materials.AcaciaWoodSlab, materials.DarkOakWoodSlab - ) + ) def render(self): pn = perlin.SimplexNoise(256) @@ -482,12 +482,12 @@ def render(self): h0 = Vec(x1, y, self.parent.hallLength[0]) - h1 = Vec(self.parent.parent.room_size-self.parent.hallLength[1]-1, + 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) + self.parent.parent.room_size - self.parent.hallLength[2] - 1) h3 = Vec(self.parent.hallLength[3], y, z2) @@ -505,10 +505,14 @@ def render(self): for x in utils.iterate_points_inside_flat_poly( *self.parent.canvas ): - p = x+self.parent.loc + 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): + 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) @@ -518,58 +522,58 @@ def render(self): # 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, + 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: + # if x == 0: # wirehooks.add((p, 4+3)) - #elif x == self.parent.halls[0].size-1: + # elif x == self.parent.halls[0].size-1: # wirehooks.add((p, 4+1)) - #else: + # else: # wires.add(p) wires.add(p) # h1 if (halls[1] != 0): - for x in xrange(1, self.parent.halls[1].size-1): + 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 + 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): + for x in xrange(1, self.parent.halls[2].size - 1): wires.add( Vec( - self.parent.halls[2].offset+x, - y-1, + self.parent.halls[2].offset + x, + y - 1, (self.parent.parent.room_size - - self.parent.hallLength[2]-1) + self.parent.hallLength[2] - 1) ) ) # h3 if (halls[3] != 0): - for x in xrange(1, self.parent.halls[3].size-1): + 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 + y - 1, + self.parent.halls[3].offset + x ) ) for p in wires: self.parent.parent.setblock( - offset+p.down(1), + offset + p.down(1), materials.Gravel, lock=True ) - self.parent.parent.setblock(offset+p, + self.parent.parent.setblock(offset + p, materials.Tripwire, hide=True) - #for p in wirehooks: + # 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]) @@ -579,26 +583,26 @@ def render(self): # h2 -> c3 # h3 -> c4 if (halls[0] != 0): - for p in utils.iterate_cube(offset+h0, offset+c1): + 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): + 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): + 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): + 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): + 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): + 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): + for p in utils.iterate_cube(offset + c3, offset + c4): self.parent.parent.setblock(p, mat) # Catalog the floors we know about. diff --git a/hall_traps.py b/hall_traps.py index 29860757..161622d4 100644 --- a/hall_traps.py +++ b/hall_traps.py @@ -98,7 +98,7 @@ def mark_hallway(self, mat): debugging.''' for p in iterate_cube( self.position, - self.position+self.dw*(self.size-1)+self.dl*(self.length-1) + self.position + self.dw * (self.size - 1) + self.dl * (self.length - 1) ): self.parent.setblock(p, mat) @@ -137,12 +137,13 @@ def render(self): # Commands cmds = { 'C1': '/summon {0} ~ ~3 ~1.8 {{Motion:{1},direction:{1},{2}}}'.format( - name, '[0.0,0.2,1.0]', data_tag - ), + 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 - ) - } + name, + '[0.0,0.2,-1.0]', + data_tag)} # If looking South, rotate some materials, and adjust the command # blocks. @@ -151,12 +152,13 @@ def render(self): 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 - ), + 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 - ) - } + name, + '[-1.0,0.2,0.0]', + data_tag)} # Trap template. # tmpl[level][dl][dw] @@ -178,8 +180,8 @@ def render(self): # Repetitions for each template row and column. reps = { - 'w': [1, 1, self.size-2, 1, 1], - 'l': [self.length-2], + 'w': [1, 1, self.size - 2, 1, 1], + 'l': [self.length - 2], } self.apply_template(tmpl, cmds, mat, reps, pos) @@ -187,7 +189,7 @@ def render(self): # 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) + self.position.down(5) + self.dw * (self.size - 1) + self.dl * (self.length - 1) ): if ( p in self.parent.blocks and @@ -212,7 +214,7 @@ class LavaTrap(Blank): def render(self): # Length of the actual trap door part. - tlength = self.length-8 + tlength = self.length - 8 # Materials lookup # Default is looking East @@ -223,10 +225,10 @@ def render(self): 'RB': [materials.BlockOfRedstone, 0], '-*': [materials.RedstoneTorchOn, 3], '*-': [materials.RedstoneTorchOn, 4], - 'P>': [materials.StickyPiston, 3+8], - '-|': [materials.PistonExtension, 3+8], - '': [materials.StickyPiston, 3 + 8], + '-|': [materials.PistonExtension, 3 + 8], + ''][1] = 5+8 - mat['-|'][1] = 5+8 - mat[''][1] = 5 + 8 + mat['-|'][1] = 5 + 8 + mat['= random.randint(1,100)): + if (loot['chance'] >= random.randint(1, 100)): amount = random.randint(loot['min'], loot['max']) item = random.choice(loot['item']) @@ -299,9 +303,10 @@ def rollLoot (tier, level): for e in item.ench.split(','): k = int(e.split('-')[0]) v = int(e.split('-')[-1]) - enchantments.append(dict({'id':k, 'lvl':v})) + enchantments.append(dict({'id': k, 'lvl': v})) elif 'level*' in loot['ench']: - ench_level = int(level*float(loot['ench'].split('level*')[-1])) + ench_level = int( + level * float(loot['ench'].split('level*')[-1])) ench_level = max(1, ench_level) elif '-' in loot['ench']: min_ench = int(loot['ench'].split('-')[0]) @@ -345,7 +350,8 @@ def rollLoot (tier, level): yield thisloot slot += 1 -def enchant (item, level, debug=False): + +def enchant(item, level, debug=False): # Based on the info available in the wiki as of 1.3.1: # http://www.minecraftwiki.net/wiki/Enchantment_Mechanics # @@ -363,11 +369,11 @@ def enchant (item, level, debug=False): # TAG_Compound(): # TAG_Short( "id" ): 17 # TAG_Short( "lvl" ): 5 - # + # # TAG_Compound(): # TAG_Short( "id" ): 19 # TAG_Short( "lvl" ): 2 - # + # # TAG_Compound(): # TAG_Short( "id" ): 20 # TAG_Short( "lvl" ): 2 @@ -461,8 +467,8 @@ def enchant (item, level, debug=False): def check_enchantment(ench, mlevel): for x in xrange(4, -1, -1): if (mlevel >= _ench_level[ench][x][0] and - mlevel <= _ench_level[ench][x][1]): - enchantments[ench] = x+1 + mlevel <= _ench_level[ench][x][1]): + enchantments[ench] = x + 1 prob.append((ench, _ench_prob[ench])) return return @@ -482,7 +488,7 @@ def check_enchantment(ench, mlevel): # is a match for the item type for (enchant, name) in _ench_name.items(): if (item_filter[enchant][0] == 'any' or - type in item_filter[enchant]): + type in item_filter[enchant]): check_enchantment(enchant, mlevel) # Item did not result in any enchantments @@ -505,15 +511,15 @@ def check_enchantment(ench, mlevel): # Add it. final[ench] = enchantments[ench] if (type == 'book'): - break; + break # Remove it so we don't pick again. prob.remove((ench, _ench_prob[ench])) # Some enchantments conflict with each other. If we picked one, remove - # its counterparts. + # its counterparts. if ench in [PROTECTION, FIRE_PROTECTION, BLAST_PROTECTION, PROJECTILE_PROTECTION]: for x in [PROTECTION, FIRE_PROTECTION, - BLAST_PROTECTION,PROJECTILE_PROTECTION]: + BLAST_PROTECTION, PROJECTILE_PROTECTION]: if (x, _ench_prob[x]) in prob: prob.remove((x, _ench_prob[x])) @@ -526,7 +532,7 @@ def check_enchantment(ench, mlevel): break # Check for additional enchantments mlevel /= 2 - if random.randint(1,50) > mlevel+1: + if random.randint(1, 50) > mlevel + 1: break if debug is True: @@ -535,17 +541,19 @@ def check_enchantment(ench, mlevel): print '\t', _ench_name[k], _level_name[v] for k, v in final.items(): - yield dict({'id':k, 'lvl':v}) + yield dict({'id': k, 'lvl': v}) + -def enchant_tags (item, level, debug=False): +def enchant_tags(item, level, debug=False): tags = nbt.TAG_List() - for ench in enchant(item, level, debug): + for ench in enchant(item, level, debug): e = nbt.TAG_Compound() e['id'] = nbt.TAG_Short(ench['id']) e['lvl'] = nbt.TAG_Short(ench['lvl']) tags.append(e) return tags + def print_enchant(item, level, debug=True): for ench in enchant(item, level, debug): if debug is not True: diff --git a/mapstore.py b/mapstore.py index 6e5c3516..11ca5100 100644 --- a/mapstore.py +++ b/mapstore.py @@ -18,20 +18,25 @@ import shutil import hashlib -from numpy import array, uint8, zeros, fromstring +from numpy import array, uint8, zeros, fromstring from pymclevel import nbt from utils import Vec import materials + class new: + def __init__(self, mapstore, dir_paintings='paintings'): self.mapstore = os.path.join(mapstore, 'data') # Load the idcounts.dat NBT if it exists, otherwise make - # a new one. + # a new one. try: - self.idcounts = nbt.load(os.path.join(self.mapstore, 'idcounts.dat')) + self.idcounts = nbt.load( + os.path.join( + self.mapstore, + 'idcounts.dat')) except: print 'No idcounts.dat file found. Creating a new one...' self.idcounts = nbt.TAG_Compound() @@ -40,7 +45,7 @@ def __init__(self, mapstore, dir_paintings='paintings'): if (os.path.isfile(os.path.join(self.mapstore, 'mcdungeon_maps'))): try: with open(os.path.join(self.mapstore, 'mcdungeon_maps'), 'rb') as FILE: - self.mapcache = cPickle.load(FILE) + self.mapcache = cPickle.load(FILE) except Exception as e: print e sys.exit('Failed to read the mcdungeon maps cache file.') @@ -52,14 +57,19 @@ def __init__(self, mapstore, dir_paintings='paintings'): self.maphash = {} for file in os.listdir(self.mapstore): if (str(file.lower()).endswith(".dat") and - str(file.lower()).startswith("map_")): - #Gen hash and extract map ID - hash = hashlib.md5(open(os.path.join(self.mapstore,file), 'r').read()).digest() + str(file.lower()).startswith("map_")): + # Gen hash and extract map ID + hash = hashlib.md5( + open( + os.path.join( + self.mapstore, + file), + 'r').read()).digest() self.maphash[hash] = int(file[4:-4]) # Store paintings path - if os.path.isdir(os.path.join(sys.path[0],dir_paintings)): - self.painting_path = os.path.join(sys.path[0],dir_paintings) + if os.path.isdir(os.path.join(sys.path[0], dir_paintings)): + self.painting_path = os.path.join(sys.path[0], dir_paintings) elif os.path.isdir(dir_paintings): self.painting_path = dir_paintings else: @@ -89,7 +99,7 @@ def delete_maps(self, loc): if loc in self.mapcache['used']: self.mapcache['available'].update(self.mapcache['used'][loc]) for m in self.mapcache['used'][loc]: - f = os.path.join(self.mapstore, 'map_%d.dat'%(m)) + f = os.path.join(self.mapstore, 'map_%d.dat' % (m)) try: os.remove(f) except: @@ -100,7 +110,7 @@ def delete_maps(self, loc): print 'No maps found for dungeon at ', loc def add_painting(self, painting_file): - src = os.path.join(self.painting_path,painting_file+'.dat') + src = os.path.join(self.painting_path, painting_file + '.dat') painting_file_hash = hashlib.md5(open(src, 'r').read()).digest() # Look up file in hashtable if painting_file_hash in self.maphash: @@ -113,9 +123,9 @@ def add_painting(self, painting_file): self.idcounts['map'].value += 1 mapid = self.idcounts['map'].value # Copy the map to the data dir - dest = os.path.join(self.mapstore, 'map_%d.dat'%(mapid)) + dest = os.path.join(self.mapstore, 'map_%d.dat' % (mapid)) try: - shutil.copy(src,dest) + shutil.copy(src, dest) except: sys.exit('Error when placing painting in map directory.') self.maphash[painting_file_hash] = mapid # Update hashtable @@ -128,28 +138,34 @@ def add_painting(self, painting_file): item['Count'] = nbt.TAG_Byte(1) # Fetch the lore text for this map - lorefile = open(os.path.join(self.painting_path, painting_file+'.txt')) + lorefile = open( + os.path.join( + self.painting_path, + painting_file + + '.txt')) loredata = lorefile.read().splitlines() lorefile.close() - #Create NBT tag + # Create NBT tag valid_characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ " item['tag'] = nbt.TAG_Compound() item['tag']['display'] = nbt.TAG_Compound() - item['tag']['display']['Name'] = nbt.TAG_String(filter(lambda x: x in valid_characters, loredata.pop(0))) + item['tag']['display']['Name'] = nbt.TAG_String( + filter( + lambda x: x in valid_characters, + loredata.pop(0))) item['tag']['display']['Lore'] = nbt.TAG_List() - #Slice at 5 lines of 50 chars each + # Slice at 5 lines of 50 chars each for p in loredata[:5]: line = filter(lambda x: x in valid_characters, p) item['tag']['display']['Lore'].append(nbt.TAG_String(line[:50])) return item - def generate_map(self, dungeon, level): '''Generate a new map, save it to disk, flush the cache, and return a map item NBT with the appropriate map ID.''' - dungeon_key = '%s,%s'%(dungeon.position.x, dungeon.position.z) + dungeon_key = '%s,%s' % (dungeon.position.x, dungeon.position.z) if dungeon_key not in self.mapcache['used']: self.mapcache['used'][dungeon_key] = set([]) @@ -166,11 +182,12 @@ def generate_map(self, dungeon, level): else: mapid = self.mapcache['available'].pop() self.mapcache['used'][dungeon_key].add(mapid) - filename = os.path.join(self.mapstore, 'map_%d.dat'%(mapid)) + filename = os.path.join(self.mapstore, 'map_%d.dat' % (mapid)) # Setup the defaults. # Offset will be way off somewhere were players are unlikely to go - # to avoid the maps from being overwritten. Nothing else really matters. + # to avoid the maps from being overwritten. Nothing else really + # matters. tags = nbt.TAG_Compound() tags['data'] = nbt.TAG_Compound() tags['data']['scale'] = nbt.TAG_Byte(0) @@ -181,17 +198,17 @@ def generate_map(self, dungeon, level): tags['data']['dimension'] = nbt.TAG_Byte(0) tags['data']['colors'] = nbt.TAG_Byte_Array(zeros(16384, uint8)) - # Generate the map. + # Generate the map. blocks = dungeon.blocks colors = tags['data']['colors'].value y = level * dungeon.room_height - 3 # Scale the map. We only scale up, not down since scaling - # looks terrible. + # looks terrible. max_dungeon = max(dungeon.xsize * dungeon.room_size, dungeon.zsize * dungeon.room_size) max_dungeon = max(128, max_dungeon) - # If the size is less than 8, try to center it. + # If the size is less than 8, try to center it. xoffset = 0 zoffset = 0 if dungeon.xsize * dungeon.room_size < 128: @@ -201,82 +218,82 @@ def generate_map(self, dungeon, level): # Draw pixels on the map corresponding to blocks just above # floor level. Color chests and spawners. Hide things that should be - # hidden. + # hidden. for x in xrange(128): for z in xrange(128): - block = Vec(x*max_dungeon/128-xoffset, + block = Vec(x * max_dungeon / 128 - xoffset, y, - z*max_dungeon/128-zoffset) + z * max_dungeon / 128 - zoffset) if block in blocks: mat = blocks[block].material if mat == materials.StonePressurePlate: - colors[x+z*128] = 10 + colors[x + z * 128] = 10 elif blocks[block].hide is True: - colors[x+z*128] = 0 + colors[x + z * 128] = 0 elif mat == materials.Air: - colors[x+z*128] = 10 + colors[x + z * 128] = 10 elif mat == materials.Spawner: - colors[x+z*128] = 48 + colors[x + z * 128] = 48 elif (mat == materials.Chest or - mat == materials.TrappedChest): - colors[x+z*128] = 42 + mat == materials.TrappedChest): + colors[x + z * 128] = 42 else: - colors[x+z*128] = 54 + colors[x + z * 128] = 54 else: - colors[x+z*128] = 0 + colors[x + z * 128] = 0 # Draw the level number in the corner digits = [ - [ 0, 1, 0, - 1, 0, 1, - 1, 0, 1, - 1, 0, 1, - 0, 1, 0 ], - [ 0, 1, 0, - 1, 1, 0, - 0, 1, 0, - 0, 1, 0, - 1, 1, 1 ], - [ 1, 1, 1, - 0, 0, 1, - 1, 1, 1, - 1, 0, 0, - 1, 1, 1 ], - [ 1, 1, 0, - 0, 0, 1, - 0, 1, 0, - 0, 0, 1, - 1, 1, 0 ], - [ 1, 0, 1, - 1, 0, 1, - 1, 1, 1, - 0, 0, 1, - 0, 0, 1 ], - [ 1, 1, 1, - 1, 0, 0, - 1, 1, 1, - 0, 0, 1, - 1, 1, 1 ], - [ 0, 1, 1, - 1, 0, 0, - 1, 1, 1, - 1, 0, 1, - 1, 1, 1 ], - [ 1, 1, 1, - 0, 0, 1, - 0, 1, 0, - 0, 1, 0, - 0, 1, 0 ], - [ 1, 1, 1, - 1, 0, 1, - 1, 1, 1, - 1, 0, 1, - 1, 1, 1 ], - [ 1, 1, 1, - 1, 0, 1, - 1, 1, 1, - 0, 0, 1, - 1, 1, 1 ] + [0, 1, 0, + 1, 0, 1, + 1, 0, 1, + 1, 0, 1, + 0, 1, 0], + [0, 1, 0, + 1, 1, 0, + 0, 1, 0, + 0, 1, 0, + 1, 1, 1], + [1, 1, 1, + 0, 0, 1, + 1, 1, 1, + 1, 0, 0, + 1, 1, 1], + [1, 1, 0, + 0, 0, 1, + 0, 1, 0, + 0, 0, 1, + 1, 1, 0], + [1, 0, 1, + 1, 0, 1, + 1, 1, 1, + 0, 0, 1, + 0, 0, 1], + [1, 1, 1, + 1, 0, 0, + 1, 1, 1, + 0, 0, 1, + 1, 1, 1], + [0, 1, 1, + 1, 0, 0, + 1, 1, 1, + 1, 0, 1, + 1, 1, 1], + [1, 1, 1, + 0, 0, 1, + 0, 1, 0, + 0, 1, 0, + 0, 1, 0], + [1, 1, 1, + 1, 0, 1, + 1, 1, 1, + 1, 0, 1, + 1, 1, 1], + [1, 1, 1, + 1, 0, 1, + 1, 1, 1, + 0, 0, 1, + 1, 1, 1] ] sx = 120 if level < 10: @@ -285,8 +302,8 @@ def generate_map(self, dungeon, level): for d in str(level): for x in xrange(3): for z in xrange(5): - if digits[int(d)][x+z*3] == 1: - colors[x+sx+(z+sz)*128] = 16 + if digits[int(d)][x + z * 3] == 1: + colors[x + sx + (z + sz) * 128] = 16 sx += 4 # Save the map file, cache, and idcount.dat diff --git a/materials.py b/materials.py index c2ba0763..60a3e154 100644 --- a/materials.py +++ b/materials.py @@ -36,7 +36,7 @@ def valByName(name): '''Return a material block value given a name string.''' for oname, obj in sys.modules[__name__].__dict__.items(): - if type(obj) == Material: + if isinstance(obj, Material): if (obj.name.lower() == name): return obj.val return -1 @@ -126,7 +126,7 @@ def update(self, x, y, z, maxx, maxy, maxz): try: parser.readfp(open(filename)) -except Exception, e: +except Exception as e: print "Failed to read materials config file!" sys.exit(e.message) @@ -157,14 +157,14 @@ def update(self, x, y, z, maxx, maxy, maxz): # Create a convenience set of blockids for heightmap blocks. heightmap_solids = set() for oname, obj in sys.modules[__name__].__dict__.items(): - if type(obj) == Material: + if isinstance(obj, Material): if obj.heightmap is True: heightmap_solids.add(obj.val) # Create a convenience set of blockids for vine blocks. vine_solids = set() for oname, obj in sys.modules[__name__].__dict__.items(): - if type(obj) == Material: + if isinstance(obj, Material): if obj.attach_vines is True: vine_solids.add(obj.val) @@ -274,12 +274,12 @@ class meta_class_stonedungeon(MetaMaterial): def update(self, x, y, z, maxx, maxy, maxz): n = self.pn.noise3(x / 100.0, y / 100.0, z / 100.0) - n = n + (float(y)/float(maxy))*2 + n = n + (float(y) / float(maxy)) * 2 # Random broken stone brick in stone brick and cobble zones. if n <= 1.5: - broken = .1+(float(y)/float(maxy))*.5 - if random.randint(1, 100) < broken*10+5: + broken = .1 + (float(y) / float(maxy)) * .5 + if random.randint(1, 100) < broken * 10 + 5: self.val = CrackedStoneBrick.val self.data = CrackedStoneBrick.data self.c = CrackedStoneBrick.c diff --git a/mcdungeon.py b/mcdungeon.py index d2f53b09..bfb33fda 100755 --- a/mcdungeon.py +++ b/mcdungeon.py @@ -360,7 +360,7 @@ def listDungeons(world, oworld, expand_fill_caves=False): for cx, cz, cmtime in regions.iterate_chunks(): count -= 1 pm.update_left(count) - key = '%s,%s' % (cx*16, cz*16) + key = '%s,%s' % (cx * 16, cz * 16) if (cmtime > mtime or key in dungeonCacheOld): notcached += 1 for tileEntity in regions.get_chunk(cx, cz)["TileEntities"]: @@ -382,7 +382,7 @@ def listDungeons(world, oworld, expand_fill_caves=False): continue pm.set_complete() print ' Cache hit rate: %d/%d (%d%%)' % (cached, world.chunkCount, - 100*cached/world.chunkCount) + 100 * cached / world.chunkCount) utils.saveDungeonCache(cache_path, dungeonCache) @@ -406,7 +406,7 @@ def listDungeons(world, oworld, expand_fill_caves=False): info = utils.decodeDungeonInfo(tileEntity) (major, minor, patch) = info['version'].split('.') - version = float(major+'.'+minor) + version = float(major + '.' + minor) xsize = info['xsize'] zsize = info['zsize'] @@ -418,10 +418,10 @@ def listDungeons(world, oworld, expand_fill_caves=False): info['fill_caves'] is True ): offset = 5 - dungeons.append((info["position"].x-offset, - info["position"].z-offset, - xsize+offset, - zsize+offset, + dungeons.append((info["position"].x - offset, + info["position"].z - offset, + xsize + offset, + zsize + offset, info, levels, info["position"].x, @@ -471,7 +471,7 @@ def listDungeons(world, oworld, expand_fill_caves=False): file_path = os.path.join(saveFileDir, file) if ( os.path.isdir(file_path) and - os.path.isfile(file_path+'/level.dat') + os.path.isfile(file_path + '/level.dat') ): print ' ', file count += 1 @@ -502,14 +502,13 @@ def listDungeons(world, oworld, expand_fill_caves=False): file_path = os.path.join(configDir, file) file = file.replace('.cfg', '') if (os.path.isfile(file_path) and - file_path.endswith('.cfg')): + file_path.endswith('.cfg')): print ' ', file print '\nEnter the name of the configuration you wish to use.' config = raw_input('(leave blank for default): ') if (config == ''): config = 'default' - #args.config = str(os.path.join(configDir, config))+'.cfg' - args.config = str(config)+'.cfg' + args.config = str(config) + '.cfg' cfg.Load(args.config) # Prompt for a mapstore if we need to @@ -529,7 +528,7 @@ def listDungeons(world, oworld, expand_fill_caves=False): print 'add many dungeons, they will not cover much of the map.\n' input_max_dist = raw_input( 'Max Distance (leave blank for config value, ' + - str(cfg.max_dist)+'): ' + str(cfg.max_dist) + '): ' ) if (input_max_dist != ''): try: @@ -580,13 +579,13 @@ def listDungeons(world, oworld, expand_fill_caves=False): file_path = os.path.join(configDir, file) file = file.replace('.cfg', '') if (os.path.isfile(file_path) and - file_path.endswith('.cfg')): + file_path.endswith('.cfg')): print ' ', file print '\nEnter the name of the configuration you wish to use.' config = raw_input('(leave blank for default): ') if (config == ''): config = 'default' - args.config = str(config)+'.cfg' + args.config = str(config) + '.cfg' cfg.Load(args.config) # Prompt for a mapstore if we need to @@ -612,7 +611,7 @@ def listDungeons(world, oworld, expand_fill_caves=False): print '\t[a] Regenerate ALL dungeons in this map.' for i in xrange(len(dlist)): print '\t[%d] Dungeon at %d %d.' % ( - i+1, + i + 1, dlist[i][0], dlist[i][1] ) @@ -622,7 +621,7 @@ def listDungeons(world, oworld, expand_fill_caves=False): args.all = True elif d.isdigit() and int(d) > 0 and int(d) <= len(dlist): d = int(d) - args.dungeons = [[dlist[d-1][0], dlist[d-1][1]]] + args.dungeons = [[dlist[d - 1][0], dlist[d - 1][1]]] elif d == 'q': print 'Quitting...' sys.exit() @@ -657,7 +656,7 @@ def listDungeons(world, oworld, expand_fill_caves=False): print '\t[a] Delete ALL dungeons from this map.' for i in xrange(len(dungeons)): print '\t[%d] Dungeon at %d %d.' % ( - i+1, + i + 1, dungeons[i][0], dungeons[i][1] ) @@ -667,7 +666,7 @@ def listDungeons(world, oworld, expand_fill_caves=False): args.all = True elif d.isdigit() and int(d) > 0 and int(d) <= len(dungeons): d = int(d) - args.dungeons = [[dungeons[d-1][0], dungeons[d-1][1]]] + args.dungeons = [[dungeons[d - 1][0], dungeons[d - 1][1]]] elif d == 'q': print 'Quitting...' sys.exit() @@ -693,7 +692,6 @@ def listDungeons(world, oworld, expand_fill_caves=False): if (args.command == 'list'): # List the known dungeons and exit dungeons = listDungeons(world, oworld) - #print dungeons sys.exit() # Delete mode @@ -731,14 +729,14 @@ def listDungeons(world, oworld, expand_fill_caves=False): dcache, dmtime = utils.loadDungeonCache(cache_path) ms = mapstore.new(cfg.mapstore, cfg.dir_paintings) for d in to_delete: - p = [d[0]/16, d[1]/16] + p = [d[0] / 16, d[1] / 16] print 'Deleting dungeon at %d %d...' % (d[0], d[1]) dkey = '%s,%s' % (d[0], d[1]) ms.delete_maps(dkey) if dkey in dcache: del dcache[dkey] else: - print 'WARN: Dungeon not in dungeon cache! '+dkey + print 'WARN: Dungeon not in dungeon cache! ' + dkey xsize = 0 zsize = 0 for e in dungeons: @@ -754,7 +752,7 @@ def listDungeons(world, oworld, expand_fill_caves=False): break for x in xrange(xsize): for z in xrange(zsize): - chunks.append((p[0]+x, p[1]+z)) + chunks.append((p[0] + x, p[1] + z)) # We need to update the caches for the chunks we are affecting ccache, cmtime = utils.loadChunkCache(cache_path) # Delete the chunks @@ -765,7 +763,7 @@ def listDungeons(world, oworld, expand_fill_caves=False): if ckey in ccache: del ccache[ckey] else: - print 'WARN: Chunk not in chunk cache! '+ckey + print 'WARN: Chunk not in chunk cache! ' + ckey # Save the world. print "Saving..." world.saveInPlace() @@ -1004,11 +1002,11 @@ def listDungeons(world, oworld, expand_fill_caves=False): sx = world.playerSpawnPosition()[0] >> 4 sz = world.playerSpawnPosition()[2] >> 4 # Far chunk - if (numpy.sqrt((cx-sx)*(cx-sx)+(cz-sz)*(cz-sz)) > cfg.max_dist): + if (numpy.sqrt((cx - sx) * (cx - sx) + (cz - sz) * (cz - sz)) > cfg.max_dist): chunk_stats[0][1] += 1 continue # Near chunk - if (numpy.sqrt((cx-sx)*(cx-sx)+(cz-sz)*(cz-sz)) < cfg.min_dist): + if (numpy.sqrt((cx - sx) * (cx - sx) + (cz - sz) * (cz - sz)) < cfg.min_dist): chunk_stats[1][1] += 1 continue # Chunk map stuff @@ -1062,7 +1060,7 @@ def listDungeons(world, oworld, expand_fill_caves=False): t = False i = 0 y = 0 - while (t is False and y < world.Height//16): + while (t is False and y < world.Height // 16): if (y not in b or i >= len(mats)): y += 1 i = 0 @@ -1078,9 +1076,9 @@ def listDungeons(world, oworld, expand_fill_caves=False): max_depth = 0 for x in xrange(16): for z in xrange(16): - y = chunk['HeightMap'][z+x*16]-1 - while (y > 0 and y//16 in b and - b[y//16][y % 16, z, x] not in + y = chunk['HeightMap'][z + x * 16] - 1 + while (y > 0 and y // 16 in b and + b[y // 16][y % 16, z, x] not in materials.heightmap_solids): y = y - 1 min_depth = min(y, min_depth) @@ -1118,20 +1116,20 @@ def listDungeons(world, oworld, expand_fill_caves=False): for d in old_dungeons: if args.debug: print 'old dungeon:', d - p = (d[0]/16, d[1]/16) + p = (d[0] / 16, d[1] / 16) for x in xrange(int(d[2])): for z in xrange(int(d[3])): - if (p[0]+x, p[1]+z) in good_chunks: - del(good_chunks[(p[0]+x, p[1]+z)]) - key = '%s,%s' % (p[0]+x, p[1]+z) + if (p[0] + x, p[1] + z) in good_chunks: + del(good_chunks[(p[0] + x, p[1] + z)]) + key = '%s,%s' % (p[0] + x, p[1] + z) chunk_cache[key] = ['S', -1, 0] chunk_stats[4][1] += 1 chunk_stats[8][1] -= 1 # Funky little chunk map if args.debug: - for cz in xrange(chunk_min[1], chunk_max[1]+1): - for cx in xrange(chunk_min[0], chunk_max[0]+1): + for cz in xrange(chunk_min[1], chunk_max[1] + 1): + for cx in xrange(chunk_min[0], chunk_max[0] + 1): key = '%s,%s' % (cx, cz) if key in chunk_cache: if chunk_cache[key][0] == 'U': @@ -1160,8 +1158,8 @@ def listDungeons(world, oworld, expand_fill_caves=False): for stat in chunk_stats: print ' %s: %d' % (stat[0], stat[1]) - print ' Cache hit rate: %d/%d (%d%%)' % (cached, notcached+cached, - 100*cached/(notcached+cached)) + print ' Cache hit rate: %d/%d (%d%%)' % (cached, notcached + cached, + 100 * cached / (notcached + cached)) # Load the dungeon cache for updates later. @@ -1180,9 +1178,9 @@ def listDungeons(world, oworld, expand_fill_caves=False): ) ): if args.number == -1: - print '\n***** Placing dungeon {0} *****\n'.format(count+1) + print '\n***** Placing dungeon {0} *****\n'.format(count + 1) else: - print '\n***** Placing dungeon {0} of {1} *****\n'.format(count+1, + print '\n***** Placing dungeon {0} of {1} *****\n'.format(count + 1, args.number) dungeon = Dungeon(args, diff --git a/namegenerator.py b/namegenerator.py index 175c9d59..7f478137 100644 --- a/namegenerator.py +++ b/namegenerator.py @@ -4,48 +4,50 @@ from utils import weighted_choice from namegen import namegen + class namegenerator: + def __init__(self, biomeid): # Get theme from biome id self.theme = self.gettheme(biomeid) # Choose DICT based on theme if (self.theme == 'egyptian'): dict = 'egyptian.txt' - self.titles = ['Pharaoh','High Priest','Vizier'] + self.titles = ['Pharaoh', 'High Priest', 'Vizier'] elif (self.theme == 'norse'): dict = 'norse.txt' - self.titles = ['King','Queen','Jarl','Hojfruen'] + self.titles = ['King', 'Queen', 'Jarl', 'Hojfruen'] elif (self.theme == 'saxon'): dict = 'saxon.txt' - self.titles = ['King','Queen', 'Elder'] + self.titles = ['King', 'Queen', 'Elder'] elif (self.theme == 'elven'): dict = 'elven.txt' - self.titles = ['King','Queen','Lord','Lady'] + self.titles = ['King', 'Queen', 'Lord', 'Lady'] elif (self.theme == 'mayan'): dict = 'mayan.txt' - self.titles = ['Tepal','Ajaw'] + self.titles = ['Tepal', 'Ajaw'] elif (self.theme == 'welsh'): dict = 'welsh.txt' - self.titles = ['Y Brenin','Y Frenhines'] + self.titles = ['Y Brenin', 'Y Frenhines'] elif (self.theme == 'greek'): dict = 'greek.txt' - self.titles = ['King','Queen','Strategos', - 'Tyrant','Archon'] + self.titles = ['King', 'Queen', 'Strategos', + 'Tyrant', 'Archon'] elif (self.theme == 'roman'): dict = 'roman.txt' - self.titles = ['Emperor','Empress', 'Praetor', + self.titles = ['Emperor', 'Empress', 'Praetor', 'Prefect', 'Consul', 'Magister'] # Find name dictionaries - if os.path.isdir(os.path.join(sys.path[0],'names')): - names_path = os.path.join(sys.path[0],'names') + if os.path.isdir(os.path.join(sys.path[0], 'names')): + names_path = os.path.join(sys.path[0], 'names') elif os.path.isdir('names'): names_path = 'names' else: sys.exit("Error: Could not find the names folder!") # Set up name generator - self.generator = namegen.NameGen(os.path.join(names_path,dict)) + self.generator = namegen.NameGen(os.path.join(names_path, dict)) def gettheme(self, biomeid): # Choose DICT based on biome @@ -62,7 +64,7 @@ def gettheme(self, biomeid): 166, # Mesa Plateau F M 39, # Mesa Plateau 167, # Mesa Plateau M - )): + )): theme_weights = [('egyptian', 50), ('greek', 10), ('roman', 10)] @@ -81,7 +83,7 @@ def gettheme(self, biomeid): 160, # Mega Spruce Taiga 33, # Mega Taiga Hills 161, # Mega Spruce Taiga - )): + )): theme_weights = [('norse', 50), ('elven', 10), ('saxon', 10)] @@ -95,7 +97,7 @@ def gettheme(self, biomeid): 26, # Stone Beach 34, # Extreme Hills+ 162, # Extreme Hills+ M - )): + )): theme_weights = [('saxon', 20), ('roman', 10), ('greek', 10)] @@ -108,7 +110,7 @@ def gettheme(self, biomeid): 156, # Birch Forest Hills M 29, # Roofed Forest 157, # Roofed Forest M - )): + )): theme_weights = [('elven', 50), ('roman', 10), ('norse', 10)] @@ -117,12 +119,12 @@ def gettheme(self, biomeid): 22, # JungleHills 23, # JungleEdge 151, # JungleEdge M - )): + )): theme_weights = [('mayan', 60), ('elven', 10)] elif (biomeid in (14, # MushroomIsland 15, # MushroomIslandShore - )): + )): theme_weights = [('welsh', 1)] else: # The rest. Including rivers, oceans etc theme_weights = [('saxon', 10), diff --git a/perlin.py b/perlin.py index bb38d858..4d8631b8 100644 --- a/perlin.py +++ b/perlin.py @@ -9,33 +9,33 @@ from random import randint # 3D Gradient vectors -_GRAD3 = ((1,1,0),(-1,1,0),(1,-1,0),(-1,-1,0), - (1,0,1),(-1,0,1),(1,0,-1),(-1,0,-1), - (0,1,1),(0,-1,1),(0,1,-1),(0,-1,-1), - (1,1,0),(0,-1,1),(-1,1,0),(0,-1,-1), -) +_GRAD3 = ((1, 1, 0), (-1, 1, 0), (1, -1, 0), (-1, -1, 0), + (1, 0, 1), (-1, 0, 1), (1, 0, -1), (-1, 0, -1), + (0, 1, 1), (0, -1, 1), (0, 1, -1), (0, -1, -1), + (1, 1, 0), (0, -1, 1), (-1, 1, 0), (0, -1, -1), + ) # 4D Gradient vectors -_GRAD4 = ((0,1,1,1), (0,1,1,-1), (0,1,-1,1), (0,1,-1,-1), - (0,-1,1,1), (0,-1,1,-1), (0,-1,-1,1), (0,-1,-1,-1), - (1,0,1,1), (1,0,1,-1), (1,0,-1,1), (1,0,-1,-1), - (-1,0,1,1), (-1,0,1,-1), (-1,0,-1,1), (-1,0,-1,-1), - (1,1,0,1), (1,1,0,-1), (1,-1,0,1), (1,-1,0,-1), - (-1,1,0,1), (-1,1,0,-1), (-1,-1,0,1), (-1,-1,0,-1), - (1,1,1,0), (1,1,-1,0), (1,-1,1,0), (1,-1,-1,0), - (-1,1,1,0), (-1,1,-1,0), (-1,-1,1,0), (-1,-1,-1,0)) - -# A lookup table to traverse the simplex around a given point in 4D. -# Details can be found where this table is used, in the 4D noise method. +_GRAD4 = ((0, 1, 1, 1), (0, 1, 1, -1), (0, 1, -1, 1), (0, 1, -1, -1), + (0, -1, 1, 1), (0, -1, 1, -1), (0, -1, -1, 1), (0, -1, -1, -1), + (1, 0, 1, 1), (1, 0, 1, -1), (1, 0, -1, 1), (1, 0, -1, -1), + (-1, 0, 1, 1), (-1, 0, 1, -1), (-1, 0, -1, 1), (-1, 0, -1, -1), + (1, 1, 0, 1), (1, 1, 0, -1), (1, -1, 0, 1), (1, -1, 0, -1), + (-1, 1, 0, 1), (-1, 1, 0, -1), (-1, -1, 0, 1), (-1, -1, 0, -1), + (1, 1, 1, 0), (1, 1, -1, 0), (1, -1, 1, 0), (1, -1, -1, 0), + (-1, 1, 1, 0), (-1, 1, -1, 0), (-1, -1, 1, 0), (-1, -1, -1, 0)) + +# A lookup table to traverse the simplex around a given point in 4D. +# Details can be found where this table is used, in the 4D noise method. _SIMPLEX = ( - (0,1,2,3),(0,1,3,2),(0,0,0,0),(0,2,3,1),(0,0,0,0),(0,0,0,0),(0,0,0,0),(1,2,3,0), - (0,2,1,3),(0,0,0,0),(0,3,1,2),(0,3,2,1),(0,0,0,0),(0,0,0,0),(0,0,0,0),(1,3,2,0), - (0,0,0,0),(0,0,0,0),(0,0,0,0),(0,0,0,0),(0,0,0,0),(0,0,0,0),(0,0,0,0),(0,0,0,0), - (1,2,0,3),(0,0,0,0),(1,3,0,2),(0,0,0,0),(0,0,0,0),(0,0,0,0),(2,3,0,1),(2,3,1,0), - (1,0,2,3),(1,0,3,2),(0,0,0,0),(0,0,0,0),(0,0,0,0),(2,0,3,1),(0,0,0,0),(2,1,3,0), - (0,0,0,0),(0,0,0,0),(0,0,0,0),(0,0,0,0),(0,0,0,0),(0,0,0,0),(0,0,0,0),(0,0,0,0), - (2,0,1,3),(0,0,0,0),(0,0,0,0),(0,0,0,0),(3,0,1,2),(3,0,2,1),(0,0,0,0),(3,1,2,0), - (2,1,0,3),(0,0,0,0),(0,0,0,0),(0,0,0,0),(3,1,0,2),(0,0,0,0),(3,2,0,1),(3,2,1,0)) + (0, 1, 2, 3), (0, 1, 3, 2), (0, 0, 0, 0), (0, 2, 3, 1), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (1, 2, 3, 0), + (0, 2, 1, 3), (0, 0, 0, 0), (0, 3, 1, 2), (0, 3, 2, 1), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (1, 3, 2, 0), + (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), + (1, 2, 0, 3), (0, 0, 0, 0), (1, 3, 0, 2), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (2, 3, 0, 1), (2, 3, 1, 0), + (1, 0, 2, 3), (1, 0, 3, 2), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (2, 0, 3, 1), (0, 0, 0, 0), (2, 1, 3, 0), + (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), + (2, 0, 1, 3), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (3, 0, 1, 2), (3, 0, 2, 1), (0, 0, 0, 0), (3, 1, 2, 0), + (2, 1, 0, 3), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (3, 1, 0, 2), (0, 0, 0, 0), (3, 2, 0, 1), (3, 2, 1, 0)) # Simplex skew constants _F2 = 0.5 * (sqrt(3.0) - 1.0) @@ -45,297 +45,331 @@ class BaseNoise: - """Noise abstract base class""" - - permutation = (151,160,137,91,90,15, - 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23, - 190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33, - 88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166, - 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244, - 102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208,89,18,169,200,196, - 135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,250,124,123, - 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42, - 223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43,172,9, - 129,22,39,253,9,98,108,110,79,113,224,232,178,185,112,104,218,246,97,228, - 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107, - 49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254, - 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180) - - period = len(permutation) - - # Double permutation array so we don't need to wrap - permutation = permutation * 2 - - def __init__(self, period=None, permutation_table=None): - """Initialize the noise generator. With no arguments, the default - period and permutation table are used (256). The default permutation - table generates the exact same noise pattern each time. - - An integer period can be specified, to generate a random permutation - table with period elements. The period determines the (integer) - interval that the noise repeats, which is useful for creating tiled - textures. period should be a power-of-two, though this is not - enforced. Note that the speed of the noise algorithm is indpendent of - the period size, though larger periods mean a larger table, which - consume more memory. - - A permutation table consisting of an iterable sequence of whole - numbers can be specified directly. This should have a power-of-two - length. Typical permutation tables are a sequnce of unique integers in - the range [0,period) in random order, though other arrangements could - prove useful, they will not be "pure" simplex noise. The largest - element in the sequence must be no larger than period-1. - - period and permutation_table may not be specified togther. - """ - if period is not None and permutation_table is not None: - raise ValueError( - 'Can specify either period or permutation_table, not both') - if period is not None: - self.randomize(period) - elif permutation_table is not None: - self.permutation = tuple(permutation_table) * 2 - self.period = len(permutation_table) - - def randomize(self, period=None): - """Randomize the permutation table used by the noise functions. This - makes them generate a different noise pattern for the same inputs. - """ - if period is not None: - self.period = period - perm = range(self.period) - perm_right = self.period - 1 - for i in list(perm): - j = randint(0, perm_right) - perm[i], perm[j] = perm[j], perm[i] - self.permutation = tuple(perm) * 2 + + """Noise abstract base class""" + + permutation = (151, 160, 137, 91, 90, 15, + 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, + 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, + 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, + 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, + 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196, + 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123, + 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, + 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, + 129, 22, 39, 253, 9, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, + 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, + 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, + 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180) + + period = len(permutation) + + # Double permutation array so we don't need to wrap + permutation = permutation * 2 + + def __init__(self, period=None, permutation_table=None): + """Initialize the noise generator. With no arguments, the default + period and permutation table are used (256). The default permutation + table generates the exact same noise pattern each time. + + An integer period can be specified, to generate a random permutation + table with period elements. The period determines the (integer) + interval that the noise repeats, which is useful for creating tiled + textures. period should be a power-of-two, though this is not + enforced. Note that the speed of the noise algorithm is indpendent of + the period size, though larger periods mean a larger table, which + consume more memory. + + A permutation table consisting of an iterable sequence of whole + numbers can be specified directly. This should have a power-of-two + length. Typical permutation tables are a sequnce of unique integers in + the range [0,period) in random order, though other arrangements could + prove useful, they will not be "pure" simplex noise. The largest + element in the sequence must be no larger than period-1. + + period and permutation_table may not be specified togther. + """ + if period is not None and permutation_table is not None: + raise ValueError( + 'Can specify either period or permutation_table, not both') + if period is not None: + self.randomize(period) + elif permutation_table is not None: + self.permutation = tuple(permutation_table) * 2 + self.period = len(permutation_table) + + def randomize(self, period=None): + """Randomize the permutation table used by the noise functions. This + makes them generate a different noise pattern for the same inputs. + """ + if period is not None: + self.period = period + perm = range(self.period) + perm_right = self.period - 1 + for i in list(perm): + j = randint(0, perm_right) + perm[i], perm[j] = perm[j], perm[i] + self.permutation = tuple(perm) * 2 class SimplexNoise(BaseNoise): - """Perlin simplex noise generator - - Adapted from Stefan Gustavson's Java implementation described here: - - http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf - - To summarize: - - "In 2001, Ken Perlin presented 'simplex noise', a replacement for his classic - noise algorithm. Classic 'Perlin noise' won him an academy award and has - become an ubiquitous procedural primitive for computer graphics over the - years, but in hindsight it has quite a few limitations. Ken Perlin himself - designed simplex noise specifically to overcome those limitations, and he - spent a lot of good thinking on it. Therefore, it is a better idea than his - original algorithm. A few of the more prominent advantages are: - - * Simplex noise has a lower computational complexity and requires fewer - multiplications. - * Simplex noise scales to higher dimensions (4D, 5D and up) with much less - computational cost, the complexity is O(N) for N dimensions instead of - the O(2^N) of classic Noise. - * Simplex noise has no noticeable directional artifacts. Simplex noise has - a well-defined and continuous gradient everywhere that can be computed - quite cheaply. - * Simplex noise is easy to implement in hardware." - """ - - def noise2(self, x, y): - """2D Perlin simplex noise. - - Return a floating point value from -1 to 1 for the given x, y coordinate. - The same value is always returned for a given x, y pair unless the - permutation table changes (see randomize above). - """ - # Skew input space to determine which simplex (triangle) we are in - s = (x + y) * _F2 - i = floor(x + s) - j = floor(y + s) - t = (i + j) * _G2 - x0 = x - (i - t) # "Unskewed" distances from cell origin - y0 = y - (j - t) - - if x0 > y0: - i1 = 1; j1 = 0 # Lower triangle, XY order: (0,0)->(1,0)->(1,1) - else: - i1 = 0; j1 = 1 # Upper triangle, YX order: (0,0)->(0,1)->(1,1) - - x1 = x0 - i1 + _G2 # Offsets for middle corner in (x,y) unskewed coords - y1 = y0 - j1 + _G2 - x2 = x0 + _G2 * 2.0 - 1.0 # Offsets for last corner in (x,y) unskewed coords - y2 = y0 + _G2 * 2.0 - 1.0 - - # Determine hashed gradient indices of the three simplex corners - perm = self.permutation - ii = int(i) % self.period - jj = int(j) % self.period - gi0 = perm[ii + perm[jj]] % 12 - gi1 = perm[ii + i1 + perm[jj + j1]] % 12 - gi2 = perm[ii + 1 + perm[jj + 1]] % 12 - - # Calculate the contribution from the three corners - tt = 0.5 - x0**2 - y0**2 - if tt > 0: - g = _GRAD3[gi0] - noise = tt**4 * (g[0] * x0 + g[1] * y0) - else: - noise = 0.0 - - tt = 0.5 - x1**2 - y1**2 - if tt > 0: - g = _GRAD3[gi1] - noise += tt**4 * (g[0] * x1 + g[1] * y1) - - tt = 0.5 - x2**2 - y2**2 - if tt > 0: - g = _GRAD3[gi2] - noise += tt**4 * (g[0] * x2 + g[1] * y2) - - return noise * 70.0 # scale noise to [-1, 1] - - def noise3(self, x, y, z): - """3D Perlin simplex noise. - - Return a floating point value from -1 to 1 for the given x, y, z coordinate. - The same value is always returned for a given x, y, z pair unless the - permutation table changes (see randomize above). - """ - # Skew the input space to determine which simplex cell we're in - s = (x + y + z) * _F3 - i = floor(x + s) - j = floor(y + s) - k = floor(z + s) - t = (i + j + k) * _G3 - x0 = x - (i - t) # "Unskewed" distances from cell origin - y0 = y - (j - t) - z0 = z - (k - t) - - # For the 3D case, the simplex shape is a slightly irregular tetrahedron. - # Determine which simplex we are in. - if x0 >= y0: - if y0 >= z0: - i1 = 1; j1 = 0; k1 = 0 - i2 = 1; j2 = 1; k2 = 0 - elif x0 >= z0: - i1 = 1; j1 = 0; k1 = 0 - i2 = 1; j2 = 0; k2 = 1 - else: - i1 = 0; j1 = 0; k1 = 1 - i2 = 1; j2 = 0; k2 = 1 - else: # x0 < y0 - if y0 < z0: - i1 = 0; j1 = 0; k1 = 1 - i2 = 0; j2 = 1; k2 = 1 - elif x0 < z0: - i1 = 0; j1 = 1; k1 = 0 - i2 = 0; j2 = 1; k2 = 1 - else: - i1 = 0; j1 = 1; k1 = 0 - i2 = 1; j2 = 1; k2 = 0 - - # Offsets for remaining corners - x1 = x0 - i1 + _G3 - y1 = y0 - j1 + _G3 - z1 = z0 - k1 + _G3 - x2 = x0 - i2 + 2.0 * _G3 - y2 = y0 - j2 + 2.0 * _G3 - z2 = z0 - k2 + 2.0 * _G3 - x3 = x0 - 1.0 + 3.0 * _G3 - y3 = y0 - 1.0 + 3.0 * _G3 - z3 = z0 - 1.0 + 3.0 * _G3 - - # Calculate the hashed gradient indices of the four simplex corners - perm = self.permutation - ii = int(i) % self.period - jj = int(j) % self.period - kk = int(k) % self.period - gi0 = perm[ii + perm[jj + perm[kk]]] % 12 - gi1 = perm[ii + i1 + perm[jj + j1 + perm[kk + k1]]] % 12 - gi2 = perm[ii + i2 + perm[jj + j2 + perm[kk + k2]]] % 12 - gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1]]] % 12 - - # Calculate the contribution from the four corners - noise = 0.0 - tt = 0.6 - x0**2 - y0**2 - z0**2 - if tt > 0: - g = _GRAD3[gi0] - noise = tt**4 * (g[0] * x0 + g[1] * y0 + g[2] * z0) - else: - noise = 0.0 - - tt = 0.6 - x1**2 - y1**2 - z1**2 - if tt > 0: - g = _GRAD3[gi1] - noise += tt**4 * (g[0] * x1 + g[1] * y1 + g[2] * z1) - - tt = 0.6 - x2**2 - y2**2 - z2**2 - if tt > 0: - g = _GRAD3[gi2] - noise += tt**4 * (g[0] * x2 + g[1] * y2 + g[2] * z2) - - tt = 0.6 - x3**2 - y3**2 - z3**2 - if tt > 0: - g = _GRAD3[gi3] - noise += tt**4 * (g[0] * x3 + g[1] * y3 + g[2] * z3) - - return noise * 32.0 + + """Perlin simplex noise generator + + Adapted from Stefan Gustavson's Java implementation described here: + + http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf + + To summarize: + + "In 2001, Ken Perlin presented 'simplex noise', a replacement for his classic + noise algorithm. Classic 'Perlin noise' won him an academy award and has + become an ubiquitous procedural primitive for computer graphics over the + years, but in hindsight it has quite a few limitations. Ken Perlin himself + designed simplex noise specifically to overcome those limitations, and he + spent a lot of good thinking on it. Therefore, it is a better idea than his + original algorithm. A few of the more prominent advantages are: + + * Simplex noise has a lower computational complexity and requires fewer + multiplications. + * Simplex noise scales to higher dimensions (4D, 5D and up) with much less + computational cost, the complexity is O(N) for N dimensions instead of + the O(2^N) of classic Noise. + * Simplex noise has no noticeable directional artifacts. Simplex noise has + a well-defined and continuous gradient everywhere that can be computed + quite cheaply. + * Simplex noise is easy to implement in hardware." + """ + + def noise2(self, x, y): + """2D Perlin simplex noise. + + Return a floating point value from -1 to 1 for the given x, y coordinate. + The same value is always returned for a given x, y pair unless the + permutation table changes (see randomize above). + """ + # Skew input space to determine which simplex (triangle) we are in + s = (x + y) * _F2 + i = floor(x + s) + j = floor(y + s) + t = (i + j) * _G2 + x0 = x - (i - t) # "Unskewed" distances from cell origin + y0 = y - (j - t) + + if x0 > y0: + i1 = 1 + j1 = 0 # Lower triangle, XY order: (0,0)->(1,0)->(1,1) + else: + i1 = 0 + j1 = 1 # Upper triangle, YX order: (0,0)->(0,1)->(1,1) + + # Offsets for middle corner in (x,y) unskewed coords + x1 = x0 - i1 + _G2 + y1 = y0 - j1 + _G2 + # Offsets for last corner in (x,y) unskewed coords + x2 = x0 + _G2 * 2.0 - 1.0 + y2 = y0 + _G2 * 2.0 - 1.0 + + # Determine hashed gradient indices of the three simplex corners + perm = self.permutation + ii = int(i) % self.period + jj = int(j) % self.period + gi0 = perm[ii + perm[jj]] % 12 + gi1 = perm[ii + i1 + perm[jj + j1]] % 12 + gi2 = perm[ii + 1 + perm[jj + 1]] % 12 + + # Calculate the contribution from the three corners + tt = 0.5 - x0 ** 2 - y0 ** 2 + if tt > 0: + g = _GRAD3[gi0] + noise = tt ** 4 * (g[0] * x0 + g[1] * y0) + else: + noise = 0.0 + + tt = 0.5 - x1 ** 2 - y1 ** 2 + if tt > 0: + g = _GRAD3[gi1] + noise += tt ** 4 * (g[0] * x1 + g[1] * y1) + + tt = 0.5 - x2 ** 2 - y2 ** 2 + if tt > 0: + g = _GRAD3[gi2] + noise += tt ** 4 * (g[0] * x2 + g[1] * y2) + + return noise * 70.0 # scale noise to [-1, 1] + + def noise3(self, x, y, z): + """3D Perlin simplex noise. + + Return a floating point value from -1 to 1 for the given x, y, z coordinate. + The same value is always returned for a given x, y, z pair unless the + permutation table changes (see randomize above). + """ + # Skew the input space to determine which simplex cell we're in + s = (x + y + z) * _F3 + i = floor(x + s) + j = floor(y + s) + k = floor(z + s) + t = (i + j + k) * _G3 + x0 = x - (i - t) # "Unskewed" distances from cell origin + y0 = y - (j - t) + z0 = z - (k - t) + + # For the 3D case, the simplex shape is a slightly irregular tetrahedron. + # Determine which simplex we are in. + if x0 >= y0: + if y0 >= z0: + i1 = 1 + j1 = 0 + k1 = 0 + i2 = 1 + j2 = 1 + k2 = 0 + elif x0 >= z0: + i1 = 1 + j1 = 0 + k1 = 0 + i2 = 1 + j2 = 0 + k2 = 1 + else: + i1 = 0 + j1 = 0 + k1 = 1 + i2 = 1 + j2 = 0 + k2 = 1 + else: # x0 < y0 + if y0 < z0: + i1 = 0 + j1 = 0 + k1 = 1 + i2 = 0 + j2 = 1 + k2 = 1 + elif x0 < z0: + i1 = 0 + j1 = 1 + k1 = 0 + i2 = 0 + j2 = 1 + k2 = 1 + else: + i1 = 0 + j1 = 1 + k1 = 0 + i2 = 1 + j2 = 1 + k2 = 0 + + # Offsets for remaining corners + x1 = x0 - i1 + _G3 + y1 = y0 - j1 + _G3 + z1 = z0 - k1 + _G3 + x2 = x0 - i2 + 2.0 * _G3 + y2 = y0 - j2 + 2.0 * _G3 + z2 = z0 - k2 + 2.0 * _G3 + x3 = x0 - 1.0 + 3.0 * _G3 + y3 = y0 - 1.0 + 3.0 * _G3 + z3 = z0 - 1.0 + 3.0 * _G3 + + # Calculate the hashed gradient indices of the four simplex corners + perm = self.permutation + ii = int(i) % self.period + jj = int(j) % self.period + kk = int(k) % self.period + gi0 = perm[ii + perm[jj + perm[kk]]] % 12 + gi1 = perm[ii + i1 + perm[jj + j1 + perm[kk + k1]]] % 12 + gi2 = perm[ii + i2 + perm[jj + j2 + perm[kk + k2]]] % 12 + gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1]]] % 12 + + # Calculate the contribution from the four corners + noise = 0.0 + tt = 0.6 - x0 ** 2 - y0 ** 2 - z0 ** 2 + if tt > 0: + g = _GRAD3[gi0] + noise = tt ** 4 * (g[0] * x0 + g[1] * y0 + g[2] * z0) + else: + noise = 0.0 + + tt = 0.6 - x1 ** 2 - y1 ** 2 - z1 ** 2 + if tt > 0: + g = _GRAD3[gi1] + noise += tt ** 4 * (g[0] * x1 + g[1] * y1 + g[2] * z1) + + tt = 0.6 - x2 ** 2 - y2 ** 2 - z2 ** 2 + if tt > 0: + g = _GRAD3[gi2] + noise += tt ** 4 * (g[0] * x2 + g[1] * y2 + g[2] * z2) + + tt = 0.6 - x3 ** 2 - y3 ** 2 - z3 ** 2 + if tt > 0: + g = _GRAD3[gi3] + noise += tt ** 4 * (g[0] * x3 + g[1] * y3 + g[2] * z3) + + return noise * 32.0 def lerp(t, a, b): - return a + t * (b - a) + return a + t * (b - a) + def grad3(hash, x, y, z): - g = _GRAD3[hash % 16] - return x*g[0] + y*g[1] + z*g[2] + g = _GRAD3[hash % 16] + return x * g[0] + y * g[1] + z * g[2] class TileableNoise(BaseNoise): - """Tileable implemention of Perlin "improved" noise. This - is based on the reference implementation published here: - - http://mrl.nyu.edu/~perlin/noise/ - """ - - def noise3(self, x, y, z, repeat, base=0.0): - """Tileable 3D noise. - - repeat specifies the integer interval in each dimension - when the noise pattern repeats. - - base allows a different texture to be generated for - the same repeat interval. - """ - i = int(fmod(floor(x), repeat)) - j = int(fmod(floor(y), repeat)) - k = int(fmod(floor(z), repeat)) - ii = (i + 1) % repeat - jj = (j + 1) % repeat - kk = (k + 1) % repeat - if base: - i += base; j += base; k += base - ii += base; jj += base; kk += base - - x -= floor(x); y -= floor(y); z -= floor(z) - fx = x**3 * (x * (x * 6 - 15) + 10) - fy = y**3 * (y * (y * 6 - 15) + 10) - fz = z**3 * (z * (z * 6 - 15) + 10) - - perm = self.permutation - A = perm[i] - AA = perm[A + j] - AB = perm[A + jj] - B = perm[ii] - BA = perm[B + j] - BB = perm[B + jj] - - return lerp(fz, lerp(fy, lerp(fx, grad3(perm[AA + k], x, y, z), - grad3(perm[BA + k], x - 1, y, z)), - lerp(fx, grad3(perm[AB + k], x, y - 1, z), - grad3(perm[BB + k], x - 1, y - 1, z))), - lerp(fy, lerp(fx, grad3(perm[AA + kk], x, y, z - 1), - grad3(perm[BA + kk], x - 1, y, z - 1)), - lerp(fx, grad3(perm[AB + kk], x, y - 1, z - 1), - grad3(perm[BB + kk], x - 1, y - 1, z - 1)))) - - - + """Tileable implemention of Perlin "improved" noise. This + is based on the reference implementation published here: + + http://mrl.nyu.edu/~perlin/noise/ + """ + + def noise3(self, x, y, z, repeat, base=0.0): + """Tileable 3D noise. + + repeat specifies the integer interval in each dimension + when the noise pattern repeats. + + base allows a different texture to be generated for + the same repeat interval. + """ + i = int(fmod(floor(x), repeat)) + j = int(fmod(floor(y), repeat)) + k = int(fmod(floor(z), repeat)) + ii = (i + 1) % repeat + jj = (j + 1) % repeat + kk = (k + 1) % repeat + if base: + i += base + j += base + k += base + ii += base + jj += base + kk += base + + x -= floor(x) + y -= floor(y) + z -= floor(z) + fx = x ** 3 * (x * (x * 6 - 15) + 10) + fy = y ** 3 * (y * (y * 6 - 15) + 10) + fz = z ** 3 * (z * (z * 6 - 15) + 10) + + perm = self.permutation + A = perm[i] + AA = perm[A + j] + AB = perm[A + jj] + B = perm[ii] + BA = perm[B + j] + BB = perm[B + jj] + + return lerp(fz, lerp(fy, lerp(fx, grad3(perm[AA + k], x, y, z), + grad3(perm[BA + k], x - 1, y, z)), + lerp(fx, grad3(perm[AB + k], x, y - 1, z), + grad3(perm[BB + k], x - 1, y - 1, z))), + lerp(fy, lerp(fx, grad3(perm[AA + kk], x, y, z - 1), + grad3(perm[BA + kk], x - 1, y, z - 1)), + lerp(fx, grad3(perm[AB + kk], x, y - 1, z - 1), + grad3(perm[BB + kk], x - 1, y - 1, z - 1)))) diff --git a/perlin_test.py b/perlin_test.py index 396825e4..8b8fcc48 100755 --- a/perlin_test.py +++ b/perlin_test.py @@ -6,6 +6,5 @@ pn = perlin.SimplexNoise(256) for y in xrange(size): for x in xrange(size): - print i[int((pn.noise3(x/factor,0,y/factor) + 1.0) / 2 * 6)], + print i[int((pn.noise3(x / factor, 0, y / factor) + 1.0) / 2 * 6)], print - diff --git a/pmeter.py b/pmeter.py index 9326bacb..026ebdd1 100644 --- a/pmeter.py +++ b/pmeter.py @@ -15,6 +15,7 @@ def format_sec(sec): class ETA(object): + ''' calculate ETA ''' @@ -34,7 +35,7 @@ def _cleanup(self): last_point_time = self.points[-1][0] while len(self.points) > 2: if (last_point_time - self.points[0][0] > self.max_seconds and - len(self.points) > self.max_point): + len(self.points) > self.max_point): self.points.pop(0) else: break @@ -52,7 +53,7 @@ def update(self, cursize): return eta = (float(self.wanted_size) - float(cursize)) / float(speed) - self.eta = format_sec(eta+1) + self.eta = format_sec(eta + 1) def getstatus(self): return self.eta @@ -106,18 +107,18 @@ def _rawupdate(self, cursize): if cursize == self.size: percent = 100.0 - eta = format_sec(tfunc()-self.start_time) + eta = format_sec(tfunc() - self.start_time) else: eta = self.eta_calculator.getstatus() message = '%s %s[%s>%s] %s' % ( self.label, percent_str, - self.done_char*donesteps, - self.left_char*stepsleft, + self.done_char * donesteps, + self.left_char * stepsleft, eta ) - self.outstream.write('\b'*len(self.prev_message) + message) + self.outstream.write('\b' * len(self.prev_message) + message) self.outstream.flush() self.prev_message = message @@ -153,7 +154,7 @@ def cleanup(self): if __name__ == '__main__': progress = ProgressMeter(30, outstream=sys.stderr) progress.init(500) - for i in range(500+1): + for i in range(500 + 1): time.sleep(0.01) progress.update(i) progress.cleanup() diff --git a/rooms.py b/rooms.py index bc37745d..96b15f4e 100644 --- a/rooms.py +++ b/rooms.py @@ -16,15 +16,15 @@ class Blank(object): _name = 'blank' - _min_size = Vec(1,1,1) - _max_size = Vec(1,1,1) - size = Vec(1,1,1) + _min_size = Vec(1, 1, 1) + _max_size = Vec(1, 1, 1) + size = Vec(1, 1, 1) _is_entrance = False _is_stairwell = False _is_treasureroom = False _pistontrap = True - def __init__ (self, parent, pos): + def __init__(self, parent, pos): self.parent = parent self.pos = pos self.loc = Vec( @@ -45,12 +45,12 @@ def placed(self): def setData(self): # West, South, East, North - self.hallLength = [0,0,0,0] - self.hallSize = [[1,15], [1,15], [1,15], [1,15]] + self.hallLength = [0, 0, 0, 0] + self.hallSize = [[1, 15], [1, 15], [1, 15], [1, 15]] self.canvas = ( - Vec(0,self.parent.room_height-2,0), - Vec(0,self.parent.room_height-2,0), - Vec(0,self.parent.room_height-2,0)) + Vec(0, self.parent.room_height - 2, 0), + Vec(0, self.parent.room_height - 2, 0), + Vec(0, self.parent.room_height - 2, 0)) def canvasWidth(self): x1 = min([p.x for p in self.canvas]) @@ -70,14 +70,14 @@ def canvasHeight(self): return min([p.y for p in self.canvas]) def canvasCenter(self): - cx = (self.canvasWidth()-1)/2.0+min([p.x for p in self.canvas]) - cz = (self.canvasLength()-1)/2.0+min([p.z for p in self.canvas]) - return Vec2f(cx,cz) + cx = (self.canvasWidth() - 1) / 2.0 + min([p.x for p in self.canvas]) + cz = (self.canvasLength() - 1) / 2.0 + min([p.z for p in self.canvas]) + return Vec2f(cx, cz) - def render (self): + def render(self): pass - def testHall (self, side, size, a1, b1): + def testHall(self, side, size, a1, b1): ''' Test to see if a hall will fit. return false if not, else return a range of valid offsets''' # This side is not allowed to have a hallway @@ -95,28 +95,31 @@ def testHall (self, side, size, a1, b1): return False return (a3, b3) - def isOnEdge (self, side): + def isOnEdge(self, side): # North edge of the map if (side == 0 and self.pos.z == 0): return True # East edge of the map - if (side == 1 and self.pos.x == self.parent.xsize-1): + if (side == 1 and self.pos.x == self.parent.xsize - 1): return True # South edge of the map - if (side == 2 and self.pos.z == self.parent.zsize-1): + if (side == 2 and self.pos.z == self.parent.zsize - 1): return True # West edge of the map if (side == 3 and self.pos.x == 0): return True return False + class CBlank(Blank): _name = 'cblank' + class BlankStairwell(Blank): _name = 'blankstairwell' _is_stairwell = True + class Basic(Blank): _name = 'basic' _is_entrance = True @@ -133,27 +136,27 @@ def setData(self): sz = self.size.z * self.parent.room_size sy = self.size.y * self.parent.room_height - # Some paramters. - self.c1 = self.loc + Vec(2,sy-2,2) - self.c2 = self.c1 + Vec(sx-5, 0, 0) - self.c3 = self.c1 + Vec(sx-5, 0, sz-5) - self.c4 = self.c1 + Vec(0, 0, sz-5) - - self.hallLength = [3,3,3,3] - self.hallSize = [[2,sx-2], - [2,sx-2], - [2,sz-2], - [2,sz-2]] + # Some paramters. + self.c1 = self.loc + Vec(2, sy - 2, 2) + self.c2 = self.c1 + Vec(sx - 5, 0, 0) + self.c3 = self.c1 + Vec(sx - 5, 0, sz - 5) + self.c4 = self.c1 + Vec(0, 0, sz - 5) + + self.hallLength = [3, 3, 3, 3] + self.hallSize = [[2, sx - 2], + [2, sx - 2], + [2, sz - 2], + [2, sz - 2]] self.canvas = ( - Vec(4 ,sy-2, 4), - Vec(sx-5,sy-2, 4), - Vec(sx-5,sy-2, sz-5), - Vec(4 ,sy-2, sz-5)) + Vec(4, sy - 2, 4), + Vec(sx - 5, sy - 2, 4), + Vec(sx - 5, sy - 2, sz - 5), + Vec(4, sy - 2, sz - 5)) - def render (self): + def render(self): height = self.size.y * self.parent.room_height - 2 # Air space - for x in self.air_func(self.c1.up(1), self.c3.up(height-1)): + for x in self.air_func(self.c1.up(1), self.c3.up(height - 1)): self.parent.setblock(x, materials.Air) # Floor for x in self.floor_func(self.c1, self.c3): @@ -168,17 +171,18 @@ def render (self): sf1 = self.loc.trans(0, self.size.y * self.parent.room_height - 1, 0) - sf2 = sf1.trans(self.size.x * self.parent.room_size-1, - 0, - self.size.z * self.parent.room_size-1) + sf2 = sf1.trans(self.size.x * self.parent.room_size - 1, + 0, + self.size.z * self.parent.room_size - 1) for x in iterate_plane(sf1, sf2): self.parent.setblock(x, materials._subfloor) + class Basic2x2(Basic): _name = 'basic2x2' - _min_size = Vec(2,1,2) - _max_size = Vec(2,1,2) - size = Vec(2,1,2) + _min_size = Vec(2, 1, 2) + _max_size = Vec(2, 1, 2) + size = Vec(2, 1, 2) _is_entrance = True _is_stairwell = True @@ -191,46 +195,46 @@ def placed(self): # West, South, East, North pos = self.pos rooms.append(pos) - self.hallLength = [3,0,0,3] - self.hallSize = [[2,sx-2], - [2,sx-2], - [2,sz-2], - [2,sz-2]] + self.hallLength = [3, 0, 0, 3] + self.hallSize = [[2, sx - 2], + [2, sx - 2], + [2, sz - 2], + [2, sz - 2]] self.parent.halls[pos.x][pos.y][pos.z][1] = 1 self.parent.halls[pos.x][pos.y][pos.z][2] = 1 # place three more blank rooms to hold the hallways # This is the Southern room - pos = self.pos + Vec(1,0,0) + pos = self.pos + Vec(1, 0, 0) room = new('blank', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [3,3,0,0] - room.hallSize = [[2,sx-2], - [2,sx-2], - [2,sz-2], - [2,sz-2]] + room.hallLength = [3, 3, 0, 0] + room.hallSize = [[2, sx - 2], + [2, sx - 2], + [2, sz - 2], + [2, sz - 2]] room.parent.halls[pos.x][pos.y][pos.z][2] = 1 room.parent.halls[pos.x][pos.y][pos.z][3] = 1 # Eastern room. - pos = self.pos + Vec(0,0,1) + pos = self.pos + Vec(0, 0, 1) room = new('blank', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [0,0,3,3] - room.hallSize = [[2,sx-2], - [2,sx-2], - [2,sz-2], - [2,sz-2]] + room.hallLength = [0, 0, 3, 3] + room.hallSize = [[2, sx - 2], + [2, sx - 2], + [2, sz - 2], + [2, sz - 2]] room.parent.halls[pos.x][pos.y][pos.z][0] = 1 room.parent.halls[pos.x][pos.y][pos.z][1] = 1 # South East room. - pos = self.pos + Vec(1,0,1) + pos = self.pos + Vec(1, 0, 1) room = new('blank', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [0,3,3,0] - room.hallSize = [[2,sx-2], - [2,sx-2], - [2,sz-2], - [2,sz-2]] + room.hallLength = [0, 3, 3, 0] + room.hallSize = [[2, sx - 2], + [2, sx - 2], + [2, sz - 2], + [2, sz - 2]] room.parent.halls[pos.x][pos.y][pos.z][0] = 1 room.parent.halls[pos.x][pos.y][pos.z][3] = 1 return rooms @@ -238,9 +242,9 @@ def placed(self): class Basic2x2x2(Basic): _name = 'basic2x2x2' - _min_size = Vec(2,2,2) - _max_size = Vec(2,2,2) - size = Vec(2,2,2) + _min_size = Vec(2, 2, 2) + _max_size = Vec(2, 2, 2) + size = Vec(2, 2, 2) _is_entrance = False _is_stairwell = False @@ -252,90 +256,90 @@ def placed(self): # West, South, East, North pos = self.pos rooms.append(pos) - self.hallLength = [3,0,0,3] - self.hallSize = [[2,sx-2], - [2,sx-2], - [2,sz-2], - [2,sz-2]] + self.hallLength = [3, 0, 0, 3] + self.hallSize = [[2, sx - 2], + [2, sx - 2], + [2, sz - 2], + [2, sz - 2]] self.parent.halls[pos.x][pos.y][pos.z][1] = 1 self.parent.halls[pos.x][pos.y][pos.z][2] = 1 # place three more blank rooms to hold the hallways # This is the Southern room - pos = self.pos + Vec(1,0,0) + pos = self.pos + Vec(1, 0, 0) room = new('blank', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [3,3,0,0] - room.hallSize = [[2,sx-2], - [2,sx-2], - [2,sz-2], - [2,sz-2]] + room.hallLength = [3, 3, 0, 0] + room.hallSize = [[2, sx - 2], + [2, sx - 2], + [2, sz - 2], + [2, sz - 2]] room.parent.halls[pos.x][pos.y][pos.z][2] = 1 room.parent.halls[pos.x][pos.y][pos.z][3] = 1 # Eastern room. - pos = self.pos + Vec(0,0,1) + pos = self.pos + Vec(0, 0, 1) room = new('blank', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [0,0,3,3] - room.hallSize = [[2,sx-2], - [2,sx-2], - [2,sz-2], - [2,sz-2]] + room.hallLength = [0, 0, 3, 3] + room.hallSize = [[2, sx - 2], + [2, sx - 2], + [2, sz - 2], + [2, sz - 2]] room.parent.halls[pos.x][pos.y][pos.z][0] = 1 room.parent.halls[pos.x][pos.y][pos.z][1] = 1 # South East room. - pos = self.pos + Vec(1,0,1) + pos = self.pos + Vec(1, 0, 1) room = new('blank', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [0,3,3,0] - room.hallSize = [[2,sx-2], - [2,sx-2], - [2,sz-2], - [2,sz-2]] + room.hallLength = [0, 3, 3, 0] + room.hallSize = [[2, sx - 2], + [2, sx - 2], + [2, sz - 2], + [2, sz - 2]] room.parent.halls[pos.x][pos.y][pos.z][0] = 1 room.parent.halls[pos.x][pos.y][pos.z][3] = 1 # Do it again for the bottom floor - pos = self.pos + Vec(0,1,0) + pos = self.pos + Vec(0, 1, 0) room = new('blankstairwell', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [3,0,0,3] - room.hallSize = [[2,sx-2], - [2,sx-2], - [2,sz-2], - [2,sz-2]] + room.hallLength = [3, 0, 0, 3] + room.hallSize = [[2, sx - 2], + [2, sx - 2], + [2, sz - 2], + [2, sz - 2]] room.parent.halls[pos.x][pos.y][pos.z][1] = 1 room.parent.halls[pos.x][pos.y][pos.z][2] = 1 # place three more blank rooms to hold the hallways # This is the Southern room - pos = self.pos + Vec(1,1,0) + pos = self.pos + Vec(1, 1, 0) room = new('blankstairwell', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [3,3,0,0] - room.hallSize = [[2,sx-2], - [2,sx-2], - [2,sz-2], - [2,sz-2]] + room.hallLength = [3, 3, 0, 0] + room.hallSize = [[2, sx - 2], + [2, sx - 2], + [2, sz - 2], + [2, sz - 2]] room.parent.halls[pos.x][pos.y][pos.z][2] = 1 room.parent.halls[pos.x][pos.y][pos.z][3] = 1 # Eastern room. - pos = self.pos + Vec(0,1,1) + pos = self.pos + Vec(0, 1, 1) room = new('blankstairwell', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [0,0,3,3] - room.hallSize = [[2,sx-2], - [2,sx-2], - [2,sz-2], - [2,sz-2]] + room.hallLength = [0, 0, 3, 3] + room.hallSize = [[2, sx - 2], + [2, sx - 2], + [2, sz - 2], + [2, sz - 2]] room.parent.halls[pos.x][pos.y][pos.z][0] = 1 room.parent.halls[pos.x][pos.y][pos.z][1] = 1 # South East room. - pos = self.pos + Vec(1,1,1) + pos = self.pos + Vec(1, 1, 1) room = new('blankstairwell', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [0,3,3,0] - room.hallSize = [[2,sx-2], - [2,sx-2], - [2,sz-2], - [2,sz-2]] + room.hallLength = [0, 3, 3, 0] + room.hallSize = [[2, sx - 2], + [2, sx - 2], + [2, sz - 2], + [2, sz - 2]] room.parent.halls[pos.x][pos.y][pos.z][0] = 1 room.parent.halls[pos.x][pos.y][pos.z][3] = 1 return rooms @@ -343,9 +347,9 @@ def placed(self): class GreatHallNS(Basic): _name = 'greathallns' - _min_size = Vec(1,2,2) - _max_size = Vec(1,2,2) - size = Vec(1,2,2) + _min_size = Vec(1, 2, 2) + _max_size = Vec(1, 2, 2) + size = Vec(1, 2, 2) _is_entrance = False _is_stairwell = False @@ -358,43 +362,43 @@ def placed(self): # North, East, South, West pos = self.pos rooms.append(pos) - self.hallLength = [1,1,0,1] - self.hallSize = [[2,sx-2], - [6,sx-6], - [2,sz-2], - [6,sz-6]] + self.hallLength = [1, 1, 0, 1] + self.hallSize = [[2, sx - 2], + [6, sx - 6], + [2, sz - 2], + [6, sz - 6]] self.parent.halls[pos.x][pos.y][pos.z][2] = 1 # place three more blank rooms to hold the hallways # This is the upper floor, Southern room - pos = self.pos + Vec(0,0,1) + pos = self.pos + Vec(0, 0, 1) room = new('blank', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [0,1,2,1] - room.hallSize = [[2,sx-2], - [6,sx-6], - [2,sz-2], - [6,sz-6]] + room.hallLength = [0, 1, 2, 1] + room.hallSize = [[2, sx - 2], + [6, sx - 6], + [2, sz - 2], + [6, sz - 6]] room.parent.halls[pos.x][pos.y][pos.z][0] = 1 # Northern lower room. - pos = self.pos + Vec(0,1,0) + pos = self.pos + Vec(0, 1, 0) room = new('blankstairwell', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [1,1,0,1] - room.hallSize = [[2,sx-2], - [6,sx-6], - [2,sz-2], - [6,sz-6]] + room.hallLength = [1, 1, 0, 1] + room.hallSize = [[2, sx - 2], + [6, sx - 6], + [2, sz - 2], + [6, sz - 6]] room.parent.halls[pos.x][pos.y][pos.z][2] = 1 # Southern lower room. - pos = self.pos + Vec(0,1,1) + pos = self.pos + Vec(0, 1, 1) room = new('blankstairwell', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [0,1,2,1] - room.hallSize = [[2,sx-2], - [6,sx-6], - [2,sz-2], - [6,sz-6]] + room.hallLength = [0, 1, 2, 1] + room.hallSize = [[2, sx - 2], + [6, sx - 6], + [2, sz - 2], + [6, sz - 6]] room.parent.halls[pos.x][pos.y][pos.z][0] = 1 return rooms @@ -410,10 +414,10 @@ def setData(self): sy = self.size.y * self.parent.room_height # Some paramters. - self.c1 = self.loc + Vec(0,sy-2,0) - self.c2 = self.c1 + Vec(sx-1, 0, 0) - self.c3 = self.c1 + Vec(sx-1, 0, sz-1) - self.c4 = self.c1 + Vec(0, 0, sz-1) + self.c1 = self.loc + Vec(0, sy - 2, 0) + self.c2 = self.c1 + Vec(sx - 1, 0, 0) + self.c3 = self.c1 + Vec(sx - 1, 0, sz - 1) + self.c4 = self.c1 + Vec(0, 0, sz - 1) if sz > sx: self.c3 = self.c3.n(1) self.c4 = self.c4.n(1) @@ -421,18 +425,18 @@ def setData(self): else: self.c2 = self.c2.w(1) self.c3 = self.c3.w(1) - sx -=1 + sx -= 1 - self.hallLength = [3,3,3,3] - self.hallSize = [[2,sx-2], - [2,sx-2], - [2,sz-2], - [2,sz-2]] + self.hallLength = [3, 3, 3, 3] + self.hallSize = [[2, sx - 2], + [2, sx - 2], + [2, sz - 2], + [2, sz - 2]] self.canvas = ( - Vec(4 ,sy-2, 4), - Vec(sx-5,sy-2, 4), - Vec(sx-5,sy-2, sz-5), - Vec(4 ,sy-2, sz-5)) + Vec(4, sy - 2, 4), + Vec(sx - 5, sy - 2, 4), + Vec(sx - 5, sy - 2, sz - 5), + Vec(4, sy - 2, sz - 5)) def render(self): height = self.size.y * self.parent.room_height - 2 @@ -452,28 +456,33 @@ def render(self): sf1 = self.loc.trans(0, self.size.y * self.parent.room_height - 1, 0) - sf2 = sf1.trans(self.size.x * self.parent.room_size-1, - 0, - self.size.z * self.parent.room_size-1) + sf2 = sf1.trans(self.size.x * self.parent.room_size - 1, + 0, + self.size.z * self.parent.room_size - 1) for x in iterate_plane(sf1, sf2): self.parent.setblock(x, materials._subfloor) # balcony - mat = random.choice(( - (materials.CobblestoneSlab,materials.meta_mossycobble,materials.meta_mossycobblewall), - (materials.StoneBrickSlab,materials.StoneBrick,materials.IronBars), - (materials.OakWoodSlab,materials.OakWoodPlanks,materials.Fence) - )) - for p in iterate_four_walls(self.c1+Vec(1,-6,1), - self.c3+Vec(-1,-6,-1),0): + mat = random.choice( + ((materials.CobblestoneSlab, + materials.meta_mossycobble, + materials.meta_mossycobblewall), + (materials.StoneBrickSlab, + materials.StoneBrick, + materials.IronBars), + (materials.OakWoodSlab, + materials.OakWoodPlanks, + materials.Fence))) + for p in iterate_four_walls(self.c1 + Vec(1, -6, 1), + self.c3 + Vec(-1, -6, -1), 0): self.parent.setblock(p, mat[0]) - for p in iterate_four_walls(self.c1+Vec(2,-6,2), - self.c3+Vec(-2,-6,-2),0): + for p in iterate_four_walls(self.c1 + Vec(2, -6, 2), + self.c3 + Vec(-2, -6, -2), 0): self.parent.setblock(p, mat[0]) - for p in iterate_four_walls(self.c1+Vec(3,-6,3), - self.c3+Vec(-3,-6,-3),0): + for p in iterate_four_walls(self.c1 + Vec(3, -6, 3), + self.c3 + Vec(-3, -6, -3), 0): self.parent.setblock(p, mat[1]) - for p in iterate_four_walls(self.c1+Vec(3,-7,3), - self.c3+Vec(-3,-7,-3),0): + for p in iterate_four_walls(self.c1 + Vec(3, -7, 3), + self.c3 + Vec(-3, -7, -3), 0): self.parent.setblock(p, mat[2]) # Columns mat = random.choice(( @@ -486,45 +495,45 @@ def render(self): )) for n in xrange(0, 26, 3): if self.size.x > self.size.z: - p = self.c1+Vec(3+n,-1,3) - d = Vec(0,0,9) + p = self.c1 + Vec(3 + n, -1, 3) + d = Vec(0, 0, 9) else: - p = self.c1+Vec(3,-1,3+n) - d = Vec(9,0,0) + p = self.c1 + Vec(3, -1, 3 + n) + d = Vec(9, 0, 0) for q in iterate_cube(p, p.up(height)): self.parent.setblock(q, mat[0]) - self.parent.setblock(q+d, mat[0]) + self.parent.setblock(q + d, mat[0]) self.parent.setblock(p, mat[1]) - self.parent.setblock(p+d, mat[1]) + self.parent.setblock(p + d, mat[1]) # Chandeliers # Type A - if (random.randint(1,100) <= 50): + if (random.randint(1, 100) <= 50): mat = random.choice(( materials.Fence, materials.IronBars )) - s = self.parent.room_size-1 + s = self.parent.room_size - 1 for x in xrange(self.size.x): for z in xrange(self.size.z): - p = self.c1+Vec(x*s+s/2+random.randint(0,1), - -height+1, - z*s+s/2+random.randint(0,1)) - for y in xrange(random.randint(1,2)): + p = self.c1 + Vec(x * s + s / 2 + random.randint(0, 1), + -height + 1, + z * s + s / 2 + random.randint(0, 1)) + for y in xrange(random.randint(1, 2)): self.parent.setblock(p, mat) p = p.down(1) - for q in iterate_cube(p+Vec(-1,0,-1), p+Vec(1,0,1)): + for q in iterate_cube(p + Vec(-1, 0, -1), p + Vec(1, 0, 1)): self.parent.setblock(q, mat) - if (random.randint(1,100) <= 33): + if (random.randint(1, 100) <= 33): self.parent.setblock(p, materials.Torch) self.parent.setblock(p.down(1), materials.Fence) # Type B - Hanging pendant else: - s = self.parent.room_size-1 + s = self.parent.room_size - 1 for x in xrange(self.size.x): for z in xrange(self.size.z): - p = self.c1+Vec(x*s+s/2+random.randint(0,1), - -height+1, - z*s+s/2+random.randint(0,1)) + p = self.c1 + Vec(x * s + s / 2 + random.randint(0, 1), + -height + 1, + z * s + s / 2 + random.randint(0, 1)) self.parent.setblock(p, materials.Fence) self.parent.setblock(p.down(1), materials.Fence) self.parent.setblock(p.down(2), materials.Piston, 1) @@ -533,37 +542,37 @@ def render(self): self.parent.setblock(p.down(5), materials.Fence) p = p.down(3) self.parent.setblock(p.n(1), - materials.Trapdoor,4+0,hide=True) + materials.Trapdoor, 4 + 0, hide=True) self.parent.setblock(p.s(1), - materials.Trapdoor,4+1,hide=True) + materials.Trapdoor, 4 + 1, hide=True) self.parent.setblock(p.e(1), - materials.Trapdoor,4+3,hide=True) + materials.Trapdoor, 4 + 3, hide=True) self.parent.setblock(p.w(1), - materials.Trapdoor,4+2,hide=True) + materials.Trapdoor, 4 + 2, hide=True) # Vines - if (random.randint(1,100) <= 25): - for p in iterate_cube(self.c1+Vec(1,-1,1), - self.c3+Vec(-1, -height+1, -1)): - if random.randint(1,100) <= 20: + if (random.randint(1, 100) <= 25): + for p in iterate_cube(self.c1 + Vec(1, -1, 1), + self.c3 + Vec(-1, -height + 1, -1)): + if random.randint(1, 100) <= 20: self.parent.vines(p, grow=True) # Cobwebs - if (random.randint(1,100) > 25): + if (random.randint(1, 100) > 25): return webs = {} - for p in iterate_cube(self.c1+Vec(1,-1,1), - self.c3+Vec(-1, -height+1, -1)): + for p in iterate_cube(self.c1 + Vec(1, -1, 1), + self.c3 + Vec(-1, -height + 1, -1)): count = 0 - perc = 90 - (p.y - self.loc.down(1).y) * (70/3) + perc = 90 - (p.y - self.loc.down(1).y) * (70 / 3) if (p not in self.parent.blocks or - self.parent.blocks[p].material != materials.Air): + self.parent.blocks[p].material != materials.Air): continue - for q in (Vec(1,0,0), Vec(-1,0,0), - Vec(0,1,0), Vec(0,-1,0), - Vec(0,0,1), Vec(0,0,-1)): - if (p+q in self.parent.blocks and - self.parent.blocks[p+q].material != materials.Air and - random.randint(1,100) <= perc): + for q in (Vec(1, 0, 0), Vec(-1, 0, 0), + Vec(0, 1, 0), Vec(0, -1, 0), + Vec(0, 0, 1), Vec(0, 0, -1)): + if (p + q in self.parent.blocks and + self.parent.blocks[p + q].material != materials.Air and + random.randint(1, 100) <= perc): count += 1 if count >= 3: webs[p] = True @@ -573,9 +582,9 @@ def render(self): class GreatHallEW(GreatHallNS): _name = 'greathallew' - _min_size = Vec(2,2,1) - _max_size = Vec(2,2,1) - size = Vec(2,2,1) + _min_size = Vec(2, 2, 1) + _max_size = Vec(2, 2, 1) + size = Vec(2, 2, 1) _is_entrance = False _is_stairwell = False @@ -588,43 +597,43 @@ def placed(self): # North, East, South, West pos = self.pos rooms.append(pos) - self.hallLength = [1,0,1,1] - self.hallSize = [[6,sx-6], - [2,sx-2], - [6,sz-6], - [2,sz-2]] + self.hallLength = [1, 0, 1, 1] + self.hallSize = [[6, sx - 6], + [2, sx - 2], + [6, sz - 6], + [2, sz - 2]] self.parent.halls[pos.x][pos.y][pos.z][1] = 1 # place three more blank rooms to hold the hallways # This is the upper floor, Eastern room - pos = self.pos + Vec(1,0,0) + pos = self.pos + Vec(1, 0, 0) room = new('blank', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [1,2,1,0] - room.hallSize = [[6,sx-6], - [2,sx-2], - [6,sz-6], - [2,sz-2]] + room.hallLength = [1, 2, 1, 0] + room.hallSize = [[6, sx - 6], + [2, sx - 2], + [6, sz - 6], + [2, sz - 2]] room.parent.halls[pos.x][pos.y][pos.z][3] = 1 # Western lower room. - pos = self.pos + Vec(0,1,0) + pos = self.pos + Vec(0, 1, 0) room = new('blank', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [1,0,1,1] - room.hallSize = [[6,sx-6], - [2,sx-2], - [6,sz-6], - [2,sz-2]] + room.hallLength = [1, 0, 1, 1] + room.hallSize = [[6, sx - 6], + [2, sx - 2], + [6, sz - 6], + [2, sz - 2]] room.parent.halls[pos.x][pos.y][pos.z][1] = 1 # Easterb lower room. - pos = self.pos + Vec(1,1,0) + pos = self.pos + Vec(1, 1, 0) room = new('blank', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [1,2,1,0] - room.hallSize = [[6,sx-6], - [2,sx-2], - [6,sz-6], - [2,sz-2]] + room.hallLength = [1, 2, 1, 0] + room.hallSize = [[6, sx - 6], + [2, sx - 2], + [6, sz - 6], + [2, sz - 2]] room.parent.halls[pos.x][pos.y][pos.z][3] = 1 return rooms @@ -639,7 +648,7 @@ def setData(self): Basic2x2.setData(self) self.features.append(features.new('blank', self)) #self.floors.append(floors.new('brokendoubleslab', self)) - self.combo = random.randint(1,62) + self.combo = random.randint(1, 62) def placed(self): rooms = Basic2x2.placed(self) @@ -648,10 +657,10 @@ def placed(self): #sy = self.parent.room_height for room in rooms: r = self.parent.rooms[room] - r.hallSize = [[6,sx-6], - [6,sx-6], - [6,sz-6], - [6,sz-6]] + r.hallSize = [[6, sx - 6], + [6, sx - 6], + [6, sz - 6], + [6, sz - 6]] return rooms def render(self): @@ -662,76 +671,76 @@ def render(self): self.floors = [] self.floors.append(floors.new('brokenstonebrick', self)) # Build some cells. They have doors. - s = self.c1+Vec(2,-1,2) + s = self.c1 + Vec(2, -1, 2) chest_rate = 80 spawner_rate = 80 - for p in iterate_cube(Vec(0,0,0), Vec(3,0,3)): - if p in ([Vec(1,0,1), Vec(1,0,2), - Vec(2,0,1), Vec(2,0,2)]): + for p in iterate_cube(Vec(0, 0, 0), Vec(3, 0, 3)): + if p in ([Vec(1, 0, 1), Vec(1, 0, 2), + Vec(2, 0, 1), Vec(2, 0, 2)]): continue - ss = s+p*6 + ss = s + p * 6 if p.x > 1: - ss = ss + Vec(1,0,0) + ss = ss + Vec(1, 0, 0) if p.z > 1: - ss = ss + Vec(0,0,1) - for pp in iterate_four_walls(ss, ss+Vec(4,0,4), 2): + ss = ss + Vec(0, 0, 1) + for pp in iterate_four_walls(ss, ss + Vec(4, 0, 4), 2): self.parent.setblock(pp, materials._wall) - doffset = Vec(4,0,2) + doffset = Vec(4, 0, 2) ddata = 3 if p.x > 1: - doffset = Vec(0,0,2) + doffset = Vec(0, 0, 2) ddata = 1 - self.parent.setblock(ss+doffset, - materials.IronDoor, ddata+4) - self.parent.setblock(ss+doffset.up(1), + self.parent.setblock(ss + doffset, + materials.IronDoor, ddata + 4) + self.parent.setblock(ss + doffset.up(1), materials.IronDoor, 8) - self.parent.setblock(ss+doffset.up(2), + self.parent.setblock(ss + doffset.up(2), materials._wall, hide=True) # Extra chests for solving the combo. - if (random.randint(1,100) <= chest_rate): + if (random.randint(1, 100) <= chest_rate): chest_rate /= 2 - cp = ss+doffset+Vec(-3,0,0) + cp = ss + doffset + Vec(-3, 0, 0) if p.x > 1: - cp = ss+doffset+Vec(3,0,0) + cp = ss + doffset + Vec(3, 0, 0) self.parent.setblock(cp, materials.Chest) self.parent.addchest(cp) # Extra spawners becuase I'm a bastard. - elif (random.randint(1,100) <= spawner_rate): + elif (random.randint(1, 100) <= spawner_rate): spawner_rate /= 2 - cp = ss+doffset+Vec(-3,0,0) + cp = ss + doffset + Vec(-3, 0, 0) if p.x > 1: - cp = ss+doffset+Vec(3,0,0) + cp = ss + doffset + Vec(3, 0, 0) self.parent.setblock(cp, materials.Spawner) self.parent.addspawner(cp) - # A central dais with a slab step around it. - # Hollow out the area under for circuits. - for p in iterate_cube(self.c1+Vec(10,-1,10), - self.c3-Vec(10, 1,10)): + # A central dais with a slab step around it. + # Hollow out the area under for circuits. + for p in iterate_cube(self.c1 + Vec(10, -1, 10), + self.c3 - Vec(10, 1, 10)): self.parent.setblock(p, materials._floor) self.parent.setblock(p.down(1), materials.Air, lock=True) - for p in iterate_four_walls(self.c1+Vec(10,-1,10), - self.c3-Vec(10, 1,10), 0): + for p in iterate_four_walls(self.c1 + Vec(10, -1, 10), + self.c3 - Vec(10, 1, 10), 0): self.parent.setblock(p, materials.StoneSlab) # Redstone triggers under the plates # Build a lookup table for the combo lock # True == on (plate depressed) # False == off - cbits = {'0': self.combo&1>0, - '1': self.combo&2>0, - '2': self.combo&4>0, - '3': self.combo&8>0, - '4': self.combo&16>0, - '5': self.combo&32>0, - } + cbits = {'0': self.combo & 1 > 0, + '1': self.combo & 2 > 0, + '2': self.combo & 4 > 0, + '3': self.combo & 8 > 0, + '4': self.combo & 16 > 0, + '5': self.combo & 32 > 0, + } ctext1 = '' ctext2 = '' # South bit = 1 - for p in iterate_cube(self.c1+Vec(14, 1,11), - self.c3-Vec(13,-1,11)): - if ((p.x+p.z)%2 == 0): - if cbits[str(bit)] == True: + for p in iterate_cube(self.c1 + Vec(14, 1, 11), + self.c3 - Vec(13, -1, 11)): + if ((p.x + p.z) % 2 == 0): + if cbits[str(bit)]: charge = 15 torch = materials.RedstoneTorchOn repeater = materials.RedstoneRepeaterOn @@ -752,10 +761,10 @@ def render(self): bit += 2 # North bit = 0 - for p in iterate_cube(self.c1+Vec(13, 1,11), - self.c3-Vec(14,-1,11)): - if ((p.x+p.z)%2 == 0): - if cbits[str(bit)] == True: + for p in iterate_cube(self.c1 + Vec(13, 1, 11), + self.c3 - Vec(14, -1, 11)): + if ((p.x + p.z) % 2 == 0): + if cbits[str(bit)]: charge = 15 torch = materials.RedstoneTorchOn repeater = materials.RedstoneRepeaterOn @@ -774,8 +783,8 @@ def render(self): self.parent.setblock(p.w(3), materials.RedstoneWire, charge, lock=True) bit += 2 - self.parent.setblock(self.c1+Vec(7,-2,12), materials.WallSign, 5) - self.parent.addsign(self.c1+Vec(7,-2,12), + self.parent.setblock(self.c1 + Vec(7, -2, 12), materials.WallSign, 5) + self.parent.addsign(self.c1 + Vec(7, -2, 12), '--==+==--', 'Cell Block', str(self.combo), @@ -788,158 +797,163 @@ def render(self): note['tag']['title'] = nbt.TAG_String("Cell Combination") note['tag']['author'] = nbt.TAG_String("Unknown") note['tag']['pages'] = nbt.TAG_List() - words = "Level: "+str(self.pos.y+1)+"\n\n"+ctext1+"\n"+ctext2 + words = "Level: " + \ + str(self.pos.y + 1) + "\n\n" + ctext1 + "\n" + ctext2 note['tag']['pages'].append(nbt.TAG_String(words)) - max_lev = (self.c1.y//self.parent.room_height) + max_lev = (self.c1.y // self.parent.room_height) self.parent.addplaceditem(note, max_lev=max_lev) # Inner bus - for p in iterate_four_walls(self.c1+Vec(9, 1,9), - self.c3-Vec(9,-1,9),0): + for p in iterate_four_walls(self.c1 + Vec(9, 1, 9), + self.c3 - Vec(9, -1, 9), 0): self.parent.setblock(p, materials.RedstoneWire, 15, lock=True) - self.parent.setblock(self.c1+Vec(10,1,18), + self.parent.setblock(self.c1 + Vec(10, 1, 18), materials.RedstoneRepeaterOff, 1, lock=True) - self.parent.setblock(self.c3-Vec(10,-1,18), + self.parent.setblock(self.c3 - Vec(10, -1, 18), materials.RedstoneRepeaterOff, 3, lock=True) # East / West Bus - for p in iterate_cube(self.c1+Vec(6,1,6), self.c4+Vec(6,1,-6)): + for p in iterate_cube(self.c1 + Vec(6, 1, 6), self.c4 + Vec(6, 1, -6)): self.parent.setblock(p, materials.RedstoneWire, 15, lock=True) self.parent.setblock(p.e(15), materials.RedstoneWire, 15, lock=True) - for p in iterate_cube(Vec(7,1,7), Vec(12,1,7)): - q = self.c1+p + for p in iterate_cube(Vec(7, 1, 7), Vec(12, 1, 7)): + q = self.c1 + p self.parent.setblock(q, materials.RedstoneWire, 15, lock=True) self.parent.setblock(q.e(8), materials.RedstoneWire, 15, lock=True) - q = self.c4+Vec(p.x, p.y, -p.z) + q = self.c4 + Vec(p.x, p.y, -p.z) self.parent.setblock(q, materials.RedstoneWire, 15, lock=True) self.parent.setblock(q.e(8), materials.RedstoneWire, 15, lock=True) - for p in [Vec(6,0,6), Vec(6,0,8), Vec(12,0,6)]: - q = self.c1+p + for p in [Vec(6, 0, 6), Vec(6, 0, 8), Vec(12, 0, 6)]: + q = self.c1 + p self.parent.setblock(q, materials.Air, lock=True) - q = self.c2+Vec(-p.x, p.y, p.z) + q = self.c2 + Vec(-p.x, p.y, p.z) self.parent.setblock(q, materials.Air, lock=True) - q = self.c3+Vec(-p.x, p.y, -p.z) + q = self.c3 + Vec(-p.x, p.y, -p.z) self.parent.setblock(q, materials.Air, lock=True) - q = self.c4+Vec(p.x, p.y, -p.z) + q = self.c4 + Vec(p.x, p.y, -p.z) self.parent.setblock(q, materials.Air, lock=True) - for p in [Vec(6,0,5), Vec(6,0,9), Vec(12,0,5), Vec(12,1,6)]: - q = self.c1+p + for p in [Vec(6, 0, 5), Vec(6, 0, 9), Vec(12, 0, 5), Vec(12, 1, 6)]: + q = self.c1 + p self.parent.setblock(q, materials.RedstoneWire, 15, lock=True) self.parent.setblock(q.down(1), materials._ceiling, lock=True) - q = self.c2+Vec(-p.x, p.y, p.z) + q = self.c2 + Vec(-p.x, p.y, p.z) self.parent.setblock(q, materials.RedstoneWire, 15, lock=True) self.parent.setblock(q.down(1), materials._ceiling, lock=True) - q = self.c3+Vec(-p.x, p.y, -p.z) + q = self.c3 + Vec(-p.x, p.y, -p.z) self.parent.setblock(q, materials.RedstoneWire, 15, lock=True) self.parent.setblock(q.down(1), materials._ceiling, lock=True) - q = self.c4+Vec(p.x, p.y, -p.z) + q = self.c4 + Vec(p.x, p.y, -p.z) self.parent.setblock(q, materials.RedstoneWire, 15, lock=True) self.parent.setblock(q.down(1), materials._ceiling, lock=True) - self.parent.setblock(self.c1+Vec(6,1,10), + self.parent.setblock(self.c1 + Vec(6, 1, 10), materials.RedstoneRepeaterOn, 0, lock=True) - self.parent.setblock(self.c1+Vec(6,1,17), + self.parent.setblock(self.c1 + Vec(6, 1, 17), materials.RedstoneRepeaterOn, 2, lock=True) - self.parent.setblock(self.c1+Vec(21,1,10), + self.parent.setblock(self.c1 + Vec(21, 1, 10), materials.RedstoneRepeaterOn, 0, lock=True) - self.parent.setblock(self.c1+Vec(21,1,17), + self.parent.setblock(self.c1 + Vec(21, 1, 17), materials.RedstoneRepeaterOn, 2, lock=True) - self.parent.setblock(self.c1+Vec(8,1,13), + self.parent.setblock(self.c1 + Vec(8, 1, 13), materials.RedstoneRepeaterOn, 3, lock=True) - self.parent.setblock(self.c1+Vec(19,1,14), + self.parent.setblock(self.c1 + Vec(19, 1, 14), materials.RedstoneRepeaterOn, 1, lock=True) - self.parent.setblock(self.c1+Vec(7,1,13), + self.parent.setblock(self.c1 + Vec(7, 1, 13), materials.RedstoneWire, 15, lock=True) - self.parent.setblock(self.c1+Vec(20,1,14), + self.parent.setblock(self.c1 + Vec(20, 1, 14), materials.RedstoneWire, 15, lock=True) # Wooden pressure plates - for p in iterate_cube(self.c1+Vec(13,-2,11), - self.c3-Vec(13, 2,11)): - if ((p.x+p.z)%2 == 0): + for p in iterate_cube(self.c1 + Vec(13, -2, 11), + self.c3 - Vec(13, 2, 11)): + if ((p.x + p.z) % 2 == 0): self.parent.setblock(p, materials.WoodenPressurePlate) # Torches - for p in [self.c1+Vec(11,-2,11), self.c2+Vec(-11,-2,11), - self.c3+Vec(-11,-2,-11), self.c4+Vec(11,-2,-11)]: + for p in [self.c1 + Vec(11, -2, 11), self.c2 + Vec(-11, -2, 11), + self.c3 + Vec(-11, -2, -11), self.c4 + Vec(11, -2, -11)]: self.parent.setblock(p, materials.Fence) self.parent.setblock(p.up(1), materials.Torch) # Zelda tune # 13,12,9,3,2,10,14,18 - self.parent.setblock(self.c1+Vec(5,1,19), + self.parent.setblock(self.c1 + Vec(5, 1, 19), materials.RedstoneRepeaterOn, 15, lock=True) - self.parent.setblock(self.c1+Vec(3,1,19), + self.parent.setblock(self.c1 + Vec(3, 1, 19), materials.RedstoneTorchOn, 2, lock=True) - self.parent.setblock(self.c1+Vec(2,1,19), + self.parent.setblock(self.c1 + Vec(2, 1, 19), materials.RedstoneWire, 0, lock=True) - self.parent.setblock(self.c1+Vec(1,1,18), + self.parent.setblock(self.c1 + Vec(1, 1, 18), materials.RedstoneWire, 0, lock=True) - for p in iterate_cube(self.c1+Vec(2,1,19), self.c1+Vec(2,1,2)): + for p in iterate_cube(self.c1 + Vec(2, 1, 19), self.c1 + Vec(2, 1, 2)): self.parent.setblock(p, materials.RedstoneWire, 0, lock=True) - for p in iterate_cube(self.c1+Vec(2,1,17), self.c1+Vec(2,1,9)): - if (p.z%2 == 1): - self.parent.setblock(p, - materials.RedstoneRepeaterOff, 4, lock=True) - self.parent.setblock(p+Vec(-1,0,-1), + for p in iterate_cube(self.c1 + Vec(2, 1, 17), self.c1 + Vec(2, 1, 9)): + if (p.z % 2 == 1): + self.parent.setblock( + p, + materials.RedstoneRepeaterOff, + 4, + lock=True) + self.parent.setblock(p + Vec(-1, 0, -1), materials.RedstoneWire, 0, lock=True) - self.parent.setblock(self.c1+Vec(2,1,3), + self.parent.setblock(self.c1 + Vec(2, 1, 3), materials.RedstoneRepeaterOff, 4, lock=True) - self.parent.setblock(self.c1+Vec(1,1,2), + self.parent.setblock(self.c1 + Vec(1, 1, 2), materials.RedstoneWire, 0, lock=True) - self.parent.setblock(self.c1+Vec(2,1,5), + self.parent.setblock(self.c1 + Vec(2, 1, 5), materials.RedstoneRepeaterOff, 4, lock=True) - self.parent.setblock(self.c1+Vec(1,1,4), + self.parent.setblock(self.c1 + Vec(1, 1, 4), materials.RedstoneWire, 0, lock=True) - for z, p in [(18,13),(16,12),(14,9),(12,3),(10,2),(8,10),(4,14),(2,18)]: - self.parent.setblock(self.c1+Vec(0,2,z), + for z, p in [(18, 13), (16, 12), (14, 9), (12, 3), (10, 2), (8, 10), (4, 14), (2, 18)]: + self.parent.setblock(self.c1 + Vec(0, 2, z), materials.Dirt, lock=True, hide=True) - self.parent.setblock(self.c1+Vec(0,1,z), + self.parent.setblock(self.c1 + Vec(0, 1, z), materials.NoteBlock, lock=True) - self.parent.addnoteblock(self.c1+Vec(0,1,z), p) - self.parent.setblock(self.c1+Vec(0,0,z), + self.parent.addnoteblock(self.c1 + Vec(0, 1, z), p) + self.parent.setblock(self.c1 + Vec(0, 0, z), materials.Air, lock=True) + class ThroneRoom(Basic): _name = 'throneroom' _is_entrance = False _is_stairwell = False _is_treasureroom = True - _min_size = Vec(1,1,2) - _max_size = Vec(1,1,2) - size = Vec(1,1,2) + _min_size = Vec(1, 1, 2) + _max_size = Vec(1, 1, 2) + size = Vec(1, 1, 2) def placed(self): self.canvas = ( - Vec(0,self.parent.room_height-2,0), - Vec(0,self.parent.room_height-2,0), - Vec(0,self.parent.room_height-2,0)) + Vec(0, self.parent.room_height - 2, 0), + Vec(0, self.parent.room_height - 2, 0), + Vec(0, self.parent.room_height - 2, 0)) rooms = [] sx = self.parent.room_size sz = self.parent.room_size #sy = self.parent.room_height - # This room contains no halls, but is connected to the East + # This room contains no halls, but is connected to the East # West, South, East, North pos = self.pos rooms.append(pos) - self.hallLength = [1,1,0,1] - self.hallSize = [[6,sx-6], - [6,sx-6], - [6,sz-6], - [6,sz-6]] - self.parent.halls[pos.x][pos.y][pos.z] = [0,0,1,0] + self.hallLength = [1, 1, 0, 1] + self.hallSize = [[6, sx - 6], + [6, sx - 6], + [6, sz - 6], + [6, sz - 6]] + self.parent.halls[pos.x][pos.y][pos.z] = [0, 0, 1, 0] # Place one room to the East # This room can have halls N, E, or S and is connected to the West - pos = self.pos + Vec(0,0,1) + pos = self.pos + Vec(0, 0, 1) room = new('blank', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [0,0,0,0] - room.hallSize = [[6,sx-6], - [6,sx-6], - [6,sz-6], - [6,sz-6]] - room.parent.halls[pos.x][pos.y][pos.z] = [1,1,1,1] + room.hallLength = [0, 0, 0, 0] + room.hallSize = [[6, sx - 6], + [6, sx - 6], + [6, sz - 6], + [6, sz - 6]] + room.parent.halls[pos.x][pos.y][pos.z] = [1, 1, 1, 1] # This room cannot connect. Make the depth < 0 room.parent.maze[pos].depth = -1 return rooms @@ -954,10 +968,10 @@ def render(self): # alias for setblock sb = self.parent.setblock - # symmetrical setblock. A lot of this room will be symmetrical. - def ssb (p, mat, data=0): - sb(o+p, mat, data) - sb(Vec(o.x+sx-1-p.x, o.y+p.y, o.z+p.z), mat, data) + # symmetrical setblock. A lot of this room will be symmetrical. + def ssb(p, mat, data=0): + sb(o + p, mat, data) + sb(Vec(o.x + sx - 1 - p.x, o.y + p.y, o.z + p.z), mat, data) # Column materials cmat = random.choice([ @@ -981,137 +995,137 @@ def ssb (p, mat, data=0): # Basic room # Air space - for p in iterate_cube(o, o+Vec(sx-1,sy-1,sz-1)): + for p in iterate_cube(o, o + Vec(sx - 1, sy - 1, sz - 1)): sb(p, materials.Air) # Walls - for p in iterate_four_walls(o, o+Vec(sx-1,0,sz-1), -sy+1): + for p in iterate_four_walls(o, o + Vec(sx - 1, 0, sz - 1), -sy + 1): sb(p, materials._wall) # Ceiling and floor - for p in iterate_cube(o, o+Vec(sx-1,0,sz-1)): + for p in iterate_cube(o, o + Vec(sx - 1, 0, sz - 1)): sb(p, materials._ceiling) - sb(p.down(sy-1), materials._floor) + sb(p.down(sy - 1), materials._floor) # Wooden balcony - for p in iterate_cube(Vec(1,4,1), Vec(3,4,9)): + for p in iterate_cube(Vec(1, 4, 1), Vec(3, 4, 9)): ssb(p, materials.OakWoodPlanks) - for p in iterate_cube(Vec(1,4,1), Vec(5,4,3)): + for p in iterate_cube(Vec(1, 4, 1), Vec(5, 4, 3)): ssb(p, materials.OakWoodPlanks) - for p in iterate_cube(Vec(1,4,1), Vec(2,4,8)): + for p in iterate_cube(Vec(1, 4, 1), Vec(2, 4, 8)): ssb(p, materials.OakWoodSlab) - for p in iterate_cube(Vec(1,4,1), Vec(5,4,2)): + for p in iterate_cube(Vec(1, 4, 1), Vec(5, 4, 2)): ssb(p, materials.OakWoodSlab) - for p in iterate_cube(Vec(1,3,9), Vec(2,3,9)): + for p in iterate_cube(Vec(1, 3, 9), Vec(2, 3, 9)): ssb(p, materials.Fence) - for p in iterate_cube(Vec(4,3,3), Vec(5,3,3)): + for p in iterate_cube(Vec(4, 3, 3), Vec(5, 3, 3)): ssb(p, materials.Fence) - for p in iterate_cube(Vec(3,3,3), Vec(3,3,9)): + for p in iterate_cube(Vec(3, 3, 3), Vec(3, 3, 9)): ssb(p, materials.Fence) # Entry stairs for x in xrange(6): - ssb(Vec(6,5+x,1+x), materials.meta_mossycobble) - ssb(Vec(7,5+x,1+x), materials.meta_mossycobble) - ssb(Vec(6,5+x,2+x), materials.meta_mossycobble) - ssb(Vec(7,5+x,2+x), materials.meta_mossycobble) - ssb(Vec(6,5+x,3+x), materials.StoneStairs, 3) - ssb(Vec(7,5+x,3+x), materials.StoneStairs, 3) + ssb(Vec(6, 5 + x, 1 + x), materials.meta_mossycobble) + ssb(Vec(7, 5 + x, 1 + x), materials.meta_mossycobble) + ssb(Vec(6, 5 + x, 2 + x), materials.meta_mossycobble) + ssb(Vec(7, 5 + x, 2 + x), materials.meta_mossycobble) + ssb(Vec(6, 5 + x, 3 + x), materials.StoneStairs, 3) + ssb(Vec(7, 5 + x, 3 + x), materials.StoneStairs, 3) # Skip this is ther is no door to the West if self.parent.halls[pos.x][pos.y][pos.z][0] == 1: - for p in iterate_cube(Vec(6,4,1), Vec(7,4,1)): + for p in iterate_cube(Vec(6, 4, 1), Vec(7, 4, 1)): ssb(p, materials.StoneStairs, 3) # Columns for i in xrange(6): - j = i*4 - for p in iterate_cube(Vec(3,0,4+j), Vec(3,11,5+j)): + j = i * 4 + for p in iterate_cube(Vec(3, 0, 4 + j), Vec(3, 11, 5 + j)): ssb(p, cmat[0]) - ssb(Vec(4,10,4+j), cmat[1]) - ssb(Vec(4,10,5+j), cmat[1]) + ssb(Vec(4, 10, 4 + j), cmat[1]) + ssb(Vec(4, 10, 5 + j), cmat[1]) # Rug - for p in iterate_cube(Vec(6,11,9), Vec(6,11,25)): + for p in iterate_cube(Vec(6, 11, 9), Vec(6, 11, 25)): ssb(p, dmat[1]) - for p in iterate_cube(Vec(7,11,9), Vec(7,11,25)): + for p in iterate_cube(Vec(7, 11, 9), Vec(7, 11, 25)): ssb(p, dmat[0]) for x in xrange(20): - p = Vec(random.randint(6,9), 11, random.randint(9,25)) - sb(o+p, materials._floor) + p = Vec(random.randint(6, 9), 11, random.randint(9, 25)) + sb(o + p, materials._floor) # Throne # Stairs for x in xrange(3): - ssb(Vec(7,10-x,24+x), materials.StoneStairs, 2) - ssb(Vec(7,10-x,25+x), materials.meta_mossycobble) - ssb(Vec(7,10-x,26+x), materials.meta_mossycobble) + ssb(Vec(7, 10 - x, 24 + x), materials.StoneStairs, 2) + ssb(Vec(7, 10 - x, 25 + x), materials.meta_mossycobble) + ssb(Vec(7, 10 - x, 26 + x), materials.meta_mossycobble) # Platform - for p in iterate_cube(Vec(6,8,27), Vec(7,10,27)): + for p in iterate_cube(Vec(6, 8, 27), Vec(7, 10, 27)): ssb(p, materials.Bedrock) - for p in iterate_cube(Vec(5,8,28), Vec(7,10,29)): + for p in iterate_cube(Vec(5, 8, 28), Vec(7, 10, 29)): ssb(p, materials.Bedrock) # Lava bucket - ssb(Vec(6,10,30), materials.meta_mossycobble) - ssb(Vec(6,9,30), materials.meta_mossycobble) - ssb(Vec(7,11,30), materials.Lava) + ssb(Vec(6, 10, 30), materials.meta_mossycobble) + ssb(Vec(6, 9, 30), materials.meta_mossycobble) + ssb(Vec(7, 11, 30), materials.Lava) # The throne - ssb(Vec(7,7,29), materials.OakWoodPlanks) - ssb(Vec(7,6,29), materials.OakWoodPlanks) - sb(o+Vec(7,7,28), materials.OakWoodStairs, 1) - sb(o+Vec(8,7,28), materials.OakWoodStairs, 0) - sb(o+Vec(6,6,29), materials.RedstoneTorchOn, 2) - sb(o+Vec(9,6,29), materials.RedstoneTorchOn, 1) - ssb(Vec(7,5,29), materials.Fence) - ssb(Vec(7,4,29), materials.RedstoneTorchOn, 5) + ssb(Vec(7, 7, 29), materials.OakWoodPlanks) + ssb(Vec(7, 6, 29), materials.OakWoodPlanks) + sb(o + Vec(7, 7, 28), materials.OakWoodStairs, 1) + sb(o + Vec(8, 7, 28), materials.OakWoodStairs, 0) + sb(o + Vec(6, 6, 29), materials.RedstoneTorchOn, 2) + sb(o + Vec(9, 6, 29), materials.RedstoneTorchOn, 1) + ssb(Vec(7, 5, 29), materials.Fence) + ssb(Vec(7, 4, 29), materials.RedstoneTorchOn, 5) # Back wall wall = random.choice( [ # Creeper - [[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], - [0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0], - [0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0], - [0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0], - [0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0], - [0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0], - [0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]], + [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], + [0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], # Wings - [[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0], - [0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0], - [0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0], - [0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0], - [0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0], - [0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]], + [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0], + [0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0], + [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0], + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], # Triforce - [[0,0,0,0,0,0,2,2,2,2,0,0,0,0,0,0], - [0,0,0,0,0,2,0,2,2,0,2,0,0,0,0,0], - [0,0,0,0,3,0,2,2,2,2,0,3,0,0,0,0], - [0,0,0,3,3,3,0,0,0,0,3,3,3,0,0,0], - [0,0,3,0,0,0,3,0,0,3,0,0,0,3,0,0], - [0,3,3,3,0,3,3,3,3,3,3,0,3,3,3,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]], + [[0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 2, 0, 2, 2, 0, 2, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 3, 0, 2, 2, 2, 2, 0, 3, 0, 0, 0, 0], + [0, 0, 0, 3, 3, 3, 0, 0, 0, 0, 3, 3, 3, 0, 0, 0], + [0, 0, 3, 0, 0, 0, 3, 0, 0, 3, 0, 0, 0, 3, 0, 0], + [0, 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 0, 3, 3, 3, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], # Banners - [[0,3,2,2,3,0,3,2,2,3,0,3,2,2,3,0], - [0,3,2,2,3,0,3,2,2,3,0,3,2,2,3,0], - [0,3,2,2,3,0,3,2,2,3,0,3,2,2,3,0], - [0,3,2,2,3,0,3,2,2,3,0,3,2,2,3,0], - [0,0,2,2,0,0,3,2,2,3,0,0,2,2,0,0], - [0,0,0,0,0,0,3,2,2,3,0,0,0,0,0,0], - [0,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]] + [[0, 3, 2, 2, 3, 0, 3, 2, 2, 3, 0, 3, 2, 2, 3, 0], + [0, 3, 2, 2, 3, 0, 3, 2, 2, 3, 0, 3, 2, 2, 3, 0], + [0, 3, 2, 2, 3, 0, 3, 2, 2, 3, 0, 3, 2, 2, 3, 0], + [0, 3, 2, 2, 3, 0, 3, 2, 2, 3, 0, 3, 2, 2, 3, 0], + [0, 0, 2, 2, 0, 0, 3, 2, 2, 3, 0, 0, 2, 2, 0, 0], + [0, 0, 0, 0, 0, 0, 3, 2, 2, 3, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] ] ) w = random.choice([materials.BlackWool, @@ -1119,54 +1133,58 @@ def ssb (p, mat, data=0): for y in xrange(10): for x in xrange(16): if wall[y][x] == 1: - sb(o+Vec(x,y+1,31), w) + sb(o + Vec(x, y + 1, 31), w) elif wall[y][x] == 2: - sb(o+Vec(x,y+1,31), dmat[0]) + sb(o + Vec(x, y + 1, 31), dmat[0]) elif wall[y][x] == 3: - sb(o+Vec(x,y+1,31), dmat[1]) + sb(o + Vec(x, y + 1, 31), dmat[1]) # Chest. Maxtier plus a level zero. - sb(o+Vec(7,7,30), materials.Chest) - self.parent.addchest(o+Vec(7,7,30), loottable._maxtier) - sb(o+Vec(8,7,30), materials.Chest) + sb(o + Vec(7, 7, 30), materials.Chest) + self.parent.addchest(o + Vec(7, 7, 30), loottable._maxtier) + sb(o + Vec(8, 7, 30), materials.Chest) if cfg.double_treasure: - self.parent.addchest(o+Vec(8,7,30), loottable._maxtier) + self.parent.addchest(o + Vec(8, 7, 30), loottable._maxtier) else: - self.parent.addchest(o+Vec(8,7,30), 0) + self.parent.addchest(o + Vec(8, 7, 30), 0) # Spawners for i in xrange(7): - j = i*4 + j = i * 4 if (random.random() < 0.5): - sb(o+Vec(0,10,4+j), materials.Spawner) - self.parent.addspawner(o+Vec(0,10,4+j), - tier=random.randint(cfg.max_mob_tier-1,cfg.max_mob_tier)) + sb(o + Vec(0, 10, 4 + j), materials.Spawner) + self.parent.addspawner(o + + Vec(0, 10, 4 + + j), tier=random.randint(cfg.max_mob_tier - + 1, cfg.max_mob_tier)) if (random.random() < 0.5): - sb(o+Vec(15,10,4+j), materials.Spawner) - self.parent.addspawner(o+Vec(15,10,4+j), - tier=random.randint(cfg.max_mob_tier-1,cfg.max_mob_tier)) + sb(o + Vec(15, 10, 4 + j), materials.Spawner) + self.parent.addspawner(o + + Vec(15, 10, 4 + + j), tier=random.randint(cfg.max_mob_tier - + 1, cfg.max_mob_tier)) # Ropes - for p in iterate_cube(o.trans(5,1,5), o.trans(10,1,30)): + for p in iterate_cube(o.trans(5, 1, 5), o.trans(10, 1, 30)): if random.random() < 0.07: - for q in iterate_cube(p, p.down(random.randint(0,2))): + for q in iterate_cube(p, p.down(random.randint(0, 2))): sb(q, materials.Fence) # Portal - drawExitPortal(o+Vec(6,7,1), self.parent) + drawExitPortal(o + Vec(6, 7, 1), self.parent) # Cobwebs webs = {} - for p in iterate_cube(o.down(1), o.trans(15,4,31)): + for p in iterate_cube(o.down(1), o.trans(15, 4, 31)): count = 0 - perc = 90 - (p.y - self.loc.down(1).y) * (70/3) + perc = 90 - (p.y - self.loc.down(1).y) * (70 / 3) if (p not in self.parent.blocks or - self.parent.blocks[p].material != materials.Air): + self.parent.blocks[p].material != materials.Air): continue - for q in (Vec(1,0,0), Vec(-1,0,0), - Vec(0,1,0), Vec(0,-1,0), - Vec(0,0,1), Vec(0,0,-1)): - if (p+q in self.parent.blocks and - self.parent.blocks[p+q].material != materials.Air and - random.randint(1,100) <= perc): + for q in (Vec(1, 0, 0), Vec(-1, 0, 0), + Vec(0, 1, 0), Vec(0, -1, 0), + Vec(0, 0, 1), Vec(0, 0, -1)): + if (p + q in self.parent.blocks and + self.parent.blocks[p + q].material != materials.Air and + random.randint(1, 100) <= perc): count += 1 if count >= 3: webs[p] = True @@ -1179,42 +1197,42 @@ class SpiderLair(Basic): _is_entrance = False _is_stairwell = False _is_treasureroom = True - _min_size = Vec(1,1,2) - _max_size = Vec(1,1,2) - size = Vec(1,1,2) + _min_size = Vec(1, 1, 2) + _max_size = Vec(1, 1, 2) + size = Vec(1, 1, 2) def placed(self): self.canvas = ( - Vec(0,self.parent.room_height-2,0), - Vec(0,self.parent.room_height-2,0), - Vec(0,self.parent.room_height-2,0)) + Vec(0, self.parent.room_height - 2, 0), + Vec(0, self.parent.room_height - 2, 0), + Vec(0, self.parent.room_height - 2, 0)) rooms = [] sx = self.parent.room_size sz = self.parent.room_size #sy = self.parent.room_height - # This room contains no halls, but is connected to the East + # This room contains no halls, but is connected to the East # West, South, East, North pos = self.pos rooms.append(pos) - self.hallLength = [0,0,0,0] - self.hallSize = [[2,sx-2], - [2,sx-2], - [2,sz-2], - [2,sz-2]] - self.parent.halls[pos.x][pos.y][pos.z] = [1,1,1,1] + self.hallLength = [0, 0, 0, 0] + self.hallSize = [[2, sx - 2], + [2, sx - 2], + [2, sz - 2], + [2, sz - 2]] + self.parent.halls[pos.x][pos.y][pos.z] = [1, 1, 1, 1] # This room cannot connect. Make the depth < 0 self.parent.maze[pos].depth = -1 # Place one room to the East # This room can have halls N, E, or S and is connected to the West - pos = self.pos + Vec(0,0,1) + pos = self.pos + Vec(0, 0, 1) room = new('blank', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [0,1,1,1] - room.hallSize = [[2,sx-2], - [2,sx-2], - [2,sz-2], - [2,sz-2]] + room.hallLength = [0, 1, 1, 1] + room.hallSize = [[2, sx - 2], + [2, sx - 2], + [2, sz - 2], + [2, sz - 2]] room.parent.halls[pos.x][pos.y][pos.z][0] = 1 return rooms @@ -1228,97 +1246,110 @@ def render(self): # Add halls #inner_room = self.parent.rooms[self.pos] - outer_room = self.parent.rooms[self.pos + Vec(0,0,1)] + outer_room = self.parent.rooms[self.pos + Vec(0, 0, 1)] # South side if (outer_room.halls[1].size > 0): - outer_cave.add_exit((outer_room.halls[1].offset, sx-1), - (outer_room.halls[1].offset+outer_room.halls[1].size, sx-1)) + outer_cave.add_exit( + (outer_room.halls[1].offset, + sx - + 1), + (outer_room.halls[1].offset + + outer_room.halls[1].size, + sx - + 1)) # East side if (outer_room.halls[2].size > 0): - outer_cave.add_exit((sz-1, outer_room.halls[2].offset), - (sz-1, outer_room.halls[2].offset+outer_room.halls[2].size)) + outer_cave.add_exit((sz - + 1, outer_room.halls[2].offset), (sz - + 1, outer_room.halls[2].offset + + outer_room.halls[2].size)) # North side if (outer_room.halls[3].size > 0): - outer_cave.add_exit((outer_room.halls[3].offset, 0), - (outer_room.halls[3].offset+outer_room.halls[3].size, 0)) + outer_cave.add_exit( + (outer_room.halls[3].offset, + 0), + (outer_room.halls[3].offset + + outer_room.halls[3].size, + 0)) # Center - inner_cave.add_exit((15,1), (15,15)) - outer_cave.add_exit((0,0), (0,15)) + inner_cave.add_exit((15, 1), (15, 15)) + outer_cave.add_exit((0, 0), (0, 15)) # Portal if (cfg.exit_portal != ''): - inner_cave.add_exit((0,1), (0,4)) + inner_cave.add_exit((0, 1), (0, 4)) # Carve caves outer_cave.gen_map() inner_cave.gen_map(mode='room') # Air space, Floor, and Ceiling - q = self.loc+Vec(0,4,15) + q = self.loc + Vec(0, 4, 15) for p in outer_cave.iterate_map(cave_factory.FLOOR): - self.parent.setblock(q+Vec(p[0],-3,p[1]), materials.Air) - self.parent.setblock(q+Vec(p[0],-2,p[1]), materials.Air) - self.parent.setblock(q+Vec(p[0],-1,p[1]), materials.Air) - self.parent.setblock(q+Vec(p[0],0,p[1]), materials._floor) - self.parent.setblock(q+Vec(p[0],-height,p[1]), + self.parent.setblock(q + Vec(p[0], -3, p[1]), materials.Air) + self.parent.setblock(q + Vec(p[0], -2, p[1]), materials.Air) + self.parent.setblock(q + Vec(p[0], -1, p[1]), materials.Air) + self.parent.setblock(q + Vec(p[0], 0, p[1]), materials._floor) + self.parent.setblock(q + Vec(p[0], -height, p[1]), materials._ceiling, 0, True) - q = self.loc+Vec(0,4,0) + q = self.loc + Vec(0, 4, 0) for p in inner_cave.iterate_map(cave_factory.FLOOR): - self.parent.setblock(q+Vec(p[0],-3,p[1]), materials.Air) - self.parent.setblock(q+Vec(p[0],-2,p[1]), materials.Air) - self.parent.setblock(q+Vec(p[0],-1,p[1]), materials.Air) - self.parent.setblock(q+Vec(p[0],0,p[1]), materials._floor) - self.parent.setblock(q+Vec(p[0],-height,p[1]), + self.parent.setblock(q + Vec(p[0], -3, p[1]), materials.Air) + self.parent.setblock(q + Vec(p[0], -2, p[1]), materials.Air) + self.parent.setblock(q + Vec(p[0], -1, p[1]), materials.Air) + self.parent.setblock(q + Vec(p[0], 0, p[1]), materials._floor) + self.parent.setblock(q + Vec(p[0], -height, p[1]), materials._ceiling, 0, True) # Walls - q = self.loc+Vec(0,4,15) + q = self.loc + Vec(0, 4, 15) for p in outer_cave.iterate_walls(): - self.parent.setblock(q+Vec(p[0],-4,p[1]), materials._wall, - 0, True) - self.parent.setblock(q+Vec(p[0],-3,p[1]), materials._wall) - self.parent.setblock(q+Vec(p[0],-2,p[1]), materials._wall) - self.parent.setblock(q+Vec(p[0],-1,p[1]), materials._wall) + self.parent.setblock(q + Vec(p[0], -4, p[1]), materials._wall, + 0, True) + self.parent.setblock(q + Vec(p[0], -3, p[1]), materials._wall) + self.parent.setblock(q + Vec(p[0], -2, p[1]), materials._wall) + self.parent.setblock(q + Vec(p[0], -1, p[1]), materials._wall) outer_cave.grow_map() for p in outer_cave.iterate_walls(): - self.parent.setblock(q+Vec(p[0],-3,p[1]), materials._wall, - 0, True) - q = self.loc+Vec(0,4,0) + self.parent.setblock(q + Vec(p[0], -3, p[1]), materials._wall, + 0, True) + q = self.loc + Vec(0, 4, 0) for p in inner_cave.iterate_walls(): - self.parent.setblock(q+Vec(p[0],-4,p[1]), materials._wall, - 0, True) - self.parent.setblock(q+Vec(p[0],-3,p[1]), materials._wall) - self.parent.setblock(q+Vec(p[0],-2,p[1]), materials._wall) - self.parent.setblock(q+Vec(p[0],-1,p[1]), materials._wall) + self.parent.setblock(q + Vec(p[0], -4, p[1]), materials._wall, + 0, True) + self.parent.setblock(q + Vec(p[0], -3, p[1]), materials._wall) + self.parent.setblock(q + Vec(p[0], -2, p[1]), materials._wall) + self.parent.setblock(q + Vec(p[0], -1, p[1]), materials._wall) inner_cave.grow_map() for p in inner_cave.iterate_walls(): - self.parent.setblock(q+Vec(p[0],-3,p[1]), materials._wall, - 0, True) + self.parent.setblock(q + Vec(p[0], -3, p[1]), materials._wall, + 0, True) # Spider pit pit_blocks = [] inner_cave.purge_exits() - inner_cave.add_exit((15,5), (15,11)) + inner_cave.add_exit((15, 5), (15, 11)) inner_cave.grow_map() pit_depth = self.parent.position.y - self.parent.levels * \ self.parent.room_height - q = self.loc+Vec(0,4,0) + q = self.loc + Vec(0, 4, 0) for p in inner_cave.iterate_map(cave_factory.FLOOR): - for x in xrange(pit_depth+1): - self.parent.setblock(q+Vec(p[0],x,p[1]), materials.Air) - self.parent.setblock(q+Vec(p[0],0,p[1]), materials.Cobweb) - pit_blocks.append(q+Vec(p[0],0,p[1])) - self.parent.setblock(q+Vec(p[0],pit_depth+1,p[1]), materials.Lava) + for x in xrange(pit_depth + 1): + self.parent.setblock(q + Vec(p[0], x, p[1]), materials.Air) + self.parent.setblock(q + Vec(p[0], 0, p[1]), materials.Cobweb) + pit_blocks.append(q + Vec(p[0], 0, p[1])) + self.parent.setblock( + q + Vec(p[0], pit_depth + 1, p[1]), materials.Lava) # Chest num_chests = 1 if cfg.double_treasure: num_chests = 2 - choices = random.sample(pit_blocks,num_chests) + choices = random.sample(pit_blocks, num_chests) for c in choices: pit_blocks.remove(c) self.parent.setblock(c, materials.Chest) self.parent.addchest(c, loottable._maxtier) # Spider spawners # In the future, maybe spiders will walk on web - #for x in xrange(3): + # for x in xrange(3): # s = random.choice(pit_blocks) # pit_blocks.remove(s) # self.parent.setblock(s, materials.Spawner) @@ -1326,7 +1357,7 @@ def render(self): # Spiders in teh walls! count = 0 while count < 5: - p = self.loc+Vec(random.randint(0,15),3,random.randint(0,32)) + p = self.loc + Vec(random.randint(0, 15), 3, random.randint(0, 32)) if p not in self.parent.blocks: self.parent.setblock(p, materials.Spawner) self.parent.setblock(p.up(1), materials.Air) @@ -1336,22 +1367,22 @@ def render(self): count += 1 # Portal - drawExitPortal(self.loc+Vec(1,0,0), self.parent) + drawExitPortal(self.loc + Vec(1, 0, 0), self.parent) # Cobwebs webs = {} - for p in iterate_cube(self.loc.down(1), self.loc.trans(15,3,31)): + for p in iterate_cube(self.loc.down(1), self.loc.trans(15, 3, 31)): count = 0 - perc = 90 - (p.y - self.loc.down(1).y) * (70/3) + perc = 90 - (p.y - self.loc.down(1).y) * (70 / 3) if (p not in self.parent.blocks or - self.parent.blocks[p].material != materials.Air): + self.parent.blocks[p].material != materials.Air): continue - for q in (Vec(1,0,0), Vec(-1,0,0), - Vec(0,1,0), Vec(0,-1,0), - Vec(0,0,1), Vec(0,0,-1)): - if (p+q in self.parent.blocks and - self.parent.blocks[p+q].material != materials.Air and - random.randint(1,100) <= perc): + for q in (Vec(1, 0, 0), Vec(-1, 0, 0), + Vec(0, 1, 0), Vec(0, -1, 0), + Vec(0, 0, 1), Vec(0, 0, -1)): + if (p + q in self.parent.blocks and + self.parent.blocks[p + q].material != materials.Air and + random.randint(1, 100) <= perc): count += 1 if count >= 3: webs[p] = True @@ -1374,10 +1405,10 @@ def placed(self): #sy = self.parent.room_height for room in rooms: r = self.parent.rooms[room] - r.hallSize = [[6,sx-6], - [6,sx-6], - [6,sz-6], - [6,sz-6]] + r.hallSize = [[6, sx - 6], + [6, sx - 6], + [6, sz - 6], + [6, sz - 6]] return rooms def render(self): @@ -1386,74 +1417,75 @@ def render(self): # We start with the basics... Basic2x2.render(self) # Clear out an air space. - for p in iterate_cube(self.c1+Vec(1,0,1), - self.c3+Vec(-1,pit_depth,-1)): + for p in iterate_cube(self.c1 + Vec(1, 0, 1), + self.c3 + Vec(-1, pit_depth, -1)): self.parent.setblock(p, materials.Air) # Lava! - for p in iterate_cube(self.c1.down(pit_depth+1), - self.c3.down(pit_depth+1)): + for p in iterate_cube(self.c1.down(pit_depth + 1), + self.c3.down(pit_depth + 1)): self.parent.setblock(p, materials.Lava) # Build a bridge around the edge - for p in iterate_four_walls(self.c1+Vec(1,0,1), - self.c3+Vec(-1,0,-1),0): + for p in iterate_four_walls(self.c1 + Vec(1, 0, 1), + self.c3 + Vec(-1, 0, -1), 0): self.parent.setblock(p, materials.OakWoodSlab) # Make some island areas cave = cave_factory.new(22, 22) cave.gen_map() for p in cave.iterate_map(cave_factory.FLOOR): - pp = Vec(p[0],0,p[1])+self.c1+Vec(3,1,3) + pp = Vec(p[0], 0, p[1]) + self.c1 + Vec(3, 1, 3) for x in iterate_cube(pp, pp.down(pit_depth)): self.parent.setblock(x, materials._floor) # Some tasteful recessed lighting - for p in iterate_cube(self.c1+Vec(14,-4,14), - self.c3-Vec(14,4,14)): + for p in iterate_cube(self.c1 + Vec(14, -4, 14), + self.c3 - Vec(14, 4, 14)): self.parent.setblock(p, materials.Air) self.parent.setblock(p.up(1), materials.Glowstone) # Central pillar - for p in iterate_cylinder(self.c1+Vec(10,2,10), - self.c3-Vec(10,-pit_depth,10)): + for p in iterate_cylinder(self.c1 + Vec(10, 2, 10), + self.c3 - Vec(10, -pit_depth, 10)): self.parent.setblock(p, materials._subfloor) - for p in iterate_disc(self.c1+Vec(10,1,10), - self.c3-Vec(10,-1,10)): + for p in iterate_disc(self.c1 + Vec(10, 1, 10), + self.c3 - Vec(10, -1, 10)): self.parent.setblock(p, materials.Air) - for p in iterate_ellipse(self.c1+Vec(10,1,10), - self.c3-Vec(10,-1,10)): + for p in iterate_ellipse(self.c1 + Vec(10, 1, 10), + self.c3 - Vec(10, -1, 10)): self.parent.setblock(p, materials.CobblestoneSlab) - center = self.c1+Vec(14,1,12) + center = self.c1 + Vec(14, 1, 12) # Portal - drawExitPortal(center.trans(-2,-3,0), self.parent) + drawExitPortal(center.trans(-2, -3, 0), self.parent) # Treasure! - self.parent.setblock(center.trans(0,0,3), - materials.Chest) - self.parent.addchest(center.trans(0,0,3), - loottable._maxtier) + self.parent.setblock(center.trans(0, 0, 3), + materials.Chest) + self.parent.addchest(center.trans(0, 0, 3), + loottable._maxtier) if cfg.double_treasure: - self.parent.setblock(center.trans(1,0,3), - materials.Chest) - self.parent.addchest(center.trans(1,0,3), - loottable._maxtier) + self.parent.setblock(center.trans(1, 0, 3), + materials.Chest) + self.parent.addchest(center.trans(1, 0, 3), + loottable._maxtier) # Oh fuck! Skeletons! - for x in (self.c1+Vec(1,0,1), self.c2+Vec(-1,0,1), - self.c3+Vec(-1,0,-1), self.c4+Vec(1,0,-1)): - b1 = x-Vec(3,0,3) - b2 = x+Vec(3,0,3) + for x in (self.c1 + Vec(1, 0, 1), self.c2 + Vec(-1, 0, 1), + self.c3 + Vec(-1, 0, -1), self.c4 + Vec(1, 0, -1)): + b1 = x - Vec(3, 0, 3) + b2 = x + Vec(3, 0, 3) for p in iterate_tube(b1, b2, 1): if (p in self.parent.blocks and ( - self.parent.blocks[p].material == materials.Air or - self.parent.blocks[p].material == materials.OakWoodSlab or - self.parent.blocks[p].material == materials.Fence)): + self.parent.blocks[p].material == materials.Air or + self.parent.blocks[p].material == materials.OakWoodSlab or + self.parent.blocks[p].material == materials.Fence)): self.parent.setblock(p, materials.Fence) for p in iterate_disc(b1, b2): if (p in self.parent.blocks and ( - self.parent.blocks[p].material == materials.Air or - self.parent.blocks[p].material == materials.OakWoodSlab or - self.parent.blocks[p].material == materials.Fence)): + self.parent.blocks[p].material == materials.Air or + self.parent.blocks[p].material == materials.OakWoodSlab or + self.parent.blocks[p].material == materials.Fence)): self.parent.setblock(p, materials._floor) self.parent.addspawner(x.up(1), 'Skeleton') self.parent.setblock(x.up(1), materials.Spawner) + class EndPortal(Basic2x2): _name = 'endportal' _is_entrance = False @@ -1463,7 +1495,7 @@ class EndPortal(Basic2x2): def placed(self): rooms = Basic2x2.placed(self) - # Narrow the hall connections + # Narrow the hall connections sx = self.parent.room_size sz = self.parent.room_size #sy = self.parent.room_height @@ -1476,18 +1508,18 @@ def placed(self): r.hallLength[h] = 3 else: r.hallLength[h] = 4 - r.hallSize = [[6,sx-7], - [6,sx-7], - [6,sz-7], - [6,sz-7]] + r.hallSize = [[6, sx - 7], + [6, sx - 7], + [6, sz - 7], + [6, sz - 7]] return rooms def setData(self): Basic2x2.setData(self) self.canvas = ( - Vec(0,0,0), - Vec(0,0,0), - Vec(0,0,0)) + Vec(0, 0, 0), + Vec(0, 0, 0), + Vec(0, 0, 0)) def render(self): sx = 31 @@ -1498,80 +1530,86 @@ def render(self): # custom setblock def sb(p, mat, data=0, hide=False, stairdat=False, flip=False): - if stairdat == True: - x = p.x-o.x-(sx-1)/2 - z = p.z-o.z-(sz-1)/2 + if stairdat: + x = p.x - o.x - (sx - 1) / 2 + z = p.z - o.z - (sz - 1) / 2 if (abs(x) == abs(z)): mat = materials.StoneBrick data = 0 else: if (abs(x) > abs(z)): if x > 0: - data = 0 # Ascending East + data = 0 # Ascending East else: - data = 1 # Ascending West + data = 1 # Ascending West else: if z > 0: - data = 2 # Ascending South + data = 2 # Ascending South else: - data = 3 # Ascending North - if flip == True: + data = 3 # Ascending North + if flip: data = data ^ 1 self.parent.setblock(p, mat, data, hide) - # symmetrical setblock. A lot of this room will be symmetrical. - def ssb (p, mat, data=0, hide=False, stairdat=False, flip=False): - sb(o+p, mat, data, hide, stairdat, flip) - sb(Vec(o.x+sx-1-p.x, o.y+p.y, o.z+p.z), mat, data, hide, - stairdat, flip) - sb(Vec(o.x+p.x, o.y+p.y, o.z+sz-1-p.z), mat, data, hide, + # symmetrical setblock. A lot of this room will be symmetrical. + def ssb(p, mat, data=0, hide=False, stairdat=False, flip=False): + sb(o + p, mat, data, hide, stairdat, flip) + sb(Vec(o.x + sx - 1 - p.x, o.y + p.y, o.z + p.z), mat, data, hide, stairdat, flip) - sb(Vec(o.x+sx-1-p.x, o.y+p.y, o.z+sz-1-p.z), mat, data, hide, + sb(Vec(o.x + p.x, o.y + p.y, o.z + sz - 1 - p.z), mat, data, hide, stairdat, flip) + sb(Vec(o.x + sx - 1 - p.x, + o.y + p.y, + o.z + sz - 1 - p.z), + mat, + data, + hide, + stairdat, + flip) # Basic room # Air space - for p in iterate_cylinder(o, o+Vec(sx-1,sy-1,sz-1)): + for p in iterate_cylinder(o, o + Vec(sx - 1, sy - 1, sz - 1)): sb(p, materials.Air) # Walls - for p in iterate_tube(o+Vec(0,sy-1,0), o+Vec(sx-1,sy-1,sz-1), sy-1): + for p in iterate_tube(o + Vec(0, sy - 1, 0), o + Vec(sx - 1, sy - 1, sz - 1), sy - 1): sb(p, materials._wall) # Ceiling and floor - for p in iterate_cylinder(o, o+Vec(sx-1,0,sz-1)): + for p in iterate_cylinder(o, o + Vec(sx - 1, 0, sz - 1)): sb(p, materials._ceiling, hide=True) - sb(p.down(sy-1), materials.meta_mossystonebrick) + sb(p.down(sy - 1), materials.meta_mossystonebrick) # Lava pit - for p in iterate_cube(o+Vec(12,sy-2,12), o+Vec(18,sy-2,18)): + for p in iterate_cube(o + Vec(12, sy - 2, 12), o + Vec(18, sy - 2, 18)): sb(p, materials.Lava) - for p in iterate_cube(Vec(14,sy-2,13), Vec(15,sy-2,13)): - ssb (p, materials.meta_mossystonebrick) - for p in iterate_cube(Vec(13,sy-2,14), Vec(13,sy-2,15)): - ssb (p, materials.meta_mossystonebrick) - ssb (Vec(11, sy-2, 13), materials.meta_mossystonebrick) - ssb (Vec(12, sy-2, 12), materials.meta_mossystonebrick) - ssb (Vec(13, sy-2, 11), materials.meta_mossystonebrick) - for p in iterate_cube(Vec(14,sy-2,10), Vec(15,sy-2,12)): - ssb (p, materials.meta_mossystonebrick) - for p in iterate_cube(Vec(10,sy-2,14), Vec(12,sy-2,15)): - ssb (p, materials.meta_mossystonebrick) + for p in iterate_cube(Vec(14, sy - 2, 13), Vec(15, sy - 2, 13)): + ssb(p, materials.meta_mossystonebrick) + for p in iterate_cube(Vec(13, sy - 2, 14), Vec(13, sy - 2, 15)): + ssb(p, materials.meta_mossystonebrick) + ssb(Vec(11, sy - 2, 13), materials.meta_mossystonebrick) + ssb(Vec(12, sy - 2, 12), materials.meta_mossystonebrick) + ssb(Vec(13, sy - 2, 11), materials.meta_mossystonebrick) + for p in iterate_cube(Vec(14, sy - 2, 10), Vec(15, sy - 2, 12)): + ssb(p, materials.meta_mossystonebrick) + for p in iterate_cube(Vec(10, sy - 2, 14), Vec(12, sy - 2, 15)): + ssb(p, materials.meta_mossystonebrick) # Lava pit stairs - for p in iterate_cube(Vec(14,sy-2,9), Vec(16,sy-2,9)): + for p in iterate_cube(Vec(14, sy - 2, 9), Vec(16, sy - 2, 9)): q = p.s(1) ssb(p, materials.StoneBrickStairs, stairdat=True, flip=True) ssb(q, materials.meta_mossystonebrick) ssb(Vec(p.z, p.y, p.x), materials.StoneBrickStairs, stairdat=True, flip=True) ssb(Vec(q.z, q.y, q.x), materials.meta_mossystonebrick) - for p in iterate_cube(Vec(14,sy-3,10), Vec(16,sy-3,10)): + for p in iterate_cube(Vec(14, sy - 3, 10), Vec(16, sy - 3, 10)): q = p.s(1) ssb(p, materials.StoneBrickStairs, stairdat=True, flip=True) ssb(q, materials.meta_mossystonebrick) ssb(Vec(p.z, p.y, p.x), materials.StoneBrickStairs, stairdat=True, flip=True) ssb(Vec(q.z, q.y, q.x), materials.meta_mossystonebrick) - for p in iterate_cube(Vec(14,sy-4,11), Vec(16,sy-4,11)): + for p in iterate_cube(Vec(14, sy - 4, 11), Vec(16, sy - 4, 11)): q = p.s(1) ssb(p, materials.StoneBrickStairs, stairdat=True, flip=True) ssb(q, materials.meta_mossystonebrick) @@ -1580,59 +1618,65 @@ def ssb (p, mat, data=0, hide=False, stairdat=False, flip=False): ssb(Vec(q.z, q.y, q.x), materials.meta_mossystonebrick) # Portal - for p in iterate_cube(Vec(14,sy-4,13), Vec(16,sy-4,13)): + for p in iterate_cube(Vec(14, sy - 4, 13), Vec(16, sy - 4, 13)): # North Edge - eye = random.choice([0,0,0,0,0,0,0,0,0,4]) - sb(o+p, materials.EndPortalFrame, 0+eye) + eye = random.choice([0, 0, 0, 0, 0, 0, 0, 0, 0, 4]) + sb(o + p, materials.EndPortalFrame, 0 + eye) # South Edge - eye = random.choice([0,0,0,0,0,0,0,0,0,4]) - sb(o+p.trans(0,0,4), materials.EndPortalFrame, 2+eye) + eye = random.choice([0, 0, 0, 0, 0, 0, 0, 0, 0, 4]) + sb(o + p.trans(0, 0, 4), materials.EndPortalFrame, 2 + eye) # West Edge - eye = random.choice([0,0,0,0,0,0,0,0,0,4]) - sb(o+Vec(p.z, p.y, p.x), materials.EndPortalFrame, 3+eye) + eye = random.choice([0, 0, 0, 0, 0, 0, 0, 0, 0, 4]) + sb(o + Vec(p.z, p.y, p.x), materials.EndPortalFrame, 3 + eye) # East Edge - eye = random.choice([0,0,0,0,0,0,0,0,0,4]) - sb(o+Vec(p.z, p.y, p.x).trans(4,0,0),materials.EndPortalFrame,1+eye) + eye = random.choice([0, 0, 0, 0, 0, 0, 0, 0, 0, 4]) + sb(o + Vec(p.z, + p.y, + p.x).trans(4, + 0, + 0), + materials.EndPortalFrame, + 1 + eye) # Entry stairs - for p in iterate_cube(Vec(7,4,3), Vec(8,4,3)): + for p in iterate_cube(Vec(7, 4, 3), Vec(8, 4, 3)): ssb(p, materials.StoneBrickStairs, stairdat=True) ssb(Vec(p.z, p.y, p.x), materials.StoneBrickStairs, stairdat=True) for q in iterate_cube(p.down(1), p.down(3)): ssb(q, materials.meta_mossystonebrick) ssb(Vec(q.z, q.y, q.x), materials.meta_mossystonebrick) - for p in iterate_cube(Vec(6,5,4), Vec(8,5,4)): + for p in iterate_cube(Vec(6, 5, 4), Vec(8, 5, 4)): ssb(p, materials.StoneBrickStairs, stairdat=True) ssb(Vec(p.z, p.y, p.x), materials.StoneBrickStairs, stairdat=True) for q in iterate_cube(p.down(1), p.down(2)): ssb(q, materials.meta_mossystonebrick) ssb(Vec(q.z, q.y, q.x), materials.meta_mossystonebrick) - for p in iterate_cube(Vec(5,6,5), Vec(8,6,5)): + for p in iterate_cube(Vec(5, 6, 5), Vec(8, 6, 5)): ssb(p, materials.StoneBrickStairs, stairdat=True) ssb(Vec(p.z, p.y, p.x), materials.StoneBrickStairs, stairdat=True) for q in iterate_cube(p.down(1), p.down(1)): ssb(q, materials.meta_mossystonebrick) ssb(Vec(q.z, q.y, q.x), materials.meta_mossystonebrick) - for p in iterate_cube(Vec(6,7,6), Vec(8,7,6)): + for p in iterate_cube(Vec(6, 7, 6), Vec(8, 7, 6)): ssb(p, materials.StoneBrickStairs, stairdat=True) ssb(Vec(p.z, p.y, p.x), materials.StoneBrickStairs, stairdat=True) # Candelabra for p in [ - Vec(9,sy-2,10), Vec(11,sy-2,10), Vec(10,sy-2,9), Vec(10,sy-2,11), - Vec(10,sy-2,10), Vec(10,sy-3,10), - Vec(9,sy-4,10), Vec(11,sy-4,10), Vec(10,sy-4,9), Vec(10,sy-4,11), - Vec(10,sy-4,10), - Vec(9,sy-5,10), Vec(11,sy-5,10), Vec(10,sy-5,9), Vec(10,sy-5,11), - ]: + Vec(9, sy - 2, 10), Vec(11, sy - 2, 10), Vec(10, sy - 2, 9), Vec(10, sy - 2, 11), + Vec(10, sy - 2, 10), Vec(10, sy - 3, 10), + Vec(9, sy - 4, 10), Vec(11, sy - 4, 10), Vec(10, sy - 4, 9), Vec(10, sy - 4, 11), + Vec(10, sy - 4, 10), + Vec(9, sy - 5, 10), Vec(11, sy - 5, 10), Vec(10, sy - 5, 9), Vec(10, sy - 5, 11), + ]: ssb(p, materials.IronBars) - ssb(Vec(10,sy-5,10), materials.Netherrack) - ssb(Vec(10,sy-6,10), materials.Fire) + ssb(Vec(10, sy - 5, 10), materials.Netherrack) + ssb(Vec(10, sy - 6, 10), materials.Fire) # Fancy iron bars - for p in iterate_cube(Vec(5,1,5), Vec(5,5,5)): + for p in iterate_cube(Vec(5, 1, 5), Vec(5, 5, 5)): ssb(p, materials.IronBars) - for p in iterate_cube(Vec(10,2,1), Vec(10,sy-3,1)): + for p in iterate_cube(Vec(10, 2, 1), Vec(10, sy - 3, 1)): ssb(p, materials.IronBars) ssb(Vec(p.z, p.y, p.x), materials.IronBars) @@ -1649,50 +1693,50 @@ def ssb (p, mat, data=0, hide=False, stairdat=False, flip=False): wall = random.choice( [ # Banner - [[3,2,2,2,2,2,3], - [0,3,2,2,2,3,0], - [0,0,3,2,3,0,0], - [0,0,3,2,3,0,0], - [0,0,0,3,0,0,0], - [0,0,0,3,0,0,0], - [0,0,0,3,0,0,0]], + [[3, 2, 2, 2, 2, 2, 3], + [0, 3, 2, 2, 2, 3, 0], + [0, 0, 3, 2, 3, 0, 0], + [0, 0, 3, 2, 3, 0, 0], + [0, 0, 0, 3, 0, 0, 0], + [0, 0, 0, 3, 0, 0, 0], + [0, 0, 0, 3, 0, 0, 0]], # Banner - [[3,2,2,2,2,2,3], - [0,3,2,2,2,3,0], - [0,0,3,2,3,0,0], - [0,0,3,2,3,0,0], - [0,0,0,3,0,0,0], - [0,0,0,3,0,0,0], - [0,0,0,3,0,0,0]] + [[3, 2, 2, 2, 2, 2, 3], + [0, 3, 2, 2, 2, 3, 0], + [0, 0, 3, 2, 3, 0, 0], + [0, 0, 3, 2, 3, 0, 0], + [0, 0, 0, 3, 0, 0, 0], + [0, 0, 0, 3, 0, 0, 0], + [0, 0, 0, 3, 0, 0, 0]] ]) for y in xrange(7): for x in xrange(7): if wall[y][x] == 2: - sb(o+Vec(x+12,y+1,0), dmat[0]) - sb(o+Vec(x+12,y+1,30), dmat[0]) - sb(o+Vec(0,y+1,x+12), dmat[0]) - sb(o+Vec(30,y+1,x+12), dmat[0]) + sb(o + Vec(x + 12, y + 1, 0), dmat[0]) + sb(o + Vec(x + 12, y + 1, 30), dmat[0]) + sb(o + Vec(0, y + 1, x + 12), dmat[0]) + sb(o + Vec(30, y + 1, x + 12), dmat[0]) elif wall[y][x] == 3: - sb(o+Vec(x+12,y+1,0), dmat[1]) - sb(o+Vec(x+12,y+1,30), dmat[1]) - sb(o+Vec(0,y+1,x+12), dmat[1]) - sb(o+Vec(30,y+1,x+12), dmat[1]) + sb(o + Vec(x + 12, y + 1, 0), dmat[1]) + sb(o + Vec(x + 12, y + 1, 30), dmat[1]) + sb(o + Vec(0, y + 1, x + 12), dmat[1]) + sb(o + Vec(30, y + 1, x + 12), dmat[1]) # Portal - drawExitPortal(o+Vec(14,sy-5,1), self.parent) + drawExitPortal(o + Vec(14, sy - 5, 1), self.parent) # Treasure! - sb(o+Vec(13,sy-2,2), materials.Chest) - self.parent.addchest(o+Vec(13,sy-2,2), loottable._maxtier) + sb(o + Vec(13, sy - 2, 2), materials.Chest) + self.parent.addchest(o + Vec(13, sy - 2, 2), loottable._maxtier) if cfg.double_treasure: - sb(o+Vec(14,sy-2,2), materials.Chest) - self.parent.addchest(o+Vec(14,sy-2,2), loottable._maxtier) + sb(o + Vec(14, sy - 2, 2), materials.Chest) + self.parent.addchest(o + Vec(14, sy - 2, 2), loottable._maxtier) # Monsters - sb(o+Vec(0,sy-2,15), materials.Spawner) - self.parent.addspawner(o+Vec(0,sy-2,15), tier=cfg.max_mob_tier) - sb(o+Vec(30,sy-2,15), materials.Spawner) - self.parent.addspawner(o+Vec(30,sy-2,15), tier=cfg.max_mob_tier) + sb(o + Vec(0, sy - 2, 15), materials.Spawner) + self.parent.addspawner(o + Vec(0, sy - 2, 15), tier=cfg.max_mob_tier) + sb(o + Vec(30, sy - 2, 15), materials.Spawner) + self.parent.addspawner(o + Vec(30, sy - 2, 15), tier=cfg.max_mob_tier) class Arena(Basic2x2): @@ -1713,10 +1757,10 @@ def placed(self): for h in xrange(4): if r.hallLength[h] > 0: r.hallLength[h] = 1 - r.hallSize = [[1,sx-1], - [6,sx-6], - [1,sz-1], - [6,sz-6]] + r.hallSize = [[1, sx - 1], + [6, sx - 6], + [1, sz - 1], + [6, sz - 6]] return rooms def render(self): @@ -1729,12 +1773,19 @@ def render(self): # alias for setblock sb = self.parent.setblock - # symmetrical setblock. A lot of this room will be symmetrical. - def ssb (p, mat, data=0, hide=False): - sb(o+p, mat, data, hide) - sb(Vec(o.x+sx-1-p.x, o.y+p.y, o.z+p.z), mat, data, hide) - sb(Vec(o.x+p.x, o.y+p.y, o.z+sz-1-p.z), mat, data, hide) - sb(Vec(o.x+sx-1-p.x, o.y+p.y, o.z+sz-1-p.z), mat, data, hide) + # symmetrical setblock. A lot of this room will be symmetrical. + def ssb(p, mat, data=0, hide=False): + sb(o + p, mat, data, hide) + sb(Vec(o.x + sx - 1 - p.x, o.y + p.y, o.z + p.z), mat, data, hide) + sb(Vec(o.x + p.x, o.y + p.y, o.z + sz - 1 - p.z), mat, data, hide) + sb(Vec(o.x + + sx - + 1 - + p.x, o.y + + p.y, o.z + + sz - + 1 - + p.z), mat, data, hide) # Decoration colors # inner color, trim color @@ -1751,108 +1802,108 @@ def ssb (p, mat, data=0, hide=False): # Basic room # Air space - for p in iterate_cube(o, o+Vec(sx-1,sy-1,sz-1)): + for p in iterate_cube(o, o + Vec(sx - 1, sy - 1, sz - 1)): sb(p, materials.Air) # Walls - for p in iterate_four_walls(o, o+Vec(sx-1,0,sz-1), -sy+1): + for p in iterate_four_walls(o, o + Vec(sx - 1, 0, sz - 1), -sy + 1): sb(p, materials._wall) # Ceiling and floor - for p in iterate_cube(o, o+Vec(sx-1,0,sz-1)): + for p in iterate_cube(o, o + Vec(sx - 1, 0, sz - 1)): sb(p, materials._ceiling, hide=True) - sb(p.down(sy-1), materials._floor) - sb(p.down(sy-2), materials._floor) - sb(p.down(sy-3), materials._floor) - ssb(Vec(15,0,15), materials.Glowstone, hide=True) + sb(p.down(sy - 1), materials._floor) + sb(p.down(sy - 2), materials._floor) + sb(p.down(sy - 3), materials._floor) + ssb(Vec(15, 0, 15), materials.Glowstone, hide=True) # Spawners - ssb(Vec(1,sy-4,1), materials.Spawner) - ssb(Vec(1,sy-5,1), materials.StoneSlab) - ssb(Vec(1,sy-6,1), materials.Fence) - for p in iterate_cube(Vec(2,sy-4,1), Vec(3,sy-5,2)): + ssb(Vec(1, sy - 4, 1), materials.Spawner) + ssb(Vec(1, sy - 5, 1), materials.StoneSlab) + ssb(Vec(1, sy - 6, 1), materials.Fence) + for p in iterate_cube(Vec(2, sy - 4, 1), Vec(3, sy - 5, 2)): ssb(p, materials.Fence) - for p in iterate_cube(Vec(1,sy-4,2), Vec(2,sy-5,3)): + for p in iterate_cube(Vec(1, sy - 4, 2), Vec(2, sy - 5, 3)): ssb(p, materials.Fence) - self.parent.addspawner(o+Vec(1,sy-4,1)) - self.parent.addspawner(o+Vec(sx-2,sy-4,1)) - self.parent.addspawner(o+Vec(1,sy-4,sz-2)) - self.parent.addspawner(o+Vec(sx-2,sy-4,sz-2)) + self.parent.addspawner(o + Vec(1, sy - 4, 1)) + self.parent.addspawner(o + Vec(sx - 2, sy - 4, 1)) + self.parent.addspawner(o + Vec(1, sy - 4, sz - 2)) + self.parent.addspawner(o + Vec(sx - 2, sy - 4, sz - 2)) # Wooden balcony - for p in iterate_cube(Vec(1,4,1), Vec(3,4,9)): + for p in iterate_cube(Vec(1, 4, 1), Vec(3, 4, 9)): ssb(p, materials.OakWoodPlanks) - for p in iterate_cube(Vec(1,4,1), Vec(14,4,3)): + for p in iterate_cube(Vec(1, 4, 1), Vec(14, 4, 3)): ssb(p, materials.OakWoodPlanks) - for p in iterate_cube(Vec(1,4,1), Vec(2,4,8)): + for p in iterate_cube(Vec(1, 4, 1), Vec(2, 4, 8)): ssb(p, materials.OakWoodSlab) - for p in iterate_cube(Vec(1,4,1), Vec(15,4,2)): + for p in iterate_cube(Vec(1, 4, 1), Vec(15, 4, 2)): ssb(p, materials.OakWoodSlab) - for p in iterate_cube(Vec(1,3,9), Vec(2,3,9)): + for p in iterate_cube(Vec(1, 3, 9), Vec(2, 3, 9)): ssb(p, materials.Fence) - for p in iterate_cube(Vec(4,3,3), Vec(14,3,3)): + for p in iterate_cube(Vec(4, 3, 3), Vec(14, 3, 3)): ssb(p, materials.Fence) - for p in iterate_cube(Vec(3,3,3), Vec(3,3,9)): + for p in iterate_cube(Vec(3, 3, 3), Vec(3, 3, 9)): ssb(p, materials.Fence) - ssb(Vec(15,4,3), materials.OakWoodSlab) - ssb(Vec(15,4,4), materials.OakWoodSlab) - ssb(Vec(15,4,5), materials.OakWoodSlab) + ssb(Vec(15, 4, 3), materials.OakWoodSlab) + ssb(Vec(15, 4, 4), materials.OakWoodSlab) + ssb(Vec(15, 4, 5), materials.OakWoodSlab) # Stairs - for y in xrange(5, sy-3): - p = Vec(25-2*y, y, 4) - for q in iterate_cube(p, p.trans(-1,0,1)): + for y in xrange(5, sy - 3): + p = Vec(25 - 2 * y, y, 4) + for q in iterate_cube(p, p.trans(-1, 0, 1)): ssb(q, materials.OakWoodPlanks) - for q in iterate_cube(p.trans(-2,0,0), p.trans(-2,0,1)): + for q in iterate_cube(p.trans(-2, 0, 0), p.trans(-2, 0, 1)): ssb(q, materials.OakWoodSlab) # Banners - for p in iterate_cube(Vec(0,0,15), Vec(0,sy-5,15)): + for p in iterate_cube(Vec(0, 0, 15), Vec(0, sy - 5, 15)): ssb(p, dmat[0]) - for p in iterate_cube(Vec(0,0,14), Vec(0,sy-7,14)): + for p in iterate_cube(Vec(0, 0, 14), Vec(0, sy - 7, 14)): ssb(p, dmat[1]) # Center arena - for p in iterate_cylinder(Vec(4,sy-3,4), Vec(sx-5,sy-3,sz-5)): - sb(o+p, materials.StoneSlab) - for p in iterate_cylinder(Vec(5,sy-4,5), Vec(sx-6,sy-3,sz-6)): - sb(o+p, materials.Air) - for p in iterate_cylinder(Vec(7,sy-2,7), Vec(sx-8,sy-2,sz-8)): - sb(o+p, materials.StoneSlab) - for p in iterate_cylinder(Vec(8,sy-3,8), Vec(sx-9,sy-2,sz-9)): - sb(o+p, materials.Air) - for p in iterate_cylinder(Vec(9,sy-1,9), Vec(sx-10,sy-1,sz-10)): - sb(o+p, materials.StoneSlab) + for p in iterate_cylinder(Vec(4, sy - 3, 4), Vec(sx - 5, sy - 3, sz - 5)): + sb(o + p, materials.StoneSlab) + for p in iterate_cylinder(Vec(5, sy - 4, 5), Vec(sx - 6, sy - 3, sz - 6)): + sb(o + p, materials.Air) + for p in iterate_cylinder(Vec(7, sy - 2, 7), Vec(sx - 8, sy - 2, sz - 8)): + sb(o + p, materials.StoneSlab) + for p in iterate_cylinder(Vec(8, sy - 3, 8), Vec(sx - 9, sy - 2, sz - 9)): + sb(o + p, materials.Air) + for p in iterate_cylinder(Vec(9, sy - 1, 9), Vec(sx - 10, sy - 1, sz - 10)): + sb(o + p, materials.StoneSlab) # Pit - depth = self.parent.position.y - (self.parent.levels-1) * \ + depth = self.parent.position.y - (self.parent.levels - 1) * \ self.parent.room_height - for p in iterate_cylinder(Vec(10,sy-2,10), Vec(sx-11,depth,sz-11)): - sb(o+p, materials.Air) - for p in iterate_cube(Vec(10,depth,10), Vec(sx-11,depth,sz-11)): - sb(o+p, materials.Lava) + for p in iterate_cylinder(Vec(10, sy - 2, 10), Vec(sx - 11, depth, sz - 11)): + sb(o + p, materials.Air) + for p in iterate_cube(Vec(10, depth, 10), Vec(sx - 11, depth, sz - 11)): + sb(o + p, materials.Lava) pn = perlin.SimplexNoise(256) - for p in iterate_cylinder(Vec(10,sy,10), Vec(sx-11,sy,sz-11)): - n = pn.noise3(p.x/4.0, p.y/4.0, p.z/4.0) + for p in iterate_cylinder(Vec(10, sy, 10), Vec(sx - 11, sy, sz - 11)): + n = pn.noise3(p.x / 4.0, p.y / 4.0, p.z / 4.0) if (n > 0): - sb(o+p, materials.Sand) + sb(o + p, materials.Sand) else: - sb(o+p, materials.Sandstone) + sb(o + p, materials.Sandstone) # Treasure and more spawners - sb(o+Vec(15,sy-1,15), materials.Chest) - self.parent.addchest(o+Vec(15,sy-1,15), loottable._maxtier) - sb(o+Vec(16,sy-1,16), materials.Chest) + sb(o + Vec(15, sy - 1, 15), materials.Chest) + self.parent.addchest(o + Vec(15, sy - 1, 15), loottable._maxtier) + sb(o + Vec(16, sy - 1, 16), materials.Chest) if cfg.double_treasure: - self.parent.addchest(o+Vec(16,sy-1,16), loottable._maxtier) + self.parent.addchest(o + Vec(16, sy - 1, 16), loottable._maxtier) else: - self.parent.addchest(o+Vec(16,sy-1,16)) - sb(o+Vec(15,sy-1,16), materials.Spawner) - self.parent.addspawner(o+Vec(15,sy-1,16), 'Blaze') - sb(o+Vec(16,sy-1,15), materials.Spawner) - self.parent.addspawner(o+Vec(16,sy-1,15), 'Blaze') + self.parent.addchest(o + Vec(16, sy - 1, 16)) + sb(o + Vec(15, sy - 1, 16), materials.Spawner) + self.parent.addspawner(o + Vec(15, sy - 1, 16), 'Blaze') + sb(o + Vec(16, sy - 1, 15), materials.Spawner) + self.parent.addspawner(o + Vec(16, sy - 1, 15), 'Blaze') # Portal - drawExitPortal(o+Vec(2,sy-7,14), self.parent, NS=True) + drawExitPortal(o + Vec(2, sy - 7, 14), self.parent, NS=True) class Crypt(Basic): @@ -1860,39 +1911,39 @@ class Crypt(Basic): _is_entrance = False _is_stairwell = False _is_treasureroom = True - _min_size = Vec(1,1,2) - _max_size = Vec(1,1,2) - size = Vec(1,1,2) + _min_size = Vec(1, 1, 2) + _max_size = Vec(1, 1, 2) + size = Vec(1, 1, 2) def placed(self): self.canvas = ( - Vec(0,self.parent.room_height-2,0), - Vec(0,self.parent.room_height-2,0), - Vec(0,self.parent.room_height-2,0)) + Vec(0, self.parent.room_height - 2, 0), + Vec(0, self.parent.room_height - 2, 0), + Vec(0, self.parent.room_height - 2, 0)) rooms = [] sx = self.parent.room_size sz = self.parent.room_size #sy = self.parent.room_height - # This room contains no halls, but is connected to the South + # This room contains no halls, but is connected to the South pos = self.pos rooms.append(pos) - self.hallLength = [1,1,0,1] - self.hallSize = [[6,sx-6], - [6,sx-6], - [6,sz-6], - [6,sz-6]] - self.parent.halls[pos.x][pos.y][pos.z] = [0,0,1,0] + self.hallLength = [1, 1, 0, 1] + self.hallSize = [[6, sx - 6], + [6, sx - 6], + [6, sz - 6], + [6, sz - 6]] + self.parent.halls[pos.x][pos.y][pos.z] = [0, 0, 1, 0] # Place one room to the South - pos = self.pos + Vec(0,0,1) + pos = self.pos + Vec(0, 0, 1) room = new('blank', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [0,0,0,0] - room.hallSize = [[6,sx-6], - [6,sx-6], - [6,sz-6], - [6,sz-6]] - room.parent.halls[pos.x][pos.y][pos.z] = [1,1,1,1] + room.hallLength = [0, 0, 0, 0] + room.hallSize = [[6, sx - 6], + [6, sx - 6], + [6, sz - 6], + [6, sz - 6]] + room.parent.halls[pos.x][pos.y][pos.z] = [1, 1, 1, 1] # This room cannot connect. Make the depth < 0 room.parent.maze[pos].depth = -1 return rooms @@ -1907,10 +1958,10 @@ def render(self): # alias for setblock sb = self.parent.setblock - # symmetrical setblock. A lot of this room will be symmetrical. - def ssb (p, mat, data=0): - sb(o+p, mat, data) - sb(Vec(o.x+sx-1-p.x, o.y+p.y, o.z+p.z), mat, data) + # symmetrical setblock. A lot of this room will be symmetrical. + def ssb(p, mat, data=0): + sb(o + p, mat, data) + sb(Vec(o.x + sx - 1 - p.x, o.y + p.y, o.z + p.z), mat, data) # Decoration colors # inner color, trim color @@ -1920,130 +1971,130 @@ def ssb (p, mat, data=0): # Basic room # Air space - for p in iterate_cube(o, o+Vec(sx-1,sy-1,sz-1)): + for p in iterate_cube(o, o + Vec(sx - 1, sy - 1, sz - 1)): sb(p, materials.Air) # Walls - for p in iterate_four_walls(o, o+Vec(sx-1,0,sz-1), -sy+1): + for p in iterate_four_walls(o, o + Vec(sx - 1, 0, sz - 1), -sy + 1): sb(p, materials.meta_mossycobble) # Ceiling and floor - for p in iterate_cube(o, o+Vec(sx-1,0,sz-1)): + for p in iterate_cube(o, o + Vec(sx - 1, 0, sz - 1)): sb(p, materials._ceiling) - sb(p.down(sy-1), materials._floor) + sb(p.down(sy - 1), materials._floor) # balcony - for p in iterate_cube(Vec(1,4,1), Vec(3,4,9)): + for p in iterate_cube(Vec(1, 4, 1), Vec(3, 4, 9)): ssb(p, materials.meta_mossystonebrick) - for p in iterate_cube(Vec(1,4,1), Vec(5,4,3)): + for p in iterate_cube(Vec(1, 4, 1), Vec(5, 4, 3)): ssb(p, materials.meta_mossystonebrick) - for p in iterate_cube(Vec(1,4,1), Vec(2,4,8)): + for p in iterate_cube(Vec(1, 4, 1), Vec(2, 4, 8)): ssb(p, materials.StoneBrickSlab) - for p in iterate_cube(Vec(1,4,1), Vec(5,4,2)): + for p in iterate_cube(Vec(1, 4, 1), Vec(5, 4, 2)): ssb(p, materials.StoneBrickSlab) - for p in iterate_cube(Vec(1,3,9), Vec(2,3,9)): + for p in iterate_cube(Vec(1, 3, 9), Vec(2, 3, 9)): ssb(p, materials.IronBars) - for p in iterate_cube(Vec(4,3,3), Vec(5,3,3)): + for p in iterate_cube(Vec(4, 3, 3), Vec(5, 3, 3)): ssb(p, materials.IronBars) - for p in iterate_cube(Vec(3,3,3), Vec(3,3,9)): + for p in iterate_cube(Vec(3, 3, 3), Vec(3, 3, 9)): ssb(p, materials.IronBars) - for p in iterate_cube(Vec(4,2,3), Vec(6,2,3)): + for p in iterate_cube(Vec(4, 2, 3), Vec(6, 2, 3)): ssb(p, materials.IronBars) - ssb(p+Vec(1,-1,0), materials.IronBars) + ssb(p + Vec(1, -1, 0), materials.IronBars) # Entry stairs for x in xrange(6): - ssb(Vec(6,5+x,1+x), materials.meta_mossystonebrick) - ssb(Vec(7,5+x,1+x), materials.meta_mossystonebrick) - ssb(Vec(6,5+x,2+x), materials.meta_mossystonebrick) - ssb(Vec(7,5+x,2+x), materials.meta_mossystonebrick) - ssb(Vec(6,5+x,3+x), materials.StoneBrickStairs, 3) - ssb(Vec(7,5+x,3+x), materials.StoneBrickStairs, 3) + ssb(Vec(6, 5 + x, 1 + x), materials.meta_mossystonebrick) + ssb(Vec(7, 5 + x, 1 + x), materials.meta_mossystonebrick) + ssb(Vec(6, 5 + x, 2 + x), materials.meta_mossystonebrick) + ssb(Vec(7, 5 + x, 2 + x), materials.meta_mossystonebrick) + ssb(Vec(6, 5 + x, 3 + x), materials.StoneBrickStairs, 3) + ssb(Vec(7, 5 + x, 3 + x), materials.StoneBrickStairs, 3) # Skip this is there is no door to the West if self.parent.halls[pos.x][pos.y][pos.z][0] == 1: - for p in iterate_cube(Vec(6,4,1), Vec(7,4,1)): + for p in iterate_cube(Vec(6, 4, 1), Vec(7, 4, 1)): ssb(p, materials.StoneBrickStairs, 3) # Rug - for p in iterate_cube(Vec(6,11,9), Vec(6,11,25)): + for p in iterate_cube(Vec(6, 11, 9), Vec(6, 11, 25)): ssb(p, dmat[1]) - for p in iterate_cube(Vec(7,11,9), Vec(7,11,25)): + for p in iterate_cube(Vec(7, 11, 9), Vec(7, 11, 25)): ssb(p, dmat[0]) for x in xrange(20): - p = Vec(random.randint(6,9), 11, random.randint(9,25)) - sb(o+p, materials._floor) + p = Vec(random.randint(6, 9), 11, random.randint(9, 25)) + sb(o + p, materials._floor) # Back wall wall = random.choice( [ # Creeper - [[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], - [0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0], - [0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0], - [0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0], - [0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0], - [0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0], - [0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]], + [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], + [0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], # Wings - [[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0], - [0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0], - [0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0], - [0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0], - [0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0], - [0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]], + [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0], + [0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0], + [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0], + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], # Triforce - [[0,0,0,0,0,0,2,2,2,2,0,0,0,0,0,0], - [0,0,0,0,0,2,0,2,2,0,2,0,0,0,0,0], - [0,0,0,0,3,0,2,2,2,2,0,3,0,0,0,0], - [0,0,0,3,3,3,0,0,0,0,3,3,3,0,0,0], - [0,0,3,0,0,0,3,0,0,3,0,0,0,3,0,0], - [0,3,3,3,0,3,3,3,3,3,3,0,3,3,3,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]], + [[0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 2, 0, 2, 2, 0, 2, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 3, 0, 2, 2, 2, 2, 0, 3, 0, 0, 0, 0], + [0, 0, 0, 3, 3, 3, 0, 0, 0, 0, 3, 3, 3, 0, 0, 0], + [0, 0, 3, 0, 0, 0, 3, 0, 0, 3, 0, 0, 0, 3, 0, 0], + [0, 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 0, 3, 3, 3, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], # Banners - [[0,3,2,2,3,0,3,2,2,3,0,3,2,2,3,0], - [0,3,2,2,3,0,3,2,2,3,0,3,2,2,3,0], - [0,3,2,2,3,0,3,2,2,3,0,3,2,2,3,0], - [0,3,2,2,3,0,3,2,2,3,0,3,2,2,3,0], - [0,0,2,2,0,0,3,2,2,3,0,0,2,2,0,0], - [0,0,0,0,0,0,3,2,2,3,0,0,0,0,0,0], - [0,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]] + [[0, 3, 2, 2, 3, 0, 3, 2, 2, 3, 0, 3, 2, 2, 3, 0], + [0, 3, 2, 2, 3, 0, 3, 2, 2, 3, 0, 3, 2, 2, 3, 0], + [0, 3, 2, 2, 3, 0, 3, 2, 2, 3, 0, 3, 2, 2, 3, 0], + [0, 3, 2, 2, 3, 0, 3, 2, 2, 3, 0, 3, 2, 2, 3, 0], + [0, 0, 2, 2, 0, 0, 3, 2, 2, 3, 0, 0, 2, 2, 0, 0], + [0, 0, 0, 0, 0, 0, 3, 2, 2, 3, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] ] ) w = materials.StoneBrick for y in xrange(10): for x in xrange(16): if wall[y][x] == 1: - sb(o+Vec(x,y+1,31), w) + sb(o + Vec(x, y + 1, 31), w) elif wall[y][x] == 2: - sb(o+Vec(x,y+1,31), dmat[0]) + sb(o + Vec(x, y + 1, 31), dmat[0]) elif wall[y][x] == 3: - sb(o+Vec(x,y+1,31), dmat[1]) + sb(o + Vec(x, y + 1, 31), dmat[1]) # Loot for the small sarcophagi loota = [] lootb = [] bone = items.byName('bone') - for slot in xrange(11,15,1): - loota.append(loottable.Loot(slot,1,bone.value,bone.data,'')) - lootb.append(loottable.Loot(slot,1,bone.value,bone.data,'')) - for slot in xrange(18,27,1): - loota.append(loottable.Loot(slot,1,bone.value,bone.data,'')) - for slot in xrange(0,9,1): - lootb.append(loottable.Loot(slot,1,bone.value,bone.data,'')) + for slot in xrange(11, 15, 1): + loota.append(loottable.Loot(slot, 1, bone.value, bone.data, '')) + lootb.append(loottable.Loot(slot, 1, bone.value, bone.data, '')) + for slot in xrange(18, 27, 1): + loota.append(loottable.Loot(slot, 1, bone.value, bone.data, '')) + for slot in xrange(0, 9, 1): + lootb.append(loottable.Loot(slot, 1, bone.value, bone.data, '')) # Random stuff to be buried with. lootc = [(items.byName('bone'), 10), @@ -2076,21 +2127,21 @@ def ssb (p, mat, data=0): # Small sarcophagi for zoff in xrange(0, 24, 6): - ssb(Vec(2,10,1+zoff), materials.Sandstone) - ssb(Vec(1,10,2+zoff), materials.Sandstone) - ssb(Vec(3,10,2+zoff), materials.Sandstone) - ssb(Vec(1,10,3+zoff), materials.Sandstone) - ssb(Vec(3,10,3+zoff), materials.Sandstone) - ssb(Vec(1,10,4+zoff), materials.Sandstone) - ssb(Vec(3,10,4+zoff), materials.Sandstone) - ssb(Vec(2,10,5+zoff), materials.Sandstone) - - ssb(Vec(1,10,1+zoff), materials.SandstoneSlab) - ssb(Vec(3,10,1+zoff), materials.SandstoneSlab) - ssb(Vec(1,10,5+zoff), materials.SandstoneSlab) - ssb(Vec(3,10,5+zoff), materials.SandstoneSlab) - - ssb(Vec(2,10,2+zoff), materials.Chest,4) + ssb(Vec(2, 10, 1 + zoff), materials.Sandstone) + ssb(Vec(1, 10, 2 + zoff), materials.Sandstone) + ssb(Vec(3, 10, 2 + zoff), materials.Sandstone) + ssb(Vec(1, 10, 3 + zoff), materials.Sandstone) + ssb(Vec(3, 10, 3 + zoff), materials.Sandstone) + ssb(Vec(1, 10, 4 + zoff), materials.Sandstone) + ssb(Vec(3, 10, 4 + zoff), materials.Sandstone) + ssb(Vec(2, 10, 5 + zoff), materials.Sandstone) + + ssb(Vec(1, 10, 1 + zoff), materials.SandstoneSlab) + ssb(Vec(3, 10, 1 + zoff), materials.SandstoneSlab) + ssb(Vec(1, 10, 5 + zoff), materials.SandstoneSlab) + ssb(Vec(3, 10, 5 + zoff), materials.SandstoneSlab) + + ssb(Vec(2, 10, 2 + zoff), materials.Chest, 4) i = weighted_choice(lootc) loota[7].id = i.value loota[7].damage = i.data @@ -2098,8 +2149,9 @@ def ssb (p, mat, data=0): i = weighted_choice(loothead) loota[4].id = i.value loota[4].damage = i.data - tomb_name = 'Here lies '+self.parent.namegen.genname() - self.parent.addchest(o+Vec(2,10,2+zoff), 0, loot=loota, name=tomb_name) + tomb_name = 'Here lies ' + self.parent.namegen.genname() + self.parent.addchest( + o + Vec(2, 10, 2 + zoff), 0, loot=loota, name=tomb_name) i = weighted_choice(lootc) loota[7].id = i.value loota[7].damage = i.data @@ -2107,122 +2159,124 @@ def ssb (p, mat, data=0): i = weighted_choice(loothead) loota[4].id = i.value loota[4].damage = i.data - tomb_name = 'Here lies '+self.parent.namegen.genname() - self.parent.addchest(o+Vec(13,10,2+zoff), 0, loot=loota, name=tomb_name) - ssb(Vec(2,10,3+zoff), materials.Chest,4) + tomb_name = 'Here lies ' + self.parent.namegen.genname() + self.parent.addchest( + o + Vec(13, 10, 2 + zoff), 0, loot=loota, name=tomb_name) + ssb(Vec(2, 10, 3 + zoff), materials.Chest, 4) i = weighted_choice(lootc) lootb[7].id = i.value lootb[7].damage = i.data lootb[7].flag = i.flag - self.parent.addchest(o+Vec(2,10,3+zoff), 0, loot=lootb) + self.parent.addchest(o + Vec(2, 10, 3 + zoff), 0, loot=lootb) i = weighted_choice(lootc) lootb[7].id = i.value lootb[7].damage = i.data lootb[7].flag = i.flag - self.parent.addchest(o+Vec(13,10,3+zoff), 0, loot=lootb) + self.parent.addchest(o + Vec(13, 10, 3 + zoff), 0, loot=lootb) - ssb(Vec(2,9,2+zoff), materials.StoneBrickStairs, 3) - ssb(Vec(2,9,3+zoff), materials.StoneBrickSlab) - ssb(Vec(2,9,4+zoff), materials.meta_mossystonebrick) + ssb(Vec(2, 9, 2 + zoff), materials.StoneBrickStairs, 3) + ssb(Vec(2, 9, 3 + zoff), materials.StoneBrickSlab) + ssb(Vec(2, 9, 4 + zoff), materials.meta_mossystonebrick) # Spawners - for p in [Vec(2,10,4),Vec(2,10,4+6),Vec(2,10,4+12),Vec(2,10,4+18), - Vec(13,10,4),Vec(13,10,4+6),Vec(13,10,4+12),Vec(13,10,4+18)]: - if random.randint(1,100) >= 33: + for p in [Vec(2, 10, 4), Vec(2, 10, 4 + 6), Vec(2, 10, 4 + 12), Vec(2, 10, 4 + 18), + Vec(13, 10, 4), Vec(13, 10, 4 + 6), Vec(13, 10, 4 + 12), Vec(13, 10, 4 + 18)]: + if random.randint(1, 100) >= 33: continue - self.parent.addspawner(o+p, random.choice(['Skeleton', - 'WitherSkeleton'])) - self.parent.setblock(o+p, materials.Spawner) + self.parent.addspawner(o + p, random.choice(['Skeleton', + 'WitherSkeleton'])) + self.parent.setblock(o + p, materials.Spawner) # Dais - for p in iterate_cube(o.trans(1,10,25), o.trans(14,10,25)): + for p in iterate_cube(o.trans(1, 10, 25), o.trans(14, 10, 25)): sb(p, materials.StoneBrickStairs, 2) - sb(p+Vec(0,-1,1), materials.StoneBrickSlab) - for p in iterate_cube(o.trans(1,9,27), o.trans(14,9,30)): + sb(p + Vec(0, -1, 1), materials.StoneBrickSlab) + for p in iterate_cube(o.trans(1, 9, 27), o.trans(14, 9, 30)): sb(p, materials.meta_mossystonebrick) # Large Sarcophagus - for p in iterate_cube(o.trans(5,8,28), o.trans(10,8,30)): + for p in iterate_cube(o.trans(5, 8, 28), o.trans(10, 8, 30)): sb(p, materials.Sandstone) - ssb(Vec(5,8,28), materials.SandstoneSlab) - ssb(Vec(5,8,30), materials.SandstoneSlab) - sb(o+Vec(6,7,29), materials.StoneBrick) - sb(o+Vec(7,7,29), materials.StoneBrickSlab) - sb(o+Vec(8,7,29), materials.StoneBrickSlab) - sb(o+Vec(9,7,29), materials.StoneBrickStairs, 0) + ssb(Vec(5, 8, 28), materials.SandstoneSlab) + ssb(Vec(5, 8, 30), materials.SandstoneSlab) + sb(o + Vec(6, 7, 29), materials.StoneBrick) + sb(o + Vec(7, 7, 29), materials.StoneBrickSlab) + sb(o + Vec(8, 7, 29), materials.StoneBrickSlab) + sb(o + Vec(9, 7, 29), materials.StoneBrickStairs, 0) # Chest. Maxtier plus a level zero. tomb_name = self.parent.owner - sb(o+Vec(7,8,29), materials.Chest, 2) - self.parent.addchest(o+Vec(7,8,29), loottable._maxtier, name=tomb_name) - sb(o+Vec(8,8,29), materials.Chest, 2) + sb(o + Vec(7, 8, 29), materials.Chest, 2) + self.parent.addchest( + o + Vec(7, 8, 29), loottable._maxtier, name=tomb_name) + sb(o + Vec(8, 8, 29), materials.Chest, 2) if cfg.double_treasure: - self.parent.addchest(o+Vec(8,8,29), loottable._maxtier) + self.parent.addchest(o + Vec(8, 8, 29), loottable._maxtier) else: - self.parent.addchest(o+Vec(8,8,29), 0) + self.parent.addchest(o + Vec(8, 8, 29), 0) # Statues # Legs/body - for p in iterate_cube(Vec(1,8,29), Vec(1,4,29)): + for p in iterate_cube(Vec(1, 8, 29), Vec(1, 4, 29)): ssb(p, materials.StoneBrick) - ssb(p+Vec(1,0,1), materials.StoneBrick) + ssb(p + Vec(1, 0, 1), materials.StoneBrick) # Sword - ssb(Vec(2,8,29), materials.GlassPane) - ssb(Vec(2,7,29), materials.GlassPane) - ssb(Vec(2,6,29), materials.GlassPane) - ssb(Vec(2,5,29), materials.Fence) + ssb(Vec(2, 8, 29), materials.GlassPane) + ssb(Vec(2, 7, 29), materials.GlassPane) + ssb(Vec(2, 6, 29), materials.GlassPane) + ssb(Vec(2, 5, 29), materials.Fence) # Arms - ssb(Vec(1,5,28), materials.StoneBrick) - ssb(Vec(1,4,28), materials.StoneBrickSlab) - ssb(Vec(3,5,30), materials.StoneBrick) - ssb(Vec(3,4,30), materials.StoneBrickSlab) + ssb(Vec(1, 5, 28), materials.StoneBrick) + ssb(Vec(1, 4, 28), materials.StoneBrickSlab) + ssb(Vec(3, 5, 30), materials.StoneBrick) + ssb(Vec(3, 4, 30), materials.StoneBrickSlab) # Head - ssb(Vec(2,3,29), materials.StoneBrick) + ssb(Vec(2, 3, 29), materials.StoneBrick) # Feet - sb(o+Vec(1,8,28), materials.StoneBrickStairs, 2) - sb(o+Vec(3,8,30), materials.StoneBrickStairs, 1) - sb(o+Vec(14,8,28), materials.StoneBrickStairs, 2) - sb(o+Vec(12,8,30), materials.StoneBrickStairs, 0) + sb(o + Vec(1, 8, 28), materials.StoneBrickStairs, 2) + sb(o + Vec(3, 8, 30), materials.StoneBrickStairs, 1) + sb(o + Vec(14, 8, 28), materials.StoneBrickStairs, 2) + sb(o + Vec(12, 8, 30), materials.StoneBrickStairs, 0) # Hands - sb(o+Vec(2,5,28), materials.StoneBrickStairs, 1) - sb(o+Vec(3,5,29), materials.StoneBrickStairs, 2) - sb(o+Vec(13,5,28), materials.StoneBrickStairs, 0) - sb(o+Vec(12,5,29), materials.StoneBrickStairs, 2) + sb(o + Vec(2, 5, 28), materials.StoneBrickStairs, 1) + sb(o + Vec(3, 5, 29), materials.StoneBrickStairs, 2) + sb(o + Vec(13, 5, 28), materials.StoneBrickStairs, 0) + sb(o + Vec(12, 5, 29), materials.StoneBrickStairs, 2) # Eyes - ssb(Vec(2,3,28), materials.StoneButton, 4) - sb(o+Vec(3,3,29), materials.StoneButton, 1) - sb(o+Vec(12,3,29), materials.StoneButton, 2) + ssb(Vec(2, 3, 28), materials.StoneButton, 4) + sb(o + Vec(3, 3, 29), materials.StoneButton, 1) + sb(o + Vec(12, 3, 29), materials.StoneButton, 2) # Torches - ssb(Vec(1,5,30), materials.Torch) + ssb(Vec(1, 5, 30), materials.Torch) # Portal - drawExitPortal(o+Vec(6,7,1), self.parent) + drawExitPortal(o + Vec(6, 7, 1), self.parent) # Webs - for p in iterate_cube(o.trans(5,1,5), o.trans(10,1,30)): + for p in iterate_cube(o.trans(5, 1, 5), o.trans(10, 1, 30)): if random.random() < 0.07: - for q in iterate_cube(p, p.down(random.randint(0,2))): + for q in iterate_cube(p, p.down(random.randint(0, 2))): sb(q, materials.Cobweb) # Vines - for p in iterate_cube(o+Vec(1,1,1), o+Vec(14,9,30)): - if random.randint(1,100) <= 20: + for p in iterate_cube(o + Vec(1, 1, 1), o + Vec(14, 9, 30)): + if random.randint(1, 100) <= 20: self.parent.vines(p, grow=True) # Cobwebs webs = {} - for p in iterate_cube(o.down(1), o.trans(15,4,31)): + for p in iterate_cube(o.down(1), o.trans(15, 4, 31)): count = 0 - perc = 90 - (p.y - self.loc.down(1).y) * (70/3) + perc = 90 - (p.y - self.loc.down(1).y) * (70 / 3) if (p not in self.parent.blocks or - self.parent.blocks[p].material != materials.Air): + self.parent.blocks[p].material != materials.Air): continue - for q in (Vec(1,0,0), Vec(-1,0,0), - Vec(0,1,0), Vec(0,-1,0), - Vec(0,0,1), Vec(0,0,-1)): - if (p+q in self.parent.blocks and - self.parent.blocks[p+q].material != materials.Air and - random.randint(1,100) <= perc): + for q in (Vec(1, 0, 0), Vec(-1, 0, 0), + Vec(0, 1, 0), Vec(0, -1, 0), + Vec(0, 0, 1), Vec(0, 0, -1)): + if (p + q in self.parent.blocks and + self.parent.blocks[p + q].material != materials.Air and + random.randint(1, 100) <= perc): count += 1 if count >= 3: webs[p] = True @@ -2243,20 +2297,20 @@ def setData(self): self.sz = self.size.z * self.parent.room_size self.sy = self.size.y * self.parent.room_height - self.c1 = self.loc + Vec(0,self.sy-2,0) - self.c3 = self.c1 + Vec(self.sx-1, 0, self.sz-1) + self.c1 = self.loc + Vec(0, self.sy - 2, 0) + self.c3 = self.c1 + Vec(self.sx - 1, 0, self.sz - 1) - self.hallLength = [1,1,1,1] - self.hallSize = [[2,self.sx-2], - [2,self.sx-2], - [2,self.sz-2], - [2,self.sz-2]] + self.hallLength = [1, 1, 1, 1] + self.hallSize = [[2, self.sx - 2], + [2, self.sx - 2], + [2, self.sz - 2], + [2, self.sz - 2]] self.canvas = ( - Vec(0 ,self.sy-2, 0), - Vec(self.sx-1,self.sy-2, 0), - Vec(self.sx-1,self.sy-2, self.sz-1), - Vec(0 ,self.sy-2, self.sz-1)) + Vec(0, self.sy - 2, 0), + Vec(self.sx - 1, self.sy - 2, 0), + Vec(self.sx - 1, self.sy - 2, self.sz - 1), + Vec(0, self.sy - 2, self.sz - 1)) self.features.append(features.new('blank', self)) if self._floortype is not '': self.floors.append(floors.new(self._floortype, self)) @@ -2265,19 +2319,31 @@ def placeCavernHalls(self, cave): # West side if (self.halls[0].size > 0): cave.add_exit((0, self.halls[0].offset), - (0, self.halls[0].offset+self.halls[0].size)) + (0, self.halls[0].offset + self.halls[0].size)) # South side if (self.halls[1].size > 0): - cave.add_exit((self.halls[1].offset, self.sz-1), - (self.halls[1].offset+self.halls[1].size, self.sz-1)) + cave.add_exit( + (self.halls[1].offset, + self.sz - + 1), + (self.halls[1].offset + + self.halls[1].size, + self.sz - + 1)) # East side if (self.halls[2].size > 0): - cave.add_exit((self.sx-1, self.halls[2].offset), - (self.sx-1, self.halls[2].offset+self.halls[2].size)) + cave.add_exit( + (self.sx - + 1, + self.halls[2].offset), + (self.sx - + 1, + self.halls[2].offset + + self.halls[2].size)) # North side if (self.halls[3].size > 0): cave.add_exit((self.halls[3].offset, 0), - (self.halls[3].offset+self.halls[3].size, 0)) + (self.halls[3].offset + self.halls[3].size, 0)) def render(self): height = self.size.y * self.parent.room_height - 2 @@ -2289,38 +2355,39 @@ def render(self): cave.gen_map() # Air space, Floor, and Ceiling for p in cave.iterate_map(cave_factory.FLOOR): - self.parent.setblock(self.c1+Vec(p[0],-3,p[1]), materials.Air) - self.parent.setblock(self.c1+Vec(p[0],-2,p[1]), materials.Air) - self.parent.setblock(self.c1+Vec(p[0],-1,p[1]), materials.Air) - self.parent.setblock(self.c1+Vec(p[0],0,p[1]), self._floor) - self.parent.setblock(self.c1+Vec(p[0],-height,p[1]), + self.parent.setblock(self.c1 + Vec(p[0], -3, p[1]), materials.Air) + self.parent.setblock(self.c1 + Vec(p[0], -2, p[1]), materials.Air) + self.parent.setblock(self.c1 + Vec(p[0], -1, p[1]), materials.Air) + self.parent.setblock(self.c1 + Vec(p[0], 0, p[1]), self._floor) + self.parent.setblock(self.c1 + Vec(p[0], -height, p[1]), self._walls, 0, True) # Walls for p in cave.iterate_walls(): - self.parent.setblock(self.c1+Vec(p[0],-4,p[1]), self._walls, - 0, True) - self.parent.setblock(self.c1+Vec(p[0],-3,p[1]), self._walls) - self.parent.setblock(self.c1+Vec(p[0],-2,p[1]), self._walls) - self.parent.setblock(self.c1+Vec(p[0],-1,p[1]), self._walls) + self.parent.setblock(self.c1 + Vec(p[0], -4, p[1]), self._walls, + 0, True) + self.parent.setblock(self.c1 + Vec(p[0], -3, p[1]), self._walls) + self.parent.setblock(self.c1 + Vec(p[0], -2, p[1]), self._walls) + self.parent.setblock(self.c1 + Vec(p[0], -1, p[1]), self._walls) cave.grow_map() for p in cave.iterate_walls(): - self.parent.setblock(self.c1+Vec(p[0],-3,p[1]), self._walls, - 0, True) + self.parent.setblock(self.c1 + Vec(p[0], -3, p[1]), self._walls, + 0, True) # Subfloor sf1 = self.loc.trans(0, self.size.y * self.parent.room_height - 1, 0) - sf2 = sf1.trans(self.size.x * self.parent.room_size-1, - 0, - self.size.z * self.parent.room_size-1) + sf2 = sf1.trans(self.size.x * self.parent.room_size - 1, + 0, + self.size.z * self.parent.room_size - 1) for x in iterate_plane(sf1, sf2): self.parent.setblock(x, self._subfloor) + class SandstoneCavernLarge(SandstoneCavern): _name = 'sandstonecavernlarge' - _min_size = Vec(2,1,2) - _max_size = Vec(2,1,2) - size = Vec(2,1,2) + _min_size = Vec(2, 1, 2) + _max_size = Vec(2, 1, 2) + size = Vec(2, 1, 2) _spread_chance = .30 _small_cavern = 'sandstonecavern' @@ -2333,93 +2400,94 @@ def placed(self): # West, South, East, North pos = self.pos rooms.append(pos) - self.hallLength = [1,0,0,1] - self.hallSize = [[2,sx-2], - [2,sx-2], - [2,sz-2], - [2,sz-2]] + self.hallLength = [1, 0, 0, 1] + self.hallSize = [[2, sx - 2], + [2, sx - 2], + [2, sz - 2], + [2, sz - 2]] self.parent.halls[pos.x][pos.y][pos.z][1] = 1 self.parent.halls[pos.x][pos.y][pos.z][2] = 1 # place three more blank rooms to hold the hallways # This is the Southern room - pos = self.pos + Vec(1,0,0) + pos = self.pos + Vec(1, 0, 0) room = new('cblank', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [1,1,0,0] - room.hallSize = [[2,sx-2], - [2,sx-2], - [2,sz-2], - [2,sz-2]] + room.hallLength = [1, 1, 0, 0] + room.hallSize = [[2, sx - 2], + [2, sx - 2], + [2, sz - 2], + [2, sz - 2]] room.parent.halls[pos.x][pos.y][pos.z][2] = 1 room.parent.halls[pos.x][pos.y][pos.z][3] = 1 # Eastern room. - pos = self.pos + Vec(0,0,1) + pos = self.pos + Vec(0, 0, 1) room = new('cblank', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [0,0,1,1] - room.hallSize = [[2,sx-2], - [2,sx-2], - [2,sz-2], - [2,sz-2]] + room.hallLength = [0, 0, 1, 1] + room.hallSize = [[2, sx - 2], + [2, sx - 2], + [2, sz - 2], + [2, sz - 2]] room.parent.halls[pos.x][pos.y][pos.z][0] = 1 room.parent.halls[pos.x][pos.y][pos.z][1] = 1 # South East room. - pos = self.pos + Vec(1,0,1) + pos = self.pos + Vec(1, 0, 1) room = new('cblank', self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) - room.hallLength = [0,1,1,0] - room.hallSize = [[2,sx-2], - [2,sx-2], - [2,sz-2], - [2,sz-2]] + room.hallLength = [0, 1, 1, 0] + room.hallSize = [[2, sx - 2], + [2, sx - 2], + [2, sz - 2], + [2, sz - 2]] room.parent.halls[pos.x][pos.y][pos.z][0] = 1 room.parent.halls[pos.x][pos.y][pos.z][3] = 1 - # There's a chance large caverns will spawn adjacent small cavern rooms. + # There's a chance large caverns will spawn adjacent small cavern + # rooms. h = self.parent.halls s = self.pos for p in (Vec(-1, 0, 0), Vec(-1, 0, 1), # North - Vec( 2, 0, 0), Vec( 2, 0, 1), # South - Vec( 0, 0, 2), Vec( 1, 0, 2), # East - Vec( 0, 0,-1), Vec( 1, 0,-1)): # West + Vec(2, 0, 0), Vec(2, 0, 1), # South + Vec(0, 0, 2), Vec(1, 0, 2), # East + Vec(0, 0, -1), Vec(1, 0, -1)): # West pos = self.pos + p if (pos.x >= 0 and - pos.z >= 0 and - pos.x < self.parent.xsize and - pos.z < self.parent.zsize and - pos not in self.parent.rooms and - random.random() < self._spread_chance): + pos.z >= 0 and + pos.x < self.parent.xsize and + pos.z < self.parent.zsize and + pos not in self.parent.rooms and + random.random() < self._spread_chance): room = new(self._small_cavern, self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) # Connect teh halls for each case # North if (p == Vec(-1, 0, 0)): h[s.x][s.y][s.z][3] = 1 - h[s.x-1][s.y][s.z][1] = 1 + h[s.x - 1][s.y][s.z][1] = 1 elif (p == Vec(-1, 0, 1)): - h[s.x][s.y][s.z+1][3] = 1 - h[s.x-1][s.y][s.z+1][1] = 1 + h[s.x][s.y][s.z + 1][3] = 1 + h[s.x - 1][s.y][s.z + 1][1] = 1 # South elif (p == Vec(2, 0, 0)): - h[s.x+1][s.y][s.z][1] = 1 - h[s.x+2][s.y][s.z][3] = 1 + h[s.x + 1][s.y][s.z][1] = 1 + h[s.x + 2][s.y][s.z][3] = 1 elif (p == Vec(2, 0, 1)): - h[s.x+1][s.y][s.z+1][1] = 1 - h[s.x+2][s.y][s.z+1][3] = 1 + h[s.x + 1][s.y][s.z + 1][1] = 1 + h[s.x + 2][s.y][s.z + 1][3] = 1 # East elif (p == Vec(0, 0, 2)): - h[s.x][s.y][s.z+1][2] = 1 - h[s.x][s.y][s.z+2][0] = 1 + h[s.x][s.y][s.z + 1][2] = 1 + h[s.x][s.y][s.z + 2][0] = 1 elif (p == Vec(1, 0, 2)): - h[s.x+1][s.y][s.z+1][2] = 1 - h[s.x+1][s.y][s.z+2][0] = 1 + h[s.x + 1][s.y][s.z + 1][2] = 1 + h[s.x + 1][s.y][s.z + 2][0] = 1 # West elif (p == Vec(0, 0, -1)): h[s.x][s.y][s.z][0] = 1 - h[s.x][s.y][s.z-1][2] = 1 + h[s.x][s.y][s.z - 1][2] = 1 elif (p == Vec(1, 0, -1)): - h[s.x+1][s.y][s.z][0] = 1 - h[s.x+1][s.y][s.z-1][2] = 1 + h[s.x + 1][s.y][s.z][0] = 1 + h[s.x + 1][s.y][s.z - 1][2] = 1 else: sys.exit('Cavern connected to unknown room! Aiiee!') @@ -2428,40 +2496,80 @@ def placed(self): def placeCavernHalls(self, cave): ''' Used when rendering to set exit zones for the cave factory''' # NE room - room_ne = self.parent.rooms[self.pos + Vec(0,0,1)] + room_ne = self.parent.rooms[self.pos + Vec(0, 0, 1)] # SE room - room_se = self.parent.rooms[self.pos + Vec(1,0,1)] + room_se = self.parent.rooms[self.pos + Vec(1, 0, 1)] # SW room - room_sw = self.parent.rooms[self.pos + Vec(1,0,0)] + room_sw = self.parent.rooms[self.pos + Vec(1, 0, 0)] # West side if (self.halls[0].size > 0): cave.add_exit((0, self.halls[0].offset), - (0, self.halls[0].offset+self.halls[0].size)) + (0, self.halls[0].offset + self.halls[0].size)) if (room_sw.halls[0].size > 0): - cave.add_exit((0, 16+room_sw.halls[0].offset), - (0, 16+room_sw.halls[0].offset+room_sw.halls[0].size)) + cave.add_exit( + (0, + 16 + + room_sw.halls[0].offset), + (0, + 16 + + room_sw.halls[0].offset + + room_sw.halls[0].size)) # South side if (room_se.halls[1].size > 0): - cave.add_exit((16+room_se.halls[1].offset, self.sz-1), - (16+room_se.halls[1].offset+room_se.halls[1].size, self.sz-1)) + cave.add_exit( + (16 + + room_se.halls[1].offset, + self.sz - + 1), + (16 + + room_se.halls[1].offset + + room_se.halls[1].size, + self.sz - + 1)) if (room_sw.halls[1].size > 0): - cave.add_exit((room_sw.halls[1].offset, self.sz-1), - (room_sw.halls[1].offset+room_sw.halls[1].size, self.sz-1)) + cave.add_exit( + (room_sw.halls[1].offset, + self.sz - + 1), + (room_sw.halls[1].offset + + room_sw.halls[1].size, + self.sz - + 1)) # East side if (room_ne.halls[2].size > 0): - cave.add_exit((self.sx-1, room_ne.halls[2].offset), - (self.sx-1, room_ne.halls[2].offset+room_ne.halls[2].size)) + cave.add_exit( + (self.sx - + 1, + room_ne.halls[2].offset), + (self.sx - + 1, + room_ne.halls[2].offset + + room_ne.halls[2].size)) if (room_se.halls[2].size > 0): - cave.add_exit((self.sx-1, 16+room_se.halls[2].offset), - (self.sx-1, 16+room_se.halls[2].offset+room_se.halls[2].size)) + cave.add_exit( + (self.sx - + 1, + 16 + + room_se.halls[2].offset), + (self.sx - + 1, + 16 + + room_se.halls[2].offset + + room_se.halls[2].size)) # North side if (self.halls[3].size > 0): cave.add_exit((self.halls[3].offset, 0), - (self.halls[3].offset+self.halls[3].size, 0)) + (self.halls[3].offset + self.halls[3].size, 0)) if (room_ne.halls[3].size > 0): - cave.add_exit((16+room_ne.halls[3].offset, 0), - (16+room_ne.halls[3].offset+room_ne.halls[3].size, 0)) + cave.add_exit( + (16 + + room_ne.halls[3].offset, + 0), + (16 + + room_ne.halls[3].offset + + room_ne.halls[3].size, + 0)) class Cavern(SandstoneCavern): @@ -2508,37 +2616,37 @@ def setData(self): self.ceil_func = iterate_disc self.floor_func = iterate_disc self.air_func = iterate_cylinder - self.c1 = self.loc + Vec(0,self.parent.room_height-2,0) - self.c3 = self.c1 + Vec(self.parent.room_size-1, + self.c1 = self.loc + Vec(0, self.parent.room_height - 2, 0) + self.c3 = self.c1 + Vec(self.parent.room_size - 1, 0, - self.parent.room_size-1) + self.parent.room_size - 1) # North, East, South, West - self.hallLength = [1,1,1,1] + self.hallLength = [1, 1, 1, 1] self.hallSize = [ - [5,self.parent.room_size-5], - [5,self.parent.room_size-5], - [5,self.parent.room_size-5], - [5,self.parent.room_size-5]] + [5, self.parent.room_size - 5], + [5, self.parent.room_size - 5], + [5, self.parent.room_size - 5], + [5, self.parent.room_size - 5]] self.canvas = ( - Vec(5,self.parent.room_height-2,2), - Vec(self.parent.room_size-6,self.parent.room_height-2,2), - Vec(self.parent.room_size-3,self.parent.room_height-2,5), - Vec(self.parent.room_size-3, - self.parent.room_height-2, - self.parent.room_size-6), - Vec(self.parent.room_size-6, - self.parent.room_height-2, - self.parent.room_size-3), - Vec(5,self.parent.room_height-2,self.parent.room_size-3), - Vec(2,self.parent.room_height-2,self.parent.room_size-6), - Vec(2,self.parent.room_height-2,5)) + Vec(5, self.parent.room_height - 2, 2), + Vec(self.parent.room_size - 6, self.parent.room_height - 2, 2), + Vec(self.parent.room_size - 3, self.parent.room_height - 2, 5), + Vec(self.parent.room_size - 3, + self.parent.room_height - 2, + self.parent.room_size - 6), + Vec(self.parent.room_size - 6, + self.parent.room_height - 2, + self.parent.room_size - 3), + Vec(5, self.parent.room_height - 2, self.parent.room_size - 3), + Vec(2, self.parent.room_height - 2, self.parent.room_size - 6), + Vec(2, self.parent.room_height - 2, 5)) class Pit(Blank): _name = 'pit' - _min_size = Vec(1,1,1) - _max_size = Vec(1,18,1) - size = Vec(1,1,1) + _min_size = Vec(1, 1, 1) + _max_size = Vec(1, 18, 1) + size = Vec(1, 1, 1) def setData(self): self.midroom = 'pitmid' @@ -2547,24 +2655,24 @@ def setData(self): self.ceil_func = iterate_cube self.floor_func = iterate_cube self.air_func = iterate_cube - self.c1 = self.loc + Vec(2,self.parent.room_height-2,2) - self.c3 = self.c1 + Vec(self.parent.room_size-5, + self.c1 = self.loc + Vec(2, self.parent.room_height - 2, 2) + self.c3 = self.c1 + Vec(self.parent.room_size - 5, 0, - self.parent.room_size-5) + self.parent.room_size - 5) # North, East, South, West - self.hallLength = [3,3,3,3] + self.hallLength = [3, 3, 3, 3] self.hallSize = [ - [2,self.parent.room_size-2], - [2,self.parent.room_size-2], - [2,self.parent.room_size-2], - [2,self.parent.room_size-2]] + [2, self.parent.room_size - 2], + [2, self.parent.room_size - 2], + [2, self.parent.room_size - 2], + [2, self.parent.room_size - 2]] self.canvas = ( - Vec(4,self.parent.room_height-2,4), - Vec(self.parent.room_size-5,self.parent.room_height-2,4), - Vec(self.parent.room_size-5, - self.parent.room_height-2, - self.parent.room_size-5), - Vec(4,self.parent.room_height-2,self.parent.room_size-5)) + Vec(4, self.parent.room_height - 2, 4), + Vec(self.parent.room_size - 5, self.parent.room_height - 2, 4), + Vec(self.parent.room_size - 5, + self.parent.room_height - 2, + self.parent.room_size - 5), + Vec(4, self.parent.room_height - 2, self.parent.room_size - 5)) self.lava = False self.toLava = False self.sandpit = False @@ -2574,9 +2682,9 @@ def setData(self): def placed(self): rooms = [] # Extend downward. First, figure out where we are and how far down - # we would like to go. - thisfloor = self.pos.y+1 - targetdepth = random.randint(1, max(self.parent.levels-thisfloor,1)) + # we would like to go. + thisfloor = self.pos.y + 1 + targetdepth = random.randint(1, max(self.parent.levels - thisfloor, 1)) self.depth = 1 # Place lower rooms. pos = self.pos @@ -2586,7 +2694,7 @@ def placed(self): if (pos in self.parent.rooms): break if (pos.down(1) in self.parent.rooms or - self.depth+1 == targetdepth): + self.depth + 1 == targetdepth): room = new(self.bottomroom, self.parent, pos) rooms.extend(self.parent.setroom(pos, room)) self.depth += 1 @@ -2599,56 +2707,56 @@ def placed(self): # If this is the only level, make it a lava pit. if (self.depth == 1): self.lava = True - # Otherwise build bridges. Or maybe a sand trap. + # Otherwise build bridges. Or maybe a sand trap. else: self.floors.append(floors.new('bridges', self)) return rooms - def render (self): + def render(self): pn = perlin.SimplexNoise(256) # Sand pit! maxhall = max(map(lambda x: x.size, self.halls)) if (self.depth > 1 and - random.randint(1,100) <= cfg.sand_traps): + random.randint(1, 100) <= cfg.sand_traps): self.sandpit = True if [f for f in self.floors if f._name == 'bridges']: f.sandpit = True # 50/50 chance of adding some columns to further the illusion. if ([f for f in cfg.master_features if (f[0] == 'columns' and - f[1] > 0)] and - random.randint(1,100) <= 50): + f[1] > 0)] and + random.randint(1, 100) <= 50): self.features.append(features.new('columns', self)) - height = self.parent.room_height-2 + height = self.parent.room_height - 2 # Air space for x in self.air_func(self.c1.down(1), self.c3.up(4)): self.parent.setblock(x, materials.Air) # Lava if (self.lava is True): - for x in self.floor_func(self.c1.trans(0,1,0), - self.c3.trans(0,1,0)): + for x in self.floor_func(self.c1.trans(0, 1, 0), + self.c3.trans(0, 1, 0)): self.parent.setblock(x, materials.Lava) - r = random.randint(1,1000) - for x in self.floor_func(self.c1.trans(0,1,0), - self.c3.trans(0,1,0)): - n = (pn.noise3(x.x/4.0, r/4.0, x.z/4.0) + 1.0) / 2.0 + r = random.randint(1, 1000) + for x in self.floor_func(self.c1.trans(0, 1, 0), + self.c3.trans(0, 1, 0)): + n = (pn.noise3(x.x / 4.0, r / 4.0, x.z / 4.0) + 1.0) / 2.0 if (n > 0.7): self.parent.setblock(x.up(1), materials.CobblestoneSlab) - if (self.parent.getblock(x.trans(1,0,0)) is - materials.Lava): - self.parent.setblock(x.trans(1,0,0), + if (self.parent.getblock(x.trans(1, 0, 0)) is + materials.Lava): + self.parent.setblock(x.trans(1, 0, 0), materials.meta_mossycobble) - if (self.parent.getblock(x.trans(-1,0,0)) is - materials.Lava): - self.parent.setblock(x.trans(-1,0,0), + if (self.parent.getblock(x.trans(-1, 0, 0)) is + materials.Lava): + self.parent.setblock(x.trans(-1, 0, 0), materials.meta_mossycobble) - if (self.parent.getblock(x.trans(0,0,1)) is - materials.Lava): - self.parent.setblock(x.trans(0,0,1), + if (self.parent.getblock(x.trans(0, 0, 1)) is + materials.Lava): + self.parent.setblock(x.trans(0, 0, 1), materials.meta_mossycobble) - if (self.parent.getblock(x.trans(0,0,-1)) is - materials.Lava): - self.parent.setblock(x.trans(0,0,-1), + if (self.parent.getblock(x.trans(0, 0, -1)) is + materials.Lava): + self.parent.setblock(x.trans(0, 0, -1), materials.meta_mossycobble) if (n < 0.2): self.parent.setblock(x, materials.Air) @@ -2656,14 +2764,15 @@ def render (self): for x in self.ceil_func(self.c1.up(4), self.c3.up(4)): self.parent.setblock(x, materials._ceiling) # Floor with no subfloor if this is a sand pit - if (self.sandpit == True): - for x in self.floor_func(self.c1.trans(0,0,0), - self.c3.trans(0,0,0)): + if (self.sandpit): + for x in self.floor_func(self.c1.trans(0, 0, 0), + self.c3.trans(0, 0, 0)): self.parent.setblock(x, materials._floor) # Walls - for x in self.wall_func(self.c1.down(1), self.c3.down(1), height+1): + for x in self.wall_func(self.c1.down(1), self.c3.down(1), height + 1): self.parent.setblock(x, materials._wall) + class CircularPit(Pit): _name = 'circularpit' @@ -2674,30 +2783,30 @@ def setData(self): self.ceil_func = iterate_disc self.floor_func = iterate_disc self.air_func = iterate_cylinder - self.c1 = self.loc + Vec(0,self.parent.room_height-2,0) - self.c3 = self.c1 + Vec(self.parent.room_size-1, + self.c1 = self.loc + Vec(0, self.parent.room_height - 2, 0) + self.c3 = self.c1 + Vec(self.parent.room_size - 1, 0, - self.parent.room_size-1) + self.parent.room_size - 1) # North, East, South, West - self.hallLength = [1,1,1,1] + self.hallLength = [1, 1, 1, 1] self.hallSize = [ - [5,self.parent.room_size-5], - [5,self.parent.room_size-5], - [5,self.parent.room_size-5], - [5,self.parent.room_size-5]] + [5, self.parent.room_size - 5], + [5, self.parent.room_size - 5], + [5, self.parent.room_size - 5], + [5, self.parent.room_size - 5]] self.canvas = ( - Vec(5,self.parent.room_height-2,2), - Vec(self.parent.room_size-6,self.parent.room_height-2,2), - Vec(self.parent.room_size-3,self.parent.room_height-2,5), - Vec(self.parent.room_size-3, - self.parent.room_height-2, - self.parent.room_size-6), - Vec(self.parent.room_size-6, - self.parent.room_height-2, - self.parent.room_size-3), - Vec(5,self.parent.room_height-2,self.parent.room_size-3), - Vec(2,self.parent.room_height-2,self.parent.room_size-6), - Vec(2,self.parent.room_height-2,5)) + Vec(5, self.parent.room_height - 2, 2), + Vec(self.parent.room_size - 6, self.parent.room_height - 2, 2), + Vec(self.parent.room_size - 3, self.parent.room_height - 2, 5), + Vec(self.parent.room_size - 3, + self.parent.room_height - 2, + self.parent.room_size - 6), + Vec(self.parent.room_size - 6, + self.parent.room_height - 2, + self.parent.room_size - 3), + Vec(5, self.parent.room_height - 2, self.parent.room_size - 3), + Vec(2, self.parent.room_height - 2, self.parent.room_size - 6), + Vec(2, self.parent.room_height - 2, 5)) self.lava = False self.toLava = False self.sandpit = False @@ -2713,21 +2822,21 @@ def setData(self): self.ceil_func = iterate_cube self.floor_func = iterate_cube self.air_func = iterate_cube - self.c1 = self.loc + Vec(2,self.parent.room_height-2,2) - self.c3 = self.c1 + Vec(self.parent.room_size-5, + self.c1 = self.loc + Vec(2, self.parent.room_height - 2, 2) + self.c3 = self.c1 + Vec(self.parent.room_size - 5, 0, - self.parent.room_size-5) + self.parent.room_size - 5) # North, East, South, West - self.hallLength = [3,3,3,3] + self.hallLength = [3, 3, 3, 3] self.hallSize = [ - [2,self.parent.room_size-2], - [2,self.parent.room_size-2], - [2,self.parent.room_size-2], - [2,self.parent.room_size-2]] + [2, self.parent.room_size - 2], + [2, self.parent.room_size - 2], + [2, self.parent.room_size - 2], + [2, self.parent.room_size - 2]] self.canvas = ( - Vec(0,self.parent.room_height-2,0), - Vec(0,self.parent.room_height-2,0), - Vec(0,self.parent.room_height-2,0)) + Vec(0, self.parent.room_height - 2, 0), + Vec(0, self.parent.room_height - 2, 0), + Vec(0, self.parent.room_height - 2, 0)) def placed(self): # This room needs bridges @@ -2735,54 +2844,56 @@ def placed(self): self.features.append(features.new('blank', self)) return [self.pos] - def render (self): - height = self.parent.room_height-2 + def render(self): + height = self.parent.room_height - 2 # Air space for x in self.air_func(self.c1.down(1), self.c3.up(4)): self.parent.setblock(x, materials.Air) # Skeleton balconies! (for circular pit rooms only) - corner = 1 if self.halls[0].size>0 else 0 - corner += 2 if self.halls[1].size>0 else 0 - corner += 4 if self.halls[2].size>0 else 0 - corner += 8 if self.halls[3].size>0 else 0 - b1 = Vec(0,0,0) # corner 1 of the balcony - b2 = Vec(0,0,0) # corner 2 of the balcony - b3 = Vec(0,0,0) # Skeleton spawner + corner = 1 if self.halls[0].size > 0 else 0 + corner += 2 if self.halls[1].size > 0 else 0 + corner += 4 if self.halls[2].size > 0 else 0 + corner += 8 if self.halls[3].size > 0 else 0 + b1 = Vec(0, 0, 0) # corner 1 of the balcony + b2 = Vec(0, 0, 0) # corner 2 of the balcony + b3 = Vec(0, 0, 0) # Skeleton spawner balcony = False - if (self._name == 'circularpitmid' and random.randint(1,100) <= - cfg.skeleton_balconies): + if (self._name == 'circularpitmid' and random.randint(1, 100) <= + cfg.skeleton_balconies): if (corner == 3): balcony = True - b1 = self.loc.down(height+1)+Vec(0,0,self.parent.room_size-1) - b2 = b1+Vec(6,0,-6) - b3 = b1+Vec(2,-1,-2) + b1 = self.loc.down( + height + 1) + Vec(0, 0, self.parent.room_size - 1) + b2 = b1 + Vec(6, 0, -6) + b3 = b1 + Vec(2, -1, -2) if (corner == 6): balcony = True - b1 = self.loc.down(height+1) - b2 = b1+Vec(6,0,6) - b3 = b1+Vec(2,-1,2) + b1 = self.loc.down(height + 1) + b2 = b1 + Vec(6, 0, 6) + b3 = b1 + Vec(2, -1, 2) if (corner == 9): balcony = True - b1 = self.loc.down(height+1)+Vec(self.parent.room_size-1, - 0, - self.parent.room_size-1) - b2 = b1+Vec(-6,0,-6) - b3 = b1+Vec(-2,-1,-2) + b1 = self.loc.down(height + 1) + Vec(self.parent.room_size - 1, + 0, + self.parent.room_size - 1) + b2 = b1 + Vec(-6, 0, -6) + b3 = b1 + Vec(-2, -1, -2) if (corner == 12): balcony = True - b1 = self.loc.down(height+1)+Vec(self.parent.room_size-1,0,0) - b2 = b1+Vec(-6,0,6) - b3 = b1+Vec(-2,-1,2) - if balcony == True: + b1 = self.loc.down( + height + 1) + Vec(self.parent.room_size - 1, 0, 0) + b2 = b1 + Vec(-6, 0, 6) + b3 = b1 + Vec(-2, -1, 2) + if balcony: for p in iterate_tube(b1, b2, 1): self.parent.setblock(p, materials.Fence) for p in iterate_disc(b1, b2): self.parent.setblock(p, materials._floor) # Walls - for x in self.wall_func(self.c1.down(1), self.c3.down(1), height+1): + for x in self.wall_func(self.c1.down(1), self.c3.down(1), height + 1): self.parent.setblock(x, materials._wall) # Skeleton balconies! - if balcony == True: + if balcony: self.parent.addspawner(b3, 'Skeleton') self.parent.setblock(b3, materials.Spawner) @@ -2795,34 +2906,34 @@ def setData(self): self.ceil_func = iterate_disc self.floor_func = iterate_disc self.air_func = iterate_cylinder - self.c1 = self.loc + Vec(0,self.parent.room_height-2,0) - self.c3 = self.c1 + Vec(self.parent.room_size-1, + self.c1 = self.loc + Vec(0, self.parent.room_height - 2, 0) + self.c3 = self.c1 + Vec(self.parent.room_size - 1, 0, - self.parent.room_size-1) + self.parent.room_size - 1) # North, East, South, West - self.hallLength = [1,1,1,1] + self.hallLength = [1, 1, 1, 1] self.hallSize = [ - [5,self.parent.room_size-5], - [5,self.parent.room_size-5], - [5,self.parent.room_size-5], - [5,self.parent.room_size-5]] - #self.canvas = ( + [5, self.parent.room_size - 5], + [5, self.parent.room_size - 5], + [5, self.parent.room_size - 5], + [5, self.parent.room_size - 5]] + # self.canvas = ( # Vec(0,self.parent.room_height-2,0), # Vec(0,self.parent.room_height-2,0), # Vec(0,self.parent.room_height-2,0)) self.canvas = ( - Vec(5,self.parent.room_height-2,2), - Vec(self.parent.room_size-6,self.parent.room_height-2,2), - Vec(self.parent.room_size-3,self.parent.room_height-2,5), - Vec(self.parent.room_size-3, - self.parent.room_height-2, - self.parent.room_size-6), - Vec(self.parent.room_size-6, - self.parent.room_height-2, - self.parent.room_size-3), - Vec(5,self.parent.room_height-2,self.parent.room_size-3), - Vec(2,self.parent.room_height-2,self.parent.room_size-6), - Vec(2,self.parent.room_height-2,5)) + Vec(5, self.parent.room_height - 2, 2), + Vec(self.parent.room_size - 6, self.parent.room_height - 2, 2), + Vec(self.parent.room_size - 3, self.parent.room_height - 2, 5), + Vec(self.parent.room_size - 3, + self.parent.room_height - 2, + self.parent.room_size - 6), + Vec(self.parent.room_size - 6, + self.parent.room_height - 2, + self.parent.room_size - 3), + Vec(5, self.parent.room_height - 2, self.parent.room_size - 3), + Vec(2, self.parent.room_height - 2, self.parent.room_size - 6), + Vec(2, self.parent.room_height - 2, 5)) class PitBottom(Blank): @@ -2833,87 +2944,87 @@ def setData(self): self.ceil_func = iterate_cube self.floor_func = iterate_cube self.air_func = iterate_cube - self.c1 = self.loc + Vec(2,self.parent.room_height-2,2) - self.c3 = self.c1 + Vec(self.parent.room_size-5, + self.c1 = self.loc + Vec(2, self.parent.room_height - 2, 2) + self.c3 = self.c1 + Vec(self.parent.room_size - 5, 0, - self.parent.room_size-5) + self.parent.room_size - 5) # North, East, South, West - self.hallLength = [3,3,3,3] + self.hallLength = [3, 3, 3, 3] self.hallSize = [ - [2,self.parent.room_size-2], - [2,self.parent.room_size-2], - [2,self.parent.room_size-2], - [2,self.parent.room_size-2]] + [2, self.parent.room_size - 2], + [2, self.parent.room_size - 2], + [2, self.parent.room_size - 2], + [2, self.parent.room_size - 2]] self.canvas = ( - Vec(4,self.parent.room_height-2,4), - Vec(self.parent.room_size-5,self.parent.room_height-2,4), - Vec(self.parent.room_size-5, - self.parent.room_height-2, - self.parent.room_size-5), - Vec(4,self.parent.room_height-2,self.parent.room_size-5)) + Vec(4, self.parent.room_height - 2, 4), + Vec(self.parent.room_size - 5, self.parent.room_height - 2, 4), + Vec(self.parent.room_size - 5, + self.parent.room_height - 2, + self.parent.room_size - 5), + Vec(4, self.parent.room_height - 2, self.parent.room_size - 5)) self.floor = 'floor' def placed(self): - self.floor = random.choice(('floor','lava','cactus')) + self.floor = random.choice(('floor', 'lava', 'cactus')) if (self.floor is not 'floor'): self.floors.append(floors.new('blank', self)) self.features.append(features.new('blank', self)) return [self.pos] - def render (self): + def render(self): pn = perlin.SimplexNoise(256) - height = self.parent.room_height-2 + height = self.parent.room_height - 2 # Air space for x in self.air_func(self.c1.down(1), self.c3.up(4)): self.parent.setblock(x, materials.Air) # Lava if (self.floor == 'lava'): - for x in self.floor_func(self.c1.trans(0,1,0), - self.c3.trans(0,1,0)): + for x in self.floor_func(self.c1.trans(0, 1, 0), + self.c3.trans(0, 1, 0)): self.parent.setblock(x, materials.Lava) - r = random.randint(1,1000) - for x in self.floor_func(self.c1.trans(0,1,0), - self.c3.trans(0,1,0)): - n = (pn.noise3(x.x/4.0, r/4.0, x.z/4.0) + 1.0) / 2.0 + r = random.randint(1, 1000) + for x in self.floor_func(self.c1.trans(0, 1, 0), + self.c3.trans(0, 1, 0)): + n = (pn.noise3(x.x / 4.0, r / 4.0, x.z / 4.0) + 1.0) / 2.0 if (n > 0.7): self.parent.setblock(x.up(1), materials.CobblestoneSlab) - if (self.parent.getblock(x.trans(1,0,0)) is - materials.Lava): - self.parent.setblock(x.trans(1,0,0), + if (self.parent.getblock(x.trans(1, 0, 0)) is + materials.Lava): + self.parent.setblock(x.trans(1, 0, 0), materials.meta_mossycobble) - if (self.parent.getblock(x.trans(-1,0,0)) is - materials.Lava): - self.parent.setblock(x.trans(-1,0,0), + if (self.parent.getblock(x.trans(-1, 0, 0)) is + materials.Lava): + self.parent.setblock(x.trans(-1, 0, 0), materials.meta_mossycobble) - if (self.parent.getblock(x.trans(0,0,1)) is - materials.Lava): - self.parent.setblock(x.trans(0,0,1), + if (self.parent.getblock(x.trans(0, 0, 1)) is + materials.Lava): + self.parent.setblock(x.trans(0, 0, 1), materials.meta_mossycobble) - if (self.parent.getblock(x.trans(0,0,-1)) is - materials.Lava): - self.parent.setblock(x.trans(0,0,-1), + if (self.parent.getblock(x.trans(0, 0, -1)) is + materials.Lava): + self.parent.setblock(x.trans(0, 0, -1), materials.meta_mossycobble) if (n < 0.2): self.parent.setblock(x, materials.Air) # Cactus (spike trap) elif (self.floor == 'cactus'): - for x in self.floor_func(self.c1.trans(0,0,0), - self.c3.trans(0,0,0)): + for x in self.floor_func(self.c1.trans(0, 0, 0), + self.c3.trans(0, 0, 0)): self.parent.setblock(x, materials.Sand) self.parent.setblock(x.down(1), materials._subfloor) - for x in self.floor_func(self.c1.trans(2,-1,2), - self.c3.trans(-2,-1,-2)): - if ((x.x+x.z)%2 == 0): - for p in iterate_cube(x, x.up(random.randint(0,2))): + for x in self.floor_func(self.c1.trans(2, -1, 2), + self.c3.trans(-2, -1, -2)): + if ((x.x + x.z) % 2 == 0): + for p in iterate_cube(x, x.up(random.randint(0, 2))): self.parent.setblock(p, materials.Cactus) # Floor else: - for x in self.floor_func(self.c1.trans(0,0,0), - self.c3.trans(0,0,0)): + for x in self.floor_func(self.c1.trans(0, 0, 0), + self.c3.trans(0, 0, 0)): self.parent.setblock(x, materials._floor) self.parent.setblock(x.down(1), materials._subfloor) # Walls - for x in self.wall_func(self.c1.down(1), self.c3.down(1), height+1): + for x in self.wall_func(self.c1.down(1), self.c3.down(1), height + 1): self.parent.setblock(x, materials._wall) @@ -2925,30 +3036,30 @@ def setData(self): self.ceil_func = iterate_disc self.floor_func = iterate_disc self.air_func = iterate_cylinder - self.c1 = self.loc + Vec(0,self.parent.room_height-2,0) - self.c3 = self.c1 + Vec(self.parent.room_size-1, + self.c1 = self.loc + Vec(0, self.parent.room_height - 2, 0) + self.c3 = self.c1 + Vec(self.parent.room_size - 1, 0, - self.parent.room_size-1) + self.parent.room_size - 1) # North, East, South, West - self.hallLength = [1,1,1,1] + self.hallLength = [1, 1, 1, 1] self.hallSize = [ - [5,self.parent.room_size-5], - [5,self.parent.room_size-5], - [5,self.parent.room_size-5], - [5,self.parent.room_size-5]] + [5, self.parent.room_size - 5], + [5, self.parent.room_size - 5], + [5, self.parent.room_size - 5], + [5, self.parent.room_size - 5]] self.canvas = ( - Vec(5,self.parent.room_height-2,2), - Vec(self.parent.room_size-6,self.parent.room_height-2,2), - Vec(self.parent.room_size-3,self.parent.room_height-2,5), - Vec(self.parent.room_size-3, - self.parent.room_height-2, - self.parent.room_size-6), - Vec(self.parent.room_size-6, - self.parent.room_height-2, - self.parent.room_size-3), - Vec(5,self.parent.room_height-2,self.parent.room_size-3), - Vec(2,self.parent.room_height-2,self.parent.room_size-6), - Vec(2,self.parent.room_height-2,5)) + Vec(5, self.parent.room_height - 2, 2), + Vec(self.parent.room_size - 6, self.parent.room_height - 2, 2), + Vec(self.parent.room_size - 3, self.parent.room_height - 2, 5), + Vec(self.parent.room_size - 3, + self.parent.room_height - 2, + self.parent.room_size - 6), + Vec(self.parent.room_size - 6, + self.parent.room_height - 2, + self.parent.room_size - 3), + Vec(5, self.parent.room_height - 2, self.parent.room_size - 3), + Vec(2, self.parent.room_height - 2, self.parent.room_size - 6), + Vec(2, self.parent.room_height - 2, 5)) self.floor = 'floor' @@ -2957,17 +3068,18 @@ class Corridor(Blank): def setData(self): # North, East, South, West - self.hallLength = [3,3,3,3] + self.hallLength = [3, 3, 3, 3] self.hallSize = [ - [2,self.parent.room_size-2], - [2,self.parent.room_size-2], - [2,self.parent.room_size-2], - [2,self.parent.room_size-2]] + [2, self.parent.room_size - 2], + [2, self.parent.room_size - 2], + [2, self.parent.room_size - 2], + [2, self.parent.room_size - 2]] self.canvas = ( - Vec(0,self.parent.room_height-2,0), - Vec(0,self.parent.room_height-2,0), - Vec(0,self.parent.room_height-2,0)) - def render (self): + Vec(0, self.parent.room_height - 2, 0), + Vec(0, self.parent.room_height - 2, 0), + Vec(0, self.parent.room_height - 2, 0)) + + def render(self): # default to a teeny tiny room x1 = 1000 x2 = -1 @@ -2983,14 +3095,14 @@ def render (self): x1 = min(x1, self.halls[2].offset) numhalls += 1 if (x1 is 1000): - x1 = self.parent.room_size/2-2 + x1 = self.parent.room_size / 2 - 2 # x2 bounds (East side) if (self.halls[0].size): - x2 = self.halls[0].offset+self.halls[0].size-1 + x2 = self.halls[0].offset + self.halls[0].size - 1 if (self.halls[2].size): - x2 = max(x2, self.halls[2].offset+self.halls[2].size-1) + x2 = max(x2, self.halls[2].offset + self.halls[2].size - 1) if (x2 is -1): - x2 = self.parent.room_size/2+2 + x2 = self.parent.room_size / 2 + 2 # z1 bounds (North side) if (self.halls[1].size): z1 = self.halls[1].offset @@ -2999,137 +3111,138 @@ def render (self): z1 = min(z1, self.halls[3].offset) numhalls += 1 if (z1 is 1000): - z1 = self.parent.room_size/2-2 + z1 = self.parent.room_size / 2 - 2 # z2 bounds (South side) if (self.halls[1].size): - z2 = self.halls[1].offset+self.halls[1].size-1 + z2 = self.halls[1].offset + self.halls[1].size - 1 if (self.halls[3].size): - z2 = max(z2, self.halls[3].offset+self.halls[3].size-1) + z2 = max(z2, self.halls[3].offset + self.halls[3].size - 1) if (z2 is -1): - z2 = self.parent.room_size/2+2 + z2 = self.parent.room_size / 2 + 2 # Orient the sides if (x1 > x2): t = x1 - x1= x2 + x1 = x2 x2 = t if (z1 > z2): t = z1 - z1= z2 + z1 = z2 z2 = t # If there is only one hall, override if (numhalls == 1): x1 = min(x1, 5) - x2 = max(x2, self.parent.room_size-6) + x2 = max(x2, self.parent.room_size - 6) z1 = min(z1, 5) - z2 = max(z2, self.parent.room_size-6) + z2 = max(z2, self.parent.room_size - 6) # Extend the halls - self.hallLength[0] = z1+1 + self.hallLength[0] = z1 + 1 self.hallLength[1] = self.parent.room_size - x2 self.hallLength[2] = self.parent.room_size - z2 - self.hallLength[3] = x1+1 + self.hallLength[3] = x1 + 1 # Canvas - if (x2-x1 > 2 and z2-z1 > 2): + if (x2 - x1 > 2 and z2 - z1 > 2): self.canvas = ( - Vec(x1+1,self.parent.room_height-2,z1+1), - Vec(x2-1,self.parent.room_height-2,z1+1), - Vec(x2-1,self.parent.room_height-2,z2-1), - Vec(x1+1,self.parent.room_height-2,z2-1)) + Vec(x1 + 1, self.parent.room_height - 2, z1 + 1), + Vec(x2 - 1, self.parent.room_height - 2, z1 + 1), + Vec(x2 - 1, self.parent.room_height - 2, z2 - 1), + Vec(x1 + 1, self.parent.room_height - 2, z2 - 1)) # Figure out our corners - c1 = self.loc+Vec(x1,self.parent.room_height-2,z1) - c2 = self.loc+Vec(x2,self.parent.room_height-2,z1) - c3 = self.loc+Vec(x2,self.parent.room_height-2,z2) - c4 = self.loc+Vec(x1,self.parent.room_height-2,z2) + c1 = self.loc + Vec(x1, self.parent.room_height - 2, z1) + c2 = self.loc + Vec(x2, self.parent.room_height - 2, z1) + c3 = self.loc + Vec(x2, self.parent.room_height - 2, z2) + c4 = self.loc + Vec(x1, self.parent.room_height - 2, z2) # Air space - for x in iterate_cube(c1.up(1),c3.up(3)): + for x in iterate_cube(c1.up(1), c3.up(3)): self.parent.setblock(x, materials.Air) # Floor for x in iterate_cube(c1, c3): self.parent.setblock(x, materials._floor) # Ceiling - for x in iterate_cube(c1.up(4),c3.up(4)): + for x in iterate_cube(c1.up(4), c3.up(4)): self.parent.setblock(x, materials._ceiling) # Walls - for x in iterate_four_walls(c1, c3, self.parent.room_height-2): + for x in iterate_four_walls(c1, c3, self.parent.room_height - 2): self.parent.setblock(x, materials._wall) # Subfloor - for x in iterate_plane(self.loc.down(self.parent.room_height-1), - self.loc.trans(self.parent.room_size-1, - self.parent.room_height-1, - self.parent.room_size-1)): + for x in iterate_plane(self.loc.down(self.parent.room_height - 1), + self.loc.trans(self.parent.room_size - 1, + self.parent.room_height - 1, + self.parent.room_size - 1)): self.parent.setblock(x, materials._subfloor) # Cave-in if (numhalls == 1): ores = ( # Resource distribution - (materials.meta_mossycobble,150), - (materials._wall,150), - (materials.CoalOre,90), - (materials.IronOre,40), - (materials.GoldOre,10), - (materials.DiamondOre,5), - (materials.RedstoneOre,20), - (materials.LapisLazuliOre,5), - (materials.EmeraldOre,5) + (materials.meta_mossycobble, 150), + (materials._wall, 150), + (materials.CoalOre, 90), + (materials.IronOre, 40), + (materials.GoldOre, 10), + (materials.DiamondOre, 5), + (materials.RedstoneOre, 20), + (materials.LapisLazuliOre, 5), + (materials.EmeraldOre, 5) ) - start = c4.trans(1,1,-2) - width = x2-x1-1 - length = self.parent.room_height-3 - stepw = Vec(1,0,0) - stepl = Vec(0,0,-1) + start = c4.trans(1, 1, -2) + width = x2 - x1 - 1 + length = self.parent.room_height - 3 + stepw = Vec(1, 0, 0) + stepl = Vec(0, 0, -1) if (self.halls[0].size): - start = c1.trans(1,1,2) - width = x2-x1-1 - stepw = Vec(1,0,0) - stepl = Vec(0,0,1) + start = c1.trans(1, 1, 2) + width = x2 - x1 - 1 + stepw = Vec(1, 0, 0) + stepl = Vec(0, 0, 1) elif (self.halls[1].size): - start = c2.trans(-2,1,1) - width = z2-z1-1 - stepw = Vec(0,0,1) - stepl = Vec(-1,0,0) + start = c2.trans(-2, 1, 1) + width = z2 - z1 - 1 + stepw = Vec(0, 0, 1) + stepl = Vec(-1, 0, 0) elif (self.halls[3].size): - start = c1.trans(2,1,1) - width = z2-z1-1 - stepw = Vec(0,0,1) - stepl = Vec(1,0,0) + start = c1.trans(2, 1, 1) + width = z2 - z1 - 1 + stepw = Vec(0, 0, 1) + stepl = Vec(1, 0, 0) h = 1 for l in xrange(length): for w in xrange(width): - p = start + (stepw*w) + (stepl*l) - for x in iterate_cube(p, p.up(h+random.randint(0,1))): + p = start + (stepw * w) + (stepl * l) + for x in iterate_cube(p, p.up(h + random.randint(0, 1))): mat = weighted_choice(ores) self.parent.setblock(x, mat) h += 1 + def drawExitPortal(pos, dungeon, NS=False): '''Draw an exit portal given the upper left corner and dungeon reference''' # Skip if this is turned off. if cfg.exit_portal is False: return # If portal exit isn't set, abort. - if dungeon.dinfo['portal_exit'] == Vec(0,0,0): + if dungeon.dinfo['portal_exit'] == Vec(0, 0, 0): print 'WARNING: Skipping exit portal. portal_exit is', dungeon.dinfo['portal_exit'] return # are we drawing WE or NS? if NS: - x=Vec(0,0,1) - y=Vec(0,1,0) - z=Vec(1,0,0) + x = Vec(0, 0, 1) + y = Vec(0, 1, 0) + z = Vec(1, 0, 0) sign_dat = 5 else: - x=Vec(1,0,0) - y=Vec(0,1,0) - z=Vec(0,0,1) + x = Vec(1, 0, 0) + y = Vec(0, 1, 0) + z = Vec(0, 0, 1) sign_dat = 3 # Portal sb = dungeon.setblock # Bedrock portal frame. - for p in iterate_cube(pos, pos+x*3+y*4): + for p in iterate_cube(pos, pos + x * 3 + y * 4): sb(p, materials.Bedrock) # Air. - for p in iterate_cube(pos+x+y, pos+x*2+y*3): + for p in iterate_cube(pos + x + y, pos + x * 2 + y * 3): sb(p, materials.Air) # Buttons - for p in iterate_cube(pos+x+y*3, pos+x*2+y*3): + for p in iterate_cube(pos + x + y * 3, pos + x * 2 + y * 3): sb(p, materials.StonePressurePlate) # Command blocks world_exit = Vec( @@ -3137,7 +3250,7 @@ def drawExitPortal(pos, dungeon, NS=False): dungeon.position.y - dungeon.dinfo['portal_exit'].y, dungeon.dinfo['portal_exit'].z + dungeon.position.z ) - for p in [pos+y*4, pos+x*3+y*4]: + for p in [pos + y * 4, pos + x * 3 + y * 4]: sb(p, materials.CommandBlock) root_tag = nbt.TAG_Compound() root_tag['id'] = nbt.TAG_String('Control') @@ -3145,21 +3258,21 @@ def drawExitPortal(pos, dungeon, NS=False): root_tag['y'] = nbt.TAG_Int(p.y) root_tag['z'] = nbt.TAG_Int(p.z) root_tag['SuccessCount'] = nbt.TAG_Int(0) - root_tag['Command'] = nbt.TAG_String('/tp @p[rm=1,r=2,c=1] %d %d %d'%(world_exit.x, - world_exit.y, - world_exit.z)) + root_tag['Command'] = nbt.TAG_String( + '/tp @p[rm=1,r=2,c=1] %d %d %d' % + (world_exit.x, world_exit.y, world_exit.z)) dungeon.tile_ents[p] = root_tag # Sign. - sb(pos+x*3+y*2+z, materials.WallSign, sign_dat) - dungeon.addsign(pos+x*3+y*2+z, - 'Portal', - 'to the', - 'Surface', - '') - -# Catalog the rooms we know about. + sb(pos + x * 3 + y * 2 + z, materials.WallSign, sign_dat) + dungeon.addsign(pos + x * 3 + y * 2 + z, + 'Portal', + 'to the', + 'Surface', + '') + +# Catalog the rooms we know about. _rooms = {} # List of classes in this module. for name, obj in inspect.getmembers(sys.modules[__name__], inspect.isclass): @@ -3167,26 +3280,28 @@ def drawExitPortal(pos, dungeon, NS=False): if issubclass(obj, Blank): _rooms[obj._name] = obj -def new (name, parent, pos): + +def new(name, parent, pos): '''Return a new instance of the room of a given name. Supply the parent dungeon object and maze position.''' if name in _rooms.keys(): return _rooms[name](parent, pos) return Blank(parent, pos) -def pickRoom (dungeon, dsize, pos, - maxsize=Vec(10,18,10), - entrance=False, - treasure=False, - stairwell=False, - room_list = None, - default = 'basic'): + +def pickRoom(dungeon, dsize, pos, + maxsize=Vec(10, 18, 10), + entrance=False, + treasure=False, + stairwell=False, + room_list=None, + default='basic'): '''Returns a pointer to a room instance given the current room set. Rooms will be chosen from a weighted list based on cfg.master_rooms, with a fall back to Basic. Restrictions on size, entrance, treasure, and stairwell can be specified.''' rooms = dungeon.rooms - if (room_list == None): + if (room_list is None): room_list = weighted_shuffle(cfg.master_rooms) else: room_list = weighted_shuffle(room_list) @@ -3200,19 +3315,19 @@ def pickRoom (dungeon, dsize, pos, if newroom not in _rooms: continue # Find the room size. - size = _rooms[newroom]._min_size - Vec(1,1,1) + size = _rooms[newroom]._min_size - Vec(1, 1, 1) # Check if we need an entrance capable room. - if (entrance == True): + if (entrance): entrance_test = _rooms[newroom]._is_entrance else: entrance_test = True # Check if we need a treasure capable room. - if (treasure == True): + if (treasure): treasure_test = _rooms[newroom]._is_treasureroom else: treasure_test = True # Check if we need a stairwell capable room. - if (stairwell == True): + if (stairwell): stairwell_test = _rooms[newroom]._is_stairwell else: stairwell_test = True @@ -3223,32 +3338,32 @@ def pickRoom (dungeon, dsize, pos, # Generate a list of horizontal offsets to test, and test them in a # random order. of = [] - for x in xrange(size.x+1): - for z in xrange(size.z+1): - of.append(Vec(-x,0,-z)) + for x in xrange(size.x + 1): + for z in xrange(size.z + 1): + of.append(Vec(-x, 0, -z)) random.shuffle(of) for o in of: ppos = pos + o # print ' ppos:',ppos if (entrance_test and - stairwell_test and - treasure_test and - ppos.x >= 0 and - ppos.y >= 0 and - ppos.z >= 0 and - ppos.x + size.x < dsize.x and - ppos.y + size.y < dsize.y and - ppos.z + size.z < dsize.z and - size.x < maxsize.x and - size.y < maxsize.y and - size.z < maxsize.z and - any(p in rooms for p in iterate_cube(ppos, ppos+size)) is False): + stairwell_test and + treasure_test and + ppos.x >= 0 and + ppos.y >= 0 and + ppos.z >= 0 and + ppos.x + size.x < dsize.x and + ppos.y + size.y < dsize.y and + ppos.z + size.z < dsize.z and + size.x < maxsize.x and + size.y < maxsize.y and + size.z < maxsize.z and + any(p in rooms for p in iterate_cube(ppos, ppos + size)) is False): name = newroom fpos = ppos break - # If we didn't find a room, fall back to basic. + # If we didn't find a room, fall back to basic. if name == '': name = default # print 'picked:', name, '@', fpos - # Return the room instance and the new offset location. + # Return the room instance and the new offset location. return new(name, dungeon, fpos), fpos diff --git a/ruins.py b/ruins.py index 29c37243..24863189 100644 --- a/ruins.py +++ b/ruins.py @@ -88,7 +88,7 @@ def __init__(self, parent): cx = (parent.parent.position.x + parent.loc.x) >> 4 cz = (parent.parent.position.z + parent.loc.z) >> 4 self.chunk = Vec(cx, 0, cz) - #print 'ruin chunk:', self.chunk + # print 'ruin chunk:', self.chunk def placed(self, world): self.depth = self.parent.parent.good_chunks[( @@ -96,7 +96,7 @@ def placed(self, world): self.chunk.z )] self.vtrans = max( - self.parent.parent.position.y-1, + self.parent.parent.position.y - 1, self.depth ) - self.parent.parent.position.y self.loc = Vec(self.pos.x * self.parent.parent.room_size, @@ -132,7 +132,7 @@ class EvilRunestones(Blank): def render(self): # For most of this one, we render directly to the chunk structure. # This works out better in the end. - height = int(self.parent.parent.room_height*cfg.tower) + height = int(self.parent.parent.room_height * cfg.tower) # This chunk cx = (self.parent.parent.position.x + self.parent.loc.x) >> 4 cz = (self.parent.parent.position.z + self.parent.loc.z) >> 4 @@ -151,7 +151,7 @@ def sb(p, mat, chunk=chunk): runes = {} for x in xrange(16): for z in xrange(16): - runes[x, z] = random.randint(height/2, height) + runes[x, z] = random.randint(height / 2, height) # Iterate over the chunk for x in xrange(16): for z in xrange(16): @@ -165,9 +165,9 @@ def sb(p, mat, chunk=chunk): q = Vec(x, y, z) # create a chest if (x == 2 and z == 2): - cp = Vec(cx*16+x-self.parent.parent.position.x, + cp = Vec(cx * 16 + x - self.parent.parent.position.x, self.parent.parent.position.y - y - 1, - cz*16+z-self.parent.parent.position.z) + cz * 16 + z - self.parent.parent.position.z) self.parent.parent.setblock(cp, materials.Chest) self.parent.parent.addchest(cp, 0) # The portal exit point is here @@ -191,7 +191,7 @@ def sb(p, mat, chunk=chunk): sb(r, materials.Air) d = ((Vec2f(q.x, q.z) - Vec2f(7, 7)).mag()) / 16 n = (pn.noise3(q.x / 4.0, 0, q.z / 4.0) + 1.0) / 2.0 - if (n >= d+.20): + if (n >= d + .20): sb(q, materials.Netherrack) # Netherrack might be on fire! if random.randint(1, 100) <= 5: @@ -241,21 +241,21 @@ def setData(self): xsize = self.parent.parent.xsize zsize = self.parent.parent.zsize self.spos = copy(self.pos) - while self.spos.x > xsize-4: + while self.spos.x > xsize - 4: self.spos.x -= 1 - while self.spos.z > zsize-4: + while self.spos.z > zsize - 4: self.spos.z -= 1 # Now go through and override the ruins on any chunks we cover # to be blank. for p in iterate_cube(Vec(self.spos.x, 0, self.spos.z), - Vec(self.spos.x+3, 0, self.spos.z+3)): + Vec(self.spos.x + 3, 0, self.spos.z + 3)): if p == self.pos: continue blank = new('blank', self.parent.parent.rooms[p]) self.parent.parent.rooms[p].ruins = [blank] # Find the low point in this region for p in iterate_cube(Vec(self.spos.x, 0, self.spos.z), - Vec(self.spos.x+3, 0, self.spos.z+3)): + Vec(self.spos.x + 3, 0, self.spos.z + 3)): cx = (self.parent.parent.position.x >> 4) + p.x cz = (self.parent.parent.position.z >> 4) + p.z self.depth = min(self.depth, @@ -271,21 +271,29 @@ def setData(self): cz = self.parent.parent.position.z >> 4 world = self.parent.parent.world # N side - (low1, high1) = findChunkDepths(Vec(cx, 0, cz+1), world) - (low2, high2) = findChunkDepths(Vec(cx, 0, cz+2), world) - self.ent_n = min(22, max(1, high1-self.depth, high2-self.depth) + 1) + (low1, high1) = findChunkDepths(Vec(cx, 0, cz + 1), world) + (low2, high2) = findChunkDepths(Vec(cx, 0, cz + 2), world) + self.ent_n = min( + 22, max( + 1, high1 - self.depth, high2 - self.depth) + 1) # S side - (low1, high1) = findChunkDepths(Vec(cx+3, 0, cz+1), world) - (low2, high2) = findChunkDepths(Vec(cx+3, 0, cz+2), world) - self.ent_s = min(22, max(1, high1-self.depth, high2-self.depth) + 1) + (low1, high1) = findChunkDepths(Vec(cx + 3, 0, cz + 1), world) + (low2, high2) = findChunkDepths(Vec(cx + 3, 0, cz + 2), world) + self.ent_s = min( + 22, max( + 1, high1 - self.depth, high2 - self.depth) + 1) # E side - (low1, high1) = findChunkDepths(Vec(cx+1, 0, cz+3), world) - (low2, high2) = findChunkDepths(Vec(cx+2, 0, cz+3), world) - self.ent_e = min(22, max(1, high1-self.depth, high2-self.depth) + 1) + (low1, high1) = findChunkDepths(Vec(cx + 1, 0, cz + 3), world) + (low2, high2) = findChunkDepths(Vec(cx + 2, 0, cz + 3), world) + self.ent_e = min( + 22, max( + 1, high1 - self.depth, high2 - self.depth) + 1) # W side - (low1, high1) = findChunkDepths(Vec(cx+1, 0, cz), world) - (low2, high2) = findChunkDepths(Vec(cx+2, 0, cz), world) - self.ent_w = min(22, max(1, high1-self.depth, high2-self.depth) + 1) + (low1, high1) = findChunkDepths(Vec(cx + 1, 0, cz), world) + (low2, high2) = findChunkDepths(Vec(cx + 2, 0, cz), world) + self.ent_w = min( + 22, max( + 1, high1 - self.depth, high2 - self.depth) + 1) def render(self): # Biome materials @@ -326,17 +334,17 @@ def render(self): mat_floor = materials.Stone c1 = self.loc - c3 = c1 + Vec(self.parent.parent.room_size*4-1, + c3 = c1 + Vec(self.parent.parent.room_size * 4 - 1, 0, - self.parent.parent.room_size*4-1) + self.parent.parent.room_size * 4 - 1) # corner of the inner shaft - start = Vec(self.parent.loc.x+5, + start = Vec(self.parent.loc.x + 5, c1.y, - self.parent.loc.z+5) + self.parent.loc.z + 5) # Walls and airspace of the pyramid for y in xrange(29): - for p in iterate_cube(c1.trans(y+1, -y, y+1), - c3.trans(-y-1, -y, -y-1)): + for p in iterate_cube(c1.trans(y + 1, -y, y + 1), + c3.trans(-y - 1, -y, -y - 1)): self.parent.parent.setblock(p, materials.Air) for p in iterate_four_walls(c1.trans(y, -y, y), c3.trans(-y, -y, -y), 0): @@ -354,11 +362,11 @@ def render(self): # Cover the floor with stuff pn = perlin.SimplexNoise(256) for p in iterate_cube(c1, c3): - d = ((Vec2f(p.x, p.z) - Vec2f(c1.x+32, c1.z+32)).mag()) / 64 + d = ((Vec2f(p.x, p.z) - Vec2f(c1.x + 32, c1.z + 32)).mag()) / 64 n = (pn.noise3(p.x / 4.0, p.y / 4.0, p.z / 4.0) + 1.0) / 2.0 - if (n >= d+.20): + if (n >= d + .20): self.parent.parent.setblock(p, mat_floor) - elif (n >= d+.10): + elif (n >= d + .10): self.parent.parent.setblock(p, mat_ruins) elif (n >= d): self.parent.parent.setblock(p, materials.Gravel) @@ -370,7 +378,7 @@ def render(self): wfunc = iterate_four_walls if random.randint(1, 100) <= 50: wfunc = iterate_tube - pp1 = c1.trans(p.x*16+1, 0, p.z*16+1) + pp1 = c1.trans(p.x * 16 + 1, 0, p.z * 16 + 1) pp2 = pp1.trans(13, 0, 13) # place a chest here if random.randint(1, 100) <= cchance: @@ -396,30 +404,29 @@ def render(self): # Clean up the stairwell shaft. Clear the air, make a half step around # it, extend the walls, and redraw the stairs. - self.parent.parent.entrance.height = abs(-c1.y-2)+2 - for p in iterate_cube(start, start.trans(5, -c1.y-1, 5)): + self.parent.parent.entrance.height = abs(-c1.y - 2) + 2 + for p in iterate_cube(start, start.trans(5, -c1.y - 1, 5)): self.parent.parent.setblock(p, materials.Air) for p in iterate_four_walls(Vec(start.x, -1, start.z), - Vec(start.x+5, -1, start.z+5), -c1.y-2): + Vec(start.x + 5, -1, start.z + 5), -c1.y - 2): self.parent.parent.setblock(p, materials._wall) for p in iterate_four_walls(start, start.trans(5, 0, 5), 0): self.parent.parent.setblock(p, materials.StoneSlab) mat = materials.OakWoodSlab if random.randint(1, 100) <= 50: mat = materials.StoneSlab - for p in iterate_spiral(Vec(start.x+1, 7, start.z+1), - Vec(start.x+5, 7, start.z+5), - (abs(c1.y)+3)*2): - self.parent.parent.setblock(Vec(p.x, - 0+int(p.y/2), - p.z), mat, mat.data+((p.y & 1) ^ 1)*8) + for p in iterate_spiral(Vec(start.x + 1, 7, start.z + 1), + Vec(start.x + 5, 7, start.z + 5), + (abs(c1.y) + 3) * 2): + self.parent.parent.setblock( + Vec(p.x, 0 + int(p.y / 2), p.z), mat, mat.data + ((p.y & 1) ^ 1) * 8) # Entrances. # Draw stairs up the sides. for y in xrange(29): # North Side # caps on either side - self.parent.parent.setblock(c1.trans(y, -y-1, 29), mat_slab) - self.parent.parent.setblock(c1.trans(y, -y-1, 34), mat_slab) + self.parent.parent.setblock(c1.trans(y, -y - 1, 29), mat_slab) + self.parent.parent.setblock(c1.trans(y, -y - 1, 34), mat_slab) # draw different stuff depending on the height # Go ahead and draw exterior stairs at every level. # (we'll overwrite some below) @@ -444,11 +451,11 @@ def render(self): mat_block, 0) # At entry level, draw a platform floor. if (self.ent_n == y): - for p in iterate_cube(c1.trans(y+1, -y, 30), - c1.trans(y+8, -y, 33)): + for p in iterate_cube(c1.trans(y + 1, -y, 30), + c1.trans(y + 8, -y, 33)): self.parent.parent.setblock(p, mat_block) # Above the entry platform, draw some walls - if (y > self.ent_n and y < self.ent_n+4): + if (y > self.ent_n and y < self.ent_n + 4): p = c1.trans(y, -y, 30) self.parent.parent.setblock(p, mat_block) self.parent.parent.setblock(p.trans(1, 0, 0), mat_block) @@ -459,32 +466,32 @@ def render(self): self.parent.parent.setblock(p.trans(0, 0, 3), mat_block) self.parent.parent.setblock(p.trans(1, 0, 3), mat_block) # Add a ceiling for the entryway. - if (y == self.ent_n+4): - p = c1.trans(y-3, -y, 30) + if (y == self.ent_n + 4): + p = c1.trans(y - 3, -y, 30) self.parent.parent.setblock(p.trans(1, 1, 0), mat_block) self.parent.parent.setblock(p.trans(0, 1, 0), mat_block) self.parent.parent.setblock(p.trans(0, 2, 0), mat_block) - p = c1.trans(y-3, -y, 33) + p = c1.trans(y - 3, -y, 33) self.parent.parent.setblock(p.trans(1, 1, 0), mat_block) self.parent.parent.setblock(p.trans(0, 1, 0), mat_block) self.parent.parent.setblock(p.trans(0, 2, 0), mat_block) - for p in iterate_cube(c1.trans(y-3, -y, 30), - c1.trans(y+1, -y, 33)): + for p in iterate_cube(c1.trans(y - 3, -y, 30), + c1.trans(y + 1, -y, 33)): self.parent.parent.setblock(p, mat_block) # South Side - self.parent.parent.setblock(c1.trans(63-y, -y-1, 29), mat_slab) - self.parent.parent.setblock(c1.trans(63-y, -y-1, 34), mat_slab) - for p in iterate_cube(c1.trans(63-y, -y, 30), - c1.trans(63-y, -y, 33)): + self.parent.parent.setblock(c1.trans(63 - y, -y - 1, 29), mat_slab) + self.parent.parent.setblock(c1.trans(63 - y, -y - 1, 34), mat_slab) + for p in iterate_cube(c1.trans(63 - y, -y, 30), + c1.trans(63 - y, -y, 33)): self.parent.parent.setblock(p, mat_stair, 1) self.parent.parent.delblock(p.up(1)) self.parent.parent.setblock(p.trans(-1, 0, 0), mat_block, 0) if (y > 0 and y <= self.ent_s): - for p in iterate_cube(c1.trans(63-y, -y, 28), - c1.trans(63-y, -y, 35)): + for p in iterate_cube(c1.trans(63 - y, -y, 28), + c1.trans(63 - y, -y, 35)): for x in xrange(2, 6): self.parent.parent.setblock(p.trans(-x, 0, 0), materials.Air, 0) @@ -493,11 +500,11 @@ def render(self): self.parent.parent.setblock(p.trans(-7, 0, 0), mat_block, 0) if (self.ent_s == y): - for p in iterate_cube(c1.trans(63-y-1, -y, 30), - c1.trans(63-y-8, -y, 33)): + for p in iterate_cube(c1.trans(63 - y - 1, -y, 30), + c1.trans(63 - y - 8, -y, 33)): self.parent.parent.setblock(p, mat_block) - if (y > self.ent_s and y < self.ent_s+4): - p = c1.trans(63-y, -y, 30) + if (y > self.ent_s and y < self.ent_s + 4): + p = c1.trans(63 - y, -y, 30) self.parent.parent.setblock(p, mat_block) self.parent.parent.setblock(p.trans(-1, 0, 0), mat_block) self.parent.parent.setblock(p.trans(0, 0, 1), materials.Air) @@ -506,22 +513,22 @@ def render(self): self.parent.parent.setblock(p.trans(-1, 0, 2), materials.Air) self.parent.parent.setblock(p.trans(0, 0, 3), mat_block) self.parent.parent.setblock(p.trans(-1, 0, 3), mat_block) - if (y == self.ent_s+4): - p = c1.trans(63-y+3, -y, 30) + if (y == self.ent_s + 4): + p = c1.trans(63 - y + 3, -y, 30) self.parent.parent.setblock(p.trans(-1, 1, 0), mat_block) self.parent.parent.setblock(p.trans(0, 1, 0), mat_block) self.parent.parent.setblock(p.trans(0, 2, 0), mat_block) - p = c1.trans(63-y+3, -y, 33) + p = c1.trans(63 - y + 3, -y, 33) self.parent.parent.setblock(p.trans(-1, 1, 0), mat_block) self.parent.parent.setblock(p.trans(0, 1, 0), mat_block) self.parent.parent.setblock(p.trans(0, 2, 0), mat_block) - for p in iterate_cube(c1.trans(63-y+3, -y, 30), - c1.trans(63-y-1, -y, 33)): + for p in iterate_cube(c1.trans(63 - y + 3, -y, 30), + c1.trans(63 - y - 1, -y, 33)): self.parent.parent.setblock(p, mat_block) # West Side - self.parent.parent.setblock(c1.trans(29, -y-1, y), mat_slab) - self.parent.parent.setblock(c1.trans(34, -y-1, y), mat_slab) + self.parent.parent.setblock(c1.trans(29, -y - 1, y), mat_slab) + self.parent.parent.setblock(c1.trans(34, -y - 1, y), mat_slab) for p in iterate_cube(c1.trans(30, -y, y), c1.trans(33, -y, y)): self.parent.parent.setblock(p, mat_stair, 2) @@ -539,10 +546,10 @@ def render(self): self.parent.parent.setblock(p.trans(0, 0, 7), mat_block, 0) if (self.ent_w == y): - for p in iterate_cube(c1.trans(30, -y, y+1), - c1.trans(33, -y, y+8)): + for p in iterate_cube(c1.trans(30, -y, y + 1), + c1.trans(33, -y, y + 8)): self.parent.parent.setblock(p, mat_block) - if (y > self.ent_w and y < self.ent_w+4): + if (y > self.ent_w and y < self.ent_w + 4): p = c1.trans(30, -y, y) self.parent.parent.setblock(p, mat_block) self.parent.parent.setblock(p.trans(0, 0, 1), mat_block) @@ -552,32 +559,32 @@ def render(self): self.parent.parent.setblock(p.trans(2, 0, 1), materials.Air) self.parent.parent.setblock(p.trans(3, 0, 0), mat_block) self.parent.parent.setblock(p.trans(3, 0, 1), mat_block) - if (y == self.ent_w+4): - p = c1.trans(30, -y, y-3) + if (y == self.ent_w + 4): + p = c1.trans(30, -y, y - 3) self.parent.parent.setblock(p.trans(0, 1, 1), mat_block) self.parent.parent.setblock(p.trans(0, 1, 0), mat_block) self.parent.parent.setblock(p.trans(0, 2, 0), mat_block) - p = c1.trans(33, -y, y-3) + p = c1.trans(33, -y, y - 3) self.parent.parent.setblock(p.trans(0, 1, 1), mat_block) self.parent.parent.setblock(p.trans(0, 1, 0), mat_block) self.parent.parent.setblock(p.trans(0, 2, 0), mat_block) - for p in iterate_cube(c1.trans(30, -y, y-3), - c1.trans(33, -y, y+1)): + for p in iterate_cube(c1.trans(30, -y, y - 3), + c1.trans(33, -y, y + 1)): self.parent.parent.setblock(p, mat_block) # East Side - self.parent.parent.setblock(c1.trans(29, -y-1, 63-y), mat_slab) - self.parent.parent.setblock(c1.trans(34, -y-1, 63-y), mat_slab) - for p in iterate_cube(c1.trans(30, -y, 63-y), - c1.trans(33, -y, 63-y)): + self.parent.parent.setblock(c1.trans(29, -y - 1, 63 - y), mat_slab) + self.parent.parent.setblock(c1.trans(34, -y - 1, 63 - y), mat_slab) + for p in iterate_cube(c1.trans(30, -y, 63 - y), + c1.trans(33, -y, 63 - y)): self.parent.parent.setblock(p, mat_stair, 3) self.parent.parent.delblock(p.up(1)) self.parent.parent.setblock(p.trans(0, 0, -1), mat_block, 0) if (y > 0 and y <= self.ent_e): - for p in iterate_cube(c1.trans(28, -y, 63-y), - c1.trans(35, -y, 63-y)): + for p in iterate_cube(c1.trans(28, -y, 63 - y), + c1.trans(35, -y, 63 - y)): for x in xrange(2, 6): self.parent.parent.setblock(p.trans(0, 0, -x), materials.Air, 0) @@ -586,11 +593,11 @@ def render(self): self.parent.parent.setblock(p.trans(0, 0, -7), mat_block, 0) if (self.ent_e == y): - for p in iterate_cube(c1.trans(30, -y, 63-y-1), - c1.trans(33, -y, 63-y-8)): + for p in iterate_cube(c1.trans(30, -y, 63 - y - 1), + c1.trans(33, -y, 63 - y - 8)): self.parent.parent.setblock(p, mat_block) - if (y > self.ent_e and y < self.ent_e+4): - p = c1.trans(30, -y, 63-y) + if (y > self.ent_e and y < self.ent_e + 4): + p = c1.trans(30, -y, 63 - y) self.parent.parent.setblock(p, mat_block) self.parent.parent.setblock(p.trans(0, 0, -1), mat_block) self.parent.parent.setblock(p.trans(1, 0, 0), materials.Air) @@ -599,17 +606,17 @@ def render(self): self.parent.parent.setblock(p.trans(2, 0, -1), materials.Air) self.parent.parent.setblock(p.trans(3, 0, 0), mat_block) self.parent.parent.setblock(p.trans(3, 0, -1), mat_block) - if (y == self.ent_e+4): - p = c1.trans(30, -y, 63-y+3) + if (y == self.ent_e + 4): + p = c1.trans(30, -y, 63 - y + 3) self.parent.parent.setblock(p.trans(0, 1, -1), mat_block) self.parent.parent.setblock(p.trans(0, 1, 0), mat_block) self.parent.parent.setblock(p.trans(0, 2, 0), mat_block) - p = c1.trans(33, -y, 63-y+3) + p = c1.trans(33, -y, 63 - y + 3) self.parent.parent.setblock(p.trans(0, 1, -1), mat_block) self.parent.parent.setblock(p.trans(0, 1, 0), mat_block) self.parent.parent.setblock(p.trans(0, 2, 0), mat_block) - for p in iterate_cube(c1.trans(30, -y, 63-y+3), - c1.trans(33, -y, 63-y-1)): + for p in iterate_cube(c1.trans(30, -y, 63 - y + 3), + c1.trans(33, -y, 63 - y - 1)): self.parent.parent.setblock(p, mat_block) # Topper @@ -622,8 +629,8 @@ def render(self): for p in iterate_cube(c1.trans(y, -y, y), c3.trans(-y, -y, -y)): self.parent.parent.setblock(p, materials.Air) - for p in iterate_four_walls(c1.trans(y-1, -y, y-1), - c3.trans(-y+1, -y, -y+1), 0): + for p in iterate_four_walls(c1.trans(y - 1, -y, y - 1), + c3.trans(-y + 1, -y, -y + 1), 0): self.parent.parent.setblock(p, materials.Glass) for p in iterate_cube(c1.trans(29, -28, 29), c3.trans(-29, -28, -29)): @@ -641,22 +648,22 @@ def render(self): # Spires if self.parent.parent.biome in _desert_biomes: for y in xrange(6): - self.parent.parent.setblock(c1.trans(20, -20-y, 20), + self.parent.parent.setblock(c1.trans(20, -20 - y, 20), materials.ChiseledSandstone) - self.parent.parent.setblock(c1.trans(43, -20-y, 20), + self.parent.parent.setblock(c1.trans(43, -20 - y, 20), materials.ChiseledSandstone) - self.parent.parent.setblock(c3.trans(-20, -20-y, -20), + self.parent.parent.setblock(c3.trans(-20, -20 - y, -20), materials.ChiseledSandstone) - self.parent.parent.setblock(c3.trans(-43, -20-y, -20), + self.parent.parent.setblock(c3.trans(-43, -20 - y, -20), materials.ChiseledSandstone) for y in xrange(2): - self.parent.parent.setblock(c1.trans(20, -26-y, 20), + self.parent.parent.setblock(c1.trans(20, -26 - y, 20), materials.Fence) - self.parent.parent.setblock(c1.trans(43, -26-y, 20), + self.parent.parent.setblock(c1.trans(43, -26 - y, 20), materials.Fence) - self.parent.parent.setblock(c3.trans(-20, -26-y, -20), + self.parent.parent.setblock(c3.trans(-20, -26 - y, -20), materials.Fence) - self.parent.parent.setblock(c3.trans(-43, -26-y, -20), + self.parent.parent.setblock(c3.trans(-43, -26 - y, -20), materials.Fence) # swamps and jungles are myan-like elif self.parent.parent.biome in _swamp_jungle_biomes: @@ -721,9 +728,9 @@ def render(self): self.parent.parent.setblock(p, materials.Chest) self.parent.parent.addchest(p, 0) # Portal exit point - self.parent.parent.dinfo['portal_exit'] = p+Vec(p.w(1).x, - c1.y + 29, - p.s(1).z) + self.parent.parent.dinfo['portal_exit'] = p + Vec(p.w(1).x, + c1.y + 29, + p.s(1).z) class RoundTowerEntrance(Blank): @@ -775,7 +782,7 @@ def render(self): self._stair = materials.StoneStairs # The room floor Y location - room_floor = self.parent.loc.y+self.parent.parent.room_height-3 + room_floor = self.parent.loc.y + self.parent.parent.room_height - 3 # The height of one room rheight = self.parent.parent.room_height # Entrance Level @@ -789,32 +796,32 @@ def render(self): maxlev = (self.parent.parent.world.Height - self.parent.parent.position.y) if -blev >= maxlev: - blev = -maxlev+2 + blev = -maxlev + 2 # corner of the inner shaft - start = Vec(self.parent.loc.x+6, + start = Vec(self.parent.loc.x + 6, glev, - self.parent.loc.z+6) + self.parent.loc.z + 6) # Corner of the inner wall wstart = start.trans(-1, 0, -1) # B Level is the upper battlements level - b1 = Vec(wstart.x-1, blev, wstart.z-1) + b1 = Vec(wstart.x - 1, blev, wstart.z - 1) b2 = b1.trans(7, 0, 0) b3 = b1.trans(7, 0, 7) b4 = b1.trans(0, 0, 7) # C level is the chest level - c1 = Vec(wstart.x-4, clev, wstart.z-4) + c1 = Vec(wstart.x - 4, clev, wstart.z - 4) c2 = c1.trans(13, 0, 0) c3 = c1.trans(13, 0, 13) c4 = c1.trans(0, 0, 13) # lower tower from ground up to chest level. # The floor for p in iterate_cylinder(Vec(c1.x, glev, c1.z), - Vec(c3.x, elev+1, c3.z)): + Vec(c3.x, elev + 1, c3.z)): self.parent.parent.setblock(p, self._mat) # The ceiling - for p in iterate_cylinder(Vec(c1.x, clev+1, c1.z), - Vec(c3.x, clev+1, c3.z)): + for p in iterate_cylinder(Vec(c1.x, clev + 1, c1.z), + Vec(c3.x, clev + 1, c3.z)): self.parent.parent.setblock(p, self._mat) # Outer wall and airspace for p in iterate_cylinder(c1.down(2), @@ -822,12 +829,12 @@ def render(self): self.parent.parent.setblock(p, materials.Air) for p in iterate_tube(Vec(c1.x, elev, c1.z), Vec(c3.x, elev, c3.z), - abs(elev-clev)): + abs(elev - clev)): self.parent.parent.setblock(p, self._mat) # Battlements for p in iterate_cube(Vec(0, 0, 0), Vec(5, 0, 5)): - if (((p.x+p.z) & 1) == 1): - self.parent.parent.setblock(c1+p, materials.Air) + if (((p.x + p.z) & 1) == 1): + self.parent.parent.setblock(c1 + p, materials.Air) self.parent.parent.setblock(c2.trans(-p.x, p.y, p.z), materials.Air) self.parent.parent.setblock(c3.trans(-p.x, p.y, -p.z), @@ -838,8 +845,8 @@ def render(self): for p in iterate_cylinder(b1, Vec(b3.x, clev, b3.z)): self.parent.parent.setblock(p, self._mat) for p in iterate_cube(Vec(0, 0, 0), Vec(4, 0, 4)): - if (((p.x+p.z) & 1) == 1): - self.parent.parent.setblock(b1+p, materials.Air) + if (((p.x + p.z) & 1) == 1): + self.parent.parent.setblock(b1 + p, materials.Air) self.parent.parent.setblock(b2.trans(-p.x, p.y, p.z), materials.Air) self.parent.parent.setblock(b3.trans(-p.x, p.y, -p.z), @@ -848,56 +855,55 @@ def render(self): materials.Air) # Chest level openings # W/E - for p in iterate_cube(Vec(b1.x+3, clev, b1.z), - Vec(b1.x+4, clev-2, b1.z+7)): - self.parent.parent.setblock(p, materials.Air) + for p in iterate_cube(Vec(b1.x + 3, clev, b1.z), + Vec(b1.x + 4, clev - 2, b1.z + 7)): + self.parent.parent.setblock(p, materials.Air) # N/S - for p in iterate_cube(Vec(b1.x, clev, b1.z+3), - Vec(b1.x+7, clev-2, b1.z+4)): - self.parent.parent.setblock(p, materials.Air) + for p in iterate_cube(Vec(b1.x, clev, b1.z + 3), + Vec(b1.x + 7, clev - 2, b1.z + 4)): + self.parent.parent.setblock(p, materials.Air) # Ground level openings # W side for p in iterate_cube(wstart.trans(2, 0, 0), wstart.trans(3, -2, -4)): - self.parent.parent.setblock(p, materials.Air) + self.parent.parent.setblock(p, materials.Air) # E side for p in iterate_cube(wstart.trans(2, 0, 5), wstart.trans(3, -2, 9)): - self.parent.parent.setblock(p, materials.Air) + self.parent.parent.setblock(p, materials.Air) # N side for p in iterate_cube(wstart.trans(0, 0, 2), wstart.trans(-4, -2, 3)): - self.parent.parent.setblock(p, materials.Air) + self.parent.parent.setblock(p, materials.Air) # S side for p in iterate_cube(wstart.trans(5, 0, 2), wstart.trans(9, -2, 3)): - self.parent.parent.setblock(p, materials.Air) + self.parent.parent.setblock(p, materials.Air) # Clear air space inside the stairwell shaft - for p in iterate_cube(Vec(wstart.x+1, elev+1, wstart.z+1), - Vec(wstart.x+4, blev-2, wstart.z+4)): + for p in iterate_cube(Vec(wstart.x + 1, elev + 1, wstart.z + 1), + Vec(wstart.x + 4, blev - 2, wstart.z + 4)): self.parent.parent.setblock(p, materials.Air) # Internal columns - for p in iterate_cube(Vec(b1.x+1, elev, b1.z+1), - Vec(b1.x+1, clev, b1.z+1)): + for p in iterate_cube(Vec(b1.x + 1, elev, b1.z + 1), + Vec(b1.x + 1, clev, b1.z + 1)): self.parent.parent.setblock(p, materials.StoneDoubleSlab) - for p in iterate_cube(Vec(b2.x-1, elev, b2.z+1), - Vec(b2.x-1, clev, b2.z+1)): + for p in iterate_cube(Vec(b2.x - 1, elev, b2.z + 1), + Vec(b2.x - 1, clev, b2.z + 1)): self.parent.parent.setblock(p, materials.StoneDoubleSlab) - for p in iterate_cube(Vec(b3.x-1, elev, b3.z-1), - Vec(b3.x-1, clev, b3.z-1)): + for p in iterate_cube(Vec(b3.x - 1, elev, b3.z - 1), + Vec(b3.x - 1, clev, b3.z - 1)): self.parent.parent.setblock(p, materials.StoneDoubleSlab) - for p in iterate_cube(Vec(b4.x+1, elev, b4.z-1), - Vec(b4.x+1, clev, b4.z-1)): + for p in iterate_cube(Vec(b4.x + 1, elev, b4.z - 1), + Vec(b4.x + 1, clev, b4.z - 1)): self.parent.parent.setblock(p, materials.StoneDoubleSlab) # (re)draw the staircase - self.parent.parent.entrance.height = abs(room_floor-elev-1) + self.parent.parent.entrance.height = abs(room_floor - elev - 1) mat = materials.OakWoodSlab if random.randint(1, 100) <= 50: mat = materials.StoneSlab - for p in iterate_spiral(Vec(start.x, room_floor+4, start.z), - Vec(start.x+4, room_floor+4, start.z+4), - (room_floor-blev)*2): - self.parent.parent.setblock(Vec(p.x, - p.y/2, - p.z), mat, mat.data+((p.y & 1) ^ 1)*8) + for p in iterate_spiral(Vec(start.x, room_floor + 4, start.z), + Vec(start.x + 4, room_floor + 4, start.z + 4), + (room_floor - blev) * 2): + self.parent.parent.setblock( + Vec(p.x, p.y / 2, p.z), mat, mat.data + ((p.y & 1) ^ 1) * 8) # Supply chest - pos = Vec(b1.x, clev, b1.z-1) + pos = Vec(b1.x, clev, b1.z - 1) self.parent.parent.setblock(pos, materials.Chest) self.parent.parent.addchest(pos, 0) # Portal exit point @@ -906,10 +912,10 @@ def render(self): pos.s(1).z) # Add a few details with upside-down stairs - N = 2+4 # Data values for a north side stair - S = 3+4 # South - E = 1+4 # East - W = 0+4 # West + N = 2 + 4 # Data values for a north side stair + S = 3 + 4 # South + E = 1 + 4 # East + W = 0 + 4 # West sb = self.parent.parent.setblock # Ground level archways sb(c1.trans(6, 3, 0), self._stair, E) @@ -923,16 +929,16 @@ def render(self): # Ruin if self._ruin is True: - ruinBlocks(b1.trans(0, rheight-1, 0), - b3.trans(0, rheight-1, 0), + ruinBlocks(b1.trans(0, rheight - 1, 0), + b3.trans(0, rheight - 1, 0), rheight, self.parent.parent) # Sandbar island if (self.parent.parent.entrance.inwater is False): return d = 2 - s1 = Vec(wstart.x-3, glev+1, wstart.z-3) - s3 = Vec(wstart.x+8, glev+1, wstart.z+8) + s1 = Vec(wstart.x - 3, glev + 1, wstart.z - 3) + s3 = Vec(wstart.x + 8, glev + 1, wstart.z + 8) for y in xrange(rheight): for p in iterate_disc(s1.trans(-d, y, -d), s3.trans(d, y, d)): @@ -995,7 +1001,7 @@ def render(self): self._stair = materials.StoneStairs # The room floor Y location - room_floor = self.parent.loc.y+self.parent.parent.room_height-3 + room_floor = self.parent.loc.y + self.parent.parent.room_height - 3 # The height of one room rheight = self.parent.parent.room_height # Entrance Level @@ -1009,21 +1015,21 @@ def render(self): maxlev = (self.parent.parent.world.Height - self.parent.parent.position.y) if -blev >= maxlev: - blev = -maxlev+2 + blev = -maxlev + 2 # corner of the inner shaft - start = Vec(self.parent.loc.x+6, + start = Vec(self.parent.loc.x + 6, glev, - self.parent.loc.z+6) + self.parent.loc.z + 6) # Corner of the inner wall wstart = start.trans(-1, 0, -1) # B Level is the upper battlements level - b1 = Vec(wstart.x-1, blev, wstart.z-1) + b1 = Vec(wstart.x - 1, blev, wstart.z - 1) b2 = b1.trans(7, 0, 0) b3 = b1.trans(7, 0, 7) b4 = b1.trans(0, 0, 7) # C level is the chest level - c1 = Vec(wstart.x-2, clev, wstart.z-2) + c1 = Vec(wstart.x - 2, clev, wstart.z - 2) c2 = c1.trans(9, 0, 0) c3 = c1.trans(9, 0, 9) c4 = c1.trans(0, 0, 9) @@ -1033,12 +1039,12 @@ def render(self): self.parent.parent.setblock(p, self._mat) # The "floor" This extends to the ground to make the base thicker. for p in iterate_cube(c1.trans(1, 1, 1), - Vec(c3.x-1, elev, c3.z-1)): + Vec(c3.x - 1, elev, c3.z - 1)): self.parent.parent.setblock(p, self._mat) # Place the battlement blocks on the wall for p in iterate_cube(Vec(0, -1, 0), Vec(4, -1, 4)): - if (((p.x+p.z) & 1) == 0): - self.parent.parent.setblock(c1+p, self._mat) + if (((p.x + p.z) & 1) == 0): + self.parent.parent.setblock(c1 + p, self._mat) self.parent.parent.setblock(c2.trans(-p.x, p.y, p.z), self._mat) self.parent.parent.setblock(c3.trans(-p.x, p.y, -p.z), @@ -1055,8 +1061,8 @@ def render(self): self.parent.parent.setblock(p, self._mat) # Place the battlement blocks on the wall for p in iterate_cube(Vec(0, -1, 0), Vec(2, -1, 2)): - if (((p.x+p.z) & 1) == 0): - self.parent.parent.setblock(b1+p, self._mat) + if (((p.x + p.z) & 1) == 0): + self.parent.parent.setblock(b1 + p, self._mat) self.parent.parent.setblock(b2.trans(-p.x, p.y, p.z), self._mat) self.parent.parent.setblock(b3.trans(-p.x, p.y, -p.z), @@ -1065,12 +1071,12 @@ def render(self): self._mat) # Clear air space inside the tower for p in iterate_cube(Vec(wstart.x, elev, wstart.z), - Vec(wstart.x+5, blev-2, wstart.z+5)): + Vec(wstart.x + 5, blev - 2, wstart.z + 5)): self.parent.parent.setblock(p, materials.Air) # Walls for p in iterate_four_walls(Vec(wstart.x, elev, wstart.z), - Vec(wstart.x+5, elev, wstart.z+5), - elev-blev-1): + Vec(wstart.x + 5, elev, wstart.z + 5), + elev - blev - 1): self.parent.parent.setblock(p, self._mat) # Chest level openings # W side @@ -1089,27 +1095,26 @@ def render(self): # W side for p in iterate_cube(wstart.trans(2, 0, 0), wstart.trans(3, -3, -1)): - self.parent.parent.setblock(p, materials.Air) + self.parent.parent.setblock(p, materials.Air) # E side for p in iterate_cube(wstart.trans(2, 0, 5), wstart.trans(3, -3, 6)): - self.parent.parent.setblock(p, materials.Air) + self.parent.parent.setblock(p, materials.Air) # N side for p in iterate_cube(wstart.trans(0, 0, 2), wstart.trans(-1, -3, 3)): - self.parent.parent.setblock(p, materials.Air) + self.parent.parent.setblock(p, materials.Air) # S side for p in iterate_cube(wstart.trans(5, 0, 2), wstart.trans(6, -3, 3)): - self.parent.parent.setblock(p, materials.Air) + self.parent.parent.setblock(p, materials.Air) # (re)draw the staircase - self.parent.parent.entrance.height = abs(room_floor-elev-1) + self.parent.parent.entrance.height = abs(room_floor - elev - 1) mat = materials.OakWoodSlab if random.randint(1, 100) <= 50: mat = materials.StoneSlab - for p in iterate_spiral(Vec(start.x, room_floor+4, start.z), - Vec(start.x+4, room_floor+4, start.z+4), - (room_floor-blev)*2): - self.parent.parent.setblock(Vec(p.x, - p.y/2, - p.z), mat, mat.data+((p.y & 1) ^ 1)*8) + for p in iterate_spiral(Vec(start.x, room_floor + 4, start.z), + Vec(start.x + 4, room_floor + 4, start.z + 4), + (room_floor - blev) * 2): + self.parent.parent.setblock( + Vec(p.x, p.y / 2, p.z), mat, mat.data + ((p.y & 1) ^ 1) * 8) # Supply chest pos = c1.trans(1, 0, 1) self.parent.parent.setblock(pos, materials.Chest) @@ -1120,10 +1125,10 @@ def render(self): pos.s(2).z) # Add a few details with upside-down stairs - N = 2+4 # Data values for a north side stair - S = 3+4 # South - E = 1+4 # East - W = 0+4 # West + N = 2 + 4 # Data values for a north side stair + S = 3 + 4 # South + E = 1 + 4 # East + W = 0 + 4 # West sb = self.parent.parent.setblock # Some supports under the lower battlements sb(c1.trans(3, 1, 0), self._support, N) @@ -1164,16 +1169,16 @@ def render(self): # Ruin if self._ruin is True: - ruinBlocks(b1.trans(0, rheight-1, 0), - b3.trans(0, rheight-1, 0), + ruinBlocks(b1.trans(0, rheight - 1, 0), + b3.trans(0, rheight - 1, 0), rheight, self.parent.parent) # Sandbar island if (self.parent.parent.entrance.inwater is False): return d = 2 - s1 = Vec(wstart.x-3, glev+1, wstart.z-3) - s3 = Vec(wstart.x+8, glev+1, wstart.z+8) + s1 = Vec(wstart.x - 3, glev + 1, wstart.z - 3) + s3 = Vec(wstart.x + 8, glev + 1, wstart.z + 8) for y in xrange(rheight): for p in iterate_disc(s1.trans(-d, y, -d), s3.trans(d, y, d)): @@ -1339,16 +1344,16 @@ def render(self): self.spos = copy(self.pos) movedX = 0 movedZ = 0 - if self.spos.x > xsize-2: + if self.spos.x > xsize - 2: self.spos.x -= 1 movedX += 1 - if self.spos.z > zsize-3: + if self.spos.z > zsize - 3: self.spos.z -= 2 movedZ += 2 # Now go through and override the ruins on any chunks we covered to # be blank. for p in iterate_cube(Vec(self.spos.x, 0, self.spos.z), - Vec(self.spos.x+1, 0, self.spos.z+2)): + Vec(self.spos.x + 1, 0, self.spos.z + 2)): if p == self.pos: continue blank = new('blank', self.parent.parent.rooms[p]) @@ -1356,13 +1361,13 @@ def render(self): # where to begin # Floor height at NW corner - start = self.parent.loc + Vec(0, self.parent.parent.room_height-3, 0) + start = self.parent.loc + Vec(0, self.parent.parent.room_height - 3, 0) # translate it 4 on the x/z to surround the stairs, translate it # more x/z if we had to move the building inside the dungeon # boundary. Move up to ground level for the entrance. - start = start.trans(4-self.parent.parent.room_size*movedX, + start = start.trans(4 - self.parent.parent.room_size * movedX, -self.parent.parent.entrance.low_height, - 4-self.parent.parent.room_size*movedZ) + 4 - self.parent.parent.room_size * movedZ) # clear the inside for p in iterate_cube(start.trans(1, 0, 1), @@ -1372,7 +1377,7 @@ def render(self): start.trans(15, -15, 38)): self.parent.parent.setblock(p, materials.Air) for p in iterate_cube(start.trans(0, 1, 0), - start.trans(23, self.parent.loc.y-start.y, 39)): + start.trans(23, self.parent.loc.y - start.y, 39)): self.parent.parent.setblock(p, soil) for p in iterate_cube(start.trans(0, 0, 0), start.trans(23, 0, 39)): @@ -1441,7 +1446,7 @@ def render(self): buttressStair, W) - #level 2 + # level 2 for p in iterate_cube(loc.up(11), loc.up(20)): self.parent.parent.setblock(p.trans(0, 0, 0), wall) self.parent.parent.setblock(p.trans(1, 0, 0), buttress) @@ -1502,7 +1507,7 @@ def render(self): buttressStair, W) - #level 3 + # level 3 for p in iterate_cube(loc.up(21), loc.up(30)): self.parent.parent.setblock(p.trans(1, 0, 1), buttress) self.parent.parent.setblock(p.trans(2, 0, 1), wall) @@ -1526,7 +1531,7 @@ def render(self): self.parent.parent.setblock(p.trans(6, 0, 4), buttress) self.parent.parent.setblock(p.trans(6, 0, 5), wall) - #follies + # follies for p in iterate_cube(loc.up(32), loc.up(33)): self.parent.parent.setblock(p.trans(2, 0, 2), wall) self.parent.parent.setblock(p.trans(2, 0, 5), wall) @@ -1539,13 +1544,13 @@ def render(self): # Randomly ruin if random.random() < .50: h = random.randint(0, 10) - ruinBlocks(loc.trans(0, -25+h, 0), - loc.trans(7, -25+h, 7), - 10+h, + ruinBlocks(loc.trans(0, -25 + h, 0), + loc.trans(7, -25 + h, 7), + 10 + h, self.parent.parent, aggressive=True) - #curtains + # curtains for p in iterate_cube(start.trans(1, 0, 8), start.trans(1, -9, 31)): self.parent.parent.setblock(p, wall) @@ -1559,7 +1564,7 @@ def render(self): start.trans(15, -15, 38)): self.parent.parent.setblock(p, wall) - #wing ceilings + # wing ceilings for p in iterate_cube(start.trans(1, -10, 8), start.trans(7, -10, 31)): self.parent.parent.setblock(p, wall) @@ -1567,18 +1572,18 @@ def render(self): start.trans(22, -10, 31)): self.parent.parent.setblock(p, wall) - #tall ceiling + # tall ceiling for p in iterate_cube(start.trans(8, -15, 1), start.trans(15, -15, 38)): if (p.z % 7 != 0): self.parent.parent.setblock(p, wall) - #and curtains + # and curtains for p in iterate_cube(start.trans(8, -10, 1), start.trans(8, -15, 38)): self.parent.parent.setblock(p, wall) self.parent.parent.setblock(p.trans(7, 0, 0), wall) - #floors + # floors for p in iterate_cube(start.trans(8, 0, 1), start.trans(15, 0, 38)): self.parent.parent.setblock(p, floor) @@ -1587,17 +1592,17 @@ def render(self): self.parent.parent.setblock(p, floor) self.parent.parent.setblock(p.trans(14, 0, 0), floor) - #interior bring it in from 1,0,8 21,0,31 + # interior bring it in from 1,0,8 21,0,31 for p in iterate_cube(start.trans(3, 0, 12), start.trans(19, 0, 29)): - if(p.x == start.x+11 or p.x == start.x+12): - #carpet would probably have deteriorated on a top floor + if(p.x == start.x + 11 or p.x == start.x + 12): + # carpet would probably have deteriorated on a top floor continue elif p.z % 2 == 0: - #pew + # pew self.parent.parent.setblock(p.up(1), stair, S) - #raised altar + # raised altar for p in iterate_cube(start.trans(8, -1, 2), start.trans(15, -1, 7)): self.parent.parent.setblock(p, wall) @@ -1641,7 +1646,7 @@ def render(self): self.parent.parent.setblock(p, mats[template[y][z][x]]) # Supply chest - loc = start.trans(8+3, -2, 2+2) + loc = start.trans(8 + 3, -2, 2 + 2) self.parent.parent.setblock(loc, materials.Chest, 2) self.parent.parent.setblock(loc.trans(1, 0, 0), materials.Chest, 2) self.parent.parent.addchest(loc, 0) @@ -1662,7 +1667,7 @@ def render(self): Motive='Wither') ) - #windows + # windows locs = [Vec(1, -3, 12), Vec(22, -3, 12), Vec(1, -3, 20), @@ -1670,42 +1675,41 @@ def render(self): Vec(1, -3, 28), Vec(22, -3, 28)] for loc in locs: - self.parent.parent.delblock(start.trans(loc.x, loc.y-5, loc.z)) + self.parent.parent.delblock(start.trans(loc.x, loc.y - 5, loc.z)) for p in iterate_cube(start.trans(loc.x, loc.y, loc.z), - start.trans(loc.x, loc.y-4, loc.z)): + start.trans(loc.x, loc.y - 4, loc.z)): self.parent.parent.delblock(p.trans(0, 0, -1)) self.parent.parent.delblock(p) self.parent.parent.delblock(p.trans(0, 0, 1)) - #door + # door self.parent.parent.delblock(start.trans(11, -11, 38)) self.parent.parent.delblock(start.trans(12, -11, 38)) for p in iterate_cube(start.trans(10, -1, 38), start.trans(13, -10, 38)): self.parent.parent.delblock(p) - #inner doorways + # inner doorways locs = [Vec(5, -1, 7), - Vec(2+16, -1, 7), - Vec(7, -1, 32+2), - Vec(16, -1, 32+2)] + Vec(2 + 16, -1, 7), + Vec(7, -1, 32 + 2), + Vec(16, -1, 32 + 2)] for loc in locs: self.parent.parent.setblock(start.trans(loc.x, loc.y, loc.z), materials.Air) - self.parent.parent.setblock(start.trans(loc.x, loc.y-1, loc.z), + self.parent.parent.setblock(start.trans(loc.x, loc.y - 1, loc.z), materials.Air) # extend the stair up - estart = self.parent.loc.up(self.parent.parent.room_height-3) + estart = self.parent.loc.up(self.parent.parent.room_height - 3) for p in iterate_cube(estart.trans(6, 0, 6), estart.trans(9, -6, 9)): self.parent.parent.setblock(p, materials.Air) mat = materials.StoneSlab - for p in iterate_spiral(Vec(estart.x+6, estart.y, estart.z+6), - Vec(estart.x+6+4, estart.y, estart.z+6+4), + for p in iterate_spiral(Vec(estart.x + 6, estart.y, estart.z + 6), + Vec(estart.x + 6 + 4, estart.y, estart.z + 6 + 4), 10): - self.parent.parent.setblock(Vec(p.x, - p.y/2, - p.z), mat, mat.data+((p.y & 1) ^ 1)*8) + self.parent.parent.setblock( + Vec(p.x, p.y / 2, p.z), mat, mat.data + ((p.y & 1) ^ 1) * 8) for p in iterate_four_walls(estart.trans(5, 0, 5), estart.trans(10, 0, 10), 3): @@ -1772,14 +1776,14 @@ def setData(self): xsize = self.parent.parent.xsize zsize = self.parent.parent.zsize self.spos = copy(self.pos) - while self.spos.x > xsize-2: + while self.spos.x > xsize - 2: self.spos.x -= 1 - while self.spos.z > zsize-2: + while self.spos.z > zsize - 2: self.spos.z -= 1 # Now go through and override the ruins on any chunks we cover # to be blank. for p in iterate_cube(Vec(self.spos.x, 0, self.spos.z), - Vec(self.spos.x+1, 0, self.spos.z+1)): + Vec(self.spos.x + 1, 0, self.spos.z + 1)): if p == self.pos: continue blank = new('blank', self.parent.parent.rooms[p]) @@ -1788,7 +1792,7 @@ def setData(self): self.low = 1024 self.high = 0 for p in iterate_cube(Vec(self.spos.x, 0, self.spos.z), - Vec(self.spos.x+1, 0, self.spos.z+1)): + Vec(self.spos.x + 1, 0, self.spos.z + 1)): cx = (self.parent.parent.position.x >> 4) + p.x cz = (self.parent.parent.position.z >> 4) + p.z (a, b) = findChunkDepths(Vec(cx, 0, cz), @@ -1805,29 +1809,29 @@ def setData(self): def render(self): sb = self.parent.parent.setblock c1 = self.loc - c3 = self.loc + Vec(self.parent.parent.room_size*2-1, + c3 = self.loc + Vec(self.parent.parent.room_size * 2 - 1, 0, - self.parent.parent.room_size*2-1) + self.parent.parent.room_size * 2 - 1) # Mound height = max(self.high - self.low + 2, 6) for z in xrange(32): for x in xrange(32): - x1 = (x - 16)/16.0 - z1 = (z - 16)/16.0 - if math.sqrt(x1*x1+z1*z1) > 1: + x1 = (x - 16) / 16.0 + z1 = (z - 16) / 16.0 + if math.sqrt(x1 * x1 + z1 * z1) > 1: continue - y = math.sqrt(abs(1.0-x1*x1-z1*z1)) - for yy in xrange(int(y*height)): - sb(c1+Vec(x, -yy, z), self._earth) - sb(c1+Vec(x, 0, z), self._floor) - sb(c1+Vec(x, -y*height, z), self._grass) + y = math.sqrt(abs(1.0 - x1 * x1 - z1 * z1)) + for yy in xrange(int(y * height)): + sb(c1 + Vec(x, -yy, z), self._earth) + sb(c1 + Vec(x, 0, z), self._floor) + sb(c1 + Vec(x, -y * height, z), self._grass) # Standing stones - for p in iterate_ellipse(c1+Vec(8, 0, 8), c3-Vec(8, 0, 8)): + for p in iterate_ellipse(c1 + Vec(8, 0, 8), c3 - Vec(8, 0, 8)): if (random.randint(0, 100) < 80): continue - for y in xrange(1, int(height)+4): + for y in xrange(1, int(height) + 4): sb(p.up(y), self._stones) # Hollow it out. @@ -1836,7 +1840,7 @@ def render(self): for x in xrange(32): for z in xrange(32): for y in xrange(1, 5): - p = c1+Vec(x, -y, z) + p = c1 + Vec(x, -y, z) if ( p in blocks and x is not 16 and @@ -1854,21 +1858,21 @@ def render(self): # A way in. for x in xrange(15, 18): for z in xrange(15, 18): - for y in xrange(1, int(height)+1): - p = c1+Vec(x, -y, z) + for y in xrange(1, int(height) + 1): + p = c1 + Vec(x, -y, z) sb(p, materials.Air) for x in xrange(15, 18): for z in xrange(15, 18): - for y in xrange(1, int(height)+1): - p = c1+Vec(x, -y, z) + for y in xrange(1, int(height) + 1): + p = c1 + Vec(x, -y, z) self.parent.parent.vines(p, grow=True) # More vines for x in xrange(32): for z in xrange(32): - for y in xrange(int(height), int(height)+4): + for y in xrange(int(height), int(height) + 4): if (random.randint(0, 100) < 30): - p = c1+Vec(x, -y, z) + p = c1 + Vec(x, -y, z) self.parent.parent.vines(p, grow=True) # Coffins @@ -1895,10 +1899,10 @@ def addnameplate(p, name): matsE = { 'W': (materials.OakWoodPlanks, random.randint(0, 3)), - '-': (materials.StoneBrickSlab, 5+8), + '-': (materials.StoneBrickSlab, 5 + 8), '_': (materials.StoneBrickSlab, 5), - '1': (materials.StoneBrickStairs, 0+4), - '2': (materials.StoneBrickStairs, 1+4), + '1': (materials.StoneBrickStairs, 0 + 4), + '2': (materials.StoneBrickStairs, 1 + 4), '3': (materials.StoneBrickStairs, 1), '4': (materials.StoneBrickStairs, 0), '#': (materials.meta_mossystonebrick, 0), @@ -1906,10 +1910,10 @@ def addnameplate(p, name): } matsW = { 'W': (materials.OakWoodPlanks, random.randint(0, 3)), - '-': (materials.StoneBrickSlab, 5+8), + '-': (materials.StoneBrickSlab, 5 + 8), '_': (materials.StoneBrickSlab, 5), - '1': (materials.StoneBrickStairs, 1+4), - '2': (materials.StoneBrickStairs, 0+4), + '1': (materials.StoneBrickStairs, 1 + 4), + '2': (materials.StoneBrickStairs, 0 + 4), '3': (materials.StoneBrickStairs, 0), '4': (materials.StoneBrickStairs, 1), '#': (materials.meta_mossystonebrick, 0), @@ -1917,10 +1921,10 @@ def addnameplate(p, name): } matsN = { 'W': (materials.OakWoodPlanks, random.randint(0, 3)), - '-': (materials.StoneBrickSlab, 5+8), + '-': (materials.StoneBrickSlab, 5 + 8), '_': (materials.StoneBrickSlab, 5), - '1': (materials.StoneBrickStairs, 2+4), - '2': (materials.StoneBrickStairs, 3+4), + '1': (materials.StoneBrickStairs, 2 + 4), + '2': (materials.StoneBrickStairs, 3 + 4), '3': (materials.StoneBrickStairs, 3), '4': (materials.StoneBrickStairs, 2), '#': (materials.meta_mossystonebrick, 0), @@ -1928,10 +1932,10 @@ def addnameplate(p, name): } matsS = { 'W': (materials.OakWoodPlanks, random.randint(0, 3)), - '-': (materials.StoneBrickSlab, 5+8), + '-': (materials.StoneBrickSlab, 5 + 8), '_': (materials.StoneBrickSlab, 5), - '1': (materials.StoneBrickStairs, 3+4), - '2': (materials.StoneBrickStairs, 2+4), + '1': (materials.StoneBrickStairs, 3 + 4), + '2': (materials.StoneBrickStairs, 2 + 4), '3': (materials.StoneBrickStairs, 2), '4': (materials.StoneBrickStairs, 3), '#': (materials.meta_mossystonebrick, 0), @@ -1943,56 +1947,56 @@ def addnameplate(p, name): ('3', '_', '*', '_', '4', '#')) for x in xrange(3, 16): for y in xrange(4): - p = c1+Vec(16, -4, 16)+Vec(x, y, 0) + p = c1 + Vec(16, -4, 16) + Vec(x, y, 0) ssb(p, - matsE[mid[y % 2][(x-3) % 6]][0], - matsE[mid[y % 2][(x-3) % 6]][1]) + matsE[mid[y % 2][(x - 3) % 6]][0], + matsE[mid[y % 2][(x - 3) % 6]][1]) ssb(p.n(1), - matsE[out[y % 2][(x-3) % 6]][0], - matsE[out[y % 2][(x-3) % 6]][1]) + matsE[out[y % 2][(x - 3) % 6]][0], + matsE[out[y % 2][(x - 3) % 6]][1]) ssb(p.s(1), - matsE[out[y % 2][(x-3) % 6]][0], - matsE[out[y % 2][(x-3) % 6]][1]) + matsE[out[y % 2][(x - 3) % 6]][0], + matsE[out[y % 2][(x - 3) % 6]][1]) - p = c1+Vec(16, -4, 16)+Vec(-x, y, 0) + p = c1 + Vec(16, -4, 16) + Vec(-x, y, 0) ssb(p, - matsW[mid[y % 2][(x-3) % 6]][0], - matsW[mid[y % 2][(x-3) % 6]][1]) + matsW[mid[y % 2][(x - 3) % 6]][0], + matsW[mid[y % 2][(x - 3) % 6]][1]) ssb(p.n(1), - matsW[out[y % 2][(x-3) % 6]][0], - matsW[out[y % 2][(x-3) % 6]][1]) + matsW[out[y % 2][(x - 3) % 6]][0], + matsW[out[y % 2][(x - 3) % 6]][1]) ssb(p.s(1), - matsW[out[y % 2][(x-3) % 6]][0], - matsW[out[y % 2][(x-3) % 6]][1]) + matsW[out[y % 2][(x - 3) % 6]][0], + matsW[out[y % 2][(x - 3) % 6]][1]) - p = c1+Vec(16, -4, 16)+Vec(0, y, x) + p = c1 + Vec(16, -4, 16) + Vec(0, y, x) ssb(p, - matsN[mid[y % 2][(x-3) % 6]][0], - matsN[mid[y % 2][(x-3) % 6]][1]) + matsN[mid[y % 2][(x - 3) % 6]][0], + matsN[mid[y % 2][(x - 3) % 6]][1]) ssb(p.e(1), - matsN[out[y % 2][(x-3) % 6]][0], - matsN[out[y % 2][(x-3) % 6]][1]) + matsN[out[y % 2][(x - 3) % 6]][0], + matsN[out[y % 2][(x - 3) % 6]][1]) ssb(p.w(1), - matsN[out[y % 2][(x-3) % 6]][0], - matsN[out[y % 2][(x-3) % 6]][1]) + matsN[out[y % 2][(x - 3) % 6]][0], + matsN[out[y % 2][(x - 3) % 6]][1]) - p = c1+Vec(16, -4, 16)+Vec(0, y, -x) + p = c1 + Vec(16, -4, 16) + Vec(0, y, -x) ssb(p, - matsS[mid[y % 2][(x-3) % 6]][0], - matsS[mid[y % 2][(x-3) % 6]][1]) + matsS[mid[y % 2][(x - 3) % 6]][0], + matsS[mid[y % 2][(x - 3) % 6]][1]) ssb(p.e(1), - matsS[out[y % 2][(x-3) % 6]][0], - matsS[out[y % 2][(x-3) % 6]][1]) + matsS[out[y % 2][(x - 3) % 6]][0], + matsS[out[y % 2][(x - 3) % 6]][1]) ssb(p.w(1), - matsS[out[y % 2][(x-3) % 6]][0], - matsS[out[y % 2][(x-3) % 6]][1]) + matsS[out[y % 2][(x - 3) % 6]][0], + matsS[out[y % 2][(x - 3) % 6]][1]) # Signs if ( - (x+1) % 6 == 0 and + (x + 1) % 6 == 0 and y % 2 == 1 ): - p = c1+Vec(16, -4, 16)+Vec(x, y, 0) + p = c1 + Vec(16, -4, 16) + Vec(x, y, 0) name = self.parent.parent.namegen.genname() ssb(p.n(1), materials.StoneBrickStairs, 3) ssb(p.n(2), materials.WallSign, 2) @@ -2001,7 +2005,7 @@ def addnameplate(p, name): ssb(p.s(2), materials.WallSign, 3) addnameplate(p.s(2), name) - p = c1+Vec(16, -4, 16)+Vec(-x, y, 0) + p = c1 + Vec(16, -4, 16) + Vec(-x, y, 0) name = self.parent.parent.namegen.genname() ssb(p.n(1), materials.StoneBrickStairs, 3) ssb(p.n(2), materials.WallSign, 2) @@ -2010,7 +2014,7 @@ def addnameplate(p, name): ssb(p.s(2), materials.WallSign, 3) addnameplate(p.s(2), name) - p = c1+Vec(16, -4, 16)+Vec(0, y, x) + p = c1 + Vec(16, -4, 16) + Vec(0, y, x) name = self.parent.parent.namegen.genname() ssb(p.e(1), materials.StoneBrickStairs, 0) ssb(p.e(2), materials.WallSign, 5) @@ -2019,7 +2023,7 @@ def addnameplate(p, name): ssb(p.w(2), materials.WallSign, 4) addnameplate(p.w(2), name) - p = c1+Vec(16, -4, 16)+Vec(0, y, -x) + p = c1 + Vec(16, -4, 16) + Vec(0, y, -x) name = self.parent.parent.namegen.genname() ssb(p.e(1), materials.StoneBrickStairs, 0) ssb(p.e(2), materials.WallSign, 5) @@ -2031,10 +2035,10 @@ def addnameplate(p, name): # Grass for x in xrange(32): for z in xrange(32): - for y in xrange(1, int(height)+1): + for y in xrange(1, int(height) + 1): if (random.randint(0, 100) < 80): continue - p = c1+Vec(x, -y, z) + p = c1 + Vec(x, -y, z) if ( p not in blocks and p.down(1) in blocks and @@ -2043,15 +2047,15 @@ def addnameplate(p, name): sb(p, self._tallgrass, soft=True) # Stairwell height - self.parent.parent.entrance.height = abs(-c1.y-2)+5 + self.parent.parent.entrance.height = abs(-c1.y - 2) + 5 # Supply chest - loc = c1+Vec(14, -int(height), 14) + loc = c1 + Vec(14, -int(height), 14) sb(loc, materials.Chest, 2) self.parent.parent.addchest(loc, 0) # Exit Portal - self.parent.parent.dinfo['portal_exit'] = c1+Vec(16, -1, 16) + self.parent.parent.dinfo['portal_exit'] = c1 + Vec(16, -1, 16) class Oasis(Blank): @@ -2067,14 +2071,14 @@ def setData(self): xsize = self.parent.parent.xsize zsize = self.parent.parent.zsize self.spos = copy(self.pos) - while self.spos.x > xsize-3: + while self.spos.x > xsize - 3: self.spos.x -= 1 - while self.spos.z > zsize-3: + while self.spos.z > zsize - 3: self.spos.z -= 1 # Now go through and override the ruins on any chunks we cover # to be blank. for p in iterate_cube(Vec(self.spos.x, 0, self.spos.z), - Vec(self.spos.x+2, 0, self.spos.z+2)): + Vec(self.spos.x + 2, 0, self.spos.z + 2)): if p == self.pos: continue blank = new('blank', self.parent.parent.rooms[p]) @@ -2083,14 +2087,14 @@ def setData(self): self.low = 1024 self.high = 0 for p in iterate_cube(Vec(self.spos.x, 0, self.spos.z), - Vec(self.spos.x+1, 0, self.spos.z+1)): + Vec(self.spos.x + 1, 0, self.spos.z + 1)): cx = (self.parent.parent.position.x >> 4) + p.x cz = (self.parent.parent.position.z >> 4) + p.z (a, b) = findChunkDepths(Vec(cx, 0, cz), self.parent.parent.world) self.low = min(self.low, a) self.high = max(self.high, b) - self.depth = self.low+1 + self.depth = self.low + 1 self.depth = max(self.depth, self.parent.parent.position.y) self.vtrans = self.depth - self.parent.parent.position.y self.loc = Vec(self.spos.x * self.parent.parent.room_size, @@ -2105,18 +2109,18 @@ def render(self): pond = cave_factory.new(32, 32) pond.resize_map(48, 48) # Add the area of the stairwell as an exit. - x1 = (self.pos.x - self.spos.x)*16+5 - y1 = (self.pos.z - self.spos.z)*16+5 + x1 = (self.pos.x - self.spos.x) * 16 + 5 + y1 = (self.pos.z - self.spos.z) * 16 + 5 stairwell = [] - for p in xrange(y1, y1+6): - pond.add_exit((p, x1), (p, x1+5)) + for p in xrange(y1, y1 + 6): + pond.add_exit((p, x1), (p, x1 + 5)) for x in xrange(6): - stairwell.append(c1+Vec(x1+x, 0, p)) + stairwell.append(c1 + Vec(x1 + x, 0, p)) pond.gen_map(mode=random.choice(('default', 'room'))) # The water for p in pond.iterate_map(cave_factory.FLOOR): - q = c1+Vec(p[0], 0, p[1]) + q = c1 + Vec(p[0], 0, p[1]) sb(q.down(1), materials.Sandstone) sb(q, materials.Water) @@ -2124,23 +2128,23 @@ def render(self): # First band is where reeds might grow. reeds = [] for p in pond.iterate_walls(): - q = c1+Vec(p[0], 0, p[1]) + q = c1 + Vec(p[0], 0, p[1]) reeds.append(q) sb(q, materials.Grass) # Second pass is where palms may grow. pond.reduce_map() palms = [] for p in pond.iterate_walls(): - q = c1+Vec(p[0], 0, p[1]) + q = c1 + Vec(p[0], 0, p[1]) palms.append(q) sb(q, materials.Grass) pond.reduce_map() # Now progressively clear out space above. # Now add air. - for h in xrange(1, self.high-self.low+10): + for h in xrange(1, self.high - self.low + 10): for p in pond.iterate_map(cave_factory.FLOOR): - q = c1+Vec(p[0], -h, p[1]) + q = c1 + Vec(p[0], -h, p[1]) sb(q, materials.Air) pond.reduce_map() @@ -2165,7 +2169,7 @@ def render(self): notchest.append(p) h = random.randint(4, 8) # Fronds - sb(p.up(h+1), materials.JungleLeaves) + sb(p.up(h + 1), materials.JungleLeaves) sb(p.up(h).n(1), materials.JungleLeaves) sb(p.up(h).s(1), materials.JungleLeaves) sb(p.up(h).e(1), materials.JungleLeaves) @@ -2190,9 +2194,9 @@ def render(self): materials.LightGrayStainedClay, ] random.shuffle(mats) - st = c1 + Vec((self.pos.x - self.spos.x)*16+5, + st = c1 + Vec((self.pos.x - self.spos.x) * 16 + 5, -1, - (self.pos.z - self.spos.z)*16+5) + (self.pos.z - self.spos.z) * 16 + 5) for p in iterate_cube(st, st.up(4)): sb(p, mats[0]) sb(p.trans(5, 0, 0), mats[0]) @@ -2218,7 +2222,7 @@ def render(self): sb(p, mats[3]) # Stairwell height - self.parent.parent.entrance.height = abs(-c1.y-2)+5 + self.parent.parent.entrance.height = abs(-c1.y - 2) + 5 # Supply chest loc = random.choice(list((set(reeds) & set(palms)) - set(notchest))) @@ -2226,10 +2230,10 @@ def render(self): self.parent.parent.addchest(loc.up(1), 0) # Exit Portal - self.parent.parent.dinfo['portal_exit'] = c1+Vec(24, -3, 24) + self.parent.parent.dinfo['portal_exit'] = c1 + Vec(24, -3, 24) -## Other ruins +# Other ruins class CircularTower(Blank): _name = 'circulartower' @@ -2255,17 +2259,17 @@ def render(self): mat = materials.meta_mossystonebrick c1 = self.loc - c3 = c1 + Vec(self.parent.parent.room_size-2, + c3 = c1 + Vec(self.parent.parent.room_size - 2, 0, - self.parent.parent.room_size-2) + self.parent.parent.room_size - 2) # Jitter! scale = random.randint(0, 8) x_jitter = random.randint(0, scale) z_jitter = random.randint(0, scale) - c1 += Vec(scale-x_jitter, 0, scale-z_jitter) + c1 += Vec(scale - x_jitter, 0, scale - z_jitter) c3 += Vec(-x_jitter, 0, -z_jitter) - height = int(self.parent.parent.room_height*1.5) + height = int(self.parent.parent.room_height * 1.5) for p in self.wallsf(c1, c3, height): self.parent.parent.setblock(p, mat, hide=True) ruinBlocks(c1.up(1), c3.up(1), height, self.parent.parent) @@ -2282,7 +2286,7 @@ class Arches(Blank): _name = 'arches' def render(self): - height = self.parent.parent.room_height*2 + height = self.parent.parent.room_height * 2 sb = self.parent.parent.setblock # Sandstone in deserts if self.parent.parent.biome in _desert_biomes: @@ -2316,24 +2320,24 @@ def render(self): for xo in xrange(2): for zo in xrange(2): - c1 = self.loc + Vec(8*xo, 0, 8*zo) + c1 = self.loc + Vec(8 * xo, 0, 8 * zo) c3 = c1 + Vec(7, 0, 7) # columns for p in iterate_cube(c1, c1.trans(0, -height, 0)): - sb(p, mat, hide=True) + sb(p, mat, hide=True) sb(p.trans(7, 0, 0), mat, hide=True) sb(p.trans(7, 0, 7), mat, hide=True) sb(p.trans(0, 0, 7), mat, hide=True) # First level - p = c1.trans(0, -height+2, 0) - sb(p.trans(1, 0, 0), stair, 1+4) - sb(p.trans(6, 0, 0), stair, 0+4) - sb(p.trans(0, 0, 1), stair, 3+4) - sb(p.trans(7, 0, 1), stair, 3+4) - sb(p.trans(0, 0, 6), stair, 2+4) - sb(p.trans(7, 0, 6), stair, 2+4) - sb(p.trans(1, 0, 7), stair, 1+4) - sb(p.trans(6, 0, 7), stair, 0+4) + p = c1.trans(0, -height + 2, 0) + sb(p.trans(1, 0, 0), stair, 1 + 4) + sb(p.trans(6, 0, 0), stair, 0 + 4) + sb(p.trans(0, 0, 1), stair, 3 + 4) + sb(p.trans(7, 0, 1), stair, 3 + 4) + sb(p.trans(0, 0, 6), stair, 2 + 4) + sb(p.trans(7, 0, 6), stair, 2 + 4) + sb(p.trans(1, 0, 7), stair, 1 + 4) + sb(p.trans(6, 0, 7), stair, 0 + 4) # Second level p = p.trans(0, -1, 0) sb(p.trans(1, 0, 0), mat) @@ -2345,14 +2349,14 @@ def render(self): sb(p.trans(1, 0, 7), mat) sb(p.trans(6, 0, 7), mat) # --- - sb(p.trans(2, 0, 0), stair, 1+4) - sb(p.trans(5, 0, 0), stair, 0+4) - sb(p.trans(0, 0, 2), stair, 3+4) - sb(p.trans(7, 0, 2), stair, 3+4) - sb(p.trans(0, 0, 5), stair, 2+4) - sb(p.trans(7, 0, 5), stair, 2+4) - sb(p.trans(2, 0, 7), stair, 1+4) - sb(p.trans(5, 0, 7), stair, 0+4) + sb(p.trans(2, 0, 0), stair, 1 + 4) + sb(p.trans(5, 0, 0), stair, 0 + 4) + sb(p.trans(0, 0, 2), stair, 3 + 4) + sb(p.trans(7, 0, 2), stair, 3 + 4) + sb(p.trans(0, 0, 5), stair, 2 + 4) + sb(p.trans(7, 0, 5), stair, 2 + 4) + sb(p.trans(2, 0, 7), stair, 1 + 4) + sb(p.trans(5, 0, 7), stair, 0 + 4) # Top layer p = p.trans(0, -1, 0) for p in iterate_four_walls(p, p.trans(7, 0, 7), 0): @@ -2395,21 +2399,21 @@ def render(self): mat = materials.meta_mossystonebrick stair = materials.StoneBrickStairs - #what direction will the stairs face? + # what direction will the stairs face? E = 0 W = 1 # got the mats. now draw the base. start one higher so it's less buried - start = self.loc.trans(3+random.randint(0, 2), + start = self.loc.trans(3 + random.randint(0, 2), -1, - 3+random.randint(0, 2)) + 3 + random.randint(0, 2)) for p in iterate_cube(start, start.trans(7, 0, 7)): self.parent.parent.setblock(p, mat) # now draw the A frame start = start.trans(0, -1, 0) - #will the head be in the south (7) or north (0) + # will the head be in the south (7) or north (0) head = random.randint(0, 1) * 7 for p in iterate_cube(start.trans(0, 0, head), @@ -2434,7 +2438,7 @@ def render(self): # cut out the window(s) if(random.randint(0, 100) < 50): - #two tall windows + # two tall windows self.parent.parent.delblock(start.trans(2, -1, head)) self.parent.parent.delblock(start.trans(4, -1, head)) self.parent.parent.delblock(start.trans(2, -2, head)) @@ -2442,13 +2446,13 @@ def render(self): self.parent.parent.delblock(start.trans(2, -3, head)) self.parent.parent.delblock(start.trans(4, -3, head)) else: - #one big arch + # one big arch for p in iterate_cube(start.trans(2, 0, head), start.trans(4, -2, head)): self.parent.parent.delblock(p) - self.parent.parent.setblock(start.trans(2, -3, head), stair, W+4) + self.parent.parent.setblock(start.trans(2, -3, head), stair, W + 4) self.parent.parent.delblock(start.trans(3, -3, head)) - self.parent.parent.setblock(start.trans(4, -3, head), stair, E+4) + self.parent.parent.setblock(start.trans(4, -3, head), stair, E + 4) # then draw the long wall for p in iterate_cube(start, start.trans(0, 0, 7)): @@ -2458,27 +2462,28 @@ def render(self): self.parent.parent.setblock(p.up(2), mat) # and the corner post opposite - for p in iterate_cube(start.trans(7, 0, 7-head), - start.trans(7, -3, 7-head)): + for p in iterate_cube(start.trans(7, 0, 7 - head), + start.trans(7, -3, 7 - head)): self.parent.parent.setblock(p, mat) # and maybe some ancient pottery if (random.randint(1, 100) < 10): - self.parent.parent.setblock(start.trans(2+random.randint(0, 3), + self.parent.parent.setblock(start.trans(2 + random.randint(0, 3), 0, 2), materials.FlowerPot, 10, soft=True) - self.parent.parent.setblock(start.trans(2+random.randint(0, 3), + self.parent.parent.setblock(start.trans(2 + random.randint(0, 3), 0, 3), materials.FlowerPot, 10, soft=True) - #ruin it! (maybe) + # ruin it! (maybe) if (random.randint(1, 100) < 50): ruinBlocks(start, start.trans(7, 0, 7), 7, self.parent.parent) class MazeEntrance(Blank): + ''' Maze-like entrance to a dungeon. ''' @@ -2519,8 +2524,8 @@ def setData(self): if ( self.pos.x > 0 and self.pos.z > 0 and - self.pos.x < xsize-1 and - self.pos.z < zsize-1 + self.pos.x < xsize - 1 and + self.pos.z < zsize - 1 ): self._size = 3 @@ -2529,8 +2534,8 @@ def setData(self): # clear all ruins with 3x3 block around dungeon entrance # the maze will be 3x3 chunks with the entrance in the center chunk if self._size == 3: - for p in iterate_cube(Vec(maze_pos.x-1, 0, maze_pos.z-1), - Vec(maze_pos.x+1, 0, maze_pos.z+1)): + for p in iterate_cube(Vec(maze_pos.x - 1, 0, maze_pos.z - 1), + Vec(maze_pos.x + 1, 0, maze_pos.z + 1)): if p == self.pos: continue blank = new('blank', self.parent.parent.rooms[p]) @@ -2544,12 +2549,12 @@ def _gen_maze_dfs(self): ''' cw = self._size * 16 cl = self._size * 16 - canvas_width = cw - ((cw)+1) % 2 - canvas_length = cl - ((cl)+1) % 2 + canvas_width = cw - ((cw) + 1) % 2 + canvas_length = cl - ((cl) + 1) % 2 blocks = [ [0 for j in xrange(canvas_length)] for i in xrange(canvas_width) ] - start_x = random.randint(0, canvas_width/2 - 1)*2 + 1 + start_x = random.randint(0, canvas_width / 2 - 1) * 2 + 1 start_z = 1 unvisited = [] # keep track of the unvisited nodes in a stack cur = (start_x, start_z) @@ -2562,18 +2567,18 @@ def _gen_maze_dfs(self): cur[1]) if len(neighbors) > 0: # pick a neighbor, and add the rest to the back of unvisited - next = neighbors.pop(random.randint(0, len(neighbors)-1)) + next = neighbors.pop(random.randint(0, len(neighbors) - 1)) if len(neighbors) > 0: unvisited += [cur] # hollow out hole in between cur and next if next[0] < cur[0]: # left - blocks[cur[0]-1][cur[1]] = 1 + blocks[cur[0] - 1][cur[1]] = 1 elif next[0] > cur[0]: # right - blocks[cur[0]+1][cur[1]] = 1 + blocks[cur[0] + 1][cur[1]] = 1 elif next[1] < cur[1]: # down - blocks[cur[0]][cur[1]-1] = 1 + blocks[cur[0]][cur[1] - 1] = 1 elif next[1] > cur[1]: # up - blocks[cur[0]][cur[1]+1] = 1 + blocks[cur[0]][cur[1] + 1] = 1 cur = next elif len(unvisited) > 0: cur = unvisited.pop() @@ -2581,34 +2586,34 @@ def _gen_maze_dfs(self): break # add an entrance on each side # front - x = random.randint(0, canvas_width/2 - 1)*2 + 1 + x = random.randint(0, canvas_width / 2 - 1) * 2 + 1 blocks[x][0] = 1 # back - x = random.randint(0, canvas_width/2 - 1)*2 + 1 - blocks[x][canvas_length-1] = 1 + x = random.randint(0, canvas_width / 2 - 1) * 2 + 1 + blocks[x][canvas_length - 1] = 1 # left - z = random.randint(0, canvas_length/2 - 1)*2 + 1 + z = random.randint(0, canvas_length / 2 - 1) * 2 + 1 blocks[0][z] = 1 # right - z = random.randint(0, canvas_length/2 - 1)*2 + 1 - blocks[canvas_width-1][z] = 1 + z = random.randint(0, canvas_length / 2 - 1) * 2 + 1 + blocks[canvas_width - 1][z] = 1 # post-process to smooth out turns in the maze # use a sliding 2x2 window - for i in xrange(canvas_width-2): - for j in xrange(canvas_length-2): + for i in xrange(canvas_width - 2): + for j in xrange(canvas_length - 2): count = blocks[i][j] + \ - 2*blocks[i+1][j] + \ - 4*blocks[i][j+1] + \ - 8*blocks[i+1][j+1] + 2 * blocks[i + 1][j] + \ + 4 * blocks[i][j + 1] + \ + 8 * blocks[i + 1][j + 1] if count == 8: blocks[i][j] = 1 elif count == 4: - blocks[i+1][j] = 1 + blocks[i + 1][j] = 1 elif count == 2: - blocks[i][j+1] = 1 + blocks[i][j + 1] = 1 elif count == 1: - blocks[i+1][j+1] = 1 + blocks[i + 1][j + 1] = 1 return blocks @@ -2617,14 +2622,14 @@ def _get_open_neighbors(self, blocks, canvas_width, canvas_length, i, j): return neighbors = [] # check 4 directions - if i > 1 and blocks[i-2][j] == 0: # left - neighbors.append((i-2, j)) - if i < canvas_width - 2 and blocks[i+2][j] == 0: # right - neighbors.append((i+2, j)) + if i > 1 and blocks[i - 2][j] == 0: # left + neighbors.append((i - 2, j)) + if i < canvas_width - 2 and blocks[i + 2][j] == 0: # right + neighbors.append((i + 2, j)) if j > 1 and blocks[i][j - 2] == 0: # down - neighbors.append((i, j-2)) - if j < canvas_length - 2 and blocks[i][j+2] == 0: - neighbors.append((i, j+2)) + neighbors.append((i, j - 2)) + if j < canvas_length - 2 and blocks[i][j + 2] == 0: + neighbors.append((i, j + 2)) return neighbors def render(self): @@ -2644,15 +2649,15 @@ def render(self): mats = self._mats['mesa'] # The room floor Y location - room_floor = self.parent.loc.y+self.parent.parent.room_height-3 + room_floor = self.parent.loc.y + self.parent.parent.room_height - 3 # The height of one room rheight = self.parent.parent.room_height # Ground level glev = room_floor - self.parent.parent.entrance.high_height # start = self.parent.loc.trans(-16, glev, -16) - sc = int(self._size/2)*16 - start = Vec(self.loc.x - sc, self.parent.loc.y+glev, self.loc.z-sc) + sc = int(self._size / 2) * 16 + start = Vec(self.loc.x - sc, self.parent.loc.y + glev, self.loc.z - sc) # render the floor of the labyrinth for i in xrange(len(blocks)): @@ -2681,8 +2686,8 @@ def render(self): ( pn.noise2(i / 32.0, j / 32.0) + 1.0 ) / 2.0 * self.parent.parent.room_height - )*( - (16*self._size)/(abs(j-(sc+8)) + abs(i-(sc+8))) + ) * ( + (16 * self._size) / (abs(j - (sc + 8)) + abs(i - (sc + 8))) ) + 7 for y in xrange(int(height)): if blocks[i][j] == 0: # wall @@ -2708,7 +2713,7 @@ def render(self): ) # adjust the entrance height to match with the floor of the labyrinth - self.parent.parent.entrance.height = abs(room_floor-glev) + self.parent.parent.entrance.height = abs(room_floor - glev) # Supply chest chest_pos = start.trans(sc + 7, -1, sc + 5) @@ -2728,9 +2733,9 @@ def render(self): ) d = 2 s1 = Vec(gstart.x - 3, glev + 1, start.z - 3) - s3 = Vec(gstart.x + self._size*3 + 3, + s3 = Vec(gstart.x + self._size * 3 + 3, glev + 1, - start.z + self._size*3 + 3) + start.z + self._size * 3 + 3) for y in xrange(rheight): for p in iterate_disc(s1.trans(-d, y, -d), s3.trans(d, y, d)): @@ -2746,15 +2751,15 @@ def ruinBlocks(p1, p2, height, dungeon, override=False, aggressive=False): cfg.ruin_ruins is False ): return - for x in xrange(p1.x, p2.x+1): - for z in xrange(p1.z, p2.z+1): + for x in xrange(p1.x, p2.x + 1): + for z in xrange(p1.z, p2.z + 1): depth = (pn.noise3(x / 4.0, 0, z / 4.0) + 1.0) / 2.0 * height - for p in iterate_cube(Vec(x, p1.y-depth, z), - Vec(x, p1.y-height, z)): + for p in iterate_cube(Vec(x, p1.y - depth, z), + Vec(x, p1.y - height, z)): dungeon.delblock(p) # Look for floating blocks floaters = [] - for p in iterate_cube(p1, Vec(p2.x, p2.y-height, p2.z)): + for p in iterate_cube(p1, Vec(p2.x, p2.y - height, p2.z)): if ( ( p in dungeon.blocks and diff --git a/utils.py b/utils.py index 838d4a09..1c619d06 100644 --- a/utils.py +++ b/utils.py @@ -22,7 +22,7 @@ def floor(n): def ceil(n): if int(n) == n: return int(n) - return int(n)+1 + return int(n) + 1 def clamp(n, a, b): @@ -36,25 +36,26 @@ def clamp(n, a, b): class Vec(object): + def __init__(self, x, y, z): self.x = int(x) self.y = int(y) self.z = int(z) def __add__(self, b): - if type(b) == Vec: - return Vec(self.x+b.x, self.y+b.y, self.z+b.z) + if isinstance(b, Vec): + return Vec(self.x + b.x, self.y + b.y, self.z + b.z) else: - return Vec(self.x+b, self.y+b, self.z+b) + return Vec(self.x + b, self.y + b, self.z + b) def __sub__(self, b): - if type(b) == Vec: - return Vec(self.x-b.x, self.y-b.y, self.z-b.z) + if isinstance(b, Vec): + return Vec(self.x - b.x, self.y - b.y, self.z - b.z) else: - return Vec(self.x-b, self.y-b, self.z-b) + return Vec(self.x - b, self.y - b, self.z - b) def __mul__(self, b): - return Vec(self.x*b, self.y*b, self.z*b) + return Vec(self.x * b, self.y * b, self.z * b) def __str__(self): return "(%d,%d,%d)" % (self.x, self.y, self.z) @@ -63,12 +64,12 @@ def __repr__(self): return self.__str__() def __eq__(self, b): - if type(b) != Vec: + if not isinstance(b, Vec): return False return self.x == b.x and self.y == b.y and self.z == b.z def __ne__(self, b): - if type(b) != Vec: + if not isinstance(b, Vec): return True return self.x != b.x or self.y != b.y or self.z != b.z @@ -76,25 +77,25 @@ def __hash__(self): return self.x + (self.y << 4) + (self.z << 8) def e(self, x): - return Vec(self.x+x, self.y, self.z) + return Vec(self.x + x, self.y, self.z) def w(self, x): - return Vec(self.x-x, self.y, self.z) + return Vec(self.x - x, self.y, self.z) def up(self, y): - return Vec(self.x, self.y-y, self.z) + return Vec(self.x, self.y - y, self.z) def down(self, y): - return Vec(self.x, self.y+y, self.z) + return Vec(self.x, self.y + y, self.z) def n(self, z): - return Vec(self.x, self.y, self.z-z) + return Vec(self.x, self.y, self.z - z) def s(self, z): - return Vec(self.x, self.y, self.z+z) + return Vec(self.x, self.y, self.z + z) def mag2d(self): - return math.sqrt(self.x*self.x + self.z*self.z) + return math.sqrt(self.x * self.x + self.z * self.z) def d(self, d): if (d == 0): @@ -126,7 +127,7 @@ def cw(self): return self.rotate(1) def trans(self, x, y, z): - return Vec(self.x+x, self.y+y, self.z+z) + return Vec(self.x + x, self.y + y, self.z + z) # As of 1.9 pre 4: @@ -143,6 +144,7 @@ def trans(self, x, y, z): class Vec2f(object): + def __init__(self, x, z): self.x = float(x) self.z = float(z) @@ -164,35 +166,36 @@ def rotate(self, r): return Vec2f(self.z, -self.x) def det(self, b): - return self.x*b.z - self.z*b.x + return self.x * b.z - self.z * b.x def mag(self): - return math.sqrt(self.x*self.x + self.z*self.z) + return math.sqrt(self.x * self.x + self.z * self.z) def unit(self): - mag = math.sqrt(self.x*self.x + self.z*self.z) - return Vec2f(self.x/mag, self.z/mag) + mag = math.sqrt(self.x * self.x + self.z * self.z) + return Vec2f(self.x / mag, self.z / mag) def __str__(self): return "(%f,%f)" % (self.x, self.z) def __add__(self, b): - if type(b) == Vec2f: - return Vec2f(self.x+b.x, self.z+b.z) + if isinstance(b, Vec2f): + return Vec2f(self.x + b.x, self.z + b.z) else: - return Vec2f(self.x+b, self.z+b) + return Vec2f(self.x + b, self.z + b) def __sub__(self, b): - if type(b) == Vec2f: - return Vec2f(self.x-b.x, self.z-b.z) + if isinstance(b, Vec2f): + return Vec2f(self.x - b.x, self.z - b.z) else: - return Vec2f(self.x-b, self.z-b) + return Vec2f(self.x - b, self.z - b) def __mul__(self, b): - return Vec2f(self.x*b, self.z*b) + return Vec2f(self.x * b, self.z * b) class Box(object): + def __init__(self, loc, w, h, d): self.loc = loc self.w = w @@ -200,13 +203,13 @@ def __init__(self, loc, w, h, d): self.d = d def x2(self): - return self.loc.x+self.w + return self.loc.x + self.w def y2(self): - return self.loc.y+self.h + return self.loc.y + self.h def z2(self): - return self.loc.z+self.d + return self.loc.z + self.d def containsPoint(self, p): x = p.x - self.loc.x @@ -231,23 +234,23 @@ def __str__(self): self.w, self.h, self.d) def area(loc1, loc2): - return abs((loc1.x-loc2.x)*(loc1.z-loc2.z)) + return abs((loc1.x - loc2.x) * (loc1.z - loc2.z)) def iterate_plane(loc1, loc2): - for x in xrange(min(loc1.x, loc2.x), max(loc1.x, loc2.x)+1): - for y in xrange(min(loc1.y, loc2.y), max(loc1.y, loc2.y)+1): - for z in xrange(min(loc1.z, loc2.z), max(loc1.z, loc2.z)+1): + for x in xrange(min(loc1.x, loc2.x), max(loc1.x, loc2.x) + 1): + for y in xrange(min(loc1.y, loc2.y), max(loc1.y, loc2.y) + 1): + for z in xrange(min(loc1.z, loc2.z), max(loc1.z, loc2.z) + 1): yield Vec(x, y, z) def iterate_cube(*points): for x in xrange(min([p.x for p in points]), - max([p.x for p in points])+1): + max([p.x for p in points]) + 1): for y in xrange(min([p.y for p in points]), - max([p.y for p in points])+1): + max([p.y for p in points]) + 1): for z in xrange(min([p.z for p in points]), - max([p.z for p in points])+1): + max([p.z for p in points]) + 1): yield Vec(x, y, z) @@ -288,27 +291,27 @@ def iterate_points_inside_flat_poly(*poly_points): num_points = len(poly_points) def point_inside(p): - if type(p) == Vec2f: + if isinstance(p, Vec2f): p = Vec(p.x, 0, p.z) for i in xrange(num_points): a = poly_points[i] - b = poly_points[(i+1) % num_points] + b = poly_points[(i + 1) % num_points] - if type(a) == Vec2f: + if isinstance(a, Vec2f): a = Vec(a.x, 0, a.z) - if type(b) == Vec2f: + if isinstance(b, Vec2f): b = Vec(b.x, 0, b.z) - b_to_a = Vec2f.fromVec(b-a) - p_to_a = Vec2f.fromVec(p-a) + b_to_a = Vec2f.fromVec(b - a) + p_to_a = Vec2f.fromVec(p - a) det = b_to_a.det(p_to_a) if det < 0: return False return True - for x in xrange(min_x, max_x+1): - for z in xrange(min_z, max_z+1): + for x in xrange(min_x, max_x + 1): + for z in xrange(min_z, max_z + 1): p = Vec(x, min_y, z) if point_inside(p): yield p @@ -327,17 +330,17 @@ def random_point_inside_flat_poly(*poly_points): def iterate_points_surrounding_box(box): near = box.loc.trans(-1, -1, -1) - far = box.loc.trans(box.w+1, box.h+1, box.d+1) + far = box.loc.trans(box.w + 1, box.h + 1, box.d + 1) return iterate_hollow_cube(near, far) def iterate_spiral(p1, p2, height): p = p1 - box = Box(p1.trans(0, -height, 0), p2.x-p1.x, height, p2.z-p1.z) + box = Box(p1.trans(0, -height, 0), p2.x - p1.x, height, p2.z - p1.z) step = Vec(1, -1, 0) for y in xrange(int(height)): yield p - if (box.containsPoint(p+step) is False): + if (box.containsPoint(p + step) is False): if (step == Vec(1, -1, 0)): step = Vec(0, -1, 1) elif (step == Vec(0, -1, 1)): @@ -384,13 +387,13 @@ def weighted_shuffle(master_list): results.insert(0, item) items.remove([item, weight]) return results - + # Generate a number between min and max. Weighted towards higher numbers. -# (Beta distribution.) -def topheavy_random(min,max): - d = max-min+1 - return int(math.floor(math.sqrt(random.randrange(d*d)))+min) +# (Beta distribution.) +def topheavy_random(min, max): + d = max - min + 1 + return int(math.floor(math.sqrt(random.randrange(d * d))) + min) def str2Vec(string): @@ -399,7 +402,7 @@ def str2Vec(string): def iterate_tube(e0, e1, height): - for y in xrange(height+1): + for y in xrange(height + 1): for p in iterate_ellipse(e0.up(y), e1.up(y)): yield p @@ -414,16 +417,16 @@ def iterate_cylinder(*points): e0 = Vec(xmin, ymax, zmin) e1 = Vec(xmax, ymax, zmax) height = ymax - ymin - for y in xrange(0, height+1): + for y in xrange(0, height + 1): for p in iterate_disc(e0.up(y), e1.up(y)): yield p def iterate_disc(e0, e1): - for (p0, p1) in zip(*[iter(iterate_ellipse(e0, e1))]*2): + for (p0, p1) in zip(*[iter(iterate_ellipse(e0, e1))] * 2): # A little wasteful. We get a few points more than once, # but oh well. - for x in xrange(p0.x, p1.x+1): + for x in xrange(p0.x, p1.x + 1): yield Vec(x, p0.y, p0.z) @@ -478,7 +481,7 @@ def iterate_ellipse(p0, p1): # Bug here... not sure what is going on, but # this is only needed for ellipese with a # horizontal radius of 1 - #while (y0 - y1 < b): + # while (y0 - y1 < b): # y0 += 1 # yield Vec(x0-1, z, y0) # y1 -= 1 @@ -520,8 +523,8 @@ def dumpEnts(world): def spin(c=''): spinner = ['O o o', 'O O o', 'o O O', 'o o O', 'o O O', 'O O o'] if (c == ''): - c = spinner[random.randint(0, len(spinner)-1)] - sys.stdout.write("\r"+str(c)+" \r") + c = spinner[random.randint(0, len(spinner) - 1)] + sys.stdout.write("\r" + str(c) + " \r") sys.stdout.flush() @@ -533,7 +536,7 @@ def findChunkDepth(p, world): depth = world.Height for x in xrange(16): for z in xrange(16): - y = chunk.HeightMap[z, x]-1 + y = chunk.HeightMap[z, x] - 1 while (y > 0 and chunk.Blocks[x, z, y] not in heightmap_solids): y = y - 1 @@ -550,7 +553,7 @@ def findChunkDepths(p, world): max_depth = 0 for x in xrange(16): for z in xrange(16): - y = chunk.HeightMap[z, x]-1 + y = chunk.HeightMap[z, x] - 1 while (y > 0 and chunk.Blocks[x, z, y] not in heightmap_solids): y = y - 1 @@ -587,7 +590,7 @@ def loadDungeonCache(cache_path): mtime = 0 # Try some basic versioning. if not os.path.exists(os.path.join(cache_path, - 'dungeon_scan_version_'+cache_version)): + 'dungeon_scan_version_' + cache_version)): print 'Dungeon cache missing, or is an old verision. Resetting...' return dungeonCache, mtime @@ -639,8 +642,12 @@ def saveDungeonCache(cache_path, dungeonCache): for f in os.listdir(cache_path): if re.search('dungeon_scan_version_.*', f): os.remove(os.path.join(cache_path, f)) - FILE = open(os.path.join(cache_path, - 'dungeon_scan_version_'+cache_version), 'wb') + FILE = open( + os.path.join( + cache_path, + 'dungeon_scan_version_' + + cache_version), + 'wb') cPickle.dump('SSsssss....BOOM', FILE, -1) FILE.close() except Exception as e: @@ -658,7 +665,7 @@ def loadChunkCache(cache_path): # Try some basic versioning. if not os.path.exists(os.path.join(cache_path, - 'chunk_scan_version_'+cache_version)): + 'chunk_scan_version_' + cache_version)): print 'Chunk cache missing, or is an old verision. Resetting...' return chunkCache, chunkMTime @@ -709,7 +716,7 @@ def saveChunkCache(cache_path, chunkCache): if re.search('chunk_scan_version_.*', f): os.remove(os.path.join(cache_path, f)) FILE = open(os.path.join(cache_path, - 'chunk_scan_version_'+cache_version), 'wb') + 'chunk_scan_version_' + cache_version), 'wb') cPickle.dump('SSsssss....BOOM', FILE, -1) FILE.close() except Exception as e: @@ -760,7 +767,7 @@ def encodeDungeonInfo(dungeon, version): tag_tag = nbt.TAG_Compound() item_tag['tag'] = tag_tag tag_tag['title'] = nbt.TAG_String( - 'MCDungeon Data Volume %d' % (slot+1) + 'MCDungeon Data Volume %d' % (slot + 1) ) tag_tag['author'] = nbt.TAG_String('Various') tag_tag['pages'] = nbt.TAG_List() @@ -820,17 +827,40 @@ def decodeDungeonInfo(lib): # Some entity helpers -def get_tile_entity_tags(eid='Chest', Pos=Vec(0,0,0), CustomName='', Lock='', - Levels=0, Primary=0, Secondary=0, BrewTime=0, - OutputSignal=0, Command='', SuccessCount=0, - LastOutput='', Item='', Data=0, BurnTime=0, CookTime=0, - TransferCooldown=0, note=0, Record=0, RecordItem='', - Text1='', Text2='', Text3='', Text4='', SkullType=0, - ExtraType='', Rot=0 - ): +def get_tile_entity_tags( + eid='Chest', + Pos=Vec( + 0, + 0, + 0), + CustomName='', + Lock='', + Levels=0, + Primary=0, + Secondary=0, + BrewTime=0, + OutputSignal=0, + Command='', + SuccessCount=0, + LastOutput='', + Item='', + Data=0, + BurnTime=0, + CookTime=0, + TransferCooldown=0, + note=0, + Record=0, + RecordItem='', + Text1='', + Text2='', + Text3='', + Text4='', + SkullType=0, + ExtraType='', + Rot=0): '''Returns an nbt.TAG_Compound containing tags for tile entities''' # Convert Vec types so we can use either - if type(Pos) is Vec: + if isinstance(Pos, Vec): Pos = (Pos.x, Pos.y, Pos.z) root_tag = nbt.TAG_Compound() @@ -884,7 +914,7 @@ def get_entity_base_tags(eid='Chicken', Pos=Vec(0, 0, 0), CustomName=''): '''Returns an nbt.TAG_Compound containing tags common to all entities''' # Convert Vec types so we can use either - if type(Pos) is Vec: + if isinstance(Pos, Vec): Pos = (Pos.x, Pos.y, Pos.z) root_tag = nbt.TAG_Compound() @@ -971,7 +1001,7 @@ def get_entity_mob_tags(eid='Chicken', Health=None, AttackTime=0, 'Slime', 'LavaSlime' ): - Health = Size*Size + Health = Size * Size elif eid == 'VillagerGolem': Health = 100 elif eid == 'EnderDragon': @@ -1107,7 +1137,7 @@ def get_entity_other_tags(eid='EnderCrystal', Direction='S', ItemInfo=None, calculated. ItemInfo should contain an item object from items.''' # Convert Vec types so we can use either - if type(Pos) is Vec: + if isinstance(Pos, Vec): Pos = (Pos.x, Pos.y, Pos.z) root_tag = get_entity_base_tags(eid=eid, Pos=Pos, **kwargs) @@ -1136,31 +1166,31 @@ def get_entity_other_tags(eid='EnderCrystal', Direction='S', ItemInfo=None, # Now, shift Pos appropriately. First we need the size of the entity. # Default is 1x1, and ItemFrames are 1x1. sizes = { - 'Kebab': (1, 1), - 'Aztec': (1, 1), - 'Alban': (1, 1), - 'Aztec2': (1, 1), - 'Bomb': (1, 1), - 'Plant': (1, 1), - 'Wasteland': (1, 1), - 'Wanderer': (1, 2), - 'Graham': (1, 2), - 'Pool': (2, 1), - 'Courbet': (2, 1), - 'Sunset': (2, 1), - 'Sea': (2, 1), - 'Creebet': (2, 1), - 'Match': (2, 2), - 'Bust': (2, 2), - 'Stage': (2, 2), - 'Void': (2, 2), + 'Kebab': (1, 1), + 'Aztec': (1, 1), + 'Alban': (1, 1), + 'Aztec2': (1, 1), + 'Bomb': (1, 1), + 'Plant': (1, 1), + 'Wasteland': (1, 1), + 'Wanderer': (1, 2), + 'Graham': (1, 2), + 'Pool': (2, 1), + 'Courbet': (2, 1), + 'Sunset': (2, 1), + 'Sea': (2, 1), + 'Creebet': (2, 1), + 'Match': (2, 2), + 'Bust': (2, 2), + 'Stage': (2, 2), + 'Void': (2, 2), 'SkullAndRoses': (2, 2), - 'Wither': (2, 2), - 'Fighters': (4, 2), - 'Skeleton': (4, 3), - 'DonkeyKong': (4, 3), - 'Pointer': (4, 4), - 'PigScene': (4, 4), + 'Wither': (2, 2), + 'Fighters': (4, 2), + 'Skeleton': (4, 3), + 'DonkeyKong': (4, 3), + 'Pointer': (4, 4), + 'PigScene': (4, 4), 'Flaming Skull': (4, 4), } if (eid == 'Painting' and Motive in sizes): @@ -1172,23 +1202,23 @@ def get_entity_other_tags(eid='EnderCrystal', Direction='S', ItemInfo=None, # North face if Direction == 2: - root_tag['Pos'][0].value += float(width)/2.0 - root_tag['Pos'][1].value -= float(height)/2.0 + root_tag['Pos'][0].value += float(width) / 2.0 + root_tag['Pos'][1].value -= float(height) / 2.0 root_tag['Pos'][2].value -= 0.0625 # South face elif Direction == 0: - root_tag['Pos'][0].value += float(width)/2.0 - root_tag['Pos'][1].value -= float(height)/2.0 + root_tag['Pos'][0].value += float(width) / 2.0 + root_tag['Pos'][1].value -= float(height) / 2.0 root_tag['Pos'][2].value += 1.0625 # East face elif Direction == 3: root_tag['Pos'][0].value += 1.0625 - root_tag['Pos'][1].value -= float(height)/2.0 - root_tag['Pos'][2].value += 1 + float(width)/2.0 + root_tag['Pos'][1].value -= float(height) / 2.0 + root_tag['Pos'][2].value += 1 + float(width) / 2.0 # West face elif Direction == 1: - root_tag['Pos'][0].value -= float(width)/2.0 - root_tag['Pos'][1].value -= float(height)/2.0 + root_tag['Pos'][0].value -= float(width) / 2.0 + root_tag['Pos'][1].value -= float(height) / 2.0 root_tag['Pos'][2].value -= 0.0625 # Attach an item to the frame (if any)