UCheckmaze.pas 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. unit UCheckmaze;
  2. interface
  3. uses Unit1;
  4. procedure InitValidate;
  5. procedure Validate(X,Z:Integer; Height:THeight);
  6. var valid:array [-mapsize..mapsize,-mapsize..mapsize,THeight] of Boolean;
  7. var validated:array [-mapsize..mapsize,-mapsize..mapsize,THeight] of Boolean;
  8. var validating:array [-mapsize..mapsize,-mapsize..mapsize,THeight] of Boolean;
  9. implementation
  10. uses UCreateRaum;
  11. procedure InitValidate;
  12. var C1,C2:Integer;
  13. C3: THeight;
  14. begin
  15. for C1:=-mapsize to mapsize do
  16. for C2:=-mapsize to mapsize do
  17. for C3:=Down to Up do begin
  18. valid[C1,C2,C3]:=false;
  19. validated[C1,C2,C3]:=false;
  20. validating[C1,C2,C3]:=false;
  21. end;
  22. end;
  23. function Walkable(FromX,FromZ:Integer; Dir:TRichtung; Height:THeight):Boolean;
  24. begin
  25. Result:=not (
  26. (Dir in Map[FromX,FromZ].Walls)
  27. or ((Dir in Map[FromX,FromZ].UpWalls) and (Height=Up))
  28. or ((Dir in Map[FromX,FromZ].DownWalls) and (Height=Down)));
  29. end;
  30. procedure Validate(X,Z:Integer; Height:THeight);
  31. begin
  32. if not Map[X,Z].created then
  33. CreateRaum(X,Z);
  34. if GetRT(X,Z).PortTo[Up] and (Height=Down) then begin
  35. Height:=Up;
  36. end;
  37. if GetRT(X,Z).PortTo[Up] and (Height=Down) then begin
  38. Height:=Down;
  39. end;
  40. if validating[X,Z,Height] then Exit;
  41. if validated[X,Z,Height] then Exit;
  42. if GetRT(X,Z).WinAtArrival
  43. then begin
  44. valid[X,Z,Height]:=true;
  45. validated[X,Z,Height]:=true;
  46. Exit;
  47. end;
  48. if not GetRT(X,Z).Passierbar then begin
  49. valid[X,Z,Height]:=false;
  50. validated[X,Z,Height]:=true;
  51. Exit;
  52. end;
  53. validating[X,Z,Height]:=true;
  54. if (X<>mapsize)
  55. and Walkable(X,Z,px,Height) then begin
  56. Validate(X+1,Z,Height);
  57. if valid[X+1,Z,Height] then begin
  58. valid[X,Z,Height]:=true;
  59. // validated[X,Z,Height]:=true;
  60. // validating[X,Z,Height]:=false;
  61. // Exit;
  62. end;
  63. end;
  64. if (X<>-mapsize)
  65. and Walkable(X,Z,nx,Height) then begin
  66. Validate(X-1,Z,Height);
  67. if valid[X-1,Z,Height] then begin
  68. valid[X,Z,Height]:=true;
  69. // validated[X,Z,Height]:=true;
  70. // validating[X,Z,Height]:=false;
  71. // Exit;
  72. end;
  73. end;
  74. if (Z<>mapsize)
  75. and Walkable(X,Z,pz,Height) then begin
  76. Validate(X,Z+1,Height);
  77. if valid[X,Z+1,Height] then begin
  78. valid[X,Z,Height]:=true;
  79. // validated[X,Z,Height]:=true;
  80. // validating[X,Z,Height]:=false;
  81. // Exit;
  82. end;
  83. end;
  84. if (Z<>-mapsize)
  85. and Walkable(X,Z,nz,Height) then begin
  86. Validate(X,Z-1,Height);
  87. if valid[X,Z-1,Height] then begin
  88. valid[X,Z,Height]:=true;
  89. // validated[X,Z,Height]:=true;
  90. // validating[X,Z,Height]:=false;
  91. // Exit;
  92. end;
  93. end;
  94. validated[X,Z,Height]:=true;
  95. validating[X,Z,Height]:=false;
  96. Exit;
  97. end;
  98. end.