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