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