author | koda |
Tue, 02 Jun 2015 18:37:40 +0100 | |
changeset 10976 | 56f07b52213a |
parent 10501 | 89e8d6d05dfa |
child 11051 | 3996500fd1e5 |
permissions | -rw-r--r-- |
9009
f8e9d1147dd8
Ehm... fix 'uLandGenMaze.pas(18,19) Fatal: (2003) Syntax error, ")" expected but "identifier A" found' error encountered by one of the users O_o
unc0rr
parents:
6580
diff
changeset
|
1 |
{$INCLUDE "options.inc"} |
f8e9d1147dd8
Ehm... fix 'uLandGenMaze.pas(18,19) Fatal: (2003) Syntax error, ")" expected but "identifier A" found' error encountered by one of the users O_o
unc0rr
parents:
6580
diff
changeset
|
2 |
|
6490 | 3 |
unit uLandGenMaze; |
4 |
||
5 |
interface |
|
6 |
||
7 |
procedure GenMaze; |
|
8 |
||
9 |
implementation |
|
10 |
||
10477
b219c5a2317f
Fiddling with slider, unbreak maze. Next to mess around w/ perlin params.
nemo
parents:
10389
diff
changeset
|
11 |
uses uRandom, uLandOutline, uLandTemplates, uVariables, uFloat, uConsts, uLandGenTemplateBased, uUtils; |
6490 | 12 |
|
13 |
type direction = record x, y: LongInt; end; |
|
14 |
const DIR_N: direction = (x: 0; y: -1); |
|
15 |
DIR_E: direction = (x: 1; y: 0); |
|
16 |
DIR_S: direction = (x: 0; y: 1); |
|
17 |
DIR_W: direction = (x: -1; y: 0); |
|
18 |
||
19 |
operator = (const a, b: direction) c: Boolean; |
|
20 |
begin |
|
21 |
c := (a.x = b.x) and (a.y = b.y); |
|
22 |
end; |
|
23 |
||
24 |
const small_cell_size = 128; |
|
25 |
medium_cell_size = 192; |
|
26 |
large_cell_size = 256; |
|
27 |
braidness = 10; |
|
28 |
||
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
6580
diff
changeset
|
29 |
type |
10015 | 30 |
cell_t = record x,y : LongInt |
31 |
end; |
|
32 |
||
33 |
var x, y : LongInt; |
|
34 |
cellsize : LongInt; //selected by the user in the gui |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
6580
diff
changeset
|
35 |
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 |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
6580
diff
changeset
|
36 |
num_edges_x, num_edges_y : LongInt; //number of resulting edges that need to be vertexificated |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
6580
diff
changeset
|
37 |
num_cells_x, num_cells_y : LongInt; //actual number of cells, depending on cell size |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
6580
diff
changeset
|
38 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
6580
diff
changeset
|
39 |
|
10015 | 40 |
seen_list : array of array of LongInt; |
41 |
xwalls : array of array of Boolean; |
|
42 |
ywalls : array of array of Boolean; |
|
43 |
x_edge_list : array of array of Boolean; |
|
44 |
y_edge_list : array of array of Boolean; |
|
45 |
maze : array of array of Boolean; |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
6580
diff
changeset
|
46 |
|
10015 | 47 |
pa : TPixAr; |
48 |
num_vertices : LongInt; |
|
49 |
off_y : LongInt; |
|
50 |
num_steps : LongInt; |
|
51 |
current_step : LongInt; |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
6580
diff
changeset
|
52 |
|
10015 | 53 |
step_done : array of Boolean; |
54 |
||
55 |
done : Boolean; |
|
56 |
||
57 |
{ last_cell : array 0..3 of record x, y :LongInt ; end; |
|
58 |
came_from : array of array of record x, y: LongInt; end; |
|
59 |
came_from_pos : array of LongInt; |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
6580
diff
changeset
|
60 |
} |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
6580
diff
changeset
|
61 |
last_cell : array of cell_t; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
6580
diff
changeset
|
62 |
came_from : array of array of cell_t; |
6490 | 63 |
came_from_pos: array of LongInt; |
10015 | 64 |
|
65 |
maze_inverted : Boolean; |
|
6490 | 66 |
|
67 |
function when_seen(x: LongInt; y: LongInt): LongInt; |
|
68 |
begin |
|
69 |
if (x < 0) or (x >= seen_cells_x) or (y < 0) or (y >= seen_cells_y) then |
|
70 |
when_seen := current_step |
|
71 |
else |
|
72 |
when_seen := seen_list[x, y]; |
|
73 |
end; |
|
74 |
||
75 |
function is_x_edge(x, y: LongInt): Boolean; |
|
76 |
begin |
|
77 |
if (x < 0) or (x > num_edges_x) or (y < 0) or (y > num_cells_y) then |
|
78 |
is_x_edge := false |
|
79 |
else |
|
80 |
is_x_edge := x_edge_list[x, y]; |
|
81 |
end; |
|
82 |
||
83 |
function is_y_edge(x, y: LongInt): Boolean; |
|
84 |
begin |
|
85 |
if (x < 0) or (x > num_cells_x) or (y < 0) or (y > num_edges_y) then |
|
86 |
is_y_edge := false |
|
87 |
else |
|
88 |
is_y_edge := y_edge_list[x, y]; |
|
89 |
end; |
|
90 |
||
91 |
procedure see_cell; |
|
92 |
var dir: direction; |
|
93 |
tries: LongInt; |
|
94 |
x, y: LongInt; |
|
95 |
found_cell: Boolean; |
|
96 |
next_dir_clockwise: Boolean; |
|
97 |
||
98 |
begin |
|
99 |
x := last_cell[current_step].x; |
|
100 |
y := last_cell[current_step].y; |
|
101 |
seen_list[x, y] := current_step; |
|
102 |
case GetRandom(4) of |
|
103 |
0: dir := DIR_N; |
|
104 |
1: dir := DIR_E; |
|
105 |
2: dir := DIR_S; |
|
106 |
3: dir := DIR_W; |
|
107 |
end; |
|
108 |
tries := 0; |
|
109 |
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
|
110 |
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
|
111 |
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
|
112 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
113 |
next_dir_clockwise := false; |
6490 | 114 |
|
115 |
while (tries < 5) and (not found_cell) do |
|
116 |
begin |
|
117 |
if when_seen(x + dir.x, y + dir.y) = current_step then //we are seeing ourselves, try another direction |
|
118 |
begin |
|
119 |
//we have already seen the target cell, decide if we should remove the wall anyway |
|
120 |
//(or put a wall there if maze_inverted, but we are not doing that right now) |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
6580
diff
changeset
|
121 |
if (not maze_inverted) and (GetRandom(braidness) = 0) then |
6490 | 122 |
//or just warn that inverted+braid+indestructible terrain != good idea |
123 |
begin |
|
124 |
case dir.x of |
|
10015 | 125 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
126 |
-1: |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
127 |
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
|
128 |
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
|
129 |
1: |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
130 |
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
|
131 |
ywalls[x, y] := false; |
6490 | 132 |
end; |
133 |
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
|
134 |
-1: |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
135 |
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
|
136 |
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
|
137 |
1: |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
138 |
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
|
139 |
xwalls[x, y] := false; |
6490 | 140 |
end; |
141 |
end; |
|
142 |
if next_dir_clockwise then |
|
143 |
begin |
|
144 |
if dir = DIR_N then |
|
145 |
dir := DIR_E |
|
146 |
else if dir = DIR_E then |
|
147 |
dir := DIR_S |
|
148 |
else if dir = DIR_S then |
|
149 |
dir := DIR_W |
|
150 |
else |
|
151 |
dir := DIR_N; |
|
152 |
end |
|
153 |
else |
|
154 |
begin |
|
155 |
if dir = DIR_N then |
|
156 |
dir := DIR_W |
|
157 |
else if dir = DIR_E then |
|
158 |
dir := DIR_N |
|
159 |
else if dir = DIR_S then |
|
160 |
dir := DIR_E |
|
161 |
else |
|
162 |
dir := DIR_S; |
|
163 |
end |
|
164 |
end |
|
165 |
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
|
166 |
begin |
6490 | 167 |
case dir.y of |
168 |
-1: xwalls[x, y-1] := false; |
|
169 |
1: xwalls[x, y] := false; |
|
170 |
end; |
|
171 |
case dir.x of |
|
172 |
-1: ywalls[x-1, y] := false; |
|
173 |
1: ywalls[x, y] := false; |
|
174 |
end; |
|
175 |
last_cell[current_step].x := x+dir.x; |
|
176 |
last_cell[current_step].y := y+dir.y; |
|
177 |
came_from_pos[current_step] := came_from_pos[current_step] + 1; |
|
178 |
came_from[current_step, came_from_pos[current_step]].x := x; |
|
179 |
came_from[current_step, came_from_pos[current_step]].y := y; |
|
180 |
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
|
181 |
end |
6490 | 182 |
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
|
183 |
begin |
6490 | 184 |
step_done[current_step] := true; |
185 |
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
|
186 |
end; |
6490 | 187 |
|
188 |
tries := tries + 1; |
|
189 |
end; |
|
190 |
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
|
191 |
begin |
6490 | 192 |
last_cell[current_step].x := came_from[current_step, came_from_pos[current_step]].x; |
193 |
last_cell[current_step].y := came_from[current_step, came_from_pos[current_step]].y; |
|
194 |
came_from_pos[current_step] := came_from_pos[current_step] - 1; |
|
10015 | 195 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
196 |
if came_from_pos[current_step] >= 0 then |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
6580
diff
changeset
|
197 |
see_cell() |
10015 | 198 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
199 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
200 |
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
|
201 |
end; |
6490 | 202 |
end; |
203 |
||
204 |
procedure add_vertex(x, y: LongInt); |
|
10387 | 205 |
var tmp_x, tmp_y, nx, ny: LongInt; |
6490 | 206 |
begin |
10387 | 207 |
if x = NTPX then |
6490 | 208 |
begin |
10387 | 209 |
if pa.ar[num_vertices - 6].x = NTPX then |
210 |
begin |
|
211 |
num_vertices := num_vertices - 6; |
|
212 |
end |
|
213 |
else |
|
214 |
begin |
|
215 |
pa.ar[num_vertices].x := NTPX; |
|
216 |
pa.ar[num_vertices].y := 0; |
|
217 |
end |
|
6490 | 218 |
end |
219 |
else |
|
220 |
begin |
|
10387 | 221 |
if maze_inverted or (x mod 2 = 0) then |
222 |
tmp_x := cellsize |
|
223 |
else |
|
224 |
tmp_x := cellsize * 2 div 3; |
|
225 |
||
226 |
if maze_inverted or (y mod 2 = 0) then |
|
227 |
tmp_y := cellsize |
|
228 |
else |
|
229 |
tmp_y := cellsize * 2 div 3; |
|
10015 | 230 |
|
10387 | 231 |
nx:= (x-1)*cellsize + tmp_x; |
232 |
ny:= (y-1)*cellsize + tmp_y + off_y; |
|
6490 | 233 |
|
10387 | 234 |
if num_vertices > 2 then |
235 |
if ((pa.ar[num_vertices - 2].x = pa.ar[num_vertices - 1].x) and (pa.ar[num_vertices - 1].x = nx)) |
|
236 |
or ((pa.ar[num_vertices - 2].y = pa.ar[num_vertices - 1].y) and (pa.ar[num_vertices - 1].y = ny)) |
|
237 |
then |
|
238 |
dec(num_vertices); |
|
239 |
||
240 |
pa.ar[num_vertices].x := nx; |
|
241 |
pa.ar[num_vertices].y := ny; |
|
242 |
end; |
|
243 |
||
244 |
num_vertices := num_vertices + 1; |
|
6490 | 245 |
end; |
246 |
||
247 |
procedure add_edge(x, y: LongInt; dir: direction); |
|
248 |
var i: LongInt; |
|
249 |
begin |
|
250 |
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
|
251 |
begin |
6490 | 252 |
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
|
253 |
end |
6490 | 254 |
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
|
255 |
begin |
6490 | 256 |
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
|
257 |
end |
6490 | 258 |
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
|
259 |
begin |
6490 | 260 |
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
|
261 |
end |
6490 | 262 |
else |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
263 |
begin |
6490 | 264 |
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
|
265 |
end; |
6490 | 266 |
|
267 |
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
|
268 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
269 |
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
|
270 |
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
|
271 |
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
|
272 |
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
|
273 |
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
|
274 |
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
|
275 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
276 |
dir := DIR_N; |
6490 | 277 |
|
10387 | 278 |
if (dir = DIR_N) and is_x_edge(x, y) then |
279 |
begin |
|
280 |
x_edge_list[x, y] := false; |
|
281 |
add_vertex(x+1, y); |
|
282 |
add_edge(x, y-1, DIR_N); |
|
283 |
break; |
|
284 |
end; |
|
6490 | 285 |
|
10387 | 286 |
if (dir = DIR_E) and is_y_edge(x+1, y) then |
287 |
begin |
|
288 |
y_edge_list[x+1, y] := false; |
|
289 |
add_vertex(x+2, y+1); |
|
290 |
add_edge(x+1, y, DIR_E); |
|
291 |
break; |
|
292 |
end; |
|
6490 | 293 |
|
10387 | 294 |
if (dir = DIR_S) and is_x_edge(x, y+1) then |
295 |
begin |
|
296 |
x_edge_list[x, y+1] := false; |
|
297 |
add_vertex(x+1, y+2); |
|
298 |
add_edge(x, y+1, DIR_S); |
|
299 |
break; |
|
300 |
end; |
|
6490 | 301 |
|
10387 | 302 |
if (dir = DIR_W) and is_y_edge(x, y) then |
303 |
begin |
|
304 |
y_edge_list[x, y] := false; |
|
305 |
add_vertex(x, y+1); |
|
306 |
add_edge(x-1, y, DIR_W); |
|
307 |
break; |
|
308 |
end; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
309 |
end; |
6490 | 310 |
|
311 |
end; |
|
312 |
||
313 |
procedure GenMaze; |
|
10494 | 314 |
var i: Longword; |
6490 | 315 |
begin |
316 |
case cTemplateFilter of |
|
317 |
0: begin |
|
318 |
cellsize := small_cell_size; |
|
319 |
maze_inverted := false; |
|
10477
b219c5a2317f
Fiddling with slider, unbreak maze. Next to mess around w/ perlin params.
nemo
parents:
10389
diff
changeset
|
320 |
minDistance:= max(cFeatureSize*8,32); |
10501 | 321 |
dabDiv:= 150; |
6490 | 322 |
end; |
323 |
1: begin |
|
324 |
cellsize := medium_cell_size; |
|
10477
b219c5a2317f
Fiddling with slider, unbreak maze. Next to mess around w/ perlin params.
nemo
parents:
10389
diff
changeset
|
325 |
minDistance:= max(cFeatureSize*6,20); |
6490 | 326 |
maze_inverted := false; |
10501 | 327 |
dabDiv:= 100; |
6490 | 328 |
end; |
329 |
2: begin |
|
330 |
cellsize := large_cell_size; |
|
10477
b219c5a2317f
Fiddling with slider, unbreak maze. Next to mess around w/ perlin params.
nemo
parents:
10389
diff
changeset
|
331 |
minDistance:= max(cFeatureSize*5,12); |
6490 | 332 |
maze_inverted := false; |
10501 | 333 |
dabDiv:= 90; |
6490 | 334 |
end; |
335 |
3: begin |
|
336 |
cellsize := small_cell_size; |
|
10477
b219c5a2317f
Fiddling with slider, unbreak maze. Next to mess around w/ perlin params.
nemo
parents:
10389
diff
changeset
|
337 |
minDistance:= max(cFeatureSize*8,32); |
6490 | 338 |
maze_inverted := true; |
10501 | 339 |
dabDiv:= 130; |
6490 | 340 |
end; |
341 |
4: begin |
|
342 |
cellsize := medium_cell_size; |
|
10477
b219c5a2317f
Fiddling with slider, unbreak maze. Next to mess around w/ perlin params.
nemo
parents:
10389
diff
changeset
|
343 |
minDistance:= max(cFeatureSize*6,20); |
6490 | 344 |
maze_inverted := true; |
10501 | 345 |
dabDiv:= 100; |
6490 | 346 |
end; |
347 |
5: begin |
|
348 |
cellsize := large_cell_size; |
|
10477
b219c5a2317f
Fiddling with slider, unbreak maze. Next to mess around w/ perlin params.
nemo
parents:
10389
diff
changeset
|
349 |
minDistance:= max(cFeatureSize*5,12); |
6490 | 350 |
maze_inverted := true; |
10501 | 351 |
dabDiv:= 85; |
6490 | 352 |
end; |
353 |
end; |
|
354 |
||
355 |
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
|
356 |
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
|
357 |
num_cells_x := num_cells_x - 1; //needs to be odd |
10015 | 358 |
|
6490 | 359 |
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
|
360 |
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
|
361 |
num_cells_y := num_cells_y - 1; |
10015 | 362 |
|
6490 | 363 |
num_edges_x := num_cells_x - 1; |
364 |
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
|
365 |
|
6490 | 366 |
seen_cells_x := num_cells_x div 2; |
367 |
seen_cells_y := num_cells_y div 2; |
|
368 |
||
369 |
if maze_inverted then |
|
370 |
num_steps := 3 //TODO randomize, between 3 and 5? |
|
371 |
else |
|
372 |
num_steps := 1; |
|
10015 | 373 |
|
6490 | 374 |
SetLength(step_done, num_steps); |
375 |
SetLength(last_cell, num_steps); |
|
376 |
SetLength(came_from_pos, num_steps); |
|
377 |
SetLength(came_from, num_steps, num_cells_x*num_cells_y); |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
6580
diff
changeset
|
378 |
|
6490 | 379 |
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
|
380 |
|
6490 | 381 |
for current_step := 0 to num_steps - 1 do |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
6580
diff
changeset
|
382 |
begin |
6490 | 383 |
step_done[current_step] := false; |
384 |
came_from_pos[current_step] := 0; |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
6580
diff
changeset
|
385 |
end; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
6580
diff
changeset
|
386 |
|
6490 | 387 |
current_step := 0; |
388 |
||
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
6580
diff
changeset
|
389 |
|
6490 | 390 |
SetLength(seen_list, seen_cells_x, seen_cells_y); |
391 |
SetLength(xwalls, seen_cells_x, seen_cells_y - 1); |
|
392 |
SetLength(ywalls, seen_cells_x - 1, seen_cells_y); |
|
393 |
SetLength(x_edge_list, num_edges_x, num_cells_y); |
|
394 |
SetLength(y_edge_list, num_cells_x, num_edges_y); |
|
395 |
SetLength(maze, num_cells_x, num_cells_y); |
|
396 |
||
10015 | 397 |
|
6490 | 398 |
num_vertices := 0; |
399 |
||
400 |
playHeight := num_cells_y * cellsize; |
|
401 |
playWidth := num_cells_x * cellsize; |
|
402 |
off_y := LAND_HEIGHT - playHeight; |
|
403 |
||
404 |
for x := 0 to playWidth do |
|
405 |
for y := 0 to off_y - 1 do |
|
406 |
Land[y, x] := 0; |
|
407 |
||
408 |
for x := 0 to playWidth do |
|
409 |
for y := off_y to LAND_HEIGHT - 1 do |
|
410 |
Land[y, x] := lfBasic; |
|
411 |
||
412 |
for y := 0 to num_cells_y - 1 do |
|
413 |
for x := 0 to num_cells_x - 1 do |
|
414 |
maze[x, y] := false; |
|
415 |
||
416 |
for x := 0 to seen_cells_x - 1 do |
|
417 |
for y := 0 to seen_cells_y - 2 do |
|
418 |
xwalls[x, y] := true; |
|
419 |
||
420 |
for x := 0 to seen_cells_x - 2 do |
|
421 |
for y := 0 to seen_cells_y - 1 do |
|
422 |
ywalls[x, y] := true; |
|
423 |
||
424 |
for x := 0 to seen_cells_x - 1 do |
|
425 |
for y := 0 to seen_cells_y - 1 do |
|
426 |
seen_list[x, y] := -1; |
|
427 |
||
428 |
for x := 0 to num_edges_x - 1 do |
|
429 |
for y := 0 to num_cells_y - 1 do |
|
430 |
x_edge_list[x, y] := false; |
|
431 |
||
432 |
for x := 0 to num_cells_x - 1 do |
|
433 |
for y := 0 to num_edges_y - 1 do |
|
434 |
y_edge_list[x, y] := false; |
|
435 |
||
436 |
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
|
437 |
begin |
6490 | 438 |
x := GetRandom(seen_cells_x - 1) div LongWord(num_steps); |
439 |
last_cell[current_step].x := x + current_step * seen_cells_x div num_steps; |
|
440 |
last_cell[current_step].y := GetRandom(seen_cells_y); |
|
441 |
end; |
|
442 |
||
443 |
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
|
444 |
begin |
6490 | 445 |
done := true; |
446 |
for current_step := 0 to num_steps-1 do |
|
447 |
begin |
|
448 |
if not step_done[current_step] then |
|
449 |
begin |
|
450 |
see_cell; |
|
451 |
done := false; |
|
452 |
end; |
|
453 |
end; |
|
454 |
end; |
|
455 |
||
456 |
for x := 0 to seen_cells_x - 1 do |
|
457 |
for y := 0 to seen_cells_y - 1 do |
|
458 |
if seen_list[x, y] > -1 then |
|
459 |
maze[(x+1)*2-1, (y+1)*2-1] := true; |
|
460 |
||
461 |
for x := 0 to seen_cells_x - 1 do |
|
462 |
for y := 0 to seen_cells_y - 2 do |
|
463 |
if not xwalls[x, y] then |
|
464 |
maze[x*2 + 1, y*2 + 2] := true; |
|
465 |
||
466 |
||
467 |
for x := 0 to seen_cells_x - 2 do |
|
468 |
for y := 0 to seen_cells_y - 1 do |
|
469 |
if not ywalls[x, y] then |
|
470 |
maze[x*2 + 2, y*2 + 1] := true; |
|
471 |
||
472 |
for x := 0 to num_edges_x - 1 do |
|
473 |
for y := 0 to num_cells_y - 1 do |
|
474 |
if maze[x, y] xor maze[x+1, y] then |
|
475 |
x_edge_list[x, y] := true |
|
476 |
else |
|
477 |
x_edge_list[x, y] := false; |
|
478 |
||
479 |
for x := 0 to num_cells_x - 1 do |
|
480 |
for y := 0 to num_edges_y - 1 do |
|
481 |
if maze[x, y] xor maze[x, y+1] then |
|
482 |
y_edge_list[x, y] := true |
|
483 |
else |
|
484 |
y_edge_list[x, y] := false; |
|
485 |
||
486 |
for x := 0 to num_edges_x - 1 do |
|
487 |
for y := 0 to num_cells_y - 1 do |
|
488 |
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
|
489 |
begin |
6490 | 490 |
x_edge_list[x, y] := false; |
491 |
add_vertex(x+1, y+1); |
|
492 |
add_vertex(x+1, y); |
|
493 |
add_edge(x, y-1, DIR_N); |
|
494 |
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
|
495 |
end; |
6490 | 496 |
|
497 |
pa.count := num_vertices; |
|
498 |
||
10387 | 499 |
leftX:= 0; |
500 |
rightX:= playWidth; |
|
501 |
topY:= off_y; |
|
502 |
||
503 |
// fill point |
|
504 |
pa.ar[pa.Count].x:= 1; |
|
505 |
pa.ar[pa.Count].y:= 1 + off_y; |
|
506 |
||
10389 | 507 |
{ |
10387 | 508 |
for i:= 0 to pa.Count - 1 do |
509 |
begin |
|
510 |
system.writeln(pa.ar[i].x, ', ', pa.ar[i].y); |
|
511 |
end; |
|
10389 | 512 |
} |
10387 | 513 |
|
514 |
// divide while it divides |
|
515 |
repeat |
|
516 |
i:= pa.Count; |
|
517 |
DivideEdges(1, pa) |
|
518 |
until i = pa.Count; |
|
519 |
||
520 |
// make it smooth |
|
521 |
BezierizeEdge(pa, _0_2); |
|
6490 | 522 |
|
523 |
DrawEdge(pa, 0); |
|
524 |
||
525 |
if maze_inverted then |
|
10387 | 526 |
FillLand(1, 1 + off_y, 0, 0) |
6490 | 527 |
else |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
528 |
begin |
6490 | 529 |
x := 0; |
530 |
while Land[cellsize div 2 + cellsize + off_y, x] = lfBasic do |
|
531 |
x := x + 1; |
|
532 |
while Land[cellsize div 2 + cellsize + off_y, x] = 0 do |
|
533 |
x := x + 1; |
|
10189 | 534 |
FillLand(x+1, cellsize div 2 + cellsize + off_y, 0, 0); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
535 |
end; |
6490 | 536 |
|
537 |
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
|
538 |
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
|
539 |
hasGirders:= false |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
540 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
541 |
hasGirders := true; |
10387 | 542 |
|
6490 | 543 |
hasBorder := false; |
544 |
end; |
|
545 |
||
546 |
end. |