hedgewars/uLandGenMaze.pas
changeset 10387 cb17b79844b5
parent 10189 875607ce793d
child 10389 2f5941a05656
equal deleted inserted replaced
10386:c9e38f8d4f94 10387:cb17b79844b5
     6 
     6 
     7 procedure GenMaze;
     7 procedure GenMaze;
     8 
     8 
     9 implementation
     9 implementation
    10 
    10 
    11 uses uRandom, uLandOutline, uLandTemplates, uVariables, uFloat, uConsts;
    11 uses uRandom, uLandOutline, uLandTemplates, uVariables, uFloat, uConsts, uLandGenTemplateBased;
    12 
    12 
    13 type direction = record x, y: LongInt; end;
    13 type direction = record x, y: LongInt; end;
    14 const DIR_N: direction = (x: 0; y: -1);
    14 const DIR_N: direction = (x: 0; y: -1);
    15     DIR_E: direction = (x: 1; y: 0);
    15     DIR_E: direction = (x: 1; y: 0);
    16     DIR_S: direction = (x: 0; y: 1);
    16     DIR_S: direction = (x: 0; y: 1);
   200         step_done[current_step] := true;
   200         step_done[current_step] := true;
   201     end;
   201     end;
   202 end;
   202 end;
   203 
   203 
   204 procedure add_vertex(x, y: LongInt);
   204 procedure add_vertex(x, y: LongInt);
   205 var tmp_x, tmp_y: LongInt;
   205 var tmp_x, tmp_y, nx, ny: LongInt;
   206 begin
   206 begin
   207 if x = NTPX then
   207     if x = NTPX then
   208 begin
   208     begin
   209     if pa.ar[num_vertices - 6].x = NTPX then
   209         if pa.ar[num_vertices - 6].x = NTPX then
   210     begin
   210         begin
   211         num_vertices := num_vertices - 6;
   211             num_vertices := num_vertices - 6;
       
   212         end
       
   213         else
       
   214         begin
       
   215             pa.ar[num_vertices].x := NTPX;
       
   216             pa.ar[num_vertices].y := 0;
       
   217         end
   212     end
   218     end
   213     else
   219     else
   214     begin
   220     begin
   215         pa.ar[num_vertices].x := NTPX;
   221         if maze_inverted or (x mod 2 = 0) then
   216         pa.ar[num_vertices].y := 0;
   222             tmp_x := cellsize
   217     end
   223         else
   218 end
   224             tmp_x := cellsize * 2 div 3;
   219 else
   225 
   220 begin
   226         if maze_inverted or (y mod 2 = 0) then
   221     if maze_inverted or (x mod 2 = 0) then
   227             tmp_y := cellsize
   222         tmp_x := cellsize
   228         else
   223     else
   229             tmp_y := cellsize * 2 div 3;
   224         tmp_x := cellsize * 2 div 3;
   230 
   225 
   231         nx:= (x-1)*cellsize + tmp_x;
   226     if maze_inverted or (y mod 2 = 0) then
   232         ny:= (y-1)*cellsize + tmp_y + off_y;
   227         tmp_y := cellsize
   233 
   228     else
   234         if num_vertices > 2 then
   229         tmp_y := cellsize * 2 div 3;
   235             if ((pa.ar[num_vertices - 2].x = pa.ar[num_vertices - 1].x) and (pa.ar[num_vertices - 1].x = nx))
   230 
   236                 or ((pa.ar[num_vertices - 2].y = pa.ar[num_vertices - 1].y) and (pa.ar[num_vertices - 1].y = ny))
   231     pa.ar[num_vertices].x := (x-1)*cellsize + tmp_x;
   237                 then
   232     pa.ar[num_vertices].y := (y-1)*cellsize + tmp_y + off_y;
   238                 dec(num_vertices);
   233 end;
   239 
   234 num_vertices := num_vertices + 1;
   240         pa.ar[num_vertices].x := nx;
       
   241         pa.ar[num_vertices].y := ny;
       
   242     end;
       
   243 
       
   244     num_vertices := num_vertices + 1;
   235 end;
   245 end;
   236 
   246 
   237 procedure add_edge(x, y: LongInt; dir: direction);
   247 procedure add_edge(x, y: LongInt; dir: direction);
   238 var i: LongInt;
   248 var i: LongInt;
   239 begin
   249 begin
   263     else if dir = DIR_S then
   273     else if dir = DIR_S then
   264         dir := DIR_W
   274         dir := DIR_W
   265     else
   275     else
   266         dir := DIR_N;
   276         dir := DIR_N;
   267 
   277 
   268 if (dir = DIR_N) and is_x_edge(x, y) then
   278     if (dir = DIR_N) and is_x_edge(x, y) then
   269     begin
   279         begin
   270         x_edge_list[x, y] := false;
   280             x_edge_list[x, y] := false;
   271         add_vertex(x+1, y);
   281             add_vertex(x+1, y);
   272         add_edge(x, y-1, DIR_N);
   282             add_edge(x, y-1, DIR_N);
   273         break;
   283             break;
   274     end;
   284         end;
   275 
   285 
   276 if (dir = DIR_E) and is_y_edge(x+1, y) then
   286     if (dir = DIR_E) and is_y_edge(x+1, y) then
   277     begin
   287         begin
   278         y_edge_list[x+1, y] := false;
   288             y_edge_list[x+1, y] := false;
   279         add_vertex(x+2, y+1);
   289             add_vertex(x+2, y+1);
   280         add_edge(x+1, y, DIR_E);
   290             add_edge(x+1, y, DIR_E);
   281         break;
   291             break;
   282     end;
   292         end;
   283 
   293 
   284 if (dir = DIR_S) and is_x_edge(x, y+1) then
   294     if (dir = DIR_S) and is_x_edge(x, y+1) then
   285     begin
   295         begin
   286         x_edge_list[x, y+1] := false;
   296             x_edge_list[x, y+1] := false;
   287         add_vertex(x+1, y+2);
   297             add_vertex(x+1, y+2);
   288         add_edge(x, y+1, DIR_S);
   298             add_edge(x, y+1, DIR_S);
   289         break;
   299             break;
   290     end;
   300         end;
   291 
   301 
   292 if (dir = DIR_W) and is_y_edge(x, y) then
   302     if (dir = DIR_W) and is_y_edge(x, y) then
   293     begin
   303         begin
   294         y_edge_list[x, y] := false;
   304             y_edge_list[x, y] := false;
   295         add_vertex(x, y+1);
   305             add_vertex(x, y+1);
   296         add_edge(x-1, y, DIR_W);
   306             add_edge(x-1, y, DIR_W);
   297         break;
   307             break;
   298     end;
   308         end;
   299 end;
   309     end;
   300 
   310 
   301 end;
   311 end;
   302 
   312 
   303 procedure GenMaze;
   313 procedure GenMaze;
       
   314 var i: LongInt;
   304 begin
   315 begin
   305 case cTemplateFilter of
   316 case cTemplateFilter of
   306     0: begin
   317     0: begin
   307         cellsize := small_cell_size;
   318         cellsize := small_cell_size;
   308         maze_inverted := false;
   319         maze_inverted := false;
   471             add_vertex(NTPX, 0);
   482             add_vertex(NTPX, 0);
   472             end;
   483             end;
   473 
   484 
   474 pa.count := num_vertices;
   485 pa.count := num_vertices;
   475 
   486 
   476 RandomizePoints(pa);
   487 leftX:= 0;
   477 BezierizeEdge(pa, _0_25);
   488 rightX:= playWidth;
   478 RandomizePoints(pa);
   489 topY:= off_y;
   479 BezierizeEdge(pa, _0_25);
   490 
       
   491 // fill point
       
   492 pa.ar[pa.Count].x:= 1;
       
   493 pa.ar[pa.Count].y:= 1 + off_y;
       
   494 
       
   495 for i:= 0 to pa.Count - 1 do
       
   496     begin
       
   497         system.writeln(pa.ar[i].x, ', ', pa.ar[i].y);
       
   498     end;
       
   499 
       
   500 // divide while it divides
       
   501 repeat
       
   502     i:= pa.Count;
       
   503     DivideEdges(1, pa)
       
   504 until i = pa.Count;
       
   505 
       
   506 // make it smooth
       
   507 BezierizeEdge(pa, _0_2);
   480 
   508 
   481 DrawEdge(pa, 0);
   509 DrawEdge(pa, 0);
   482 
   510 
   483 if maze_inverted then
   511 if maze_inverted then
   484     FillLand(1, 1+off_y, 0, 0)
   512     FillLand(1, 1 + off_y, 0, 0)
   485 else
   513 else
   486     begin
   514     begin
   487     x := 0;
   515     x := 0;
   488     while Land[cellsize div 2 + cellsize + off_y, x] = lfBasic do
   516     while Land[cellsize div 2 + cellsize + off_y, x] = lfBasic do
   489         x := x + 1;
   517         x := x + 1;
   495 MaxHedgehogs:= 32;
   523 MaxHedgehogs:= 32;
   496 if (GameFlags and gfDisableGirders) <> 0 then
   524 if (GameFlags and gfDisableGirders) <> 0 then
   497     hasGirders:= false
   525     hasGirders:= false
   498 else
   526 else
   499     hasGirders := true;
   527     hasGirders := true;
   500 leftX:= 0;
   528 
   501 rightX:= playWidth;
       
   502 topY:= off_y;
       
   503 hasBorder := false;
   529 hasBorder := false;
   504 end;
   530 end;
   505 
   531 
   506 end.
   532 end.