author | koda |
Tue, 21 Jan 2014 22:38:13 +0100 | |
changeset 10015 | 4feced261c68 |
parent 9998 | 736015b847e3 |
parent 9950 | 2759212a27de |
child 10017 | de822cd3df3a |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
9998 | 3 |
* Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
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 |
|
9295
f8819c3dde54
Remove some GLunit dependencies noticed on graph. uUtils was using it for GLfloat - but, the stuff it was returning to was usually converting to "real" anyway. uLand was including it unnecessarily. Minor refactor
nemo
parents:
9243
diff
changeset
|
23 |
uses SDLh, uLandTemplates, uFloat, 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); |
4 | 30 |
|
31 |
implementation |
|
7063 | 32 |
uses uConsole, uStore, uRandom, uLandObjects, uIO, uLandTexture, SysUtils, |
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
|
33 |
uVariables, uUtils, uCommands, adler32, uDebug, uLandPainted, uTextures, |
8060 | 34 |
uLandGenMaze, uLandOutline, uPhysFSLayer; |
365 | 35 |
|
7028 | 36 |
var digest: shortstring; |
4 | 37 |
|
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
|
38 |
procedure ResizeLand(width, height: LongWord); |
8003 | 39 |
var potW, potH: LongInt; |
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
|
40 |
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
|
41 |
potW:= toPowerOf2(width); |
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
|
42 |
potH:= toPowerOf2(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
|
43 |
if (potW <> LAND_WIDTH) or (potH <> LAND_HEIGHT) 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
|
44 |
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
|
45 |
LAND_WIDTH:= potW; |
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 |
LAND_HEIGHT:= potH; |
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
|
47 |
LAND_WIDTH_MASK:= not(LAND_WIDTH-1); |
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 |
LAND_HEIGHT_MASK:= not(LAND_HEIGHT-1); |
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 |
cWaterLine:= 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
|
50 |
if (cReducedQuality and rqBlurryLand) = 0 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
|
51 |
SetLength(LandPixels, LAND_HEIGHT, LAND_WIDTH) |
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
|
52 |
else |
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
|
53 |
SetLength(LandPixels, LAND_HEIGHT div 2, 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
|
54 |
|
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
|
55 |
SetLength(Land, LAND_HEIGHT, LAND_WIDTH); |
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
|
56 |
SetLength(LandDirty, (LAND_HEIGHT div 32), (LAND_WIDTH div 32)); |
7974 | 57 |
// 0.5 is already approaching on unplayable |
58 |
if (width div 4096 >= 2) or (height div 2048 >= 2) then cMaxZoomLevel:= 0.5; |
|
59 |
cMinMaxZoomLevelDelta:= cMaxZoomLevel - cMinZoomLevel |
|
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
|
60 |
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
|
61 |
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
|
62 |
|
9387 | 63 |
|
64 |
procedure DrawBorderFromImage(Surface: PSDL_Surface); |
|
4 | 65 |
var tmpsurf: PSDL_Surface; |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
66 |
r, rr: TSDL_Rect; |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
67 |
x, yd, yu: LongInt; |
4 | 68 |
begin |
7640
e9e6b4d740f6
clean up LoadImage and UserPathz/AltPath/etc related redundancy by introducing 3 new functions in uStore.pas
sheepluva
parents:
7594
diff
changeset
|
69 |
tmpsurf:= LoadDataImage(ptCurrTheme, 'Border', ifCritical or ifIgnoreCaps or ifTransparent); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
70 |
for x:= 0 to LAND_WIDTH - 1 do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
71 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
72 |
yd:= LAND_HEIGHT - 1; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
73 |
repeat |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
74 |
while (yd > 0) and (Land[yd, x] = 0) do dec(yd); |
2376 | 75 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
76 |
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
|
77 |
yd:= 0; |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
78 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
79 |
while (yd < LAND_HEIGHT) and (Land[yd, x] <> 0) do |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
80 |
inc(yd); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
81 |
dec(yd); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
82 |
yu:= yd; |
2376 | 83 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
84 |
while (yu > 0 ) and (Land[yu, x] <> 0) do dec(yu); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
85 |
while (yu < yd ) and (Land[yu, x] = 0) do inc(yu); |
2376 | 86 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
87 |
if (yd < LAND_HEIGHT - 1) and ((yd - yu) >= 16) then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
88 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
89 |
rr.x:= x; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
90 |
rr.y:= yd - 15; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
91 |
r.x:= x mod tmpsurf^.w; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
92 |
r.y:= 16; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
93 |
r.w:= 1; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
94 |
r.h:= 16; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
95 |
SDL_UpperBlit(tmpsurf, @r, Surface, @rr); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
96 |
end; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
97 |
if (yu > 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
|
98 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
99 |
rr.x:= x; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
100 |
rr.y:= yu; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
101 |
r.x:= x mod tmpsurf^.w; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
102 |
r.y:= 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
103 |
r.w:= 1; |
4374 | 104 |
r.h:= Min(16, yd - yu + 1); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
105 |
SDL_UpperBlit(tmpsurf, @r, Surface, @rr); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
106 |
end; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
107 |
yd:= yu - 1; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
108 |
until yd < 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
109 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
110 |
SDL_FreeSurface(tmpsurf); |
4 | 111 |
end; |
112 |
||
9387 | 113 |
|
114 |
procedure DrawShoppaBorder; |
|
115 |
var x, y, s, i: Longword; |
|
116 |
c1, c2, c: Longword; |
|
117 |
begin |
|
118 |
c1:= AMask; |
|
119 |
c2:= AMask or RMask or GMask; |
|
120 |
||
121 |
// vertical |
|
122 |
s:= LAND_HEIGHT; |
|
123 |
||
124 |
for x:= 0 to LAND_WIDTH - 1 do |
|
125 |
for y:= 0 to LAND_HEIGHT - 1 do |
|
9864 | 126 |
if Land[y, x] = 0 then |
9387 | 127 |
if s < y then |
128 |
begin |
|
129 |
for i:= max(s, y - 8) to y - 1 do |
|
130 |
begin |
|
131 |
if ((x + i) and 16) = 0 then c:= c1 else c:= c2; |
|
132 |
||
133 |
if (cReducedQuality and rqBlurryLand) = 0 then |
|
134 |
LandPixels[i, x]:= c |
|
135 |
else |
|
136 |
LandPixels[i div 2, x div 2]:= c |
|
137 |
end; |
|
138 |
s:= LAND_HEIGHT |
|
139 |
end |
|
140 |
else |
|
141 |
else |
|
142 |
begin |
|
143 |
if s > y then s:= y; |
|
144 |
if s + 8 > y then |
|
145 |
begin |
|
146 |
if ((x + y) and 16) = 0 then c:= c1 else c:= c2; |
|
147 |
||
148 |
if (cReducedQuality and rqBlurryLand) = 0 then |
|
149 |
LandPixels[y, x]:= c |
|
150 |
else |
|
151 |
LandPixels[y div 2, x div 2]:= c |
|
152 |
end; |
|
153 |
end; |
|
154 |
||
155 |
// horizontal |
|
156 |
s:= LAND_WIDTH; |
|
157 |
||
158 |
for y:= 0 to LAND_HEIGHT - 1 do |
|
159 |
for x:= 0 to LAND_WIDTH - 1 do |
|
9864 | 160 |
if Land[y, x] = 0 then |
9387 | 161 |
if s < x then |
162 |
begin |
|
163 |
for i:= max(s, x - 8) to x - 1 do |
|
164 |
begin |
|
165 |
if ((y + i) and 16) = 0 then c:= c1 else c:= c2; |
|
166 |
||
167 |
if (cReducedQuality and rqBlurryLand) = 0 then |
|
168 |
LandPixels[y, i]:= c |
|
169 |
else |
|
170 |
LandPixels[y div 2, i div 2]:= c |
|
171 |
end; |
|
172 |
s:= LAND_WIDTH |
|
173 |
end |
|
174 |
else |
|
175 |
else |
|
176 |
begin |
|
177 |
if s > x then s:= x; |
|
178 |
if s + 8 > x then |
|
179 |
begin |
|
180 |
if ((x + y) and 16) = 0 then c:= c1 else c:= c2; |
|
181 |
||
182 |
if (cReducedQuality and rqBlurryLand) = 0 then |
|
183 |
LandPixels[y, x]:= c |
|
184 |
else |
|
185 |
LandPixels[y div 2, x div 2]:= c |
|
186 |
end; |
|
187 |
end |
|
188 |
end; |
|
189 |
||
190 |
procedure ColorizeLand(Surface: PSDL_Surface); |
|
191 |
var tmpsurf: PSDL_Surface; |
|
192 |
r: TSDL_Rect; |
|
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
|
193 |
y: LongWord; // 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 | 194 |
begin |
195 |
tmpsurf:= LoadDataImage(ptCurrTheme, 'LandTex', ifCritical or ifIgnoreCaps); |
|
196 |
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
|
197 |
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
|
198 |
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
|
199 |
begin |
9387 | 200 |
r.x:= 0; |
201 |
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
|
202 |
begin |
9387 | 203 |
SDL_UpperBlit(tmpsurf, nil, Surface, @r); |
204 |
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
|
205 |
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
|
206 |
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
|
207 |
r.y:= y |
9387 | 208 |
end; |
209 |
SDL_FreeSurface(tmpsurf); |
|
210 |
||
211 |
// freed in freeModule() below |
|
212 |
LandBackSurface:= LoadDataImage(ptCurrTheme, 'LandBackTex', ifIgnoreCaps or ifTransparent); |
|
213 |
if (LandBackSurface <> nil) and GrayScale then Surface2GrayScale(LandBackSurface); |
|
214 |
end; |
|
215 |
||
7556
4617e8ec0507
engine: Fixed sigsegv on android caused by modifying Template.FillPoints constants
Medo <smaxein@googlemail.com>
parents:
7483
diff
changeset
|
216 |
procedure SetPoints(var Template: TEdgeTemplate; var pa: TPixAr; fps: PPointArray); |
371 | 217 |
var i: LongInt; |
22 | 218 |
begin |
23 | 219 |
with Template do |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
220 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
221 |
pa.Count:= BasePointsCount; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
222 |
for i:= 0 to pred(pa.Count) do |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
223 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
224 |
pa.ar[i].x:= BasePoints^[i].x + LongInt(GetRandom(BasePoints^[i].w)); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
225 |
if pa.ar[i].x <> NTPX then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
226 |
pa.ar[i].x:= pa.ar[i].x + ((LAND_WIDTH - Template.TemplateWidth) div 2); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
227 |
pa.ar[i].y:= BasePoints^[i].y + LongInt(GetRandom(BasePoints^[i].h)) + LAND_HEIGHT - LongInt(Template.TemplateHeight) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
228 |
end; |
1183
540cea859395
Step 4: repair girder rendering (girder is 32bit now)
unc0rr
parents:
1182
diff
changeset
|
229 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
230 |
if canMirror then |
360 | 231 |
if getrandom(2) = 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
|
232 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
233 |
for i:= 0 to pred(BasePointsCount) do |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
234 |
if pa.ar[i].x <> NTPX then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
235 |
pa.ar[i].x:= LAND_WIDTH - 1 - pa.ar[i].x; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
236 |
for i:= 0 to pred(FillPointsCount) do |
7556
4617e8ec0507
engine: Fixed sigsegv on android caused by modifying Template.FillPoints constants
Medo <smaxein@googlemail.com>
parents:
7483
diff
changeset
|
237 |
fps^[i].x:= LAND_WIDTH - 1 - fps^[i].x; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
238 |
end; |
22 | 239 |
|
2338
8f6508c97f3f
An experiment with increasing number of caves by selecting a few potential non-cave maps and adding to the cave map array. Ones selected here might not actually be that playable as caves.
nemo
parents:
2308
diff
changeset
|
240 |
(* Experiment in making this option more useful |
2376 | 241 |
if ((not isNegative) and (cTemplateFilter = 4)) or |
2338
8f6508c97f3f
An experiment with increasing number of caves by selecting a few potential non-cave maps and adding to the cave map array. Ones selected here might not actually be that playable as caves.
nemo
parents:
2308
diff
changeset
|
242 |
(canFlip and (getrandom(2) = 0)) then |
8f6508c97f3f
An experiment with increasing number of caves by selecting a few potential non-cave maps and adding to the cave map array. Ones selected here might not actually be that playable as caves.
nemo
parents:
2308
diff
changeset
|
243 |
begin |
8f6508c97f3f
An experiment with increasing number of caves by selecting a few potential non-cave maps and adding to the cave map array. Ones selected here might not actually be that playable as caves.
nemo
parents:
2308
diff
changeset
|
244 |
for i:= 0 to pred(BasePointsCount) do |
8f6508c97f3f
An experiment with increasing number of caves by selecting a few potential non-cave maps and adding to the cave map array. Ones selected here might not actually be that playable as caves.
nemo
parents:
2308
diff
changeset
|
245 |
begin |
8f6508c97f3f
An experiment with increasing number of caves by selecting a few potential non-cave maps and adding to the cave map array. Ones selected here might not actually be that playable as caves.
nemo
parents:
2308
diff
changeset
|
246 |
pa.ar[i].y:= LAND_HEIGHT - 1 - pa.ar[i].y + (LAND_HEIGHT - TemplateHeight) * 2; |
8f6508c97f3f
An experiment with increasing number of caves by selecting a few potential non-cave maps and adding to the cave map array. Ones selected here might not actually be that playable as caves.
nemo
parents:
2308
diff
changeset
|
247 |
if pa.ar[i].y > LAND_HEIGHT - 1 then |
8f6508c97f3f
An experiment with increasing number of caves by selecting a few potential non-cave maps and adding to the cave map array. Ones selected here might not actually be that playable as caves.
nemo
parents:
2308
diff
changeset
|
248 |
pa.ar[i].y:= LAND_HEIGHT - 1; |
8f6508c97f3f
An experiment with increasing number of caves by selecting a few potential non-cave maps and adding to the cave map array. Ones selected here might not actually be that playable as caves.
nemo
parents:
2308
diff
changeset
|
249 |
end; |
8f6508c97f3f
An experiment with increasing number of caves by selecting a few potential non-cave maps and adding to the cave map array. Ones selected here might not actually be that playable as caves.
nemo
parents:
2308
diff
changeset
|
250 |
for i:= 0 to pred(FillPointsCount) do |
8f6508c97f3f
An experiment with increasing number of caves by selecting a few potential non-cave maps and adding to the cave map array. Ones selected here might not actually be that playable as caves.
nemo
parents:
2308
diff
changeset
|
251 |
begin |
8f6508c97f3f
An experiment with increasing number of caves by selecting a few potential non-cave maps and adding to the cave map array. Ones selected here might not actually be that playable as caves.
nemo
parents:
2308
diff
changeset
|
252 |
FillPoints^[i].y:= LAND_HEIGHT - 1 - FillPoints^[i].y + (LAND_HEIGHT - TemplateHeight) * 2; |
8f6508c97f3f
An experiment with increasing number of caves by selecting a few potential non-cave maps and adding to the cave map array. Ones selected here might not actually be that playable as caves.
nemo
parents:
2308
diff
changeset
|
253 |
if FillPoints^[i].y > LAND_HEIGHT - 1 then |
8f6508c97f3f
An experiment with increasing number of caves by selecting a few potential non-cave maps and adding to the cave map array. Ones selected here might not actually be that playable as caves.
nemo
parents:
2308
diff
changeset
|
254 |
FillPoints^[i].y:= LAND_HEIGHT - 1; |
8f6508c97f3f
An experiment with increasing number of caves by selecting a few potential non-cave maps and adding to the cave map array. Ones selected here might not actually be that playable as caves.
nemo
parents:
2308
diff
changeset
|
255 |
end; |
8f6508c97f3f
An experiment with increasing number of caves by selecting a few potential non-cave maps and adding to the cave map array. Ones selected here might not actually be that playable as caves.
nemo
parents:
2308
diff
changeset
|
256 |
end; |
2376 | 257 |
end |
2338
8f6508c97f3f
An experiment with increasing number of caves by selecting a few potential non-cave maps and adding to the cave map array. Ones selected here might not actually be that playable as caves.
nemo
parents:
2308
diff
changeset
|
258 |
*) |
8f6508c97f3f
An experiment with increasing number of caves by selecting a few potential non-cave maps and adding to the cave map array. Ones selected here might not actually be that playable as caves.
nemo
parents:
2308
diff
changeset
|
259 |
// template recycling. Pull these off the floor a bit |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
260 |
if (not isNegative) and (cTemplateFilter = 4) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
261 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
262 |
for i:= 0 to pred(BasePointsCount) do |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
263 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
264 |
dec(pa.ar[i].y, 100); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
265 |
if pa.ar[i].y < 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
266 |
pa.ar[i].y:= 0; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
267 |
end; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
268 |
for i:= 0 to pred(FillPointsCount) do |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
269 |
begin |
7556
4617e8ec0507
engine: Fixed sigsegv on android caused by modifying Template.FillPoints constants
Medo <smaxein@googlemail.com>
parents:
7483
diff
changeset
|
270 |
dec(fps^[i].y, 100); |
4617e8ec0507
engine: Fixed sigsegv on android caused by modifying Template.FillPoints constants
Medo <smaxein@googlemail.com>
parents:
7483
diff
changeset
|
271 |
if fps^[i].y < 0 then |
4617e8ec0507
engine: Fixed sigsegv on android caused by modifying Template.FillPoints constants
Medo <smaxein@googlemail.com>
parents:
7483
diff
changeset
|
272 |
fps^[i].y:= 0; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
273 |
end; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
274 |
end; |
2338
8f6508c97f3f
An experiment with increasing number of caves by selecting a few potential non-cave maps and adding to the cave map array. Ones selected here might not actually be that playable as caves.
nemo
parents:
2308
diff
changeset
|
275 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
276 |
if (canFlip and (getrandom(2) = 0)) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
277 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
278 |
for i:= 0 to pred(BasePointsCount) do |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
279 |
pa.ar[i].y:= LAND_HEIGHT - 1 - pa.ar[i].y; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
280 |
for i:= 0 to pred(FillPointsCount) do |
7556
4617e8ec0507
engine: Fixed sigsegv on android caused by modifying Template.FillPoints constants
Medo <smaxein@googlemail.com>
parents:
7483
diff
changeset
|
281 |
fps^[i].y:= LAND_HEIGHT - 1 - fps^[i].y; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
282 |
end; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
283 |
end |
4 | 284 |
end; |
67 | 285 |
|
364 | 286 |
|
23 | 287 |
procedure GenBlank(var Template: TEdgeTemplate); |
4 | 288 |
var pa: TPixAr; |
23 | 289 |
i: Longword; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
290 |
y, x: Longword; |
7563
09a44c8fbfba
engine: Fixed indentation regression
Medo <smaxein@googlemail.com>
parents:
7561
diff
changeset
|
291 |
fps: TPointArray; |
4 | 292 |
begin |
7563
09a44c8fbfba
engine: Fixed indentation regression
Medo <smaxein@googlemail.com>
parents:
7561
diff
changeset
|
293 |
fps:=Template.FillPoints^; |
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
|
294 |
ResizeLand(Template.TemplateWidth, Template.TemplateHeight); |
1773 | 295 |
for y:= 0 to LAND_HEIGHT - 1 do |
296 |
for x:= 0 to LAND_WIDTH - 1 do |
|
4458 | 297 |
Land[y, x]:= lfBasic; |
298 |
{$HINTS OFF} |
|
7556
4617e8ec0507
engine: Fixed sigsegv on android caused by modifying Template.FillPoints constants
Medo <smaxein@googlemail.com>
parents:
7483
diff
changeset
|
299 |
SetPoints(Template, pa, @fps); |
4458 | 300 |
{$HINTS ON} |
301 |
for i:= 1 to Template.BezierizeCount do |
|
302 |
begin |
|
303 |
BezierizeEdge(pa, _0_5); |
|
304 |
RandomizePoints(pa); |
|
305 |
RandomizePoints(pa) |
|
306 |
end; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
307 |
for i:= 1 to Template.RandPassesCount do |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
308 |
RandomizePoints(pa); |
4458 | 309 |
BezierizeEdge(pa, _0_1); |
310 |
||
311 |
||
312 |
DrawEdge(pa, 0); |
|
313 |
||
314 |
with Template do |
|
315 |
for i:= 0 to pred(FillPointsCount) do |
|
7556
4617e8ec0507
engine: Fixed sigsegv on android caused by modifying Template.FillPoints constants
Medo <smaxein@googlemail.com>
parents:
7483
diff
changeset
|
316 |
with fps[i] do |
4458 | 317 |
FillLand(x, y); |
318 |
||
319 |
DrawEdge(pa, lfBasic); |
|
320 |
||
321 |
MaxHedgehogs:= Template.MaxHedgehogs; |
|
322 |
hasGirders:= Template.hasGirders; |
|
323 |
playHeight:= Template.TemplateHeight; |
|
324 |
playWidth:= Template.TemplateWidth; |
|
325 |
leftX:= ((LAND_WIDTH - playWidth) div 2); |
|
326 |
rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; |
|
327 |
topY:= LAND_HEIGHT - playHeight; |
|
328 |
||
329 |
// HACK: force to only cavern even if a cavern map is invertable if cTemplateFilter = 4 ? |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
330 |
if (cTemplateFilter = 4) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
331 |
or (Template.canInvert and (getrandom(2) = 0)) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
332 |
or (not Template.canInvert and Template.isNegative) then |
4458 | 333 |
begin |
334 |
hasBorder:= true; |
|
335 |
for y:= 0 to LAND_HEIGHT - 1 do |
|
336 |
for x:= 0 to LAND_WIDTH - 1 do |
|
337 |
if (y < topY) or (x < leftX) or (x > rightX) then |
|
338 |
Land[y, x]:= 0 |
|
339 |
else |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
340 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
341 |
if Land[y, x] = 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
342 |
Land[y, x]:= lfBasic |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
343 |
else if Land[y, x] = lfBasic then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
344 |
Land[y, x]:= 0; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
345 |
end; |
4458 | 346 |
end; |
23 | 347 |
end; |
348 |
||
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
349 |
procedure GenDrawnMap; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
350 |
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
|
351 |
ResizeLand(4096, 2048); |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
352 |
uLandPainted.Draw; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
353 |
|
4559 | 354 |
MaxHedgehogs:= 48; |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
355 |
hasGirders:= true; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
356 |
playHeight:= 2048; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
357 |
playWidth:= 4096; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
358 |
leftX:= ((LAND_WIDTH - playWidth) div 2); |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
359 |
rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
360 |
topY:= LAND_HEIGHT - playHeight; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
361 |
end; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
362 |
|
371 | 363 |
function SelectTemplate: LongInt; |
9243
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
364 |
var l: LongInt; |
161 | 365 |
begin |
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
|
366 |
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
|
367 |
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
|
368 |
else |
9243
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
369 |
begin |
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
370 |
if cTemplateFilter = 0 then |
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
371 |
begin |
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
372 |
l:= getRandom(GroupedTemplatesCount); |
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
373 |
repeat |
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
374 |
inc(cTemplateFilter); |
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
375 |
dec(l, TemplateCounts[cTemplateFilter]); |
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
376 |
until l < 0; |
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
377 |
end else getRandom(1); |
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
378 |
|
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
|
379 |
case cTemplateFilter of |
9243
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
380 |
0: OutError('Ask unC0Rr about what you did wrong', true); |
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
381 |
1: SelectTemplate:= SmallTemplates[getrandom(TemplateCounts[cTemplateFilter])]; |
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
382 |
2: SelectTemplate:= MediumTemplates[getrandom(TemplateCounts[cTemplateFilter])]; |
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
383 |
3: SelectTemplate:= LargeTemplates[getrandom(TemplateCounts[cTemplateFilter])]; |
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
384 |
4: SelectTemplate:= CavernTemplates[getrandom(TemplateCounts[cTemplateFilter])]; |
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
385 |
5: SelectTemplate:= WackyTemplates[getrandom(TemplateCounts[cTemplateFilter])]; |
7567 | 386 |
// For lua only! |
7575
f415b3e0f3b9
Burn a random number in the override. Make sure cirbuf is reset.
nemo
parents:
7571
diff
changeset
|
387 |
6: begin |
7594 | 388 |
SelectTemplate:= min(LuaTemplateNumber,High(EdgeTemplates)); |
7575
f415b3e0f3b9
Burn a random number in the override. Make sure cirbuf is reset.
nemo
parents:
7571
diff
changeset
|
389 |
GetRandom(2) // burn 1 |
f415b3e0f3b9
Burn a random number in the override. Make sure cirbuf is reset.
nemo
parents:
7571
diff
changeset
|
390 |
end; |
9243
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
391 |
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
|
392 |
end; |
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
|
393 |
|
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
|
394 |
WriteLnToConsole('Selected template #'+inttostr(SelectTemplate)+' using filter #'+inttostr(cTemplateFilter)); |
161 | 395 |
end; |
396 |
||
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
397 |
procedure LandSurface2LandPixels(Surface: PSDL_Surface); |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
398 |
var x, y: LongInt; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
399 |
p: PLongwordArray; |
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1085
diff
changeset
|
400 |
begin |
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
401 |
TryDo(Surface <> nil, 'Assert (LandSurface <> nil) failed', true); |
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
402 |
|
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
403 |
if SDL_MustLock(Surface) then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
404 |
SDLTry(SDL_LockSurface(Surface) >= 0, true); |
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1085
diff
changeset
|
405 |
|
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
406 |
p:= Surface^.pixels; |
1760 | 407 |
for y:= 0 to LAND_HEIGHT - 1 do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
408 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
409 |
for x:= 0 to LAND_WIDTH - 1 do |
3598 | 410 |
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
|
411 |
if (cReducedQuality and rqBlurryLand) = 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
|
412 |
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
|
413 |
else |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
414 |
LandPixels[y div 2, x div 2]:= p^[x] or AMask; |
2376 | 415 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
416 |
p:= @(p^[Surface^.pitch div 4]); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
417 |
end; |
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1085
diff
changeset
|
418 |
|
1182
e2e13aa055c1
Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents:
1181
diff
changeset
|
419 |
if SDL_MustLock(Surface) then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
420 |
SDL_UnlockSurface(Surface); |
1754 | 421 |
end; |
422 |
||
3133 | 423 |
|
1754 | 424 |
procedure GenLandSurface; |
425 |
var tmpsurf: PSDL_Surface; |
|
5225 | 426 |
x,y: Longword; |
1754 | 427 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
428 |
AddProgress(); |
1754 | 429 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
430 |
tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, LAND_WIDTH, LAND_HEIGHT, 32, RMask, GMask, BMask, 0); |
1754 | 431 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
432 |
TryDo(tmpsurf <> nil, 'Error creating pre-land surface', true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
433 |
ColorizeLand(tmpsurf); |
9387 | 434 |
if gameFlags and gfShoppaBorder = 0 then DrawBorderFromImage(tmpsurf); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
435 |
AddOnLandObjects(tmpsurf); |
1754 | 436 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
437 |
LandSurface2LandPixels(tmpsurf); |
5227 | 438 |
SDL_FreeSurface(tmpsurf); |
9387 | 439 |
|
440 |
if gameFlags and gfShoppaBorder <> 0 then DrawShoppaBorder; |
|
441 |
||
5274 | 442 |
for x:= leftX+2 to rightX-2 do |
443 |
for y:= topY+2 to LAND_HEIGHT-3 do |
|
444 |
if (Land[y, x] = 0) and |
|
445 |
(((Land[y, x-1] = lfBasic) and ((Land[y+1,x] = lfBasic)) or (Land[y-1,x] = lfBasic)) or |
|
446 |
((Land[y, x+1] = lfBasic) and ((Land[y-1,x] = lfBasic) or (Land[y+1,x] = lfBasic)))) then |
|
447 |
begin |
|
448 |
if (cReducedQuality and rqBlurryLand) = 0 then |
|
449 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
450 |
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
|
451 |
LandPixels[y, x]:= LandPixels[y, x-1] |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
452 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
453 |
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
|
454 |
LandPixels[y, x]:= LandPixels[y, x+1] |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
455 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
456 |
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
|
457 |
LandPixels[y, x]:= LandPixels[y-1, x] |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
458 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
459 |
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
|
460 |
LandPixels[y, x]:= LandPixels[y+1, x]; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
461 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
462 |
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
|
463 |
LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (128 shl AShift) |
5274 | 464 |
end; |
465 |
Land[y,x]:= lfObject |
|
466 |
end |
|
467 |
else if (Land[y, x] = 0) and |
|
468 |
(((Land[y, x-1] = lfBasic) and (Land[y+1,x-1] = lfBasic) and (Land[y+2,x] = lfBasic)) or |
|
469 |
((Land[y, x-1] = lfBasic) and (Land[y-1,x-1] = lfBasic) and (Land[y-2,x] = lfBasic)) or |
|
470 |
((Land[y, x+1] = lfBasic) and (Land[y+1,x+1] = lfBasic) and (Land[y+2,x] = lfBasic)) or |
|
471 |
((Land[y, x+1] = lfBasic) and (Land[y-1,x+1] = lfBasic) and (Land[y-2,x] = lfBasic)) or |
|
472 |
((Land[y+1, x] = lfBasic) and (Land[y+1,x+1] = lfBasic) and (Land[y,x+2] = lfBasic)) or |
|
473 |
((Land[y-1, x] = lfBasic) and (Land[y-1,x+1] = lfBasic) and (Land[y,x+2] = lfBasic)) or |
|
474 |
((Land[y+1, x] = lfBasic) and (Land[y+1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic)) or |
|
475 |
((Land[y-1, x] = lfBasic) and (Land[y-1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic))) then |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
476 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
477 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
478 |
|
5274 | 479 |
if (cReducedQuality and rqBlurryLand) = 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
|
480 |
|
5274 | 481 |
begin |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
482 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
483 |
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
|
484 |
LandPixels[y, x]:= LandPixels[y, x-1] |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
485 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
486 |
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
|
487 |
LandPixels[y, x]:= LandPixels[y, x+1] |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
488 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
489 |
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
|
490 |
LandPixels[y, x]:= LandPixels[y+1, x] |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
491 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
492 |
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
|
493 |
LandPixels[y, x]:= LandPixels[y-1, x]; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
494 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
495 |
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
|
496 |
LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (64 shl AShift) |
5274 | 497 |
end; |
498 |
Land[y,x]:= lfObject |
|
499 |
end; |
|
5441
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
500 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
501 |
AddProgress(); |
1754 | 502 |
end; |
503 |
||
504 |
procedure MakeFortsMap; |
|
505 |
var tmpsurf: PSDL_Surface; |
|
506 |
begin |
|
7922 | 507 |
ResizeLand(4096,2048); |
2866 | 508 |
MaxHedgehogs:= 32; |
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
|
509 |
// 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 | 510 |
playHeight:= 1200; |
2096 | 511 |
playWidth:= 2560; |
1776 | 512 |
leftX:= (LAND_WIDTH - playWidth) div 2; |
513 |
rightX:= ((playWidth + (LAND_WIDTH - playWidth) div 2) - 1); |
|
514 |
topY:= LAND_HEIGHT - playHeight; |
|
515 |
||
1754 | 516 |
WriteLnToConsole('Generating forts land...'); |
517 |
||
7640
e9e6b4d740f6
clean up LoadImage and UserPathz/AltPath/etc related redundancy by introducing 3 new functions in uStore.pas
sheepluva
parents:
7594
diff
changeset
|
518 |
tmpsurf:= LoadDataImage(ptForts, ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); |
1784 | 519 |
BlitImageAndGenerateCollisionInfo(leftX+150, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf); |
1754 | 520 |
SDL_FreeSurface(tmpsurf); |
521 |
||
7640
e9e6b4d740f6
clean up LoadImage and UserPathz/AltPath/etc related redundancy by introducing 3 new functions in uStore.pas
sheepluva
parents:
7594
diff
changeset
|
522 |
tmpsurf:= LoadDataImage(ptForts, ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); |
1784 | 523 |
BlitImageAndGenerateCollisionInfo(rightX - 150 - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf); |
1754 | 524 |
SDL_FreeSurface(tmpsurf); |
525 |
end; |
|
526 |
||
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
527 |
procedure LoadMapConfig; |
8060 | 528 |
var f: PFSFile; |
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
529 |
s: shortstring; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
530 |
begin |
8025 | 531 |
s:= cPathz[ptMapCurrent] + '/map.cfg'; |
532 |
||
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
533 |
WriteLnToConsole('Fetching map HH limit'); |
8060 | 534 |
|
535 |
f:= pfsOpenRead(s); |
|
536 |
if f <> nil then |
|
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
537 |
begin |
8060 | 538 |
pfsReadLn(f, s); |
539 |
if not pfsEof(f) then |
|
540 |
begin |
|
541 |
pfsReadLn(f, s); |
|
542 |
val(s, MaxHedgehogs) |
|
543 |
end; |
|
544 |
||
545 |
pfsClose(f) |
|
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
546 |
end; |
8060 | 547 |
|
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
548 |
if (MaxHedgehogs = 0) then |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
549 |
MaxHedgehogs:= 18; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
550 |
end; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
551 |
|
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
|
552 |
// 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
|
553 |
procedure LoadMask; |
1792 | 554 |
var tmpsurf: PSDL_Surface; |
555 |
p: PLongwordArray; |
|
556 |
x, y, cpX, cpY: Longword; |
|
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
557 |
mapName: shortstring; |
1792 | 558 |
begin |
7640
e9e6b4d740f6
clean up LoadImage and UserPathz/AltPath/etc related redundancy by introducing 3 new functions in uStore.pas
sheepluva
parents:
7594
diff
changeset
|
559 |
tmpsurf:= LoadDataImage(ptMapCurrent, 'mask', ifAlpha or ifTransparent or ifIgnoreCaps); |
5770 | 560 |
if tmpsurf = nil then |
561 |
begin |
|
8025 | 562 |
mapName:= ExtractFileName(cPathz[ptMapCurrent]); |
7640
e9e6b4d740f6
clean up LoadImage and UserPathz/AltPath/etc related redundancy by introducing 3 new functions in uStore.pas
sheepluva
parents:
7594
diff
changeset
|
563 |
tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps); |
5770 | 564 |
end; |
3920
a54ca6185307
updated lua loading in the ifrontend and also fixed masked maps
koda
parents:
3912
diff
changeset
|
565 |
|
6096
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
566 |
|
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
567 |
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
|
568 |
begin |
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
569 |
if LAND_WIDTH = 0 then |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
570 |
begin |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
571 |
LoadMapConfig; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
572 |
ResizeLand(tmpsurf^.w, tmpsurf^.h); |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
573 |
playHeight:= tmpsurf^.h; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
574 |
playWidth:= tmpsurf^.w; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
575 |
leftX:= (LAND_WIDTH - playWidth) div 2; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
576 |
rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
577 |
topY:= LAND_HEIGHT - playHeight; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
578 |
end; |
6096
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
579 |
disableLandBack:= true; |
2376 | 580 |
|
6096
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
581 |
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
|
582 |
cpY:= LAND_HEIGHT - tmpsurf^.h; |
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
583 |
if SDL_MustLock(tmpsurf) then |
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
584 |
SDLTry(SDL_LockSurface(tmpsurf) >= 0, true); |
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
585 |
|
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
586 |
p:= tmpsurf^.pixels; |
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
587 |
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
|
588 |
begin |
6096
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
589 |
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
|
590 |
SetLand(Land[cpY + y, cpX + x], p^[x]); |
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
|
591 |
p:= @(p^[tmpsurf^.pitch div 4]); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
592 |
end; |
2243
b4764993f833
additional touch support and nemo's reduced land array size
koda
parents:
2240
diff
changeset
|
593 |
|
6096
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
594 |
if SDL_MustLock(tmpsurf) then |
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
595 |
SDL_UnlockSurface(tmpsurf); |
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
596 |
if not disableLandBack then |
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
597 |
begin |
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
598 |
// freed in freeModule() below |
7640
e9e6b4d740f6
clean up LoadImage and UserPathz/AltPath/etc related redundancy by introducing 3 new functions in uStore.pas
sheepluva
parents:
7594
diff
changeset
|
599 |
LandBackSurface:= LoadDataImage(ptCurrTheme, 'LandBackTex', ifIgnoreCaps or ifTransparent); |
6982 | 600 |
if (LandBackSurface <> nil) and GrayScale then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
601 |
Surface2GrayScale(LandBackSurface) |
6096
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
602 |
end; |
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
603 |
end; |
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
604 |
if (tmpsurf <> nil) then |
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
605 |
SDL_FreeSurface(tmpsurf); |
a00dbbf49d6c
Add landbacktex to a few maps, just to see how it looks.
nemo
parents:
6082
diff
changeset
|
606 |
tmpsurf:= nil; |
1792 | 607 |
end; |
608 |
||
1754 | 609 |
procedure LoadMap; |
610 |
var tmpsurf: PSDL_Surface; |
|
3920
a54ca6185307
updated lua loading in the ifrontend and also fixed masked maps
koda
parents:
3912
diff
changeset
|
611 |
mapName: shortstring = ''; |
1754 | 612 |
begin |
613 |
WriteLnToConsole('Loading land from file...'); |
|
614 |
AddProgress; |
|
7640
e9e6b4d740f6
clean up LoadImage and UserPathz/AltPath/etc related redundancy by introducing 3 new functions in uStore.pas
sheepluva
parents:
7594
diff
changeset
|
615 |
tmpsurf:= LoadDataImage(ptMapCurrent, 'map', ifAlpha or ifTransparent 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
|
616 |
if tmpsurf = nil then |
5770 | 617 |
begin |
8025 | 618 |
mapName:= ExtractFileName(cPathz[ptMapCurrent]); |
7640
e9e6b4d740f6
clean up LoadImage and UserPathz/AltPath/etc related redundancy by introducing 3 new functions in uStore.pas
sheepluva
parents:
7594
diff
changeset
|
619 |
tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); |
5770 | 620 |
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
|
621 |
// (bare) Sanity check. Considering possible LongInt comparisons as well as just how much system memoery it would take |
9243
d8f6a396d98e
First select group of templates, then pick template from selected group
unc0rr
parents:
9080
diff
changeset
|
622 |
TryDo((tmpsurf^.w < $40000000) and (tmpsurf^.h < $40000000) and (QWord(tmpsurf^.w) * tmpsurf^.h < 6*1024*1024*1024), 'Map dimensions too big!', true); |
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
|
623 |
|
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
|
624 |
ResizeLand(tmpsurf^.w, tmpsurf^.h); |
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
625 |
LoadMapConfig; |
1792 | 626 |
|
1776 | 627 |
playHeight:= tmpsurf^.h; |
628 |
playWidth:= tmpsurf^.w; |
|
629 |
leftX:= (LAND_WIDTH - playWidth) div 2; |
|
630 |
rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; |
|
631 |
topY:= LAND_HEIGHT - playHeight; |
|
632 |
||
1754 | 633 |
TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Map should be 32bit', true); |
634 |
||
1772 | 635 |
BlitImageAndGenerateCollisionInfo( |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
636 |
(LAND_WIDTH - tmpsurf^.w) div 2, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
637 |
LAND_HEIGHT - tmpsurf^.h, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
638 |
tmpsurf^.w, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
639 |
tmpsurf); |
1754 | 640 |
SDL_FreeSurface(tmpsurf); |
1792 | 641 |
|
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
642 |
LoadMask; |
1754 | 643 |
end; |
644 |
||
5717 | 645 |
procedure DrawBottomBorder; // broken out from other borders for doing a floor-only map, or possibly updating bottom during SD |
5832
f730c8a9777b
Remove some unused variables and options.inc which uFloat doesn't use, probably should never use, and was getting in the way of my testcase - but most importantly, remove the inline on hwSqrt which was causing very bad math on my compiler/machine. We may have to remove more inlining. A pity.
nemo
parents:
5775
diff
changeset
|
646 |
var x, w, c: Longword; |
5717 | 647 |
begin |
5718
e74de0528ef4
Let's draw the bottom border thicker, so it is more visible
nemo
parents:
5717
diff
changeset
|
648 |
for w:= 0 to 23 do |
5717 | 649 |
for x:= leftX to rightX do |
650 |
begin |
|
6011
519f8a58c021
Fix a bunch of warnings (also improves speed a bit in 32 bit code)
unC0Rr
parents:
5832
diff
changeset
|
651 |
Land[Longword(cWaterLine) - 1 - w, x]:= lfIndestructible; |
5717 | 652 |
if (x + w) mod 32 < 16 then |
653 |
c:= AMask |
|
654 |
else |
|
655 |
c:= AMask or RMask or GMask; // FF00FFFF |
|
656 |
||
657 |
if (cReducedQuality and rqBlurryLand) = 0 then |
|
6011
519f8a58c021
Fix a bunch of warnings (also improves speed a bit in 32 bit code)
unC0Rr
parents:
5832
diff
changeset
|
658 |
LandPixels[Longword(cWaterLine) - 1 - w, x]:= c |
5717 | 659 |
else |
6011
519f8a58c021
Fix a bunch of warnings (also improves speed a bit in 32 bit code)
unC0Rr
parents:
5832
diff
changeset
|
660 |
LandPixels[(Longword(cWaterLine) - 1 - w) 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
|
661 |
end |
5717 | 662 |
end; |
663 |
||
1754 | 664 |
procedure GenMap; |
1784 | 665 |
var x, y, w, c: Longword; |
8025 | 666 |
map, mask: shortstring; |
8011 | 667 |
maskOnly: boolean; |
1754 | 668 |
begin |
3463 | 669 |
hasBorder:= false; |
8011 | 670 |
maskOnly:= false; |
2891
e1f902eb0cfe
Formerly "Draw Girders" by MrMfS - now "Disable Girders" to allow template prefs to still exist
nemo
parents:
2866
diff
changeset
|
671 |
|
3463 | 672 |
LoadThemeConfig; |
3697 | 673 |
|
4900 | 674 |
// is this not needed any more? lets hope setlength sets also 0s |
3630 | 675 |
//if ((GameFlags and gfForts) <> 0) or (Pathz[ptMapCurrent] <> '') then |
676 |
// FillChar(Land,SizeOf(TCollisionArray),0);*) |
|
3697 | 677 |
|
3463 | 678 |
if (GameFlags and gfForts) = 0 then |
8025 | 679 |
if cPathz[ptMapCurrent] <> '' then |
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
680 |
begin |
8025 | 681 |
map:= cPathz[ptMapCurrent] + '/map.png'; |
682 |
mask:= cPathz[ptMapCurrent] + '/mask.png'; |
|
8182 | 683 |
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
|
684 |
begin |
8011 | 685 |
maskOnly:= true; |
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
686 |
LoadMask; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
687 |
GenLandSurface |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
688 |
end |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
689 |
else LoadMap; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
690 |
end |
3463 | 691 |
else |
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
692 |
begin |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
693 |
WriteLnToConsole('Generating land...'); |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
694 |
case cMapGen of |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
695 |
0: GenBlank(EdgeTemplates[SelectTemplate]); |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
696 |
1: begin ResizeLand(4096,2048); GenMaze; end; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
697 |
2: GenDrawnMap; |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
698 |
else |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
699 |
OutError('Unknown mapgen', true); |
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
700 |
end; |
3463 | 701 |
GenLandSurface |
8010
195677b0d06b
something bender asked for. allow a mask without a map
nemo
parents:
8003
diff
changeset
|
702 |
end |
3463 | 703 |
else |
704 |
MakeFortsMap; |
|
705 |
||
706 |
AddProgress; |
|
1760 | 707 |
|
1768 | 708 |
// check for land near top |
1784 | 709 |
c:= 0; |
710 |
if (GameFlags and gfBorder) <> 0 then |
|
711 |
hasBorder:= true |
|
712 |
else |
|
713 |
for y:= topY to topY + 5 do |
|
714 |
for x:= leftX to rightX do |
|
715 |
if Land[y, x] <> 0 then |
|
716 |
begin |
|
717 |
inc(c); |
|
8370 | 718 |
if c > LongWord((LAND_WIDTH div 2)) then // avoid accidental triggering |
1784 | 719 |
begin |
720 |
hasBorder:= true; |
|
721 |
break; |
|
722 |
end; |
|
723 |
end; |
|
1768 | 724 |
|
1776 | 725 |
if hasBorder then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
726 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
727 |
for y:= 0 to LAND_HEIGHT - 1 do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
728 |
for x:= 0 to LAND_WIDTH - 1 do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
729 |
if (y < topY) or (x < leftX) or (x > rightX) then |
3519 | 730 |
Land[y, x]:= lfIndestructible; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
731 |
// experiment hardcoding cave |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
732 |
// 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
|
733 |
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
|
734 |
begin |
9524 | 735 |
if (WorldEdge <> weBounce) and (WorldEdge <> weWrap) then |
736 |
for y:= topY to LAND_HEIGHT - 1 do |
|
737 |
begin |
|
738 |
Land[y, leftX + w]:= lfIndestructible; |
|
739 |
Land[y, rightX - w]:= lfIndestructible; |
|
740 |
if (y + w) mod 32 < 16 then |
|
741 |
c:= AMask |
|
742 |
else |
|
743 |
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
|
744 |
|
9524 | 745 |
if (cReducedQuality and rqBlurryLand) = 0 then |
746 |
begin |
|
747 |
LandPixels[y, leftX + w]:= c; |
|
748 |
LandPixels[y, rightX - w]:= c; |
|
749 |
end |
|
750 |
else |
|
751 |
begin |
|
752 |
LandPixels[y div 2, (leftX + w) div 2]:= c; |
|
753 |
LandPixels[y div 2, (rightX - w) div 2]:= c; |
|
754 |
end; |
|
5717 | 755 |
end; |
1768 | 756 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
757 |
for x:= leftX to rightX do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
758 |
begin |
5717 | 759 |
Land[topY + w, x]:= lfIndestructible; |
760 |
if (x + w) mod 32 < 16 then |
|
761 |
c:= AMask |
|
762 |
else |
|
763 |
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
|
764 |
|
5717 | 765 |
if (cReducedQuality and rqBlurryLand) = 0 then |
766 |
LandPixels[topY + w, x]:= c |
|
767 |
else |
|
768 |
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
|
769 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
770 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
771 |
end; |
1768 | 772 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
773 |
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
|
774 |
DrawBottomBorder; |
5717 | 775 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
776 |
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
|
777 |
hasGirders:= false; |
2891
e1f902eb0cfe
Formerly "Draw Girders" by MrMfS - now "Disable Girders" to allow template prefs to still exist
nemo
parents:
2866
diff
changeset
|
778 |
|
8025 | 779 |
if (GameFlags and gfForts = 0) 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
|
780 |
AddObjects |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
781 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
782 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
783 |
AddProgress(); |
1776 | 784 |
|
3058 | 785 |
FreeLandObjects; |
786 |
||
6982 | 787 |
if GrayScale then |
5441
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
788 |
begin |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
789 |
if (cReducedQuality and rqBlurryLand) = 0 then |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
790 |
for x:= leftX to rightX do |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
791 |
for y:= topY to LAND_HEIGHT-1 do |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
792 |
begin |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
793 |
w:= LandPixels[y,x]; |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
794 |
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
|
795 |
(w shr BShift and $FF) * RGB_LUMINANCE_GREEN + |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
796 |
(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
|
797 |
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
|
798 |
w:= 255; |
5441
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
799 |
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
|
800 |
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
|
801 |
end |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
802 |
else |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
803 |
for x:= leftX div 2 to rightX div 2 do |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
804 |
for y:= topY div 2 to LAND_HEIGHT-1 div 2 do |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
805 |
begin |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
806 |
w:= LandPixels[y div 2,x div 2]; |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
807 |
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
|
808 |
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
|
809 |
w:= 255; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
810 |
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
|
811 |
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
|
812 |
end |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5274
diff
changeset
|
813 |
end; |
37 | 814 |
end; |
815 |
||
7079 | 816 |
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
|
817 |
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
|
818 |
begin |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
819 |
WriteLnToConsole('Generating preview...'); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
820 |
case cMapGen of |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
821 |
0: GenBlank(EdgeTemplates[SelectTemplate]); |
7559 | 822 |
1: begin ResizeLand(4096,2048); GenMaze; end; |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4458
diff
changeset
|
823 |
2: GenDrawnMap; |
4562 | 824 |
else |
825 |
OutError('Unknown mapgen', true); |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
826 |
end; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
827 |
|
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
|
828 |
// 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
|
829 |
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
|
830 |
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
|
831 |
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
|
832 |
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
|
833 |
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
|
834 |
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
|
835 |
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
|
836 |
if rh < rw div 2 then rh:= rw * 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
|
837 |
|
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
|
838 |
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
|
839 |
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
|
840 |
|
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
|
841 |
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
|
842 |
lw:= rw div 32; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
843 |
for y:= 0 to 127 do |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
844 |
for x:= 0 to 31 do |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
845 |
begin |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
846 |
Preview[y, x]:= 0; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
847 |
for bit:= 0 to 7 do |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
848 |
begin |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
849 |
t:= 0; |
3617 | 850 |
cbit:= bit * 8; |
851 |
for yy:= y * lh to y * lh + 7 do |
|
852 |
for xx:= x * lw + cbit to x * lw + cbit + 7 do |
|
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
|
853 |
if ((yy-oy) and LAND_HEIGHT_MASK = 0) and ((xx-ox) and LAND_WIDTH_MASK = 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
|
854 |
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
|
855 |
inc(t); |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
856 |
if t > 8 then |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3287
diff
changeset
|
857 |
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
|
858 |
end; |
566 | 859 |
end; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
860 |
end; |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
861 |
|
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
|
862 |
|
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
|
863 |
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
|
864 |
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
|
865 |
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
|
866 |
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
|
867 |
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
|
868 |
else |
6025
cac1d5601d7c
reviewed the build system and parts of the previous merge, performed some code cleanup
koda
parents:
6023
diff
changeset
|
869 |
TryDo(s = digest, 'Different maps generated, sorry', 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
|
870 |
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
|
871 |
|
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
|
872 |
procedure chSendLandDigest(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
|
873 |
var adler, i: LongInt; |
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
|
874 |
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
|
875 |
adler:= 1; |
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
|
876 |
for i:= 0 to LAND_HEIGHT-1 do |
6927
ee000959d645
Oh, and I guess this is needed as well, although if many other places in the code do this, pas2c will need
nemo
parents:
6898
diff
changeset
|
877 |
adler:= Adler32Update(adler, @Land[i,0], LAND_WIDTH); |
6254
e90fb60cb46d
Force a desync if there is a script name mismatch. This avoids playing until the game desyncs due to script differences.
nemo
parents:
6096
diff
changeset
|
878 |
s:= 'M' + IntToStr(adler) + cScriptName; |
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
|
879 |
|
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
|
880 |
chLandCheck(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
|
881 |
SendIPCRaw(@s[0], Length(s) + 1) |
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
|
882 |
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
|
883 |
|
3038 | 884 |
procedure initModule; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2692
diff
changeset
|
885 |
begin |
6898 | 886 |
RegisterVariable('landcheck', @chLandCheck, false); |
887 |
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
|
888 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
889 |
LandBackSurface:= nil; |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
890 |
digest:= ''; |
7549 | 891 |
LAND_WIDTH:= 0; |
892 |
LAND_HEIGHT:= 0; |
|
893 |
(* |
|
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
|
894 |
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
|
895 |
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
|
896 |
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
|
897 |
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
|
898 |
|
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
|
899 |
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
|
900 |
SetLength(LandDirty, (LAND_HEIGHT div 32), (LAND_WIDTH div 32)); |
7549 | 901 |
*) |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2692
diff
changeset
|
902 |
end; |
51 | 903 |
|
3038 | 904 |
procedure freeModule; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2692
diff
changeset
|
905 |
begin |
7151 | 906 |
SetLength(Land, 0, 0); |
907 |
SetLength(LandPixels, 0, 0); |
|
908 |
SetLength(LandDirty, 0, 0); |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2692
diff
changeset
|
909 |
end; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2692
diff
changeset
|
910 |
|
4 | 911 |
end. |