18 |
18 |
19 {$INCLUDE "options.inc"} |
19 {$INCLUDE "options.inc"} |
20 |
20 |
21 unit uLand; |
21 unit uLand; |
22 interface |
22 interface |
23 uses SDLh, uLandTemplates, uFloat, uConsts, GLunit, uTypes, uAILandMarks; |
23 uses SDLh, uLandTemplates, uFloat, uConsts, uTypes, uAILandMarks; |
24 |
24 |
25 procedure initModule; |
25 procedure initModule; |
26 procedure freeModule; |
26 procedure freeModule; |
27 procedure DrawBottomBorder; |
27 procedure DrawBottomBorder; |
28 procedure GenMap; |
28 procedure GenMap; |
58 if (width div 4096 >= 2) or (height div 2048 >= 2) then cMaxZoomLevel:= 0.5; |
58 if (width div 4096 >= 2) or (height div 2048 >= 2) then cMaxZoomLevel:= 0.5; |
59 cMinMaxZoomLevelDelta:= cMaxZoomLevel - cMinZoomLevel |
59 cMinMaxZoomLevelDelta:= cMaxZoomLevel - cMinZoomLevel |
60 end; |
60 end; |
61 end; |
61 end; |
62 |
62 |
63 procedure ColorizeLand(Surface: PSDL_Surface); |
63 |
|
64 procedure DrawBorderFromImage(Surface: PSDL_Surface); |
64 var tmpsurf: PSDL_Surface; |
65 var tmpsurf: PSDL_Surface; |
65 r, rr: TSDL_Rect; |
66 r, rr: TSDL_Rect; |
66 x, yd, yu: LongInt; |
67 x, yd, yu: LongInt; |
67 begin |
68 begin |
68 tmpsurf:= LoadDataImage(ptCurrTheme, 'LandTex', ifCritical or ifIgnoreCaps); |
|
69 r.y:= 0; |
|
70 while r.y < LAND_HEIGHT do |
|
71 begin |
|
72 r.x:= 0; |
|
73 while r.x < LAND_WIDTH do |
|
74 begin |
|
75 SDL_UpperBlit(tmpsurf, nil, Surface, @r); |
|
76 inc(r.x, tmpsurf^.w) |
|
77 end; |
|
78 inc(r.y, tmpsurf^.h) |
|
79 end; |
|
80 SDL_FreeSurface(tmpsurf); |
|
81 |
|
82 // freed in freeModule() below |
|
83 LandBackSurface:= LoadDataImage(ptCurrTheme, 'LandBackTex', ifIgnoreCaps or ifTransparent); |
|
84 if (LandBackSurface <> nil) and GrayScale then Surface2GrayScale(LandBackSurface); |
|
85 |
|
86 tmpsurf:= LoadDataImage(ptCurrTheme, 'Border', ifCritical or ifIgnoreCaps or ifTransparent); |
69 tmpsurf:= LoadDataImage(ptCurrTheme, 'Border', ifCritical or ifIgnoreCaps or ifTransparent); |
87 for x:= 0 to LAND_WIDTH - 1 do |
70 for x:= 0 to LAND_WIDTH - 1 do |
88 begin |
71 begin |
89 yd:= LAND_HEIGHT - 1; |
72 yd:= LAND_HEIGHT - 1; |
90 repeat |
73 repeat |
125 until yd < 0; |
108 until yd < 0; |
126 end; |
109 end; |
127 SDL_FreeSurface(tmpsurf); |
110 SDL_FreeSurface(tmpsurf); |
128 end; |
111 end; |
129 |
112 |
|
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 |
|
126 if LandPixels[y, x] = 0 then |
|
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 |
|
160 if LandPixels[y, x] = 0 then |
|
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; |
|
193 begin |
|
194 tmpsurf:= LoadDataImage(ptCurrTheme, 'LandTex', ifCritical or ifIgnoreCaps); |
|
195 r.y:= 0; |
|
196 while r.y < LAND_HEIGHT do |
|
197 begin |
|
198 r.x:= 0; |
|
199 while r.x < LAND_WIDTH do |
|
200 begin |
|
201 SDL_UpperBlit(tmpsurf, nil, Surface, @r); |
|
202 inc(r.x, tmpsurf^.w) |
|
203 end; |
|
204 inc(r.y, tmpsurf^.h) |
|
205 end; |
|
206 SDL_FreeSurface(tmpsurf); |
|
207 |
|
208 // freed in freeModule() below |
|
209 LandBackSurface:= LoadDataImage(ptCurrTheme, 'LandBackTex', ifIgnoreCaps or ifTransparent); |
|
210 if (LandBackSurface <> nil) and GrayScale then Surface2GrayScale(LandBackSurface); |
|
211 end; |
|
212 |
130 procedure SetPoints(var Template: TEdgeTemplate; var pa: TPixAr; fps: PPointArray); |
213 procedure SetPoints(var Template: TEdgeTemplate; var pa: TPixAr; fps: PPointArray); |
131 var i: LongInt; |
214 var i: LongInt; |
132 begin |
215 begin |
133 with Template do |
216 with Template do |
134 begin |
217 begin |
274 rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; |
357 rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; |
275 topY:= LAND_HEIGHT - playHeight; |
358 topY:= LAND_HEIGHT - playHeight; |
276 end; |
359 end; |
277 |
360 |
278 function SelectTemplate: LongInt; |
361 function SelectTemplate: LongInt; |
|
362 var l: LongInt; |
279 begin |
363 begin |
280 if (cReducedQuality and rqLowRes) <> 0 then |
364 if (cReducedQuality and rqLowRes) <> 0 then |
281 SelectTemplate:= SmallTemplates[getrandom(Succ(High(SmallTemplates)))] |
365 SelectTemplate:= SmallTemplates[getrandom(Succ(High(SmallTemplates)))] |
282 else |
366 else |
|
367 begin |
|
368 if cTemplateFilter = 0 then |
|
369 begin |
|
370 l:= getRandom(GroupedTemplatesCount); |
|
371 repeat |
|
372 inc(cTemplateFilter); |
|
373 dec(l, TemplateCounts[cTemplateFilter]); |
|
374 until l < 0; |
|
375 end else getRandom(1); |
|
376 |
283 case cTemplateFilter of |
377 case cTemplateFilter of |
284 0: SelectTemplate:= getrandom(Succ(High(EdgeTemplates))); |
378 0: OutError('Ask unC0Rr about what you did wrong', true); |
285 1: SelectTemplate:= SmallTemplates[getrandom(Succ(High(SmallTemplates)))]; |
379 1: SelectTemplate:= SmallTemplates[getrandom(TemplateCounts[cTemplateFilter])]; |
286 2: SelectTemplate:= MediumTemplates[getrandom(Succ(High(MediumTemplates)))]; |
380 2: SelectTemplate:= MediumTemplates[getrandom(TemplateCounts[cTemplateFilter])]; |
287 3: SelectTemplate:= LargeTemplates[getrandom(Succ(High(LargeTemplates)))]; |
381 3: SelectTemplate:= LargeTemplates[getrandom(TemplateCounts[cTemplateFilter])]; |
288 4: SelectTemplate:= CavernTemplates[getrandom(Succ(High(CavernTemplates)))]; |
382 4: SelectTemplate:= CavernTemplates[getrandom(TemplateCounts[cTemplateFilter])]; |
289 5: SelectTemplate:= WackyTemplates[getrandom(Succ(High(WackyTemplates)))]; |
383 5: SelectTemplate:= WackyTemplates[getrandom(TemplateCounts[cTemplateFilter])]; |
290 // For lua only! |
384 // For lua only! |
291 6: begin |
385 6: begin |
292 SelectTemplate:= min(LuaTemplateNumber,High(EdgeTemplates)); |
386 SelectTemplate:= min(LuaTemplateNumber,High(EdgeTemplates)); |
293 GetRandom(2) // burn 1 |
387 GetRandom(2) // burn 1 |
294 end; |
388 end; |
|
389 end |
295 end; |
390 end; |
296 |
391 |
297 WriteLnToConsole('Selected template #'+inttostr(SelectTemplate)+' using filter #'+inttostr(cTemplateFilter)); |
392 WriteLnToConsole('Selected template #'+inttostr(SelectTemplate)+' using filter #'+inttostr(cTemplateFilter)); |
298 end; |
393 end; |
299 |
394 |
332 |
427 |
333 tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, LAND_WIDTH, LAND_HEIGHT, 32, RMask, GMask, BMask, 0); |
428 tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, LAND_WIDTH, LAND_HEIGHT, 32, RMask, GMask, BMask, 0); |
334 |
429 |
335 TryDo(tmpsurf <> nil, 'Error creating pre-land surface', true); |
430 TryDo(tmpsurf <> nil, 'Error creating pre-land surface', true); |
336 ColorizeLand(tmpsurf); |
431 ColorizeLand(tmpsurf); |
|
432 if gameFlags and gfShoppaBorder = 0 then DrawBorderFromImage(tmpsurf); |
337 AddOnLandObjects(tmpsurf); |
433 AddOnLandObjects(tmpsurf); |
338 |
434 |
339 LandSurface2LandPixels(tmpsurf); |
435 LandSurface2LandPixels(tmpsurf); |
340 SDL_FreeSurface(tmpsurf); |
436 SDL_FreeSurface(tmpsurf); |
|
437 |
|
438 if gameFlags and gfShoppaBorder <> 0 then DrawShoppaBorder; |
|
439 |
341 for x:= leftX+2 to rightX-2 do |
440 for x:= leftX+2 to rightX-2 do |
342 for y:= topY+2 to LAND_HEIGHT-3 do |
441 for y:= topY+2 to LAND_HEIGHT-3 do |
343 if (Land[y, x] = 0) and |
442 if (Land[y, x] = 0) and |
344 (((Land[y, x-1] = lfBasic) and ((Land[y+1,x] = lfBasic)) or (Land[y-1,x] = lfBasic)) or |
443 (((Land[y, x-1] = lfBasic) and ((Land[y+1,x] = lfBasic)) or (Land[y-1,x] = lfBasic)) or |
345 ((Land[y, x+1] = lfBasic) and ((Land[y-1,x] = lfBasic) or (Land[y+1,x] = lfBasic)))) then |
444 ((Land[y, x+1] = lfBasic) and ((Land[y-1,x] = lfBasic) or (Land[y+1,x] = lfBasic)))) then |
516 begin |
615 begin |
517 mapName:= ExtractFileName(cPathz[ptMapCurrent]); |
616 mapName:= ExtractFileName(cPathz[ptMapCurrent]); |
518 tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); |
617 tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); |
519 end; |
618 end; |
520 // (bare) Sanity check. Considering possible LongInt comparisons as well as just how much system memoery it would take |
619 // (bare) Sanity check. Considering possible LongInt comparisons as well as just how much system memoery it would take |
521 TryDo((tmpsurf^.w < $40000000) and (tmpsurf^.h < $40000000) and (tmpsurf^.w * tmpsurf^.h < 6*1024*1024*1024), 'Map dimensions too big!', true); |
620 TryDo((tmpsurf^.w < $40000000) and (tmpsurf^.h < $40000000) and (QWord(tmpsurf^.w) * tmpsurf^.h < 6*1024*1024*1024), 'Map dimensions too big!', true); |
522 |
621 |
523 ResizeLand(tmpsurf^.w, tmpsurf^.h); |
622 ResizeLand(tmpsurf^.w, tmpsurf^.h); |
524 LoadMapConfig; |
623 LoadMapConfig; |
525 |
624 |
526 playHeight:= tmpsurf^.h; |
625 playHeight:= tmpsurf^.h; |