diff --git a/src/landscape.cpp b/src/landscape.cpp index 916201615d..66422db748 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -1219,7 +1219,7 @@ struct River_UserData { /* AyStar callback for checking whether we reached our destination. */ static AyStarStatus River_EndNodeCheck(const AyStar *aystar, const PathNode *current) { - return current->GetTile() == *(TileIndex*)aystar->user_target ? AYSTAR_FOUND_END_NODE : AYSTAR_DONE; + return current->GetTile() == *(TileIndex*)aystar->user_target ? AyStarStatus::FoundEndNode : AyStarStatus::Done; } /* AyStar callback for getting the cost of the current node. */ diff --git a/src/pathfinder/aystar.cpp b/src/pathfinder/aystar.cpp index db30cb570f..7e8fecfe3f 100644 --- a/src/pathfinder/aystar.cpp +++ b/src/pathfinder/aystar.cpp @@ -84,24 +84,24 @@ void AyStar::CheckTile(AyStarNode *current, PathNode *parent) * This function is the core of %AyStar. It handles one item and checks * its neighbour items. If they are valid, they are added to be checked too. * @return Possible values: - * - #AYSTAR_EMPTY_OPENLIST : indicates all items are tested, and no path has been found. - * - #AYSTAR_LIMIT_REACHED : Indicates that the max_search_nodes limit has been reached. - * - #AYSTAR_FOUND_END_NODE : indicates we found the end. Path_found now is true, and in path is the path found. - * - #AYSTAR_STILL_BUSY : indicates we have done this tile, did not found the path yet, and have items left to try. + * - #AyStarStatus::EmptyOpenList + * - #AyStarStatus::LimitReached + * - #AyStarStatus::FoundEndNode + * - #AyStarStatus::StillBusy */ AyStarStatus AyStar::Loop() { /* Get the best node from OpenList */ PathNode *current = this->nodes.PopBestOpenNode(); /* If empty, drop an error */ - if (current == nullptr) return AYSTAR_EMPTY_OPENLIST; + if (current == nullptr) return AyStarStatus::EmptyOpenList; /* Check for end node and if found, return that code */ - if (this->EndNodeCheck(this, current) == AYSTAR_FOUND_END_NODE && current->parent != nullptr) { + if (this->EndNodeCheck(this, current) == AyStarStatus::FoundEndNode && current->parent != nullptr) { if (this->FoundEndNode != nullptr) { this->FoundEndNode(this, current); } - return AYSTAR_FOUND_END_NODE; + return AyStarStatus::FoundEndNode; } /* Add the node to the ClosedList */ @@ -118,43 +118,43 @@ AyStarStatus AyStar::Loop() if (this->max_search_nodes != 0 && this->nodes.ClosedCount() >= this->max_search_nodes) { /* We've expanded enough nodes */ - return AYSTAR_LIMIT_REACHED; + return AyStarStatus::LimitReached; } else { /* Return that we are still busy */ - return AYSTAR_STILL_BUSY; + return AyStarStatus::StillBusy; } } /** * This is the function you call to run AyStar. * @return Possible values: - * - #AYSTAR_FOUND_END_NODE : indicates we found an end node. - * - #AYSTAR_NO_PATH : indicates that there was no path found. - * - #AYSTAR_STILL_BUSY : indicates we have done some checked, that we did not found the path yet, and that we still have items left to try. - * @note When the algorithm is done (when the return value is not #AYSTAR_STILL_BUSY) #Clear() is called automatically. + * - #AyStarStatus::FoundEndNode + * - #AyStarStatus::NoPath + * - #AyStarStatus::StillBusy + * @note When the algorithm is done (when the return value is not #AyStarStatus::StillBusy) #Clear() is called automatically. * When you stop the algorithm halfway, you should call #Clear() yourself! */ AyStarStatus AyStar::Main() { - AyStarStatus r = AYSTAR_FOUND_END_NODE; + AyStarStatus r = AyStarStatus::FoundEndNode; int i = 0; /* Loop through the OpenList - * Quit if result is no AYSTAR_STILL_BUSY or is more than loops_per_tick */ - while ((r = this->Loop()) == AYSTAR_STILL_BUSY && (this->loops_per_tick == 0 || ++i < this->loops_per_tick)) { } + * Quit if result is no AyStarStatus::StillBusy or is more than loops_per_tick */ + while ((r = this->Loop()) == AyStarStatus::StillBusy && (this->loops_per_tick == 0 || ++i < this->loops_per_tick)) { } #ifdef AYSTAR_DEBUG switch (r) { - case AYSTAR_FOUND_END_NODE: Debug(misc, 0, "[AyStar] Found path!"); break; - case AYSTAR_EMPTY_OPENLIST: Debug(misc, 0, "[AyStar] OpenList run dry, no path found"); break; - case AYSTAR_LIMIT_REACHED: Debug(misc, 0, "[AyStar] Exceeded search_nodes, no path found"); break; + case AyStarStatus::FoundEndNode: Debug(misc, 0, "[AyStar] Found path!"); break; + case AyStarStatus::EmptyOpenList: Debug(misc, 0, "[AyStar] OpenList run dry, no path found"); break; + case AyStarStatus::LimitReached: Debug(misc, 0, "[AyStar] Exceeded search_nodes, no path found"); break; default: break; } #endif switch (r) { - case AYSTAR_FOUND_END_NODE: return AYSTAR_FOUND_END_NODE; - case AYSTAR_EMPTY_OPENLIST: - case AYSTAR_LIMIT_REACHED: return AYSTAR_NO_PATH; - default: return AYSTAR_STILL_BUSY; + case AyStarStatus::FoundEndNode: return AyStarStatus::FoundEndNode; + case AyStarStatus::EmptyOpenList: + case AyStarStatus::LimitReached: return AyStarStatus::NoPath; + default: return AyStarStatus::StillBusy; } } diff --git a/src/pathfinder/aystar.h b/src/pathfinder/aystar.h index 1e94bfa02d..f8830c61c4 100644 --- a/src/pathfinder/aystar.h +++ b/src/pathfinder/aystar.h @@ -28,13 +28,13 @@ static const int AYSTAR_DEF_MAX_SEARCH_NODES = 10000; ///< Reference limit for #AyStar::max_search_nodes /** Return status of #AyStar methods. */ -enum AyStarStatus { - AYSTAR_FOUND_END_NODE, ///< An end node was found. - AYSTAR_EMPTY_OPENLIST, ///< All items are tested, and no path has been found. - AYSTAR_STILL_BUSY, ///< Some checking was done, but no path found yet, and there are still items left to try. - AYSTAR_NO_PATH, ///< No path to the goal was found. - AYSTAR_LIMIT_REACHED, ///< The #AyStar::max_search_nodes limit has been reached, aborting search. - AYSTAR_DONE, ///< Not an end-tile, or wrong direction. +enum class AyStarStatus : uint8_t { + FoundEndNode, ///< An end node was found. + EmptyOpenList, ///< All items are tested, and no path has been found. + StillBusy, ///< Some checking was done, but no path found yet, and there are still items left to try. + NoPath, ///< No path to the goal was found. + LimitReached, ///< The #AyStar::max_search_nodes limit has been reached, aborting search. + Done, ///< Not an end-tile, or wrong direction. }; static const int AYSTAR_INVALID_NODE = -1; ///< Item is not valid (for example, not walkable). @@ -59,8 +59,8 @@ struct AyStar; * don't try to enter the file tile with a 90-degree curve. So please, leave * this an #OpenListNode, it works just fine. * @return Status of the node: - * - #AYSTAR_FOUND_END_NODE : indicates this is the end tile - * - #AYSTAR_DONE : indicates this is not the end tile (or direction was wrong) + * - #AyStarStatus::FoundEndNode : indicates this is the end tile + * - #AyStarStatus::Done : indicates this is not the end tile (or direction was wrong) */ typedef AyStarStatus AyStar_EndNodeCheck(const AyStar *aystar, const PathNode *current);