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