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