4
|
1 |
(*
|
|
2 |
* Hedgewars, a worms-like game
|
70
|
3 |
* Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
|
4
|
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
|
70
|
36 |
uses SDLh, uGears;
|
4
|
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 |
|
37
|
43 |
procedure GenMap;
|
4
|
44 |
|
|
45 |
implementation
|
37
|
46 |
uses uConsole, uStore, uMisc, uConsts, uRandom, uTeams, uIO, uLandTemplates, uLandObjects, uSHA;
|
4
|
47 |
|
|
48 |
type TPixAr = record
|
|
49 |
Count: Longword;
|
22
|
50 |
ar: array[0..Pred(cMaxEdgePoints)] of TPoint;
|
4
|
51 |
end;
|
|
52 |
|
37
|
53 |
procedure LogLandDigest;
|
|
54 |
var ctx: TSHA1Context;
|
|
55 |
dig: TSHA1Digest;
|
|
56 |
begin
|
|
57 |
SHA1Init(ctx);
|
|
58 |
SHA1Update(ctx, @Land, sizeof(Land));
|
|
59 |
dig:= SHA1Final(ctx);
|
57
|
60 |
{$IFDEF DEBUGFILE}
|
37
|
61 |
AddFileLog('SHA1 Land digest: {'+inttostr(dig.LongWords[0])+':'
|
|
62 |
+inttostr(dig.LongWords[1])+':'+inttostr(dig.LongWords[2])+':'
|
|
63 |
+inttostr(dig.LongWords[3])+':'+inttostr(dig.LongWords[4])+'}');
|
57
|
64 |
{$ENDIF}
|
37
|
65 |
end;
|
|
66 |
|
22
|
67 |
procedure DrawBezierEdge(var pa: TPixAr);
|
4
|
68 |
var x, y, i: integer;
|
|
69 |
tx, ty, vx, vy, vlen, t: real;
|
|
70 |
r1, r2, r3, r4: real;
|
|
71 |
x1, y1, x2, y2, cx1, cy1, cx2, cy2, tsq, tcb: real;
|
|
72 |
begin
|
|
73 |
vx:= 0;
|
|
74 |
vy:= 0;
|
|
75 |
with pa do
|
|
76 |
for i:= 0 to Count-2 do
|
|
77 |
begin
|
|
78 |
vlen:= sqrt(sqr(ar[i + 1].x - ar[i ].X) + sqr(ar[i + 1].y - ar[i ].y));
|
|
79 |
t:= sqrt(sqr(ar[i + 1].x - ar[i + 2].X) + sqr(ar[i + 1].y - ar[i + 2].y));
|
|
80 |
if t<vlen then vlen:= t;
|
|
81 |
vlen:= vlen/3;
|
|
82 |
tx:= ar[i+2].X - ar[i].X;
|
|
83 |
ty:= ar[i+2].y - ar[i].y;
|
|
84 |
t:= sqrt(sqr(tx)+sqr(ty));
|
|
85 |
if t = 0 then
|
|
86 |
begin
|
|
87 |
tx:= -tx * 100000;
|
|
88 |
ty:= -ty * 100000;
|
|
89 |
end else
|
|
90 |
begin
|
|
91 |
tx:= -tx/t;
|
|
92 |
ty:= -ty/t;
|
|
93 |
end;
|
|
94 |
t:= 1.0*vlen;
|
|
95 |
tx:= tx*t;
|
|
96 |
ty:= ty*t;
|
|
97 |
x1:= ar[i].x;
|
|
98 |
y1:= ar[i].y;
|
|
99 |
x2:= ar[i + 1].x;
|
|
100 |
y2:= ar[i + 1].y;
|
|
101 |
cx1:= ar[i].X + trunc(vx);
|
|
102 |
cy1:= ar[i].y + trunc(vy);
|
|
103 |
cx2:= ar[i+1].X + trunc(tx);
|
|
104 |
cy2:= ar[i+1].y + trunc(ty);
|
|
105 |
vx:= -tx;
|
|
106 |
vy:= -ty;
|
|
107 |
t:= 0;
|
|
108 |
while t <= 1.0 do
|
|
109 |
begin
|
|
110 |
tsq:= sqr(t);
|
|
111 |
tcb:= tsq * t;
|
|
112 |
r1:= (1 - 3*t + 3*tsq - tcb) * x1;
|
|
113 |
r2:= ( 3*t - 6*tsq + 3*tcb) * cx1;
|
|
114 |
r3:= ( 3*tsq - 3*tcb) * cx2;
|
|
115 |
r4:= ( tcb) * x2;
|
|
116 |
X:= round(r1 + r2 + r3 + r4);
|
|
117 |
r1:= (1 - 3*t + 3*tsq - tcb) * y1;
|
|
118 |
r2:= ( 3*t - 6*tsq + 3*tcb) * cy1;
|
|
119 |
r3:= ( 3*tsq - 3*tcb) * cy2;
|
|
120 |
r4:= ( tcb) * y2;
|
|
121 |
Y:= round(r1 + r2 + r3 + r4);
|
|
122 |
t:= t + 0.001;
|
|
123 |
if ((x and $FFFFF800) = 0) and ((y and $FFFFFC00) = 0) then
|
51
|
124 |
Land[y, x]:= 0;
|
4
|
125 |
end;
|
|
126 |
end;
|
|
127 |
end;
|
|
128 |
|
22
|
129 |
procedure BezierizeEdge(var pa: TPixAr; Delta: real);
|
|
130 |
var x, y, i: integer;
|
|
131 |
tx, ty, vx, vy, vlen, t: real;
|
|
132 |
r1, r2, r3, r4: real;
|
|
133 |
x1, y1, x2, y2, cx1, cy1, cx2, cy2, tsq, tcb: real;
|
|
134 |
opa: TPixAr;
|
|
135 |
begin
|
|
136 |
opa:= pa;
|
|
137 |
pa.Count:= 0;
|
|
138 |
vx:= 0;
|
|
139 |
vy:= 0;
|
|
140 |
with opa do
|
|
141 |
for i:= 0 to Count-2 do
|
|
142 |
begin
|
|
143 |
vlen:= sqrt(sqr(ar[i + 1].x - ar[i ].X) + sqr(ar[i + 1].y - ar[i ].y));
|
|
144 |
t:= sqrt(sqr(ar[i + 1].x - ar[i + 2].X) + sqr(ar[i + 1].y - ar[i + 2].y));
|
|
145 |
if t<vlen then vlen:= t;
|
|
146 |
vlen:= vlen/3;
|
|
147 |
tx:= ar[i+2].X - ar[i].X;
|
|
148 |
ty:= ar[i+2].y - ar[i].y;
|
|
149 |
t:= sqrt(sqr(tx)+sqr(ty));
|
|
150 |
if t = 0 then
|
|
151 |
begin
|
|
152 |
tx:= -tx * 100000;
|
|
153 |
ty:= -ty * 100000;
|
|
154 |
end else
|
|
155 |
begin
|
|
156 |
tx:= -tx/t;
|
|
157 |
ty:= -ty/t;
|
|
158 |
end;
|
|
159 |
t:= 1.0*vlen;
|
|
160 |
tx:= tx*t;
|
|
161 |
ty:= ty*t;
|
|
162 |
x1:= ar[i].x;
|
|
163 |
y1:= ar[i].y;
|
|
164 |
x2:= ar[i + 1].x;
|
|
165 |
y2:= ar[i + 1].y;
|
|
166 |
cx1:= ar[i].X + trunc(vx);
|
|
167 |
cy1:= ar[i].y + trunc(vy);
|
|
168 |
cx2:= ar[i+1].X + trunc(tx);
|
|
169 |
cy2:= ar[i+1].y + trunc(ty);
|
|
170 |
vx:= -tx;
|
|
171 |
vy:= -ty;
|
|
172 |
t:= 0;
|
|
173 |
while t <= 1.0 do
|
|
174 |
begin
|
|
175 |
tsq:= sqr(t);
|
|
176 |
tcb:= tsq * t;
|
|
177 |
r1:= (1 - 3*t + 3*tsq - tcb) * x1;
|
|
178 |
r2:= ( 3*t - 6*tsq + 3*tcb) * cx1;
|
|
179 |
r3:= ( 3*tsq - 3*tcb) * cx2;
|
|
180 |
r4:= ( tcb) * x2;
|
|
181 |
X:= round(r1 + r2 + r3 + r4);
|
|
182 |
r1:= (1 - 3*t + 3*tsq - tcb) * y1;
|
|
183 |
r2:= ( 3*t - 6*tsq + 3*tcb) * cy1;
|
|
184 |
r3:= ( 3*tsq - 3*tcb) * cy2;
|
|
185 |
r4:= ( tcb) * y2;
|
|
186 |
Y:= round(r1 + r2 + r3 + r4);
|
|
187 |
t:= t + Delta;
|
|
188 |
pa.ar[pa.Count].x:= X;
|
|
189 |
pa.ar[pa.Count].y:= Y;
|
|
190 |
inc(pa.Count);
|
|
191 |
TryDo(pa.Count < cMaxEdgePoints, 'Edge points overflow', true)
|
|
192 |
end;
|
|
193 |
end;
|
|
194 |
end;
|
|
195 |
|
4
|
196 |
procedure FillLand(x, y: integer);
|
|
197 |
var Stack: record
|
|
198 |
Count: Longword;
|
|
199 |
points: array[0..8192] of record
|
|
200 |
xl, xr, y, dir: integer;
|
|
201 |
end
|
|
202 |
end;
|
|
203 |
|
|
204 |
procedure Push(_xl, _xr, _y, _dir: integer);
|
|
205 |
begin
|
|
206 |
_y:= _y + _dir;
|
|
207 |
if (_y < 0) or (_y > 1023) then exit;
|
|
208 |
with Stack.points[Stack.Count] do
|
|
209 |
begin
|
|
210 |
xl:= _xl;
|
|
211 |
xr:= _xr;
|
|
212 |
y:= _y;
|
|
213 |
dir:= _dir
|
|
214 |
end;
|
|
215 |
inc(Stack.Count);
|
|
216 |
TryDo(Stack.Count < 8192, 'stack overflow', true)
|
|
217 |
end;
|
|
218 |
|
|
219 |
procedure Pop(out _xl, _xr, _y, _dir: integer);
|
|
220 |
begin
|
|
221 |
dec(Stack.Count);
|
|
222 |
with Stack.points[Stack.Count] do
|
|
223 |
begin
|
|
224 |
_xl:= xl;
|
|
225 |
_xr:= xr;
|
|
226 |
_y:= y;
|
|
227 |
_dir:= dir
|
|
228 |
end
|
|
229 |
end;
|
|
230 |
|
|
231 |
var xl, xr, dir: integer;
|
|
232 |
begin
|
|
233 |
Stack.Count:= 0;
|
|
234 |
xl:= x - 1;
|
|
235 |
xr:= x;
|
23
|
236 |
Push(xl, xr, y, -1);
|
|
237 |
Push(xl, xr, y, 1);
|
4
|
238 |
while Stack.Count > 0 do
|
|
239 |
begin
|
|
240 |
Pop(xl, xr, y, dir);
|
51
|
241 |
while (xl > 0) and (Land[y, xl] <> 0) do dec(xl);
|
|
242 |
while (xr < 2047) and (Land[y, xr] <> 0) do inc(xr);
|
4
|
243 |
while (xl < xr) do
|
|
244 |
begin
|
51
|
245 |
while (xl <= xr) and (Land[y, xl] = 0) do inc(xl);
|
4
|
246 |
x:= xl;
|
51
|
247 |
while (xl <= xr) and (Land[y, xl] <> 0) do
|
4
|
248 |
begin
|
51
|
249 |
Land[y, xl]:= 0;
|
4
|
250 |
inc(xl)
|
|
251 |
end;
|
22
|
252 |
if x < xl then
|
|
253 |
begin
|
|
254 |
Push(x, Pred(xl), y, dir);
|
|
255 |
Push(x, Pred(xl), y,-dir);
|
|
256 |
end;
|
4
|
257 |
end;
|
|
258 |
end;
|
|
259 |
end;
|
|
260 |
|
|
261 |
procedure ColorizeLand(Surface: PSDL_Surface);
|
|
262 |
var tmpsurf: PSDL_Surface;
|
|
263 |
r: TSDL_Rect;
|
|
264 |
begin
|
74
|
265 |
tmpsurf:= LoadImage(Pathz[ptThemeCurrent] + '/LandTex', false);
|
4
|
266 |
r.y:= 0;
|
|
267 |
while r.y < 1024 do
|
|
268 |
begin
|
|
269 |
r.x:= 0;
|
|
270 |
while r.x < 2048 do
|
|
271 |
begin
|
|
272 |
SDL_UpperBlit(tmpsurf, nil, Surface, @r);
|
|
273 |
inc(r.x, tmpsurf.w)
|
|
274 |
end;
|
|
275 |
inc(r.y, tmpsurf.h)
|
|
276 |
end;
|
|
277 |
SDL_FreeSurface(tmpsurf);
|
|
278 |
|
|
279 |
tmpsurf:= SDL_CreateRGBSurfaceFrom(@Land, 2048, 1024, 32, 2048*4, $FF0000, $FF00, $FF, 0);
|
|
280 |
SDLTry(tmpsurf <> nil, true);
|
|
281 |
SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, SDL_MapRGB(tmpsurf.format, $FF, $FF, $FF));
|
22
|
282 |
SDL_UpperBlit(tmpsurf, nil, Surface, nil);
|
|
283 |
SDL_FreeSurface(tmpsurf)
|
4
|
284 |
end;
|
|
285 |
|
|
286 |
procedure AddBorder(Surface: PSDL_Surface);
|
|
287 |
var tmpsurf: PSDL_Surface;
|
|
288 |
r, rr: TSDL_Rect;
|
|
289 |
x, yd, yu: integer;
|
|
290 |
begin
|
74
|
291 |
tmpsurf:= LoadImage(Pathz[ptThemeCurrent] + '/Border', false);
|
4
|
292 |
for x:= 0 to 2047 do
|
|
293 |
begin
|
|
294 |
yd:= 1023;
|
|
295 |
repeat
|
|
296 |
while (yd > 0 ) and (Land[yd, x] = 0) do dec(yd);
|
|
297 |
if (yd < 0) then yd:= 0;
|
|
298 |
while (yd < 1024) and (Land[yd, x] <> 0) do inc(yd);
|
|
299 |
dec(yd);
|
|
300 |
yu:= yd;
|
|
301 |
while (yu > 0 ) and (Land[yu, x] <> 0) do dec(yu);
|
|
302 |
while (yu < yd ) and (Land[yu, x] = 0) do inc(yu);
|
|
303 |
if (yd < 1023) and ((yd - yu) >= 16) then
|
|
304 |
begin
|
|
305 |
rr.x:= x;
|
|
306 |
rr.y:= yd - 15;
|
|
307 |
r.x:= x mod tmpsurf.w;
|
|
308 |
r.y:= 16;
|
|
309 |
r.w:= 1;
|
|
310 |
r.h:= 16;
|
|
311 |
SDL_UpperBlit(tmpsurf, @r, Surface, @rr);
|
|
312 |
end;
|
|
313 |
if (yu > 0) then
|
|
314 |
begin
|
|
315 |
rr.x:= x;
|
|
316 |
rr.y:= yu;
|
|
317 |
r.x:= x mod tmpsurf.w;
|
|
318 |
r.y:= 0;
|
|
319 |
r.w:= 1;
|
|
320 |
r.h:= min(16, yd - yu + 1);
|
|
321 |
SDL_UpperBlit(tmpsurf, @r, Surface, @rr);
|
|
322 |
end;
|
|
323 |
yd:= yu - 1;
|
|
324 |
until yd < 0;
|
|
325 |
end;
|
|
326 |
end;
|
|
327 |
|
23
|
328 |
procedure PointWave(var Template: TEdgeTemplate; var pa: TPixAr);
|
27
|
329 |
const MAXPASSES = 32;
|
|
330 |
var ar: array[0..MAXPASSES, 0..5] of real;
|
22
|
331 |
i, k: integer;
|
|
332 |
rx, ry, oy: real;
|
23
|
333 |
PassesNum: Longword;
|
22
|
334 |
begin
|
23
|
335 |
with Template do
|
|
336 |
begin
|
|
337 |
PassesNum:= PassMin + getrandom(PassDelta);
|
|
338 |
TryDo(PassesNum < MAXPASSES, 'Passes number too big', true);
|
27
|
339 |
ar[0, 1]:= WaveFreqMin;
|
|
340 |
ar[0, 4]:= WaveFreqMin;
|
23
|
341 |
for i:= 1 to PassesNum do // initialize random parameters
|
|
342 |
begin
|
|
343 |
ar[i, 0]:= WaveAmplMin + getrandom * WaveAmplDelta;
|
27
|
344 |
ar[i, 1]:= ar[i - 1, 1] + (getrandom * 0.7 + 0.3) * WaveFreqDelta;
|
23
|
345 |
ar[i, 2]:= getrandom * pi * 2;
|
|
346 |
ar[i, 3]:= WaveAmplMin + getrandom * WaveAmplDelta;
|
27
|
347 |
ar[i, 4]:= ar[i - 1, 4] + (getrandom * 0.7 + 0.3) * WaveFreqDelta;
|
23
|
348 |
ar[i, 5]:= getrandom * pi * 2;
|
53
|
349 |
{$IFDEF DEBUGFILE}
|
|
350 |
AddFileLog('Wave params ¹' + inttostr(i) + ':');
|
|
351 |
AddFileLog('X: ampl = ' + floattostr(ar[i, 0]) + '; freq = ' + floattostr(ar[i, 1]) + '; shift = ' + floattostr(ar[i, 2]));
|
|
352 |
AddFileLog('Y: ampl = ' + floattostr(ar[i, 3]) + '; freq = ' + floattostr(ar[i, 4]) + '; shift = ' + floattostr(ar[i, 5]));
|
|
353 |
{$ENDIF}
|
23
|
354 |
end;
|
|
355 |
end;
|
22
|
356 |
|
|
357 |
for k:= 0 to Pred(pa.Count) do // apply transformation
|
|
358 |
begin
|
|
359 |
rx:= pa.ar[k].x;
|
|
360 |
ry:= pa.ar[k].y;
|
24
|
361 |
for i:= 1 to PassesNum do
|
22
|
362 |
begin
|
|
363 |
oy:= ry;
|
|
364 |
ry:= ry + ar[i, 0] * sin(ar[i, 1] * rx + ar[i, 2]);
|
|
365 |
rx:= rx + ar[i, 3] * sin(ar[i, 4] * oy + ar[i, 5]);
|
|
366 |
end;
|
24
|
367 |
pa.ar[k].x:= round(rx);
|
|
368 |
pa.ar[k].y:= round(ry);
|
|
369 |
end;
|
4
|
370 |
end;
|
|
371 |
|
67
|
372 |
procedure NormalizePoints(var pa: TPixAr);
|
|
373 |
const brd = 32;
|
|
374 |
var isUP: boolean; // HACK: transform for Y should be exact as one for X
|
|
375 |
Left, Right, Top, Bottom,
|
|
376 |
OWidth, Width, OHeight, Height,
|
|
377 |
OLeft: integer;
|
|
378 |
i: integer;
|
|
379 |
begin
|
|
380 |
TryDo((pa.ar[0].y < 0) or (pa.ar[0].y > 1023), 'Bad land generated', true);
|
|
381 |
isUP:= pa.ar[0].y > 0;
|
|
382 |
Left:= 1023;
|
|
383 |
Right:= Left;
|
|
384 |
Top:= pa.ar[0].y;
|
|
385 |
Bottom:= Top;
|
|
386 |
|
|
387 |
for i:= 1 to Pred(pa.Count) do
|
|
388 |
with pa.ar[i] do
|
|
389 |
begin
|
|
390 |
if (y and $FFFFFC00) = 0 then
|
|
391 |
if x < Left then Left:= x else
|
|
392 |
if x > Right then Right:= x;
|
|
393 |
if y < Top then Top:= y else
|
|
394 |
if y > Bottom then Bottom:= y
|
|
395 |
end;
|
|
396 |
|
|
397 |
if (Left < brd) or (Right > 2047 - brd) then
|
|
398 |
begin
|
|
399 |
OLeft:= Left;
|
|
400 |
OWidth:= Right - OLeft;
|
|
401 |
if Left < brd then Left:= brd;
|
|
402 |
if Right > 2047 - brd then Right:= 2047 - brd;
|
|
403 |
Width:= Right - Left;
|
|
404 |
for i:= 0 to Pred(pa.Count) do
|
|
405 |
with pa.ar[i] do
|
|
406 |
x:= round((x - OLeft) * Width div OWidth + Left)
|
|
407 |
end;
|
|
408 |
|
|
409 |
if isUp then // FIXME: remove hack
|
|
410 |
if Top < brd then
|
|
411 |
begin
|
|
412 |
OHeight:= 1023 - Top;
|
|
413 |
Height:= 1023 - brd;
|
|
414 |
for i:= 0 to Pred(pa.Count) do
|
|
415 |
with pa.ar[i] do
|
|
416 |
y:= round((y - 1023) * Height div OHeight + 1023)
|
|
417 |
end;
|
|
418 |
end;
|
|
419 |
|
23
|
420 |
procedure GenBlank(var Template: TEdgeTemplate);
|
4
|
421 |
var pa: TPixAr;
|
23
|
422 |
i: Longword;
|
4
|
423 |
begin
|
23
|
424 |
with Template do
|
|
425 |
begin
|
27
|
426 |
if canMirror then
|
|
427 |
if getrandom(16) < 8 then
|
|
428 |
begin
|
|
429 |
for i:= 0 to pred(BasePointsCount) do
|
|
430 |
BasePoints^[i].x:= 2047 - BasePoints^[i].x;
|
|
431 |
for i:= 0 to pred(FillPointsCount) do
|
|
432 |
FillPoints^[i].x:= 2047 - FillPoints^[i].x;
|
|
433 |
end;
|
|
434 |
|
|
435 |
if canFlip then
|
|
436 |
if getrandom(16) < 8 then
|
|
437 |
begin
|
|
438 |
for i:= 0 to pred(BasePointsCount) do
|
|
439 |
BasePoints^[i].y:= 1023 - BasePoints^[i].y;
|
|
440 |
for i:= 0 to pred(FillPointsCount) do
|
|
441 |
FillPoints^[i].y:= 1023 - FillPoints^[i].y;
|
|
442 |
end;
|
|
443 |
|
23
|
444 |
pa.Count:= BasePointsCount;
|
|
445 |
for i:= 0 to pred(pa.Count) do
|
|
446 |
pa.ar[i]:= BasePoints^[i];
|
|
447 |
|
|
448 |
for i:= 1 to BezPassCnt do
|
|
449 |
BezierizeEdge(pa, 0.33333334);
|
|
450 |
|
|
451 |
PointWave(Template, pa);
|
67
|
452 |
NormalizePoints(pa);
|
23
|
453 |
DrawBezierEdge(pa);
|
|
454 |
|
|
455 |
for i:= 0 to pred(FillPointsCount) do
|
|
456 |
with FillPoints^[i] do
|
|
457 |
FillLand(x, y)
|
|
458 |
end;
|
|
459 |
end;
|
|
460 |
|
|
461 |
procedure GenLandSurface;
|
|
462 |
var tmpsurf: PSDL_Surface;
|
51
|
463 |
i: Longword;
|
23
|
464 |
begin
|
53
|
465 |
WriteLnToConsole('Generating land...');
|
51
|
466 |
for i:= 0 to sizeof(Land) div 4 do
|
64
|
467 |
PLongword(Longword(@Land) + i * 4)^:= COLOR_LAND;
|
53
|
468 |
GenBlank(EdgeTemplates[getrandom(Succ(High(EdgeTemplates)))]);
|
22
|
469 |
|
4
|
470 |
AddProgress;
|
|
471 |
with PixelFormat^ do
|
|
472 |
tmpsurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, 0);
|
67
|
473 |
TryDo(tmpsurf <> nil, 'Error creating pre-land surface', true);
|
4
|
474 |
ColorizeLand(tmpsurf);
|
|
475 |
AddProgress;
|
|
476 |
AddBorder(tmpsurf);
|
|
477 |
with PixelFormat^ do
|
|
478 |
LandSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, 0);
|
67
|
479 |
TryDo(LandSurface <> nil, 'Error creating land surface', true);
|
4
|
480 |
SDL_FillRect(LandSurface, nil, 0);
|
27
|
481 |
AddProgress;
|
24
|
482 |
|
70
|
483 |
SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0);
|
|
484 |
AddObjects(tmpsurf, LandSurface);
|
|
485 |
SDL_FreeSurface(tmpsurf);
|
24
|
486 |
|
70
|
487 |
AddProgress
|
4
|
488 |
end;
|
|
489 |
|
|
490 |
procedure MakeFortsMap;
|
|
491 |
var p: PTeam;
|
|
492 |
tmpsurf: PSDL_Surface;
|
|
493 |
begin
|
53
|
494 |
WriteLnToConsole('Generating forts land...');
|
4
|
495 |
p:= TeamsList;
|
|
496 |
TryDo(p <> nil, 'No teams on map!', true);
|
|
497 |
with PixelFormat^ do
|
|
498 |
LandSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, 0);
|
37
|
499 |
SDL_FillRect(LandSurface, nil, 0);
|
74
|
500 |
tmpsurf:= LoadImage(Pathz[ptForts] + '/' + p.FortName + 'L', false);
|
4
|
501 |
BlitImageAndGenerateCollisionInfo(0, 0, tmpsurf, LandSurface);
|
|
502 |
SDL_FreeSurface(tmpsurf);
|
|
503 |
p:= p.Next;
|
|
504 |
TryDo(p <> nil, 'Only one team on map!', true);
|
74
|
505 |
tmpsurf:= LoadImage(Pathz[ptForts] + '/' + p.FortName + 'R', false);
|
4
|
506 |
BlitImageAndGenerateCollisionInfo(1024, 0, tmpsurf, LandSurface);
|
|
507 |
SDL_FreeSurface(tmpsurf);
|
|
508 |
p:= p.Next;
|
|
509 |
TryDo(p = nil, 'More than 2 teams on map in forts mode!', true);
|
|
510 |
end;
|
|
511 |
|
53
|
512 |
procedure LoadMap;
|
|
513 |
var p, x, y, i: Longword;
|
|
514 |
begin
|
|
515 |
WriteLnToConsole('Loading land from file...');
|
|
516 |
AddProgress;
|
74
|
517 |
LandSurface:= LoadImage(Pathz[ptMapCurrent] + '/map', false);
|
53
|
518 |
TryDo((LandSurface.w = 2048) and (LandSurface.h = 1024), 'Map dimensions should be 2048x1024!', true);
|
|
519 |
|
|
520 |
if SDL_MustLock(LandSurface) then
|
|
521 |
SDLTry(SDL_LockSurface(LandSurface) >= 0, true);
|
|
522 |
|
|
523 |
p:= Longword(LandSurface.pixels);
|
|
524 |
i:= Longword(@Land);
|
|
525 |
case LandSurface.format.BytesPerPixel of
|
|
526 |
1: OutError('We don''t work with 8 bit surfaces', true);
|
|
527 |
2: for y:= 0 to 1023 do
|
|
528 |
begin
|
|
529 |
for x:= 0 to 2047 do
|
64
|
530 |
if PWord(p + x * 2)^ <> 0 then PLongWord(i + x * 4)^:= COLOR_LAND;
|
53
|
531 |
inc(i, 2048 * 4);
|
|
532 |
inc(p, LandSurface.pitch);
|
|
533 |
end;
|
|
534 |
3: for y:= 0 to 1023 do
|
|
535 |
begin
|
|
536 |
for x:= 0 to 2047 do
|
|
537 |
if (PByte(p + x * 3 + 0)^ <> 0)
|
|
538 |
or (PByte(p + x * 3 + 1)^ <> 0)
|
64
|
539 |
or (PByte(p + x * 3 + 2)^ <> 0) then PLongWord(i + x * 4)^:= COLOR_LAND;
|
53
|
540 |
inc(i, 2048 * 4);
|
|
541 |
inc(p, LandSurface.pitch);
|
|
542 |
end;
|
|
543 |
4: for y:= 0 to 1023 do
|
|
544 |
begin
|
|
545 |
for x:= 0 to 2047 do
|
64
|
546 |
if PLongword(p + x * 4)^ <> 0 then PLongWord(i + x * 4)^:= COLOR_LAND;
|
53
|
547 |
inc(i, 2048 * 4);
|
|
548 |
inc(p, LandSurface.pitch);
|
|
549 |
end;
|
|
550 |
end;
|
|
551 |
if SDL_MustLock(LandSurface) then
|
|
552 |
SDL_UnlockSurface(LandSurface);
|
|
553 |
end;
|
|
554 |
|
37
|
555 |
procedure GenMap;
|
|
556 |
begin
|
53
|
557 |
if (GameFlags and gfForts) = 0 then
|
|
558 |
if Pathz[ptMapCurrent] <> '' then LoadMap
|
|
559 |
else GenLandSurface
|
37
|
560 |
else MakeFortsMap;
|
|
561 |
AddProgress;
|
|
562 |
{$IFDEF DEBUGFILE}LogLandDigest{$ENDIF}
|
|
563 |
end;
|
|
564 |
|
51
|
565 |
initialization
|
|
566 |
|
4
|
567 |
end.
|