hedgewars/uLandGenMaze.pas
author unC0Rr
Sat, 21 Dec 2013 01:14:59 +0400
changeset 9809 1e32628eb167
parent 9009 f8e9d1147dd8
child 9127 e350500c4edb
permissions -rw-r--r--
Fix warnings
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
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    20
operator = (const a, b: direction) c: Boolean;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    21
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    22
    c := (a.x = b.x) and (a.y = b.y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    23
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    24
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    25
const small_cell_size = 128;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    26
    medium_cell_size = 192;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    27
    large_cell_size = 256;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    28
    braidness = 10;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    29
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    30
var x, y: LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    31
    cellsize: LongInt; //selected by the user in the gui
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    32
    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
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    33
    num_edges_x, num_edges_y: LongInt; //number of resulting edges that need to be vertexificated
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    34
    num_cells_x, num_cells_y: LongInt; //actual number of cells, depending on cell size
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    35
    seen_list: array of array of LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    36
    xwalls: array of array of Boolean;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    37
    ywalls: array of array of Boolean;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    38
    x_edge_list: array of array of Boolean;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    39
    y_edge_list: array of array of Boolean;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    40
    maze: array of array of Boolean;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    41
    pa: TPixAr;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    42
    num_vertices: LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    43
    off_y: LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    44
    num_steps: LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    45
    current_step: LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    46
    step_done: array of Boolean;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    47
    done: Boolean;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    48
    last_cell: array of record x, y: LongInt; end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    49
    came_from: array of array of record x, y: LongInt; end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    50
    came_from_pos: array of LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    51
    maze_inverted: Boolean;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    52
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    53
function when_seen(x: LongInt; y: LongInt): LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    54
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    55
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
    56
    when_seen := current_step
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    57
else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    58
    when_seen := seen_list[x, y];
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    59
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    60
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    61
function is_x_edge(x, y: LongInt): Boolean;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    62
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    63
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
    64
    is_x_edge := false
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    65
else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    66
    is_x_edge := x_edge_list[x, y];
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    67
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    68
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    69
function is_y_edge(x, y: LongInt): Boolean;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    70
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    71
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
    72
    is_y_edge := false
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    73
else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    74
    is_y_edge := y_edge_list[x, y];
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    75
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    76
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    77
procedure see_cell;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    78
var dir: direction;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    79
    tries: LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    80
    x, y: LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    81
    found_cell: Boolean;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    82
    next_dir_clockwise: Boolean;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    83
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    84
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    85
x := last_cell[current_step].x;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    86
y := last_cell[current_step].y;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    87
seen_list[x, y] := current_step;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    88
case GetRandom(4) of
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    89
    0: dir := DIR_N;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    90
    1: dir := DIR_E;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    91
    2: dir := DIR_S;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    92
    3: dir := DIR_W;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    93
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    94
tries := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    95
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
    96
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
    97
    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
    98
else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
    99
    next_dir_clockwise := false;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   100
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   101
while (tries < 5) and (not found_cell) do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   102
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   103
    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
   104
    begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   105
        //we have already seen the target cell, decide if we should remove the wall anyway
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   106
        //(or put a wall there if maze_inverted, but we are not doing that right now)
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   107
        if not maze_inverted and (GetRandom(braidness) = 0) then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   108
        //or just warn that inverted+braid+indestructible terrain != good idea
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   109
        begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   110
            case dir.x of
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   111
            
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   112
                -1:
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   113
                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
   114
                    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
   115
                1:
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   116
                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
   117
                    ywalls[x, y] := false;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   118
            end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   119
            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
   120
                -1:
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   121
                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
   122
                    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
   123
                1:
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   124
                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
   125
                    xwalls[x, y] := false;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   126
            end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   127
        end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   128
        if next_dir_clockwise then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   129
        begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   130
            if dir = DIR_N then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   131
                dir := DIR_E
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   132
            else if dir = DIR_E then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   133
                dir := DIR_S
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   134
            else if dir = DIR_S then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   135
                dir := DIR_W
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   136
            else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   137
                dir := DIR_N;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   138
        end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   139
        else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   140
        begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   141
            if dir = DIR_N then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   142
                dir := DIR_W
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   143
            else if dir = DIR_E then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   144
                dir := DIR_N
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   145
            else if dir = DIR_S then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   146
                dir := DIR_E
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   147
            else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   148
                dir := DIR_S;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   149
        end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   150
    end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   151
    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
   152
        begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   153
        case dir.y of
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   154
            -1: xwalls[x, y-1] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   155
            1: xwalls[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   156
        end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   157
        case dir.x of
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   158
            -1: ywalls[x-1, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   159
            1: ywalls[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   160
        end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   161
        last_cell[current_step].x := x+dir.x;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   162
        last_cell[current_step].y := y+dir.y;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   163
        came_from_pos[current_step] := came_from_pos[current_step] + 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   164
        came_from[current_step, came_from_pos[current_step]].x := x;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   165
        came_from[current_step, came_from_pos[current_step]].y := y;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   166
        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
   167
        end
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   168
    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
   169
        begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   170
        step_done[current_step] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   171
        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
   172
        end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   173
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   174
    tries := tries + 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   175
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   176
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
   177
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   178
    last_cell[current_step].x := came_from[current_step, came_from_pos[current_step]].x;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   179
    last_cell[current_step].y := came_from[current_step, came_from_pos[current_step]].y;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   180
    came_from_pos[current_step] := came_from_pos[current_step] - 1;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   181
    
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   182
    if came_from_pos[current_step] >= 0 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   183
        see_cell
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   184
        
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   185
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   186
        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
   187
    end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   188
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   189
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   190
procedure add_vertex(x, y: LongInt);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   191
var tmp_x, tmp_y: LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   192
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   193
if x = NTPX then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   194
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   195
    if pa.ar[num_vertices - 6].x = NTPX then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   196
    begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   197
        num_vertices := num_vertices - 6;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   198
    end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   199
    else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   200
    begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   201
        pa.ar[num_vertices].x := NTPX;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   202
        pa.ar[num_vertices].y := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   203
    end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   204
end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   205
else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   206
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   207
    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
   208
        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
   209
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   210
        tmp_x := cellsize * 2 div 3;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   211
        
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   212
    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
   213
        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
   214
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   215
        tmp_y := cellsize * 2 div 3;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   216
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   217
    pa.ar[num_vertices].x := (x-1)*cellsize + tmp_x;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   218
    pa.ar[num_vertices].y := (y-1)*cellsize + tmp_y + off_y;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   219
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   220
num_vertices := num_vertices + 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   221
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   222
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   223
procedure add_edge(x, y: LongInt; dir: direction);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   224
var i: LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   225
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   226
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
   227
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   228
    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
   229
    end
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   230
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
   231
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   232
    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
   233
    end
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   234
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
   235
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   236
    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
   237
    end
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   238
else
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   239
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   240
    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
   241
    end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   242
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   243
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
   244
    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   245
    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
   246
        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
   247
    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
   248
        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
   249
    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
   250
        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
   251
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   252
        dir := DIR_N;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   253
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   254
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
   255
    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   256
        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
   257
        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
   258
        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
   259
        break;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   260
    end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   261
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   262
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
   263
    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   264
        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
   265
        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
   266
        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
   267
        break;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   268
    end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   269
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   270
if (dir = DIR_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
   271
    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   272
        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
   273
        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
   274
        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
   275
        break;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   276
    end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   277
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   278
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
   279
    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   280
        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
   281
        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
   282
        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
   283
        break;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   284
    end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   285
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   286
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   287
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   288
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   289
procedure GenMaze;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   290
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   291
case cTemplateFilter of
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   292
    0: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   293
        cellsize := small_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   294
        maze_inverted := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   295
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   296
    1: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   297
        cellsize := medium_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   298
        maze_inverted := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   299
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   300
    2: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   301
        cellsize := large_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   302
        maze_inverted := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   303
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   304
    3: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   305
        cellsize := small_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   306
        maze_inverted := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   307
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   308
    4: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   309
        cellsize := medium_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   310
        maze_inverted := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   311
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   312
    5: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   313
        cellsize := large_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   314
        maze_inverted := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   315
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   316
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   317
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   318
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
   319
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
   320
    num_cells_x := num_cells_x - 1; //needs to be odd
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   321
    
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   322
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
   323
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
   324
    num_cells_y := num_cells_y - 1;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   325
    
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   326
num_edges_x := num_cells_x - 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   327
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
   328
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   329
seen_cells_x := num_cells_x div 2;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   330
seen_cells_y := num_cells_y div 2;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   331
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   332
if maze_inverted then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   333
    num_steps := 3 //TODO randomize, between 3 and 5?
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   334
else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   335
    num_steps := 1;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   336
    
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   337
SetLength(step_done, num_steps);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   338
SetLength(last_cell, num_steps);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   339
SetLength(came_from_pos, num_steps);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   340
SetLength(came_from, num_steps, num_cells_x*num_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   341
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
   342
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   343
for current_step := 0 to num_steps - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   344
    step_done[current_step] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   345
    came_from_pos[current_step] := 0;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   346
    
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   347
current_step := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   348
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   349
SetLength(seen_list, seen_cells_x, seen_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   350
SetLength(xwalls, seen_cells_x, seen_cells_y - 1);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   351
SetLength(ywalls, seen_cells_x - 1, seen_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   352
SetLength(x_edge_list, num_edges_x, num_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   353
SetLength(y_edge_list, num_cells_x, num_edges_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   354
SetLength(maze, num_cells_x, num_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   355
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   356
num_vertices := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   357
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   358
playHeight := num_cells_y * cellsize;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   359
playWidth := num_cells_x * cellsize;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   360
off_y := LAND_HEIGHT - playHeight;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   361
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   362
for x := 0 to playWidth do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   363
    for y := 0 to off_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   364
        Land[y, x] := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   365
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   366
for x := 0 to playWidth do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   367
    for y := off_y to LAND_HEIGHT - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   368
        Land[y, x] := lfBasic;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   369
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   370
for y := 0 to num_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   371
    for x := 0 to num_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   372
        maze[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   373
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   374
for x := 0 to seen_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   375
    for y := 0 to seen_cells_y - 2 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   376
        xwalls[x, y] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   377
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   378
for x := 0 to seen_cells_x - 2 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   379
    for y := 0 to seen_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   380
        ywalls[x, y] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   381
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   382
for x := 0 to seen_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   383
    for y := 0 to seen_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   384
        seen_list[x, y] := -1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   385
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   386
for x := 0 to num_edges_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   387
    for y := 0 to num_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   388
        x_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   389
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
    for y := 0 to num_edges_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   392
        y_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   393
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   394
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
   395
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   396
    x := GetRandom(seen_cells_x - 1) div LongWord(num_steps);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   397
    last_cell[current_step].x := x + current_step * seen_cells_x div num_steps;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   398
    last_cell[current_step].y := GetRandom(seen_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   399
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   400
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   401
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
   402
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   403
    done := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   404
    for current_step := 0 to num_steps-1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   405
    begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   406
        if not step_done[current_step] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   407
        begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   408
            see_cell;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   409
            done := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   410
        end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   411
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   412
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   413
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   414
for x := 0 to seen_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   415
    for y := 0 to seen_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   416
        if seen_list[x, y] > -1 then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   417
            maze[(x+1)*2-1, (y+1)*2-1] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   418
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   419
for x := 0 to seen_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   420
    for y := 0 to seen_cells_y - 2 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   421
        if not xwalls[x, y] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   422
            maze[x*2 + 1, y*2 + 2] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   423
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   424
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   425
for x := 0 to seen_cells_x - 2 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   426
     for y := 0 to seen_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   427
        if not ywalls[x, y] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   428
            maze[x*2 + 2, y*2 + 1] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   429
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   430
for x := 0 to num_edges_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   431
    for y := 0 to num_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   432
        if maze[x, y] xor maze[x+1, y] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   433
            x_edge_list[x, y] := true
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   434
        else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   435
            x_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   436
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   437
for x := 0 to num_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   438
    for y := 0 to num_edges_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   439
        if maze[x, y] xor maze[x, y+1] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   440
            y_edge_list[x, y] := true
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   441
        else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   442
            y_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   443
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   444
for x := 0 to num_edges_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   445
    for y := 0 to num_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   446
        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
   447
            begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   448
            x_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   449
            add_vertex(x+1, y+1);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   450
            add_vertex(x+1, y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   451
            add_edge(x, y-1, DIR_N);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   452
            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
   453
            end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   454
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   455
pa.count := num_vertices;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   456
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   457
RandomizePoints(pa);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   458
BezierizeEdge(pa, _0_25);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   459
RandomizePoints(pa);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   460
BezierizeEdge(pa, _0_25);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   461
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   462
DrawEdge(pa, 0);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   463
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   464
if maze_inverted then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   465
    FillLand(1, 1+off_y)
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   466
else
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   467
    begin
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   468
    x := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   469
    while Land[cellsize div 2 + cellsize + off_y, x] = lfBasic do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   470
        x := x + 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   471
    while Land[cellsize div 2 + cellsize + off_y, x] = 0 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   472
        x := x + 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   473
    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
   474
    end;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   475
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   476
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
   477
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
   478
    hasGirders:= false
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   479
else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6490
diff changeset
   480
    hasGirders := true;
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   481
leftX:= 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   482
rightX:= playWidth;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   483
topY:= off_y;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   484
hasBorder := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   485
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   486
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   487
end.