Class: RDGC::Maker::DivideTempBlock
Constant Summary
RDGC::Map::TileType::OUT, RDGC::Map::TileType::ROAD, RDGC::Map::TileType::ROOM, RDGC::Map::TileType::WALL
Instance Attribute Summary collapse
#bottom, #left, #right, #top
Instance Method Summary
collapse
Methods inherited from TempBlock
#create_pure_block, create_whole_block
#add_road, #cling_direction_to, #cling_to_bottom?, #cling_to_left?, #cling_to_right?, #cling_to_top?, create, #create_cross_point, #create_room, #cross_point, #empty?, #fill, #fill_roads, #fill_room, #has_cross_point?, #has_road?, #has_room?, #remove_all, #remove_cross_point, #remove_roads, #remove_room, #roads, #room, #room=
#blind_level, #blind_level_blind?, #blind_level_dark?, #blind_level_none?, #blind_level_open?, #coordinates, create, #each, #each_tile, #each_x, #each_y, #fill, #fill_tile, #has_xy?, #height, #random_point, #set_blind, #set_tile, #tile, #width
Instance Attribute Details
#depth ⇒ Object
9
10
11
12
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 9
def depth
@depth ||= 0
@depth
end
|
#divide_direction ⇒ Object
Returns the value of attribute divide_direction.
6
7
8
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 6
def divide_direction
@divide_direction
end
|
Instance Method Details
#add_remain_cling_blocks(b) ⇒ Object
142
143
144
145
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 142
def add_remain_cling_blocks(b)
return if b.has_room?
remain_cling_blocks << b
end
|
#create_road_for_adjoin_x(x1, x2) ⇒ Object
257
258
259
260
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 257
def create_road_for_adjoin_x(x1, x2)
p_s, p_e = [x1, x2].sort
add_road(Map::Road.create(bottom, bottom, p_s, p_e))
end
|
#create_road_for_adjoin_y(y1, y2) ⇒ Object
262
263
264
265
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 262
def create_road_for_adjoin_y(y1, y2)
p_s, p_e = [y1, y2].sort
add_road(Map::Road.create(p_s, p_e, right, right))
end
|
#create_road_for_direction(d) ⇒ Object
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 188
def create_road_for_direction(d)
val = road_point[d]
return val if val
case
when has_room?
val = create_road_from_room(d)
when has_cross_point?
val = create_road_from_point(d)
end
val
end
|
#create_road_from_point(d) ⇒ Object
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 232
def create_road_from_point(d)
return unless has_cross_point?
return if road_point[d]
x, y = cross_point
case d
when :top
set_road_point(:top, x)
add_road(Map::Road.create(top, y, x, x))
x
when :bottom
set_road_point(:bottom, x)
add_road(Map::Road.create(y, bottom, x, x))
x
when :left
set_road_point(:left, y)
add_road(Map::Road.create(y, y, left, x))
y
when :right
set_road_point(:right, y)
add_road(Map::Road.create(y, y, x, right))
y
end
end
|
#create_road_from_room(d) ⇒ Object
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 204
def create_road_from_room(d)
return unless has_room?
return if road_point[d]
case d
when :top
x = range_rand(room.left, room.right)
set_road_point(:top, x)
add_road(Map::Road.create(top, room.top-1, x, x))
x
when :bottom
x = range_rand(room.left, room.right)
set_road_point(:bottom, x)
add_road(Map::Road.create(room.bottom+1, bottom, x, x))
x
when :left
y = range_rand(room.top, room.bottom)
set_road_point(:left, y)
add_road(Map::Road.create(y, y, left, room.left-1))
y
when :right
y = range_rand(room.top, room.bottom)
set_road_point(:right, y)
add_road(Map::Road.create(y, y, room.right+1, right))
y
end
end
|
#create_road_to(b) ⇒ Object
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 161
def create_road_to(b)
return unless (has_room? || has_cross_point?)
return unless (b.has_room? || b.has_cross_point?)
case cling_direction_to(b)
when :top
my_x = create_road_for_direction(:top)
b_x = b.create_road_for_direction(:bottom)
b.create_road_for_adjoin_x(my_x, b_x)
when :bottom
my_x = create_road_for_direction(:bottom)
b_x = b.create_road_for_direction(:top)
create_road_for_adjoin_x(my_x, b_x)
when :left
my_y = create_road_for_direction(:left)
b_y = b.create_road_for_direction(:right)
b.create_road_for_adjoin_y(my_y, b_y)
when :right
my_y = create_road_for_direction(:right)
b_y = b.create_road_for_direction(:left)
create_road_for_adjoin_y(my_y, b_y)
end
end
|
#dead_end? ⇒ Boolean
151
152
153
154
155
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 151
def dead_end?
return false if has_room?
return false unless has_cross_point?
road_point.keys.size == 1 ? true : false
end
|
#dividable(f = true) ⇒ Object
45
46
47
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 45
def dividable(f = true)
@dividable = f
end
|
#dividable? ⇒ Boolean
49
50
51
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 49
def dividable?
@dividable
end
|
#dividable_size? ⇒ Boolean
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 34
def dividable_size?
case self.divide_direction
when :horizontal
height >= min_divide_size ? true : false
when :vertical
width >= min_divide_size ? true : false
else
false
end
end
|
#divide ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 62
def divide
self.divide_direction ||= select_rand({:horizontal => 1, :vertical => 1})
return unless dividable_size?
case self.divide_direction
when :horizontal
divide_horizontal
when :vertical
divide_vertical
end
end
|
#divide_horizontal ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 74
def divide_horizontal
return unless dividable_size?
point = divide_point(height)
upper = DivideTempBlock.create(top, top + point - 1, left, right)
lower = DivideTempBlock.create(top + point, bottom, left, right)
set_next_value(upper, lower)
[upper, lower].shuffle
end
|
#divide_point(val) ⇒ Object
58
59
60
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 58
def divide_point(val)
range_rand(min_size, val - min_divide_size)
end
|
#divide_vertical ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 87
def divide_vertical
return unless dividable_size?
point = divide_point(width)
lefter = DivideTempBlock.create(top, bottom, left, left + point - 1)
righter = DivideTempBlock.create(top, bottom, left + point, right)
set_next_value(lefter, righter)
[lefter, righter].shuffle
end
|
#has_remain_cling_blocks? ⇒ Boolean
147
148
149
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 147
def has_remain_cling_blocks?
remain_cling_blocks.empty? ? false : true
end
|
#min_divide_size ⇒ Object
19
20
21
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 19
def min_divide_size
min_size * 2
end
|
#opposite_direction ⇒ Object
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 23
def opposite_direction
case self.divide_direction
when :horizontal
:vertical
when :vertical
:horizontal
else
nil
end
end
|
#remain_cling_blocks ⇒ Object
137
138
139
140
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 137
def remain_cling_blocks
@remain_cling_blocks ||= []
@remain_cling_blocks
end
|
#remain_direction ⇒ Object
157
158
159
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 157
def remain_direction
[:top, :bottom, :left, :right] - road_point.keys
end
|
#road_created(f = true) ⇒ Object
for road —————————————————-
118
119
120
121
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 118
def road_created(f = true)
@road_created = f
self
end
|
#road_created? ⇒ Boolean
123
124
125
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 123
def road_created?
@road_created
end
|
#road_point ⇒ Object
132
133
134
135
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 132
def road_point
@road_point ||= {}
@road_point
end
|
#set_dividable ⇒ Object
53
54
55
56
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 53
def set_dividable
return unless dividable_size?
dividable
end
|
#set_next_value(b1, b2) ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 100
def set_next_value(b1, b2)
[b1, b2].each do |b|
b.depth = self.depth + 1
b.divide_direction = opposite_direction
b.min_size = min_size
end
if bool_rand
b1.set_dividable
b2.set_dividable if bool_rand
else
b2.set_dividable
b1.set_dividable if bool_rand
end
end
|
#set_road_point(direction, point) ⇒ Object
127
128
129
130
|
# File 'lib/rdgc/maker/divide_temp_block.rb', line 127
def set_road_point(direction, point)
@road_point ||= {}
@road_point[direction] = point
end
|