hedgewars/uLandGenMaze.pas
author koda
Sun, 04 Dec 2011 18:53:49 +0100
changeset 6495 48acc6111b87
parent 6490 531bf083e8db
child 6580 6155187bf599
permissions -rw-r--r--
audio mono is back
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;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    94
if getrandom(2) = 1 then next_dir_clockwise := true
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    95
else next_dir_clockwise := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    96
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    97
while (tries < 5) and (not found_cell) do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    98
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
    99
    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
   100
    begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   101
        //we have already seen the target cell, decide if we should remove the wall anyway
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   102
        //(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
   103
        if not maze_inverted and (GetRandom(braidness) = 0) then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   104
        //or just warn that inverted+braid+indestructible terrain != good idea
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   105
        begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   106
            case dir.x of
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   107
                -1: if x > 0 then ywalls[x-1, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   108
                1: if x < seen_cells_x - 1 then ywalls[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   109
            end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   110
            case dir.y of
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   111
                -1: if y > 0 then xwalls[x, y-1] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   112
                1: if y < seen_cells_y - 1 then xwalls[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   113
            end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   114
        end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   115
        if next_dir_clockwise then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   116
        begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   117
            if dir = DIR_N then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   118
                dir := DIR_E
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   119
            else if dir = DIR_E then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   120
                dir := DIR_S
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   121
            else if dir = DIR_S then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   122
                dir := DIR_W
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   123
            else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   124
                dir := DIR_N;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   125
        end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   126
        else
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_W
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_N
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_E
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   134
            else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   135
                dir := DIR_S;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   136
        end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   137
    end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   138
    else if when_seen(x + dir.x, y + dir.y) = -1 then //cell was not seen yet, go there
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   139
    begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   140
        case dir.y of
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   141
            -1: xwalls[x, y-1] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   142
            1: xwalls[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   143
        end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   144
        case dir.x of
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   145
            -1: ywalls[x-1, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   146
            1: ywalls[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   147
        end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   148
        last_cell[current_step].x := x+dir.x;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   149
        last_cell[current_step].y := y+dir.y;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   150
        came_from_pos[current_step] := came_from_pos[current_step] + 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   151
        came_from[current_step, came_from_pos[current_step]].x := x;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   152
        came_from[current_step, came_from_pos[current_step]].y := y;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   153
        found_cell := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   154
    end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   155
    else //we are seeing someone else, quit
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   156
    begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   157
        step_done[current_step] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   158
        found_cell := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   159
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   160
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   161
    tries := tries + 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   162
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   163
if not found_cell then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   164
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   165
    last_cell[current_step].x := came_from[current_step, came_from_pos[current_step]].x;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   166
    last_cell[current_step].y := came_from[current_step, came_from_pos[current_step]].y;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   167
    came_from_pos[current_step] := came_from_pos[current_step] - 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   168
    if came_from_pos[current_step] >= 0 then see_cell
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   169
    else step_done[current_step] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   170
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   171
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   172
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   173
procedure add_vertex(x, y: LongInt);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   174
var tmp_x, tmp_y: LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   175
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   176
if x = NTPX then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   177
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   178
    if pa.ar[num_vertices - 6].x = NTPX then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   179
    begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   180
        num_vertices := num_vertices - 6;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   181
    end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   182
    else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   183
    begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   184
        pa.ar[num_vertices].x := NTPX;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   185
        pa.ar[num_vertices].y := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   186
    end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   187
end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   188
else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   189
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   190
    if maze_inverted or (x mod 2 = 0) then tmp_x := cellsize
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   191
    else tmp_x := cellsize * 2 div 3;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   192
    if maze_inverted or (y mod 2 = 0) then tmp_y := cellsize
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   193
    else tmp_y := cellsize * 2 div 3;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   194
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   195
    pa.ar[num_vertices].x := (x-1)*cellsize + tmp_x;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   196
    pa.ar[num_vertices].y := (y-1)*cellsize + tmp_y + off_y;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   197
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   198
num_vertices := num_vertices + 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   199
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   200
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   201
procedure add_edge(x, y: LongInt; dir: direction);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   202
var i: LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   203
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   204
if dir = DIR_N then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   205
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   206
    dir := DIR_W
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   207
end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   208
else if dir = DIR_E then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   209
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   210
    dir := DIR_N
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   211
end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   212
else if dir = DIR_S then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   213
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   214
    dir := DIR_E
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   215
end
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   216
else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   217
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   218
    dir := DIR_S;
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
for i := 0 to 3 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   222
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   223
        if dir = DIR_N then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   224
            dir := DIR_E
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   225
        else if dir = DIR_E then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   226
            dir := DIR_S
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   227
        else if dir = DIR_S then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   228
            dir := DIR_W
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   229
        else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   230
            dir := DIR_N;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   231
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   232
    if (dir = DIR_N) and is_x_edge(x, y) then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   233
        begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   234
            x_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   235
            add_vertex(x+1, y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   236
            add_edge(x, y-1, DIR_N);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   237
            break;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   238
        end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   239
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   240
    if (dir = DIR_E) and is_y_edge(x+1, y) then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   241
        begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   242
            y_edge_list[x+1, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   243
            add_vertex(x+2, y+1);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   244
            add_edge(x+1, y, DIR_E);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   245
            break;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   246
        end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   247
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   248
    if (dir = DIR_S) and is_x_edge(x, y+1) then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   249
        begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   250
            x_edge_list[x, y+1] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   251
            add_vertex(x+1, y+2);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   252
            add_edge(x, y+1, DIR_S);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   253
            break;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   254
        end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   255
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   256
    if (dir = DIR_W) and is_y_edge(x, y) then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   257
        begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   258
            y_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   259
            add_vertex(x, y+1);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   260
            add_edge(x-1, y, DIR_W);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   261
            break;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   262
        end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   263
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   264
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   265
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   266
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   267
procedure GenMaze;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   268
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   269
case cTemplateFilter of
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   270
    0: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   271
        cellsize := small_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   272
        maze_inverted := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   273
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   274
    1: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   275
        cellsize := medium_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   276
        maze_inverted := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   277
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   278
    2: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   279
        cellsize := large_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   280
        maze_inverted := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   281
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   282
    3: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   283
        cellsize := small_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   284
        maze_inverted := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   285
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   286
    4: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   287
        cellsize := medium_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   288
        maze_inverted := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   289
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   290
    5: begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   291
        cellsize := large_cell_size;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   292
        maze_inverted := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   293
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   294
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   295
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   296
num_cells_x := LAND_WIDTH div cellsize;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   297
if not odd(num_cells_x) then num_cells_x := num_cells_x - 1; //needs to be odd
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   298
num_cells_y := LAND_HEIGHT div cellsize;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   299
if not odd(num_cells_y) then num_cells_y := num_cells_y - 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   300
num_edges_x := num_cells_x - 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   301
num_edges_y := num_cells_y - 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   302
seen_cells_x := num_cells_x div 2;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   303
seen_cells_y := num_cells_y div 2;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   304
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   305
if maze_inverted then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   306
    num_steps := 3 //TODO randomize, between 3 and 5?
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   307
else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   308
    num_steps := 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   309
SetLength(step_done, num_steps);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   310
SetLength(last_cell, num_steps);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   311
SetLength(came_from_pos, num_steps);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   312
SetLength(came_from, num_steps, num_cells_x*num_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   313
done := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   314
for current_step := 0 to num_steps - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   315
    step_done[current_step] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   316
    came_from_pos[current_step] := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   317
current_step := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   318
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   319
SetLength(seen_list, seen_cells_x, seen_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   320
SetLength(xwalls, seen_cells_x, seen_cells_y - 1);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   321
SetLength(ywalls, seen_cells_x - 1, seen_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   322
SetLength(x_edge_list, num_edges_x, num_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   323
SetLength(y_edge_list, num_cells_x, num_edges_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   324
SetLength(maze, num_cells_x, num_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   325
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   326
num_vertices := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   327
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   328
playHeight := num_cells_y * cellsize;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   329
playWidth := num_cells_x * cellsize;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   330
off_y := LAND_HEIGHT - playHeight;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   331
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   332
for x := 0 to playWidth do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   333
    for y := 0 to off_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   334
        Land[y, x] := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   335
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   336
for x := 0 to playWidth do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   337
    for y := off_y to LAND_HEIGHT - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   338
        Land[y, x] := lfBasic;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   339
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   340
for y := 0 to num_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   341
    for x := 0 to num_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   342
        maze[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   343
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   344
for x := 0 to seen_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   345
    for y := 0 to seen_cells_y - 2 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   346
        xwalls[x, y] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   347
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   348
for x := 0 to seen_cells_x - 2 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   349
    for y := 0 to seen_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   350
        ywalls[x, y] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   351
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   352
for x := 0 to seen_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   353
    for y := 0 to seen_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   354
        seen_list[x, y] := -1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   355
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   356
for x := 0 to num_edges_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   357
    for y := 0 to num_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   358
        x_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   359
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   360
for x := 0 to num_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   361
    for y := 0 to num_edges_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   362
        y_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   363
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   364
for current_step := 0 to num_steps-1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   365
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   366
    x := GetRandom(seen_cells_x - 1) div LongWord(num_steps);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   367
    last_cell[current_step].x := x + current_step * seen_cells_x div num_steps;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   368
    last_cell[current_step].y := GetRandom(seen_cells_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   369
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   370
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   371
while not done do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   372
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   373
    done := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   374
    for current_step := 0 to num_steps-1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   375
    begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   376
        if not step_done[current_step] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   377
        begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   378
            see_cell;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   379
            done := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   380
        end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   381
    end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   382
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   383
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   384
for x := 0 to seen_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   385
    for y := 0 to seen_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   386
        if seen_list[x, y] > -1 then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   387
            maze[(x+1)*2-1, (y+1)*2-1] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   388
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   389
for x := 0 to seen_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   390
    for y := 0 to seen_cells_y - 2 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   391
        if not xwalls[x, y] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   392
            maze[x*2 + 1, y*2 + 2] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   393
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   394
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   395
for x := 0 to seen_cells_x - 2 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   396
     for y := 0 to seen_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   397
        if not ywalls[x, y] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   398
            maze[x*2 + 2, y*2 + 1] := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   399
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   400
for x := 0 to num_edges_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   401
    for y := 0 to num_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   402
        if maze[x, y] xor maze[x+1, y] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   403
            x_edge_list[x, y] := true
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   404
        else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   405
            x_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   406
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   407
for x := 0 to num_cells_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   408
    for y := 0 to num_edges_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   409
        if maze[x, y] xor maze[x, y+1] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   410
            y_edge_list[x, y] := true
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   411
        else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   412
            y_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   413
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   414
for x := 0 to num_edges_x - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   415
    for y := 0 to num_cells_y - 1 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   416
        if x_edge_list[x, y] then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   417
        begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   418
            x_edge_list[x, y] := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   419
            add_vertex(x+1, y+1);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   420
            add_vertex(x+1, y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   421
            add_edge(x, y-1, DIR_N);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   422
            add_vertex(NTPX, 0);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   423
        end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   424
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   425
pa.count := num_vertices;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   426
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   427
RandomizePoints(pa);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   428
BezierizeEdge(pa, _0_25);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   429
RandomizePoints(pa);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   430
BezierizeEdge(pa, _0_25);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   431
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   432
DrawEdge(pa, 0);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   433
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   434
if maze_inverted then
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   435
    FillLand(1, 1+off_y)
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   436
else
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   437
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   438
    x := 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   439
    while Land[cellsize div 2 + cellsize + off_y, x] = lfBasic do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   440
        x := x + 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   441
    while Land[cellsize div 2 + cellsize + off_y, x] = 0 do
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   442
        x := x + 1;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   443
    FillLand(x+1, cellsize div 2 + cellsize + off_y);
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   444
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   445
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   446
MaxHedgehogs:= 32;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   447
if (GameFlags and gfDisableGirders) <> 0 then hasGirders:= false
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   448
else hasGirders := true;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   449
leftX:= 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   450
rightX:= playWidth;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   451
topY:= off_y;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   452
hasBorder := false;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   453
end;
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   454
531bf083e8db - Give uLand more modularity
unc0rr
parents:
diff changeset
   455
end.