hedgewars/uLandUtils.pas
author unC0Rr
Wed, 28 Aug 2024 15:31:51 +0200
branchtransitional_engine
changeset 16021 6a3dc15b78b9
parent 16007 96d0e6149d3d
child 16023 0fd23fc57947
permissions -rw-r--r--
Add corrosion as a subdirectory, CMake fixes
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
15901
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
     3
uses SDLh;
10198
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
     4
16007
96d0e6149d3d Fix type
unC0Rr
parents: 15928
diff changeset
     5
procedure GenerateTemplatedLand(featureSize: Longword; seed, templateType: shortstring; dataPath: ansistring);
10198
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
     6
procedure ResizeLand(width, height: LongWord);
15900
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
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
15900
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    10
function  LandGet(y, x: LongInt): Word;
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    11
procedure LandSet(y, x: LongInt; value: Word);
15901
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    12
function  LandRow(row: LongInt): PWordArray;
15900
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    13
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    14
procedure FillLand(x, y: LongInt; border, value: Word);
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    15
15901
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    16
function  LandPixelGet(y, x: LongInt): Longword;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    17
procedure LandPixelSet(y, x: LongInt; value: Longword);
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    18
function  LandPixelRow(row: LongInt): PLongwordArray;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
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
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents: 16007
diff changeset
    23
function  create_empty_game_field(width, height: Longword): pointer; cdecl; external;
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents: 16007
diff changeset
    24
procedure get_game_field_parameters(game_field: pointer; var width: LongInt; var height: LongInt; var play_width: LongInt; var play_height: LongInt); cdecl; external;
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents: 16007
diff changeset
    25
procedure dispose_game_field(game_field: pointer); cdecl; external;
15904
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    26
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents: 16007
diff changeset
    27
function  land_get(game_field: pointer; x, y: LongInt): Word; cdecl; external;
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents: 16007
diff changeset
    28
procedure land_set(game_field: pointer; x, y: LongInt; value: Word); cdecl; external;
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents: 16007
diff changeset
    29
function  land_row(game_field: pointer; row: LongInt): PWordArray; cdecl; external;
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents: 16007
diff changeset
    30
procedure land_fill(game_field: pointer; x, y: LongInt; border, fill: Word); cdecl; external;
15900
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    31
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents: 16007
diff changeset
    32
function  land_pixel_get(game_field: pointer; x, y: LongInt): Longword; cdecl; external;
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents: 16007
diff changeset
    33
procedure land_pixel_set(game_field: pointer; x, y: LongInt; value: Longword); cdecl; external;
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents: 16007
diff changeset
    34
function  land_pixel_row(game_field: pointer; row: LongInt): PLongwordArray; cdecl; external;
15901
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    35
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents: 16007
diff changeset
    36
function  generate_templated_game_field(feature_size: Longword; seed, template_type, data_path: PChar): pointer; cdecl; external;
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents: 16007
diff changeset
    37
procedure apply_theme(game_field: pointer; data_path, theme_name: PChar); cdecl; external;
15904
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    38
15900
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    39
var gameField: pointer;
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    40
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    41
function  LandGet(y, x: LongInt): Word;
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    42
begin
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    43
    LandGet:= land_get(gameField, x, y)
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    44
end;
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    45
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    46
procedure LandSet(y, x: LongInt; value: Word);
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    47
begin
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    48
    land_set(gameField, x, y, value)
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    49
end;
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    50
15901
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    51
function  LandRow(row: LongInt): PWordArray;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    52
begin
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    53
    LandRow:= land_row(gameField, row)
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    54
end;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    55
15900
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    56
procedure FillLand(x, y: LongInt; border, value: Word);
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    57
begin
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    58
    land_fill(gameField, x, y, border, value)
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    59
end;
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
    60
15901
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    61
function  LandPixelGet(y, x: LongInt): Longword;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    62
begin
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    63
    LandPixelGet:= land_pixel_get(gameField, x, y)
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    64
end;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    65
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    66
procedure LandPixelSet(y, x: LongInt; value: Longword);
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    67
begin
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    68
    land_pixel_set(gameField, x, y, value)
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    69
end;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    70
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    71
function  LandPixelRow(row: LongInt): PLongwordArray;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    72
begin
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    73
    LandPixelRow:= land_pixel_row(gameField, row)
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    74
end;
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
    75
16007
96d0e6149d3d Fix type
unC0Rr
parents: 15928
diff changeset
    76
procedure GenerateTemplatedLand(featureSize: Longword; seed, templateType: shortstring; dataPath: ansistring);
15904
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    77
begin
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    78
    seed[byte(seed[0]) + 1]:= #0;
15905
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
    79
    templateType[byte(templateType[0]) + 1]:= #0;
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
    80
16007
96d0e6149d3d Fix type
unC0Rr
parents: 15928
diff changeset
    81
    gameField:= generate_templated_game_field(featureSize, @seed[1], @templateType[1], PChar(dataPath));
15905
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
    82
    get_game_field_parameters(gameField, LAND_WIDTH, LAND_HEIGHT, playWidth, playHeight);
15904
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    83
15905
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
    84
    MaxHedgehogs:= 32;
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
    85
    hasGirders:= true;
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
    86
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
    87
    leftX:= (LAND_WIDTH - playWidth) div 2;
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
    88
    rightX:= Pred(leftX + playWidth);
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
    89
    topY:= LAND_HEIGHT - playHeight;
15928
772a43d88e6b Fix water level, add medium template
unC0Rr
parents: 15905
diff changeset
    90
    cWaterLine:= LAND_HEIGHT;
15904
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    91
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    92
    // let's assume those are powers of two
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    93
    LAND_WIDTH_MASK:= not(LAND_WIDTH-1);
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    94
    LAND_HEIGHT_MASK:= not(LAND_HEIGHT-1);
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    95
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    96
    SetLength(LandDirty, (LAND_HEIGHT div 32), (LAND_WIDTH div 32));
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    97
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    98
    initScreenSpaceVars();
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    99
end;
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   100
10198
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   101
procedure ResizeLand(width, height: LongWord);
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   102
var potW, potH: LongInt;
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   103
begin
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   104
potW:= toPowerOf2(width);
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   105
potH:= toPowerOf2(height);
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   106
if (potW <> LAND_WIDTH) or (potH <> LAND_HEIGHT) then
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   107
    begin
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   108
    LAND_WIDTH:= potW;
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   109
    LAND_HEIGHT:= potH;
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   110
    LAND_WIDTH_MASK:= not(LAND_WIDTH-1);
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   111
    LAND_HEIGHT_MASK:= not(LAND_HEIGHT-1);
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   112
    cWaterLine:= LAND_HEIGHT;
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   113
15904
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   114
    gameField:= create_empty_game_field(LAND_WIDTH, LAND_HEIGHT);
10198
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   115
    SetLength(LandDirty, (LAND_HEIGHT div 32), (LAND_WIDTH div 32));
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   116
    // 0.5 is already approaching on unplayable
10994
cd7f918eed30 bit friendlier if the uVariables values get changed
nemo
parents: 10626
diff changeset
   117
    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
   118
    cMinMaxZoomLevelDelta:= cMaxZoomLevel - cMinZoomLevel
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   119
    end;
11704
1694b379c83f fix clouds/flakes area not being adjusted after ResizeLand()
sheepluva
parents: 10994
diff changeset
   120
initScreenSpaceVars();
10198
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   121
end;
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   122
15900
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
   123
procedure DisposeLand();
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
   124
begin
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
   125
    dispose_game_field(gameField)
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
   126
end;
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
   127
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
   128
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
   129
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
   130
    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
   131
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
   132
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
   133
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
   134
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
   135
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
   136
15143
794dc7237ca1 Fix world edge positions for drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 12311
diff changeset
   137
// don't change world edges for drawn maps
794dc7237ca1 Fix world edge positions for drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 12311
diff changeset
   138
if (cMapGen = mgDrawn) then
794dc7237ca1 Fix world edge positions for drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 12311
diff changeset
   139
    // edges were adjusted already in GenDrawnMap() in uLand
794dc7237ca1 Fix world edge positions for drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 12311
diff changeset
   140
    EXIT;
794dc7237ca1 Fix world edge positions for drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 12311
diff changeset
   141
12311
1b5a4807f8f4 fix fort mode's edge adjustments getting lost with weWrap. issue #181
sheepluva
parents: 11704
diff changeset
   142
// 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
   143
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
   144
    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
   145
    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
   146
    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
   147
    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
   148
    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
   149
    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
   150
12311
1b5a4807f8f4 fix fort mode's edge adjustments getting lost with weWrap. issue #181
sheepluva
parents: 11704
diff changeset
   151
// 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
   152
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
   153
    begin
1b5a4807f8f4 fix fort mode's edge adjustments getting lost with weWrap. issue #181
sheepluva
parents: 11704
diff changeset
   154
    // 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
   155
    EXIT;
1b5a4807f8f4 fix fort mode's edge adjustments getting lost with weWrap. issue #181
sheepluva
parents: 11704
diff changeset
   156
    end;
1b5a4807f8f4 fix fort mode's edge adjustments getting lost with weWrap. issue #181
sheepluva
parents: 11704
diff changeset
   157
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
   158
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
   159
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
// 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
   161
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
   162
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
   163
    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
   164
    for cy:= ly downto 0 do
15900
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
   165
        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
   166
            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
   167
            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
   168
            // 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
   169
            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
   170
            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
   171
            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
   172
    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
   173
    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
   174
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
// 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
   176
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
   177
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
   178
    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
   179
    for cy:= ly downto 0 do
15900
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 15143
diff changeset
   180
        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
   181
            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
   182
            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
   183
            // 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
   184
            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
   185
            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
   186
            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
   187
    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
   188
    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
   189
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
   190
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
   191
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
   192
10198
e9cbe111c0df Move template-based generator into its own file
unc0rr
parents:
diff changeset
   193
end.