author | alfadur |
Fri, 06 Oct 2017 14:45:22 +0200 | |
changeset 12657 | 2065819170ce |
parent 12311 | 1b5a4807f8f4 |
child 15164 | 794dc7237ca1 |
permissions | -rw-r--r-- |
10198 | 1 |
unit uLandUtils; |
2 |
interface |
|
3 |
||
4 |
procedure ResizeLand(width, height: LongWord); |
|
10626
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
5 |
procedure InitWorldEdges(); |
10198 | 6 |
|
7 |
implementation |
|
10626
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
8 |
uses uUtils, uConsts, uVariables, uTypes; |
10198 | 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 |
|
10994 | 30 |
if (width div 4096 >= 2) or (height div 2048 >= 2) then cMaxZoomLevel:= cMaxZoomLevel/2; |
10198 | 31 |
cMinMaxZoomLevelDelta:= cMaxZoomLevel - cMinZoomLevel |
32 |
end; |
|
11704
1694b379c83f
fix clouds/flakes area not being adjusted after ResizeLand()
sheepluva
parents:
10994
diff
changeset
|
33 |
initScreenSpaceVars(); |
10198 | 34 |
end; |
35 |
||
10626
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
36 |
procedure InitWorldEdges(); |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
37 |
var cy, cx, lx, ly: LongInt; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
38 |
found: boolean; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
39 |
begin |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
40 |
playHeight:= LAND_HEIGHT; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
41 |
topY:= 0; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
42 |
|
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
43 |
lx:= LongInt(LAND_WIDTH) - 1; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
44 |
|
12311
1b5a4807f8f4
fix fort mode's edge adjustments getting lost with weWrap. issue #181
sheepluva
parents:
11704
diff
changeset
|
45 |
// use maximum available map width if there is no special world edge |
10626
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
46 |
if WorldEdge = weNone then |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
47 |
begin |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
48 |
playWidth:= LAND_WIDTH; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
49 |
leftX := 0; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
50 |
rightX:= lx; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
51 |
EXIT; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
52 |
end; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
53 |
|
12311
1b5a4807f8f4
fix fort mode's edge adjustments getting lost with weWrap. issue #181
sheepluva
parents:
11704
diff
changeset
|
54 |
// keep fort distance consistent if we're in wrap mode on fort map |
1b5a4807f8f4
fix fort mode's edge adjustments getting lost with weWrap. issue #181
sheepluva
parents:
11704
diff
changeset
|
55 |
if (cMapGen = mgForts) and (WorldEdge = weWrap) then |
1b5a4807f8f4
fix fort mode's edge adjustments getting lost with weWrap. issue #181
sheepluva
parents:
11704
diff
changeset
|
56 |
begin |
1b5a4807f8f4
fix fort mode's edge adjustments getting lost with weWrap. issue #181
sheepluva
parents:
11704
diff
changeset
|
57 |
// edges were adjusted already in MakeFortsMap() in uLand |
1b5a4807f8f4
fix fort mode's edge adjustments getting lost with weWrap. issue #181
sheepluva
parents:
11704
diff
changeset
|
58 |
EXIT; |
1b5a4807f8f4
fix fort mode's edge adjustments getting lost with weWrap. issue #181
sheepluva
parents:
11704
diff
changeset
|
59 |
end; |
1b5a4807f8f4
fix fort mode's edge adjustments getting lost with weWrap. issue #181
sheepluva
parents:
11704
diff
changeset
|
60 |
|
10626
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
61 |
ly:= LongInt(LAND_HEIGHT) - 1; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
62 |
|
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
63 |
// find most left land pixels and set leftX accordingly |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
64 |
found:= false; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
65 |
for cx:= 0 to lx do |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
66 |
begin |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
67 |
for cy:= ly downto 0 do |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
68 |
if Land[cy, cx] <> 0 then |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
69 |
begin |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
70 |
leftX:= max(0, cx - cWorldEdgeDist); |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
71 |
// break out of both loops |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
72 |
found:= true; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
73 |
break; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
74 |
end; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
75 |
if found then break; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
76 |
end; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
77 |
|
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
78 |
// find most right land pixels and set rightX accordingly |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
79 |
found:= false; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
80 |
for cx:= lx downto 0 do |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
81 |
begin |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
82 |
for cy:= ly downto 0 do |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
83 |
if Land[cy, cx] <> 0 then |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
84 |
begin |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
85 |
rightX:= min(lx, cx + cWorldEdgeDist); |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
86 |
// break out of both loops |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
87 |
found:= true; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
88 |
break; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
89 |
end; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
90 |
if found then break; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
91 |
end; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
92 |
|
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
93 |
playWidth := rightX + 1 - leftX; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
94 |
end; |
2562797ab3cf
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents:
10198
diff
changeset
|
95 |
|
10198 | 96 |
end. |