author | unc0rr |
Thu, 19 Jan 2006 21:12:20 +0000 | |
changeset 53 | 0e27949850e3 |
parent 51 | b6e3ae05857f |
child 54 | 839fd258ae6f |
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); |
|
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 |
|
51 | 130 |
Land[y, x]:= 0; |
4 | 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); |
|
51 | 247 |
while (xl > 0) and (Land[y, xl] <> 0) do dec(xl); |
248 |
while (xr < 2047) and (Land[y, xr] <> 0) do inc(xr); |
|
4 | 249 |
while (xl < xr) do |
250 |
begin |
|
51 | 251 |
while (xl <= xr) and (Land[y, xl] = 0) do inc(xl); |
4 | 252 |
x:= xl; |
51 | 253 |
while (xl <= xr) and (Land[y, xl] <> 0) do |
4 | 254 |
begin |
51 | 255 |
Land[y, xl]:= 0; |
4 | 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; |
53 | 405 |
{$IFDEF DEBUGFILE} |
406 |
AddFileLog('Wave params ¹' + inttostr(i) + ':'); |
|
407 |
AddFileLog('X: ampl = ' + floattostr(ar[i, 0]) + '; freq = ' + floattostr(ar[i, 1]) + '; shift = ' + floattostr(ar[i, 2])); |
|
408 |
AddFileLog('Y: ampl = ' + floattostr(ar[i, 3]) + '; freq = ' + floattostr(ar[i, 4]) + '; shift = ' + floattostr(ar[i, 5])); |
|
409 |
{$ENDIF} |
|
23 | 410 |
end; |
411 |
end; |
|
22 | 412 |
|
413 |
for k:= 0 to Pred(pa.Count) do // apply transformation |
|
414 |
begin |
|
415 |
rx:= pa.ar[k].x; |
|
416 |
ry:= pa.ar[k].y; |
|
24 | 417 |
for i:= 1 to PassesNum do |
22 | 418 |
begin |
419 |
oy:= ry; |
|
420 |
ry:= ry + ar[i, 0] * sin(ar[i, 1] * rx + ar[i, 2]); |
|
421 |
rx:= rx + ar[i, 3] * sin(ar[i, 4] * oy + ar[i, 5]); |
|
422 |
end; |
|
24 | 423 |
pa.ar[k].x:= round(rx); |
424 |
pa.ar[k].y:= round(ry); |
|
425 |
end; |
|
4 | 426 |
end; |
427 |
||
23 | 428 |
procedure GenBlank(var Template: TEdgeTemplate); |
4 | 429 |
var pa: TPixAr; |
23 | 430 |
i: Longword; |
4 | 431 |
begin |
23 | 432 |
with Template do |
433 |
begin |
|
27 | 434 |
if canMirror then |
435 |
if getrandom(16) < 8 then |
|
436 |
begin |
|
437 |
for i:= 0 to pred(BasePointsCount) do |
|
438 |
BasePoints^[i].x:= 2047 - BasePoints^[i].x; |
|
439 |
for i:= 0 to pred(FillPointsCount) do |
|
440 |
FillPoints^[i].x:= 2047 - FillPoints^[i].x; |
|
441 |
end; |
|
442 |
||
443 |
if canFlip then |
|
444 |
if getrandom(16) < 8 then |
|
445 |
begin |
|
446 |
for i:= 0 to pred(BasePointsCount) do |
|
447 |
BasePoints^[i].y:= 1023 - BasePoints^[i].y; |
|
448 |
for i:= 0 to pred(FillPointsCount) do |
|
449 |
FillPoints^[i].y:= 1023 - FillPoints^[i].y; |
|
450 |
end; |
|
451 |
||
23 | 452 |
pa.Count:= BasePointsCount; |
453 |
for i:= 0 to pred(pa.Count) do |
|
454 |
pa.ar[i]:= BasePoints^[i]; |
|
455 |
||
456 |
for i:= 1 to BezPassCnt do |
|
457 |
BezierizeEdge(pa, 0.33333334); |
|
458 |
||
459 |
PointWave(Template, pa); |
|
460 |
DrawBezierEdge(pa); |
|
461 |
||
462 |
for i:= 0 to pred(FillPointsCount) do |
|
463 |
with FillPoints^[i] do |
|
464 |
FillLand(x, y) |
|
465 |
end; |
|
466 |
end; |
|
467 |
||
468 |
procedure GenLandSurface; |
|
469 |
var tmpsurf: PSDL_Surface; |
|
51 | 470 |
i: Longword; |
23 | 471 |
begin |
53 | 472 |
WriteLnToConsole('Generating land...'); |
51 | 473 |
for i:= 0 to sizeof(Land) div 4 do |
474 |
PLongword(Longword(@Land) + i * 4)^:= $FFFFFF; |
|
53 | 475 |
GenBlank(EdgeTemplates[getrandom(Succ(High(EdgeTemplates)))]); |
22 | 476 |
|
4 | 477 |
AddProgress; |
478 |
with PixelFormat^ do |
|
479 |
tmpsurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, 0); |
|
480 |
ColorizeLand(tmpsurf); |
|
481 |
AddProgress; |
|
482 |
AddBorder(tmpsurf); |
|
483 |
with PixelFormat^ do |
|
484 |
LandSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, 0); |
|
485 |
SDL_FillRect(LandSurface, nil, 0); |
|
27 | 486 |
AddProgress; |
24 | 487 |
|
488 |
AddObjects(LandSurface); |
|
489 |
||
4 | 490 |
SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0); |
491 |
SDL_UpperBlit(tmpsurf, nil, LandSurface, nil); |
|
492 |
SDL_FreeSurface(tmpsurf); |
|
493 |
AddProgress; |
|
494 |
AddHHPoints; |
|
495 |
RandomizeHHPoints; |
|
496 |
end; |
|
497 |
||
498 |
procedure MakeFortsMap; |
|
499 |
var p: PTeam; |
|
500 |
tmpsurf: PSDL_Surface; |
|
501 |
begin |
|
53 | 502 |
WriteLnToConsole('Generating forts land...'); |
4 | 503 |
p:= TeamsList; |
504 |
TryDo(p <> nil, 'No teams on map!', true); |
|
505 |
with PixelFormat^ do |
|
506 |
LandSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, 0); |
|
37 | 507 |
SDL_FillRect(LandSurface, nil, 0); |
53 | 508 |
tmpsurf:= LoadImage(Pathz[ptForts] + '/' + p.FortName + 'L.png', false); |
4 | 509 |
BlitImageAndGenerateCollisionInfo(0, 0, tmpsurf, LandSurface); |
510 |
SDL_FreeSurface(tmpsurf); |
|
511 |
LoadFortPoints(p.FortName, false, TeamSize(p)); |
|
512 |
p:= p.Next; |
|
513 |
TryDo(p <> nil, 'Only one team on map!', true); |
|
53 | 514 |
tmpsurf:= LoadImage(Pathz[ptForts] + '/' + p.FortName + 'R.png', false); |
4 | 515 |
BlitImageAndGenerateCollisionInfo(1024, 0, tmpsurf, LandSurface); |
516 |
SDL_FreeSurface(tmpsurf); |
|
517 |
LoadFortPoints(p.FortName, true, TeamSize(p)); |
|
518 |
p:= p.Next; |
|
519 |
TryDo(p = nil, 'More than 2 teams on map in forts mode!', true); |
|
520 |
end; |
|
521 |
||
53 | 522 |
procedure LoadMap; |
523 |
var p, x, y, i: Longword; |
|
524 |
begin |
|
525 |
WriteLnToConsole('Loading land from file...'); |
|
526 |
AddProgress; |
|
527 |
LandSurface:= LoadImage(Pathz[ptMapCurrent] + '/map.png', false); |
|
528 |
TryDo((LandSurface.w = 2048) and (LandSurface.h = 1024), 'Map dimensions should be 2048x1024!', true); |
|
529 |
||
530 |
if SDL_MustLock(LandSurface) then |
|
531 |
SDLTry(SDL_LockSurface(LandSurface) >= 0, true); |
|
532 |
||
533 |
p:= Longword(LandSurface.pixels); |
|
534 |
i:= Longword(@Land); |
|
535 |
case LandSurface.format.BytesPerPixel of |
|
536 |
1: OutError('We don''t work with 8 bit surfaces', true); |
|
537 |
2: for y:= 0 to 1023 do |
|
538 |
begin |
|
539 |
for x:= 0 to 2047 do |
|
540 |
if PWord(p + x * 2)^ <> 0 then PLongWord(i + x * 4)^:= $FFFFFF; |
|
541 |
inc(i, 2048 * 4); |
|
542 |
inc(p, LandSurface.pitch); |
|
543 |
end; |
|
544 |
3: for y:= 0 to 1023 do |
|
545 |
begin |
|
546 |
for x:= 0 to 2047 do |
|
547 |
if (PByte(p + x * 3 + 0)^ <> 0) |
|
548 |
or (PByte(p + x * 3 + 1)^ <> 0) |
|
549 |
or (PByte(p + x * 3 + 2)^ <> 0) then PLongWord(i + x * 4)^:= $FFFFFF; |
|
550 |
inc(i, 2048 * 4); |
|
551 |
inc(p, LandSurface.pitch); |
|
552 |
end; |
|
553 |
4: for y:= 0 to 1023 do |
|
554 |
begin |
|
555 |
for x:= 0 to 2047 do |
|
556 |
if PLongword(p + x * 4)^ <> 0 then PLongWord(i + x * 4)^:= $FFFFFF; |
|
557 |
inc(i, 2048 * 4); |
|
558 |
inc(p, LandSurface.pitch); |
|
559 |
end; |
|
560 |
end; |
|
561 |
if SDL_MustLock(LandSurface) then |
|
562 |
SDL_UnlockSurface(LandSurface); |
|
563 |
||
564 |
AddHHPoints; |
|
565 |
RandomizeHHPoints; |
|
566 |
end; |
|
567 |
||
37 | 568 |
procedure GenMap; |
569 |
begin |
|
53 | 570 |
if (GameFlags and gfForts) = 0 then |
571 |
if Pathz[ptMapCurrent] <> '' then LoadMap |
|
572 |
else GenLandSurface |
|
37 | 573 |
else MakeFortsMap; |
574 |
AddProgress; |
|
575 |
{$IFDEF DEBUGFILE}LogLandDigest{$ENDIF} |
|
576 |
end; |
|
577 |
||
4 | 578 |
procedure AddHHPoint(_x, _y: integer); |
579 |
begin |
|
580 |
with HHPoints do |
|
581 |
begin |
|
582 |
inc(Last); |
|
22 | 583 |
TryDo(Last < cMaxSpawnPoints, 'HHs coords queue overflow', true); |
4 | 584 |
with ar[Last] do |
585 |
begin |
|
586 |
x:= _x; |
|
587 |
y:= _y |
|
588 |
end |
|
589 |
end |
|
590 |
end; |
|
591 |
||
592 |
procedure GetHHPoint(out _x, _y: integer); |
|
593 |
begin |
|
594 |
with HHPoints do |
|
595 |
begin |
|
596 |
TryDo(First <= Last, 'HHs coords queue underflow ' + inttostr(First), true); |
|
597 |
with ar[First] do |
|
598 |
begin |
|
599 |
_x:= x; |
|
600 |
_y:= y |
|
601 |
end; |
|
602 |
inc(First) |
|
603 |
end |
|
604 |
end; |
|
605 |
||
606 |
procedure RandomizeHHPoints; |
|
607 |
var i, t: integer; |
|
608 |
p: TPoint; |
|
609 |
begin |
|
610 |
with HHPoints do |
|
611 |
begin |
|
612 |
for i:= First to Last do |
|
613 |
begin |
|
614 |
t:= GetRandom(Last - First + 1) + First; |
|
615 |
if i <> t then |
|
616 |
begin |
|
617 |
p:= ar[i]; |
|
618 |
ar[i]:= ar[t]; |
|
619 |
ar[t]:= p |
|
620 |
end |
|
621 |
end |
|
622 |
end |
|
623 |
end; |
|
624 |
||
51 | 625 |
initialization |
626 |
||
627 |
HHPoints.First:= 1 |
|
628 |
||
4 | 629 |
end. |