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;
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 &&
m_naviPathStep < m_naviLastPath.size() - 1 )
auto distanceToDest = Util::distance( getPos().x, getPos().y, getPos().z,
m_naviTarget.x, m_naviTarget.y, m_naviTarget.z );
if( distanceToStep <= 4 && m_naviPathStep < m_naviLastPath.size() - 1 )
{
// Reached step in path
m_naviPathStep++;
@ -179,10 +183,16 @@ void Sapphire::Entity::BNpc::step()
if( m_state == BNpcState::Roaming )
speed *= 0.5f;
if( distanceToDest <= distanceToStep + speed )
{
speed = distanceToDest;
}
auto x = ( cosf( angle ) * speed );
auto y = stepPos.y;
auto z = ( sinf( angle ) * speed );
face( stepPos );
setPos( { getPos().x + x, y, getPos().z + z } );
sendPositionUpdate();
@ -198,34 +208,32 @@ bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos )
return true;
}
// Check if we have to recalculate
if( Util::getTimeMs() - m_naviLastUpdate > 500 )
auto pNaviMgr = m_pFw->get< World::Manager::NaviMgr >();
auto pNaviProvider = pNaviMgr->getNaviProvider( m_pCurrentZone->getBgPath() );
if( !pNaviProvider )
{
auto pNaviMgr = m_pFw->get< World::Manager::NaviMgr >();
auto pNaviProvider = pNaviMgr->getNaviProvider( m_pCurrentZone->getBgPath() );
Logger::error( "No NaviProvider for zone#{0} - {1}",
m_pCurrentZone->getGuId(),
m_pCurrentZone->getInternalName() );
return false;
}
if( !pNaviProvider )
{
Logger::error( "No NaviProvider for zone#{0} - {1}",
m_pCurrentZone->getGuId(),
m_pCurrentZone->getInternalName() );
return false;
}
auto path = pNaviProvider->findFollowPath( m_pos, pos );
auto path = pNaviProvider->findFollowPath( m_pos, pos );
if( !path.empty() )
{
m_naviLastPath = path;
m_naviTarget = pos;
m_naviPathStep = 0;
m_naviLastUpdate = Util::getTimeMs();
}
else
{
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() );
if( !path.empty() )
{
m_naviLastPath = path;
m_naviTarget = pos;
m_naviPathStep = 0;
m_naviLastUpdate = Util::getTimeMs();
}
else
{
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() );
}
hateListClear();
}

View file

@ -8,7 +8,7 @@
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 NAVMESHSET_MAGIC = 'M' << 24 | 'S' << 16 | 'E' << 8 | 'T'; //'MSET'