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