mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-27 22:57:45 +00:00
Simplified in range logic
This commit is contained in:
parent
62f69040b4
commit
c4206ee9bc
3 changed files with 16 additions and 42 deletions
|
@ -538,38 +538,6 @@ void Core::Entity::Actor::removeFromInRange()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::Entity::Actor::checkInRangeActors()
|
|
||||||
{
|
|
||||||
if( hasInRangeActor() )
|
|
||||||
{
|
|
||||||
Entity::ActorPtr pCurAct;
|
|
||||||
|
|
||||||
float fRange = 70.0f;
|
|
||||||
for( auto iter = m_inRangeActors.begin(); iter != m_inRangeActors.end();)
|
|
||||||
{
|
|
||||||
pCurAct = *iter;
|
|
||||||
auto iter2 = iter++;
|
|
||||||
|
|
||||||
float distance = Math::Util::distance( pCurAct->getPos().x, pCurAct->getPos().y, pCurAct->getPos().z,
|
|
||||||
getPos().x, getPos().y, getPos().z );
|
|
||||||
|
|
||||||
if( fRange > 0.0f && distance > fRange )
|
|
||||||
{
|
|
||||||
pCurAct->removeInRangeActor( *this );
|
|
||||||
|
|
||||||
if( getCurrentZone() != pCurAct->getCurrentZone() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
removeInRangeActor( **iter2 );
|
|
||||||
|
|
||||||
// @TODO FIXME!
|
|
||||||
// this break is more or less a hack, iteration will break otherwise after removing
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! Clear the whole in range set, this does no cleanup */
|
/*! Clear the whole in range set, this does no cleanup */
|
||||||
void Core::Entity::Actor::clearInRangeSet()
|
void Core::Entity::Actor::clearInRangeSet()
|
||||||
{
|
{
|
||||||
|
|
|
@ -271,8 +271,6 @@ public:
|
||||||
// return true if there is at least one actor in the in range set
|
// return true if there is at least one actor in the in range set
|
||||||
bool hasInRangeActor() const;
|
bool hasInRangeActor() const;
|
||||||
|
|
||||||
void checkInRangeActors();
|
|
||||||
|
|
||||||
void removeFromInRange();
|
void removeFromInRange();
|
||||||
|
|
||||||
// clear the whole in range set, this does no cleanup
|
// clear the whole in range set, this does no cleanup
|
||||||
|
|
|
@ -631,7 +631,7 @@ void Core::Zone::updateActorPosition( Entity::Actor &actor )
|
||||||
if( actor.getCurrentZone() != shared_from_this() )
|
if( actor.getCurrentZone() != shared_from_this() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
actor.checkInRangeActors();
|
//actor.checkInRangeActors();
|
||||||
|
|
||||||
uint32_t cellX = getPosX( actor.getPos().x );
|
uint32_t cellX = getPosX( actor.getPos().x );
|
||||||
uint32_t cellY = getPosY( actor.getPos().z );
|
uint32_t cellY = getPosY( actor.getPos().z );
|
||||||
|
@ -712,19 +712,18 @@ void Core::Zone::updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell )
|
||||||
pCurAct = *iter;
|
pCurAct = *iter;
|
||||||
++iter;
|
++iter;
|
||||||
|
|
||||||
if( !pCurAct )
|
if( !pCurAct || pCurAct == pActor )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
float distance = Math::Util::distance( pCurAct->getPos().x, pCurAct->getPos().y, pCurAct->getPos().z,
|
float distance = Math::Util::distance( pCurAct->getPos().x, pCurAct->getPos().y, pCurAct->getPos().z,
|
||||||
pActor->getPos().x, pActor->getPos().y, pActor->getPos().z );
|
pActor->getPos().x, pActor->getPos().y, pActor->getPos().z );
|
||||||
|
|
||||||
// Add if we are not ourself and range == 0 or distance is withing range.
|
bool isInRange = ( fRange == 0.0f || distance <= fRange );
|
||||||
if( pCurAct != pActor && ( fRange == 0.0f || distance <= fRange ) )
|
bool isInRangeSet = pActor->isInRangeSet( pCurAct );
|
||||||
{
|
|
||||||
|
|
||||||
if( pActor->isInRangeSet( pCurAct ) )
|
// Add if we are not ourself and range == 0 or distance is withing range.
|
||||||
// Actor already in range set, skip
|
if( isInRange && !isInRangeSet )
|
||||||
continue;
|
{
|
||||||
|
|
||||||
if( pActor->isPlayer() )
|
if( pActor->isPlayer() )
|
||||||
{
|
{
|
||||||
|
@ -769,6 +768,15 @@ void Core::Zone::updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell )
|
||||||
pCurAct->addInRangeActor( pActor );
|
pCurAct->addInRangeActor( pActor );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if( !isInRange && isInRangeSet )
|
||||||
|
{
|
||||||
|
pCurAct->removeInRangeActor( *pActor );
|
||||||
|
|
||||||
|
if( pActor->getCurrentZone() != pCurAct->getCurrentZone() )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
pActor->removeInRangeActor( *pCurAct );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue