diff -r 125e120165aa -r 2562797ab3cf hedgewars/uLandUtils.pas --- a/hedgewars/uLandUtils.pas Thu Dec 04 20:15:03 2014 +0100 +++ b/hedgewars/uLandUtils.pas Fri Dec 05 02:19:30 2014 +0100 @@ -2,9 +2,10 @@ interface procedure ResizeLand(width, height: LongWord); +procedure InitWorldEdges(); implementation -uses uUtils, uConsts, uVariables; +uses uUtils, uConsts, uVariables, uTypes; procedure ResizeLand(width, height: LongWord); var potW, potH: LongInt; @@ -31,4 +32,56 @@ end; end; +procedure InitWorldEdges(); +var cy, cx, lx, ly: LongInt; + found: boolean; +begin +playHeight:= LAND_HEIGHT; +topY:= 0; + +lx:= LongInt(LAND_WIDTH) - 1; + +if WorldEdge = weNone then + begin + playWidth:= LAND_WIDTH; + leftX := 0; + rightX:= lx; + EXIT; + end; + +ly:= LongInt(LAND_HEIGHT) - 1; + +// find most left land pixels and set leftX accordingly +found:= false; +for cx:= 0 to lx do + begin + for cy:= ly downto 0 do + if Land[cy, cx] <> 0 then + begin + leftX:= max(0, cx - cWorldEdgeDist); + // break out of both loops + found:= true; + break; + end; + if found then break; + end; + +// find most right land pixels and set rightX accordingly +found:= false; +for cx:= lx downto 0 do + begin + for cy:= ly downto 0 do + if Land[cy, cx] <> 0 then + begin + rightX:= min(lx, cx + cWorldEdgeDist); + // break out of both loops + found:= true; + break; + end; + if found then break; + end; + +playWidth := rightX + 1 - leftX; +end; + end.