OpenClonk
C4PathFinder Class Reference

#include <C4PathFinder.h>

Public Types

typedef std::function< bool(int32_t x, int32_t y)> PointFreeFn
 
typedef std::function< bool(int32_t x, int32_t y, C4Object *transfer_object)> SetWaypointFn
 

Public Member Functions

 C4PathFinder ()
 
 ~C4PathFinder ()
 
void Draw (C4TargetFacet &cgo)
 
void Clear ()
 
void Default ()
 
void Init (PointFreeFn fnPointFree, C4TransferZones *pTransferZones=nullptr)
 
bool Find (int32_t iFromX, int32_t iFromY, int32_t iToX, int32_t iToY, SetWaypointFn fnSetWaypoint)
 
void EnableTransferZones (bool fEnabled)
 
void SetLevel (int iLevel)
 

Friends

class C4PathFinderRay
 

Detailed Description

Definition at line 27 of file C4PathFinder.h.

Member Typedef Documentation

◆ PointFreeFn

typedef std::function<bool(int32_t x, int32_t y)> C4PathFinder::PointFreeFn

Definition at line 34 of file C4PathFinder.h.

◆ SetWaypointFn

typedef std::function<bool(int32_t x, int32_t y, C4Object *transfer_object)> C4PathFinder::SetWaypointFn

Definition at line 35 of file C4PathFinder.h.

Constructor & Destructor Documentation

◆ C4PathFinder()

C4PathFinder::C4PathFinder ( )

Definition at line 537 of file C4PathFinder.cpp.

References C4PathFinderRay::Default().

538 {
539  Default();
540 }
Here is the call graph for this function:

◆ ~C4PathFinder()

C4PathFinder::~C4PathFinder ( )

Definition at line 542 of file C4PathFinder.cpp.

References C4PathFinderRay::Clear().

543 {
544  Clear();
545 }
Here is the call graph for this function:

Member Function Documentation

◆ Clear()

void C4PathFinder::Clear ( )

Definition at line 558 of file C4PathFinder.cpp.

References C4PathFinderRay::Next.

Referenced by C4Game::Clear().

559 {
560  C4PathFinderRay *pRay,*pNext;
561  for (pRay=FirstRay; pRay; pRay=pNext) { pNext=pRay->Next; delete pRay; }
562  FirstRay=nullptr;
563 }
C4PathFinderRay * Next
Here is the caller graph for this function:

◆ Default()

void C4PathFinder::Default ( )

Definition at line 547 of file C4PathFinder.cpp.

References C4PathFinderRay::PointFree().

Referenced by C4Game::Default().

548 {
549  PointFree=nullptr;
550  SetWaypoint=nullptr;
551  FirstRay=nullptr;
552  Success=false;
553  TransferZones=nullptr;
554  TransferZonesEnabled=true;
555  Level=1;
556 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Draw()

void C4PathFinder::Draw ( C4TargetFacet cgo)

Definition at line 582 of file C4PathFinder.cpp.

References C4PF_Draw_Rate, C4PF_MaxRay, C4GraphicsSystem::Execute(), C4PathFinderRay::Execute(), GraphicsSystem, C4PathFinderRay::Next, and C4GraphicsSystem::ShowPathfinder.

Referenced by C4Viewport::Draw().

583 {
584  if (TransferZones) TransferZones->Draw(cgo);
585  for (C4PathFinderRay *pRay=FirstRay; pRay; pRay=pRay->Next) pRay->Draw(cgo);
586 }
void Draw(C4TargetFacet &cgo)
C4PathFinderRay * Next
Here is the call graph for this function:
Here is the caller graph for this function:

◆ EnableTransferZones()

void C4PathFinder::EnableTransferZones ( bool  fEnabled)

Definition at line 572 of file C4PathFinder.cpp.

Referenced by C4Command::MoveTo().

573 {
574  TransferZonesEnabled = fEnabled;
575 }
Here is the caller graph for this function:

◆ Find()

bool C4PathFinder::Find ( int32_t  iFromX,
int32_t  iFromY,
int32_t  iToX,
int32_t  iToY,
SetWaypointFn  fnSetWaypoint 
)

Definition at line 623 of file C4PathFinder.cpp.

References C4PF_Direction_Left, C4PF_Direction_Right, C4PF_MaxDepth, C4PF_Ray_Still, C4PathFinderRay::Clear(), C4PathFinderRay::Depth, C4PathFinderRay::Direction, C4PathFinderRay::From, C4PathFinderRay::Next, C4PathFinderRay::PointFree(), C4PathFinderRay::pPathFinder, C4PathFinderRay::Status, C4PathFinderRay::TargetX, C4PathFinderRay::TargetY, C4PathFinderRay::UseZone, C4PathFinderRay::X, C4PathFinderRay::X2, C4PathFinderRay::Y, and C4PathFinderRay::Y2.

Referenced by C4Command::MoveTo().

624 {
625 
626  // Prepare
627  Clear();
628 
629  // Parameter safety
630  if (!fnSetWaypoint) return false;
631  SetWaypoint=fnSetWaypoint;
632 
633  // Start & target coordinates must be free
634  if (!PointFree(iFromX,iFromY) || !PointFree(iToX,iToY)) return false;
635 
636  // Add the first two rays
637  if (!AddRay(iFromX,iFromY,iToX,iToY,0,C4PF_Direction_Left,nullptr)) return false;
638  if (!AddRay(iFromX,iFromY,iToX,iToY,0,C4PF_Direction_Right,nullptr)) return false;
639 
640  // Run
641  Run();
642 
643  // Success
644  return Success;
645 
646 }
const int32_t C4PF_Direction_Right
const int32_t C4PF_Direction_Left
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Init()

void C4PathFinder::Init ( PointFreeFn  fnPointFree,
C4TransferZones pTransferZones = nullptr 
)

Definition at line 565 of file C4PathFinder.cpp.

References C4PathFinderRay::PointFree().

566 {
567  // Set data
568  PointFree = fnPointFree;
569  TransferZones = pTransferZones;
570 }
Here is the call graph for this function:

◆ SetLevel()

void C4PathFinder::SetLevel ( int  iLevel)

Definition at line 577 of file C4PathFinder.cpp.

References Clamp().

Referenced by C4Command::MoveTo().

578 {
579  Level = Clamp(iLevel, 1, 10);
580 }
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:44
Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ C4PathFinderRay

friend class C4PathFinderRay
friend

Definition at line 29 of file C4PathFinder.h.


The documentation for this class was generated from the following files: