2015-06-30 12:46:07 +03:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Globals initialization
|
|
|
|
*/
|
|
|
|
#ifndef HOOK_GAMEDLL
|
|
|
|
|
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
|
|
|
|
2016-02-23 02:13:52 +03:00
|
|
|
#endif
|
2015-06-30 12:46:07 +03:00
|
|
|
|
2016-02-23 02:13:52 +03:00
|
|
|
//Extent NodeMapExtent;
|
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;
|
|
|
|
|
|
|
|
m_next = IMPL(m_list);
|
|
|
|
IMPL(m_list) = this;
|
|
|
|
IMPL(m_listLength)++;
|
|
|
|
|
|
|
|
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-12 17:50:56 +03:00
|
|
|
for (const CNavNode *node = IMPL(m_list); node; node = node->m_next)
|
2015-12-22 21:07:49 +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);
|
|
|
|
|
|
|
|
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
|
|
|
}
|