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