IsWorldCellPassable
Description:
Check possibility to step from point with X CurrX, Y CurrY and Z CuzzZ to point with X DestX, Y DestY and Z DestZ in the word WorldNum
NB: Param DestZ is variable in Pascal and contains predicted value of Z in destination point. In Python it returns as 2nd return value.
Related variables (not parameters, thats independent variables):
- moveOpenDoor : Boolean - mover check if door can be opened. Default False, means doors and obstructions and cannot be passable.
- moveThroughNPC : Word - Minimum of stamina need to walk through NPC. Default 1000, mean almost impossible. Than 0 - than easier. 0 - means walk through npc without limits.
- moveBetweenTwoCorners : Boolean - Try to pass between two obstructions corners with diagonal direction
- moveThroughCorner : Boolean - Try to pass with obstructions corner with diagonal direction
NB: In Python those variables defined as methods, f.e. SetMoveOpenDoor(Value) and GetMoveOpenDoor()
Pascal
function IsWorldCellPassable(CurrX : Word; CurrY : Word; CurrZ : ShortInt; DestX : Word; DestY : Word; var DestZ : ShortInt; WorldNum : Byte) : Boolean;
Python Syntax:
def IsWorldCellPassable(CurrX, CurrY, CurrZ, DestX, DestY, WorldNum): -- > bool, shortint
Pascal Example:
function MoveToPoint(X,Y: Integer; Running: Boolean) : boolean;
var
remap : array [0..8] of byte;
dx,dy,dir,StepResult : Integer;
Begin
remap[0] := 7;
remap[1] := 6;
remap[2] := 5;
remap[3] := 0 ;
remap[4] := -1;
remap[5] := 4;
remap[6] := 1;
remap[7] := 2;
remap[8] := 3;
Result:=false;
While true do
begin
dx:=X-getX(self); dy:=Y-getY(self);
If (dx=0) AND (dy=0) then
begin
Result:=true;
Exit;
end;
dx:=sign(dx);
dy:=sign(dy);
dir := remap[(dx + 1)*3 + dy + 1];
// AddToSystemJournal('1');
If GetDirection(self) <> dir then StepQ(dir, Running);
// AddToSystemJournal('2');
StepResult:=StepQ(dir,Running);
// AddToSystemJournal('3');
If (StepResult=1) OR (StepResult=5) then Wait(5000);
If StepResult<7 then
begin
result:=false;
Exit;
end;
end;
End;
function easyMoveXY(X,Y: integer; Optimized: boolean; Accuracy : Integer; Running: boolean): boolean;
var
StepCnt,i : Integer;
mPathArr : TPathArray;
Begin
Result:=false;
moveThroughNPC := True;
While true do
begin
''AddToSystemJournal('pathfinding...')
StepCnt:=GetPathArray(X,Y,Optimized,Accuracy,mPathArr);
If StepCnt<0 then Exit;
If StepCnt=0 then
begin
Result:= true;
Exit;
end;
For i:=0 to StepCnt do
begin
If Not IsWorldCellPassable(getX(self),getY(self),mPathArr[i].X,mPathArr[i].Y,WorldNum,getZ(self)) then Break;
If Not MoveToPoint(mPathArr[i].X,mPathArr[i].Y,Running) then Break;
If Dist(X,Y)<=Accuracy then
begin
AddToSystemJournal('Location reached!');
Result:=true;
Exit;
end;
end;
end;
End;