94 void TurnAttach(int32_t &rAttach, int32_t iDirection);
95 void CrawlToAttach(int32_t &rX, int32_t &rY, int32_t iAttach);
96 void CrawlByAttach(int32_t &rX, int32_t &rY, int32_t iAttach, int32_t iDirection);
103 bool CrawlTargetFree(int32_t iX, int32_t iY, int32_t iAttach, int32_t iDirection);
140 int32_t iX,iY,iLastX,iLastY;
219 iLastX=
X2; iLastY=
Y2;
275 uint32_t Color=0xffff0000;
311 C4RGB(0xff, 0xff, 0));
317 int32_t d,dx,dy,aincr,bincr,xincr,yincr,x,y;
319 if (
Abs(iToX-rX)<
Abs(iToY-rY))
321 xincr=(iToX>rX) ? +1 : -1; yincr=(iToY>rY) ? +1 : -1;
322 dy=
Abs(iToY-rY); dx=
Abs(iToX-rX);
323 d=2*dx-dy; aincr=2*(dx-dy); bincr=2*dx; x=rX; y=rY;
324 for (y=rY; y!=iToY; y+=yincr)
336 if (d>=0) { x+=xincr; d+=aincr; }
343 yincr=(iToY>rY) ? +1 : -1; xincr=(iToX>rX) ? +1 : -1;
344 dx=
Abs(iToX-rX); dy=
Abs(iToY-rY);
345 d=2*dy-dx; aincr=2*(dy-dx); bincr=2*dy; x=rX; y=rY;
346 for (x=rX; x!=iToX; x+=xincr)
358 if (d>=0) { y+=yincr; d+=aincr; }
410 for (pRay=
this; pRay->
From; pRay=pRay->
From)
413 for (pRay=
this; pRay->
From; pRay=pRay->
From)
512 for (pRay=
From; pRay; pRay=pRay->
From)
515 if (pRay->
UseZone)
return false;
517 if (pRay==
From)
continue;
523 for (pRay2=
From; pRay2!=pRay; pRay2=pRay2->
From)
553 TransferZones=
nullptr;
554 TransferZonesEnabled=
true;
561 for (pRay=FirstRay; pRay; pRay=pNext) { pNext=pRay->
Next;
delete pRay; }
568 PointFree = fnPointFree;
569 TransferZones = pTransferZones;
574 TransferZonesEnabled = fEnabled;
579 Level =
Clamp(iLevel, 1, 10);
584 if (TransferZones) TransferZones->
Draw(cgo);
588 void C4PathFinder::Run()
590 if (TransferZones) TransferZones->
ClearUsed();
592 while (!Success && Execute()) {}
596 bool C4PathFinder::Execute()
600 bool fContinue=
false;
602 for (
C4PathFinderRay *pRay=FirstRay; pRay && !Success; pRay=pRay->Next,iRays++)
612 static int32_t iDelay=0;
630 if (!fnSetWaypoint)
return false;
631 SetWaypoint=fnSetWaypoint;
634 if (!PointFree(iFromX,iFromY) || !PointFree(iToX,iToY))
return false;
648 bool C4PathFinder::AddRay(int32_t iFromX, int32_t iFromY, int32_t iToX, int32_t iToY, int32_t iDepth, int32_t iDirection,
C4PathFinderRay *pFrom,
C4TransferZone *pUseZone)
655 pRay->
X=iFromX; pRay->
Y=iFromY;
656 pRay->
X2=iFromX; pRay->
Y2=iFromY;
668 bool C4PathFinder::SplitRay(
C4PathFinderRay *pRay, int32_t iAtX, int32_t iAtY)
676 pNewRay->
X=pRay->
X; pNewRay->
Y=pRay->
Y;
677 pNewRay->
X2=iAtX; pNewRay->
Y2=iAtY;
683 pNewRay->
Next=FirstRay;
687 pRay->
X=iAtX; pRay->
Y=iAtY;
C4GraphicsSystem GraphicsSystem
const int32_t C4PF_Ray_Launch
const int32_t C4PF_MaxRay
const int32_t C4PF_Crawl_NoAttach
const int32_t C4PF_Ray_Crawl
const int32_t C4PF_Crawl_Bottom
const int32_t C4PF_Direction_Right
const int32_t C4PF_Ray_Failure
const int32_t C4PF_Draw_Rate
const int32_t C4PF_MaxCrawl
const int32_t C4PF_MaxDepth
const int32_t C4PF_Ray_Still
const int32_t C4PF_Ray_Deleted
const int32_t C4PF_Crawl_Left
const int32_t C4PF_Direction_Left
const int32_t C4PF_Threshold
const int32_t C4PF_Crawl_Right
const int32_t C4PF_Crawl_Top
int32_t Distance(int32_t iX1, int32_t iY1, int32_t iX2, int32_t iY2)
T Clamp(T bval, T lbound, T rbound)
void DrawFrameDw(C4Surface *sfcDest, int x1, int y1, int x2, int y2, DWORD dwClr, float width=1.0f)
void DrawLineDw(C4Surface *sfcTarget, float x1, float y1, float x2, float y2, DWORD dwClr, float width=1.0f)
std::function< bool(int32_t x, int32_t y)> PointFreeFn
void EnableTransferZones(bool fEnabled)
void Init(PointFreeFn fnPointFree, C4TransferZones *pTransferZones=nullptr)
void SetLevel(int iLevel)
void Draw(C4TargetFacet &cgo)
bool Find(int32_t iFromX, int32_t iFromY, int32_t iToX, int32_t iToY, SetWaypointFn fnSetWaypoint)
std::function< bool(int32_t x, int32_t y, C4Object *transfer_object)> SetWaypointFn
bool CrawlTargetFree(int32_t iX, int32_t iY, int32_t iAttach, int32_t iDirection)
void Draw(C4TargetFacet &cgo)
bool CheckBackRayShorten()
int32_t FindCrawlAttach(int32_t iX, int32_t iY)
bool PointFree(int32_t iX, int32_t iY)
void TurnAttach(int32_t &rAttach, int32_t iDirection)
C4PathFinder * pPathFinder
int32_t FindCrawlAttachDiagonal(int32_t iX, int32_t iY, int32_t iDirection)
bool PathFree(int32_t &rX, int32_t &rY, int32_t iToX, int32_t iToY, C4TransferZone **ppZone=nullptr)
bool IsCrawlAttach(int32_t iX, int32_t iY, int32_t iAttach)
void CrawlByAttach(int32_t &rX, int32_t &rY, int32_t iAttach, int32_t iDirection)
void CrawlToAttach(int32_t &rX, int32_t &rY, int32_t iAttach)
bool GetEntryPoint(int32_t &rX, int32_t &rY, int32_t iToX, int32_t iToY)
bool At(int32_t iX, int32_t iY)
void Draw(C4TargetFacet &cgo)
C4TransferZone * Find(C4Object *pObj)