-
Notifications
You must be signed in to change notification settings - Fork 18
/
halls.py
169 lines (139 loc) · 4.45 KB
/
halls.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import sys
import inspect
import materials
import doors
import cfg
from utils import *
from random import *
class Blank(object):
_name = 'blank'
size = 0
def __init__(self, parent, direction, offset):
self.parent = parent
self.direction = direction
self.offset = offset
def render(self):
pass
class Single(Blank):
_name = 'single'
size = 3
def render(self):
drawHall(self)
class Double(Blank):
_name = 'double'
size = 4
def render(self):
drawHall(self)
class Triple(Blank):
_name = 'triple'
size = 5
def render(self):
drawHall(self)
class Four(Blank):
_name = 'four'
size = 6
def render(self):
drawHall(self)
class Ten(Blank):
_name = 'ten'
size = 12
def render(self):
drawHall(self)
def drawHall(hall):
length = hall.parent.hallLength[hall.direction]
start = hall.parent.loc
if (hall.direction == 0):
start += Vec(0, 0, 0)
start = start.e(hall.offset)
stepw = Vec(1, 0, 0)
stepl = Vec(0, 0, 1)
dd1 = 5
dd2 = 4
torch_dat = 3
elif(hall.direction == 1):
start += Vec(hall.parent.parent.room_size - 1, 0, 0)
start = start.s(hall.offset)
stepw = Vec(0, 0, 1)
stepl = Vec(-1, 0, 0)
dd1 = 3
dd2 = 2
torch_dat = 2
elif(hall.direction == 2):
start += Vec(0, 0, hall.parent.parent.room_size - 1)
start = start.e(hall.offset)
stepw = Vec(1, 0, 0)
stepl = Vec(0, 0, -1)
dd1 = 5
dd2 = 4
torch_dat = 4
else:
start += Vec(0, 0, 0)
start = start.s(hall.offset)
stepw = Vec(0, 0, 1)
stepl = Vec(1, 0, 0)
dd1 = 3
dd2 = 2
torch_dat = 1
for j in xrange(length):
pen = start + stepl * j
# First wall
for k in xrange(hall.parent.parent.room_height - 1):
hall.parent.parent.setblock(pen.down(k), materials._wall)
# hallway (ceiling and floor)
for x in xrange(hall.size - 2):
pen += stepw
hall.parent.parent.setblock(pen, materials._ceiling)
for k in xrange(1, hall.parent.parent.room_height - 2):
hall.parent.parent.setblock(pen.down(k), materials.Air)
hall.parent.parent.setblock(
pen.down(hall.parent.parent.room_height - 2),
materials._floor)
# Second wall
pen += stepw
for k in xrange(hall.parent.parent.room_height - 1):
hall.parent.parent.setblock(pen.down(k), materials._wall)
# Possible torches.
pen = start + stepl * length
hall.parent.parent.torches[pen.down(1)] = torch_dat
hall.parent.parent.torches[
pen.down(1) + (stepw * (hall.size - 1))] = torch_dat
# Possible doors
# Only halls of width 1 and 2 can have doors (single and double doors)
if (3 <= hall.size <= 4):
# find a starting position at the end of the hall
pen = start + stepl * (length - 1)
pen = pen.down(1)
door = pen
# Look for adjacent doors. We don't want doors upon doors.
box = Box(door, 0, 0, 0)
abort = False
for x in iterate_points_surrounding_box(box):
if (x in hall.parent.parent.doors):
abort = True
# Create the door
if (abort == False):
# Give this door a direction.
hall.parent.parent.doors[door] = doors.Door()
hall.parent.parent.doors[door].material = hall.parent.parent.doormaterial
hall.parent.parent.doors[door].direction = hall.direction
# place the actual door positions
for x in xrange(hall.size - 2):
pen += stepw
hall.parent.parent.doors[door].doors.append(pen)
# Catalog the halls we know about.
_halls = {}
# List of classes in this module.
for name, obj in inspect.getmembers(sys.modules[__name__], inspect.isclass):
# Only count the ones that are subclasses if of halls.Blank
if issubclass(obj, Blank):
_halls[obj._name] = obj
def new(name, parent, direction, offset):
'''Return a new instance of the hall of a given name. Supply the parent
dungeon object.'''
if name in _halls.keys():
return _halls[name](parent, direction, offset)
return Blank(parent, direction, offset)
def sizeByName(name):
if name in _halls:
return _halls[name].size
return Blank.size