author | sheepluva |
Sun, 06 Jul 2014 19:20:43 +0200 | |
changeset 10360 | c243b6a8ad9a |
parent 10189 | 875607ce793d |
child 10387 | cb17b79844b5 |
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 |
||
11 |
uses uRandom, uLandOutline, uLandTemplates, uVariables, uFloat, uConsts; |
|
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); |
|
205 |
var tmp_x, tmp_y: LongInt; |
|
206 |
begin |
|
207 |
if x = NTPX then |
|
208 |
begin |
|
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 |
|
218 |
end |
|
219 |
else |
|
220 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
221 |
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
|
222 |
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
|
223 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
224 |
tmp_x := cellsize * 2 div 3; |
10015 | 225 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
226 |
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
|
227 |
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
|
228 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
229 |
tmp_y := cellsize * 2 div 3; |
6490 | 230 |
|
231 |
pa.ar[num_vertices].x := (x-1)*cellsize + tmp_x; |
|
232 |
pa.ar[num_vertices].y := (y-1)*cellsize + tmp_y + off_y; |
|
233 |
end; |
|
234 |
num_vertices := num_vertices + 1; |
|
235 |
end; |
|
236 |
||
237 |
procedure add_edge(x, y: LongInt; dir: direction); |
|
238 |
var i: LongInt; |
|
239 |
begin |
|
240 |
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
|
241 |
begin |
6490 | 242 |
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
|
243 |
end |
6490 | 244 |
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
|
245 |
begin |
6490 | 246 |
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
|
247 |
end |
6490 | 248 |
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
|
249 |
begin |
6490 | 250 |
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
|
251 |
end |
6490 | 252 |
else |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
253 |
begin |
6490 | 254 |
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
|
255 |
end; |
6490 | 256 |
|
257 |
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
|
258 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
259 |
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
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
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
|
264 |
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
|
265 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
266 |
dir := DIR_N; |
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_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
|
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] := 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); |
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_N); |
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_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
|
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+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
|
279 |
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
|
280 |
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
|
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 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
284 |
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
|
285 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
286 |
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
|
287 |
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
|
288 |
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
|
289 |
break; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
290 |
end; |
6490 | 291 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
292 |
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
|
293 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
294 |
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
|
295 |
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
|
296 |
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
|
297 |
break; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
298 |
end; |
6490 | 299 |
end; |
300 |
||
301 |
end; |
|
302 |
||
303 |
procedure GenMaze; |
|
304 |
begin |
|
305 |
case cTemplateFilter of |
|
306 |
0: begin |
|
307 |
cellsize := small_cell_size; |
|
308 |
maze_inverted := false; |
|
309 |
end; |
|
310 |
1: begin |
|
311 |
cellsize := medium_cell_size; |
|
312 |
maze_inverted := false; |
|
313 |
end; |
|
314 |
2: begin |
|
315 |
cellsize := large_cell_size; |
|
316 |
maze_inverted := false; |
|
317 |
end; |
|
318 |
3: begin |
|
319 |
cellsize := small_cell_size; |
|
320 |
maze_inverted := true; |
|
321 |
end; |
|
322 |
4: begin |
|
323 |
cellsize := medium_cell_size; |
|
324 |
maze_inverted := true; |
|
325 |
end; |
|
326 |
5: begin |
|
327 |
cellsize := large_cell_size; |
|
328 |
maze_inverted := true; |
|
329 |
end; |
|
330 |
end; |
|
331 |
||
332 |
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
|
333 |
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
|
334 |
num_cells_x := num_cells_x - 1; //needs to be odd |
10015 | 335 |
|
6490 | 336 |
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
|
337 |
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
|
338 |
num_cells_y := num_cells_y - 1; |
10015 | 339 |
|
6490 | 340 |
num_edges_x := num_cells_x - 1; |
341 |
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
|
342 |
|
6490 | 343 |
seen_cells_x := num_cells_x div 2; |
344 |
seen_cells_y := num_cells_y div 2; |
|
345 |
||
346 |
if maze_inverted then |
|
347 |
num_steps := 3 //TODO randomize, between 3 and 5? |
|
348 |
else |
|
349 |
num_steps := 1; |
|
10015 | 350 |
|
6490 | 351 |
SetLength(step_done, num_steps); |
352 |
SetLength(last_cell, num_steps); |
|
353 |
SetLength(came_from_pos, num_steps); |
|
354 |
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
|
355 |
|
6490 | 356 |
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
|
357 |
|
6490 | 358 |
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
|
359 |
begin |
6490 | 360 |
step_done[current_step] := false; |
361 |
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
|
362 |
end; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
6580
diff
changeset
|
363 |
|
6490 | 364 |
current_step := 0; |
365 |
||
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
6580
diff
changeset
|
366 |
|
6490 | 367 |
SetLength(seen_list, seen_cells_x, seen_cells_y); |
368 |
SetLength(xwalls, seen_cells_x, seen_cells_y - 1); |
|
369 |
SetLength(ywalls, seen_cells_x - 1, seen_cells_y); |
|
370 |
SetLength(x_edge_list, num_edges_x, num_cells_y); |
|
371 |
SetLength(y_edge_list, num_cells_x, num_edges_y); |
|
372 |
SetLength(maze, num_cells_x, num_cells_y); |
|
373 |
||
10015 | 374 |
|
6490 | 375 |
num_vertices := 0; |
376 |
||
377 |
playHeight := num_cells_y * cellsize; |
|
378 |
playWidth := num_cells_x * cellsize; |
|
379 |
off_y := LAND_HEIGHT - playHeight; |
|
380 |
||
381 |
for x := 0 to playWidth do |
|
382 |
for y := 0 to off_y - 1 do |
|
383 |
Land[y, x] := 0; |
|
384 |
||
385 |
for x := 0 to playWidth do |
|
386 |
for y := off_y to LAND_HEIGHT - 1 do |
|
387 |
Land[y, x] := lfBasic; |
|
388 |
||
389 |
for y := 0 to num_cells_y - 1 do |
|
390 |
for x := 0 to num_cells_x - 1 do |
|
391 |
maze[x, y] := false; |
|
392 |
||
393 |
for x := 0 to seen_cells_x - 1 do |
|
394 |
for y := 0 to seen_cells_y - 2 do |
|
395 |
xwalls[x, y] := true; |
|
396 |
||
397 |
for x := 0 to seen_cells_x - 2 do |
|
398 |
for y := 0 to seen_cells_y - 1 do |
|
399 |
ywalls[x, y] := true; |
|
400 |
||
401 |
for x := 0 to seen_cells_x - 1 do |
|
402 |
for y := 0 to seen_cells_y - 1 do |
|
403 |
seen_list[x, y] := -1; |
|
404 |
||
405 |
for x := 0 to num_edges_x - 1 do |
|
406 |
for y := 0 to num_cells_y - 1 do |
|
407 |
x_edge_list[x, y] := false; |
|
408 |
||
409 |
for x := 0 to num_cells_x - 1 do |
|
410 |
for y := 0 to num_edges_y - 1 do |
|
411 |
y_edge_list[x, y] := false; |
|
412 |
||
413 |
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
|
414 |
begin |
6490 | 415 |
x := GetRandom(seen_cells_x - 1) div LongWord(num_steps); |
416 |
last_cell[current_step].x := x + current_step * seen_cells_x div num_steps; |
|
417 |
last_cell[current_step].y := GetRandom(seen_cells_y); |
|
418 |
end; |
|
419 |
||
420 |
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
|
421 |
begin |
6490 | 422 |
done := true; |
423 |
for current_step := 0 to num_steps-1 do |
|
424 |
begin |
|
425 |
if not step_done[current_step] then |
|
426 |
begin |
|
427 |
see_cell; |
|
428 |
done := false; |
|
429 |
end; |
|
430 |
end; |
|
431 |
end; |
|
432 |
||
433 |
for x := 0 to seen_cells_x - 1 do |
|
434 |
for y := 0 to seen_cells_y - 1 do |
|
435 |
if seen_list[x, y] > -1 then |
|
436 |
maze[(x+1)*2-1, (y+1)*2-1] := true; |
|
437 |
||
438 |
for x := 0 to seen_cells_x - 1 do |
|
439 |
for y := 0 to seen_cells_y - 2 do |
|
440 |
if not xwalls[x, y] then |
|
441 |
maze[x*2 + 1, y*2 + 2] := true; |
|
442 |
||
443 |
||
444 |
for x := 0 to seen_cells_x - 2 do |
|
445 |
for y := 0 to seen_cells_y - 1 do |
|
446 |
if not ywalls[x, y] then |
|
447 |
maze[x*2 + 2, y*2 + 1] := true; |
|
448 |
||
449 |
for x := 0 to num_edges_x - 1 do |
|
450 |
for y := 0 to num_cells_y - 1 do |
|
451 |
if maze[x, y] xor maze[x+1, y] then |
|
452 |
x_edge_list[x, y] := true |
|
453 |
else |
|
454 |
x_edge_list[x, y] := false; |
|
455 |
||
456 |
for x := 0 to num_cells_x - 1 do |
|
457 |
for y := 0 to num_edges_y - 1 do |
|
458 |
if maze[x, y] xor maze[x, y+1] then |
|
459 |
y_edge_list[x, y] := true |
|
460 |
else |
|
461 |
y_edge_list[x, y] := false; |
|
462 |
||
463 |
for x := 0 to num_edges_x - 1 do |
|
464 |
for y := 0 to num_cells_y - 1 do |
|
465 |
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
|
466 |
begin |
6490 | 467 |
x_edge_list[x, y] := false; |
468 |
add_vertex(x+1, y+1); |
|
469 |
add_vertex(x+1, y); |
|
470 |
add_edge(x, y-1, DIR_N); |
|
471 |
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
|
472 |
end; |
6490 | 473 |
|
474 |
pa.count := num_vertices; |
|
475 |
||
476 |
RandomizePoints(pa); |
|
477 |
BezierizeEdge(pa, _0_25); |
|
478 |
RandomizePoints(pa); |
|
479 |
BezierizeEdge(pa, _0_25); |
|
480 |
||
481 |
DrawEdge(pa, 0); |
|
482 |
||
483 |
if maze_inverted then |
|
10189 | 484 |
FillLand(1, 1+off_y, 0, 0) |
6490 | 485 |
else |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
486 |
begin |
6490 | 487 |
x := 0; |
488 |
while Land[cellsize div 2 + cellsize + off_y, x] = lfBasic do |
|
489 |
x := x + 1; |
|
490 |
while Land[cellsize div 2 + cellsize + off_y, x] = 0 do |
|
491 |
x := x + 1; |
|
10189 | 492 |
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
|
493 |
end; |
6490 | 494 |
|
495 |
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
|
496 |
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
|
497 |
hasGirders:= false |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
498 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6490
diff
changeset
|
499 |
hasGirders := true; |
6490 | 500 |
leftX:= 0; |
501 |
rightX:= playWidth; |
|
502 |
topY:= off_y; |
|
503 |
hasBorder := false; |
|
504 |
end; |
|
505 |
||
506 |
end. |