author | nemo |
Sat, 21 Apr 2012 18:11:24 -0400 | |
changeset 6905 | cdfb2bf05bbd |
parent 6580 | 6155187bf599 |
child 8026 | 4a4f21070479 |
child 9009 | f8e9d1147dd8 |
permissions | -rw-r--r-- |
6490 | 1 |
unit uLandGenMaze; |
2 |
||
3 |
interface |
|
4 |
||
5 |
procedure GenMaze; |
|
6 |
||
7 |
implementation |
|
8 |
||
9 |
uses uRandom, uLandOutline, uLandTemplates, uVariables, uFloat, uConsts; |
|
10 |
||
11 |
type direction = record x, y: LongInt; end; |
|
12 |
const DIR_N: direction = (x: 0; y: -1); |
|
13 |
DIR_E: direction = (x: 1; y: 0); |
|
14 |
DIR_S: direction = (x: 0; y: 1); |
|
15 |
DIR_W: direction = (x: -1; y: 0); |
|
16 |
||
17 |
||
18 |
operator = (const a, b: direction) c: Boolean; |
|
19 |
begin |
|
20 |
c := (a.x = b.x) and (a.y = b.y); |
|
21 |
end; |
|
22 |
||
23 |
const small_cell_size = 128; |
|
24 |
medium_cell_size = 192; |
|
25 |
large_cell_size = 256; |
|
26 |
braidness = 10; |
|
27 |
||
28 |
var x, y: LongInt; |
|
29 |
cellsize: LongInt; //selected by the user in the gui |
|
30 |
seen_cells_x, seen_cells_y: LongInt; //number of cells that can be visited by the generator, that is every second cell in x and y direction. the cells between there are walls that will be removed when we move from one cell to another |
|
31 |
num_edges_x, num_edges_y: LongInt; //number of resulting edges that need to be vertexificated |
|
32 |
num_cells_x, num_cells_y: LongInt; //actual number of cells, depending on cell size |
|
33 |
seen_list: array of array of LongInt; |
|
34 |
xwalls: array of array of Boolean; |
|
35 |
ywalls: array of array of Boolean; |
|
36 |
x_edge_list: array of array of Boolean; |
|
37 |
y_edge_list: array of array of Boolean; |
|
38 |
maze: array of array of Boolean; |
|
39 |
pa: TPixAr; |
|
40 |
num_vertices: LongInt; |
|
41 |
off_y: LongInt; |
|
42 |
num_steps: LongInt; |
|
43 |
current_step: LongInt; |
|
44 |
step_done: array of Boolean; |
|
45 |
done: Boolean; |
|
46 |
last_cell: array of record x, y: LongInt; end; |
|
47 |
came_from: array of array of record x, y: LongInt; end; |
|
48 |
came_from_pos: array of LongInt; |
|
49 |
maze_inverted: Boolean; |
|
50 |
||
51 |
function when_seen(x: LongInt; y: LongInt): LongInt; |
|
52 |
begin |
|
53 |
if (x < 0) or (x >= seen_cells_x) or (y < 0) or (y >= seen_cells_y) then |
|
54 |
when_seen := current_step |
|
55 |
else |
|
56 |
when_seen := seen_list[x, y]; |
|
57 |
end; |
|
58 |
||
59 |
function is_x_edge(x, y: LongInt): Boolean; |
|
60 |
begin |
|
61 |
if (x < 0) or (x > num_edges_x) or (y < 0) or (y > num_cells_y) then |
|
62 |
is_x_edge := false |
|
63 |
else |
|
64 |
is_x_edge := x_edge_list[x, y]; |
|
65 |
end; |
|
66 |
||
67 |
function is_y_edge(x, y: LongInt): Boolean; |
|
68 |
begin |
|
69 |
if (x < 0) or (x > num_cells_x) or (y < 0) or (y > num_edges_y) then |
|
70 |
is_y_edge := false |
|
71 |
else |
|
72 |
is_y_edge := y_edge_list[x, y]; |
|
73 |
end; |
|
74 |
||
75 |
procedure see_cell; |
|
76 |
var dir: direction; |
|
77 |
tries: LongInt; |
|
78 |
x, y: LongInt; |
|
79 |
found_cell: Boolean; |
|
80 |
next_dir_clockwise: Boolean; |
|
81 |
||
82 |
begin |
|
83 |
x := last_cell[current_step].x; |
|
84 |
y := last_cell[current_step].y; |
|
85 |
seen_list[x, y] := current_step; |
|
86 |
case GetRandom(4) of |
|
87 |
0: dir := DIR_N; |
|
88 |
1: dir := DIR_E; |
|
89 |
2: dir := DIR_S; |
|
90 |
3: dir := DIR_W; |
|
91 |
end; |
|
92 |
tries := 0; |
|
93 |
found_cell := false; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
94 |
if getrandom(2) = 1 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
95 |
next_dir_clockwise := true |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
96 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
97 |
next_dir_clockwise := false; |
6490 | 98 |
|
99 |
while (tries < 5) and (not found_cell) do |
|
100 |
begin |
|
101 |
if when_seen(x + dir.x, y + dir.y) = current_step then //we are seeing ourselves, try another direction |
|
102 |
begin |
|
103 |
//we have already seen the target cell, decide if we should remove the wall anyway |
|
104 |
//(or put a wall there if maze_inverted, but we are not doing that right now) |
|
105 |
if not maze_inverted and (GetRandom(braidness) = 0) then |
|
106 |
//or just warn that inverted+braid+indestructible terrain != good idea |
|
107 |
begin |
|
108 |
case dir.x of |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
109 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
110 |
-1: |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
111 |
if x > 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
112 |
ywalls[x-1, y] := false; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
113 |
1: |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
114 |
if x < seen_cells_x - 1 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
115 |
ywalls[x, y] := false; |
6490 | 116 |
end; |
117 |
case dir.y of |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
118 |
-1: |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
119 |
if y > 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
120 |
xwalls[x, y-1] := false; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
121 |
1: |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
122 |
if y < seen_cells_y - 1 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
123 |
xwalls[x, y] := false; |
6490 | 124 |
end; |
125 |
end; |
|
126 |
if next_dir_clockwise then |
|
127 |
begin |
|
128 |
if dir = DIR_N then |
|
129 |
dir := DIR_E |
|
130 |
else if dir = DIR_E then |
|
131 |
dir := DIR_S |
|
132 |
else if dir = DIR_S then |
|
133 |
dir := DIR_W |
|
134 |
else |
|
135 |
dir := DIR_N; |
|
136 |
end |
|
137 |
else |
|
138 |
begin |
|
139 |
if dir = DIR_N then |
|
140 |
dir := DIR_W |
|
141 |
else if dir = DIR_E then |
|
142 |
dir := DIR_N |
|
143 |
else if dir = DIR_S then |
|
144 |
dir := DIR_E |
|
145 |
else |
|
146 |
dir := DIR_S; |
|
147 |
end |
|
148 |
end |
|
149 |
else if when_seen(x + dir.x, y + dir.y) = -1 then //cell was not seen yet, go there |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
150 |
begin |
6490 | 151 |
case dir.y of |
152 |
-1: xwalls[x, y-1] := false; |
|
153 |
1: xwalls[x, y] := false; |
|
154 |
end; |
|
155 |
case dir.x of |
|
156 |
-1: ywalls[x-1, y] := false; |
|
157 |
1: ywalls[x, y] := false; |
|
158 |
end; |
|
159 |
last_cell[current_step].x := x+dir.x; |
|
160 |
last_cell[current_step].y := y+dir.y; |
|
161 |
came_from_pos[current_step] := came_from_pos[current_step] + 1; |
|
162 |
came_from[current_step, came_from_pos[current_step]].x := x; |
|
163 |
came_from[current_step, came_from_pos[current_step]].y := y; |
|
164 |
found_cell := true; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
165 |
end |
6490 | 166 |
else //we are seeing someone else, quit |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
167 |
begin |
6490 | 168 |
step_done[current_step] := true; |
169 |
found_cell := true; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
170 |
end; |
6490 | 171 |
|
172 |
tries := tries + 1; |
|
173 |
end; |
|
174 |
if not found_cell then |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
175 |
begin |
6490 | 176 |
last_cell[current_step].x := came_from[current_step, came_from_pos[current_step]].x; |
177 |
last_cell[current_step].y := came_from[current_step, came_from_pos[current_step]].y; |
|
178 |
came_from_pos[current_step] := came_from_pos[current_step] - 1; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
179 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
180 |
if came_from_pos[current_step] >= 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
181 |
see_cell |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
182 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
183 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
184 |
step_done[current_step] := true; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
185 |
end; |
6490 | 186 |
end; |
187 |
||
188 |
procedure add_vertex(x, y: LongInt); |
|
189 |
var tmp_x, tmp_y: LongInt; |
|
190 |
begin |
|
191 |
if x = NTPX then |
|
192 |
begin |
|
193 |
if pa.ar[num_vertices - 6].x = NTPX then |
|
194 |
begin |
|
195 |
num_vertices := num_vertices - 6; |
|
196 |
end |
|
197 |
else |
|
198 |
begin |
|
199 |
pa.ar[num_vertices].x := NTPX; |
|
200 |
pa.ar[num_vertices].y := 0; |
|
201 |
end |
|
202 |
end |
|
203 |
else |
|
204 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
205 |
if maze_inverted or (x mod 2 = 0) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
206 |
tmp_x := cellsize |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
207 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
208 |
tmp_x := cellsize * 2 div 3; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
209 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
210 |
if maze_inverted or (y mod 2 = 0) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
211 |
tmp_y := cellsize |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
212 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
213 |
tmp_y := cellsize * 2 div 3; |
6490 | 214 |
|
215 |
pa.ar[num_vertices].x := (x-1)*cellsize + tmp_x; |
|
216 |
pa.ar[num_vertices].y := (y-1)*cellsize + tmp_y + off_y; |
|
217 |
end; |
|
218 |
num_vertices := num_vertices + 1; |
|
219 |
end; |
|
220 |
||
221 |
procedure add_edge(x, y: LongInt; dir: direction); |
|
222 |
var i: LongInt; |
|
223 |
begin |
|
224 |
if dir = DIR_N then |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
225 |
begin |
6490 | 226 |
dir := DIR_W |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
227 |
end |
6490 | 228 |
else if dir = DIR_E then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
229 |
begin |
6490 | 230 |
dir := DIR_N |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
231 |
end |
6490 | 232 |
else if dir = DIR_S then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
233 |
begin |
6490 | 234 |
dir := DIR_E |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
235 |
end |
6490 | 236 |
else |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
237 |
begin |
6490 | 238 |
dir := DIR_S; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
239 |
end; |
6490 | 240 |
|
241 |
for i := 0 to 3 do |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
242 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
243 |
if dir = DIR_N then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
244 |
dir := DIR_E |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
245 |
else if dir = DIR_E then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
246 |
dir := DIR_S |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
247 |
else if dir = DIR_S then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
248 |
dir := DIR_W |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
249 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
250 |
dir := DIR_N; |
6490 | 251 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
252 |
if (dir = DIR_N) and is_x_edge(x, y) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
253 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
254 |
x_edge_list[x, y] := false; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
255 |
add_vertex(x+1, y); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
256 |
add_edge(x, y-1, DIR_N); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
257 |
break; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
258 |
end; |
6490 | 259 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
260 |
if (dir = DIR_E) and is_y_edge(x+1, y) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
261 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
262 |
y_edge_list[x+1, y] := false; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
263 |
add_vertex(x+2, y+1); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
264 |
add_edge(x+1, y, DIR_E); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
265 |
break; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
266 |
end; |
6490 | 267 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
268 |
if (dir = DIR_S) and is_x_edge(x, y+1) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
269 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
270 |
x_edge_list[x, y+1] := false; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
271 |
add_vertex(x+1, y+2); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
272 |
add_edge(x, y+1, DIR_S); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
273 |
break; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
274 |
end; |
6490 | 275 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
276 |
if (dir = DIR_W) and is_y_edge(x, y) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
277 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
278 |
y_edge_list[x, y] := false; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
279 |
add_vertex(x, y+1); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
280 |
add_edge(x-1, y, DIR_W); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
281 |
break; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
282 |
end; |
6490 | 283 |
end; |
284 |
||
285 |
end; |
|
286 |
||
287 |
procedure GenMaze; |
|
288 |
begin |
|
289 |
case cTemplateFilter of |
|
290 |
0: begin |
|
291 |
cellsize := small_cell_size; |
|
292 |
maze_inverted := false; |
|
293 |
end; |
|
294 |
1: begin |
|
295 |
cellsize := medium_cell_size; |
|
296 |
maze_inverted := false; |
|
297 |
end; |
|
298 |
2: begin |
|
299 |
cellsize := large_cell_size; |
|
300 |
maze_inverted := false; |
|
301 |
end; |
|
302 |
3: begin |
|
303 |
cellsize := small_cell_size; |
|
304 |
maze_inverted := true; |
|
305 |
end; |
|
306 |
4: begin |
|
307 |
cellsize := medium_cell_size; |
|
308 |
maze_inverted := true; |
|
309 |
end; |
|
310 |
5: begin |
|
311 |
cellsize := large_cell_size; |
|
312 |
maze_inverted := true; |
|
313 |
end; |
|
314 |
end; |
|
315 |
||
316 |
num_cells_x := LAND_WIDTH div cellsize; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
317 |
if not odd(num_cells_x) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
318 |
num_cells_x := num_cells_x - 1; //needs to be odd |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
319 |
|
6490 | 320 |
num_cells_y := LAND_HEIGHT div cellsize; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
321 |
if not odd(num_cells_y) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
322 |
num_cells_y := num_cells_y - 1; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
323 |
|
6490 | 324 |
num_edges_x := num_cells_x - 1; |
325 |
num_edges_y := num_cells_y - 1; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
326 |
|
6490 | 327 |
seen_cells_x := num_cells_x div 2; |
328 |
seen_cells_y := num_cells_y div 2; |
|
329 |
||
330 |
if maze_inverted then |
|
331 |
num_steps := 3 //TODO randomize, between 3 and 5? |
|
332 |
else |
|
333 |
num_steps := 1; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
334 |
|
6490 | 335 |
SetLength(step_done, num_steps); |
336 |
SetLength(last_cell, num_steps); |
|
337 |
SetLength(came_from_pos, num_steps); |
|
338 |
SetLength(came_from, num_steps, num_cells_x*num_cells_y); |
|
339 |
done := false; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
340 |
|
6490 | 341 |
for current_step := 0 to num_steps - 1 do |
342 |
step_done[current_step] := false; |
|
343 |
came_from_pos[current_step] := 0; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
344 |
|
6490 | 345 |
current_step := 0; |
346 |
||
347 |
SetLength(seen_list, seen_cells_x, seen_cells_y); |
|
348 |
SetLength(xwalls, seen_cells_x, seen_cells_y - 1); |
|
349 |
SetLength(ywalls, seen_cells_x - 1, seen_cells_y); |
|
350 |
SetLength(x_edge_list, num_edges_x, num_cells_y); |
|
351 |
SetLength(y_edge_list, num_cells_x, num_edges_y); |
|
352 |
SetLength(maze, num_cells_x, num_cells_y); |
|
353 |
||
354 |
num_vertices := 0; |
|
355 |
||
356 |
playHeight := num_cells_y * cellsize; |
|
357 |
playWidth := num_cells_x * cellsize; |
|
358 |
off_y := LAND_HEIGHT - playHeight; |
|
359 |
||
360 |
for x := 0 to playWidth do |
|
361 |
for y := 0 to off_y - 1 do |
|
362 |
Land[y, x] := 0; |
|
363 |
||
364 |
for x := 0 to playWidth do |
|
365 |
for y := off_y to LAND_HEIGHT - 1 do |
|
366 |
Land[y, x] := lfBasic; |
|
367 |
||
368 |
for y := 0 to num_cells_y - 1 do |
|
369 |
for x := 0 to num_cells_x - 1 do |
|
370 |
maze[x, y] := false; |
|
371 |
||
372 |
for x := 0 to seen_cells_x - 1 do |
|
373 |
for y := 0 to seen_cells_y - 2 do |
|
374 |
xwalls[x, y] := true; |
|
375 |
||
376 |
for x := 0 to seen_cells_x - 2 do |
|
377 |
for y := 0 to seen_cells_y - 1 do |
|
378 |
ywalls[x, y] := true; |
|
379 |
||
380 |
for x := 0 to seen_cells_x - 1 do |
|
381 |
for y := 0 to seen_cells_y - 1 do |
|
382 |
seen_list[x, y] := -1; |
|
383 |
||
384 |
for x := 0 to num_edges_x - 1 do |
|
385 |
for y := 0 to num_cells_y - 1 do |
|
386 |
x_edge_list[x, y] := false; |
|
387 |
||
388 |
for x := 0 to num_cells_x - 1 do |
|
389 |
for y := 0 to num_edges_y - 1 do |
|
390 |
y_edge_list[x, y] := false; |
|
391 |
||
392 |
for current_step := 0 to num_steps-1 do |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
393 |
begin |
6490 | 394 |
x := GetRandom(seen_cells_x - 1) div LongWord(num_steps); |
395 |
last_cell[current_step].x := x + current_step * seen_cells_x div num_steps; |
|
396 |
last_cell[current_step].y := GetRandom(seen_cells_y); |
|
397 |
end; |
|
398 |
||
399 |
while not done do |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
400 |
begin |
6490 | 401 |
done := true; |
402 |
for current_step := 0 to num_steps-1 do |
|
403 |
begin |
|
404 |
if not step_done[current_step] then |
|
405 |
begin |
|
406 |
see_cell; |
|
407 |
done := false; |
|
408 |
end; |
|
409 |
end; |
|
410 |
end; |
|
411 |
||
412 |
for x := 0 to seen_cells_x - 1 do |
|
413 |
for y := 0 to seen_cells_y - 1 do |
|
414 |
if seen_list[x, y] > -1 then |
|
415 |
maze[(x+1)*2-1, (y+1)*2-1] := true; |
|
416 |
||
417 |
for x := 0 to seen_cells_x - 1 do |
|
418 |
for y := 0 to seen_cells_y - 2 do |
|
419 |
if not xwalls[x, y] then |
|
420 |
maze[x*2 + 1, y*2 + 2] := true; |
|
421 |
||
422 |
||
423 |
for x := 0 to seen_cells_x - 2 do |
|
424 |
for y := 0 to seen_cells_y - 1 do |
|
425 |
if not ywalls[x, y] then |
|
426 |
maze[x*2 + 2, y*2 + 1] := true; |
|
427 |
||
428 |
for x := 0 to num_edges_x - 1 do |
|
429 |
for y := 0 to num_cells_y - 1 do |
|
430 |
if maze[x, y] xor maze[x+1, y] then |
|
431 |
x_edge_list[x, y] := true |
|
432 |
else |
|
433 |
x_edge_list[x, y] := false; |
|
434 |
||
435 |
for x := 0 to num_cells_x - 1 do |
|
436 |
for y := 0 to num_edges_y - 1 do |
|
437 |
if maze[x, y] xor maze[x, y+1] then |
|
438 |
y_edge_list[x, y] := true |
|
439 |
else |
|
440 |
y_edge_list[x, y] := false; |
|
441 |
||
442 |
for x := 0 to num_edges_x - 1 do |
|
443 |
for y := 0 to num_cells_y - 1 do |
|
444 |
if x_edge_list[x, y] then |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
445 |
begin |
6490 | 446 |
x_edge_list[x, y] := false; |
447 |
add_vertex(x+1, y+1); |
|
448 |
add_vertex(x+1, y); |
|
449 |
add_edge(x, y-1, DIR_N); |
|
450 |
add_vertex(NTPX, 0); |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
451 |
end; |
6490 | 452 |
|
453 |
pa.count := num_vertices; |
|
454 |
||
455 |
RandomizePoints(pa); |
|
456 |
BezierizeEdge(pa, _0_25); |
|
457 |
RandomizePoints(pa); |
|
458 |
BezierizeEdge(pa, _0_25); |
|
459 |
||
460 |
DrawEdge(pa, 0); |
|
461 |
||
462 |
if maze_inverted then |
|
463 |
FillLand(1, 1+off_y) |
|
464 |
else |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
465 |
begin |
6490 | 466 |
x := 0; |
467 |
while Land[cellsize div 2 + cellsize + off_y, x] = lfBasic do |
|
468 |
x := x + 1; |
|
469 |
while Land[cellsize div 2 + cellsize + off_y, x] = 0 do |
|
470 |
x := x + 1; |
|
471 |
FillLand(x+1, cellsize div 2 + cellsize + off_y); |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
472 |
end; |
6490 | 473 |
|
474 |
MaxHedgehogs:= 32; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
475 |
if (GameFlags and gfDisableGirders) <> 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
476 |
hasGirders:= false |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
477 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
478 |
hasGirders := true; |
6490 | 479 |
leftX:= 0; |
480 |
rightX:= playWidth; |
|
481 |
topY:= off_y; |
|
482 |
hasBorder := false; |
|
483 |
end; |
|
484 |
||
485 |
end. |