hedgewars/uLandGenMaze.pas
author nemo
Fri, 26 Sep 2014 22:20:12 -0400
changeset 10413 afd746a538ef
parent 10389 2f5941a05656
child 10477 b219c5a2317f
permissions -rw-r--r--
climb home training/multiplayer
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
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
    11
uses uRandom, uLandOutline, uLandTemplates, uVariables, uFloat, uConsts, uLandGenTemplateBased;
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;
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   314
var i: LongInt;
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
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   318
        cellsize := small_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   319
        maze_inverted := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   320
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   321
    1: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   322
        cellsize := medium_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   323
        maze_inverted := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   324
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   325
    2: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   326
        cellsize := large_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   327
        maze_inverted := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   328
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   329
    3: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   330
        cellsize := small_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   331
        maze_inverted := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   332
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   333
    4: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   334
        cellsize := medium_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   335
        maze_inverted := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   336
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   337
    5: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   338
        cellsize := large_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   339
        maze_inverted := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   340
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   341
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   342
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   343
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
   344
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
   345
    num_cells_x := num_cells_x - 1; //needs to be odd
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
   346
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   347
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
   348
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
   349
    num_cells_y := num_cells_y - 1;
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
   350
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   351
num_edges_x := num_cells_x - 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   352
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
   353
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   354
seen_cells_x := num_cells_x div 2;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   355
seen_cells_y := num_cells_y div 2;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   356
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   357
if maze_inverted then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   358
    num_steps := 3 //TODO randomize, between 3 and 5?
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   359
else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   360
    num_steps := 1;
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
   361
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   362
SetLength(step_done, num_steps);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   363
SetLength(last_cell, num_steps);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   364
SetLength(came_from_pos, num_steps);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   365
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
   366
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   367
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
   368
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   369
for current_step := 0 to num_steps - 1 do
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
   370
begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   371
    step_done[current_step] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   372
    came_from_pos[current_step] := 0;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
   373
end;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
   374
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   375
current_step := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   376
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
   377
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   378
SetLength(seen_list, seen_cells_x, seen_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   379
SetLength(xwalls, seen_cells_x, seen_cells_y - 1);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   380
SetLength(ywalls, seen_cells_x - 1, seen_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   381
SetLength(x_edge_list, num_edges_x, num_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   382
SetLength(y_edge_list, num_cells_x, num_edges_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   383
SetLength(maze, num_cells_x, num_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   384
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
   385
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   386
num_vertices := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   387
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   388
playHeight := num_cells_y * cellsize;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   389
playWidth := num_cells_x * cellsize;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   390
off_y := LAND_HEIGHT - playHeight;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   391
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   392
for x := 0 to playWidth do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   393
    for y := 0 to off_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   394
        Land[y, x] := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   395
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   396
for x := 0 to playWidth do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   397
    for y := off_y to LAND_HEIGHT - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   398
        Land[y, x] := lfBasic;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   399
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   400
for y := 0 to num_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   401
    for x := 0 to num_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   402
        maze[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   403
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   404
for x := 0 to seen_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   405
    for y := 0 to seen_cells_y - 2 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   406
        xwalls[x, y] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   407
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   408
for x := 0 to seen_cells_x - 2 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   409
    for y := 0 to seen_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   410
        ywalls[x, y] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   411
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   412
for x := 0 to seen_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   413
    for y := 0 to seen_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   414
        seen_list[x, y] := -1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   415
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   416
for x := 0 to num_edges_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   417
    for y := 0 to num_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   418
        x_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   419
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   420
for x := 0 to num_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   421
    for y := 0 to num_edges_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   422
        y_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   423
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   424
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
   425
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   426
    x := GetRandom(seen_cells_x - 1) div LongWord(num_steps);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   427
    last_cell[current_step].x := x + current_step * seen_cells_x div num_steps;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   428
    last_cell[current_step].y := GetRandom(seen_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   429
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   430
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   431
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
   432
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   433
    done := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   434
    for current_step := 0 to num_steps-1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   435
    begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   436
        if not step_done[current_step] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   437
        begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   438
            see_cell;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   439
            done := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   440
        end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   441
    end;
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
for x := 0 to seen_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   445
    for y := 0 to seen_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   446
        if seen_list[x, y] > -1 then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   447
            maze[(x+1)*2-1, (y+1)*2-1] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   448
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   449
for x := 0 to seen_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   450
    for y := 0 to seen_cells_y - 2 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   451
        if not xwalls[x, y] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   452
            maze[x*2 + 1, y*2 + 2] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   453
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   454
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   455
for x := 0 to seen_cells_x - 2 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   456
     for y := 0 to seen_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   457
        if not ywalls[x, y] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   458
            maze[x*2 + 2, y*2 + 1] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   459
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   460
for x := 0 to num_edges_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   461
    for y := 0 to num_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   462
        if maze[x, y] xor maze[x+1, y] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   463
            x_edge_list[x, y] := true
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   464
        else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   465
            x_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   466
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   467
for x := 0 to num_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   468
    for y := 0 to num_edges_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   469
        if maze[x, y] xor maze[x, y+1] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   470
            y_edge_list[x, y] := true
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   471
        else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   472
            y_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   473
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   474
for x := 0 to num_edges_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   475
    for y := 0 to num_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   476
        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
   477
            begin
6490
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
            add_vertex(x+1, y+1);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   480
            add_vertex(x+1, y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   481
            add_edge(x, y-1, DIR_N);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   482
            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
   483
            end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   484
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   485
pa.count := num_vertices;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   486
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   487
leftX:= 0;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   488
rightX:= playWidth;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   489
topY:= off_y;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   490
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   491
// fill point
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   492
pa.ar[pa.Count].x:= 1;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   493
pa.ar[pa.Count].y:= 1 + off_y;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   494
10389
2f5941a05656 comment out some debug output code
sheepluva
parents: 10387
diff changeset
   495
{
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   496
for i:= 0 to pa.Count - 1 do
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   497
    begin
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   498
        system.writeln(pa.ar[i].x, ', ', pa.ar[i].y);
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   499
    end;
10389
2f5941a05656 comment out some debug output code
sheepluva
parents: 10387
diff changeset
   500
}
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   501
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   502
// divide while it divides
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   503
repeat
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   504
    i:= pa.Count;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   505
    DivideEdges(1, pa)
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   506
until i = pa.Count;
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   507
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   508
// make it smooth
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   509
BezierizeEdge(pa, _0_2);
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   510
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   511
DrawEdge(pa, 0);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   512
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   513
if maze_inverted then
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   514
    FillLand(1, 1 + off_y, 0, 0)
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   515
else
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   516
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   517
    x := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   518
    while Land[cellsize div 2 + cellsize + off_y, x] = lfBasic do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   519
        x := x + 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   520
    while Land[cellsize div 2 + cellsize + off_y, x] = 0 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   521
        x := x + 1;
10189
875607ce793d - Rework FillLand
unc0rr
parents: 10015
diff changeset
   522
    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
   523
    end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   524
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   525
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
   526
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
   527
    hasGirders:= false
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   528
else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   529
    hasGirders := true;
10387
cb17b79844b5 Apply new distortion on maze gen
unc0rr
parents: 10189
diff changeset
   530
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   531
hasBorder := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   532
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   533
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   534
end.