hedgewars/uLandGenMaze.pas
author unC0Rr
Wed, 15 Feb 2023 12:42:43 +0100
branchtransitional_engine
changeset 15956 c273908218f3
parent 15929 128ace913837
permissions -rw-r--r--
Format the code, apply clippy fixes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9009
f8e9d1147dd8 Ehm... fix 'uLandGenMaze.pas(18,19) Fatal: (2003) Syntax error, ")" expected but "identifier A" found' error encountered by one of the users O_o
unc0rr
parents: 6580
diff changeset
     1
{$INCLUDE "options.inc"}
f8e9d1147dd8 Ehm... fix 'uLandGenMaze.pas(18,19) Fatal: (2003) Syntax error, ")" expected but "identifier A" found' error encountered by one of the users O_o
unc0rr
parents: 6580
diff changeset
     2
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
     3
unit uLandGenMaze;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
     4
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
     5
interface
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
     6
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
     7
procedure GenMaze;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
     8
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
     9
implementation
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    10
15929
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 11051
diff changeset
    11
uses uRandom, uLandOutline, uLandTemplates, uVariables, uFloat, uConsts,
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 11051
diff changeset
    12
     uLandGenTemplateBased, uUtils, uLandUtils;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    13
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    14
type direction = record x, y: LongInt; end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    15
const DIR_N: direction = (x: 0; y: -1);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    16
    DIR_E: direction = (x: 1; y: 0);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    17
    DIR_S: direction = (x: 0; y: 1);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    18
    DIR_W: direction = (x: -1; y: 0);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    19
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    20
operator = (const a, b: direction) c: Boolean;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    21
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    22
    c := (a.x = b.x) and (a.y = b.y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    23
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    24
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    25
const small_cell_size = 128;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    26
    medium_cell_size = 192;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    27
    large_cell_size = 256;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    28
    braidness = 10;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    29
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    30
type
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    31
   cell_t = record x,y         : LongInt
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    32
        end;
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    33
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    34
var x, y               : LongInt;
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    35
    cellsize               : LongInt; //selected by the user in the gui
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    36
    seen_cells_x, seen_cells_y : LongInt; //number of cells that can be visited by the generator, that is every second cell in x and y direction. the cells between there are walls that will be removed when we move from one cell to another
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    37
    num_edges_x, num_edges_y   : LongInt; //number of resulting edges that need to be vertexificated
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    38
    num_cells_x, num_cells_y   : LongInt; //actual number of cells, depending on cell size
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    39
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    40
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    41
    seen_list              : array of array of LongInt;
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    42
    xwalls             : array of array of Boolean;
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    43
    ywalls             : array of array of Boolean;
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    44
    x_edge_list            : array of array of Boolean;
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    45
    y_edge_list            : array of array of Boolean;
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    46
    maze               : array of array of Boolean;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    47
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    48
    pa                 : TPixAr;
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    49
    num_vertices           : LongInt;
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    50
    off_y              : LongInt;
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    51
    num_steps              : LongInt;
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    52
    current_step           : LongInt;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    53
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    54
    step_done              : array of Boolean;
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    55
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    56
    done               : Boolean;
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    57
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    58
{   last_cell              : array 0..3 of record x, y :LongInt ; end;
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    59
    came_from              : array of array of record x, y: LongInt; end;
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    60
    came_from_pos          : array of LongInt;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    61
}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    62
    last_cell : array of cell_t;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    63
    came_from : array of array of cell_t;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    64
    came_from_pos: array of LongInt;
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    65
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
    66
    maze_inverted                      : Boolean;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    67
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    68
function when_seen(x: LongInt; y: LongInt): LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    69
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    70
if (x < 0) or (x >= seen_cells_x) or (y < 0) or (y >= seen_cells_y) then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    71
    when_seen := current_step
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    72
else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    73
    when_seen := seen_list[x, y];
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    74
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    75
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    76
function is_x_edge(x, y: LongInt): Boolean;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    77
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    78
if (x < 0) or (x > num_edges_x) or (y < 0) or (y > num_cells_y) then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    79
    is_x_edge := false
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    80
else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    81
    is_x_edge := x_edge_list[x, y];
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    82
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    83
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    84
function is_y_edge(x, y: LongInt): Boolean;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    85
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    86
if (x < 0) or (x > num_cells_x) or (y < 0) or (y > num_edges_y) then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    87
    is_y_edge := false
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    88
else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    89
    is_y_edge := y_edge_list[x, y];
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    90
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    91
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    92
procedure see_cell;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    93
var dir: direction;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    94
    tries: LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    95
    x, y: LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    96
    found_cell: Boolean;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    97
    next_dir_clockwise: Boolean;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    98
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    99
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   100
x := last_cell[current_step].x;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   101
y := last_cell[current_step].y;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   102
seen_list[x, y] := current_step;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   103
case GetRandom(4) of
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   104
    0: dir := DIR_N;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   105
    1: dir := DIR_E;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   106
    2: dir := DIR_S;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   107
    3: dir := DIR_W;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   108
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   109
tries := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   110
found_cell := false;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   111
if getrandom(2) = 1 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   112
    next_dir_clockwise := true
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   113
else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   114
    next_dir_clockwise := false;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   115
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   116
while (tries < 5) and (not found_cell) do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   117
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   118
    if when_seen(x + dir.x, y + dir.y) = current_step then //we are seeing ourselves, try another direction
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   119
    begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   120
        //we have already seen the target cell, decide if we should remove the wall anyway
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   121
        //(or put a wall there if maze_inverted, but we are not doing that right now)
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
   122
        if (not maze_inverted) and (GetRandom(braidness) = 0) then
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   123
        //or just warn that inverted+braid+indestructible terrain != good idea
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   124
        begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   125
            case dir.x of
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
   126
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   127
                -1:
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   128
                if x > 0 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   129
                    ywalls[x-1, y] := false;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   130
                1:
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   131
                if x < seen_cells_x - 1 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   132
                    ywalls[x, y] := false;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   133
            end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   134
            case dir.y of
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   135
                -1:
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   136
                if y > 0 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   137
                    xwalls[x, y-1] := false;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   138
                1:
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   139
                if y < seen_cells_y - 1 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   140
                    xwalls[x, y] := false;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   141
            end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   142
        end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   143
        if next_dir_clockwise then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   144
        begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   145
            if dir = DIR_N then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   146
                dir := DIR_E
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   147
            else if dir = DIR_E then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   148
                dir := DIR_S
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   149
            else if dir = DIR_S then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   150
                dir := DIR_W
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   151
            else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   152
                dir := DIR_N;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   153
        end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   154
        else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   155
        begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   156
            if dir = DIR_N then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   157
                dir := DIR_W
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   158
            else if dir = DIR_E then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   159
                dir := DIR_N
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   160
            else if dir = DIR_S then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   161
                dir := DIR_E
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   162
            else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   163
                dir := DIR_S;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   164
        end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   165
    end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   166
    else if when_seen(x + dir.x, y + dir.y) = -1 then //cell was not seen yet, go there
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   167
        begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   168
        case dir.y of
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   169
            -1: xwalls[x, y-1] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   170
            1: xwalls[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   171
        end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   172
        case dir.x of
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   173
            -1: ywalls[x-1, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   174
            1: ywalls[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   175
        end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   176
        last_cell[current_step].x := x+dir.x;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   177
        last_cell[current_step].y := y+dir.y;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   178
        came_from_pos[current_step] := came_from_pos[current_step] + 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   179
        came_from[current_step, came_from_pos[current_step]].x := x;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   180
        came_from[current_step, came_from_pos[current_step]].y := y;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   181
        found_cell := true;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   182
        end
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   183
    else //we are seeing someone else, quit
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   184
        begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   185
        step_done[current_step] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   186
        found_cell := true;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   187
        end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   188
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   189
    tries := tries + 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   190
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   191
if not found_cell then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   192
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   193
    last_cell[current_step].x := came_from[current_step, came_from_pos[current_step]].x;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   194
    last_cell[current_step].y := came_from[current_step, came_from_pos[current_step]].y;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   195
    came_from_pos[current_step] := came_from_pos[current_step] - 1;
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
   196
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   197
    if came_from_pos[current_step] >= 0 then
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
   198
        see_cell()
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
   199
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   200
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   201
        step_done[current_step] := true;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   202
    end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   203
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   204
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   205
procedure add_vertex(x, y: LongInt);
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   206
var tmp_x, tmp_y, nx, ny: LongInt;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   207
begin
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   208
    if x = NTPX then
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   209
    begin
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   210
        if pa.ar[num_vertices - 6].x = NTPX then
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   211
        begin
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   212
            num_vertices := num_vertices - 6;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   213
        end
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   214
        else
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   215
        begin
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   216
            pa.ar[num_vertices].x := NTPX;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   217
            pa.ar[num_vertices].y := 0;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   218
        end
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   219
    end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   220
    else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   221
    begin
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   222
        if maze_inverted or (x mod 2 = 0) then
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   223
            tmp_x := cellsize
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   224
        else
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   225
            tmp_x := cellsize * 2 div 3;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   226
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   227
        if maze_inverted or (y mod 2 = 0) then
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   228
            tmp_y := cellsize
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   229
        else
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   230
            tmp_y := cellsize * 2 div 3;
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
   231
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   232
        nx:= (x-1)*cellsize + tmp_x;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   233
        ny:= (y-1)*cellsize + tmp_y + off_y;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   234
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   235
        if num_vertices > 2 then
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   236
            if ((pa.ar[num_vertices - 2].x = pa.ar[num_vertices - 1].x) and (pa.ar[num_vertices - 1].x = nx))
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   237
                or ((pa.ar[num_vertices - 2].y = pa.ar[num_vertices - 1].y) and (pa.ar[num_vertices - 1].y = ny))
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   238
                then
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   239
                dec(num_vertices);
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   240
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   241
        pa.ar[num_vertices].x := nx;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   242
        pa.ar[num_vertices].y := ny;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   243
    end;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   244
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   245
    num_vertices := num_vertices + 1;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   246
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   247
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   248
procedure add_edge(x, y: LongInt; dir: direction);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   249
var i: LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   250
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   251
if dir = DIR_N then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   252
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   253
    dir := DIR_W
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   254
    end
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   255
else if dir = DIR_E then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   256
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   257
    dir := DIR_N
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   258
    end
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   259
else if dir = DIR_S then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   260
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   261
    dir := DIR_E
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   262
    end
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   263
else
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   264
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   265
    dir := DIR_S;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   266
    end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   267
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   268
for i := 0 to 3 do
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   269
    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   270
    if dir = DIR_N then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   271
        dir := DIR_E
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   272
    else if dir = DIR_E then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   273
        dir := DIR_S
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   274
    else if dir = DIR_S then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   275
        dir := DIR_W
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   276
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   277
        dir := DIR_N;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   278
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   279
    if (dir = DIR_N) and is_x_edge(x, y) then
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   280
        begin
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   281
            x_edge_list[x, y] := false;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   282
            add_vertex(x+1, y);
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   283
            add_edge(x, y-1, DIR_N);
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   284
            break;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   285
        end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   286
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   287
    if (dir = DIR_E) and is_y_edge(x+1, y) then
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   288
        begin
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   289
            y_edge_list[x+1, y] := false;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   290
            add_vertex(x+2, y+1);
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   291
            add_edge(x+1, y, DIR_E);
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   292
            break;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   293
        end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   294
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   295
    if (dir = DIR_S) and is_x_edge(x, y+1) then
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   296
        begin
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   297
            x_edge_list[x, y+1] := false;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   298
            add_vertex(x+1, y+2);
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   299
            add_edge(x, y+1, DIR_S);
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   300
            break;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   301
        end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   302
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   303
    if (dir = DIR_W) and is_y_edge(x, y) then
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   304
        begin
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   305
            y_edge_list[x, y] := false;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   306
            add_vertex(x, y+1);
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   307
            add_edge(x-1, y, DIR_W);
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   308
            break;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   309
        end;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   310
    end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   311
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   312
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   313
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   314
procedure GenMaze;
10494
0eb97cf4c78e Fix warnings given by 32-bit fpc
unC0Rr
parents: 10477
diff changeset
   315
var i: Longword;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   316
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   317
case cTemplateFilter of
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   318
    0: begin
11051
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   319
       cellsize := small_cell_size;
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   320
       maze_inverted := false;
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   321
       minDistance:= max(cFeatureSize*8,32);
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   322
       dabDiv:= 150;
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   323
       end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   324
    1: begin
11051
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   325
       cellsize := medium_cell_size;
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   326
       minDistance:= max(cFeatureSize*6,20);
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   327
       maze_inverted := false;
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   328
       dabDiv:= 100;
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   329
       end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   330
    2: begin
11051
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   331
       cellsize := large_cell_size;
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   332
       minDistance:= max(cFeatureSize*5,12);
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   333
       maze_inverted := false;
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   334
       dabDiv:= 90;
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   335
       end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   336
    3: begin
11051
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   337
       cellsize := small_cell_size;
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   338
       minDistance:= max(cFeatureSize*8,32);
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   339
       maze_inverted := true;
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   340
       dabDiv:= 130;
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   341
       end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   342
    4: begin
11051
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   343
       cellsize := medium_cell_size;
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   344
       minDistance:= max(cFeatureSize*6,20);
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   345
       maze_inverted := true;
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   346
       dabDiv:= 100;
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   347
       end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   348
    5: begin
11051
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   349
       cellsize := large_cell_size;
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   350
       minDistance:= max(cFeatureSize*5,12);
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   351
       maze_inverted := true;
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   352
       dabDiv:= 85;
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   353
       end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   354
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   355
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   356
num_cells_x := LAND_WIDTH div cellsize;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   357
if not odd(num_cells_x) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   358
    num_cells_x := num_cells_x - 1; //needs to be odd
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
   359
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   360
num_cells_y := LAND_HEIGHT div cellsize;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   361
if not odd(num_cells_y) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   362
    num_cells_y := num_cells_y - 1;
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
   363
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   364
num_edges_x := num_cells_x - 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   365
num_edges_y := num_cells_y - 1;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   366
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   367
seen_cells_x := num_cells_x div 2;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   368
seen_cells_y := num_cells_y div 2;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   369
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   370
if maze_inverted then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   371
    num_steps := 3 //TODO randomize, between 3 and 5?
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   372
else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   373
    num_steps := 1;
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
   374
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   375
SetLength(step_done, num_steps);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   376
SetLength(last_cell, num_steps);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   377
SetLength(came_from_pos, num_steps);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   378
SetLength(came_from, num_steps, num_cells_x*num_cells_y);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
   379
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   380
done := false;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   381
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   382
for current_step := 0 to num_steps - 1 do
11051
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   383
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   384
    step_done[current_step] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   385
    came_from_pos[current_step] := 0;
11051
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   386
    end;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
   387
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   388
current_step := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   389
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
   390
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   391
SetLength(seen_list, seen_cells_x, seen_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   392
SetLength(xwalls, seen_cells_x, seen_cells_y - 1);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   393
SetLength(ywalls, seen_cells_x - 1, seen_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   394
SetLength(x_edge_list, num_edges_x, num_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   395
SetLength(y_edge_list, num_cells_x, num_edges_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   396
SetLength(maze, num_cells_x, num_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   397
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
   398
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   399
num_vertices := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   400
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   401
playHeight := num_cells_y * cellsize;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   402
playWidth := num_cells_x * cellsize;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   403
off_y := LAND_HEIGHT - playHeight;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   404
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   405
for x := 0 to playWidth do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   406
    for y := 0 to off_y - 1 do
15929
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 11051
diff changeset
   407
        LandSet(y, x, 0);
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   408
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   409
for x := 0 to playWidth do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   410
    for y := off_y to LAND_HEIGHT - 1 do
15929
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 11051
diff changeset
   411
        LandSet(y, x, lfBasic);
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   412
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   413
for y := 0 to num_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   414
    for x := 0 to num_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   415
        maze[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   416
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   417
for x := 0 to seen_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   418
    for y := 0 to seen_cells_y - 2 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   419
        xwalls[x, y] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   420
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   421
for x := 0 to seen_cells_x - 2 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   422
    for y := 0 to seen_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   423
        ywalls[x, y] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   424
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   425
for x := 0 to seen_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   426
    for y := 0 to seen_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   427
        seen_list[x, y] := -1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   428
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   429
for x := 0 to num_edges_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   430
    for y := 0 to num_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   431
        x_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   432
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   433
for x := 0 to num_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   434
    for y := 0 to num_edges_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   435
        y_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   436
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   437
for current_step := 0 to num_steps-1 do
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   438
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   439
    x := GetRandom(seen_cells_x - 1) div LongWord(num_steps);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   440
    last_cell[current_step].x := x + current_step * seen_cells_x div num_steps;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   441
    last_cell[current_step].y := GetRandom(seen_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   442
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   443
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   444
while not done do
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   445
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   446
    done := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   447
    for current_step := 0 to num_steps-1 do
11051
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   448
        begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   449
        if not step_done[current_step] then
11051
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   450
            begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   451
            see_cell;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   452
            done := false;
11051
3996500fd1e5 just some indentation tweaks to help me read this while looking for possible causes of the iOS crasher
nemo
parents: 10501
diff changeset
   453
            end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   454
        end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   455
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   456
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   457
for x := 0 to seen_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   458
    for y := 0 to seen_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   459
        if seen_list[x, y] > -1 then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   460
            maze[(x+1)*2-1, (y+1)*2-1] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   461
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   462
for x := 0 to seen_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   463
    for y := 0 to seen_cells_y - 2 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   464
        if not xwalls[x, y] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   465
            maze[x*2 + 1, y*2 + 2] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   466
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   467
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   468
for x := 0 to seen_cells_x - 2 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   469
     for y := 0 to seen_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   470
        if not ywalls[x, y] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   471
            maze[x*2 + 2, y*2 + 1] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   472
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   473
for x := 0 to num_edges_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   474
    for y := 0 to num_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   475
        if maze[x, y] xor maze[x+1, y] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   476
            x_edge_list[x, y] := true
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   477
        else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   478
            x_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   479
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   480
for x := 0 to num_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   481
    for y := 0 to num_edges_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   482
        if maze[x, y] xor maze[x, y+1] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   483
            y_edge_list[x, y] := true
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   484
        else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   485
            y_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   486
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   487
for x := 0 to num_edges_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   488
    for y := 0 to num_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   489
        if x_edge_list[x, y] then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   490
            begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   491
            x_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   492
            add_vertex(x+1, y+1);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   493
            add_vertex(x+1, y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   494
            add_edge(x, y-1, DIR_N);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   495
            add_vertex(NTPX, 0);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   496
            end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   497
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   498
pa.count := num_vertices;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   499
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   500
leftX:= 0;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   501
rightX:= playWidth;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   502
topY:= off_y;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   503
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   504
// fill point
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   505
pa.ar[pa.Count].x:= 1;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   506
pa.ar[pa.Count].y:= 1 + off_y;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   507
10389
2f5941a05656 comment out some debug output code
sheepluva
parents: 10387
diff changeset
   508
{
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   509
for i:= 0 to pa.Count - 1 do
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   510
    begin
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   511
        system.writeln(pa.ar[i].x, ', ', pa.ar[i].y);
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   512
    end;
10389
2f5941a05656 comment out some debug output code
sheepluva
parents: 10387
diff changeset
   513
}
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   514
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   515
// divide while it divides
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   516
repeat
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   517
    i:= pa.Count;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   518
    DivideEdges(1, pa)
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   519
until i = pa.Count;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   520
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   521
// make it smooth
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   522
BezierizeEdge(pa, _0_2);
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   523
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   524
DrawEdge(pa, 0);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   525
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   526
if maze_inverted then
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   527
    FillLand(1, 1 + off_y, 0, 0)
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   528
else
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   529
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   530
    x := 0;
15929
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 11051
diff changeset
   531
    while LandGet(cellsize div 2 + cellsize + off_y, x) = lfBasic do
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   532
        x := x + 1;
15929
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents: 11051
diff changeset
   533
    while LandGet(cellsize div 2 + cellsize + off_y, x) = 0 do
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   534
        x := x + 1;
10189
875607ce793d - Rework FillLand
unc0rr
parents: 10015
diff changeset
   535
    FillLand(x+1, cellsize div 2 + cellsize + off_y, 0, 0);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   536
    end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   537
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   538
MaxHedgehogs:= 32;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   539
if (GameFlags and gfDisableGirders) <> 0 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   540
    hasGirders:= false
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   541
else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   542
    hasGirders := true;
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   543
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   544
hasBorder := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   545
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   546
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   547
end.