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