Skip to content

Commit

Permalink
Code cleanup via autopep8.
Browse files Browse the repository at this point in the history
To everyone merging this commit, I am truly sorry.
I'll keep this kind of thing to a minimum in the future.
  • Loading branch information
orphu committed Apr 24, 2014
1 parent 7c28359 commit 2dcea2d
Show file tree
Hide file tree
Showing 22 changed files with 4,520 additions and 4,201 deletions.
30 changes: 15 additions & 15 deletions cave_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -33,30 +33,30 @@
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()
# Resize
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
67 changes: 36 additions & 31 deletions cave_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@


class new:

def __init__(self, length, width, walls=0.40):
self.__length = length
self.__width = width
Expand All @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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

Expand All @@ -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.
Expand All @@ -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
Expand All @@ -158,37 +159,37 @@ 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.
for pos in self.__exits:
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

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):
Expand All @@ -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
Expand Down Expand Up @@ -232,22 +233,22 @@ 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:
self.__ds.union(root1, root2)

def __join_points(self, pt1):
next_pt = pt1
while 1:
while True:
dir = self.__get_tunnel_dir(pt1, self.__cpt)
move = randrange(0, 3)

Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 '" +\
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions doors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


class Door(object):

def __init__(self):
self.loc = Vec(0, 0, 0)
self.material = None
Expand Down
Loading

0 comments on commit 2dcea2d

Please sign in to comment.