hedgewars/uLandUtils.pas
author unC0Rr
Wed, 04 Jan 2023 10:42:21 +0100
branchtransitional_engine
changeset 15933 33798b649d9c
parent 15930 f39f0f614dbf
child 15934 022ec6b916b7
permissions -rw-r--r--
Use rust land generator in hwengine
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10198
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
     1
unit uLandUtils;
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
     2
interface
15930
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
     3
uses SDLh;
10198
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
     4
15933
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
     5
procedure CreateTemplatedLand(featureSize: Longword; seed, dataPath, theme: shortstring);
10198
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
     6
procedure ResizeLand(width, height: LongWord);
15929
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
     7
procedure DisposeLand();
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
procedure InitWorldEdges();
10198
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
     9
15929
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    10
function  LandGet(y, x: LongInt): Word;
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    11
procedure LandSet(y, x: LongInt; value: Word);
15930
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    12
function  LandRow(row: LongInt): PWordArray;
15929
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    13
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    14
procedure FillLand(x, y: LongInt; border, value: Word);
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    15
15930
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    16
function  LandPixelGet(y, x: LongInt): Longword;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    17
procedure LandPixelSet(y, x: LongInt; value: Longword);
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    18
function  LandPixelRow(row: LongInt): PLongwordArray;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    19
10198
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
    20
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
    21
uses uUtils, uConsts, uVariables, uTypes;
10198
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
    22
15929
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    23
const LibFutureName = 'hwengine_future';
15933
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    24
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    25
function  create_empty_game_field(width, height: Longword): pointer; cdecl; external LibFutureName;
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    26
procedure get_game_field_parameters(game_field: pointer; var width: LongInt; var height: LongInt); cdecl; external LibFutureName;
15929
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    27
procedure dispose_game_field(game_field: pointer); cdecl; external LibFutureName;
15933
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    28
15929
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    29
function  land_get(game_field: pointer; x, y: LongInt): Word; cdecl; external LibFutureName;
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    30
procedure land_set(game_field: pointer; x, y: LongInt; value: Word); cdecl; external LibFutureName;
15930
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    31
function  land_row(game_field: pointer; row: LongInt): PWordArray; cdecl; external LibFutureName;
15929
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    32
procedure land_fill(game_field: pointer; x, y: LongInt; border, fill: Word); cdecl; external LibFutureName;
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    33
15930
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    34
function  land_pixel_get(game_field: pointer; x, y: LongInt): Longword; cdecl; external LibFutureName;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    35
procedure land_pixel_set(game_field: pointer; x, y: LongInt; value: Longword); cdecl; external LibFutureName;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    36
function  land_pixel_row(game_field: pointer; row: LongInt): PLongwordArray; cdecl; external LibFutureName;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    37
15933
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    38
function  generate_templated_game_field(feature_size: Longword; seed, data_path, theme_name: PChar): pointer; cdecl; external LibFutureName;
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    39
15929
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    40
var gameField: pointer;
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    41
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    42
function  LandGet(y, x: LongInt): Word;
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    43
begin
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    44
    LandGet:= land_get(gameField, x, y)
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    45
end;
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    46
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    47
procedure LandSet(y, x: LongInt; value: Word);
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    48
begin
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    49
    land_set(gameField, x, y, value)
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    50
end;
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    51
15930
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    52
function  LandRow(row: LongInt): PWordArray;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    53
begin
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    54
    LandRow:= land_row(gameField, row)
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    55
end;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    56
15929
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    57
procedure FillLand(x, y: LongInt; border, value: Word);
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    58
begin
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    59
    land_fill(gameField, x, y, border, value)
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    60
end;
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
    61
15930
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    62
function  LandPixelGet(y, x: LongInt): Longword;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    63
begin
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    64
    LandPixelGet:= land_pixel_get(gameField, x, y)
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    65
end;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    66
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    67
procedure LandPixelSet(y, x: LongInt; value: Longword);
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    68
begin
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    69
    land_pixel_set(gameField, x, y, value)
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    70
end;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    71
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    72
function  LandPixelRow(row: LongInt): PLongwordArray;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    73
begin
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    74
    LandPixelRow:= land_pixel_row(gameField, row)
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    75
end;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15929
diff changeset
    76
15933
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    77
procedure CreateTemplatedLand(featureSize: Longword; seed, dataPath, theme: shortstring);
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    78
begin
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    79
    seed[byte(seed[0]) + 1]:= #0;
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    80
    theme[byte(theme[0]) + 1]:= #0;
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    81
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    82
    gameField:= generate_templated_game_field(featureSize, @seed[1], Str2PChar(dataPath), @theme[1]);
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    83
    get_game_field_parameters(gameField, LAND_WIDTH, LAND_HEIGHT);
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    84
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    85
    // let's assume those are powers of two
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    86
    LAND_WIDTH_MASK:= not(LAND_WIDTH-1);
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    87
    LAND_HEIGHT_MASK:= not(LAND_HEIGHT-1);
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    88
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    89
    SetLength(LandDirty, (LAND_HEIGHT div 32), (LAND_WIDTH div 32));
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    90
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    91
    initScreenSpaceVars();
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    92
end;
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
    93
10198
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
    94
procedure ResizeLand(width, height: LongWord);
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
    95
var potW, potH: LongInt;
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
    96
begin
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
    97
potW:= toPowerOf2(width);
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
    98
potH:= toPowerOf2(height);
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
    99
if (potW <> LAND_WIDTH) or (potH <> LAND_HEIGHT) then
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   100
    begin
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   101
    LAND_WIDTH:= potW;
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   102
    LAND_HEIGHT:= potH;
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   103
    LAND_WIDTH_MASK:= not(LAND_WIDTH-1);
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   104
    LAND_HEIGHT_MASK:= not(LAND_HEIGHT-1);
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   105
    cWaterLine:= LAND_HEIGHT;
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   106
15933
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15930
diff changeset
   107
    gameField:= create_empty_game_field(LAND_WIDTH, LAND_HEIGHT);
10198
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   108
    SetLength(LandDirty, (LAND_HEIGHT div 32), (LAND_WIDTH div 32));
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   109
    // 0.5 is already approaching on unplayable
10994
cd7f918eed30 bit friendlier if the uVariables values get changed
nemo
parents: 10626
diff changeset
   110
    if (width div 4096 >= 2) or (height div 2048 >= 2) then cMaxZoomLevel:= cMaxZoomLevel/2;
10198
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   111
    cMinMaxZoomLevelDelta:= cMaxZoomLevel - cMinZoomLevel
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   112
    end;
11704
1694b379c83f fix clouds/flakes area not being adjusted after ResizeLand()
sheepluva
parents: 10994
diff changeset
   113
initScreenSpaceVars();
10198
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   114
end;
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   115
15929
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
   116
procedure DisposeLand();
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
   117
begin
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
   118
    dispose_game_field(gameField)
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
   119
end;
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
   120
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
   121
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
   122
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
   123
    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
   124
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
   125
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
   126
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
   127
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
   128
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
   129
15164
794dc7237ca1 Fix world edge positions for drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 12311
diff changeset
   130
// don't change world edges for drawn maps
794dc7237ca1 Fix world edge positions for drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 12311
diff changeset
   131
if (cMapGen = mgDrawn) then
794dc7237ca1 Fix world edge positions for drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 12311
diff changeset
   132
    // edges were adjusted already in GenDrawnMap() in uLand
794dc7237ca1 Fix world edge positions for drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 12311
diff changeset
   133
    EXIT;
794dc7237ca1 Fix world edge positions for drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 12311
diff changeset
   134
12311
1b5a4807f8f4 fix fort mode's edge adjustments getting lost with weWrap. issue #181
sheepluva
parents: 11704
diff changeset
   135
// 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
   136
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
   137
    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
   138
    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
   139
    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
   140
    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
   141
    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
   142
    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
   143
12311
1b5a4807f8f4 fix fort mode's edge adjustments getting lost with weWrap. issue #181
sheepluva
parents: 11704
diff changeset
   144
// 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
   145
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
   146
    begin
1b5a4807f8f4 fix fort mode's edge adjustments getting lost with weWrap. issue #181
sheepluva
parents: 11704
diff changeset
   147
    // 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
   148
    EXIT;
1b5a4807f8f4 fix fort mode's edge adjustments getting lost with weWrap. issue #181
sheepluva
parents: 11704
diff changeset
   149
    end;
1b5a4807f8f4 fix fort mode's edge adjustments getting lost with weWrap. issue #181
sheepluva
parents: 11704
diff changeset
   150
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
   151
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
   152
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
   153
// 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
   154
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
   155
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
   156
    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
   157
    for cy:= ly downto 0 do
15929
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
   158
        if LandGet(cy, cx) <> 0 then
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
   159
            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
   160
            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
   161
            // 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
   162
            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
   163
            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
   164
            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
   165
    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
   166
    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
   167
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
   168
// 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
   169
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
   170
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
   171
    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
   172
    for cy:= ly downto 0 do
15929
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15164
diff changeset
   173
        if LandGet(cy, cx) <> 0 then
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
   174
            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
   175
            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
   176
            // 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
   177
            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
   178
            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
   179
            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
   180
    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
   181
    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
   182
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
   183
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
   184
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
   185
10198
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   186
end.