author | Wuzzy <Wuzzy2@mail.ru> |
Thu, 29 Nov 2018 17:13:09 +0100 | |
changeset 14348 | 2221c418026a |
parent 14291 | 7a7c090f96f6 |
child 14421 | 96624a6cdb93 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
11046 | 3 |
* Copyright (c) 2004-2015 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 |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
10040
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4 | 17 |
*) |
18 |
||
2599 | 19 |
{$INCLUDE "options.inc"} |
2587
0dfa56a8513c
fix a segfault in the iphone simulator by moving options.inc at the beginning of the file
koda
parents:
2376
diff
changeset
|
20 |
|
4 | 21 |
unit uLand; |
22 |
interface |
|
10249 | 23 |
uses SDLh, uLandTemplates, uConsts, uTypes, uAILandMarks; |
4 | 24 |
|
3038 | 25 |
procedure initModule; |
26 |
procedure freeModule; |
|
5717 | 27 |
procedure DrawBottomBorder; |
37 | 28 |
procedure GenMap; |
7079 | 29 |
procedure GenPreview(out Preview: TPreview); |
10162 | 30 |
procedure GenPreviewAlpha(out Preview: TPreviewAlpha); |
4 | 31 |
|
32 |
implementation |
|
11831
7654e2357934
implement ExtraftFileDir and ExtractFileName in uUtils
sheepluva
parents:
11751
diff
changeset
|
33 |
uses uConsole, uStore, uRandom, uLandObjects, uIO, uLandTexture, |
6626
a447993f2ad7
Further work on propagating types. Now it hopefully works fully, just need to annotate namespace with types first.
unc0rr
parents:
6580
diff
changeset
|
34 |
uVariables, uUtils, uCommands, adler32, uDebug, uLandPainted, uTextures, |
10249 | 35 |
uLandGenMaze, uPhysFSLayer, uScript, uLandGenPerlin, |
11654
1fd1525653d8
SDL blit wraps at 16,384 - not the first time that routine has disappointed us.
nemo
parents:
11544
diff
changeset
|
36 |
uLandGenTemplateBased, uLandUtils, uRenderUtils; |
365 | 37 |
|
7028 | 38 |
var digest: shortstring; |
11019
67ef02300508
always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents:
11006
diff
changeset
|
39 |
maskOnly: boolean; |
4 | 40 |
|
7477
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
41 |
|
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
42 |
procedure PrettifyLandAlpha(); |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
43 |
begin |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
44 |
if (cReducedQuality and rqBlurryLand) <> 0 then |
10018
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
45 |
PrettifyAlpha2D(LandPixels, LAND_HEIGHT div 2, LAND_WIDTH div 2) |
7477
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
46 |
else |
10018
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
47 |
PrettifyAlpha2D(LandPixels, LAND_HEIGHT, LAND_WIDTH); |
7477
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
48 |
end; |
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
49 |
|
9387 | 50 |
procedure DrawBorderFromImage(Surface: PSDL_Surface); |
4 | 51 |
var tmpsurf: PSDL_Surface; |
11655 | 52 |
//r, rr: TSDL_Rect; |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
53 |
x, yd, yu: LongInt; |
11019
67ef02300508
always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents:
11006
diff
changeset
|
54 |
targetMask: Word; |
4 | 55 |
begin |
12597 | 56 |
tmpsurf:= LoadDataImage(ptCurrTheme, 'Border', ifCritical or ifIgnoreCaps or ifColorKey); |
11019
67ef02300508
always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents:
11006
diff
changeset
|
57 |
|
67ef02300508
always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents:
11006
diff
changeset
|
58 |
// if mask only, all land gets filled with landtex and therefore needs borders |
67ef02300508
always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents:
11006
diff
changeset
|
59 |
if maskOnly then |
67ef02300508
always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents:
11006
diff
changeset
|
60 |
targetMask:= lfLandMask |
67ef02300508
always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents:
11006
diff
changeset
|
61 |
else |
67ef02300508
always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents:
11006
diff
changeset
|
62 |
targetMask:= lfBasic; |
67ef02300508
always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents:
11006
diff
changeset
|
63 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
64 |
for x:= 0 to LAND_WIDTH - 1 do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
65 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
66 |
yd:= LAND_HEIGHT - 1; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
67 |
repeat |
11019
67ef02300508
always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents:
11006
diff
changeset
|
68 |
while (yd > 0) and ((Land[yd, x] and targetMask) = 0) do dec(yd); |
2376 | 69 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
70 |
if (yd < 0) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
71 |
yd:= 0; |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
72 |
|
11019
67ef02300508
always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents:
11006
diff
changeset
|
73 |
while (yd < LAND_HEIGHT) and ((Land[yd, x] and targetMask) <> 0) do |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
74 |
inc(yd); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
75 |
dec(yd); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
76 |
yu:= yd; |
2376 | 77 |
|
11019
67ef02300508
always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents:
11006
diff
changeset
|
78 |
while (yu > 0 ) and ((Land[yu, x] and targetMask) <> 0) do dec(yu); |
67ef02300508
always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents:
11006
diff
changeset
|
79 |
while (yu < yd ) and ((Land[yu, x] and targetMask) = 0) do inc(yu); |
2376 | 80 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
81 |
if (yd < LAND_HEIGHT - 1) and ((yd - yu) >= 16) then |
11655 | 82 |
copyToXYFromRect(tmpsurf, Surface, x mod tmpsurf^.w, 16, 1, 16, x, yd - 15); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
83 |
if (yu > 0) then |
11655 | 84 |
copyToXYFromRect(tmpsurf, Surface, x mod tmpsurf^.w, 0, 1, Min(16, yd - yu + 1), x, yu); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
85 |
yd:= yu - 1; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
86 |
until yd < 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
87 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
88 |
SDL_FreeSurface(tmpsurf); |
4 | 89 |
end; |
90 |
||
9387 | 91 |
|
92 |
procedure DrawShoppaBorder; |
|
93 |
var x, y, s, i: Longword; |
|
94 |
c1, c2, c: Longword; |
|
95 |
begin |
|
96 |
c1:= AMask; |
|
97 |
c2:= AMask or RMask or GMask; |
|
98 |
||
99 |
// vertical |
|
100 |
s:= LAND_HEIGHT; |
|
10017 | 101 |
|
9387 | 102 |
for x:= 0 to LAND_WIDTH - 1 do |
103 |
for y:= 0 to LAND_HEIGHT - 1 do |
|
9864 | 104 |
if Land[y, x] = 0 then |
9387 | 105 |
if s < y then |
106 |
begin |
|
107 |
for i:= max(s, y - 8) to y - 1 do |
|
108 |
begin |
|
109 |
if ((x + i) and 16) = 0 then c:= c1 else c:= c2; |
|
10017 | 110 |
|
9387 | 111 |
if (cReducedQuality and rqBlurryLand) = 0 then |
112 |
LandPixels[i, x]:= c |
|
113 |
else |
|
114 |
LandPixels[i div 2, x div 2]:= c |
|
115 |
end; |
|
116 |
s:= LAND_HEIGHT |
|
117 |
end |
|
118 |
else |
|
119 |
else |
|
120 |
begin |
|
121 |
if s > y then s:= y; |
|
122 |
if s + 8 > y then |
|
123 |
begin |
|
124 |
if ((x + y) and 16) = 0 then c:= c1 else c:= c2; |
|
10017 | 125 |
|
9387 | 126 |
if (cReducedQuality and rqBlurryLand) = 0 then |
127 |
LandPixels[y, x]:= c |
|
128 |
else |
|
129 |
LandPixels[y div 2, x div 2]:= c |
|
10017 | 130 |
end; |
9387 | 131 |
end; |
10017 | 132 |
|
9387 | 133 |
// horizontal |
134 |
s:= LAND_WIDTH; |
|
10017 | 135 |
|
9387 | 136 |
for y:= 0 to LAND_HEIGHT - 1 do |
137 |
for x:= 0 to LAND_WIDTH - 1 do |
|
9864 | 138 |
if Land[y, x] = 0 then |
9387 | 139 |
if s < x then |
140 |
begin |
|
141 |
for i:= max(s, x - 8) to x - 1 do |
|
142 |
begin |
|
143 |
if ((y + i) and 16) = 0 then c:= c1 else c:= c2; |
|
10017 | 144 |
|
9387 | 145 |
if (cReducedQuality and rqBlurryLand) = 0 then |
146 |
LandPixels[y, i]:= c |
|
147 |
else |
|
148 |
LandPixels[y div 2, i div 2]:= c |
|
149 |
end; |
|
150 |
s:= LAND_WIDTH |
|
151 |
end |
|
152 |
else |
|
153 |
else |
|
154 |
begin |
|
155 |
if s > x then s:= x; |
|
156 |
if s + 8 > x then |
|
157 |
begin |
|
158 |
if ((x + y) and 16) = 0 then c:= c1 else c:= c2; |
|
10017 | 159 |
|
9387 | 160 |
if (cReducedQuality and rqBlurryLand) = 0 then |
161 |
LandPixels[y, x]:= c |
|
162 |
else |
|
163 |
LandPixels[y div 2, x div 2]:= c |
|
10017 | 164 |
end; |
9387 | 165 |
end |
166 |
end; |
|
167 |
||
12109 | 168 |
procedure ColorizeLandFast(mapsurf: PSDL_Surface); |
169 |
var ltexsurf: PSDL_Surface; |
|
170 |
i: LongInt; |
|
171 |
ltlnp, srcp, dstp, stopp: Pointer; |
|
172 |
c: SizeInt; |
|
12105 | 173 |
begin |
12109 | 174 |
ltexsurf:= LoadDataImage(ptCurrTheme, 'LandTex', ifCritical or ifIgnoreCaps); |
12105 | 175 |
|
12109 | 176 |
// pointer to current line of ltexsurf pixels. will be moved from line to line |
177 |
ltlnp:= ltexsurf^.pixels; |
|
178 |
// pointer to mapsurf pixels. will jump forward after every move() |
|
179 |
dstp:= mapsurf^.pixels; |
|
180 |
||
181 |
// time to get serious |
|
182 |
SDL_LockSurface(mapsurf); |
|
183 |
SDL_LockSurface(ltexsurf); |
|
184 |
||
185 |
// for now only fill a row with the height of landtex. do vertical copies within mapsurf after |
|
12105 | 186 |
|
12109 | 187 |
// do this loop for each line of ltexsurf (unless we run out of map height first) |
188 |
for i:= 1 to min(ltexsurf^.h, mapsurf^.h) do |
|
189 |
begin |
|
190 |
// amount of pixels to write in first move() |
|
191 |
c:= ltexsurf^.pitch; |
|
12105 | 192 |
|
12109 | 193 |
// protect from odd cases where landtex wider than map |
194 |
if c > mapsurf^.pitch then |
|
195 |
c:= mapsurf^.pitch; |
|
196 |
||
197 |
// write line of landtex to mapsurf |
|
198 |
move(ltlnp^, dstp^, c); |
|
12105 | 199 |
|
12109 | 200 |
// fill the rest of the line by copying left-to-right until full |
201 |
||
202 |
// new src is start of line that we've just written to |
|
203 |
srcp:= dstp; |
|
204 |
// set stop pointer to start of next pixel line of mapsurf |
|
205 |
stopp:= dstp + mapsurf^.pitch; |
|
206 |
// move dst pointer to after what we've just written |
|
207 |
inc(dstp, c); |
|
208 |
||
209 |
// loop until dstp went past end of line |
|
210 |
while dstp < stopp do |
|
12105 | 211 |
begin |
12109 | 212 |
// copy all from left of dstp to right of it (or just fill the gap if smaller) |
213 |
c:= min(dstp-srcp, stopp-dstp); |
|
12105 | 214 |
move(srcp^, dstp^, c); |
215 |
inc(dstp, c); |
|
216 |
end; |
|
217 |
||
12109 | 218 |
// move to next line in ltexsurf |
219 |
inc(ltlnp, ltexsurf^.pitch); |
|
12105 | 220 |
end; |
221 |
||
12109 | 222 |
// we don't need ltexsurf itself anymore -> cleanup |
223 |
ltlnp:= nil; |
|
224 |
SDL_UnlockSurface(ltexsurf); |
|
225 |
SDL_FreeSurface(ltexsurf); |
|
226 |
ltexsurf:= nil; |
|
12105 | 227 |
|
12109 | 228 |
// from now on only copy pixels within mapsurf |
12105 | 229 |
|
230 |
// copy all the already written lines at once for that get number of written bytes so far |
|
12109 | 231 |
// already written pixels are between start and current dstp |
232 |
srcp:= mapsurf^.pixels; |
|
12105 | 233 |
|
12109 | 234 |
// first byte after end of pixels |
235 |
stopp:= srcp + (mapsurf^.pitch * mapsurf^.h); |
|
12105 | 236 |
|
12109 | 237 |
while dstp < stopp do |
12105 | 238 |
begin |
12109 | 239 |
// copy all from before dstp to after (or just fill the gap if smaller) |
240 |
c:= min(dstp-srcp, stopp-dstp); |
|
241 |
// worried about size of c with humongous maps? don't be: |
|
242 |
// the OS wouldn't have allowed allocation of object with size > max of SizeInt anyway |
|
12105 | 243 |
move(srcp^, dstp^, c); |
244 |
inc(dstp, c); |
|
245 |
end; |
|
246 |
||
12109 | 247 |
// cleanup |
248 |
srcp:= nil; |
|
249 |
dstp:= nil; |
|
250 |
stopp:= nil; |
|
251 |
SDL_UnlockSurface(mapsurf); |
|
12105 | 252 |
|
253 |
// freed in freeModule() below |
|
12597 | 254 |
LandBackSurface:= LoadDataImage(ptCurrTheme, 'LandBackTex', ifIgnoreCaps or ifColorKey); |
12105 | 255 |
if (LandBackSurface <> nil) and GrayScale then Surface2GrayScale(LandBackSurface); |
256 |
end; |
|
257 |
||
9387 | 258 |
procedure ColorizeLand(Surface: PSDL_Surface); |
259 |
var tmpsurf: PSDL_Surface; |
|
260 |
r: TSDL_Rect; |
|
10197 | 261 |
y: LongInt; // stupid SDL 1.2 uses stupid SmallInt for y which limits us to 32767. But is even worse if LandTex is large, can overflow on 32767 map. |
9387 | 262 |
begin |
263 |
tmpsurf:= LoadDataImage(ptCurrTheme, 'LandTex', ifCritical or ifIgnoreCaps); |
|
264 |
r.y:= 0; |
|
9892
5a0a7ef7af2d
allow SDL 1.2 to at least do a 32767 map. We probably should add a TryDo somewhere to assert that limit on SDL 1.2 to avoid overflows. Ditto int version for SDL 2
nemo
parents:
9864
diff
changeset
|
265 |
y:= 0; |
5a0a7ef7af2d
allow SDL 1.2 to at least do a 32767 map. We probably should add a TryDo somewhere to assert that limit on SDL 1.2 to avoid overflows. Ditto int version for SDL 2
nemo
parents:
9864
diff
changeset
|
266 |
while y < LAND_HEIGHT do |
5a0a7ef7af2d
allow SDL 1.2 to at least do a 32767 map. We probably should add a TryDo somewhere to assert that limit on SDL 1.2 to avoid overflows. Ditto int version for SDL 2
nemo
parents:
9864
diff
changeset
|
267 |
begin |
9387 | 268 |
r.x:= 0; |
269 |
while r.x < LAND_WIDTH do |
|
9892
5a0a7ef7af2d
allow SDL 1.2 to at least do a 32767 map. We probably should add a TryDo somewhere to assert that limit on SDL 1.2 to avoid overflows. Ditto int version for SDL 2
nemo
parents:
9864
diff
changeset
|
270 |
begin |
11654
1fd1525653d8
SDL blit wraps at 16,384 - not the first time that routine has disappointed us.
nemo
parents:
11544
diff
changeset
|
271 |
copyToXY(tmpsurf, Surface, r.x, r.y); |
1fd1525653d8
SDL blit wraps at 16,384 - not the first time that routine has disappointed us.
nemo
parents:
11544
diff
changeset
|
272 |
//SDL_UpperBlit(tmpsurf, nil, Surface, @r); |
9387 | 273 |
inc(r.x, tmpsurf^.w) |
9892
5a0a7ef7af2d
allow SDL 1.2 to at least do a 32767 map. We probably should add a TryDo somewhere to assert that limit on SDL 1.2 to avoid overflows. Ditto int version for SDL 2
nemo
parents:
9864
diff
changeset
|
274 |
end; |
5a0a7ef7af2d
allow SDL 1.2 to at least do a 32767 map. We probably should add a TryDo somewhere to assert that limit on SDL 1.2 to avoid overflows. Ditto int version for SDL 2
nemo
parents:
9864
diff
changeset
|
275 |
inc(y, tmpsurf^.h); |
5a0a7ef7af2d
allow SDL 1.2 to at least do a 32767 map. We probably should add a TryDo somewhere to assert that limit on SDL 1.2 to avoid overflows. Ditto int version for SDL 2
nemo
parents:
9864
diff
changeset
|
276 |
r.y:= y |
9387 | 277 |
end; |
278 |
SDL_FreeSurface(tmpsurf); |
|
279 |
||
280 |
// freed in freeModule() below |
|
12597 | 281 |
LandBackSurface:= LoadDataImage(ptCurrTheme, 'LandBackTex', ifIgnoreCaps or ifColorKey); |
9387 | 282 |
if (LandBackSurface <> nil) and GrayScale then Surface2GrayScale(LandBackSurface); |
283 |
end; |
|
284 |
||
23 | 285 |
|
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
286 |
procedure GenDrawnMap; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
287 |
begin |
7477
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
288 |
ResizeLand(4096, 2048); |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
289 |
uLandPainted.Draw; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
290 |
|
4559 | 291 |
MaxHedgehogs:= 48; |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
292 |
hasGirders:= true; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
293 |
playHeight:= 2048; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
294 |
playWidth:= 4096; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
295 |
leftX:= ((LAND_WIDTH - playWidth) div 2); |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
296 |
rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
297 |
topY:= LAND_HEIGHT - playHeight; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
298 |
end; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
299 |
|
371 | 300 |
function SelectTemplate: LongInt; |
9243
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
301 |
var l: LongInt; |
161 | 302 |
begin |
14289 | 303 |
SelectTemplate:= 0; |
3612
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3608
diff
changeset
|
304 |
if (cReducedQuality and rqLowRes) <> 0 then |
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3608
diff
changeset
|
305 |
SelectTemplate:= SmallTemplates[getrandom(Succ(High(SmallTemplates)))] |
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3608
diff
changeset
|
306 |
else |
14289 | 307 |
begin |
9243
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
308 |
if cTemplateFilter = 0 then |
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
309 |
begin |
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
310 |
l:= getRandom(GroupedTemplatesCount); |
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
311 |
repeat |
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
312 |
inc(cTemplateFilter); |
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
313 |
dec(l, TemplateCounts[cTemplateFilter]); |
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
314 |
until l < 0; |
14289 | 315 |
end |
316 |
else getRandom(1); |
|
10017 | 317 |
|
14289 | 318 |
case cTemplateFilter of |
319 |
0: OutError('Error selecting TemplateFilter. Ask unC0Rr about what you did wrong', true); |
|
320 |
1: SelectTemplate:= SmallTemplates[getrandom(TemplateCounts[cTemplateFilter])]; |
|
321 |
2: SelectTemplate:= MediumTemplates[getrandom(TemplateCounts[cTemplateFilter])]; |
|
322 |
3: SelectTemplate:= LargeTemplates[getrandom(TemplateCounts[cTemplateFilter])]; |
|
323 |
4: SelectTemplate:= CavernTemplates[getrandom(TemplateCounts[cTemplateFilter])]; |
|
324 |
5: SelectTemplate:= WackyTemplates[getrandom(TemplateCounts[cTemplateFilter])]; |
|
325 |
// For lua only! |
|
326 |
6: begin |
|
327 |
SelectTemplate:= min(LuaTemplateNumber,High(EdgeTemplates)); |
|
328 |
GetRandom(2) // burn 1 |
|
329 |
end |
|
330 |
end |
|
331 |
end; |
|
3612
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3608
diff
changeset
|
332 |
|
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3608
diff
changeset
|
333 |
WriteLnToConsole('Selected template #'+inttostr(SelectTemplate)+' using filter #'+inttostr(cTemplateFilter)); |
161 | 334 |
end; |
335 |
||
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
336 |
procedure LandSurface2LandPixels(Surface: PSDL_Surface); |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
337 |
var x, y: LongInt; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
338 |
p: PLongwordArray; |
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1085
diff
changeset
|
339 |
begin |
11537 | 340 |
if checkFails(Surface <> nil, 'Assert (LandSurface <> nil) failed', true) then exit; |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
341 |
|
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
342 |
if SDL_MustLock(Surface) then |
11512 | 343 |
if SDLCheck(SDL_LockSurface(Surface) >= 0, 'SDL_LockSurface', true) then exit; |
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1085
diff
changeset
|
344 |
|
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
345 |
p:= Surface^.pixels; |
1760 | 346 |
for y:= 0 to LAND_HEIGHT - 1 do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
347 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
348 |
for x:= 0 to LAND_WIDTH - 1 do |
3598 | 349 |
if Land[y, x] <> 0 then |
3595
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3551
diff
changeset
|
350 |
if (cReducedQuality and rqBlurryLand) = 0 then |
11478
023db094b22d
Some themers expressed desire to have translucent themes. While the current AA stuff in uLandGraphics won't really allow this to work with LandBackTex properly, seems to me it should be safe to allow alpha for LandTex. Our LandTex should all have alpha of 255 on the existing themes.
nemo
parents:
11342
diff
changeset
|
351 |
LandPixels[y, x]:= p^[x]// or AMask |
3595
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3551
diff
changeset
|
352 |
else |
11478
023db094b22d
Some themers expressed desire to have translucent themes. While the current AA stuff in uLandGraphics won't really allow this to work with LandBackTex properly, seems to me it should be safe to allow alpha for LandTex. Our LandTex should all have alpha of 255 on the existing themes.
nemo
parents:
11342
diff
changeset
|
353 |
LandPixels[y div 2, x div 2]:= p^[x];// or AMask; |
2376 | 354 |
|
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10108
diff
changeset
|
355 |
p:= PLongwordArray(@(p^[Surface^.pitch div 4])); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
356 |
end; |
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1085
diff
changeset
|
357 |
|
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
358 |
if SDL_MustLock(Surface) then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
359 |
SDL_UnlockSurface(Surface); |
1754 | 360 |
end; |
361 |
||
3133 | 362 |
|
1754 | 363 |
procedure GenLandSurface; |
364 |
var tmpsurf: PSDL_Surface; |
|
5225 | 365 |
x,y: Longword; |
1754 | 366 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
367 |
AddProgress(); |
1754 | 368 |
|
11478
023db094b22d
Some themers expressed desire to have translucent themes. While the current AA stuff in uLandGraphics won't really allow this to work with LandBackTex properly, seems to me it should be safe to allow alpha for LandTex. Our LandTex should all have alpha of 255 on the existing themes.
nemo
parents:
11342
diff
changeset
|
369 |
tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, LAND_WIDTH, LAND_HEIGHT, 32, RMask, GMask, BMask, AMask); |
1754 | 370 |
|
11537 | 371 |
if checkFails(tmpsurf <> nil, 'Error creating pre-land surface', true) then exit; |
12105 | 372 |
ColorizeLandFast(tmpsurf); |
9387 | 373 |
if gameFlags and gfShoppaBorder = 0 then DrawBorderFromImage(tmpsurf); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
374 |
AddOnLandObjects(tmpsurf); |
1754 | 375 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
376 |
LandSurface2LandPixels(tmpsurf); |
5227 | 377 |
SDL_FreeSurface(tmpsurf); |
10017 | 378 |
|
9387 | 379 |
if gameFlags and gfShoppaBorder <> 0 then DrawShoppaBorder; |
10017 | 380 |
|
14287
6015b74eea55
overall, using LongInt for leftX/rightX results in fewer casts, since most comparisons are against ints.
nemo
parents:
13793
diff
changeset
|
381 |
for x:= LongWord(leftX+2) to LongWord(rightX-2) do |
14291 | 382 |
for y:= LongWord(topY+2) to LAND_HEIGHT-3 do |
10017 | 383 |
if (Land[y, x] = 0) and |
5274 | 384 |
(((Land[y, x-1] = lfBasic) and ((Land[y+1,x] = lfBasic)) or (Land[y-1,x] = lfBasic)) or |
385 |
((Land[y, x+1] = lfBasic) and ((Land[y-1,x] = lfBasic) or (Land[y+1,x] = lfBasic)))) then |
|
386 |
begin |
|
387 |
if (cReducedQuality and rqBlurryLand) = 0 then |
|
388 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
389 |
if (Land[y, x-1] = lfBasic) and (LandPixels[y, x-1] and AMask <> 0) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
390 |
LandPixels[y, x]:= LandPixels[y, x-1] |
10017 | 391 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
392 |
else if (Land[y, x+1] = lfBasic) and (LandPixels[y, x+1] and AMask <> 0) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
393 |
LandPixels[y, x]:= LandPixels[y, x+1] |
10017 | 394 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
395 |
else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1, x] and AMask <> 0) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
396 |
LandPixels[y, x]:= LandPixels[y-1, x] |
10017 | 397 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
398 |
else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1, x] and AMask <> 0) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
399 |
LandPixels[y, x]:= LandPixels[y+1, x]; |
10017 | 400 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
401 |
if (((LandPixels[y,x] and AMask) shr AShift) > 10) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
402 |
LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (128 shl AShift) |
5274 | 403 |
end; |
404 |
Land[y,x]:= lfObject |
|
405 |
end |
|
406 |
else if (Land[y, x] = 0) and |
|
407 |
(((Land[y, x-1] = lfBasic) and (Land[y+1,x-1] = lfBasic) and (Land[y+2,x] = lfBasic)) or |
|
408 |
((Land[y, x-1] = lfBasic) and (Land[y-1,x-1] = lfBasic) and (Land[y-2,x] = lfBasic)) or |
|
409 |
((Land[y, x+1] = lfBasic) and (Land[y+1,x+1] = lfBasic) and (Land[y+2,x] = lfBasic)) or |
|
410 |
((Land[y, x+1] = lfBasic) and (Land[y-1,x+1] = lfBasic) and (Land[y-2,x] = lfBasic)) or |
|
411 |
((Land[y+1, x] = lfBasic) and (Land[y+1,x+1] = lfBasic) and (Land[y,x+2] = lfBasic)) or |
|
412 |
((Land[y-1, x] = lfBasic) and (Land[y-1,x+1] = lfBasic) and (Land[y,x+2] = lfBasic)) or |
|
413 |
((Land[y+1, x] = lfBasic) and (Land[y+1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic)) or |
|
414 |
((Land[y-1, x] = lfBasic) and (Land[y-1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic))) then |
|
10017 | 415 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
416 |
begin |
10017 | 417 |
|
5274 | 418 |
if (cReducedQuality and rqBlurryLand) = 0 then |
10017 | 419 |
|
5274 | 420 |
begin |
10017 | 421 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
422 |
if (Land[y, x-1] = lfBasic) and (LandPixels[y,x-1] and AMask <> 0) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
423 |
LandPixels[y, x]:= LandPixels[y, x-1] |
10017 | 424 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
425 |
else if (Land[y, x+1] = lfBasic) and (LandPixels[y,x+1] and AMask <> 0) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
426 |
LandPixels[y, x]:= LandPixels[y, x+1] |
10017 | 427 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
428 |
else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1,x] and AMask <> 0) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
429 |
LandPixels[y, x]:= LandPixels[y+1, x] |
10017 | 430 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
431 |
else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1,x] and AMask <> 0) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
432 |
LandPixels[y, x]:= LandPixels[y-1, x]; |
10017 | 433 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
434 |
if (((LandPixels[y,x] and AMask) shr AShift) > 10) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
435 |
LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (64 shl AShift) |
5274 | 436 |
end; |
437 |
Land[y,x]:= lfObject |
|
438 |
end; |
|
5441
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
439 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
440 |
AddProgress(); |
1754 | 441 |
end; |
442 |
||
11749
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
443 |
procedure MakeFortsPreview; |
11750 | 444 |
var gap: LongInt; |
445 |
h1, h2, w1, w2, x, y, lastX, wbm, bmref: LongWord; |
|
11749
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
446 |
const fortHeight = 960; |
11750 | 447 |
fortWidth = 704; |
448 |
bmHeight = 53; |
|
449 |
bmWidth = 64; |
|
11749
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
450 |
begin |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
451 |
ResizeLand(4096,2048); |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
452 |
|
11750 | 453 |
lastX:= LAND_WIDTH-1; |
454 |
||
11749
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
455 |
gap:= (1024 - fortWidth) + 60 + 20 * cFeatureSize; |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
456 |
|
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
457 |
h2:= LAND_HEIGHT-1; |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
458 |
h1:= h2 - fortHeight; |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
459 |
w2:= (LAND_WIDTH - gap) div 2; |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
460 |
w1:= w2 - fortWidth; |
11750 | 461 |
wbm:= h1 + bmHeight; |
11749
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
462 |
|
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
463 |
// generate 2 forts in center |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
464 |
for y:= h1 to h2 do |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
465 |
for x:= w1 to w2 do |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
466 |
begin |
11751 | 467 |
if x mod 4 <> 0 then |
468 |
begin |
|
469 |
if (y <= wbm) and ((x - w1) mod (bmWidth * 2) >= bmWidth) then |
|
470 |
continue; |
|
471 |
Land[y,x]:= lfBasic; |
|
472 |
Land[y,lastX-x]:= lfBasic; |
|
473 |
end; |
|
11749
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
474 |
end; |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
475 |
|
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
476 |
w2:= w1 - gap; |
11750 | 477 |
w1:= max(0, w2 - fortWidth); |
478 |
wbm:= h1 + bmHeight; |
|
479 |
bmref:= w2 + bmWidth; |
|
11749
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
480 |
|
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
481 |
for y:= h1 to h2 do |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
482 |
for x:= w1 to w2 do |
11750 | 483 |
begin |
11751 | 484 |
if ((y - x) mod 2) = 0 then |
11749
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
485 |
begin |
11750 | 486 |
// align battlement on inner edge, because real outer edge could be offscreen |
487 |
if (y <= wbm) and ((LAND_WIDTH + x - bmref) mod (bmWidth * 2) >= bmWidth) then |
|
488 |
continue; |
|
11749
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
489 |
Land[y,x]:= lfBasic; |
11750 | 490 |
Land[y,lastX-x]:= lfBasic; |
11749
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
491 |
end; |
11750 | 492 |
end; |
11749
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
493 |
end; |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
494 |
|
1754 | 495 |
procedure MakeFortsMap; |
496 |
var tmpsurf: PSDL_Surface; |
|
11749
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
497 |
sectionWidth, i, t, p: integer; |
11710 | 498 |
mirror: boolean; |
11739 | 499 |
pc: PClan; |
1754 | 500 |
begin |
11739 | 501 |
|
11749
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
502 |
// make the gaps between forts adjustable if fort map was selected |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
503 |
if cMapGen = mgForts then |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
504 |
sectionWidth:= 1024 + 60 + 20 * cFeatureSize |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
505 |
else |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
506 |
sectionWidth:= 1024 * 300; |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
507 |
|
11739 | 508 |
// mix up spawn/fort order of clans |
11749
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
509 |
for i:= 0 to ClansCount - 1 do |
11739 | 510 |
begin |
11749
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
511 |
t:= GetRandom(ClansCount); |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
512 |
p:= GetRandom(ClansCount); |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
513 |
if t <> p then |
11739 | 514 |
begin |
11749
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
515 |
pc:= SpawnClansArray[t]; |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
516 |
SpawnClansArray[t]:= SpawnClansArray[p]; |
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
517 |
SpawnClansArray[p]:= pc; |
11739 | 518 |
end; |
519 |
end; |
|
520 |
||
11710 | 521 |
// figure out how much space we need |
522 |
playWidth:= sectionWidth * ClansCount; |
|
523 |
||
524 |
// note: LAND_WIDTH might be bigger than specified below (rounded to next power of 2) |
|
525 |
ResizeLand(playWidth, 2048); |
|
526 |
||
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2163
diff
changeset
|
527 |
// For now, defining a fort is playable area as 3072x1200 - there are no tall forts. The extra height is to avoid triggering border with current code, also if user turns on a border, it will give a bit more maneuvering room. |
1784 | 528 |
playHeight:= 1200; |
11710 | 529 |
|
530 |
// center playable area in land array |
|
531 |
leftX:= ((LAND_WIDTH - playWidth) div 2); |
|
1776 | 532 |
rightX:= ((playWidth + (LAND_WIDTH - playWidth) div 2) - 1); |
533 |
topY:= LAND_HEIGHT - playHeight; |
|
534 |
||
1754 | 535 |
WriteLnToConsole('Generating forts land...'); |
536 |
||
11710 | 537 |
for i := 0 to ClansCount - 1 do |
538 |
begin |
|
539 |
||
540 |
// face in random direction |
|
541 |
mirror:= (GetRandom(2) = 0); |
|
542 |
// make first/last fort face inwards |
|
11712
ecbf5e6c2c37
also make forts face inwards in wrap mode, if there are only 2 teams
sheepluva
parents:
11711
diff
changeset
|
543 |
if (WorldEdge <> weWrap) or (ClansCount = 2) then |
11711 | 544 |
mirror:= (i <> 0) and (mirror or (i = ClansCount - 1)); |
1754 | 545 |
|
11710 | 546 |
if mirror then |
547 |
begin |
|
548 |
// not critical because if no R we can fallback to mirrored L |
|
12597 | 549 |
tmpsurf:= LoadDataImage(ptForts, SpawnClansArray[i]^.Teams[0]^.FortName + 'R', ifAlpha or ifColorKey or ifIgnoreCaps); |
11710 | 550 |
// fallback |
551 |
if tmpsurf = nil then |
|
552 |
begin |
|
12597 | 553 |
tmpsurf:= LoadDataImage(ptForts, SpawnClansArray[i]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifColorKey or ifIgnoreCaps); |
11710 | 554 |
BlitImageAndGenerateCollisionInfo(leftX + sectionWidth * i + ((sectionWidth - tmpsurf^.w) div 2), LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf, 0, true); |
555 |
end |
|
556 |
else |
|
557 |
BlitImageAndGenerateCollisionInfo(leftX + sectionWidth * i + ((sectionWidth - tmpsurf^.w) div 2), LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf); |
|
558 |
SDL_FreeSurface(tmpsurf); |
|
559 |
end |
|
560 |
else |
|
561 |
begin |
|
12597 | 562 |
tmpsurf:= LoadDataImage(ptForts, SpawnClansArray[i]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifColorKey or ifIgnoreCaps); |
11710 | 563 |
BlitImageAndGenerateCollisionInfo(leftX + sectionWidth * i + ((sectionWidth - tmpsurf^.w) div 2), LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf); |
564 |
SDL_FreeSurface(tmpsurf); |
|
565 |
end; |
|
566 |
||
567 |
end; |
|
1754 | 568 |
end; |
569 |
||
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
570 |
procedure LoadMapConfig; |
8060 | 571 |
var f: PFSFile; |
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
572 |
s: shortstring; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
573 |
begin |
8025 | 574 |
s:= cPathz[ptMapCurrent] + '/map.cfg'; |
575 |
||
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
576 |
WriteLnToConsole('Fetching map HH limit'); |
8060 | 577 |
|
578 |
f:= pfsOpenRead(s); |
|
579 |
if f <> nil then |
|
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
580 |
begin |
8060 | 581 |
pfsReadLn(f, s); |
582 |
if not pfsEof(f) then |
|
583 |
begin |
|
584 |
pfsReadLn(f, s); |
|
585 |
val(s, MaxHedgehogs) |
|
586 |
end; |
|
587 |
||
588 |
pfsClose(f) |
|
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
589 |
end; |
8060 | 590 |
|
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
591 |
if (MaxHedgehogs = 0) then |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
592 |
MaxHedgehogs:= 18; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
593 |
end; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
594 |
|
5238
46ddaf14509d
Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents:
5231
diff
changeset
|
595 |
// Loads Land[] from an image, allowing overriding standard collision |
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
596 |
procedure LoadMask; |
1792 | 597 |
var tmpsurf: PSDL_Surface; |
598 |
p: PLongwordArray; |
|
599 |
x, y, cpX, cpY: Longword; |
|
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
600 |
mapName: shortstring; |
1792 | 601 |
begin |
12597 | 602 |
tmpsurf:= LoadDataImage(ptMapCurrent, 'mask', ifAlpha or ifColorKey or ifIgnoreCaps); |
5770 | 603 |
if tmpsurf = nil then |
604 |
begin |
|
8025 | 605 |
mapName:= ExtractFileName(cPathz[ptMapCurrent]); |
12597 | 606 |
tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/mask', ifAlpha or ifColorKey or ifIgnoreCaps); |
5770 | 607 |
end; |
3920
a54ca6185307
updated lua loading in the ifrontend and also fixed masked maps
koda
parents:
3912
diff
changeset
|
608 |
|
6096
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
609 |
|
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
610 |
if (tmpsurf <> nil) and (tmpsurf^.format^.BytesPerPixel = 4) then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
611 |
begin |
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
612 |
if LAND_WIDTH = 0 then |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
613 |
begin |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
614 |
LoadMapConfig; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
615 |
ResizeLand(tmpsurf^.w, tmpsurf^.h); |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
616 |
playHeight:= tmpsurf^.h; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
617 |
playWidth:= tmpsurf^.w; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
618 |
leftX:= (LAND_WIDTH - playWidth) div 2; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
619 |
rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
620 |
topY:= LAND_HEIGHT - playHeight; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
621 |
end; |
6096
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
622 |
disableLandBack:= true; |
2376 | 623 |
|
6096
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
624 |
cpX:= (LAND_WIDTH - tmpsurf^.w) div 2; |
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
625 |
cpY:= LAND_HEIGHT - tmpsurf^.h; |
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
626 |
if SDL_MustLock(tmpsurf) then |
11512 | 627 |
SDLCheck(SDL_LockSurface(tmpsurf) >= 0, 'SDL_LockSurface', true); |
6096
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
628 |
|
11512 | 629 |
if allOK then |
630 |
begin |
|
6096
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
631 |
p:= tmpsurf^.pixels; |
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
632 |
for y:= 0 to Pred(tmpsurf^.h) do |
8848
e9ebd63f8a03
So. Some themes have objects that seem to be large natural extensions of the landscape. Masks allow maintaining that. Lemme know if it doesn't look good. If it doesn't, can still use for ice/bounce/indestructible. Indestructible bunker object for example.
nemo
parents:
8370
diff
changeset
|
633 |
begin |
6096
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
634 |
for x:= 0 to Pred(tmpsurf^.w) do |
8848
e9ebd63f8a03
So. Some themes have objects that seem to be large natural extensions of the landscape. Masks allow maintaining that. Lemme know if it doesn't look good. If it doesn't, can still use for ice/bounce/indestructible. Indestructible bunker object for example.
nemo
parents:
8370
diff
changeset
|
635 |
SetLand(Land[cpY + y, cpX + x], p^[x]); |
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10108
diff
changeset
|
636 |
p:= PLongwordArray(@(p^[tmpsurf^.pitch div 4])); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
637 |
end; |
2243
b4764993f833
additional touch support and nemo's reduced land array size
koda
parents:
2240
diff
changeset
|
638 |
|
11512 | 639 |
if SDL_MustLock(tmpsurf) then |
640 |
SDL_UnlockSurface(tmpsurf); |
|
641 |
if not disableLandBack then |
|
642 |
begin |
|
643 |
// freed in freeModule() below |
|
12597 | 644 |
LandBackSurface:= LoadDataImage(ptCurrTheme, 'LandBackTex', ifIgnoreCaps or ifColorKey); |
11512 | 645 |
if (LandBackSurface <> nil) and GrayScale then |
646 |
Surface2GrayScale(LandBackSurface) |
|
647 |
end; |
|
648 |
end; |
|
6096
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
649 |
end; |
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
650 |
if (tmpsurf <> nil) then |
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
651 |
SDL_FreeSurface(tmpsurf); |
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
652 |
tmpsurf:= nil; |
1792 | 653 |
end; |
654 |
||
1754 | 655 |
procedure LoadMap; |
656 |
var tmpsurf: PSDL_Surface; |
|
3920
a54ca6185307
updated lua loading in the ifrontend and also fixed masked maps
koda
parents:
3912
diff
changeset
|
657 |
mapName: shortstring = ''; |
1754 | 658 |
begin |
659 |
WriteLnToConsole('Loading land from file...'); |
|
660 |
AddProgress; |
|
12597 | 661 |
tmpsurf:= LoadDataImage(ptMapCurrent, 'map', ifAlpha or ifColorKey or ifIgnoreCaps); |
3912
e11df2de6af2
have engine try for a second position when map loading fails (in this way it's possible to move Missions data to any path)
koda
parents:
3836
diff
changeset
|
662 |
if tmpsurf = nil then |
5770 | 663 |
begin |
8025 | 664 |
mapName:= ExtractFileName(cPathz[ptMapCurrent]); |
12597 | 665 |
tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/map', ifAlpha or ifCritical or ifColorKey or ifIgnoreCaps); |
11537 | 666 |
if not allOK then exit; |
5770 | 667 |
end; |
7477
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
668 |
// (bare) Sanity check. Considering possible LongInt comparisons as well as just how much system memoery it would take |
11537 | 669 |
if checkFails((tmpsurf^.w < $40000000) and (tmpsurf^.h < $40000000) and (QWord(tmpsurf^.w) * tmpsurf^.h < 6*1024*1024*1024), 'Map dimensions too big!', true) |
670 |
then exit; |
|
7477
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
671 |
|
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
672 |
ResizeLand(tmpsurf^.w, tmpsurf^.h); |
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
673 |
LoadMapConfig; |
1792 | 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 |
||
11537 | 681 |
if not checkFails(tmpsurf^.format^.BytesPerPixel = 4, 'Map should be 32bit', true) then |
682 |
BlitImageAndGenerateCollisionInfo( |
|
683 |
(LAND_WIDTH - tmpsurf^.w) div 2, |
|
684 |
LAND_HEIGHT - tmpsurf^.h, |
|
685 |
tmpsurf^.w, |
|
686 |
tmpsurf); |
|
1754 | 687 |
|
688 |
SDL_FreeSurface(tmpsurf); |
|
1792 | 689 |
|
11537 | 690 |
if allOK then LoadMask; |
1754 | 691 |
end; |
692 |
||
5717 | 693 |
procedure DrawBottomBorder; // broken out from other borders for doing a floor-only map, or possibly updating bottom during SD |
12091
ba1807589eaa
OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents:
11886
diff
changeset
|
694 |
var x, w, c, y: Longword; |
5717 | 695 |
begin |
5718
e74de0528ef4
Let's draw the bottom border thicker, so it is more visible
nemo
parents:
5717
diff
changeset
|
696 |
for w:= 0 to 23 do |
14287
6015b74eea55
overall, using LongInt for leftX/rightX results in fewer casts, since most comparisons are against ints.
nemo
parents:
13793
diff
changeset
|
697 |
for x:= LongWord(leftX) to LongWord(rightX) do |
5717 | 698 |
begin |
12091
ba1807589eaa
OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents:
11886
diff
changeset
|
699 |
y:= Longword(cWaterLine) - 1 - w; |
ba1807589eaa
OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents:
11886
diff
changeset
|
700 |
Land[y, x]:= lfIndestructible; |
ba1807589eaa
OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents:
11886
diff
changeset
|
701 |
if (x + y) mod 32 < 16 then |
5717 | 702 |
c:= AMask |
703 |
else |
|
704 |
c:= AMask or RMask or GMask; // FF00FFFF |
|
705 |
||
706 |
if (cReducedQuality and rqBlurryLand) = 0 then |
|
12091
ba1807589eaa
OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents:
11886
diff
changeset
|
707 |
LandPixels[y, x]:= c |
5717 | 708 |
else |
12091
ba1807589eaa
OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents:
11886
diff
changeset
|
709 |
LandPixels[y div 2, x div 2]:= c |
5718
e74de0528ef4
Let's draw the bottom border thicker, so it is more visible
nemo
parents:
5717
diff
changeset
|
710 |
end |
5717 | 711 |
end; |
712 |
||
1754 | 713 |
procedure GenMap; |
12091
ba1807589eaa
OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents:
11886
diff
changeset
|
714 |
var x, y, w, c, c2: Longword; |
8025 | 715 |
map, mask: shortstring; |
1754 | 716 |
begin |
3463 | 717 |
hasBorder:= false; |
8011 | 718 |
maskOnly:= false; |
2891
e1f902eb0cfe
Formerly "Draw Girders" by MrMfS - now "Disable Girders" to allow template prefs to still exist
nemo
parents:
2866
diff
changeset
|
719 |
|
3463 | 720 |
LoadThemeConfig; |
3697 | 721 |
|
11886
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
722 |
if cPathz[ptMapCurrent] <> '' then |
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
723 |
begin |
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
724 |
map:= cPathz[ptMapCurrent] + '/map.png'; |
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
725 |
mask:= cPathz[ptMapCurrent] + '/mask.png'; |
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
726 |
if (not(pfsExists(map)) and pfsExists(mask)) then |
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
727 |
begin |
11886
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
728 |
maskOnly:= true; |
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
729 |
LoadMask; |
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
730 |
GenLandSurface |
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
731 |
end |
11886
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
732 |
else LoadMap; |
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
733 |
end |
3463 | 734 |
else |
11886
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
735 |
begin |
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
736 |
WriteLnToConsole('Generating land...'); |
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
737 |
case cMapGen of |
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
738 |
mgRandom: GenTemplated(EdgeTemplates[SelectTemplate]); |
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
739 |
mgMaze : begin ResizeLand(4096,2048); GenMaze; end; |
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
740 |
mgPerlin: begin ResizeLand(4096,2048); GenPerlin; end; |
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
741 |
mgDrawn : GenDrawnMap; |
13277
5984e8c6cbeb
Add new game flag gfSwitchHog, enable hog switching at turn start
Wuzzy <Wuzzy2@mail.ru>
parents:
12763
diff
changeset
|
742 |
mgForts : begin GameFlags:= (GameFlags or gfDivideTeams); MakeFortsMap(); end; |
11886
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
743 |
else |
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
744 |
OutError('Unknown mapgen', true); |
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
745 |
end; |
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
746 |
if cMapGen <> mgForts then |
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
747 |
GenLandSurface |
34ede05e4d4f
Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
748 |
end; |
3463 | 749 |
|
750 |
AddProgress; |
|
1760 | 751 |
|
1768 | 752 |
// check for land near top |
1784 | 753 |
c:= 0; |
754 |
if (GameFlags and gfBorder) <> 0 then |
|
755 |
hasBorder:= true |
|
756 |
else |
|
14291 | 757 |
for y:= LongWord(topY) to LongWord(topY + 5) do |
14287
6015b74eea55
overall, using LongInt for leftX/rightX results in fewer casts, since most comparisons are against ints.
nemo
parents:
13793
diff
changeset
|
758 |
for x:= LongWord(leftX) to LongWord(rightX) do |
1784 | 759 |
if Land[y, x] <> 0 then |
760 |
begin |
|
761 |
inc(c); |
|
8370 | 762 |
if c > LongWord((LAND_WIDTH div 2)) then // avoid accidental triggering |
1784 | 763 |
begin |
764 |
hasBorder:= true; |
|
765 |
break; |
|
766 |
end; |
|
767 |
end; |
|
1768 | 768 |
|
1776 | 769 |
if hasBorder then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
770 |
begin |
10661 | 771 |
if WorldEdge = weNone then |
772 |
begin |
|
773 |
for y:= 0 to LAND_HEIGHT - 1 do |
|
774 |
for x:= 0 to LAND_WIDTH - 1 do |
|
14291 | 775 |
if (y < LongWord(topY)) or (x < LongWord(leftX)) or (x > LongWord(rightX)) then |
10661 | 776 |
Land[y, x]:= lfIndestructible; |
777 |
end |
|
778 |
else if topY > 0 then |
|
779 |
begin |
|
14291 | 780 |
for y:= 0 to LongWord(topY - 1) do |
10661 | 781 |
for x:= 0 to LAND_WIDTH - 1 do |
3519 | 782 |
Land[y, x]:= lfIndestructible; |
10661 | 783 |
end; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
784 |
// experiment hardcoding cave |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
785 |
// also try basing cave dimensions on map/template dimensions, if they exist |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
786 |
for w:= 0 to 5 do // width of 3 allowed hogs to be knocked through with grenade |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
787 |
begin |
9524 | 788 |
if (WorldEdge <> weBounce) and (WorldEdge <> weWrap) then |
14291 | 789 |
for y:= LongWord(topY) to LAND_HEIGHT - 1 do |
9524 | 790 |
begin |
791 |
Land[y, leftX + w]:= lfIndestructible; |
|
792 |
Land[y, rightX - w]:= lfIndestructible; |
|
12091
ba1807589eaa
OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents:
11886
diff
changeset
|
793 |
if (y + leftX + w) mod 32 < 16 then |
9524 | 794 |
c:= AMask |
795 |
else |
|
796 |
c:= AMask or RMask or GMask; // FF00FFFF |
|
12092
78e9fbd52ffc
simplify code of previous commit ( ba1807589eaa )
sheepluva
parents:
12091
diff
changeset
|
797 |
if (y + rightX - w) mod 32 < 16 then |
12091
ba1807589eaa
OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents:
11886
diff
changeset
|
798 |
c2:= AMask |
ba1807589eaa
OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents:
11886
diff
changeset
|
799 |
else |
ba1807589eaa
OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents:
11886
diff
changeset
|
800 |
c2:= AMask or RMask or GMask; // FF00FFFF |
3595
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3551
diff
changeset
|
801 |
|
9524 | 802 |
if (cReducedQuality and rqBlurryLand) = 0 then |
803 |
begin |
|
804 |
LandPixels[y, leftX + w]:= c; |
|
12092
78e9fbd52ffc
simplify code of previous commit ( ba1807589eaa )
sheepluva
parents:
12091
diff
changeset
|
805 |
LandPixels[y, rightX - w]:= c2; |
9524 | 806 |
end |
807 |
else |
|
808 |
begin |
|
809 |
LandPixels[y div 2, (leftX + w) div 2]:= c; |
|
12092
78e9fbd52ffc
simplify code of previous commit ( ba1807589eaa )
sheepluva
parents:
12091
diff
changeset
|
810 |
LandPixels[y div 2, (rightX - w) div 2]:= c2; |
9524 | 811 |
end; |
5717 | 812 |
end; |
1768 | 813 |
|
14287
6015b74eea55
overall, using LongInt for leftX/rightX results in fewer casts, since most comparisons are against ints.
nemo
parents:
13793
diff
changeset
|
814 |
for x:= LongWord(leftX) to LongWord(rightX) do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
815 |
begin |
5717 | 816 |
Land[topY + w, x]:= lfIndestructible; |
817 |
if (x + w) mod 32 < 16 then |
|
818 |
c:= AMask |
|
819 |
else |
|
820 |
c:= AMask or RMask or GMask; // FF00FFFF |
|
3595
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3551
diff
changeset
|
821 |
|
5717 | 822 |
if (cReducedQuality and rqBlurryLand) = 0 then |
823 |
LandPixels[topY + w, x]:= c |
|
824 |
else |
|
825 |
LandPixels[(topY + w) div 2, x div 2]:= c; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
826 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
827 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
828 |
end; |
1768 | 829 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
830 |
if (GameFlags and gfBottomBorder) <> 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
831 |
DrawBottomBorder; |
5717 | 832 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
833 |
if (GameFlags and gfDisableGirders) <> 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
834 |
hasGirders:= false; |
2891
e1f902eb0cfe
Formerly "Draw Girders" by MrMfS - now "Disable Girders" to allow template prefs to still exist
nemo
parents:
2866
diff
changeset
|
835 |
|
13277
5984e8c6cbeb
Add new game flag gfSwitchHog, enable hog switching at turn start
Wuzzy <Wuzzy2@mail.ru>
parents:
12763
diff
changeset
|
836 |
if (cMapGen <> mgForts) and (maskOnly or (cPathz[ptMapCurrent] = '')) then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
837 |
AddObjects |
10017 | 838 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
839 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
840 |
AddProgress(); |
1776 | 841 |
|
3058 | 842 |
FreeLandObjects; |
843 |
||
11544 | 844 |
if not allOK then exit; |
845 |
||
6982 | 846 |
if GrayScale then |
5441
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
847 |
begin |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
848 |
if (cReducedQuality and rqBlurryLand) = 0 then |
14287
6015b74eea55
overall, using LongInt for leftX/rightX results in fewer casts, since most comparisons are against ints.
nemo
parents:
13793
diff
changeset
|
849 |
for x:= LongWord(leftX) to LongWord(rightX) do |
14291 | 850 |
for y:= LongWord(topY) to LAND_HEIGHT-1 do |
5441
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
851 |
begin |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
852 |
w:= LandPixels[y,x]; |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
853 |
w:= round(((w shr RShift and $FF) * RGB_LUMINANCE_RED + |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
854 |
(w shr BShift and $FF) * RGB_LUMINANCE_GREEN + |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
855 |
(w shr GShift and $FF) * RGB_LUMINANCE_BLUE)); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
856 |
if w > 255 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
857 |
w:= 255; |
5441
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
858 |
w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y,x] and AMask); |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
859 |
LandPixels[y,x]:= w or (LandPixels[y, x] and AMask) |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
860 |
end |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
861 |
else |
14287
6015b74eea55
overall, using LongInt for leftX/rightX results in fewer casts, since most comparisons are against ints.
nemo
parents:
13793
diff
changeset
|
862 |
for x:= LongWord(leftX div 2) to LongWord(rightX div 2) do |
14291 | 863 |
for y:= LongWord(topY div 2) to LAND_HEIGHT-1 div 2 do |
5441
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
864 |
begin |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
865 |
w:= LandPixels[y div 2,x div 2]; |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
866 |
w:= ((w shr RShift and $FF) + (w shr BShift and $FF) + (w shr GShift and $FF)) div 3; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
867 |
w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y div 2,x div 2] and AMask); |
5441
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
868 |
LandPixels[y,x]:= w or (LandPixels[y div 2, x div 2] and AMask) |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
869 |
end |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
870 |
end; |
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
871 |
|
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
872 |
PrettifyLandAlpha(); |
10626
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10603
diff
changeset
|
873 |
|
10661 | 874 |
// adjust world edges for borderless maps |
875 |
if (WorldEdge <> weNone) and (not hasBorder) then |
|
876 |
InitWorldEdges(); |
|
10626
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10603
diff
changeset
|
877 |
|
13757
f1c66a34f2fe
Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
Wuzzy <Wuzzy2@mail.ru>
parents:
13506
diff
changeset
|
878 |
ScriptSetMapGlobals; |
37 | 879 |
end; |
880 |
||
7079 | 881 |
procedure GenPreview(out Preview: TPreview); |
7477
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
882 |
var rh, rw, ox, oy, x, y, xx, yy, t, bit, cbit, lh, lw: LongInt; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
883 |
begin |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
884 |
WriteLnToConsole('Generating preview...'); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
885 |
case cMapGen of |
10603
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10490
diff
changeset
|
886 |
mgRandom: GenTemplated(EdgeTemplates[SelectTemplate]); |
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10490
diff
changeset
|
887 |
mgMaze: begin ResizeLand(4096,2048); GenMaze; end; |
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10490
diff
changeset
|
888 |
mgPerlin: begin ResizeLand(4096,2048); GenPerlin; end; |
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10490
diff
changeset
|
889 |
mgDrawn: GenDrawnMap; |
11749
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
890 |
mgForts: MakeFortsPreview(); |
4562 | 891 |
else |
892 |
OutError('Unknown mapgen', true); |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
893 |
end; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
894 |
|
13757
f1c66a34f2fe
Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
Wuzzy <Wuzzy2@mail.ru>
parents:
13506
diff
changeset
|
895 |
ScriptSetMapGlobals; |
f1c66a34f2fe
Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
Wuzzy <Wuzzy2@mail.ru>
parents:
13506
diff
changeset
|
896 |
|
7477
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
897 |
// strict scaling needed here since preview assumes a rectangle |
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
898 |
rh:= max(LAND_HEIGHT,2048); |
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
899 |
rw:= max(LAND_WIDTH,4096); |
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
900 |
ox:= 0; |
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
901 |
if rw < rh*2 then |
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
902 |
begin |
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
903 |
rw:= rh*2; |
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
904 |
end; |
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
905 |
if rh < rw div 2 then rh:= rw * 2; |
10017 | 906 |
|
7477
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
907 |
ox:= (rw-LAND_WIDTH) div 2; |
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
908 |
oy:= rh-LAND_HEIGHT; |
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
909 |
|
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
910 |
lh:= rh div 128; |
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
911 |
lw:= rw div 32; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
912 |
for y:= 0 to 127 do |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
913 |
for x:= 0 to 31 do |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
914 |
begin |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
915 |
Preview[y, x]:= 0; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
916 |
for bit:= 0 to 7 do |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
917 |
begin |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
918 |
t:= 0; |
3617 | 919 |
cbit:= bit * 8; |
920 |
for yy:= y * lh to y * lh + 7 do |
|
921 |
for xx:= x * lw + cbit to x * lw + cbit + 7 do |
|
10017 | 922 |
if ((yy-oy) and LAND_HEIGHT_MASK = 0) and ((xx-ox) and LAND_WIDTH_MASK = 0) |
7477
26706bf32ecf
First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents:
7293
diff
changeset
|
923 |
and (Land[yy-oy, xx-ox] <> 0) then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
924 |
inc(t); |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
925 |
if t > 8 then |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
926 |
Preview[y, x]:= Preview[y, x] or ($80 shr bit); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
927 |
end; |
566 | 928 |
end; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
929 |
end; |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
930 |
|
4398
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4389
diff
changeset
|
931 |
|
10162 | 932 |
procedure GenPreviewAlpha(out Preview: TPreviewAlpha); |
933 |
var rh, rw, ox, oy, x, y, xx, yy, t, lh, lw: LongInt; |
|
934 |
begin |
|
935 |
WriteLnToConsole('Generating preview...'); |
|
936 |
case cMapGen of |
|
10603
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10490
diff
changeset
|
937 |
mgRandom: GenTemplated(EdgeTemplates[SelectTemplate]); |
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10490
diff
changeset
|
938 |
mgMaze: begin ResizeLand(4096,2048); GenMaze; end; |
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10490
diff
changeset
|
939 |
mgPerlin: begin ResizeLand(4096,2048); GenPerlin; end; |
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10490
diff
changeset
|
940 |
mgDrawn: GenDrawnMap; |
11749
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11739
diff
changeset
|
941 |
mgForts: MakeFortsPreview; |
10162 | 942 |
else |
943 |
OutError('Unknown mapgen', true); |
|
944 |
end; |
|
945 |
||
13757
f1c66a34f2fe
Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
Wuzzy <Wuzzy2@mail.ru>
parents:
13506
diff
changeset
|
946 |
ScriptSetMapGlobals; |
f1c66a34f2fe
Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
Wuzzy <Wuzzy2@mail.ru>
parents:
13506
diff
changeset
|
947 |
|
10162 | 948 |
// strict scaling needed here since preview assumes a rectangle |
949 |
rh:= max(LAND_HEIGHT, 2048); |
|
950 |
rw:= max(LAND_WIDTH, 4096); |
|
951 |
ox:= 0; |
|
952 |
if rw < rh*2 then |
|
953 |
begin |
|
954 |
rw:= rh*2; |
|
955 |
end; |
|
956 |
if rh < rw div 2 then rh:= rw * 2; |
|
957 |
||
958 |
ox:= (rw-LAND_WIDTH) div 2; |
|
959 |
oy:= rh-LAND_HEIGHT; |
|
960 |
||
961 |
lh:= rh div 128; |
|
962 |
lw:= rw div 256; |
|
963 |
for y:= 0 to 127 do |
|
964 |
for x:= 0 to 255 do |
|
965 |
begin |
|
966 |
t:= 0; |
|
967 |
||
10165 | 968 |
for yy:= y * lh - oy to y * lh + lh - 1 - oy do |
969 |
for xx:= x * lw - ox to x * lw + lw - 1 - ox do |
|
10162 | 970 |
if (yy and LAND_HEIGHT_MASK = 0) and (xx and LAND_WIDTH_MASK = 0) |
971 |
and (Land[yy, xx] <> 0) then |
|
972 |
inc(t); |
|
973 |
||
10165 | 974 |
Preview[y, x]:= t * 255 div (lh * lw); |
10162 | 975 |
end; |
976 |
end; |
|
977 |
||
4398
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4389
diff
changeset
|
978 |
procedure chLandCheck(var s: shortstring); |
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4389
diff
changeset
|
979 |
begin |
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4389
diff
changeset
|
980 |
AddFileLog('CheckLandDigest: ' + s + ' digest : ' + digest); |
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4389
diff
changeset
|
981 |
if digest = '' then |
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4389
diff
changeset
|
982 |
digest:= s |
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4389
diff
changeset
|
983 |
else |
13504
c41b16ac2e05
Clarify the wording of a few checkFails messages
Wuzzy <Wuzzy2@mail.ru>
parents:
13277
diff
changeset
|
984 |
checkFails(s = digest, 'Loaded map or other critical resource does not match across all players', true); |
4398
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4389
diff
changeset
|
985 |
end; |
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4389
diff
changeset
|
986 |
|
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4389
diff
changeset
|
987 |
procedure chSendLandDigest(var s: shortstring); |
12716
20dbb3a03e61
extend land digest to all surfaces that could possibly be loaded into Land[] - i.e. ones that impact sync
nemo
parents:
12597
diff
changeset
|
988 |
var i: LongInt; |
13793
381e37c6d5d9
Separate synced pixels from land digests - this is mostly to allow the official racer digests to remain unchanged.
nemo
parents:
13757
diff
changeset
|
989 |
landPixelDigest : LongInt; |
4398
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4389
diff
changeset
|
990 |
begin |
13793
381e37c6d5d9
Separate synced pixels from land digests - this is mostly to allow the official racer digests to remain unchanged.
nemo
parents:
13757
diff
changeset
|
991 |
landPixelDigest:= 1; |
4398
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4389
diff
changeset
|
992 |
for i:= 0 to LAND_HEIGHT-1 do |
13793
381e37c6d5d9
Separate synced pixels from land digests - this is mostly to allow the official racer digests to remain unchanged.
nemo
parents:
13757
diff
changeset
|
993 |
landPixelDigest:= Adler32Update(landPixelDigest, @Land[i,0], LAND_WIDTH*2); |
381e37c6d5d9
Separate synced pixels from land digests - this is mostly to allow the official racer digests to remain unchanged.
nemo
parents:
13757
diff
changeset
|
994 |
s:= 'M' + IntToStr(syncedPixelDigest)+'|'+IntToStr(landPixelDigest); |
4398
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4389
diff
changeset
|
995 |
|
13793
381e37c6d5d9
Separate synced pixels from land digests - this is mostly to allow the official racer digests to remain unchanged.
nemo
parents:
13757
diff
changeset
|
996 |
ScriptSetString('LandDigest',IntToStr(landPixelDigest)); |
10022 | 997 |
|
4398
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4389
diff
changeset
|
998 |
chLandCheck(s); |
11537 | 999 |
if allOK then SendIPCRaw(@s[0], Length(s) + 1) |
4398
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4389
diff
changeset
|
1000 |
end; |
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4389
diff
changeset
|
1001 |
|
3038 | 1002 |
procedure initModule; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2692
diff
changeset
|
1003 |
begin |
6898 | 1004 |
RegisterVariable('landcheck', @chLandCheck, false); |
1005 |
RegisterVariable('sendlanddigest', @chSendLandDigest, false); |
|
4398
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4389
diff
changeset
|
1006 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
1007 |
LandBackSurface:= nil; |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
1008 |
digest:= ''; |
11019
67ef02300508
always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents:
11006
diff
changeset
|
1009 |
maskOnly:= false; |
7549 | 1010 |
LAND_WIDTH:= 0; |
1011 |
LAND_HEIGHT:= 0; |
|
1012 |
(* |
|
3612
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3608
diff
changeset
|
1013 |
if (cReducedQuality and rqBlurryLand) = 0 then |
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3608
diff
changeset
|
1014 |
SetLength(LandPixels, LAND_HEIGHT, LAND_WIDTH) |
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3608
diff
changeset
|
1015 |
else |
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3608
diff
changeset
|
1016 |
SetLength(LandPixels, LAND_HEIGHT div 2, LAND_WIDTH div 2); |
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3608
diff
changeset
|
1017 |
|
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3608
diff
changeset
|
1018 |
SetLength(Land, LAND_HEIGHT, LAND_WIDTH); |
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3608
diff
changeset
|
1019 |
SetLength(LandDirty, (LAND_HEIGHT div 32), (LAND_WIDTH div 32)); |
7549 | 1020 |
*) |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2692
diff
changeset
|
1021 |
end; |
51 | 1022 |
|
3038 | 1023 |
procedure freeModule; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2692
diff
changeset
|
1024 |
begin |
7151 | 1025 |
SetLength(Land, 0, 0); |
1026 |
SetLength(LandPixels, 0, 0); |
|
1027 |
SetLength(LandDirty, 0, 0); |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2692
diff
changeset
|
1028 |
end; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2692
diff
changeset
|
1029 |
|
4 | 1030 |
end. |