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