GetPathArray
Description:
Calculates path from present position to point with DestX and DestY. Calculated path point will be written to PathArray. Returns path length.
Optimized - not in use, left for compatibility. Use MoveHeuristicMult Accuracy - approaching accuracy: 0 - exactly to destination point, 1 - in area of 1 tiles from destination point, etc. Limited to 1000 tiles. PathArray - founded points array.
This method call GetPathArray3D for calculation.
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.
- moveCheckStamina : Word - minimum stamina for step. If less - step try exit with False as return
- 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()
function GetPathArray(Xdst : Word; Ydst : Word; Optimized : Boolean; Accuracy : Integer; var PathArray : TPathArray) : Integer;
function GetPathArray(Xdst : Word; Ydst : Word; Optimized : Boolean; Accuracy : Integer; var PathArray : TPathArray) : Integer;
function GetPathArray(Xdst : Word; Ydst : Word; Optimized : Boolean; Accuracy : Integer) : TPathArray;
Python Syntax:
def GetPathArray(DestX, DestY, Optimized, Accuracy): -- > list
PPascal 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;
Pascal Example 2:
look module mover3d.pas