| 1 | /* |
| 2 | * LegacyClonk |
| 3 | * |
| 4 | * Copyright (c) 1998-2000, Matthes Bender (RedWolf Design) |
| 5 | * Copyright (c) 2017-2019, The LegacyClonk Team and contributors |
| 6 | * |
| 7 | * Distributed under the terms of the ISC license; see accompanying file |
| 8 | * "COPYING" for details. |
| 9 | * |
| 10 | * "Clonk" is a registered trademark of Matthes Bender, used with permission. |
| 11 | * See accompanying file "TRADEMARK" for details. |
| 12 | * |
| 13 | * To redistribute this file separately, substitute the full license texts |
| 14 | * for the above references. |
| 15 | */ |
| 16 | |
| 17 | /* Finds the way through the Clonk landscape */ |
| 18 | |
| 19 | #pragma once |
| 20 | |
| 21 | #include "C4ForwardDeclarations.h" |
| 22 | #include <C4TransferZone.h> |
| 23 | |
| 24 | class C4PathFinderRay |
| 25 | { |
| 26 | friend class C4PathFinder; |
| 27 | |
| 28 | public: |
| 29 | C4PathFinderRay(); |
| 30 | ~C4PathFinderRay(); |
| 31 | |
| 32 | public: |
| 33 | void Clear(); |
| 34 | void Default(); |
| 35 | |
| 36 | protected: |
| 37 | int32_t Status; |
| 38 | int32_t X, Y, X2, Y2, TargetX, TargetY; |
| 39 | int32_t CrawlStartX, CrawlStartY, CrawlAttach, CrawlLength, CrawlStartAttach; |
| 40 | int32_t Direction, Depth; |
| 41 | C4TransferZone *UseZone; |
| 42 | C4PathFinderRay *From; |
| 43 | C4PathFinderRay *Next; |
| 44 | C4PathFinder *pPathFinder; |
| 45 | |
| 46 | protected: |
| 47 | void SetCompletePath(); |
| 48 | void TurnAttach(int32_t &rAttach, int32_t iDirection); |
| 49 | void CrawlToAttach(int32_t &rX, int32_t &rY, int32_t iAttach); |
| 50 | void CrawlByAttach(int32_t &rX, int32_t &rY, int32_t iAttach, int32_t iDirection); |
| 51 | void Draw(C4FacetEx &cgo); |
| 52 | int32_t FindCrawlAttachDiagonal(int32_t iX, int32_t iY, int32_t iDirection); |
| 53 | int32_t FindCrawlAttach(int32_t iX, int32_t iY); |
| 54 | bool IsCrawlAttach(int32_t iX, int32_t iY, int32_t iAttach); |
| 55 | bool CheckBackRayShorten(); |
| 56 | bool Execute(); |
| 57 | bool CrawlTargetFree(int32_t iX, int32_t iY, int32_t iAttach, int32_t iDirection); |
| 58 | bool PointFree(int32_t iX, int32_t iY); |
| 59 | bool Crawl(); |
| 60 | bool PathFree(int32_t &rX, int32_t &rY, int32_t iToX, int32_t iToY, C4TransferZone **ppZone = nullptr); |
| 61 | }; |
| 62 | |
| 63 | class C4PathFinder |
| 64 | { |
| 65 | friend class C4PathFinderRay; |
| 66 | |
| 67 | public: |
| 68 | C4PathFinder(); |
| 69 | ~C4PathFinder(); |
| 70 | |
| 71 | protected: |
| 72 | bool(*PointFree)(int32_t, int32_t); |
| 73 | // iToX and iToY are intptr_t because there are stored object |
| 74 | // pointers sometimes |
| 75 | bool(*SetWaypoint)(int32_t, int32_t, intptr_t, intptr_t); |
| 76 | C4PathFinderRay *FirstRay; |
| 77 | intptr_t WaypointParameter; |
| 78 | bool Success; |
| 79 | C4TransferZones *TransferZones; |
| 80 | bool TransferZonesEnabled; |
| 81 | int Level; |
| 82 | |
| 83 | public: |
| 84 | void Draw(C4FacetEx &cgo); |
| 85 | void Clear(); |
| 86 | void Default(); |
| 87 | void Init(bool(*fnPointFree)(int32_t, int32_t), C4TransferZones *pTransferZones = nullptr); |
| 88 | bool Find(int32_t iFromX, int32_t iFromY, int32_t iToX, int32_t iToY, bool(*fnSetWaypoint)(int32_t, int32_t, intptr_t, intptr_t), intptr_t iWaypointParameter); |
| 89 | void EnableTransferZones(bool fEnabled); |
| 90 | void SetLevel(int iLevel); |
| 91 | |
| 92 | protected: |
| 93 | void Run(); |
| 94 | 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); |
| 95 | bool SplitRay(C4PathFinderRay *pRay, int32_t iAtX, int32_t iAtY); |
| 96 | bool Execute(); |
| 97 | }; |
| 98 | |