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