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