mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-02-15 00:06:11 +00:00
refactor(Core/Misc): fabs() to std::fabs() (#9790)
- prefer std functions over C functions
This commit is contained in:
@@ -317,7 +317,7 @@ void CreatureGroup::LeaderMoveTo(float x, float y, float z, bool run)
|
||||
|
||||
// Xinef: this should be automatized, if turn angle is greater than PI/2 (90<39>) we should swap formation angle
|
||||
float followAngle = pFormationInfo.follow_angle;
|
||||
if (static_cast<float>(M_PI) - fabs(fabs(m_leader->GetOrientation() - pathAngle) - static_cast<float>(M_PI)) > static_cast<float>(M_PI)* 0.5f)
|
||||
if (static_cast<float>(M_PI) - std::fabs(std::fabs(m_leader->GetOrientation() - pathAngle) - static_cast<float>(M_PI)) > static_cast<float>(M_PI)* 0.5f)
|
||||
{
|
||||
// pussywizard: in both cases should be 2*M_PI - follow_angle
|
||||
// pussywizard: also, GetCurrentWaypointID() returns 0..n-1, while point_1 must be > 0, so +1
|
||||
|
||||
@@ -1022,7 +1022,7 @@ bool Position::HasInLine(WorldObject const* target, float width) const
|
||||
return false;
|
||||
width += target->GetObjectSize();
|
||||
float angle = GetRelativeAngle(target);
|
||||
return fabs(sin(angle)) * GetExactDist2d(target->GetPositionX(), target->GetPositionY()) < width;
|
||||
return std::fabs(sin(angle)) * GetExactDist2d(target->GetPositionX(), target->GetPositionY()) < width;
|
||||
}
|
||||
|
||||
std::string Position::ToString() const
|
||||
@@ -1247,7 +1247,7 @@ InstanceScript* WorldObject::GetInstanceScript() const
|
||||
|
||||
float WorldObject::GetDistanceZ(const WorldObject* obj) const
|
||||
{
|
||||
float dz = fabs(GetPositionZ() - obj->GetPositionZ());
|
||||
float dz = std::fabs(GetPositionZ() - obj->GetPositionZ());
|
||||
float sizefactor = GetObjectSize() + obj->GetObjectSize();
|
||||
float dist = dz - sizefactor;
|
||||
return (dist > 0 ? dist : 0);
|
||||
@@ -1555,7 +1555,7 @@ void Position::GetSinCos(const float x, const float y, float& vsin, float& vcos)
|
||||
float dx = GetPositionX() - x;
|
||||
float dy = GetPositionY() - y;
|
||||
|
||||
if (fabs(dx) < 0.001f && fabs(dy) < 0.001f)
|
||||
if (std::fabs(dx) < 0.001f && std::fabs(dy) < 0.001f)
|
||||
{
|
||||
float angle = (float)rand_norm() * static_cast<float>(2 * M_PI);
|
||||
vcos = cos(angle);
|
||||
@@ -1651,7 +1651,7 @@ bool WorldObject::IsInBetween(const WorldObject* obj1, const WorldObject* obj2,
|
||||
float A = (obj2->GetPositionY() - obj1->GetPositionY()) / (obj2->GetPositionX() - obj1->GetPositionX());
|
||||
float B = -1;
|
||||
float C = obj1->GetPositionY() - A * obj1->GetPositionX();
|
||||
float dist = fabs(A * GetPositionX() + B * GetPositionY() + C) / sqrt(A * A + B * B);
|
||||
float dist = std::fabs(A * GetPositionX() + B * GetPositionY() + C) / sqrt(A * A + B * B);
|
||||
return dist <= size;
|
||||
}
|
||||
|
||||
@@ -2786,7 +2786,7 @@ bool WorldObject::GetClosePoint(float& x, float& y, float& z, float size, float
|
||||
// angle calculated from current orientation
|
||||
GetNearPoint(forWho, x, y, z, size, distance2d, GetOrientation() + angle);
|
||||
|
||||
if (fabs(this->GetPositionZ() - z) > 3.0f || !IsWithinLOS(x, y, z))
|
||||
if (std::fabs(this->GetPositionZ() - z) > 3.0f || !IsWithinLOS(x, y, z))
|
||||
{
|
||||
x = this->GetPositionX();
|
||||
y = this->GetPositionY();
|
||||
@@ -2830,7 +2830,7 @@ void WorldObject::GetContactPoint(const WorldObject* obj, float& x, float& y, fl
|
||||
GetNearPoint(obj, x, y, z, obj->GetObjectSize(), distance2d, GetAngle(obj));
|
||||
|
||||
// Exclude gameobjects from LoS calculations
|
||||
if (fabs(this->GetPositionZ() - z) > 3.0f || (GetTypeId() != TYPEID_GAMEOBJECT && !IsWithinLOS(x, y, z)))
|
||||
if (std::fabs(this->GetPositionZ() - z) > 3.0f || (GetTypeId() != TYPEID_GAMEOBJECT && !IsWithinLOS(x, y, z)))
|
||||
{
|
||||
x = this->GetPositionX();
|
||||
y = this->GetPositionY();
|
||||
@@ -2844,7 +2844,7 @@ void WorldObject::GetChargeContactPoint(const WorldObject* obj, float& x, float&
|
||||
// angle to face `obj` to `this` using distance includes size of `obj`
|
||||
GetNearPoint(obj, x, y, z, obj->GetObjectSize(), distance2d, GetAngle(obj));
|
||||
|
||||
if (fabs(this->GetPositionZ() - z) > 3.0f || !IsWithinLOS(x, y, z))
|
||||
if (std::fabs(this->GetPositionZ() - z) > 3.0f || !IsWithinLOS(x, y, z))
|
||||
{
|
||||
x = this->GetPositionX();
|
||||
y = this->GetPositionY();
|
||||
@@ -2874,20 +2874,20 @@ void WorldObject::MovePosition(Position& pos, float dist, float angle)
|
||||
|
||||
ground = GetMapHeight(destx, desty, MAX_HEIGHT);
|
||||
floor = GetMapHeight(destx, desty, pos.m_positionZ);
|
||||
destz = fabs(ground - pos.m_positionZ) <= fabs(floor - pos.m_positionZ) ? ground : floor;
|
||||
destz = std::fabs(ground - pos.m_positionZ) <= std::fabs(floor - pos.m_positionZ) ? ground : floor;
|
||||
|
||||
float step = dist / 10.0f;
|
||||
|
||||
for (uint8 j = 0; j < 10; ++j)
|
||||
{
|
||||
// do not allow too big z changes
|
||||
if (fabs(pos.m_positionZ - destz) > 6.0f)
|
||||
if (std::fabs(pos.m_positionZ - destz) > 6.0f)
|
||||
{
|
||||
destx -= step * cos(angle);
|
||||
desty -= step * sin(angle);
|
||||
ground = GetMapHeight(destx, desty, MAX_HEIGHT);
|
||||
floor = GetMapHeight(destx, desty, pos.m_positionZ);
|
||||
destz = fabs(ground - pos.m_positionZ) <= fabs(floor - pos.m_positionZ) ? ground : floor;
|
||||
destz = std::fabs(ground - pos.m_positionZ) <= std::fabs(floor - pos.m_positionZ) ? ground : floor;
|
||||
}
|
||||
// we have correct destz now
|
||||
else
|
||||
|
||||
@@ -62,7 +62,7 @@ struct ObjectPosSelector
|
||||
if (nextUsedPos.second.sign * sign < 0) // last node from diff. list (-pi+alpha)
|
||||
next_angle = 2 * M_PI - next_angle; // move to positive
|
||||
|
||||
return fabs(angle) + angle_step2 <= next_angle;
|
||||
return std::fabs(angle) + angle_step2 <= next_angle;
|
||||
}
|
||||
|
||||
bool CheckOriginal() const
|
||||
@@ -104,7 +104,7 @@ struct ObjectPosSelector
|
||||
// next possible angle
|
||||
angle = m_smallStepAngle[uptype] + m_anglestep * sign;
|
||||
|
||||
if (fabs(angle) > M_PI)
|
||||
if (std::fabs(angle) > M_PI)
|
||||
{
|
||||
m_smallStepOk[uptype] = false;
|
||||
return false;
|
||||
@@ -112,7 +112,7 @@ struct ObjectPosSelector
|
||||
|
||||
if (m_smallStepNextUsedPos[uptype])
|
||||
{
|
||||
if (fabs(angle) >= m_smallStepNextUsedPos[uptype]->first)
|
||||
if (std::fabs(angle) >= m_smallStepNextUsedPos[uptype]->first)
|
||||
{
|
||||
m_smallStepOk[uptype] = false;
|
||||
return false;
|
||||
|
||||
@@ -1887,7 +1887,7 @@ void Player::Regenerate(Powers power)
|
||||
return;
|
||||
|
||||
addvalue += m_powerFraction[power];
|
||||
uint32 integerValue = uint32(fabs(addvalue));
|
||||
uint32 integerValue = uint32(std::fabs(addvalue));
|
||||
|
||||
if (addvalue < 0.0f)
|
||||
{
|
||||
|
||||
@@ -681,7 +681,7 @@ bool Unit::GetRandomContactPoint(const Unit* obj, float& x, float& y, float& z,
|
||||
GetAngle(obj) + (attacker_number ? (static_cast<float>(M_PI / 2) - static_cast<float>(M_PI) * (float)rand_norm()) * float(attacker_number) / combat_reach * 0.3f : 0));
|
||||
|
||||
// pussywizard
|
||||
if (fabs(this->GetPositionZ() - z) > this->GetCollisionHeight() || !IsWithinLOS(x, y, z))
|
||||
if (std::fabs(this->GetPositionZ() - z) > this->GetCollisionHeight() || !IsWithinLOS(x, y, z))
|
||||
{
|
||||
x = this->GetPositionX();
|
||||
y = this->GetPositionY();
|
||||
@@ -1910,7 +1910,7 @@ void Unit::CalcAbsorbResist(DamageInfo& dmgInfo, bool Splited)
|
||||
float discreteResistProbability[11];
|
||||
for (uint32 i = 0; i < 11; ++i)
|
||||
{
|
||||
discreteResistProbability[i] = 0.5f - 2.5f * fabs(0.1f * i - averageResist);
|
||||
discreteResistProbability[i] = 0.5f - 2.5f * std::fabs(0.1f * i - averageResist);
|
||||
if (discreteResistProbability[i] < 0.0f)
|
||||
discreteResistProbability[i] = 0.0f;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user