|
@@ -29,30 +29,30 @@
|
|
|
#include "../../core/alloc_func.hpp"
|
|
|
#include "aystar.h"
|
|
|
|
|
|
/* This looks in the Hash if a node exists in ClosedList
|
|
|
* If so, it returns the PathNode, else NULL */
|
|
|
static PathNode *AyStarMain_ClosedList_IsInList(AyStar *aystar, const AyStarNode *node)
|
|
|
{
|
|
|
return (PathNode*)Hash_Get(&aystar->ClosedListHash, node->tile, node->direction);
|
|
|
}
|
|
|
|
|
|
/* This adds a node to the ClosedList
|
|
|
* It makes a copy of the data */
|
|
|
static void AyStarMain_ClosedList_Add(AyStar *aystar, const PathNode *node)
|
|
|
void AyStar::ClosedListAdd(const PathNode *node)
|
|
|
{
|
|
|
/* Add a node to the ClosedList */
|
|
|
PathNode *new_node = MallocT<PathNode>(1);
|
|
|
*new_node = *node;
|
|
|
Hash_Set(&aystar->ClosedListHash, node->node.tile, node->node.direction, new_node);
|
|
|
Hash_Set(&this->ClosedListHash, node->node.tile, node->node.direction, new_node);
|
|
|
}
|
|
|
|
|
|
/* Checks if a node is in the OpenList
|
|
|
* If so, it returns the OpenListNode, else NULL */
|
|
|
OpenListNode *AyStar::OpenListIsInList(const AyStarNode *node)
|
|
|
{
|
|
|
return (OpenListNode*)Hash_Get(&this->OpenListHash, node->tile, node->direction);
|
|
|
}
|
|
|
|
|
|
/* Gets the best node from OpenList
|
|
|
* returns the best node, or NULL of none is found
|
|
|
* Also it deletes the node from the OpenList */
|
|
@@ -159,25 +159,25 @@ int AyStar::Loop()
|
|
|
if (current == NULL) return AYSTAR_EMPTY_OPENLIST;
|
|
|
|
|
|
/* Check for end node and if found, return that code */
|
|
|
if (this->EndNodeCheck(this, current) == AYSTAR_FOUND_END_NODE) {
|
|
|
if (this->FoundEndNode != NULL) {
|
|
|
this->FoundEndNode(this, current);
|
|
|
}
|
|
|
free(current);
|
|
|
return AYSTAR_FOUND_END_NODE;
|
|
|
}
|
|
|
|
|
|
/* Add the node to the ClosedList */
|
|
|
AyStarMain_ClosedList_Add(this, ¤t->path);
|
|
|
this->ClosedListAdd(¤t->path);
|
|
|
|
|
|
/* Load the neighbours */
|
|
|
this->GetNeighbours(this, current);
|
|
|
|
|
|
/* Go through all neighbours */
|
|
|
for (i = 0; i < this->num_neighbours; i++) {
|
|
|
/* Check and add them to the OpenList if needed */
|
|
|
this->CheckTile(&this->neighbours[i], current);
|
|
|
}
|
|
|
|
|
|
/* Free the node */
|
|
|
free(current);
|