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