diff --git a/Include/Core/Types/Counter.hpp b/Include/Core/Types/Counter.hpp index 6ae960d..8323f1b 100644 --- a/Include/Core/Types/Counter.hpp +++ b/Include/Core/Types/Counter.hpp @@ -6,48 +6,17 @@ /** @addtogroup Types * @{ */ -/** -* @brief A Counter can be used, well as a Counter. You construct it with MaxIterations, the counter is marked as finished whenever the current Iterations reach, or exceed MaxIterations. -* You can use @ref Increment to increase, and @ref Reset to reset the current Iterations. -* You can also use @ref IsFinished to check the current state of the Counter. -*/ class Counter { public: - /** - * @brief Default Counter constructor with MaxIterations as 0 - */ + Counter(); - /** - * @brief Constructs a Counter with - * @param std::int32_t MaxIterations Maximum amount of Iterations before the counter is Finished - */ Counter(std::int32_t MaxIterations); - /** - * @brief Resets the Counter's current Iterations to 0 - * @par Description - * Resets the Counter's current Iterations to 0 - */ + void Reset(); - /** - * @brief Increases the Counter's current Iterations by Amount, and returns true if the Counter isn't Finished - * @return True if the Counter isn't Finished, after it increments the Counter's current Iterations - */ bool Increment(std::int32_t Amount = 1); - /** - * @brief Returns True if the Counter's current Iterations equals the MaxIterations Paramater passed in the Constructor - * @return True if the Counter's current Iterations equals the MaxIterations Paramater passed in the Constructor - */ bool IsFinished() const; - /** - * @brief Returns the Counter's current Iterations - * @return Returns the Counter's current Iterations - */ std::int32_t GetIterations() const; - /** - * @brief Returns the Counter's maximum Iterations - * @return Returns the Counter's maximum Iterations - */ std::int32_t GetMaxIterations() const; friend std::ostream& operator<<(std::ostream& OS, const Counter& C); ~Counter(); diff --git a/Include/Game/Tools/Pathfinding.hpp b/Include/Game/Tools/Pathfinding.hpp index 266c3fe..1c122d9 100644 --- a/Include/Game/Tools/Pathfinding.hpp +++ b/Include/Game/Tools/Pathfinding.hpp @@ -5,6 +5,9 @@ #include #include +/** + * @brief A class allowing easy pathfinding within the local region + */ class Pathfinding { public: @@ -26,67 +29,112 @@ class Pathfinding NORTHEAST = 0x4, SOUTHEAST = 0x10, SOUTHWEST = 0x40, - NORTHWEST = 0x1, - - BLOCKED_NORTH = 0x400, - BLOCKED_EAST = 0x1000, - BLOCKED_SOUTH = 0x4000, - BLOCKED_WEST = 0x10000, - - BLOCKED_NORTHEAST = 0x800, - BLOCKED_SOUTHEAST = 0x2000, - BLOCKED_NORTHWEST = 0x200, - BLOCKED_SOUTHWEST = 0x8000, + NORTHWEST = 0x1 }; typedef enum PATHFINDER { + /** Breadth-first search algorithim */ BREADTH_FIRST_SEARCH } PATHFINDER; + enum PATHFIND_OPTION + { + /** Checks collision */ + CHECK_COLLISION = (1 << 1), + /** Checks whitelist */ + CHECK_WHITELIST = (1 << 2), + /** Checks blacklist */ + CHECK_BLACKLIST = (1 << 3), + /** The passed goal is a local tile, the function won't normalize it */ + GOAL_IS_LOCAL = (1 << 4), + /** Returns a path as local tiles */ + RETURN_LOCAL = (1 << 5) + }; + + /** + * @brief A subclass used to store information about tile nodes generated by the Pathfinding class + */ class TileNode { public: + /** @brief The local region X coordinate */ std::int32_t X; + /** @brief The local region Y coordinate */ std::int32_t Y; + /** @brief The collision flag associated with the node */ std::int32_t Flag; + /** @brief For pathfinding use only */ bool Inspected; + /** @brief True if this node matches the whitelisted tiles set in Pathfinding */ + bool MatchesWhitelist; + /** @brief True if this node matches the blacklisted tiles set in Pathfinding */ + bool MatchesBlacklist; + /** @brief For pathfinding use only */ std::int32_t Parent[2]; TileNode(); TileNode(std::int32_t X, std::int32_t Y, std::int32_t Flag); - bool IsBlocked(bool AllowOccupied = true) const; + /** @brief True if the node is occupied or blocked according to its collision flag*/ + bool IsBlocked() const; + /** @brief Adds ClientX/Y to the local X and Y coordinates of the node, returning a world tile */ Tile ToWorldTile() const; bool operator==(const TileNode& N) const; operator bool() const; }; - static void RegenerateNodes(); + /** @brief Clears the internal cached nodes, and generates new ones based on the local region */ + static void GenerateNodes(); + /** + * @brief Sets the internal Whitelist tiles + * @note This will set the internal Whitelist object to the one passed + * */ + static void SetWhitelist(const std::vector& W); + /** + * @brief Sets the internal Blacklist tiles + * @note This will set the internal Blacklist object to the one passed + * */ + static void SetBlacklist(const std::vector& B); + /** @brief Returns the internal TileNode cache generated by GenerateNodes() */ static std::vector> GetNodes(); + /** @brief Returns the internal Whitelist cache */ + static std::vector GetWhitelist(); + /** @brief Returns the internal Blacklist cache */ + static std::vector GetBlacklist(); static Tile FindWalkableTile(const Tile& T); static Tile FindWalkableTile(const Tile& T, const Tile& Min, const Tile& Max); static std::vector FindWalkableTiles(const Tile& T); static std::vector FindWalkableTiles(const Tile& T, const Tile& Min, const Tile& Max); - static std::vector FindPathTo(const Tile& Goal, bool AllowOccupied = false, PATHFINDER Finder = BREADTH_FIRST_SEARCH); - static std::vector FindPathTo(const std::vector& Goals, bool AllowOccupied = false, PATHFINDER Finder = BREADTH_FIRST_SEARCH); - // Ignores collision - static std::vector FindDirectPathTo(const Tile& Goal, PATHFINDER Finder = BREADTH_FIRST_SEARCH); - static std::vector FindDirectPathTo(const std::vector& Goals, PATHFINDER Finder = BREADTH_FIRST_SEARCH); + static std::vector FindPathTo( const Tile& Goal, + std::int32_t Options = CHECK_COLLISION | CHECK_WHITELIST | CHECK_BLACKLIST, + PATHFINDER Finder = BREADTH_FIRST_SEARCH ); + static std::vector FindPathTo( const std::vector& Goals, + std::int32_t Options = CHECK_COLLISION | CHECK_WHITELIST | CHECK_BLACKLIST, + PATHFINDER Finder = BREADTH_FIRST_SEARCH ); + static std::vector FindNodePathTo( const Tile& Goal, + std::int32_t Options = CHECK_COLLISION | CHECK_WHITELIST | CHECK_BLACKLIST, + PATHFINDER Finder = BREADTH_FIRST_SEARCH ); - static bool IsInside(std::uint32_t X, std::uint32_t Y); - static std::vector GetNeighborsTo(std::uint32_t X, std::uint32_t Y, bool AllowOccupied = false, bool CheckCollision = true); - static std::vector Finder_BFS( std::uint32_t StartX, std::uint32_t StartY, - std::uint32_t EndX, std::uint32_t EndY, - bool AllowOccupied = false, bool CheckCollision = true ); - - static std::vector Finder_BFS( std::uint32_t StartX, std::uint32_t StartY, - const std::vector>& Ends, - bool AllowOccupied = false, bool CheckCollision = true ); + static std::vector FindNodePathTo( const std::vector& Goals, + std::int32_t Options = CHECK_COLLISION | CHECK_WHITELIST | CHECK_BLACKLIST, + PATHFINDER Finder = BREADTH_FIRST_SEARCH ); private: static std::vector> Nodes; + static std::vector Whitelist; + static std::vector Blacklist; + + static bool IsInside(std::uint32_t X, std::uint32_t Y); + static std::vector GetNeighborsTo(std::uint32_t X, std::uint32_t Y, bool CheckCollision = true); + + static std::vector Finder_BFS( std::uint32_t StartX, std::uint32_t StartY, + std::uint32_t EndX, std::uint32_t EndY, + std::int32_t Options ); + static std::vector Finder_BFS( std::uint32_t StartX, std::uint32_t StartY, + const std::vector>& Ends, + std::int32_t Options ); }; #endif // PATHFINDING_HPP_INCLUDED diff --git a/Library/libAlpacaLibrary.a b/Library/libAlpacaLibrary.a index 7c6788f..ff6d38e 100644 Binary files a/Library/libAlpacaLibrary.a and b/Library/libAlpacaLibrary.a differ