hedgewars/uLandGenMaze.pas
author koda
Fri, 24 Jan 2014 11:11:39 +0100
changeset 10069 c4ad9c76b542
parent 10015 4feced261c68
child 10189 875607ce793d
permissions -rw-r--r--
add AppData file close #706
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
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    11
uses uRandom, uLandOutline, uLandTemplates, uVariables, uFloat, uConsts;
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);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   205
var tmp_x, tmp_y: LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   206
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   207
if x = NTPX then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   208
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   209
    if pa.ar[num_vertices - 6].x = NTPX then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   210
    begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   211
        num_vertices := num_vertices - 6;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   212
    end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   213
    else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   214
    begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   215
        pa.ar[num_vertices].x := NTPX;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   216
        pa.ar[num_vertices].y := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   217
    end
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
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   221
    if maze_inverted or (x mod 2 = 0) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   222
        tmp_x := cellsize
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   223
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   224
        tmp_x := cellsize * 2 div 3;
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
   225
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   226
    if maze_inverted or (y mod 2 = 0) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   227
        tmp_y := cellsize
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   228
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   229
        tmp_y := cellsize * 2 div 3;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   230
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   231
    pa.ar[num_vertices].x := (x-1)*cellsize + tmp_x;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   232
    pa.ar[num_vertices].y := (y-1)*cellsize + tmp_y + off_y;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   233
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   234
num_vertices := num_vertices + 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   235
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   236
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   237
procedure add_edge(x, y: LongInt; dir: direction);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   238
var i: LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   239
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   240
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
   241
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   242
    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
   243
    end
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   244
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
   245
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   246
    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
   247
    end
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   248
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
   249
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   250
    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
   251
    end
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   252
else
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   253
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   254
    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
   255
    end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   256
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   257
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
   258
    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   259
    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
   260
        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
   261
    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
   262
        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
   263
    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
   264
        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
   265
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   266
        dir := DIR_N;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   267
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   268
if (dir = DIR_N) and is_x_edge(x, y) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   269
    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   270
        x_edge_list[x, y] := false;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   271
        add_vertex(x+1, y);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   272
        add_edge(x, y-1, DIR_N);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   273
        break;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   274
    end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   275
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   276
if (dir = DIR_E) and is_y_edge(x+1, y) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   277
    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   278
        y_edge_list[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
   279
        add_vertex(x+2, y+1);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   280
        add_edge(x+1, y, DIR_E);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   281
        break;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   282
    end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   283
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   284
if (dir = DIR_S) and is_x_edge(x, 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
   285
    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   286
        x_edge_list[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
   287
        add_vertex(x+1, y+2);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   288
        add_edge(x, y+1, DIR_S);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   289
        break;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   290
    end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   291
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   292
if (dir = DIR_W) and is_y_edge(x, y) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   293
    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   294
        y_edge_list[x, y] := false;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   295
        add_vertex(x, y+1);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   296
        add_edge(x-1, y, DIR_W);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   297
        break;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   298
    end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   299
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   300
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   301
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   302
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   303
procedure GenMaze;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   304
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   305
case cTemplateFilter of
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   306
    0: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   307
        cellsize := small_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   308
        maze_inverted := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   309
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   310
    1: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   311
        cellsize := medium_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   312
        maze_inverted := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   313
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   314
    2: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   315
        cellsize := large_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   316
        maze_inverted := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   317
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   318
    3: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   319
        cellsize := small_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   320
        maze_inverted := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   321
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   322
    4: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   323
        cellsize := medium_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   324
        maze_inverted := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   325
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   326
    5: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   327
        cellsize := large_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   328
        maze_inverted := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   329
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   330
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   331
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   332
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
   333
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
   334
    num_cells_x := num_cells_x - 1; //needs to be odd
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
   335
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   336
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
   337
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
   338
    num_cells_y := num_cells_y - 1;
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
   339
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   340
num_edges_x := num_cells_x - 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   341
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
   342
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   343
seen_cells_x := num_cells_x div 2;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   344
seen_cells_y := num_cells_y div 2;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   345
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   346
if maze_inverted then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   347
    num_steps := 3 //TODO randomize, between 3 and 5?
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   348
else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   349
    num_steps := 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
SetLength(step_done, num_steps);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   352
SetLength(last_cell, num_steps);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   353
SetLength(came_from_pos, num_steps);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   354
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
   355
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   356
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
   357
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   358
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
   359
begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   360
    step_done[current_step] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   361
    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
   362
end;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
   363
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   364
current_step := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   365
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
SetLength(seen_list, seen_cells_x, seen_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   368
SetLength(xwalls, seen_cells_x, seen_cells_y - 1);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   369
SetLength(ywalls, seen_cells_x - 1, seen_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   370
SetLength(x_edge_list, num_edges_x, num_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   371
SetLength(y_edge_list, num_cells_x, num_edges_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   372
SetLength(maze, num_cells_x, num_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   373
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9127
diff changeset
   374
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   375
num_vertices := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   376
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   377
playHeight := num_cells_y * cellsize;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   378
playWidth := num_cells_x * cellsize;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   379
off_y := LAND_HEIGHT - playHeight;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   380
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   381
for x := 0 to playWidth do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   382
    for y := 0 to off_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   383
        Land[y, x] := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   384
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   385
for x := 0 to playWidth do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   386
    for y := off_y to LAND_HEIGHT - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   387
        Land[y, x] := lfBasic;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   388
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   389
for y := 0 to num_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   390
    for x := 0 to num_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   391
        maze[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   392
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   393
for x := 0 to seen_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   394
    for y := 0 to seen_cells_y - 2 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   395
        xwalls[x, y] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   396
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   397
for x := 0 to seen_cells_x - 2 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   398
    for y := 0 to seen_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   399
        ywalls[x, y] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   400
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   401
for x := 0 to seen_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   402
    for y := 0 to seen_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   403
        seen_list[x, y] := -1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   404
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   405
for x := 0 to num_edges_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   406
    for y := 0 to num_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   407
        x_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   408
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   409
for x := 0 to num_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   410
    for y := 0 to num_edges_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   411
        y_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   412
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   413
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
   414
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   415
    x := GetRandom(seen_cells_x - 1) div LongWord(num_steps);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   416
    last_cell[current_step].x := x + current_step * seen_cells_x div num_steps;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   417
    last_cell[current_step].y := GetRandom(seen_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   418
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   419
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   420
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
   421
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   422
    done := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   423
    for current_step := 0 to num_steps-1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   424
    begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   425
        if not step_done[current_step] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   426
        begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   427
            see_cell;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   428
            done := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   429
        end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   430
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   431
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   432
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   433
for x := 0 to seen_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   434
    for y := 0 to seen_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   435
        if seen_list[x, y] > -1 then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   436
            maze[(x+1)*2-1, (y+1)*2-1] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   437
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   438
for x := 0 to seen_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   439
    for y := 0 to seen_cells_y - 2 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   440
        if not xwalls[x, y] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   441
            maze[x*2 + 1, y*2 + 2] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   442
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 - 2 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 not ywalls[x, y] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   447
            maze[x*2 + 2, y*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 num_edges_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   450
    for y := 0 to num_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   451
        if maze[x, y] xor maze[x+1, y] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   452
            x_edge_list[x, y] := true
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   453
        else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   454
            x_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   455
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   456
for x := 0 to num_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   457
    for y := 0 to num_edges_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   458
        if maze[x, y] xor maze[x, y+1] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   459
            y_edge_list[x, y] := true
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   460
        else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   461
            y_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   462
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   463
for x := 0 to num_edges_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   464
    for y := 0 to num_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   465
        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
   466
            begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   467
            x_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   468
            add_vertex(x+1, y+1);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   469
            add_vertex(x+1, y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   470
            add_edge(x, y-1, DIR_N);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   471
            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
   472
            end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   473
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   474
pa.count := num_vertices;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   475
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   476
RandomizePoints(pa);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   477
BezierizeEdge(pa, _0_25);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   478
RandomizePoints(pa);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   479
BezierizeEdge(pa, _0_25);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   480
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   481
DrawEdge(pa, 0);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   482
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   483
if maze_inverted then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   484
    FillLand(1, 1+off_y)
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   485
else
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   486
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   487
    x := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   488
    while Land[cellsize div 2 + cellsize + off_y, x] = lfBasic do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   489
        x := x + 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   490
    while Land[cellsize div 2 + cellsize + off_y, x] = 0 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   491
        x := x + 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   492
    FillLand(x+1, cellsize div 2 + cellsize + off_y);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   493
    end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   494
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   495
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
   496
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
   497
    hasGirders:= false
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   498
else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   499
    hasGirders := true;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   500
leftX:= 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   501
rightX:= playWidth;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   502
topY:= off_y;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   503
hasBorder := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   504
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   505
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   506
end.