hedgewars/uLand.pas
changeset 3242 d8adb26ea6a9
parent 3239 ac829895edfc
child 3287 4f7b57ed18b6
equal deleted inserted replaced
3241:6f51f92af8a7 3242:d8adb26ea6a9
    34     hasGirders: boolean;  
    34     hasGirders: boolean;  
    35     isMap: boolean;  
    35     isMap: boolean;  
    36     playHeight, playWidth, leftX, rightX, topY, MaxHedgehogs: Longword;  // idea is that a template can specify height/width.  Or, a map, a height/width by the dimensions of the image.  If the map has pixels near top of image, it triggers border.
    36     playHeight, playWidth, leftX, rightX, topY, MaxHedgehogs: Longword;  // idea is that a template can specify height/width.  Or, a map, a height/width by the dimensions of the image.  If the map has pixels near top of image, it triggers border.
    37     LandBackSurface: PSDL_Surface;
    37     LandBackSurface: PSDL_Surface;
    38 
    38 
    39 type direction = record x, y: Longint; end;
    39 type direction = record x, y: LongInt; end;
    40 const DIR_N: direction = (x: 0; y: -1);
    40 const DIR_N: direction = (x: 0; y: -1);
    41     DIR_E: direction = (x: 1; y: 0);
    41     DIR_E: direction = (x: 1; y: 0);
    42     DIR_S: direction = (x: 0; y: 1);
    42     DIR_S: direction = (x: 0; y: 1);
    43     DIR_W: direction = (x: -1; y: 0);
    43     DIR_W: direction = (x: -1; y: 0);
    44 
    44 
   650 const small_cell_size = 128;
   650 const small_cell_size = 128;
   651     medium_cell_size = 192;
   651     medium_cell_size = 192;
   652     large_cell_size = 256;
   652     large_cell_size = 256;
   653     braidness = 10;
   653     braidness = 10;
   654 
   654 
   655 var x, y: Longint;
   655 var x, y: LongInt;
   656     cellsize: LongInt; //selected by the user in the gui
   656     cellsize: LongInt; //selected by the user in the gui
   657     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
   657     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
   658     num_edges_x, num_edges_y: Longint; //number of resulting edges that need to be vertexificated
   658     num_edges_x, num_edges_y: LongInt; //number of resulting edges that need to be vertexificated
   659     num_cells_x, num_cells_y: Longint; //actual number of cells, depending on cell size
   659     num_cells_x, num_cells_y: LongInt; //actual number of cells, depending on cell size
   660     seen_list: array of array of Longint;
   660     seen_list: array of array of LongInt;
   661     xwalls: array of array of Boolean;
   661     xwalls: array of array of Boolean;
   662     ywalls: array of array of Boolean;
   662     ywalls: array of array of Boolean;
   663     x_edge_list: array of array of Boolean;
   663     x_edge_list: array of array of Boolean;
   664     y_edge_list: array of array of Boolean;
   664     y_edge_list: array of array of Boolean;
   665     maze: array of array of Boolean;
   665     maze: array of array of Boolean;
   666     pa: TPixAr;
   666     pa: TPixAr;
   667     num_vertices: Longint;
   667     num_vertices: LongInt;
   668     off_y: LongInt;
   668     off_y: LongInt;
   669     num_steps: Longint;
   669     num_steps: LongInt;
   670     current_step: Longint;
   670     current_step: LongInt;
   671     step_done: array of Boolean;
   671     step_done: array of Boolean;
   672     done: Boolean;
   672     done: Boolean;
   673     last_cell: array of record x, y: Longint; end;
   673     last_cell: array of record x, y: LongInt; end;
   674     came_from: array of array of record x, y: Longint; end;
   674     came_from: array of array of record x, y: LongInt; end;
   675     came_from_pos: array of Longint;
   675     came_from_pos: array of LongInt;
   676     maze_inverted: Boolean;
   676     maze_inverted: Boolean;
   677 
   677 
   678 function when_seen(x: Longint; y: Longint): Longint;
   678 function when_seen(x: LongInt; y: LongInt): LongInt;
   679 begin
   679 begin
   680 if (x < 0) or (x >= seen_cells_x) or (y < 0) or (y >= seen_cells_y) then
   680 if (x < 0) or (x >= seen_cells_x) or (y < 0) or (y >= seen_cells_y) then
   681     when_seen := current_step
   681     when_seen := current_step
   682 else
   682 else
   683     when_seen := seen_list[x, y];
   683     when_seen := seen_list[x, y];
   684 end;
   684 end;
   685 
   685 
   686 function is_x_edge(x, y: Longint): Boolean;
   686 function is_x_edge(x, y: LongInt): Boolean;
   687 begin
   687 begin
   688 if (x < 0) or (x > num_edges_x) or (y < 0) or (y > num_cells_y) then
   688 if (x < 0) or (x > num_edges_x) or (y < 0) or (y > num_cells_y) then
   689     is_x_edge := false
   689     is_x_edge := false
   690 else
   690 else
   691     is_x_edge := x_edge_list[x, y];
   691     is_x_edge := x_edge_list[x, y];
   692 end;
   692 end;
   693 
   693 
   694 function is_y_edge(x, y: Longint): Boolean;
   694 function is_y_edge(x, y: LongInt): Boolean;
   695 begin
   695 begin
   696 if (x < 0) or (x > num_cells_x) or (y < 0) or (y > num_edges_y) then
   696 if (x < 0) or (x > num_cells_x) or (y < 0) or (y > num_edges_y) then
   697     is_y_edge := false
   697     is_y_edge := false
   698 else
   698 else
   699     is_y_edge := y_edge_list[x, y];
   699     is_y_edge := y_edge_list[x, y];
   700 end;
   700 end;
   701 
   701 
   702 procedure see_cell;
   702 procedure see_cell;
   703 var dir: direction;
   703 var dir: direction;
   704     tries: Longint;
   704     tries: LongInt;
   705     x, y: Longint;
   705     x, y: LongInt;
   706     found_cell: Boolean;
   706     found_cell: Boolean;
   707     next_dir_clockwise: Boolean;
   707     next_dir_clockwise: Boolean;
   708 
   708 
   709 begin
   709 begin
   710 x := last_cell[current_step].x;
   710 x := last_cell[current_step].x;
   795     if came_from_pos[current_step] >= 0 then see_cell
   795     if came_from_pos[current_step] >= 0 then see_cell
   796     else step_done[current_step] := true;
   796     else step_done[current_step] := true;
   797 end;
   797 end;
   798 end;
   798 end;
   799 
   799 
   800 procedure add_vertex(x, y: Longint);
   800 procedure add_vertex(x, y: LongInt);
   801 var tmp_x, tmp_y: Longint;
   801 var tmp_x, tmp_y: LongInt;
   802 begin
   802 begin
   803 if x = NTPX then
   803 if x = NTPX then
   804 begin
   804 begin
   805     if pa.ar[num_vertices - 6].x = NTPX then
   805     if pa.ar[num_vertices - 6].x = NTPX then
   806     begin
   806     begin
   823     pa.ar[num_vertices].y := (y-1)*cellsize + tmp_y + off_y;
   823     pa.ar[num_vertices].y := (y-1)*cellsize + tmp_y + off_y;
   824 end;
   824 end;
   825 num_vertices := num_vertices + 1;
   825 num_vertices := num_vertices + 1;
   826 end;
   826 end;
   827 
   827 
   828 procedure add_edge(x, y: Longint; dir: direction);
   828 procedure add_edge(x, y: LongInt; dir: direction);
   829 var i: Longint;
   829 var i: LongInt;
   830 begin
   830 begin
   831 if dir = DIR_N then
   831 if dir = DIR_N then
   832 begin
   832 begin
   833     dir := DIR_W
   833     dir := DIR_W
   834 end
   834 end
   987     for y := 0 to num_edges_y - 1 do
   987     for y := 0 to num_edges_y - 1 do
   988         y_edge_list[x, y] := false;
   988         y_edge_list[x, y] := false;
   989 
   989 
   990 for current_step := 0 to num_steps-1 do
   990 for current_step := 0 to num_steps-1 do
   991 begin
   991 begin
   992     x := GetRandom(seen_cells_x - 1) div num_steps;
   992     x := GetRandom(seen_cells_x - 1) div LongWord(num_steps);
   993     last_cell[current_step].x := x + current_step * seen_cells_x div num_steps;
   993     last_cell[current_step].x := x + current_step * seen_cells_x div num_steps;
   994     last_cell[current_step].y := GetRandom(seen_cells_y);
   994     last_cell[current_step].y := GetRandom(seen_cells_y);
   995 end;
   995 end;
   996 
   996 
   997 while not done do
   997 while not done do