1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-29 07:37:45 +00:00

Merge pull request #510 from NotAdam/develop

bnpc pathing
This commit is contained in:
Mordred 2019-01-27 13:54:48 +01:00 committed by GitHub
commit 7bef38d475
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 27 deletions

View file

@ -162,9 +162,13 @@ void Sapphire::Entity::BNpc::step()
return; return;
auto stepPos = m_naviLastPath[ m_naviPathStep ]; auto stepPos = m_naviLastPath[ m_naviPathStep ];
auto distanceToStep = Util::distance( getPos().x, getPos().y, getPos().z,
stepPos.x, stepPos.y, stepPos.z );
if( Util::distance( getPos().x, getPos().y, getPos().z, stepPos.x, stepPos.y, stepPos.z ) <= 4 && auto distanceToDest = Util::distance( getPos().x, getPos().y, getPos().z,
m_naviPathStep < m_naviLastPath.size() - 1 ) m_naviTarget.x, m_naviTarget.y, m_naviTarget.z );
if( distanceToStep <= 4 && m_naviPathStep < m_naviLastPath.size() - 1 )
{ {
// Reached step in path // Reached step in path
m_naviPathStep++; m_naviPathStep++;
@ -179,10 +183,16 @@ void Sapphire::Entity::BNpc::step()
if( m_state == BNpcState::Roaming ) if( m_state == BNpcState::Roaming )
speed *= 0.5f; speed *= 0.5f;
if( distanceToDest <= distanceToStep + speed )
{
speed = distanceToDest;
}
auto x = ( cosf( angle ) * speed ); auto x = ( cosf( angle ) * speed );
auto y = stepPos.y; auto y = stepPos.y;
auto z = ( sinf( angle ) * speed ); auto z = ( sinf( angle ) * speed );
face( stepPos ); face( stepPos );
setPos( { getPos().x + x, y, getPos().z + z } ); setPos( { getPos().x + x, y, getPos().z + z } );
sendPositionUpdate(); sendPositionUpdate();
@ -198,9 +208,6 @@ bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos )
return true; return true;
} }
// Check if we have to recalculate
if( Util::getTimeMs() - m_naviLastUpdate > 500 )
{
auto pNaviMgr = m_pFw->get< World::Manager::NaviMgr >(); auto pNaviMgr = m_pFw->get< World::Manager::NaviMgr >();
auto pNaviProvider = pNaviMgr->getNaviProvider( m_pCurrentZone->getBgPath() ); auto pNaviProvider = pNaviMgr->getNaviProvider( m_pCurrentZone->getBgPath() );
@ -225,7 +232,8 @@ bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos )
{ {
Logger::debug( "No path found from x{0} y{1} z{2} to x{3} y{4} z{5} in {6}", Logger::debug( "No path found from x{0} y{1} z{2} to x{3} y{4} z{5} in {6}",
getPos().x, getPos().y, getPos().z, pos.x, pos.y, pos.z, m_pCurrentZone->getInternalName() ); getPos().x, getPos().y, getPos().z, pos.x, pos.y, pos.z, m_pCurrentZone->getInternalName() );
}
hateListClear();
} }

View file

@ -8,7 +8,7 @@
namespace Sapphire::World::Navi namespace Sapphire::World::Navi
{ {
const int32_t MAX_POLYS = 256; const int32_t MAX_POLYS = 8;
const int32_t MAX_SMOOTH = 2048; const int32_t MAX_SMOOTH = 2048;
const int32_t NAVMESHSET_MAGIC = 'M' << 24 | 'S' << 16 | 'E' << 8 | 'T'; //'MSET' const int32_t NAVMESHSET_MAGIC = 'M' << 24 | 'S' << 16 | 'E' << 8 | 'T'; //'MSET'