author | koda |
Tue, 30 Jun 2009 14:59:25 +0000 | |
changeset 2214 | eacb5b19d587 |
parent 2171 | 8208946331ba |
child 2221 | ef52dae4130b |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2005-2008 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 |
|
1906 | 21 |
uses SDLh, uLandTemplates, uFloat, |
2152 | 22 |
{$IFDEF GLES11} |
1906 | 23 |
gles11, |
24 |
{$ELSE} |
|
25 |
GL, |
|
26 |
{$ENDIF} |
|
27 |
uConsts; |
|
4 | 28 |
{$include options.inc} |
1760 | 29 |
type TLandArray = packed array[0 .. LAND_HEIGHT - 1, 0 .. LAND_WIDTH - 1] of LongWord; |
30 |
TPreview = packed array[0..127, 0..31] of byte; |
|
31 |
TDirtyTag = packed array[0 .. LAND_HEIGHT div 32 - 1, 0 .. LAND_WIDTH div 32 - 1] of byte; |
|
4 | 32 |
|
33 |
var Land: TLandArray; |
|
768 | 34 |
LandPixels: TLandArray; |
1738
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1537
diff
changeset
|
35 |
LandDirty: TDirtyTag; |
1776 | 36 |
hasBorder: boolean; // I'm putting this here for now. I'd like it to be toggleable by user (so user can set a border on a non-cave map) - will turn off air attacks |
2152 | 37 |
hasGirders: boolean; // I think should be on template by template basis. some caverns might have open water and large spaces. Some islands do not need? It might be better to tweak the girder code based upon space above. dunno. |
1792 | 38 |
playHeight, playWidth, leftX, rightX, topY, MaxHedgehogs: Longword; // idea is that a template can specify height/width. Or, a map, a height/width by the dimensions of the image. If the map has pixels near top of image, it triggers border. Maybe not a good idea, but, for now? Could also be used to prevent placing a girder outside play area on maps with hasBorder = true |
1776 | 39 |
|
40 |
// in your coding style, it appears to be "isXXXX" for a verb, and "FooBar" for everything else - should be PlayHeight ? |
|
4 | 41 |
|
37 | 42 |
procedure GenMap; |
766 | 43 |
function GenPreview: TPreview; |
367 | 44 |
procedure CheckLandDigest(s: shortstring); |
4 | 45 |
|
46 |
implementation |
|
1806 | 47 |
uses uConsole, uStore, uMisc, uRandom, uTeams, uLandObjects, uSHA, uIO, uAmmos, uLandTexture; |
4 | 48 |
|
49 |
type TPixAr = record |
|
50 |
Count: Longword; |
|
22 | 51 |
ar: array[0..Pred(cMaxEdgePoints)] of TPoint; |
4 | 52 |
end; |
53 |
||
37 | 54 |
procedure LogLandDigest; |
316 | 55 |
var ctx: TSHA1Context; |
56 |
dig: TSHA1Digest; |
|
57 |
s: shortstring; |
|
37 | 58 |
begin |
316 | 59 |
SHA1Init(ctx); |
2157 | 60 |
SHA1UpdateLongwords(ctx, @Land, sizeof(Land) div 4); |
316 | 61 |
dig:= SHA1Final(ctx); |
367 | 62 |
s:='M{'+inttostr(dig[0])+':' |
316 | 63 |
+inttostr(dig[1])+':' |
64 |
+inttostr(dig[2])+':' |
|
65 |
+inttostr(dig[3])+':' |
|
66 |
+inttostr(dig[4])+'}'; |
|
699 | 67 |
CheckLandDigest(s); |
367 | 68 |
SendIPCRaw(@s[0], Length(s) + 1) |
69 |
end; |
|
70 |
||
71 |
procedure CheckLandDigest(s: shortstring); |
|
72 |
const digest: shortstring = ''; |
|
73 |
begin |
|
368 | 74 |
{$IFDEF DEBUGFILE} |
75 |
AddFileLog('CheckLandDigest: ' + s); |
|
76 |
{$ENDIF} |
|
367 | 77 |
if digest = '' then |
78 |
digest:= s |
|
79 |
else |
|
2163
12730f5e79b9
koda's patch fixing some iphone port troubles (color, mouse)
unc0rr
parents:
2157
diff
changeset
|
80 |
{$IFNDEF IPHONEOS} |
12730f5e79b9
koda's patch fixing some iphone port troubles (color, mouse)
unc0rr
parents:
2157
diff
changeset
|
81 |
//HACK & FIXME!!! |
700 | 82 |
TryDo(s = digest, 'Different maps generated, sorry', true) |
2163
12730f5e79b9
koda's patch fixing some iphone port troubles (color, mouse)
unc0rr
parents:
2157
diff
changeset
|
83 |
{$ENDIF} |
37 | 84 |
end; |
85 |
||
371 | 86 |
procedure DrawLine(X1, Y1, X2, Y2: LongInt; Color: Longword); |
358 | 87 |
var |
371 | 88 |
eX, eY, dX, dY: LongInt; |
89 |
i, sX, sY, x, y, d: LongInt; |
|
358 | 90 |
begin |
91 |
eX:= 0; |
|
92 |
eY:= 0; |
|
93 |
dX:= X2 - X1; |
|
94 |
dY:= Y2 - Y1; |
|
95 |
||
96 |
if (dX > 0) then sX:= 1 |
|
97 |
else |
|
98 |
if (dX < 0) then |
|
99 |
begin |
|
100 |
sX:= -1; |
|
101 |
dX:= -dX |
|
102 |
end else sX:= dX; |
|
103 |
||
104 |
if (dY > 0) then sY:= 1 |
|
105 |
else |
|
106 |
if (dY < 0) then |
|
107 |
begin |
|
108 |
sY:= -1; |
|
109 |
dY:= -dY |
|
110 |
end else sY:= dY; |
|
111 |
||
112 |
if (dX > dY) then d:= dX |
|
113 |
else d:= dY; |
|
114 |
||
115 |
x:= X1; |
|
116 |
y:= Y1; |
|
117 |
||
118 |
for i:= 0 to d do |
|
119 |
begin |
|
120 |
inc(eX, dX); |
|
121 |
inc(eY, dY); |
|
122 |
if (eX > d) then |
|
123 |
begin |
|
124 |
dec(eX, d); |
|
125 |
inc(x, sX); |
|
126 |
end; |
|
127 |
if (eY > d) then |
|
128 |
begin |
|
129 |
dec(eY, d); |
|
130 |
inc(y, sY); |
|
131 |
end; |
|
364 | 132 |
|
1753 | 133 |
if ((x and LAND_WIDTH_MASK) = 0) and ((y and LAND_HEIGHT_MASK) = 0) then |
358 | 134 |
Land[y, x]:= Color; |
135 |
end |
|
136 |
end; |
|
137 |
||
365 | 138 |
procedure DrawEdge(var pa: TPixAr; Color: Longword); |
371 | 139 |
var i: LongInt; |
4 | 140 |
begin |
365 | 141 |
i:= 0; |
4 | 142 |
with pa do |
371 | 143 |
while i < LongInt(Count) - 1 do |
365 | 144 |
if (ar[i + 1].X = NTPX) then inc(i, 2) |
145 |
else begin |
|
146 |
DrawLine(ar[i].x, ar[i].y, ar[i + 1].x, ar[i + 1].y, Color); |
|
147 |
inc(i) |
|
148 |
end |
|
22 | 149 |
end; |
150 |
||
365 | 151 |
procedure Vector(p1, p2, p3: TPoint; var Vx, Vy: hwFloat); |
152 |
var d1, d2, d: hwFloat; |
|
364 | 153 |
begin |
498 | 154 |
Vx:= int2hwFloat(p1.X - p3.X); |
155 |
Vy:= int2hwFloat(p1.Y - p3.Y); |
|
156 |
d:= DistanceI(p2.X - p1.X, p2.Y - p1.Y); |
|
157 |
d1:= DistanceI(p2.X - p3.X, p2.Y - p3.Y); |
|
365 | 158 |
d2:= Distance(Vx, Vy); |
159 |
if d1 < d then d:= d1; |
|
160 |
if d2 < d then d:= d2; |
|
161 |
d:= d * _1div3; |
|
162 |
if d2.QWordValue = 0 then |
|
163 |
begin |
|
498 | 164 |
Vx:= _0; |
165 |
Vy:= _0 |
|
365 | 166 |
end else |
167 |
begin |
|
498 | 168 |
d2:= _1 / d2; |
365 | 169 |
Vx:= Vx * d2; |
170 |
Vy:= Vy * d2; |
|
171 |
||
172 |
Vx:= Vx * d; |
|
173 |
Vy:= Vy * d |
|
174 |
end |
|
175 |
end; |
|
176 |
||
371 | 177 |
procedure AddLoopPoints(var pa, opa: TPixAr; StartI, EndI: LongInt; Delta: hwFloat); |
178 |
var i, pi, ni: LongInt; |
|
365 | 179 |
NVx, NVy, PVx, PVy: hwFloat; |
498 | 180 |
x1, x2, y1, y2: LongInt; |
181 |
tsq, tcb, t, r1, r2, r3, cx1, cx2, cy1, cy2: hwFloat; |
|
371 | 182 |
X, Y: LongInt; |
365 | 183 |
begin |
184 |
pi:= EndI; |
|
185 |
i:= StartI; |
|
186 |
ni:= Succ(StartI); |
|
187 |
Vector(opa.ar[pi], opa.ar[i], opa.ar[ni], NVx, NVy); |
|
188 |
repeat |
|
189 |
inc(pi); |
|
190 |
if pi > EndI then pi:= StartI; |
|
191 |
inc(i); |
|
192 |
if i > EndI then i:= StartI; |
|
193 |
inc(ni); |
|
194 |
if ni > EndI then ni:= StartI; |
|
195 |
PVx:= NVx; |
|
196 |
PVy:= NVy; |
|
197 |
Vector(opa.ar[pi], opa.ar[i], opa.ar[ni], NVx, NVy); |
|
198 |
||
199 |
x1:= opa.ar[pi].x; |
|
200 |
y1:= opa.ar[pi].y; |
|
201 |
x2:= opa.ar[i].x; |
|
202 |
y2:= opa.ar[i].y; |
|
498 | 203 |
cx1:= int2hwFloat(x1) - PVx; |
204 |
cy1:= int2hwFloat(y1) - PVy; |
|
205 |
cx2:= int2hwFloat(x2) + NVx; |
|
206 |
cy2:= int2hwFloat(y2) + NVy; |
|
207 |
t:= _0; |
|
364 | 208 |
while t.Round = 0 do |
209 |
begin |
|
210 |
tsq:= t * t; |
|
211 |
tcb:= tsq * t; |
|
498 | 212 |
r1:= (_1 - t*3 + tsq*3 - tcb); |
213 |
r2:= ( t*3 - tsq*6 + tcb*3); |
|
214 |
r3:= ( tsq*3 - tcb*3); |
|
430 | 215 |
X:= hwRound(r1 * x1 + r2 * cx1 + r3 * cx2 + tcb * x2); |
216 |
Y:= hwRound(r1 * y1 + r2 * cy1 + r3 * cy2 + tcb * y2); |
|
364 | 217 |
t:= t + Delta; |
218 |
pa.ar[pa.Count].x:= X; |
|
219 |
pa.ar[pa.Count].y:= Y; |
|
220 |
inc(pa.Count); |
|
221 |
TryDo(pa.Count <= cMaxEdgePoints, 'Edge points overflow', true) |
|
222 |
end; |
|
365 | 223 |
until i = StartI; |
224 |
pa.ar[pa.Count].x:= opa.ar[StartI].X; |
|
225 |
pa.ar[pa.Count].y:= opa.ar[StartI].Y; |
|
364 | 226 |
inc(pa.Count) |
227 |
end; |
|
228 |
||
365 | 229 |
procedure BezierizeEdge(var pa: TPixAr; Delta: hwFloat); |
495 | 230 |
var i, StartLoop: LongInt; |
365 | 231 |
opa: TPixAr; |
232 |
begin |
|
233 |
opa:= pa; |
|
234 |
pa.Count:= 0; |
|
235 |
i:= 0; |
|
236 |
StartLoop:= 0; |
|
371 | 237 |
while i < LongInt(opa.Count) do |
365 | 238 |
if (opa.ar[i + 1].X = NTPX) then |
239 |
begin |
|
240 |
AddLoopPoints(pa, opa, StartLoop, i, Delta); |
|
241 |
inc(i, 2); |
|
242 |
StartLoop:= i; |
|
243 |
pa.ar[pa.Count].X:= NTPX; |
|
244 |
inc(pa.Count); |
|
245 |
end else inc(i) |
|
246 |
end; |
|
247 |
||
371 | 248 |
procedure FillLand(x, y: LongInt); |
4 | 249 |
var Stack: record |
250 |
Count: Longword; |
|
251 |
points: array[0..8192] of record |
|
371 | 252 |
xl, xr, y, dir: LongInt; |
4 | 253 |
end |
254 |
end; |
|
255 |
||
371 | 256 |
procedure Push(_xl, _xr, _y, _dir: LongInt); |
4 | 257 |
begin |
75 | 258 |
TryDo(Stack.Count <= 8192, 'FillLand: stack overflow', true); |
4 | 259 |
_y:= _y + _dir; |
1760 | 260 |
if (_y < 0) or (_y >= LAND_HEIGHT) then exit; |
4 | 261 |
with Stack.points[Stack.Count] do |
262 |
begin |
|
263 |
xl:= _xl; |
|
264 |
xr:= _xr; |
|
265 |
y:= _y; |
|
266 |
dir:= _dir |
|
267 |
end; |
|
75 | 268 |
inc(Stack.Count) |
4 | 269 |
end; |
270 |
||
371 | 271 |
procedure Pop(var _xl, _xr, _y, _dir: LongInt); |
4 | 272 |
begin |
273 |
dec(Stack.Count); |
|
274 |
with Stack.points[Stack.Count] do |
|
275 |
begin |
|
276 |
_xl:= xl; |
|
277 |
_xr:= xr; |
|
278 |
_y:= y; |
|
279 |
_dir:= dir |
|
280 |
end |
|
281 |
end; |
|
282 |
||
371 | 283 |
var xl, xr, dir: LongInt; |
351 | 284 |
begin |
4 | 285 |
Stack.Count:= 0; |
286 |
xl:= x - 1; |
|
287 |
xr:= x; |
|
23 | 288 |
Push(xl, xr, y, -1); |
289 |
Push(xl, xr, y, 1); |
|
4 | 290 |
while Stack.Count > 0 do |
291 |
begin |
|
292 |
Pop(xl, xr, y, dir); |
|
51 | 293 |
while (xl > 0) and (Land[y, xl] <> 0) do dec(xl); |
1760 | 294 |
while (xr < LAND_WIDTH - 1) and (Land[y, xr] <> 0) do inc(xr); |
4 | 295 |
while (xl < xr) do |
296 |
begin |
|
51 | 297 |
while (xl <= xr) and (Land[y, xl] = 0) do inc(xl); |
4 | 298 |
x:= xl; |
51 | 299 |
while (xl <= xr) and (Land[y, xl] <> 0) do |
4 | 300 |
begin |
51 | 301 |
Land[y, xl]:= 0; |
4 | 302 |
inc(xl) |
303 |
end; |
|
22 | 304 |
if x < xl then |
305 |
begin |
|
306 |
Push(x, Pred(xl), y, dir); |
|
307 |
Push(x, Pred(xl), y,-dir); |
|
308 |
end; |
|
4 | 309 |
end; |
310 |
end; |
|
311 |
end; |
|
312 |
||
313 |
procedure ColorizeLand(Surface: PSDL_Surface); |
|
314 |
var tmpsurf: PSDL_Surface; |
|
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
315 |
r, rr: TSDL_Rect; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
316 |
x, yd, yu: LongInt; |
4 | 317 |
begin |
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2163
diff
changeset
|
318 |
tmpsurf:= LoadImage(Pathz[ptCurrTheme] + '/LandTex', ifCritical or ifIgnoreCaps); |
4 | 319 |
r.y:= 0; |
1760 | 320 |
while r.y < LAND_HEIGHT do |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
321 |
begin |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
322 |
r.x:= 0; |
1760 | 323 |
while r.x < LAND_WIDTH do |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
324 |
begin |
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2163
diff
changeset
|
325 |
{$IFDEF IPHONEOS} |
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2163
diff
changeset
|
326 |
//does not draw border with SDL_UpperBlit function, so we will use our own copy |
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2163
diff
changeset
|
327 |
copyToXY(tmpsurf,Surface, r.x,r.y); |
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2163
diff
changeset
|
328 |
{$ELSE} |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
329 |
SDL_UpperBlit(tmpsurf, nil, Surface, @r); |
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2163
diff
changeset
|
330 |
{$ENDIF} |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
331 |
inc(r.x, tmpsurf^.w) |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
332 |
end; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
333 |
inc(r.y, tmpsurf^.h) |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
334 |
end; |
4 | 335 |
SDL_FreeSurface(tmpsurf); |
336 |
||
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2163
diff
changeset
|
337 |
tmpsurf:= LoadImage(Pathz[ptCurrTheme] + '/Border', ifCritical or ifIgnoreCaps or ifTransparent); |
1760 | 338 |
for x:= 0 to LAND_WIDTH - 1 do |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
339 |
begin |
1760 | 340 |
yd:= LAND_HEIGHT - 1; |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
341 |
repeat |
1760 | 342 |
while (yd > 0) and (Land[yd, x] = 0) do dec(yd); |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
343 |
|
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
344 |
if (yd < 0) then yd:= 0; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
345 |
|
1760 | 346 |
while (yd < LAND_HEIGHT) and (Land[yd, x] <> 0) do inc(yd); |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
347 |
dec(yd); |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
348 |
yu:= yd; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
349 |
|
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
350 |
while (yu > 0 ) and (Land[yu, x] <> 0) do dec(yu); |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
351 |
while (yu < yd ) and (Land[yu, x] = 0) do inc(yu); |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
352 |
|
1760 | 353 |
if (yd < LAND_HEIGHT - 1) and ((yd - yu) >= 16) then |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
354 |
begin |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
355 |
rr.x:= x; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
356 |
rr.y:= yd - 15; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
357 |
r.x:= x mod tmpsurf^.w; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
358 |
r.y:= 16; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
359 |
r.w:= 1; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
360 |
r.h:= 16; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
361 |
SDL_UpperBlit(tmpsurf, @r, Surface, @rr); |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
362 |
end; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
363 |
if (yu > 0) then |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
364 |
begin |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
365 |
rr.x:= x; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
366 |
rr.y:= yu; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
367 |
r.x:= x mod tmpsurf^.w; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
368 |
r.y:= 0; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
369 |
r.w:= 1; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
370 |
r.h:= min(16, yd - yu + 1); |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
371 |
SDL_UpperBlit(tmpsurf, @r, Surface, @rr); |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
372 |
end; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
373 |
yd:= yu - 1; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
374 |
until yd < 0; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
375 |
end; |
4 | 376 |
end; |
377 |
||
358 | 378 |
procedure SetPoints(var Template: TEdgeTemplate; var pa: TPixAr); |
371 | 379 |
var i: LongInt; |
22 | 380 |
begin |
23 | 381 |
with Template do |
382 |
begin |
|
358 | 383 |
pa.Count:= BasePointsCount; |
384 |
for i:= 0 to pred(pa.Count) do |
|
23 | 385 |
begin |
371 | 386 |
pa.ar[i].x:= BasePoints^[i].x + LongInt(GetRandom(BasePoints^[i].w)); |
1792 | 387 |
if pa.ar[i].x <> NTPX then |
388 |
pa.ar[i].x:= pa.ar[i].x + ((LAND_WIDTH - Template.TemplateWidth) div 2); |
|
1776 | 389 |
pa.ar[i].y:= BasePoints^[i].y + LongInt(GetRandom(BasePoints^[i].h)) + LAND_HEIGHT - Template.TemplateHeight |
23 | 390 |
end; |
1183
540cea859395
Step 4: repair girder rendering (girder is 32bit now)
unc0rr
parents:
1182
diff
changeset
|
391 |
|
358 | 392 |
if canMirror then |
360 | 393 |
if getrandom(2) = 0 then |
358 | 394 |
begin |
395 |
for i:= 0 to pred(BasePointsCount) do |
|
365 | 396 |
if pa.ar[i].x <> NTPX then |
1760 | 397 |
pa.ar[i].x:= LAND_WIDTH - 1 - pa.ar[i].x; |
358 | 398 |
for i:= 0 to pred(FillPointsCount) do |
1760 | 399 |
FillPoints^[i].x:= LAND_WIDTH - 1 - FillPoints^[i].x; |
358 | 400 |
end; |
22 | 401 |
|
358 | 402 |
if canFlip then |
360 | 403 |
if getrandom(2) = 0 then |
358 | 404 |
begin |
405 |
for i:= 0 to pred(BasePointsCount) do |
|
1760 | 406 |
pa.ar[i].y:= LAND_HEIGHT - 1 - pa.ar[i].y; |
358 | 407 |
for i:= 0 to pred(FillPointsCount) do |
1760 | 408 |
FillPoints^[i].y:= LAND_HEIGHT - 1 - FillPoints^[i].y; |
358 | 409 |
end; |
410 |
end |
|
4 | 411 |
end; |
67 | 412 |
|
561 | 413 |
function CheckIntersect(V1, V2, V3, V4: TPoint): boolean; |
414 |
var c1, c2, dm: LongInt; |
|
415 |
begin |
|
416 |
dm:= (V4.y - V3.y) * (V2.x - V1.x) - (V4.x - V3.x) * (V2.y - V1.y); |
|
417 |
c1:= (V4.x - V3.x) * (V1.y - V3.y) - (V4.y - V3.y) * (V1.x - V3.x); |
|
418 |
if dm = 0 then exit(false); |
|
419 |
||
420 |
c2:= (V2.x - V3.x) * (V1.y - V3.y) - (V2.y - V3.y) * (V1.x - V3.x); |
|
421 |
if dm > 0 then |
|
422 |
begin |
|
423 |
if (c1 < 0) or (c1 > dm) then exit(false); |
|
424 |
if (c2 < 0) or (c2 > dm) then exit(false) |
|
425 |
end else |
|
426 |
begin |
|
427 |
if (c1 > 0) or (c1 < dm) then exit(false); |
|
428 |
if (c2 > 0) or (c2 < dm) then exit(false) |
|
429 |
end; |
|
430 |
||
431 |
//AddFileLog('1 (' + inttostr(V1.x) + ',' + inttostr(V1.y) + ')x(' + inttostr(V2.x) + ',' + inttostr(V2.y) + ')'); |
|
432 |
//AddFileLog('2 (' + inttostr(V3.x) + ',' + inttostr(V3.y) + ')x(' + inttostr(V4.x) + ',' + inttostr(V4.y) + ')'); |
|
433 |
CheckIntersect:= true |
|
434 |
end; |
|
435 |
||
436 |
function CheckSelfIntersect(var pa: TPixAr; ind: Longword): boolean; |
|
437 |
var i: Longword; |
|
438 |
begin |
|
439 |
if (ind <= 0) or (ind >= Pred(pa.Count)) then exit(false); |
|
440 |
for i:= 1 to pa.Count - 3 do |
|
441 |
if (i <= ind - 1) or (i >= ind + 2) then |
|
442 |
begin |
|
443 |
if (i <> ind - 1) and |
|
444 |
CheckIntersect(pa.ar[ind], pa.ar[ind - 1], pa.ar[i], pa.ar[i - 1]) then exit(true); |
|
445 |
if (i <> ind + 2) and |
|
446 |
CheckIntersect(pa.ar[ind], pa.ar[ind + 1], pa.ar[i], pa.ar[i - 1]) then exit(true); |
|
447 |
end; |
|
448 |
CheckSelfIntersect:= false |
|
449 |
end; |
|
450 |
||
429 | 451 |
procedure RandomizePoints(var pa: TPixAr); |
364 | 452 |
const cEdge = 55; |
561 | 453 |
cMinDist = 8; |
371 | 454 |
var radz: array[0..Pred(cMaxEdgePoints)] of LongInt; |
561 | 455 |
i, k, dist, px, py: LongInt; |
364 | 456 |
begin |
457 |
radz[0]:= 0; |
|
458 |
for i:= 0 to Pred(pa.Count) do |
|
459 |
with pa.ar[i] do |
|
365 | 460 |
if x <> NTPX then |
461 |
begin |
|
1760 | 462 |
radz[i]:= Min(Max(x - cEdge, 0), Max(LAND_WIDTH - cEdge - x, 0)); |
463 |
radz[i]:= Min(radz[i], Min(Max(y - cEdge, 0), Max(LAND_HEIGHT - cEdge - y, 0))); |
|
365 | 464 |
if radz[i] > 0 then |
465 |
for k:= 0 to Pred(i) do |
|
364 | 466 |
begin |
429 | 467 |
dist:= Max(abs(x - pa.ar[k].x), abs(y - pa.ar[k].y)); |
365 | 468 |
radz[k]:= Max(0, Min((dist - cMinDist) div 2, radz[k])); |
469 |
radz[i]:= Max(0, Min(dist - radz[k] - cMinDist, radz[i])) |
|
470 |
end |
|
471 |
end; |
|
364 | 472 |
|
473 |
for i:= 0 to Pred(pa.Count) do |
|
474 |
with pa.ar[i] do |
|
1753 | 475 |
if ((x and LAND_WIDTH_MASK) = 0) and ((y and LAND_HEIGHT_MASK) = 0) then |
364 | 476 |
begin |
561 | 477 |
px:= x; |
478 |
py:= y; |
|
371 | 479 |
x:= x + LongInt(GetRandom(7) - 3) * (radz[i] * 5 div 7) div 3; |
561 | 480 |
y:= y + LongInt(GetRandom(7) - 3) * (radz[i] * 5 div 7) div 3; |
481 |
if CheckSelfIntersect(pa, i) then |
|
482 |
begin |
|
483 |
x:= px; |
|
484 |
y:= py |
|
485 |
end; |
|
364 | 486 |
end |
67 | 487 |
end; |
488 |
||
364 | 489 |
|
23 | 490 |
procedure GenBlank(var Template: TEdgeTemplate); |
4 | 491 |
var pa: TPixAr; |
23 | 492 |
i: Longword; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
493 |
y, x: Longword; |
4 | 494 |
begin |
1760 | 495 |
for y:= 0 to LAND_HEIGHT - 1 do |
496 |
for x:= 0 to LAND_WIDTH - 1 do |
|
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
497 |
Land[y, x]:= COLOR_LAND; |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
498 |
|
358 | 499 |
SetPoints(Template, pa); |
429 | 500 |
for i:= 1 to Template.BezierizeCount do |
501 |
begin |
|
431 | 502 |
BezierizeEdge(pa, _0_5); |
561 | 503 |
RandomizePoints(pa); |
429 | 504 |
RandomizePoints(pa) |
505 |
end; |
|
506 |
for i:= 1 to Template.RandPassesCount do RandomizePoints(pa); |
|
365 | 507 |
BezierizeEdge(pa, _0_1); |
27 | 508 |
|
365 | 509 |
DrawEdge(pa, 0); |
27 | 510 |
|
358 | 511 |
with Template do |
23 | 512 |
for i:= 0 to pred(FillPointsCount) do |
513 |
with FillPoints^[i] do |
|
89 | 514 |
FillLand(x, y); |
515 |
||
1773 | 516 |
DrawEdge(pa, COLOR_LAND); |
517 |
||
1792 | 518 |
MaxHedgehogs:= Template.MaxHedgehogs; |
1776 | 519 |
hasGirders:= Template.hasGirders; |
520 |
playHeight:= Template.TemplateHeight; |
|
521 |
playWidth:= Template.TemplateWidth; |
|
522 |
leftX:= ((LAND_WIDTH - playWidth) div 2); |
|
523 |
rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; |
|
524 |
topY:= LAND_HEIGHT - playHeight; |
|
525 |
||
1797 | 526 |
// force to only cavern even if a cavern map is invertable if cTemplateFilter = 4 ? |
1773 | 527 |
if (Template.canInvert and (getrandom(2) = 0)) or |
528 |
(not Template.canInvert and Template.isNegative) then |
|
1776 | 529 |
begin |
530 |
hasBorder:= true; |
|
1773 | 531 |
for y:= 0 to LAND_HEIGHT - 1 do |
532 |
for x:= 0 to LAND_WIDTH - 1 do |
|
1776 | 533 |
if (y < topY) or (x < leftX) or (x > rightX) then |
534 |
Land[y, x]:= 0 |
|
535 |
else |
|
536 |
begin |
|
537 |
if Land[y, x] = 0 then |
|
538 |
Land[y, x]:= COLOR_LAND |
|
539 |
else if Land[y, x] = COLOR_LAND then |
|
540 |
Land[y, x]:= 0; |
|
541 |
end; |
|
542 |
end; |
|
23 | 543 |
end; |
544 |
||
371 | 545 |
function SelectTemplate: LongInt; |
161 | 546 |
begin |
1797 | 547 |
case cTemplateFilter of |
548 |
0: begin |
|
549 |
SelectTemplate:= getrandom(Succ(High(EdgeTemplates))); |
|
550 |
end; |
|
551 |
1: begin |
|
552 |
SelectTemplate:= SmallTemplates[getrandom(Succ(High(SmallTemplates)))]; |
|
553 |
end; |
|
554 |
2: begin |
|
555 |
SelectTemplate:= MediumTemplates[getrandom(Succ(High(MediumTemplates)))]; |
|
556 |
end; |
|
557 |
3: begin |
|
558 |
SelectTemplate:= LargeTemplates[getrandom(Succ(High(LargeTemplates)))]; |
|
559 |
end; |
|
560 |
4: begin |
|
561 |
SelectTemplate:= CavernTemplates[getrandom(Succ(High(CavernTemplates)))]; |
|
562 |
end; |
|
563 |
5: begin |
|
564 |
SelectTemplate:= WackyTemplates[getrandom(Succ(High(WackyTemplates)))]; |
|
565 |
end; |
|
566 |
end; |
|
567 |
WriteLnToConsole('Selected template #'+inttostr(SelectTemplate)+' using filter #'+inttostr(cTemplateFilter)); |
|
161 | 568 |
end; |
569 |
||
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
570 |
procedure LandSurface2LandPixels(Surface: PSDL_Surface); |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
571 |
var x, y: LongInt; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
572 |
p: PLongwordArray; |
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1085
diff
changeset
|
573 |
begin |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
574 |
TryDo(Surface <> nil, 'Assert (LandSurface <> nil) failed', true); |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
575 |
|
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
576 |
if SDL_MustLock(Surface) then |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
577 |
SDLTry(SDL_LockSurface(Surface) >= 0, true); |
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1085
diff
changeset
|
578 |
|
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
579 |
p:= Surface^.pixels; |
1760 | 580 |
for y:= 0 to LAND_HEIGHT - 1 do |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
581 |
begin |
1760 | 582 |
for x:= 0 to LAND_WIDTH - 1 do |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
583 |
if Land[y, x] <> 0 then LandPixels[y, x]:= p^[x] or $FF000000; |
1760 | 584 |
|
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
585 |
p:= @(p^[Surface^.pitch div 4]); |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
586 |
end; |
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1085
diff
changeset
|
587 |
|
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
588 |
if SDL_MustLock(Surface) then |
1753 | 589 |
SDL_UnlockSurface(Surface); |
1754 | 590 |
end; |
591 |
||
592 |
procedure GenLandSurface; |
|
593 |
var tmpsurf: PSDL_Surface; |
|
594 |
begin |
|
595 |
WriteLnToConsole('Generating land...'); |
|
596 |
||
597 |
GenBlank(EdgeTemplates[SelectTemplate]); |
|
598 |
||
599 |
AddProgress; |
|
600 |
||
1760 | 601 |
tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, LAND_WIDTH, LAND_HEIGHT, 32, RMask, GMask, BMask, 0); |
1754 | 602 |
|
603 |
TryDo(tmpsurf <> nil, 'Error creating pre-land surface', true); |
|
604 |
ColorizeLand(tmpsurf); |
|
605 |
AddOnLandObjects(tmpsurf); |
|
606 |
||
607 |
LandSurface2LandPixels(tmpsurf); |
|
608 |
SDL_FreeSurface(tmpsurf); |
|
609 |
||
610 |
AddProgress; |
|
611 |
||
612 |
AddProgress |
|
613 |
end; |
|
614 |
||
615 |
procedure MakeFortsMap; |
|
616 |
var tmpsurf: PSDL_Surface; |
|
617 |
begin |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2163
diff
changeset
|
618 |
// For now, defining a fort is playable area as 3072x1200 - there are no tall forts. The extra height is to avoid triggering border with current code, also if user turns on a border, it will give a bit more maneuvering room. |
1784 | 619 |
playHeight:= 1200; |
2096 | 620 |
playWidth:= 2560; |
1776 | 621 |
leftX:= (LAND_WIDTH - playWidth) div 2; |
622 |
rightX:= ((playWidth + (LAND_WIDTH - playWidth) div 2) - 1); |
|
623 |
topY:= LAND_HEIGHT - playHeight; |
|
624 |
||
1754 | 625 |
WriteLnToConsole('Generating forts land...'); |
626 |
||
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2163
diff
changeset
|
627 |
tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); |
1784 | 628 |
BlitImageAndGenerateCollisionInfo(leftX+150, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf); |
1754 | 629 |
SDL_FreeSurface(tmpsurf); |
630 |
||
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2163
diff
changeset
|
631 |
tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); |
1784 | 632 |
BlitImageAndGenerateCollisionInfo(rightX - 150 - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf); |
1754 | 633 |
SDL_FreeSurface(tmpsurf); |
634 |
end; |
|
635 |
||
1792 | 636 |
// Hi unC0Rr. |
637 |
// This is a function that Tiy assures me would not be good for gameplay. |
|
638 |
// It allows the setting of arbitrary portions of landscape as indestructible, or regular, or even blank. |
|
2154
3d2917be12c3
Change default output to stderr since /tmp doesn't exist under windows and is useless under iphoneos, add a couple of extra parameters
nemo
parents:
2152
diff
changeset
|
639 |
// He said I could add it here only when I swore it would not impact gameplay. Which, as far as I can tell, is true. |
3d2917be12c3
Change default output to stderr since /tmp doesn't exist under windows and is useless under iphoneos, add a couple of extra parameters
nemo
parents:
2152
diff
changeset
|
640 |
// I would just like to play with it with my friends if you do not mind. |
1792 | 641 |
// Can allow for amusing maps. |
642 |
procedure LoadMask; |
|
643 |
var tmpsurf: PSDL_Surface; |
|
644 |
p: PLongwordArray; |
|
645 |
x, y, cpX, cpY: Longword; |
|
646 |
begin |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2163
diff
changeset
|
647 |
tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps); |
1792 | 648 |
if (tmpsurf <> nil) and (tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT) and (tmpsurf^.format^.BytesPerPixel = 4) then |
649 |
begin |
|
650 |
cpX:= (LAND_WIDTH - tmpsurf^.w) div 2; |
|
651 |
cpY:= LAND_HEIGHT - tmpsurf^.h; |
|
652 |
if SDL_MustLock(tmpsurf) then |
|
653 |
SDLTry(SDL_LockSurface(tmpsurf) >= 0, true); |
|
654 |
||
655 |
p:= tmpsurf^.pixels; |
|
656 |
for y:= 0 to Pred(tmpsurf^.h) do |
|
657 |
begin |
|
658 |
for x:= 0 to Pred(tmpsurf^.w) do |
|
1849 | 659 |
begin |
660 |
if (($FF000000 and p^[x]) = 0) then // Tiy was having trouble generating transparent black |
|
661 |
Land[cpY + y, cpX + x]:= 0 |
|
662 |
else |
|
663 |
Land[cpY + y, cpX + x]:= p^[x]; |
|
664 |
end; |
|
1792 | 665 |
p:= @(p^[tmpsurf^.pitch div 4]); |
666 |
end; |
|
667 |
||
668 |
if SDL_MustLock(tmpsurf) then |
|
669 |
SDL_UnlockSurface(tmpsurf); |
|
670 |
SDL_FreeSurface(tmpsurf); |
|
671 |
end; |
|
672 |
end; |
|
673 |
||
1754 | 674 |
procedure LoadMap; |
675 |
var tmpsurf: PSDL_Surface; |
|
1795 | 676 |
s: string; |
677 |
f: textfile; |
|
1754 | 678 |
begin |
679 |
WriteLnToConsole('Loading land from file...'); |
|
680 |
AddProgress; |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2163
diff
changeset
|
681 |
tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); |
1760 | 682 |
TryDo((tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT), 'Map dimensions too big!', true); |
1754 | 683 |
|
2154
3d2917be12c3
Change default output to stderr since /tmp doesn't exist under windows and is useless under iphoneos, add a couple of extra parameters
nemo
parents:
2152
diff
changeset
|
684 |
// unC0Rr - should this be passed from the GUI? I am not sure which layer does what |
1792 | 685 |
s:= Pathz[ptMapCurrent] + '/map.cfg'; |
686 |
WriteLnToConsole('Fetching map HH limit'); |
|
687 |
Assign(f, s); |
|
688 |
Reset(f); |
|
1795 | 689 |
Readln(f); |
690 |
if not eof(f) then Readln(f, MaxHedgehogs); |
|
691 |
||
1792 | 692 |
if(MaxHedgehogs = 0) then MaxHedgehogs:= 18; |
693 |
||
1776 | 694 |
playHeight:= tmpsurf^.h; |
695 |
playWidth:= tmpsurf^.w; |
|
696 |
leftX:= (LAND_WIDTH - playWidth) div 2; |
|
697 |
rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; |
|
698 |
topY:= LAND_HEIGHT - playHeight; |
|
699 |
||
1754 | 700 |
TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Map should be 32bit', true); |
701 |
||
1772 | 702 |
BlitImageAndGenerateCollisionInfo( |
703 |
(LAND_WIDTH - tmpsurf^.w) div 2, |
|
704 |
LAND_HEIGHT - tmpsurf^.h, |
|
705 |
tmpsurf^.w, |
|
706 |
tmpsurf); |
|
1754 | 707 |
SDL_FreeSurface(tmpsurf); |
1792 | 708 |
|
709 |
LoadMask; |
|
1754 | 710 |
end; |
711 |
||
712 |
procedure GenMap; |
|
1784 | 713 |
var x, y, w, c: Longword; |
1754 | 714 |
begin |
1776 | 715 |
hasBorder:= false; |
716 |
hasGirders:= true; |
|
1754 | 717 |
LoadThemeConfig; |
718 |
||
719 |
if (GameFlags and gfForts) = 0 then |
|
720 |
if Pathz[ptMapCurrent] <> '' then LoadMap |
|
721 |
else GenLandSurface |
|
722 |
else MakeFortsMap; |
|
723 |
AddProgress; |
|
1760 | 724 |
|
1754 | 725 |
{$IFDEF DEBUGFILE}LogLandDigest;{$ENDIF} |
1753 | 726 |
|
1768 | 727 |
// check for land near top |
1784 | 728 |
c:= 0; |
729 |
if (GameFlags and gfBorder) <> 0 then |
|
730 |
hasBorder:= true |
|
731 |
else |
|
732 |
for y:= topY to topY + 5 do |
|
733 |
for x:= leftX to rightX do |
|
734 |
if Land[y, x] <> 0 then |
|
735 |
begin |
|
736 |
inc(c); |
|
737 |
if c > 200 then // avoid accidental triggering |
|
738 |
begin |
|
739 |
hasBorder:= true; |
|
740 |
break; |
|
741 |
end; |
|
742 |
end; |
|
1768 | 743 |
|
1776 | 744 |
if hasBorder then |
1768 | 745 |
begin |
1784 | 746 |
for y:= 0 to LAND_HEIGHT - 1 do |
747 |
for x:= 0 to LAND_WIDTH - 1 do |
|
748 |
if (y < topY) or (x < leftX) or (x > rightX) then |
|
749 |
Land[y, x]:= COLOR_INDESTRUCTIBLE; |
|
1768 | 750 |
// experiment hardcoding cave |
1784 | 751 |
// also try basing cave dimensions on map/template dimensions, if they exist |
752 |
for w:= 0 to 5 do // width of 3 allowed worms to be knocked through with grenade |
|
753 |
begin |
|
754 |
for y:= topY to LAND_HEIGHT - 1 do |
|
755 |
begin |
|
756 |
Land[y, leftX + w]:= COLOR_INDESTRUCTIBLE; |
|
757 |
Land[y, rightX - w]:= COLOR_INDESTRUCTIBLE; |
|
758 |
if (y + w) mod 32 < 16 then |
|
759 |
c:= $FF000000 |
|
760 |
else |
|
761 |
c:= $FF00FFFF; |
|
762 |
LandPixels[y, leftX + w]:= c; |
|
763 |
LandPixels[y, rightX - w]:= c; |
|
764 |
end; |
|
1768 | 765 |
|
1784 | 766 |
for x:= leftX to rightX do |
767 |
begin |
|
768 |
Land[topY + w, x]:= COLOR_INDESTRUCTIBLE; |
|
769 |
if (x + w) mod 32 < 16 then |
|
770 |
c:= $FF000000 |
|
771 |
else |
|
772 |
c:= $FF00FFFF; |
|
773 |
LandPixels[topY + w, x]:= c; |
|
774 |
end; |
|
775 |
end; |
|
1768 | 776 |
end; |
777 |
||
1776 | 778 |
if ((GameFlags and gfForts) = 0) and (Pathz[ptMapCurrent] = '') then AddObjects; |
779 |
||
1807 | 780 |
UpdateLandTexture(0, LAND_WIDTH, 0, LAND_HEIGHT); |
37 | 781 |
end; |
782 |
||
566 | 783 |
function GenPreview: TPreview; |
371 | 784 |
var x, y, xx, yy, t, bit: LongInt; |
566 | 785 |
Preview: TPreview; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
786 |
begin |
160 | 787 |
WriteLnToConsole('Generating preview...'); |
161 | 788 |
GenBlank(EdgeTemplates[SelectTemplate]); |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
789 |
|
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
790 |
for y:= 0 to 127 do |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
791 |
for x:= 0 to 31 do |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
792 |
begin |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
793 |
Preview[y, x]:= 0; |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
794 |
for bit:= 0 to 7 do |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
795 |
begin |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
796 |
t:= 0; |
1760 | 797 |
for yy:= y * (LAND_HEIGHT div 128) to y * (LAND_HEIGHT div 128) + 7 do |
798 |
for xx:= x * (LAND_WIDTH div 32) + bit * 8 to x * (LAND_WIDTH div 32) + bit * 8 + 7 do |
|
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
799 |
if Land[yy, xx] <> 0 then inc(t); |
351 | 800 |
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
|
801 |
end |
566 | 802 |
end; |
1768 | 803 |
GenPreview:= Preview |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
804 |
end; |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
805 |
|
51 | 806 |
initialization |
807 |
||
4 | 808 |
end. |