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