author | unc0rr |
Fri, 30 Oct 2009 19:28:44 +0000 | |
changeset 2594 | 0047e16dbacb |
parent 2592 | d86618629e20 |
child 2599 | c7153d2348f3 |
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 |
||
2587
0dfa56a8513c
fix a segfault in the iphone simulator by moving options.inc at the beginning of the file
koda
parents:
2376
diff
changeset
|
19 |
{$include options.inc} |
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; |
1776 | 38 |
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 | 39 |
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 | 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. 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 | 41 |
|
42 |
// in your coding style, it appears to be "isXXXX" for a verb, and "FooBar" for everything else - should be PlayHeight ? |
|
4 | 43 |
|
37 | 44 |
procedure GenMap; |
766 | 45 |
function GenPreview: TPreview; |
367 | 46 |
procedure CheckLandDigest(s: shortstring); |
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 |
||
312 |
procedure ColorizeLand(Surface: PSDL_Surface); |
|
313 |
var tmpsurf: PSDL_Surface; |
|
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
314 |
r, rr: TSDL_Rect; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
315 |
x, yd, yu: LongInt; |
4 | 316 |
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
|
317 |
tmpsurf:= LoadImage(Pathz[ptCurrTheme] + '/LandTex', ifCritical or ifIgnoreCaps); |
4 | 318 |
r.y:= 0; |
1760 | 319 |
while r.y < LAND_HEIGHT do |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
320 |
begin |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
321 |
r.x:= 0; |
1760 | 322 |
while r.x < LAND_WIDTH do |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
323 |
begin |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
324 |
SDL_UpperBlit(tmpsurf, nil, Surface, @r); |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
325 |
inc(r.x, tmpsurf^.w) |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
326 |
end; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
327 |
inc(r.y, tmpsurf^.h) |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
328 |
end; |
4 | 329 |
SDL_FreeSurface(tmpsurf); |
330 |
||
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
|
331 |
tmpsurf:= LoadImage(Pathz[ptCurrTheme] + '/Border', ifCritical or ifIgnoreCaps or ifTransparent); |
1760 | 332 |
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
|
333 |
begin |
1760 | 334 |
yd:= LAND_HEIGHT - 1; |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
335 |
repeat |
1760 | 336 |
while (yd > 0) and (Land[yd, x] = 0) do dec(yd); |
2376 | 337 |
|
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
338 |
if (yd < 0) then yd:= 0; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
339 |
|
1760 | 340 |
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
|
341 |
dec(yd); |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
342 |
yu:= yd; |
2376 | 343 |
|
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
344 |
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
|
345 |
while (yu < yd ) and (Land[yu, x] = 0) do inc(yu); |
2376 | 346 |
|
1760 | 347 |
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
|
348 |
begin |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
349 |
rr.x:= x; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
350 |
rr.y:= yd - 15; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
351 |
r.x:= x mod tmpsurf^.w; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
352 |
r.y:= 16; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
353 |
r.w:= 1; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
354 |
r.h:= 16; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
355 |
SDL_UpperBlit(tmpsurf, @r, Surface, @rr); |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
356 |
end; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
357 |
if (yu > 0) then |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
358 |
begin |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
359 |
rr.x:= x; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
360 |
rr.y:= yu; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
361 |
r.x:= x mod tmpsurf^.w; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
362 |
r.y:= 0; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
363 |
r.w:= 1; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
364 |
r.h:= min(16, yd - yu + 1); |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
365 |
SDL_UpperBlit(tmpsurf, @r, Surface, @rr); |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
366 |
end; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
367 |
yd:= yu - 1; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
368 |
until yd < 0; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
369 |
end; |
4 | 370 |
end; |
371 |
||
358 | 372 |
procedure SetPoints(var Template: TEdgeTemplate; var pa: TPixAr); |
371 | 373 |
var i: LongInt; |
22 | 374 |
begin |
23 | 375 |
with Template do |
376 |
begin |
|
358 | 377 |
pa.Count:= BasePointsCount; |
378 |
for i:= 0 to pred(pa.Count) do |
|
23 | 379 |
begin |
371 | 380 |
pa.ar[i].x:= BasePoints^[i].x + LongInt(GetRandom(BasePoints^[i].w)); |
1792 | 381 |
if pa.ar[i].x <> NTPX then |
382 |
pa.ar[i].x:= pa.ar[i].x + ((LAND_WIDTH - Template.TemplateWidth) div 2); |
|
1776 | 383 |
pa.ar[i].y:= BasePoints^[i].y + LongInt(GetRandom(BasePoints^[i].h)) + LAND_HEIGHT - Template.TemplateHeight |
23 | 384 |
end; |
1183
540cea859395
Step 4: repair girder rendering (girder is 32bit now)
unc0rr
parents:
1182
diff
changeset
|
385 |
|
358 | 386 |
if canMirror then |
360 | 387 |
if getrandom(2) = 0 then |
358 | 388 |
begin |
389 |
for i:= 0 to pred(BasePointsCount) do |
|
365 | 390 |
if pa.ar[i].x <> NTPX then |
1760 | 391 |
pa.ar[i].x:= LAND_WIDTH - 1 - pa.ar[i].x; |
358 | 392 |
for i:= 0 to pred(FillPointsCount) do |
1760 | 393 |
FillPoints^[i].x:= LAND_WIDTH - 1 - FillPoints^[i].x; |
358 | 394 |
end; |
22 | 395 |
|
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
|
396 |
(* Experiment in making this option more useful |
2376 | 397 |
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
|
398 |
(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
|
399 |
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
|
400 |
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
|
401 |
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
|
402 |
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
|
403 |
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
|
404 |
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
|
405 |
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
|
406 |
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
|
407 |
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
|
408 |
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
|
409 |
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
|
410 |
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
|
411 |
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
|
412 |
end; |
2376 | 413 |
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
|
414 |
*) |
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 |
// 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
|
416 |
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
|
417 |
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
|
418 |
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
|
419 |
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
|
420 |
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
|
421 |
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
|
422 |
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
|
423 |
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
|
424 |
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
|
425 |
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
|
426 |
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
|
427 |
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
|
428 |
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
|
429 |
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
|
430 |
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
|
431 |
|
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 |
if (canFlip and (getrandom(2) = 0)) then |
358 | 433 |
begin |
434 |
for i:= 0 to pred(BasePointsCount) do |
|
1760 | 435 |
pa.ar[i].y:= LAND_HEIGHT - 1 - pa.ar[i].y; |
358 | 436 |
for i:= 0 to pred(FillPointsCount) do |
1760 | 437 |
FillPoints^[i].y:= LAND_HEIGHT - 1 - FillPoints^[i].y; |
358 | 438 |
end; |
439 |
end |
|
4 | 440 |
end; |
67 | 441 |
|
561 | 442 |
function CheckIntersect(V1, V2, V3, V4: TPoint): boolean; |
443 |
var c1, c2, dm: LongInt; |
|
444 |
begin |
|
445 |
dm:= (V4.y - V3.y) * (V2.x - V1.x) - (V4.x - V3.x) * (V2.y - V1.y); |
|
446 |
c1:= (V4.x - V3.x) * (V1.y - V3.y) - (V4.y - V3.y) * (V1.x - V3.x); |
|
447 |
if dm = 0 then exit(false); |
|
448 |
||
449 |
c2:= (V2.x - V3.x) * (V1.y - V3.y) - (V2.y - V3.y) * (V1.x - V3.x); |
|
450 |
if dm > 0 then |
|
451 |
begin |
|
452 |
if (c1 < 0) or (c1 > dm) then exit(false); |
|
453 |
if (c2 < 0) or (c2 > dm) then exit(false) |
|
454 |
end else |
|
455 |
begin |
|
456 |
if (c1 > 0) or (c1 < dm) then exit(false); |
|
457 |
if (c2 > 0) or (c2 < dm) then exit(false) |
|
458 |
end; |
|
459 |
||
460 |
//AddFileLog('1 (' + inttostr(V1.x) + ',' + inttostr(V1.y) + ')x(' + inttostr(V2.x) + ',' + inttostr(V2.y) + ')'); |
|
461 |
//AddFileLog('2 (' + inttostr(V3.x) + ',' + inttostr(V3.y) + ')x(' + inttostr(V4.x) + ',' + inttostr(V4.y) + ')'); |
|
462 |
CheckIntersect:= true |
|
463 |
end; |
|
464 |
||
465 |
function CheckSelfIntersect(var pa: TPixAr; ind: Longword): boolean; |
|
466 |
var i: Longword; |
|
467 |
begin |
|
468 |
if (ind <= 0) or (ind >= Pred(pa.Count)) then exit(false); |
|
469 |
for i:= 1 to pa.Count - 3 do |
|
470 |
if (i <= ind - 1) or (i >= ind + 2) then |
|
471 |
begin |
|
472 |
if (i <> ind - 1) and |
|
473 |
CheckIntersect(pa.ar[ind], pa.ar[ind - 1], pa.ar[i], pa.ar[i - 1]) then exit(true); |
|
474 |
if (i <> ind + 2) and |
|
475 |
CheckIntersect(pa.ar[ind], pa.ar[ind + 1], pa.ar[i], pa.ar[i - 1]) then exit(true); |
|
476 |
end; |
|
477 |
CheckSelfIntersect:= false |
|
478 |
end; |
|
479 |
||
429 | 480 |
procedure RandomizePoints(var pa: TPixAr); |
364 | 481 |
const cEdge = 55; |
561 | 482 |
cMinDist = 8; |
371 | 483 |
var radz: array[0..Pred(cMaxEdgePoints)] of LongInt; |
561 | 484 |
i, k, dist, px, py: LongInt; |
364 | 485 |
begin |
486 |
radz[0]:= 0; |
|
487 |
for i:= 0 to Pred(pa.Count) do |
|
488 |
with pa.ar[i] do |
|
365 | 489 |
if x <> NTPX then |
490 |
begin |
|
1760 | 491 |
radz[i]:= Min(Max(x - cEdge, 0), Max(LAND_WIDTH - cEdge - x, 0)); |
492 |
radz[i]:= Min(radz[i], Min(Max(y - cEdge, 0), Max(LAND_HEIGHT - cEdge - y, 0))); |
|
365 | 493 |
if radz[i] > 0 then |
494 |
for k:= 0 to Pred(i) do |
|
364 | 495 |
begin |
429 | 496 |
dist:= Max(abs(x - pa.ar[k].x), abs(y - pa.ar[k].y)); |
365 | 497 |
radz[k]:= Max(0, Min((dist - cMinDist) div 2, radz[k])); |
498 |
radz[i]:= Max(0, Min(dist - radz[k] - cMinDist, radz[i])) |
|
499 |
end |
|
500 |
end; |
|
364 | 501 |
|
502 |
for i:= 0 to Pred(pa.Count) do |
|
503 |
with pa.ar[i] do |
|
1753 | 504 |
if ((x and LAND_WIDTH_MASK) = 0) and ((y and LAND_HEIGHT_MASK) = 0) then |
364 | 505 |
begin |
561 | 506 |
px:= x; |
507 |
py:= y; |
|
371 | 508 |
x:= x + LongInt(GetRandom(7) - 3) * (radz[i] * 5 div 7) div 3; |
561 | 509 |
y:= y + LongInt(GetRandom(7) - 3) * (radz[i] * 5 div 7) div 3; |
510 |
if CheckSelfIntersect(pa, i) then |
|
511 |
begin |
|
512 |
x:= px; |
|
513 |
y:= py |
|
514 |
end; |
|
364 | 515 |
end |
67 | 516 |
end; |
517 |
||
364 | 518 |
|
23 | 519 |
procedure GenBlank(var Template: TEdgeTemplate); |
4 | 520 |
var pa: TPixAr; |
23 | 521 |
i: Longword; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
522 |
y, x: Longword; |
4 | 523 |
begin |
1760 | 524 |
for y:= 0 to LAND_HEIGHT - 1 do |
525 |
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
|
526 |
Land[y, x]:= COLOR_LAND; |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
527 |
|
358 | 528 |
SetPoints(Template, pa); |
429 | 529 |
for i:= 1 to Template.BezierizeCount do |
530 |
begin |
|
431 | 531 |
BezierizeEdge(pa, _0_5); |
561 | 532 |
RandomizePoints(pa); |
429 | 533 |
RandomizePoints(pa) |
534 |
end; |
|
535 |
for i:= 1 to Template.RandPassesCount do RandomizePoints(pa); |
|
365 | 536 |
BezierizeEdge(pa, _0_1); |
27 | 537 |
|
365 | 538 |
DrawEdge(pa, 0); |
27 | 539 |
|
358 | 540 |
with Template do |
23 | 541 |
for i:= 0 to pred(FillPointsCount) do |
542 |
with FillPoints^[i] do |
|
89 | 543 |
FillLand(x, y); |
544 |
||
1773 | 545 |
DrawEdge(pa, COLOR_LAND); |
546 |
||
1792 | 547 |
MaxHedgehogs:= Template.MaxHedgehogs; |
1776 | 548 |
hasGirders:= Template.hasGirders; |
549 |
playHeight:= Template.TemplateHeight; |
|
550 |
playWidth:= Template.TemplateWidth; |
|
551 |
leftX:= ((LAND_WIDTH - playWidth) div 2); |
|
552 |
rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; |
|
553 |
topY:= LAND_HEIGHT - playHeight; |
|
554 |
||
1797 | 555 |
// force to only cavern even if a cavern map is invertable if cTemplateFilter = 4 ? |
2376 | 556 |
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
|
557 |
(Template.canInvert and (getrandom(2) = 0)) or |
2376 | 558 |
(not Template.canInvert and Template.isNegative) then |
1776 | 559 |
begin |
560 |
hasBorder:= true; |
|
1773 | 561 |
for y:= 0 to LAND_HEIGHT - 1 do |
562 |
for x:= 0 to LAND_WIDTH - 1 do |
|
1776 | 563 |
if (y < topY) or (x < leftX) or (x > rightX) then |
564 |
Land[y, x]:= 0 |
|
565 |
else |
|
566 |
begin |
|
567 |
if Land[y, x] = 0 then |
|
568 |
Land[y, x]:= COLOR_LAND |
|
569 |
else if Land[y, x] = COLOR_LAND then |
|
570 |
Land[y, x]:= 0; |
|
571 |
end; |
|
572 |
end; |
|
23 | 573 |
end; |
574 |
||
371 | 575 |
function SelectTemplate: LongInt; |
161 | 576 |
begin |
1797 | 577 |
case cTemplateFilter of |
578 |
0: begin |
|
579 |
SelectTemplate:= getrandom(Succ(High(EdgeTemplates))); |
|
580 |
end; |
|
581 |
1: begin |
|
582 |
SelectTemplate:= SmallTemplates[getrandom(Succ(High(SmallTemplates)))]; |
|
583 |
end; |
|
584 |
2: begin |
|
585 |
SelectTemplate:= MediumTemplates[getrandom(Succ(High(MediumTemplates)))]; |
|
586 |
end; |
|
587 |
3: begin |
|
588 |
SelectTemplate:= LargeTemplates[getrandom(Succ(High(LargeTemplates)))]; |
|
589 |
end; |
|
590 |
4: begin |
|
591 |
SelectTemplate:= CavernTemplates[getrandom(Succ(High(CavernTemplates)))]; |
|
592 |
end; |
|
593 |
5: begin |
|
594 |
SelectTemplate:= WackyTemplates[getrandom(Succ(High(WackyTemplates)))]; |
|
595 |
end; |
|
596 |
end; |
|
597 |
WriteLnToConsole('Selected template #'+inttostr(SelectTemplate)+' using filter #'+inttostr(cTemplateFilter)); |
|
161 | 598 |
end; |
599 |
||
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
600 |
procedure LandSurface2LandPixels(Surface: PSDL_Surface); |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
601 |
var x, y: LongInt; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
602 |
p: PLongwordArray; |
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1085
diff
changeset
|
603 |
begin |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
604 |
TryDo(Surface <> nil, 'Assert (LandSurface <> nil) failed', true); |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
605 |
|
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
606 |
if SDL_MustLock(Surface) then |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
607 |
SDLTry(SDL_LockSurface(Surface) >= 0, true); |
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1085
diff
changeset
|
608 |
|
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
609 |
p:= Surface^.pixels; |
1760 | 610 |
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
|
611 |
begin |
1760 | 612 |
for x:= 0 to LAND_WIDTH - 1 do |
2592 | 613 |
if Land[y, x] <> 0 then LandPixels[y, x]:= p^[x] or AMask; |
2376 | 614 |
|
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
615 |
p:= @(p^[Surface^.pitch div 4]); |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
616 |
end; |
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1085
diff
changeset
|
617 |
|
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
618 |
if SDL_MustLock(Surface) then |
1753 | 619 |
SDL_UnlockSurface(Surface); |
1754 | 620 |
end; |
621 |
||
622 |
procedure GenLandSurface; |
|
623 |
var tmpsurf: PSDL_Surface; |
|
624 |
begin |
|
625 |
WriteLnToConsole('Generating land...'); |
|
626 |
||
627 |
GenBlank(EdgeTemplates[SelectTemplate]); |
|
628 |
||
629 |
AddProgress; |
|
630 |
||
1760 | 631 |
tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, LAND_WIDTH, LAND_HEIGHT, 32, RMask, GMask, BMask, 0); |
1754 | 632 |
|
633 |
TryDo(tmpsurf <> nil, 'Error creating pre-land surface', true); |
|
634 |
ColorizeLand(tmpsurf); |
|
635 |
AddOnLandObjects(tmpsurf); |
|
636 |
||
637 |
LandSurface2LandPixels(tmpsurf); |
|
638 |
SDL_FreeSurface(tmpsurf); |
|
639 |
||
640 |
AddProgress; |
|
641 |
||
642 |
end; |
|
643 |
||
644 |
procedure MakeFortsMap; |
|
645 |
var tmpsurf: PSDL_Surface; |
|
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 |
// 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 | 648 |
playHeight:= 1200; |
2096 | 649 |
playWidth:= 2560; |
1776 | 650 |
leftX:= (LAND_WIDTH - playWidth) div 2; |
651 |
rightX:= ((playWidth + (LAND_WIDTH - playWidth) div 2) - 1); |
|
652 |
topY:= LAND_HEIGHT - playHeight; |
|
653 |
||
1754 | 654 |
WriteLnToConsole('Generating forts land...'); |
655 |
||
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
|
656 |
tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); |
1784 | 657 |
BlitImageAndGenerateCollisionInfo(leftX+150, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf); |
1754 | 658 |
SDL_FreeSurface(tmpsurf); |
659 |
||
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
|
660 |
tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); |
1784 | 661 |
BlitImageAndGenerateCollisionInfo(rightX - 150 - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf); |
1754 | 662 |
SDL_FreeSurface(tmpsurf); |
663 |
end; |
|
664 |
||
1792 | 665 |
// Hi unC0Rr. |
666 |
// This is a function that Tiy assures me would not be good for gameplay. |
|
667 |
// 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
|
668 |
// 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
|
669 |
// I would just like to play with it with my friends if you do not mind. |
1792 | 670 |
// Can allow for amusing maps. |
671 |
procedure LoadMask; |
|
672 |
var tmpsurf: PSDL_Surface; |
|
673 |
p: PLongwordArray; |
|
674 |
x, y, cpX, cpY: Longword; |
|
675 |
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
|
676 |
tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps); |
1792 | 677 |
if (tmpsurf <> nil) and (tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT) and (tmpsurf^.format^.BytesPerPixel = 4) then |
678 |
begin |
|
679 |
cpX:= (LAND_WIDTH - tmpsurf^.w) div 2; |
|
680 |
cpY:= LAND_HEIGHT - tmpsurf^.h; |
|
681 |
if SDL_MustLock(tmpsurf) then |
|
682 |
SDLTry(SDL_LockSurface(tmpsurf) >= 0, true); |
|
2376 | 683 |
|
1792 | 684 |
p:= tmpsurf^.pixels; |
685 |
for y:= 0 to Pred(tmpsurf^.h) do |
|
686 |
begin |
|
687 |
for x:= 0 to Pred(tmpsurf^.w) do |
|
1849 | 688 |
begin |
2592 | 689 |
if ((AMask and p^[x]) = 0) then // Tiy was having trouble generating transparent black |
1849 | 690 |
Land[cpY + y, cpX + x]:= 0 |
2592 | 691 |
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
|
692 |
Land[cpY + y, cpX + x]:= COLOR_INDESTRUCTIBLE |
2592 | 693 |
else if p^[x] = (AMask or RMask or GMask or BMask) then |
2243
b4764993f833
additional touch support and nemo's reduced land array size
koda
parents:
2240
diff
changeset
|
694 |
Land[cpY + y, cpX + x]:= COLOR_LAND; |
b4764993f833
additional touch support and nemo's reduced land array size
koda
parents:
2240
diff
changeset
|
695 |
|
1849 | 696 |
end; |
1792 | 697 |
p:= @(p^[tmpsurf^.pitch div 4]); |
698 |
end; |
|
2376 | 699 |
|
1792 | 700 |
if SDL_MustLock(tmpsurf) then |
701 |
SDL_UnlockSurface(tmpsurf); |
|
702 |
SDL_FreeSurface(tmpsurf); |
|
703 |
end; |
|
704 |
end; |
|
705 |
||
1754 | 706 |
procedure LoadMap; |
707 |
var tmpsurf: PSDL_Surface; |
|
1795 | 708 |
s: string; |
709 |
f: textfile; |
|
1754 | 710 |
begin |
711 |
WriteLnToConsole('Loading land from file...'); |
|
712 |
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
|
713 |
tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); |
1760 | 714 |
TryDo((tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT), 'Map dimensions too big!', true); |
1754 | 715 |
|
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
|
716 |
// unC0Rr - should this be passed from the GUI? I am not sure which layer does what |
1792 | 717 |
s:= Pathz[ptMapCurrent] + '/map.cfg'; |
718 |
WriteLnToConsole('Fetching map HH limit'); |
|
719 |
Assign(f, s); |
|
720 |
Reset(f); |
|
1795 | 721 |
Readln(f); |
722 |
if not eof(f) then Readln(f, MaxHedgehogs); |
|
723 |
||
1792 | 724 |
if(MaxHedgehogs = 0) then MaxHedgehogs:= 18; |
725 |
||
1776 | 726 |
playHeight:= tmpsurf^.h; |
727 |
playWidth:= tmpsurf^.w; |
|
728 |
leftX:= (LAND_WIDTH - playWidth) div 2; |
|
729 |
rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; |
|
730 |
topY:= LAND_HEIGHT - playHeight; |
|
731 |
||
1754 | 732 |
TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Map should be 32bit', true); |
733 |
||
1772 | 734 |
BlitImageAndGenerateCollisionInfo( |
735 |
(LAND_WIDTH - tmpsurf^.w) div 2, |
|
736 |
LAND_HEIGHT - tmpsurf^.h, |
|
737 |
tmpsurf^.w, |
|
738 |
tmpsurf); |
|
1754 | 739 |
SDL_FreeSurface(tmpsurf); |
1792 | 740 |
|
741 |
LoadMask; |
|
1754 | 742 |
end; |
743 |
||
744 |
procedure GenMap; |
|
1784 | 745 |
var x, y, w, c: Longword; |
1754 | 746 |
begin |
1776 | 747 |
hasBorder:= false; |
748 |
hasGirders:= true; |
|
1754 | 749 |
LoadThemeConfig; |
750 |
||
751 |
if (GameFlags and gfForts) = 0 then |
|
752 |
if Pathz[ptMapCurrent] <> '' then LoadMap |
|
753 |
else GenLandSurface |
|
754 |
else MakeFortsMap; |
|
755 |
AddProgress; |
|
1760 | 756 |
|
1754 | 757 |
{$IFDEF DEBUGFILE}LogLandDigest;{$ENDIF} |
1753 | 758 |
|
1768 | 759 |
// check for land near top |
1784 | 760 |
c:= 0; |
761 |
if (GameFlags and gfBorder) <> 0 then |
|
762 |
hasBorder:= true |
|
763 |
else |
|
764 |
for y:= topY to topY + 5 do |
|
765 |
for x:= leftX to rightX do |
|
766 |
if Land[y, x] <> 0 then |
|
767 |
begin |
|
768 |
inc(c); |
|
769 |
if c > 200 then // avoid accidental triggering |
|
770 |
begin |
|
771 |
hasBorder:= true; |
|
772 |
break; |
|
773 |
end; |
|
774 |
end; |
|
1768 | 775 |
|
1776 | 776 |
if hasBorder then |
1768 | 777 |
begin |
1784 | 778 |
for y:= 0 to LAND_HEIGHT - 1 do |
779 |
for x:= 0 to LAND_WIDTH - 1 do |
|
780 |
if (y < topY) or (x < leftX) or (x > rightX) then |
|
781 |
Land[y, x]:= COLOR_INDESTRUCTIBLE; |
|
1768 | 782 |
// experiment hardcoding cave |
1784 | 783 |
// also try basing cave dimensions on map/template dimensions, if they exist |
2308 | 784 |
for w:= 0 to 5 do // width of 3 allowed hogs to be knocked through with grenade |
1784 | 785 |
begin |
786 |
for y:= topY to LAND_HEIGHT - 1 do |
|
787 |
begin |
|
788 |
Land[y, leftX + w]:= COLOR_INDESTRUCTIBLE; |
|
789 |
Land[y, rightX - w]:= COLOR_INDESTRUCTIBLE; |
|
790 |
if (y + w) mod 32 < 16 then |
|
2592 | 791 |
c:= AMask |
1784 | 792 |
else |
2592 | 793 |
c:= AMask or RMask or GMask; |
1784 | 794 |
LandPixels[y, leftX + w]:= c; |
795 |
LandPixels[y, rightX - w]:= c; |
|
796 |
end; |
|
1768 | 797 |
|
1784 | 798 |
for x:= leftX to rightX do |
799 |
begin |
|
800 |
Land[topY + w, x]:= COLOR_INDESTRUCTIBLE; |
|
801 |
if (x + w) mod 32 < 16 then |
|
2592 | 802 |
c:= AMask |
1784 | 803 |
else |
2592 | 804 |
c:= AMask or RMask or GMask; |
1784 | 805 |
LandPixels[topY + w, x]:= c; |
806 |
end; |
|
807 |
end; |
|
1768 | 808 |
end; |
809 |
||
1776 | 810 |
if ((GameFlags and gfForts) = 0) and (Pathz[ptMapCurrent] = '') then AddObjects; |
811 |
||
1807 | 812 |
UpdateLandTexture(0, LAND_WIDTH, 0, LAND_HEIGHT); |
37 | 813 |
end; |
814 |
||
566 | 815 |
function GenPreview: TPreview; |
371 | 816 |
var x, y, xx, yy, t, bit: LongInt; |
566 | 817 |
Preview: TPreview; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
818 |
begin |
160 | 819 |
WriteLnToConsole('Generating preview...'); |
161 | 820 |
GenBlank(EdgeTemplates[SelectTemplate]); |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
821 |
|
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
822 |
for y:= 0 to 127 do |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
823 |
for x:= 0 to 31 do |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
824 |
begin |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
825 |
Preview[y, x]:= 0; |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
826 |
for bit:= 0 to 7 do |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
827 |
begin |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
828 |
t:= 0; |
1760 | 829 |
for yy:= y * (LAND_HEIGHT div 128) to y * (LAND_HEIGHT div 128) + 7 do |
830 |
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
|
831 |
if Land[yy, xx] <> 0 then inc(t); |
351 | 832 |
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
|
833 |
end |
566 | 834 |
end; |
1768 | 835 |
GenPreview:= Preview |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
836 |
end; |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
837 |
|
51 | 838 |
initialization |
839 |
||
4 | 840 |
end. |