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