mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-27 14:57:44 +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 */
|
||||
void Core::Entity::Actor::clearInRangeSet()
|
||||
{
|
||||
|
|
|
@ -271,8 +271,6 @@ public:
|
|||
// return true if there is at least one actor in the in range set
|
||||
bool hasInRangeActor() const;
|
||||
|
||||
void checkInRangeActors();
|
||||
|
||||
void removeFromInRange();
|
||||
|
||||
// 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() )
|
||||
return;
|
||||
|
||||
actor.checkInRangeActors();
|
||||
//actor.checkInRangeActors();
|
||||
|
||||
uint32_t cellX = getPosX( actor.getPos().x );
|
||||
uint32_t cellY = getPosY( actor.getPos().z );
|
||||
|
@ -712,19 +712,18 @@ void Core::Zone::updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell )
|
|||
pCurAct = *iter;
|
||||
++iter;
|
||||
|
||||
if( !pCurAct )
|
||||
if( !pCurAct || pCurAct == pActor )
|
||||
continue;
|
||||
|
||||
float distance = Math::Util::distance( pCurAct->getPos().x, pCurAct->getPos().y, pCurAct->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.
|
||||
if( pCurAct != pActor && ( fRange == 0.0f || distance <= fRange ) )
|
||||
{
|
||||
bool isInRange = ( fRange == 0.0f || distance <= fRange );
|
||||
bool isInRangeSet = pActor->isInRangeSet( pCurAct );
|
||||
|
||||
if( pActor->isInRangeSet( pCurAct ) )
|
||||
// Actor already in range set, skip
|
||||
continue;
|
||||
// Add if we are not ourself and range == 0 or distance is withing range.
|
||||
if( isInRange && !isInRangeSet )
|
||||
{
|
||||
|
||||
if( pActor->isPlayer() )
|
||||
{
|
||||
|
@ -769,6 +768,15 @@ void Core::Zone::updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell )
|
|||
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