Use distSqTo instead of distTo

This commit is contained in:
kaetemi 2013-09-07 15:53:17 +02:00
parent bf87d4d1c0
commit c9d14899ac
2 changed files with 16 additions and 12 deletions

View file

@ -310,9 +310,9 @@ void CWanderFaunaProfile::updateProfile(uint ticksSinceLastUpdate)
CFollowPathContext fpcWanderFaunaProfileUpdate("WanderFaunaProfileUpdate");
// calculate distance from bot position to magnet point (used in all the different processes)
_magnetDist=_Bot->pos().distTo(_Bot->spawnGrp().magnetPos());
if (_magnetDist>_Bot->spawnGrp().magnetRadiusFar())
_magnetDistSq=_Bot->pos().distSqTo(_Bot->spawnGrp().magnetPos());
double grpMagnetRadiusFar=_Bot->spawnGrp().magnetRadiusFar();
if (_magnetDistSq>(grpMagnetRadiusFar*grpMagnetRadiusFar))
{
_Bot->setMode( MBEHAV::NORMAL );
@ -405,11 +405,12 @@ void CGrazeFaunaProfile::updateProfile(uint ticksSinceLastUpdate)
CFollowPathContext fpcGrazeFaunaProfileUpdate("GrazeFaunaProfileUpdate");
// calculate distance from bot position to magnet point (used in all the different processes)
_magnetDist=_Bot->pos().distTo(_Bot->spawnGrp().magnetPos());
_magnetDistSq=_Bot->pos().distSqTo(_Bot->spawnGrp().magnetPos());
if (!_ArrivedInZone)
{
if (_magnetDist>_Bot->spawnGrp().magnetRadiusFar())
float grpMagnetRadiusFar=_Bot->spawnGrp().magnetRadiusFar();
if (_magnetDistSq>(grpMagnetRadiusFar*grpMagnetRadiusFar))
{
_Bot->setMode( MBEHAV::NORMAL );
@ -501,7 +502,8 @@ void CGrazeFaunaProfile::updateProfile(uint ticksSinceLastUpdate)
}
// && _state==0 ) // means wait in movementmagnet.
if ( _magnetDist<=_Bot->spawnGrp().magnetRadiusNear()
const float grpMagnetRadiusNear=_Bot->spawnGrp().magnetRadiusNear();
if ( _magnetDistSq<=(grpMagnetRadiusNear*grpMagnetRadiusNear)
&& _MovementMagnet->getMovementType()==CMovementMagnet::Movement_Anim)
{
if (_Bot->getPersistent().grp().getType()==AITYPES::FaunaTypePredator)
@ -564,11 +566,12 @@ void CRestFaunaProfile::updateProfile(uint ticksSinceLastUpdate)
CFollowPathContext fpcRestFaunaProfileUpdate("RestFaunaProfileUpdate");
// calculate distance from bot position to magnet point (used in all the different processes)
_magnetDist=_Bot->pos().distTo(_Bot->spawnGrp().magnetPos());
_magnetDistSq=_Bot->pos().distSqTo(_Bot->spawnGrp().magnetPos());
if (!_ArrivedInZone)
{
if (_magnetDist>_Bot->spawnGrp().magnetRadiusFar())
float grpMagnetRadiusFar=_Bot->spawnGrp().magnetRadiusFar();
if (_magnetDistSq>(grpMagnetRadiusFar*grpMagnetRadiusFar))
{
if (!_OutOfMagnet)
{
@ -656,7 +659,8 @@ void CRestFaunaProfile::updateProfile(uint ticksSinceLastUpdate)
break;
}
if ( _magnetDist<=_Bot->spawnGrp().magnetRadiusNear()
const float grpMagnetRadiusNear=_Bot->spawnGrp().magnetRadiusNear();
if ( _magnetDistSq<=(grpMagnetRadiusNear*grpMagnetRadiusNear)
&& _MovementMagnet->getMovementType()==CMovementMagnet::Movement_Anim)
{
_Bot->setMode(MBEHAV::REST);

View file

@ -137,7 +137,7 @@ public:
protected:
RYAI_MAP_CRUNCH::TAStarFlag _DenyFlags;
CSpawnBotFauna* _Bot;
double _magnetDist; ///< distance from bot to his magnet at last move
double _magnetDistSq; ///< square distance from bot to his magnet at last move
static CFaunaProfileFloodLogger _FloodLogger;
};
@ -166,7 +166,7 @@ private:
CAITimer _CycleTimer;
uint _CycleTimerBaseTime;
bool _ArrivedInZone;
double _magnetDist; ///< distance from bot to his magnet at last move
double _magnetDistSq; ///< square distance from bot to his magnet at last move
RYAI_MAP_CRUNCH::TAStarFlag _DenyFlags;
static CFaunaProfileFloodLogger _FloodLogger;
};
@ -196,7 +196,7 @@ private:
CAITimer _CycleTimer;
uint _CycleTimerBaseTime;
bool _ArrivedInZone;
double _magnetDist; // distance from bot to his magnet at last move
double _magnetDistSq; // square distance from bot to his magnet at last move
RYAI_MAP_CRUNCH::TAStarFlag _DenyFlags;
static CFaunaProfileFloodLogger _FloodLogger;
};