OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4PathFinder.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Finds the way through the Clonk landscape */
19 
20 #ifndef INC_C4PathFinder
21 #define INC_C4PathFinder
22 
23 #include <functional>
24 
25 class C4Object;
26 class C4PathFinderRay;
28 {
29  friend class C4PathFinderRay;
30 public:
31  C4PathFinder();
32  ~C4PathFinder();
33 
34  typedef std::function<bool(int32_t x, int32_t y)> PointFreeFn;
35  typedef std::function<bool(int32_t x, int32_t y, C4Object *transfer_object)> SetWaypointFn;
36 
37  void Draw(C4TargetFacet &cgo);
38  void Clear();
39  void Default();
40  void Init(PointFreeFn fnPointFree, C4TransferZones* pTransferZones=nullptr);
41  bool Find(int32_t iFromX, int32_t iFromY, int32_t iToX, int32_t iToY, SetWaypointFn fnSetWaypoint);
42  void EnableTransferZones(bool fEnabled);
43  void SetLevel(int iLevel);
44 
45 private:
46  void Run();
47  bool AddRay(int32_t iFromX, int32_t iFromY, int32_t iToX, int32_t iToY, int32_t iDepth, int32_t iDirection, C4PathFinderRay *pFrom, C4TransferZone *pUseZone=nullptr);
48  bool SplitRay(C4PathFinderRay *pRay, int32_t iAtX, int32_t iAtY);
49  bool Execute();
50 
51  PointFreeFn PointFree;
52  SetWaypointFn SetWaypoint;
53  C4PathFinderRay *FirstRay;
54  bool Success;
55  C4TransferZones *TransferZones;
56  bool TransferZonesEnabled;
57  int Level;
58 };
59 
60 
61 #endif
bool Find(int32_t iFromX, int32_t iFromY, int32_t iToX, int32_t iToY, SetWaypointFn fnSetWaypoint)
void Init(PointFreeFn fnPointFree, C4TransferZones *pTransferZones=nullptr)
void SetLevel(int iLevel)
void Draw(C4TargetFacet &cgo)
std::function< bool(int32_t x, int32_t y, C4Object *transfer_object)> SetWaypointFn
Definition: C4PathFinder.h:35
std::function< bool(int32_t x, int32_t y)> PointFreeFn
Definition: C4PathFinder.h:34
bool PointFree(int32_t iX, int32_t iY)
void EnableTransferZones(bool fEnabled)