author | unc0rr |
Mon, 09 Jan 2006 20:29:14 +0000 | |
changeset 41 | 5d7a505875cd |
parent 37 | 2b7f2a43b999 |
child 51 | b6e3ae05857f |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* Distributed under the terms of the BSD-modified licence: |
|
6 |
* |
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 |
* of this software and associated documentation files (the "Software"), to deal |
|
9 |
* with the Software without restriction, including without limitation the |
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is |
|
12 |
* furnished to do so, subject to the following conditions: |
|
13 |
* |
|
14 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
15 |
* this list of conditions and the following disclaimer. |
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
17 |
* this list of conditions and the following disclaimer in the documentation |
|
18 |
* and/or other materials provided with the distribution. |
|
19 |
* 3. The name of the author may not be used to endorse or promote products |
|
20 |
* derived from this software without specific prior written permission. |
|
21 |
* |
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|
23 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
24 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|
25 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|
28 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 |
*) |
|
33 |
||
34 |
unit uLand; |
|
35 |
interface |
|
36 |
uses SDLh; |
|
37 |
{$include options.inc} |
|
38 |
type TLandArray = packed array[0..1023, 0..2047] of LongWord; |
|
39 |
||
40 |
var Land: TLandArray; |
|
41 |
LandSurface: PSDL_Surface; |
|
42 |
||
43 |
procedure AddHHPoint(_x, _y: integer); |
|
44 |
procedure GetHHPoint(out _x, _y: integer); |
|
45 |
procedure RandomizeHHPoints; |
|
37 | 46 |
procedure GenMap; |
4 | 47 |
|
48 |
implementation |
|
37 | 49 |
uses uConsole, uStore, uMisc, uConsts, uRandom, uTeams, uIO, uLandTemplates, uLandObjects, uSHA; |
4 | 50 |
|
51 |
type TPixAr = record |
|
52 |
Count: Longword; |
|
22 | 53 |
ar: array[0..Pred(cMaxEdgePoints)] of TPoint; |
4 | 54 |
end; |
55 |
||
56 |
var HHPoints: record |
|
57 |
First, Last: word; |
|
22 | 58 |
ar: array[1..Pred(cMaxSpawnPoints)] of TPoint |
4 | 59 |
end = (First: 1); |
60 |
||
37 | 61 |
procedure LogLandDigest; |
62 |
var ctx: TSHA1Context; |
|
63 |
dig: TSHA1Digest; |
|
64 |
begin |
|
65 |
SHA1Init(ctx); |
|
66 |
SHA1Update(ctx, @Land, sizeof(Land)); |
|
67 |
dig:= SHA1Final(ctx); |
|
68 |
AddFileLog('SHA1 Land digest: {'+inttostr(dig.LongWords[0])+':' |
|
69 |
+inttostr(dig.LongWords[1])+':'+inttostr(dig.LongWords[2])+':' |
|
70 |
+inttostr(dig.LongWords[3])+':'+inttostr(dig.LongWords[4])+'}'); |
|
71 |
end; |
|
72 |
||
22 | 73 |
procedure DrawBezierEdge(var pa: TPixAr); |
4 | 74 |
var x, y, i: integer; |
75 |
tx, ty, vx, vy, vlen, t: real; |
|
76 |
r1, r2, r3, r4: real; |
|
77 |
x1, y1, x2, y2, cx1, cy1, cx2, cy2, tsq, tcb: real; |
|
78 |
begin |
|
79 |
vx:= 0; |
|
80 |
vy:= 0; |
|
81 |
with pa do |
|
82 |
for i:= 0 to Count-2 do |
|
83 |
begin |
|
84 |
vlen:= sqrt(sqr(ar[i + 1].x - ar[i ].X) + sqr(ar[i + 1].y - ar[i ].y)); |
|
85 |
t:= sqrt(sqr(ar[i + 1].x - ar[i + 2].X) + sqr(ar[i + 1].y - ar[i + 2].y)); |
|
86 |
if t<vlen then vlen:= t; |
|
87 |
vlen:= vlen/3; |
|
88 |
tx:= ar[i+2].X - ar[i].X; |
|
89 |
ty:= ar[i+2].y - ar[i].y; |
|
90 |
t:= sqrt(sqr(tx)+sqr(ty)); |
|
91 |
if t = 0 then |
|
92 |
begin |
|
93 |
tx:= -tx * 100000; |
|
94 |
ty:= -ty * 100000; |
|
95 |
end else |
|
96 |
begin |
|
97 |
tx:= -tx/t; |
|
98 |
ty:= -ty/t; |
|
99 |
end; |
|
100 |
t:= 1.0*vlen; |
|
101 |
tx:= tx*t; |
|
102 |
ty:= ty*t; |
|
103 |
x1:= ar[i].x; |
|
104 |
y1:= ar[i].y; |
|
105 |
x2:= ar[i + 1].x; |
|
106 |
y2:= ar[i + 1].y; |
|
107 |
cx1:= ar[i].X + trunc(vx); |
|
108 |
cy1:= ar[i].y + trunc(vy); |
|
109 |
cx2:= ar[i+1].X + trunc(tx); |
|
110 |
cy2:= ar[i+1].y + trunc(ty); |
|
111 |
vx:= -tx; |
|
112 |
vy:= -ty; |
|
113 |
t:= 0; |
|
114 |
while t <= 1.0 do |
|
115 |
begin |
|
116 |
tsq:= sqr(t); |
|
117 |
tcb:= tsq * t; |
|
118 |
r1:= (1 - 3*t + 3*tsq - tcb) * x1; |
|
119 |
r2:= ( 3*t - 6*tsq + 3*tcb) * cx1; |
|
120 |
r3:= ( 3*tsq - 3*tcb) * cx2; |
|
121 |
r4:= ( tcb) * x2; |
|
122 |
X:= round(r1 + r2 + r3 + r4); |
|
123 |
r1:= (1 - 3*t + 3*tsq - tcb) * y1; |
|
124 |
r2:= ( 3*t - 6*tsq + 3*tcb) * cy1; |
|
125 |
r3:= ( 3*tsq - 3*tcb) * cy2; |
|
126 |
r4:= ( tcb) * y2; |
|
127 |
Y:= round(r1 + r2 + r3 + r4); |
|
128 |
t:= t + 0.001; |
|
129 |
if ((x and $FFFFF800) = 0) and ((y and $FFFFFC00) = 0) then |
|
130 |
Land[y, x]:= $FFFFFF; |
|
131 |
end; |
|
132 |
end; |
|
133 |
end; |
|
134 |
||
22 | 135 |
procedure BezierizeEdge(var pa: TPixAr; Delta: real); |
136 |
var x, y, i: integer; |
|
137 |
tx, ty, vx, vy, vlen, t: real; |
|
138 |
r1, r2, r3, r4: real; |
|
139 |
x1, y1, x2, y2, cx1, cy1, cx2, cy2, tsq, tcb: real; |
|
140 |
opa: TPixAr; |
|
141 |
begin |
|
142 |
opa:= pa; |
|
143 |
pa.Count:= 0; |
|
144 |
vx:= 0; |
|
145 |
vy:= 0; |
|
146 |
with opa do |
|
147 |
for i:= 0 to Count-2 do |
|
148 |
begin |
|
149 |
vlen:= sqrt(sqr(ar[i + 1].x - ar[i ].X) + sqr(ar[i + 1].y - ar[i ].y)); |
|
150 |
t:= sqrt(sqr(ar[i + 1].x - ar[i + 2].X) + sqr(ar[i + 1].y - ar[i + 2].y)); |
|
151 |
if t<vlen then vlen:= t; |
|
152 |
vlen:= vlen/3; |
|
153 |
tx:= ar[i+2].X - ar[i].X; |
|
154 |
ty:= ar[i+2].y - ar[i].y; |
|
155 |
t:= sqrt(sqr(tx)+sqr(ty)); |
|
156 |
if t = 0 then |
|
157 |
begin |
|
158 |
tx:= -tx * 100000; |
|
159 |
ty:= -ty * 100000; |
|
160 |
end else |
|
161 |
begin |
|
162 |
tx:= -tx/t; |
|
163 |
ty:= -ty/t; |
|
164 |
end; |
|
165 |
t:= 1.0*vlen; |
|
166 |
tx:= tx*t; |
|
167 |
ty:= ty*t; |
|
168 |
x1:= ar[i].x; |
|
169 |
y1:= ar[i].y; |
|
170 |
x2:= ar[i + 1].x; |
|
171 |
y2:= ar[i + 1].y; |
|
172 |
cx1:= ar[i].X + trunc(vx); |
|
173 |
cy1:= ar[i].y + trunc(vy); |
|
174 |
cx2:= ar[i+1].X + trunc(tx); |
|
175 |
cy2:= ar[i+1].y + trunc(ty); |
|
176 |
vx:= -tx; |
|
177 |
vy:= -ty; |
|
178 |
t:= 0; |
|
179 |
while t <= 1.0 do |
|
180 |
begin |
|
181 |
tsq:= sqr(t); |
|
182 |
tcb:= tsq * t; |
|
183 |
r1:= (1 - 3*t + 3*tsq - tcb) * x1; |
|
184 |
r2:= ( 3*t - 6*tsq + 3*tcb) * cx1; |
|
185 |
r3:= ( 3*tsq - 3*tcb) * cx2; |
|
186 |
r4:= ( tcb) * x2; |
|
187 |
X:= round(r1 + r2 + r3 + r4); |
|
188 |
r1:= (1 - 3*t + 3*tsq - tcb) * y1; |
|
189 |
r2:= ( 3*t - 6*tsq + 3*tcb) * cy1; |
|
190 |
r3:= ( 3*tsq - 3*tcb) * cy2; |
|
191 |
r4:= ( tcb) * y2; |
|
192 |
Y:= round(r1 + r2 + r3 + r4); |
|
193 |
t:= t + Delta; |
|
194 |
pa.ar[pa.Count].x:= X; |
|
195 |
pa.ar[pa.Count].y:= Y; |
|
196 |
inc(pa.Count); |
|
197 |
TryDo(pa.Count < cMaxEdgePoints, 'Edge points overflow', true) |
|
198 |
end; |
|
199 |
end; |
|
200 |
end; |
|
201 |
||
4 | 202 |
procedure FillLand(x, y: integer); |
203 |
var Stack: record |
|
204 |
Count: Longword; |
|
205 |
points: array[0..8192] of record |
|
206 |
xl, xr, y, dir: integer; |
|
207 |
end |
|
208 |
end; |
|
209 |
||
210 |
procedure Push(_xl, _xr, _y, _dir: integer); |
|
211 |
begin |
|
212 |
_y:= _y + _dir; |
|
213 |
if (_y < 0) or (_y > 1023) then exit; |
|
214 |
with Stack.points[Stack.Count] do |
|
215 |
begin |
|
216 |
xl:= _xl; |
|
217 |
xr:= _xr; |
|
218 |
y:= _y; |
|
219 |
dir:= _dir |
|
220 |
end; |
|
221 |
inc(Stack.Count); |
|
222 |
TryDo(Stack.Count < 8192, 'stack overflow', true) |
|
223 |
end; |
|
224 |
||
225 |
procedure Pop(out _xl, _xr, _y, _dir: integer); |
|
226 |
begin |
|
227 |
dec(Stack.Count); |
|
228 |
with Stack.points[Stack.Count] do |
|
229 |
begin |
|
230 |
_xl:= xl; |
|
231 |
_xr:= xr; |
|
232 |
_y:= y; |
|
233 |
_dir:= dir |
|
234 |
end |
|
235 |
end; |
|
236 |
||
237 |
var xl, xr, dir: integer; |
|
238 |
begin |
|
239 |
Stack.Count:= 0; |
|
240 |
xl:= x - 1; |
|
241 |
xr:= x; |
|
23 | 242 |
Push(xl, xr, y, -1); |
243 |
Push(xl, xr, y, 1); |
|
4 | 244 |
while Stack.Count > 0 do |
245 |
begin |
|
246 |
Pop(xl, xr, y, dir); |
|
247 |
while (xl > 0) and (Land[y, xl] = 0) do dec(xl); |
|
248 |
while (xr < 2047) and (Land[y, xr] = 0) do inc(xr); |
|
249 |
while (xl < xr) do |
|
250 |
begin |
|
251 |
while (xl <= xr) and (Land[y, xl] <> 0) do inc(xl); |
|
252 |
x:= xl; |
|
253 |
while (xl <= xr) and (Land[y, xl] = 0) do |
|
254 |
begin |
|
255 |
Land[y, xl]:= $FFFFFF; |
|
256 |
inc(xl) |
|
257 |
end; |
|
22 | 258 |
if x < xl then |
259 |
begin |
|
260 |
Push(x, Pred(xl), y, dir); |
|
261 |
Push(x, Pred(xl), y,-dir); |
|
262 |
end; |
|
4 | 263 |
end; |
264 |
end; |
|
265 |
end; |
|
266 |
||
267 |
procedure ColorizeLand(Surface: PSDL_Surface); |
|
268 |
var tmpsurf: PSDL_Surface; |
|
269 |
r: TSDL_Rect; |
|
270 |
begin |
|
35 | 271 |
tmpsurf:= LoadImage(Pathz[ptThemeCurrent] + 'LandTex.png', false); |
4 | 272 |
r.y:= 0; |
273 |
while r.y < 1024 do |
|
274 |
begin |
|
275 |
r.x:= 0; |
|
276 |
while r.x < 2048 do |
|
277 |
begin |
|
278 |
SDL_UpperBlit(tmpsurf, nil, Surface, @r); |
|
279 |
inc(r.x, tmpsurf.w) |
|
280 |
end; |
|
281 |
inc(r.y, tmpsurf.h) |
|
282 |
end; |
|
283 |
SDL_FreeSurface(tmpsurf); |
|
284 |
||
285 |
tmpsurf:= SDL_CreateRGBSurfaceFrom(@Land, 2048, 1024, 32, 2048*4, $FF0000, $FF00, $FF, 0); |
|
286 |
SDLTry(tmpsurf <> nil, true); |
|
287 |
SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, SDL_MapRGB(tmpsurf.format, $FF, $FF, $FF)); |
|
22 | 288 |
SDL_UpperBlit(tmpsurf, nil, Surface, nil); |
289 |
SDL_FreeSurface(tmpsurf) |
|
4 | 290 |
end; |
291 |
||
292 |
procedure AddBorder(Surface: PSDL_Surface); |
|
293 |
var tmpsurf: PSDL_Surface; |
|
294 |
r, rr: TSDL_Rect; |
|
295 |
x, yd, yu: integer; |
|
296 |
begin |
|
35 | 297 |
tmpsurf:= LoadImage(Pathz[ptThemeCurrent] + 'Border.png', false); |
4 | 298 |
for x:= 0 to 2047 do |
299 |
begin |
|
300 |
yd:= 1023; |
|
301 |
repeat |
|
302 |
while (yd > 0 ) and (Land[yd, x] = 0) do dec(yd); |
|
303 |
if (yd < 0) then yd:= 0; |
|
304 |
while (yd < 1024) and (Land[yd, x] <> 0) do inc(yd); |
|
305 |
dec(yd); |
|
306 |
yu:= yd; |
|
307 |
while (yu > 0 ) and (Land[yu, x] <> 0) do dec(yu); |
|
308 |
while (yu < yd ) and (Land[yu, x] = 0) do inc(yu); |
|
309 |
if (yd < 1023) and ((yd - yu) >= 16) then |
|
310 |
begin |
|
311 |
rr.x:= x; |
|
312 |
rr.y:= yd - 15; |
|
313 |
r.x:= x mod tmpsurf.w; |
|
314 |
r.y:= 16; |
|
315 |
r.w:= 1; |
|
316 |
r.h:= 16; |
|
317 |
SDL_UpperBlit(tmpsurf, @r, Surface, @rr); |
|
318 |
end; |
|
319 |
if (yu > 0) then |
|
320 |
begin |
|
321 |
rr.x:= x; |
|
322 |
rr.y:= yu; |
|
323 |
r.x:= x mod tmpsurf.w; |
|
324 |
r.y:= 0; |
|
325 |
r.w:= 1; |
|
326 |
r.h:= min(16, yd - yu + 1); |
|
327 |
SDL_UpperBlit(tmpsurf, @r, Surface, @rr); |
|
328 |
end; |
|
329 |
yd:= yu - 1; |
|
330 |
until yd < 0; |
|
331 |
end; |
|
332 |
end; |
|
333 |
||
334 |
procedure AddHHPoints; |
|
10 | 335 |
var x, y, t: integer; |
8
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
336 |
|
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
337 |
function CountNonZeroz(x, y: integer): integer; |
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
338 |
var i: integer; |
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
339 |
begin |
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
340 |
Result:= 0; |
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
341 |
if (y and $FFFFFC00) <> 0 then exit; |
23 | 342 |
for i:= max(x - 5, 0) to min(x + 5, 2043) do |
8
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
343 |
if Land[y, i] <> 0 then inc(Result) |
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
344 |
end; |
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
345 |
|
4 | 346 |
begin |
10 | 347 |
x:= 40; |
348 |
while x < 2010 do |
|
4 | 349 |
begin |
8
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
350 |
y:= -24; |
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
351 |
while y < 1023 do |
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
352 |
begin |
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
353 |
repeat |
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
354 |
inc(y, 2); |
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
355 |
until (y > 1023) or (CountNonZeroz(x, y) = 0); |
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
356 |
t:= 0; |
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
357 |
repeat |
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
358 |
inc(y, 2); |
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
359 |
inc(t, 2) |
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
360 |
until (y > 1023) or (CountNonZeroz(x, y) <> 0); |
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
361 |
if (t > 22) and (y < 1023) then AddHHPoint(x, y - 12); |
27 | 362 |
inc(y, 80) |
8
24048039955c
- Hedgehogs spawn points can be generated under the girder
unc0rr
parents:
4
diff
changeset
|
363 |
end; |
27 | 364 |
inc(x, 100) |
4 | 365 |
end; |
22 | 366 |
|
367 |
if HHPoints.Last < cMaxHHs then |
|
368 |
begin |
|
369 |
AddHHPoint(300, 800); |
|
370 |
AddHHPoint(400, 800); |
|
371 |
AddHHPoint(500, 800); |
|
372 |
AddHHPoint(600, 800); |
|
373 |
AddHHPoint(700, 800); |
|
374 |
AddHHPoint(800, 800); |
|
375 |
AddHHPoint(900, 800); |
|
376 |
AddHHPoint(1000, 800); |
|
377 |
AddHHPoint(1100, 800); |
|
378 |
AddHHPoint(1200, 800); |
|
379 |
AddHHPoint(1300, 800); |
|
380 |
AddHHPoint(1400, 800); |
|
381 |
end; |
|
382 |
end; |
|
383 |
||
23 | 384 |
procedure PointWave(var Template: TEdgeTemplate; var pa: TPixAr); |
27 | 385 |
const MAXPASSES = 32; |
386 |
var ar: array[0..MAXPASSES, 0..5] of real; |
|
22 | 387 |
i, k: integer; |
388 |
rx, ry, oy: real; |
|
23 | 389 |
PassesNum: Longword; |
22 | 390 |
begin |
23 | 391 |
with Template do |
392 |
begin |
|
393 |
PassesNum:= PassMin + getrandom(PassDelta); |
|
394 |
TryDo(PassesNum < MAXPASSES, 'Passes number too big', true); |
|
27 | 395 |
ar[0, 1]:= WaveFreqMin; |
396 |
ar[0, 4]:= WaveFreqMin; |
|
23 | 397 |
for i:= 1 to PassesNum do // initialize random parameters |
398 |
begin |
|
399 |
ar[i, 0]:= WaveAmplMin + getrandom * WaveAmplDelta; |
|
27 | 400 |
ar[i, 1]:= ar[i - 1, 1] + (getrandom * 0.7 + 0.3) * WaveFreqDelta; |
23 | 401 |
ar[i, 2]:= getrandom * pi * 2; |
402 |
ar[i, 3]:= WaveAmplMin + getrandom * WaveAmplDelta; |
|
27 | 403 |
ar[i, 4]:= ar[i - 1, 4] + (getrandom * 0.7 + 0.3) * WaveFreqDelta; |
23 | 404 |
ar[i, 5]:= getrandom * pi * 2; |
405 |
end; |
|
406 |
end; |
|
22 | 407 |
|
408 |
for k:= 0 to Pred(pa.Count) do // apply transformation |
|
409 |
begin |
|
410 |
rx:= pa.ar[k].x; |
|
411 |
ry:= pa.ar[k].y; |
|
24 | 412 |
for i:= 1 to PassesNum do |
22 | 413 |
begin |
414 |
oy:= ry; |
|
415 |
ry:= ry + ar[i, 0] * sin(ar[i, 1] * rx + ar[i, 2]); |
|
416 |
rx:= rx + ar[i, 3] * sin(ar[i, 4] * oy + ar[i, 5]); |
|
417 |
end; |
|
24 | 418 |
pa.ar[k].x:= round(rx); |
419 |
pa.ar[k].y:= round(ry); |
|
420 |
end; |
|
4 | 421 |
end; |
422 |
||
23 | 423 |
procedure GenBlank(var Template: TEdgeTemplate); |
4 | 424 |
var pa: TPixAr; |
23 | 425 |
i: Longword; |
4 | 426 |
begin |
23 | 427 |
with Template do |
428 |
begin |
|
27 | 429 |
if canMirror then |
430 |
if getrandom(16) < 8 then |
|
431 |
begin |
|
432 |
for i:= 0 to pred(BasePointsCount) do |
|
433 |
BasePoints^[i].x:= 2047 - BasePoints^[i].x; |
|
434 |
for i:= 0 to pred(FillPointsCount) do |
|
435 |
FillPoints^[i].x:= 2047 - FillPoints^[i].x; |
|
436 |
end; |
|
437 |
||
438 |
if canFlip then |
|
439 |
if getrandom(16) < 8 then |
|
440 |
begin |
|
441 |
for i:= 0 to pred(BasePointsCount) do |
|
442 |
BasePoints^[i].y:= 1023 - BasePoints^[i].y; |
|
443 |
for i:= 0 to pred(FillPointsCount) do |
|
444 |
FillPoints^[i].y:= 1023 - FillPoints^[i].y; |
|
445 |
end; |
|
446 |
||
23 | 447 |
pa.Count:= BasePointsCount; |
448 |
for i:= 0 to pred(pa.Count) do |
|
449 |
pa.ar[i]:= BasePoints^[i]; |
|
450 |
||
451 |
for i:= 1 to BezPassCnt do |
|
452 |
BezierizeEdge(pa, 0.33333334); |
|
453 |
||
454 |
PointWave(Template, pa); |
|
455 |
DrawBezierEdge(pa); |
|
456 |
||
457 |
for i:= 0 to pred(FillPointsCount) do |
|
458 |
with FillPoints^[i] do |
|
459 |
FillLand(x, y) |
|
460 |
end; |
|
461 |
end; |
|
462 |
||
463 |
procedure GenLandSurface; |
|
464 |
var tmpsurf: PSDL_Surface; |
|
465 |
begin |
|
466 |
GenBlank(EdgeTemplates[getrandom(Succ(High(EdgeTemplates)))]); |
|
22 | 467 |
|
4 | 468 |
AddProgress; |
469 |
with PixelFormat^ do |
|
470 |
tmpsurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, 0); |
|
471 |
ColorizeLand(tmpsurf); |
|
472 |
AddProgress; |
|
473 |
AddBorder(tmpsurf); |
|
474 |
with PixelFormat^ do |
|
475 |
LandSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, 0); |
|
476 |
SDL_FillRect(LandSurface, nil, 0); |
|
27 | 477 |
AddProgress; |
24 | 478 |
|
479 |
AddObjects(LandSurface); |
|
480 |
||
4 | 481 |
SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0); |
482 |
SDL_UpperBlit(tmpsurf, nil, LandSurface, nil); |
|
483 |
SDL_FreeSurface(tmpsurf); |
|
484 |
AddProgress; |
|
485 |
AddHHPoints; |
|
486 |
RandomizeHHPoints; |
|
487 |
end; |
|
488 |
||
489 |
procedure MakeFortsMap; |
|
490 |
var p: PTeam; |
|
491 |
tmpsurf: PSDL_Surface; |
|
492 |
begin |
|
493 |
p:= TeamsList; |
|
494 |
TryDo(p <> nil, 'No teams on map!', true); |
|
495 |
with PixelFormat^ do |
|
496 |
LandSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, 0); |
|
37 | 497 |
SDL_FillRect(LandSurface, nil, 0); |
35 | 498 |
tmpsurf:= LoadImage(Pathz[ptForts] + p.FortName + 'L.png', false); |
4 | 499 |
BlitImageAndGenerateCollisionInfo(0, 0, tmpsurf, LandSurface); |
500 |
SDL_FreeSurface(tmpsurf); |
|
501 |
LoadFortPoints(p.FortName, false, TeamSize(p)); |
|
502 |
p:= p.Next; |
|
503 |
TryDo(p <> nil, 'Only one team on map!', true); |
|
35 | 504 |
tmpsurf:= LoadImage(Pathz[ptForts] + p.FortName + 'R.png', false); |
4 | 505 |
BlitImageAndGenerateCollisionInfo(1024, 0, tmpsurf, LandSurface); |
506 |
SDL_FreeSurface(tmpsurf); |
|
507 |
LoadFortPoints(p.FortName, true, TeamSize(p)); |
|
508 |
p:= p.Next; |
|
509 |
TryDo(p = nil, 'More than 2 teams on map in forts mode!', true); |
|
510 |
end; |
|
511 |
||
37 | 512 |
procedure GenMap; |
513 |
begin |
|
514 |
if (GameFlags and gfForts) = 0 then GenLandSurface |
|
515 |
else MakeFortsMap; |
|
516 |
AddProgress; |
|
517 |
{$IFDEF DEBUGFILE}LogLandDigest{$ENDIF} |
|
518 |
end; |
|
519 |
||
4 | 520 |
procedure AddHHPoint(_x, _y: integer); |
521 |
begin |
|
522 |
with HHPoints do |
|
523 |
begin |
|
524 |
inc(Last); |
|
22 | 525 |
TryDo(Last < cMaxSpawnPoints, 'HHs coords queue overflow', true); |
4 | 526 |
with ar[Last] do |
527 |
begin |
|
528 |
x:= _x; |
|
529 |
y:= _y |
|
530 |
end |
|
531 |
end |
|
532 |
end; |
|
533 |
||
534 |
procedure GetHHPoint(out _x, _y: integer); |
|
535 |
begin |
|
536 |
with HHPoints do |
|
537 |
begin |
|
538 |
TryDo(First <= Last, 'HHs coords queue underflow ' + inttostr(First), true); |
|
539 |
with ar[First] do |
|
540 |
begin |
|
541 |
_x:= x; |
|
542 |
_y:= y |
|
543 |
end; |
|
544 |
inc(First) |
|
545 |
end |
|
546 |
end; |
|
547 |
||
548 |
procedure RandomizeHHPoints; |
|
549 |
var i, t: integer; |
|
550 |
p: TPoint; |
|
551 |
begin |
|
552 |
with HHPoints do |
|
553 |
begin |
|
554 |
for i:= First to Last do |
|
555 |
begin |
|
556 |
t:= GetRandom(Last - First + 1) + First; |
|
557 |
if i <> t then |
|
558 |
begin |
|
559 |
p:= ar[i]; |
|
560 |
ar[i]:= ar[t]; |
|
561 |
ar[t]:= p |
|
562 |
end |
|
563 |
end |
|
564 |
end |
|
565 |
end; |
|
566 |
||
567 |
end. |