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.

538 {
539  Default();
540 }

References Default().

Here is the call graph for this function:

◆ ~C4PathFinder()

C4PathFinder::~C4PathFinder ( )

Definition at line 542 of file C4PathFinder.cpp.

543 {
544  Clear();
545 }

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ Clear()

void C4PathFinder::Clear ( )

Definition at line 558 of file C4PathFinder.cpp.

559 {
560  C4PathFinderRay *pRay,*pNext;
561  for (pRay=FirstRay; pRay; pRay=pNext) { pNext=pRay->Next; delete pRay; }
562  FirstRay=nullptr;
563 }
C4PathFinderRay * Next

References C4PathFinderRay::Next.

Referenced by C4Game::Clear(), Find(), and ~C4PathFinder().

Here is the caller graph for this function:

◆ Default()

void C4PathFinder::Default ( )

Definition at line 547 of file C4PathFinder.cpp.

548 {
549  PointFree=nullptr;
550  SetWaypoint=nullptr;
551  FirstRay=nullptr;
552  Success=false;
553  TransferZones=nullptr;
554  TransferZonesEnabled=true;
555  Level=1;
556 }

Referenced by C4PathFinder(), and C4Game::Default().

Here is the caller graph for this function:

◆ Draw()

void C4PathFinder::Draw ( C4TargetFacet cgo)

Definition at line 582 of file C4PathFinder.cpp.

583 {
584  if (TransferZones) TransferZones->Draw(cgo);
585  for (C4PathFinderRay *pRay=FirstRay; pRay; pRay=pRay->Next) pRay->Draw(cgo);
586 }
void Draw(C4TargetFacet &cgo)

References C4TransferZones::Draw(), and C4PathFinderRay::Next.

Referenced by C4Viewport::Draw().

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.

573 {
574  TransferZonesEnabled = fEnabled;
575 }

Referenced by C4Command::MoveTo().

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.

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

References C4PF_Direction_Left, C4PF_Direction_Right, and Clear().

Referenced by C4Command::MoveTo().

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.

566 {
567  // Set data
568  PointFree = fnPointFree;
569  TransferZones = pTransferZones;
570 }

◆ SetLevel()

void C4PathFinder::SetLevel ( int  iLevel)

Definition at line 577 of file C4PathFinder.cpp.

578 {
579  Level = Clamp(iLevel, 1, 10);
580 }
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:44

References Clamp().

Referenced by C4Command::MoveTo().

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: