author | unc0rr |
Fri, 26 Jan 2007 18:11:03 +0000 | |
changeset 367 | bc3c3edc5ce1 |
parent 365 | a26cec847dd7 |
child 368 | fe71e55d2d7b |
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 |
|
351 | 21 |
uses SDLh, uLandTemplates, uFloat; |
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; |
367 | 32 |
procedure CheckLandDigest(s: shortstring); |
4 | 33 |
|
34 |
implementation |
|
316 | 35 |
uses uConsole, uStore, uMisc, uConsts, uRandom, uTeams, uLandObjects, uSHA, uIO; |
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; |
316 | 43 |
var ctx: TSHA1Context; |
44 |
dig: TSHA1Digest; |
|
45 |
s: shortstring; |
|
37 | 46 |
begin |
316 | 47 |
SHA1Init(ctx); |
48 |
SHA1Update(ctx, @Land, sizeof(Land)); |
|
49 |
dig:= SHA1Final(ctx); |
|
367 | 50 |
s:='M{'+inttostr(dig[0])+':' |
316 | 51 |
+inttostr(dig[1])+':' |
52 |
+inttostr(dig[2])+':' |
|
53 |
+inttostr(dig[3])+':' |
|
54 |
+inttostr(dig[4])+'}'; |
|
367 | 55 |
CheckLandDigest(s); |
56 |
SendIPCRaw(@s[0], Length(s) + 1) |
|
57 |
end; |
|
58 |
||
59 |
procedure CheckLandDigest(s: shortstring); |
|
60 |
const digest: shortstring = ''; |
|
61 |
begin |
|
62 |
if digest = '' then |
|
63 |
digest:= s |
|
64 |
else |
|
65 |
TryDo(s = digest, 'Different maps generated, sorry', true) |
|
37 | 66 |
end; |
67 |
||
358 | 68 |
procedure DrawLine(X1, Y1, X2, Y2: integer; Color: Longword); |
69 |
var |
|
70 |
eX, eY, dX, dY: integer; |
|
71 |
i, sX, sY, x, y, d: integer; |
|
72 |
begin |
|
73 |
eX:= 0; |
|
74 |
eY:= 0; |
|
75 |
dX:= X2 - X1; |
|
76 |
dY:= Y2 - Y1; |
|
77 |
||
78 |
if (dX > 0) then sX:= 1 |
|
79 |
else |
|
80 |
if (dX < 0) then |
|
81 |
begin |
|
82 |
sX:= -1; |
|
83 |
dX:= -dX |
|
84 |
end else sX:= dX; |
|
85 |
||
86 |
if (dY > 0) then sY:= 1 |
|
87 |
else |
|
88 |
if (dY < 0) then |
|
89 |
begin |
|
90 |
sY:= -1; |
|
91 |
dY:= -dY |
|
92 |
end else sY:= dY; |
|
93 |
||
94 |
if (dX > dY) then d:= dX |
|
95 |
else d:= dY; |
|
96 |
||
97 |
x:= X1; |
|
98 |
y:= Y1; |
|
99 |
||
100 |
for i:= 0 to d do |
|
101 |
begin |
|
102 |
inc(eX, dX); |
|
103 |
inc(eY, dY); |
|
104 |
if (eX > d) then |
|
105 |
begin |
|
106 |
dec(eX, d); |
|
107 |
inc(x, sX); |
|
108 |
end; |
|
109 |
if (eY > d) then |
|
110 |
begin |
|
111 |
dec(eY, d); |
|
112 |
inc(y, sY); |
|
113 |
end; |
|
364 | 114 |
|
358 | 115 |
if ((x and $FFFFF800) = 0) and ((y and $FFFFFC00) = 0) then |
116 |
Land[y, x]:= Color; |
|
117 |
end |
|
118 |
end; |
|
119 |
||
365 | 120 |
procedure DrawEdge(var pa: TPixAr; Color: Longword); |
121 |
var i: integer; |
|
4 | 122 |
begin |
365 | 123 |
i:= 0; |
4 | 124 |
with pa do |
365 | 125 |
while i < integer(Count) - 1 do |
126 |
if (ar[i + 1].X = NTPX) then inc(i, 2) |
|
127 |
else begin |
|
128 |
DrawLine(ar[i].x, ar[i].y, ar[i + 1].x, ar[i + 1].y, Color); |
|
129 |
inc(i) |
|
130 |
end |
|
22 | 131 |
end; |
132 |
||
365 | 133 |
procedure Vector(p1, p2, p3: TPoint; var Vx, Vy: hwFloat); |
134 |
var d1, d2, d: hwFloat; |
|
364 | 135 |
begin |
365 | 136 |
Vx:= p1.X - p3.X; |
137 |
Vy:= p1.Y - p3.Y; |
|
138 |
d:= Distance(p2.X - p1.X, p2.Y - p1.Y); |
|
139 |
d1:= Distance(p2.X - p3.X, p2.Y - p3.Y); |
|
140 |
d2:= Distance(Vx, Vy); |
|
141 |
if d1 < d then d:= d1; |
|
142 |
if d2 < d then d:= d2; |
|
143 |
d:= d * _1div3; |
|
144 |
if d2.QWordValue = 0 then |
|
145 |
begin |
|
146 |
Vx:= 0; |
|
147 |
Vy:= 0 |
|
148 |
end else |
|
149 |
begin |
|
150 |
d2:= 1 / d2; |
|
151 |
Vx:= Vx * d2; |
|
152 |
Vy:= Vy * d2; |
|
153 |
||
154 |
Vx:= Vx * d; |
|
155 |
Vy:= Vy * d |
|
156 |
end |
|
157 |
end; |
|
158 |
||
159 |
procedure AddLoopPoints(var pa, opa: TPixAr; StartI, EndI: integer; Delta: hwFloat); |
|
160 |
var i, pi, ni: integer; |
|
161 |
NVx, NVy, PVx, PVy: hwFloat; |
|
162 |
x1, x2, y1, y2, cx1, cx2, cy1, cy2: hwFloat; |
|
163 |
tsq, tcb, t, r1, r2, r3, r4: hwFloat; |
|
164 |
X, Y: integer; |
|
165 |
begin |
|
166 |
pi:= EndI; |
|
167 |
i:= StartI; |
|
168 |
ni:= Succ(StartI); |
|
169 |
Vector(opa.ar[pi], opa.ar[i], opa.ar[ni], NVx, NVy); |
|
170 |
repeat |
|
171 |
inc(pi); |
|
172 |
if pi > EndI then pi:= StartI; |
|
173 |
inc(i); |
|
174 |
if i > EndI then i:= StartI; |
|
175 |
inc(ni); |
|
176 |
if ni > EndI then ni:= StartI; |
|
177 |
PVx:= NVx; |
|
178 |
PVy:= NVy; |
|
179 |
Vector(opa.ar[pi], opa.ar[i], opa.ar[ni], NVx, NVy); |
|
180 |
||
181 |
x1:= opa.ar[pi].x; |
|
182 |
y1:= opa.ar[pi].y; |
|
183 |
x2:= opa.ar[i].x; |
|
184 |
y2:= opa.ar[i].y; |
|
185 |
cx1:= x1 - PVx; |
|
186 |
cy1:= y1 - PVy; |
|
187 |
cx2:= x2 + NVx; |
|
188 |
cy2:= y2 + NVy; |
|
364 | 189 |
t:= 0; |
190 |
while t.Round = 0 do |
|
191 |
begin |
|
192 |
tsq:= t * t; |
|
193 |
tcb:= tsq * t; |
|
194 |
r1:= (1 - 3*t + 3*tsq - tcb) * x1; |
|
195 |
r2:= ( 3*t - 6*tsq + 3*tcb) * cx1; |
|
196 |
r3:= ( 3*tsq - 3*tcb) * cx2; |
|
197 |
r4:= ( tcb) * x2; |
|
198 |
X:= hwRound(r1 + r2 + r3 + r4); |
|
199 |
r1:= (1 - 3*t + 3*tsq - tcb) * y1; |
|
200 |
r2:= ( 3*t - 6*tsq + 3*tcb) * cy1; |
|
201 |
r3:= ( 3*tsq - 3*tcb) * cy2; |
|
202 |
r4:= ( tcb) * y2; |
|
203 |
Y:= hwRound(r1 + r2 + r3 + r4); |
|
204 |
t:= t + Delta; |
|
205 |
pa.ar[pa.Count].x:= X; |
|
206 |
pa.ar[pa.Count].y:= Y; |
|
207 |
inc(pa.Count); |
|
208 |
TryDo(pa.Count <= cMaxEdgePoints, 'Edge points overflow', true) |
|
209 |
end; |
|
365 | 210 |
until i = StartI; |
211 |
pa.ar[pa.Count].x:= opa.ar[StartI].X; |
|
212 |
pa.ar[pa.Count].y:= opa.ar[StartI].Y; |
|
364 | 213 |
inc(pa.Count) |
214 |
end; |
|
215 |
||
365 | 216 |
procedure BezierizeEdge(var pa: TPixAr; Delta: hwFloat); |
217 |
var x, y, i, StartLoop: integer; |
|
218 |
opa: TPixAr; |
|
219 |
begin |
|
220 |
opa:= pa; |
|
221 |
pa.Count:= 0; |
|
222 |
i:= 0; |
|
223 |
StartLoop:= 0; |
|
224 |
while i < integer(opa.Count) do |
|
225 |
if (opa.ar[i + 1].X = NTPX) then |
|
226 |
begin |
|
227 |
AddLoopPoints(pa, opa, StartLoop, i, Delta); |
|
228 |
inc(i, 2); |
|
229 |
StartLoop:= i; |
|
230 |
pa.ar[pa.Count].X:= NTPX; |
|
231 |
inc(pa.Count); |
|
232 |
end else inc(i) |
|
233 |
end; |
|
234 |
||
4 | 235 |
procedure FillLand(x, y: integer); |
236 |
var Stack: record |
|
237 |
Count: Longword; |
|
238 |
points: array[0..8192] of record |
|
239 |
xl, xr, y, dir: integer; |
|
240 |
end |
|
241 |
end; |
|
242 |
||
243 |
procedure Push(_xl, _xr, _y, _dir: integer); |
|
244 |
begin |
|
75 | 245 |
TryDo(Stack.Count <= 8192, 'FillLand: stack overflow', true); |
4 | 246 |
_y:= _y + _dir; |
247 |
if (_y < 0) or (_y > 1023) then exit; |
|
248 |
with Stack.points[Stack.Count] do |
|
249 |
begin |
|
250 |
xl:= _xl; |
|
251 |
xr:= _xr; |
|
252 |
y:= _y; |
|
253 |
dir:= _dir |
|
254 |
end; |
|
75 | 255 |
inc(Stack.Count) |
4 | 256 |
end; |
257 |
||
351 | 258 |
procedure Pop(var _xl, _xr, _y, _dir: integer); |
4 | 259 |
begin |
260 |
dec(Stack.Count); |
|
261 |
with Stack.points[Stack.Count] do |
|
262 |
begin |
|
263 |
_xl:= xl; |
|
264 |
_xr:= xr; |
|
265 |
_y:= y; |
|
266 |
_dir:= dir |
|
267 |
end |
|
268 |
end; |
|
269 |
||
270 |
var xl, xr, dir: integer; |
|
351 | 271 |
begin |
4 | 272 |
Stack.Count:= 0; |
273 |
xl:= x - 1; |
|
274 |
xr:= x; |
|
23 | 275 |
Push(xl, xr, y, -1); |
276 |
Push(xl, xr, y, 1); |
|
4 | 277 |
while Stack.Count > 0 do |
278 |
begin |
|
279 |
Pop(xl, xr, y, dir); |
|
51 | 280 |
while (xl > 0) and (Land[y, xl] <> 0) do dec(xl); |
281 |
while (xr < 2047) and (Land[y, xr] <> 0) do inc(xr); |
|
4 | 282 |
while (xl < xr) do |
283 |
begin |
|
51 | 284 |
while (xl <= xr) and (Land[y, xl] = 0) do inc(xl); |
4 | 285 |
x:= xl; |
51 | 286 |
while (xl <= xr) and (Land[y, xl] <> 0) do |
4 | 287 |
begin |
51 | 288 |
Land[y, xl]:= 0; |
4 | 289 |
inc(xl) |
290 |
end; |
|
22 | 291 |
if x < xl then |
292 |
begin |
|
293 |
Push(x, Pred(xl), y, dir); |
|
294 |
Push(x, Pred(xl), y,-dir); |
|
295 |
end; |
|
4 | 296 |
end; |
297 |
end; |
|
298 |
end; |
|
299 |
||
300 |
procedure ColorizeLand(Surface: PSDL_Surface); |
|
301 |
var tmpsurf: PSDL_Surface; |
|
302 |
r: TSDL_Rect; |
|
303 |
begin |
|
351 | 304 |
tmpsurf:= LoadImage(Pathz[ptCurrTheme] + '/LandTex', false, true, true); |
4 | 305 |
r.y:= 0; |
306 |
while r.y < 1024 do |
|
307 |
begin |
|
308 |
r.x:= 0; |
|
309 |
while r.x < 2048 do |
|
310 |
begin |
|
311 |
SDL_UpperBlit(tmpsurf, nil, Surface, @r); |
|
351 | 312 |
inc(r.x, tmpsurf^.w) |
4 | 313 |
end; |
351 | 314 |
inc(r.y, tmpsurf^.h) |
4 | 315 |
end; |
316 |
SDL_FreeSurface(tmpsurf); |
|
317 |
||
318 |
tmpsurf:= SDL_CreateRGBSurfaceFrom(@Land, 2048, 1024, 32, 2048*4, $FF0000, $FF00, $FF, 0); |
|
319 |
SDLTry(tmpsurf <> nil, true); |
|
351 | 320 |
SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, SDL_MapRGB(tmpsurf^.format, $FF, $FF, $FF)); |
22 | 321 |
SDL_UpperBlit(tmpsurf, nil, Surface, nil); |
322 |
SDL_FreeSurface(tmpsurf) |
|
4 | 323 |
end; |
324 |
||
325 |
procedure AddBorder(Surface: PSDL_Surface); |
|
326 |
var tmpsurf: PSDL_Surface; |
|
327 |
r, rr: TSDL_Rect; |
|
328 |
x, yd, yu: integer; |
|
329 |
begin |
|
351 | 330 |
tmpsurf:= LoadImage(Pathz[ptCurrTheme] + '/Border', false, true, true); |
4 | 331 |
for x:= 0 to 2047 do |
332 |
begin |
|
333 |
yd:= 1023; |
|
334 |
repeat |
|
335 |
while (yd > 0 ) and (Land[yd, x] = 0) do dec(yd); |
|
336 |
if (yd < 0) then yd:= 0; |
|
337 |
while (yd < 1024) and (Land[yd, x] <> 0) do inc(yd); |
|
338 |
dec(yd); |
|
339 |
yu:= yd; |
|
340 |
while (yu > 0 ) and (Land[yu, x] <> 0) do dec(yu); |
|
341 |
while (yu < yd ) and (Land[yu, x] = 0) do inc(yu); |
|
342 |
if (yd < 1023) and ((yd - yu) >= 16) then |
|
343 |
begin |
|
344 |
rr.x:= x; |
|
345 |
rr.y:= yd - 15; |
|
351 | 346 |
r.x:= x mod tmpsurf^.w; |
4 | 347 |
r.y:= 16; |
348 |
r.w:= 1; |
|
349 |
r.h:= 16; |
|
350 |
SDL_UpperBlit(tmpsurf, @r, Surface, @rr); |
|
351 |
end; |
|
352 |
if (yu > 0) then |
|
353 |
begin |
|
354 |
rr.x:= x; |
|
355 |
rr.y:= yu; |
|
351 | 356 |
r.x:= x mod tmpsurf^.w; |
4 | 357 |
r.y:= 0; |
358 |
r.w:= 1; |
|
359 |
r.h:= min(16, yd - yu + 1); |
|
360 |
SDL_UpperBlit(tmpsurf, @r, Surface, @rr); |
|
361 |
end; |
|
362 |
yd:= yu - 1; |
|
363 |
until yd < 0; |
|
364 |
end; |
|
365 |
end; |
|
366 |
||
358 | 367 |
procedure SetPoints(var Template: TEdgeTemplate; var pa: TPixAr); |
368 |
var i: integer; |
|
22 | 369 |
begin |
23 | 370 |
with Template do |
371 |
begin |
|
358 | 372 |
pa.Count:= BasePointsCount; |
373 |
for i:= 0 to pred(pa.Count) do |
|
23 | 374 |
begin |
358 | 375 |
pa.ar[i].x:= BasePoints^[i].x + integer(GetRandom(BasePoints^[i].w)); |
376 |
pa.ar[i].y:= BasePoints^[i].y + integer(GetRandom(BasePoints^[i].h)) |
|
23 | 377 |
end; |
358 | 378 |
|
379 |
if canMirror then |
|
360 | 380 |
if getrandom(2) = 0 then |
358 | 381 |
begin |
382 |
for i:= 0 to pred(BasePointsCount) do |
|
365 | 383 |
if pa.ar[i].x <> NTPX then |
360 | 384 |
pa.ar[i].x:= 2047 - pa.ar[i].x; |
358 | 385 |
for i:= 0 to pred(FillPointsCount) do |
386 |
FillPoints^[i].x:= 2047 - FillPoints^[i].x; |
|
387 |
end; |
|
22 | 388 |
|
358 | 389 |
if canFlip then |
360 | 390 |
if getrandom(2) = 0 then |
358 | 391 |
begin |
392 |
for i:= 0 to pred(BasePointsCount) do |
|
360 | 393 |
pa.ar[i].y:= 1023 - pa.ar[i].y; |
358 | 394 |
for i:= 0 to pred(FillPointsCount) do |
395 |
FillPoints^[i].y:= 1023 - FillPoints^[i].y; |
|
396 |
end; |
|
397 |
end |
|
4 | 398 |
end; |
67 | 399 |
|
365 | 400 |
procedure RandomizePoints(var pa: TPixAr; MaxRad: integer); |
364 | 401 |
const cEdge = 55; |
365 | 402 |
cMinDist = 0; |
364 | 403 |
var radz: array[0..Pred(cMaxEdgePoints)] of integer; |
404 |
i, k, dist: integer; |
|
405 |
begin |
|
406 |
radz[0]:= 0; |
|
407 |
for i:= 0 to Pred(pa.Count) do |
|
408 |
with pa.ar[i] do |
|
365 | 409 |
if x <> NTPX then |
410 |
begin |
|
411 |
radz[i]:= Min(Max(x - cEdge, 0), Max(2048 - cEdge - x, 0)); |
|
412 |
radz[i]:= Min(radz[i], Min(Max(y - cEdge, 0), Max(1024 - cEdge - y, 0))); |
|
413 |
if radz[i] > 0 then |
|
414 |
for k:= 0 to Pred(i) do |
|
364 | 415 |
begin |
365 | 416 |
dist:= Min(Max(abs(x - pa.ar[k].x), abs(y - pa.ar[k].y)), MaxRad); |
417 |
radz[k]:= Max(0, Min((dist - cMinDist) div 2, radz[k])); |
|
418 |
radz[i]:= Max(0, Min(dist - radz[k] - cMinDist, radz[i])) |
|
419 |
end |
|
420 |
end; |
|
364 | 421 |
|
422 |
for i:= 0 to Pred(pa.Count) do |
|
423 |
with pa.ar[i] do |
|
424 |
if ((x and $FFFFF800) = 0) and ((y and $FFFFFC00) = 0) then |
|
425 |
begin |
|
365 | 426 |
x:= x + integer(GetRandom(7) - 3) * (radz[i] * 5 div 7) div 3; |
427 |
y:= y + integer(GetRandom(7) - 3) * (radz[i] * 5 div 7) div 3 |
|
364 | 428 |
end |
67 | 429 |
end; |
430 |
||
364 | 431 |
|
23 | 432 |
procedure GenBlank(var Template: TEdgeTemplate); |
4 | 433 |
var pa: TPixAr; |
23 | 434 |
i: Longword; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
435 |
y, x: Longword; |
4 | 436 |
begin |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
437 |
for y:= 0 to 1023 do |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
438 |
for x:= 0 to 2047 do |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
439 |
Land[y, x]:= COLOR_LAND; |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
440 |
|
358 | 441 |
SetPoints(Template, pa); |
364 | 442 |
BezierizeEdge(pa, _1div3); |
365 | 443 |
for i:= 0 to Pred(Template.RandPassesCount) do RandomizePoints(pa, 1000); |
444 |
BezierizeEdge(pa, _1div3); |
|
445 |
RandomizePoints(pa, 1000); |
|
446 |
BezierizeEdge(pa, _0_1); |
|
27 | 447 |
|
365 | 448 |
DrawEdge(pa, 0); |
27 | 449 |
|
358 | 450 |
with Template do |
23 | 451 |
for i:= 0 to pred(FillPointsCount) do |
452 |
with FillPoints^[i] do |
|
89 | 453 |
FillLand(x, y); |
454 |
||
365 | 455 |
DrawEdge(pa, COLOR_LAND) |
23 | 456 |
end; |
457 |
||
161 | 458 |
function SelectTemplate: integer; |
459 |
begin |
|
351 | 460 |
SelectTemplate:= getrandom(Succ(High(EdgeTemplates))) |
161 | 461 |
end; |
462 |
||
23 | 463 |
procedure GenLandSurface; |
464 |
var tmpsurf: PSDL_Surface; |
|
465 |
begin |
|
53 | 466 |
WriteLnToConsole('Generating land...'); |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
467 |
|
161 | 468 |
GenBlank(EdgeTemplates[SelectTemplate]); |
22 | 469 |
|
4 | 470 |
AddProgress; |
471 |
with PixelFormat^ do |
|
191
a03c2d037e24
Bots are in the same thread as game. Fixes FreePascal issues.
unc0rr
parents:
183
diff
changeset
|
472 |
tmpsurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, AMask); |
67 | 473 |
TryDo(tmpsurf <> nil, 'Error creating pre-land surface', true); |
4 | 474 |
ColorizeLand(tmpsurf); |
475 |
AddProgress; |
|
476 |
AddBorder(tmpsurf); |
|
477 |
with PixelFormat^ do |
|
191
a03c2d037e24
Bots are in the same thread as game. Fixes FreePascal issues.
unc0rr
parents:
183
diff
changeset
|
478 |
LandSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, AMask); |
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 |
|
191
a03c2d037e24
Bots are in the same thread as game. Fixes FreePascal issues.
unc0rr
parents:
183
diff
changeset
|
498 |
LandSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, AMask); |
37 | 499 |
SDL_FillRect(LandSurface, nil, 0); |
351 | 500 |
tmpsurf:= LoadImage(Pathz[ptForts] + '/' + p^.FortName + 'L', false, true, true); |
4 | 501 |
BlitImageAndGenerateCollisionInfo(0, 0, tmpsurf, LandSurface); |
502 |
SDL_FreeSurface(tmpsurf); |
|
351 | 503 |
p:= p^.Next; |
4 | 504 |
TryDo(p <> nil, 'Only one team on map!', true); |
351 | 505 |
tmpsurf:= LoadImage(Pathz[ptForts] + '/' + p^.FortName + 'R', false, true, true); |
4 | 506 |
BlitImageAndGenerateCollisionInfo(1024, 0, tmpsurf, LandSurface); |
507 |
SDL_FreeSurface(tmpsurf); |
|
351 | 508 |
p:= p^.Next; |
4 | 509 |
TryDo(p = nil, 'More than 2 teams on map in forts mode!', true); |
510 |
end; |
|
511 |
||
53 | 512 |
procedure LoadMap; |
107 | 513 |
var x, y: Longword; |
514 |
p: PByteArray; |
|
53 | 515 |
begin |
516 |
WriteLnToConsole('Loading land from file...'); |
|
517 |
AddProgress; |
|
351 | 518 |
LandSurface:= LoadImage(Pathz[ptMapCurrent] + '/map', false, true, true); |
519 |
TryDo((LandSurface^.w = 2048) and (LandSurface^.h = 1024), 'Map dimensions should be 2048x1024!', true); |
|
53 | 520 |
|
521 |
if SDL_MustLock(LandSurface) then |
|
522 |
SDLTry(SDL_LockSurface(LandSurface) >= 0, true); |
|
523 |
||
351 | 524 |
p:= LandSurface^.pixels; |
525 |
case LandSurface^.format^.BytesPerPixel of |
|
53 | 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 |
|
351 | 530 |
if PWord(@(p^[x * 2]))^ <> 0 then Land[y, x]:= COLOR_LAND; |
531 |
p:= @(p^[LandSurface^.pitch]); |
|
53 | 532 |
end; |
533 |
3: for y:= 0 to 1023 do |
|
534 |
begin |
|
535 |
for x:= 0 to 2047 do |
|
351 | 536 |
if (p^[x * 3 + 0] <> 0) |
537 |
or (p^[x * 3 + 1] <> 0) |
|
538 |
or (p^[x * 3 + 2] <> 0) then Land[y, x]:= COLOR_LAND; |
|
539 |
p:= @(p^[LandSurface^.pitch]); |
|
53 | 540 |
end; |
541 |
4: for y:= 0 to 1023 do |
|
542 |
begin |
|
543 |
for x:= 0 to 2047 do |
|
351 | 544 |
if PLongword(@(p^[x * 4]))^ <> 0 then Land[y, x]:= COLOR_LAND; |
545 |
p:= @(p^[LandSurface^.pitch]); |
|
53 | 546 |
end; |
547 |
end; |
|
351 | 548 |
|
53 | 549 |
if SDL_MustLock(LandSurface) then |
550 |
SDL_UnlockSurface(LandSurface); |
|
551 |
end; |
|
552 |
||
37 | 553 |
procedure GenMap; |
554 |
begin |
|
53 | 555 |
if (GameFlags and gfForts) = 0 then |
556 |
if Pathz[ptMapCurrent] <> '' then LoadMap |
|
557 |
else GenLandSurface |
|
37 | 558 |
else MakeFortsMap; |
559 |
AddProgress; |
|
560 |
{$IFDEF DEBUGFILE}LogLandDigest{$ENDIF} |
|
561 |
end; |
|
562 |
||
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
563 |
procedure GenPreview; |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
564 |
var x, y, xx, yy, t, bit: integer; |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
565 |
begin |
160 | 566 |
WriteLnToConsole('Generating preview...'); |
161 | 567 |
GenBlank(EdgeTemplates[SelectTemplate]); |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
568 |
|
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
569 |
for y:= 0 to 127 do |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
570 |
for x:= 0 to 31 do |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
571 |
begin |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
572 |
Preview[y, x]:= 0; |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
573 |
for bit:= 0 to 7 do |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
574 |
begin |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
575 |
t:= 0; |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
576 |
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
|
577 |
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
|
578 |
if Land[yy, xx] <> 0 then inc(t); |
351 | 579 |
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
|
580 |
end |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
581 |
end |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
582 |
end; |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
583 |
|
51 | 584 |
initialization |
585 |
||
4 | 586 |
end. |