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