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