2015-06-30 12:46:07 +03:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
NavDirType Opposite[NUM_DIRECTIONS] = { SOUTH, WEST, NORTH, EAST };
|
2015-06-30 12:46:07 +03:00
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
CNavNode *CNavNode::m_list = nullptr;
|
2015-12-07 17:18:21 +03:00
|
|
|
unsigned int CNavNode::m_listLength = 0;
|
2015-06-30 12:46:07 +03:00
|
|
|
|
2015-12-22 21:07:49 +03:00
|
|
|
CNavNode::CNavNode(const Vector *pos, const Vector *normal, CNavNode *parent)
|
2015-06-30 12:46:07 +03:00
|
|
|
{
|
2015-12-22 21:07:49 +03:00
|
|
|
m_pos = *pos;
|
|
|
|
m_normal = *normal;
|
|
|
|
|
|
|
|
static unsigned int nextID = 1;
|
|
|
|
m_id = nextID++;
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
for (int i = 0; i < NUM_DIRECTIONS; i++)
|
|
|
|
m_to[i] = nullptr;
|
2015-12-22 21:07:49 +03:00
|
|
|
|
|
|
|
m_visited = 0;
|
|
|
|
m_parent = parent;
|
|
|
|
|
2017-10-19 20:12:02 +03:00
|
|
|
m_next = m_list;
|
|
|
|
m_list = this;
|
|
|
|
m_listLength++;
|
2015-12-22 21:07:49 +03:00
|
|
|
|
|
|
|
m_isCovered = FALSE;
|
2017-10-12 17:50:56 +03:00
|
|
|
m_area = nullptr;
|
2015-12-22 21:07:49 +03:00
|
|
|
|
|
|
|
m_attributeFlags = 0;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2015-12-22 21:07:49 +03:00
|
|
|
// Create a connection FROM this node TO the given node, in the given direction
|
2015-06-30 12:46:07 +03:00
|
|
|
void CNavNode::ConnectTo(CNavNode *node, NavDirType dir)
|
|
|
|
{
|
2017-10-12 17:50:56 +03:00
|
|
|
m_to[dir] = node;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2015-12-22 21:07:49 +03:00
|
|
|
// Return node at given position
|
|
|
|
// TODO: Need a hash table to make this lookup fast
|
2015-06-30 12:46:07 +03:00
|
|
|
const CNavNode *CNavNode::GetNode(const Vector *pos)
|
|
|
|
{
|
2015-12-22 21:07:49 +03:00
|
|
|
const float tolerance = 0.45f * GenerationStepSize;
|
2017-10-19 20:12:02 +03:00
|
|
|
for (const CNavNode *node = m_list; node; node = node->m_next)
|
2015-12-22 21:07:49 +03:00
|
|
|
{
|
2017-10-19 20:12:02 +03:00
|
|
|
float dx = abs(node->m_pos.x - pos->x);
|
|
|
|
float dy = abs(node->m_pos.y - pos->y);
|
|
|
|
float dz = abs(node->m_pos.z - pos->z);
|
2015-12-22 21:07:49 +03:00
|
|
|
|
|
|
|
if (dx < tolerance && dy < tolerance && dz < tolerance)
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
return nullptr;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2016-02-04 03:18:26 +03:00
|
|
|
// Return true if this node is bidirectionally linked to
|
2015-12-22 21:07:49 +03:00
|
|
|
// another node in the given direction
|
2015-06-30 12:46:07 +03:00
|
|
|
BOOL CNavNode::IsBiLinked(NavDirType dir) const
|
|
|
|
{
|
2017-10-12 17:50:56 +03:00
|
|
|
if (m_to[dir] && m_to[dir]->m_to[Opposite[dir]] == this)
|
2015-12-22 21:07:49 +03:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2015-12-22 21:07:49 +03:00
|
|
|
// Return true if this node is the NW corner of a quad of nodes
|
|
|
|
// that are all bidirectionally linked
|
2016-02-04 03:18:26 +03:00
|
|
|
BOOL CNavNode::IsClosedCell() const
|
2015-06-30 12:46:07 +03:00
|
|
|
{
|
2017-10-12 17:50:56 +03:00
|
|
|
if (IsBiLinked(SOUTH) && IsBiLinked(EAST) && m_to[EAST]->IsBiLinked(SOUTH) && m_to[SOUTH]->IsBiLinked(EAST)
|
|
|
|
&& m_to[EAST]->m_to[SOUTH] == m_to[SOUTH]->m_to[EAST])
|
2015-12-22 21:07:49 +03:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|