1 unit uLandUtils;
2 interface
3 
4 procedure ResizeLand(width, height: LongWord);
5 procedure InitWorldEdges();
6 
7 implementation
8 uses uUtils, uConsts, uVariables, uTypes;
9 
10 procedure ResizeLand(width, height: LongWord);
11 var potW, potH: LongInt;
12 begin
13 potW:= toPowerOf2(width);
14 potH:= toPowerOf2(height);
15 if (potW <> LAND_WIDTH) or (potH <> LAND_HEIGHT) then
16     begin
17     LAND_WIDTH:= potW;
18     LAND_HEIGHT:= potH;
19     LAND_WIDTH_MASK:= not(LAND_WIDTH-1);
20     LAND_HEIGHT_MASK:= not(LAND_HEIGHT-1);
21     cWaterLine:= LAND_HEIGHT;
22     if (cReducedQuality and rqBlurryLand) = 0 then
23         SetLength(LandPixels, LAND_HEIGHT, LAND_WIDTH)
24     else
25         SetLength(LandPixels, LAND_HEIGHT div 2, LAND_WIDTH div 2);
26 
27     SetLength(Land, LAND_HEIGHT, LAND_WIDTH);
28     SetLength(LandDirty, (LAND_HEIGHT div 32), (LAND_WIDTH div 32));
29     // 0.5 is already approaching on unplayable
30     if (width div 4096 >= 2) or (height div 2048 >= 2) then cMaxZoomLevel:= cMaxZoomLevel/2;
31     cMinMaxZoomLevelDelta:= cMaxZoomLevel - cMinZoomLevel
32     end;
33 initScreenSpaceVars();
34 end;
35 
36 procedure InitWorldEdges();
37 var cy, cx, lx, ly: LongInt;
38     found: boolean;
39 begin
40 playHeight:= LAND_HEIGHT;
41 topY:= 0;
42 
43 lx:= LongInt(LAND_WIDTH) - 1;
44 
45 // don't change world edges for drawn maps
46 if (cMapGen = mgDrawn) then
47     // edges were adjusted already in GenDrawnMap() in uLand
48     EXIT;
49 
50 // use maximum available map width if there is no special world edge
51 if WorldEdge = weNone then
52     begin
53     playWidth:= LAND_WIDTH;
54     leftX := 0;
55     rightX:= lx;
56     EXIT;
57     end;
58 
59 // keep fort distance consistent if we're in wrap mode on fort map
60 if (cMapGen = mgForts) and (WorldEdge = weWrap) then
61     begin
62     // edges were adjusted already in MakeFortsMap() in uLand
63     EXIT;
64     end;
65 
66 ly:= LongInt(LAND_HEIGHT) - 1;
67 
68 // find most left land pixels and set leftX accordingly
69 found:= false;
70 for cx:= 0 to lx do
71     begin
72     for cy:= ly downto 0 do
73         if Land[cy, cx] <> 0 then
74             begin
75             leftX:= max(0, cx - cWorldEdgeDist);
76             // break out of both loops
77             found:= true;
78             break;
79             end;
80     if found then break;
81     end;
82 
83 // find most right land pixels and set rightX accordingly
84 found:= false;
85 for cx:= lx downto 0 do
86     begin
87     for cy:= ly downto 0 do
88         if Land[cy, cx] <> 0 then
89             begin
90             rightX:= min(lx, cx + cWorldEdgeDist);
91             // break out of both loops
92             found:= true;
93             break;
94             end;
95     if found then break;
96     end;
97 
98 playWidth := rightX + 1 - leftX;
99 end;
100 
101 end.
102