diff options
Diffstat (limited to 'src/server/game')
36 files changed, 205 insertions, 163 deletions
diff --git a/src/server/game/AI/CoreAI/PetAI.cpp b/src/server/game/AI/CoreAI/PetAI.cpp index 4bce9113082..603c34e2403 100644 --- a/src/server/game/AI/CoreAI/PetAI.cpp +++ b/src/server/game/AI/CoreAI/PetAI.cpp @@ -236,7 +236,7 @@ void PetAI::UpdateAI(uint32 diff) SpellCastTargets targets; targets.SetUnitTarget(target); - if (!me->HasInArc(M_PI, target)) + if (!me->HasInArc(float(M_PI), target)) { me->SetInFront(target); if (target && target->GetTypeId() == TYPEID_PLAYER) diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index 55f69a113be..58e82bfcbbf 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -1623,7 +1623,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u break; float attackDistance = float(e.action.setRangedMovement.distance); - float attackAngle = float(e.action.setRangedMovement.angle) / 180.0f * M_PI; + float attackAngle = float(e.action.setRangedMovement.angle) / 180.0f * float(M_PI); ObjectList* targets = GetTargets(e, unit); if (targets) diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp index 07b41edebbe..40935a0712c 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp @@ -547,16 +547,8 @@ void AuctionHouseObject::BuildListAuctionItems(WorldPacket& data, Player* player if (levelmin != 0x00 && (proto->RequiredLevel < levelmin || (levelmax != 0x00 && proto->RequiredLevel > levelmax))) continue; - if (usable != 0x00) - { - if (player->CanUseItem(item) != EQUIP_ERR_OK) - continue; - - if (proto->Class == ITEM_CLASS_RECIPE) - if (SpellEntry const* spell = sSpellStore.LookupEntry(proto->Spells[0].SpellId)) - if (player->HasSpell(spell->EffectTriggerSpell[EFFECT_INDEX_0])) - continue; - } + if (usable != 0x00 && player->CanUseItem(item) != EQUIP_ERR_OK) + continue; // Allow search by suffix (ie: of the Monkey) or partial name (ie: Monkey) // No need to do any of this if no search term was entered diff --git a/src/server/game/Battlefield/Battlefield.cpp b/src/server/game/Battlefield/Battlefield.cpp index 5ef3426d602..41de1970344 100644 --- a/src/server/game/Battlefield/Battlefield.cpp +++ b/src/server/game/Battlefield/Battlefield.cpp @@ -908,7 +908,7 @@ void BfCapturePoint::SendChangePhase() // send this too, sometimes the slider disappears, dunno why :( SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldState1, 1); // send these updates to only the ones in this objective - SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate2, (uint32) ceil((m_value + m_maxValue) / (2 * m_maxValue) * 100.0f)); + SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate2, (uint32) std::ceil((m_value + m_maxValue) / (2 * m_maxValue) * 100.0f)); // send this too, sometimes it resets :S SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate3, m_neutralValuePct); } diff --git a/src/server/game/Battlegrounds/ArenaTeam.cpp b/src/server/game/Battlegrounds/ArenaTeam.cpp index 17d95dbbe6b..630780f43bf 100644 --- a/src/server/game/Battlegrounds/ArenaTeam.cpp +++ b/src/server/game/Battlegrounds/ArenaTeam.cpp @@ -637,7 +637,7 @@ float ArenaTeam::GetChanceAgainst(uint32 ownRating, uint32 opponentRating) { // Returns the chance to win against a team with the given rating, used in the rating adjustment calculation // ELO system - return 1.0f / (1.0f + exp(log(10.0f) * (float)((float)opponentRating - (float)ownRating) / 650.0f)); + return 1.0f / (1.0f + std::exp(std::log(10.0f) * (float(opponentRating) - float(ownRating)) / 650.0f)); } int32 ArenaTeam::GetMatchmakerRatingMod(uint32 ownRating, uint32 opponentRating, bool won) diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp index 10ede74685c..11e07566092 100644 --- a/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp +++ b/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp @@ -712,7 +712,7 @@ WorldSafeLocsEntry const* BattlegroundSA::GetClosestGraveYard(Player* player) safeloc = BG_SA_GYEntries[BG_SA_DEFENDER_LAST_GY]; closest = sWorldSafeLocsStore.LookupEntry(safeloc); - nearest = sqrt((closest->x - x)*(closest->x - x) + (closest->y - y)*(closest->y - y) + (closest->z - z)*(closest->z - z)); + nearest = std::sqrt((closest->x - x)*(closest->x - x) + (closest->y - y)*(closest->y - y) + (closest->z - z)*(closest->z - z)); for (uint8 i = BG_SA_RIGHT_CAPTURABLE_GY; i < BG_SA_MAX_GY; i++) { @@ -720,7 +720,7 @@ WorldSafeLocsEntry const* BattlegroundSA::GetClosestGraveYard(Player* player) continue; ret = sWorldSafeLocsStore.LookupEntry(BG_SA_GYEntries[i]); - dist = sqrt((ret->x - x)*(ret->x - x) + (ret->y - y)*(ret->y - y) + (ret->z - z)*(ret->z - z)); + dist = std::sqrt((ret->x - x)*(ret->x - x) + (ret->y - y)*(ret->y - y) + (ret->z - z)*(ret->z - z)); if (dist < nearest) { closest = ret; diff --git a/src/server/game/Conditions/ConditionMgr.cpp b/src/server/game/Conditions/ConditionMgr.cpp index 6083895ab26..34ed979291b 100644 --- a/src/server/game/Conditions/ConditionMgr.cpp +++ b/src/server/game/Conditions/ConditionMgr.cpp @@ -211,10 +211,25 @@ bool Condition::Meets(ConditionSourceInfo& sourceInfo) condMeets = GetClosestGameObjectWithEntry(object, ConditionValue1, (float)ConditionValue2) ? true : false; break; } - case CONDITION_OBJECT_ENTRY: + case CONDITION_OBJECT_ENTRY_GUID: { if (uint32(object->GetTypeId()) == ConditionValue1) - condMeets = (!ConditionValue2) || (object->GetEntry() == ConditionValue2); + { + condMeets = !ConditionValue2 || (object->GetEntry() == ConditionValue2); + + if (ConditionValue3) + { + switch (object->GetTypeId()) + { + case TYPEID_UNIT: + condMeets &= object->ToCreature()->GetDBTableGUIDLow() == ConditionValue3; + break; + case TYPEID_GAMEOBJECT: + condMeets &= object->ToGameObject()->GetDBTableGUIDLow() == ConditionValue3; + break; + } + } + } break; } case CONDITION_TYPE_MASK: @@ -419,7 +434,7 @@ uint32 Condition::GetSearcherTypeMaskForCondition() case CONDITION_NEAR_GAMEOBJECT: mask |= GRID_MAP_TYPE_MASK_ALL; break; - case CONDITION_OBJECT_ENTRY: + case CONDITION_OBJECT_ENTRY_GUID: switch (ConditionValue1) { case TYPEID_UNIT: @@ -1841,35 +1856,67 @@ bool ConditionMgr::isConditionTypeValid(Condition* cond) TC_LOG_ERROR("sql.sql", "NearGameObject condition has useless data in value3 (%u)!", cond->ConditionValue3); break; } - case CONDITION_OBJECT_ENTRY: + case CONDITION_OBJECT_ENTRY_GUID: { switch (cond->ConditionValue1) { case TYPEID_UNIT: if (cond->ConditionValue2 && !sObjectMgr->GetCreatureTemplate(cond->ConditionValue2)) { - TC_LOG_ERROR("sql.sql", "ObjectEntry condition has non existing creature template entry (%u), skipped", cond->ConditionValue2); + TC_LOG_ERROR("sql.sql", "ObjectEntryGuid condition has non existing creature template entry (%u), skipped", cond->ConditionValue2); return false; } + if (cond->ConditionValue3) + { + if (CreatureData const* creatureData = sObjectMgr->GetCreatureData(cond->ConditionValue3)) + { + if (cond->ConditionValue2 && creatureData->id != cond->ConditionValue2) + { + TC_LOG_ERROR("sql.sql", "ObjectEntryGuid condition has guid %u set but does not match creature entry (%u), skipped", cond->ConditionValue3, cond->ConditionValue2); + return false; + } + } + else + { + TC_LOG_ERROR("sql.sql", "ObjectEntryGuid condition has non existing creature guid (%u), skipped", cond->ConditionValue3); + return false; + } + } break; case TYPEID_GAMEOBJECT: if (cond->ConditionValue2 && !sObjectMgr->GetGameObjectTemplate(cond->ConditionValue2)) { - TC_LOG_ERROR("sql.sql", "ObjectEntry condition has non existing game object template entry (%u), skipped", cond->ConditionValue2); + TC_LOG_ERROR("sql.sql", "ObjectEntryGuid condition has non existing gameobject template entry (%u), skipped", cond->ConditionValue2); return false; } + if (cond->ConditionValue3) + { + if (GameObjectData const* goData = sObjectMgr->GetGOData(cond->ConditionValue3)) + { + if (cond->ConditionValue2 && goData->id != cond->ConditionValue2) + { + TC_LOG_ERROR("sql.sql", "ObjectEntryGuid condition has guid %u set but does not match gameobject entry (%u), skipped", cond->ConditionValue3, cond->ConditionValue2); + return false; + } + } + else + { + TC_LOG_ERROR("sql.sql", "ObjectEntryGuid condition has non existing gameobject guid (%u), skipped", cond->ConditionValue3); + return false; + } + } break; case TYPEID_PLAYER: case TYPEID_CORPSE: if (cond->ConditionValue2) - TC_LOG_ERROR("sql.sql", "ObjectEntry condition has useless data in value2 (%u)!", cond->ConditionValue2); + TC_LOG_ERROR("sql.sql", "ObjectEntryGuid condition has useless data in value2 (%u)!", cond->ConditionValue2); + if (cond->ConditionValue3) + TC_LOG_ERROR("sql.sql", "ObjectEntryGuid condition has useless data in value3 (%u)!", cond->ConditionValue3); break; default: - TC_LOG_ERROR("sql.sql", "ObjectEntry condition has wrong typeid set (%u), skipped", cond->ConditionValue1); + TC_LOG_ERROR("sql.sql", "ObjectEntryGuid condition has wrong typeid set (%u), skipped", cond->ConditionValue1); return false; } - if (cond->ConditionValue3) - TC_LOG_ERROR("sql.sql", "ObjectEntry condition has useless data in value3 (%u)!", cond->ConditionValue3); break; } case CONDITION_TYPE_MASK: diff --git a/src/server/game/Conditions/ConditionMgr.h b/src/server/game/Conditions/ConditionMgr.h index 9a48985b90d..317db5b2019 100644 --- a/src/server/game/Conditions/ConditionMgr.h +++ b/src/server/game/Conditions/ConditionMgr.h @@ -63,7 +63,7 @@ enum ConditionTypes CONDITION_QUEST_COMPLETE = 28, // quest_id 0 0 true if player has quest_id with all objectives complete, but not yet rewarded CONDITION_NEAR_CREATURE = 29, // creature entry distance 0 true if there is a creature of entry in range CONDITION_NEAR_GAMEOBJECT = 30, // gameobject entry distance 0 true if there is a gameobject of entry in range - CONDITION_OBJECT_ENTRY = 31, // TypeID entry 0 true if object is type TypeID and the entry is 0 or matches entry of the object + CONDITION_OBJECT_ENTRY_GUID = 31, // TypeID entry guid true if object is type TypeID and the entry is 0 or matches entry of the object or matches guid of the object CONDITION_TYPE_MASK = 32, // TypeMask 0 0 true if object is type object's TypeMask matches provided TypeMask CONDITION_RELATION_TO = 33, // ConditionTarget RelationType 0 true if object is in given relation with object specified by ConditionTarget CONDITION_REACTION_TO = 34, // ConditionTarget rankMask 0 true if object's reaction matches rankMask object specified by ConditionTarget diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 2a2795bba64..6a6caa72e76 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -1089,7 +1089,7 @@ void Creature::SelectLevel() float basedamage = stats->GenerateBaseDamage(cInfo); float weaponBaseMinDamage = basedamage; - float weaponBaseMaxDamage = basedamage * 1.5; + float weaponBaseMaxDamage = basedamage * 1.5f; SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, weaponBaseMinDamage); SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, weaponBaseMaxDamage); diff --git a/src/server/game/Entities/Creature/CreatureGroups.cpp b/src/server/game/Entities/Creature/CreatureGroups.cpp index 14a76ae07ce..f02543a60af 100644 --- a/src/server/game/Entities/Creature/CreatureGroups.cpp +++ b/src/server/game/Entities/Creature/CreatureGroups.cpp @@ -107,7 +107,7 @@ void FormationMgr::LoadCreatureFormations() if (group_member->leaderGUID != memberGUID) { group_member->follow_dist = fields[2].GetFloat(); - group_member->follow_angle = fields[3].GetFloat() * M_PI / 180; + group_member->follow_angle = fields[3].GetFloat() * float(M_PI) / 180; } else { @@ -218,7 +218,7 @@ void CreatureGroup::LeaderMoveTo(float x, float y, float z) if (!m_leader) return; - float pathangle = atan2(m_leader->GetPositionY() - y, m_leader->GetPositionX() - x); + float pathangle = std::atan2(m_leader->GetPositionY() - y, m_leader->GetPositionX() - x); for (CreatureGroupMemberType::iterator itr = m_members.begin(); itr != m_members.end(); ++itr) { @@ -229,9 +229,9 @@ void CreatureGroup::LeaderMoveTo(float x, float y, float z) if (itr->second->point_1) { if (m_leader->GetCurrentWaypointID() == itr->second->point_1) - itr->second->follow_angle = (2 * M_PI) - itr->second->follow_angle; + itr->second->follow_angle = (2 * float(M_PI)) - itr->second->follow_angle; if (m_leader->GetCurrentWaypointID() == itr->second->point_2) - itr->second->follow_angle = (2 * M_PI) + itr->second->follow_angle; + itr->second->follow_angle = (2 * float(M_PI)) + itr->second->follow_angle; } float angle = itr->second->follow_angle; diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index 71e223527f3..567ada4cccf 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -1270,7 +1270,7 @@ void GameObject::Use(Unit* user) // the object orientation + 1/2 pi // every slot will be on that straight line - float orthogonalOrientation = GetOrientation()+M_PI*0.5f; + float orthogonalOrientation = GetOrientation() + float(M_PI) * 0.5f; // find nearest slot bool found_free_slot = false; for (ChairSlotAndUser::iterator itr = ChairListSlots.begin(); itr != ChairListSlots.end(); ++itr) @@ -1835,7 +1835,7 @@ bool GameObject::IsInRange(float x, float y, float z, float radius) const float dx = x - GetPositionX(); float dy = y - GetPositionY(); float dz = z - GetPositionZ(); - float dist = sqrt(dx*dx + dy*dy); + float dist = std::sqrt(dx*dx + dy*dy); //! Check if the distance between the 2 objects is 0, can happen if both objects are on the same position. //! The code below this check wont crash if dist is 0 because 0/0 in float operations is valid, and returns infinite if (G3D::fuzzyEq(dist, 0.0f)) diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 623680dad7e..32a9496803d 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -1190,11 +1190,11 @@ bool Position::operator==(Position const &a) bool Position::HasInLine(WorldObject const* target, float width) const { - if (!HasInArc(M_PI, target)) + if (!HasInArc(float(M_PI), target)) return false; width += target->GetObjectSize(); float angle = GetRelativeAngle(target); - return fabs(sin(angle)) * GetExactDist2d(target->GetPositionX(), target->GetPositionY()) < width; + return std::fabs(std::sin(angle)) * GetExactDist2d(target->GetPositionX(), target->GetPositionY()) < width; } std::string Position::ToString() const @@ -1379,7 +1379,7 @@ InstanceScript* WorldObject::GetInstanceScript() 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); @@ -1602,7 +1602,7 @@ bool WorldObject::IsInRange3d(float x, float y, float z, float minRange, float m void Position::RelocateOffset(const Position & offset) { - m_positionX = GetPositionX() + (offset.GetPositionX() * std::cos(GetOrientation()) + offset.GetPositionY() * std::sin(GetOrientation() + M_PI)); + m_positionX = GetPositionX() + (offset.GetPositionX() * std::cos(GetOrientation()) + offset.GetPositionY() * std::sin(GetOrientation() + float(M_PI))); m_positionY = GetPositionY() + (offset.GetPositionY() * std::cos(GetOrientation()) + offset.GetPositionX() * std::sin(GetOrientation())); m_positionZ = GetPositionZ() + offset.GetPositionZ(); SetOrientation(GetOrientation() + offset.GetOrientation()); @@ -1633,8 +1633,8 @@ float Position::GetAngle(const float x, const float y) const float dx = x - GetPositionX(); float dy = y - GetPositionY(); - float ang = atan2(dy, dx); - ang = (ang >= 0) ? ang : 2 * M_PI + ang; + float ang = std::atan2(dy, dx); + ang = (ang >= 0) ? ang : 2 * float(M_PI) + ang; return ang; } @@ -1643,7 +1643,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 = std::cos(angle); @@ -1651,7 +1651,7 @@ void Position::GetSinCos(const float x, const float y, float &vsin, float &vcos) } else { - float dist = sqrt((dx*dx) + (dy*dy)); + float dist = std::sqrt((dx*dx) + (dy*dy)); vcos = dx / dist; vsin = dy / dist; } @@ -1671,8 +1671,8 @@ bool Position::HasInArc(float arc, const Position* obj, float border) const // move angle to range -pi ... +pi angle = NormalizeOrientation(angle); - if (angle > M_PI) - angle -= 2.0f*M_PI; + if (angle > float(M_PI)) + angle -= 2.0f * float(M_PI); float lborder = -1 * (arc/border); // in range -pi..0 float rborder = (arc/border); // in range 0..pi @@ -1706,7 +1706,7 @@ bool WorldObject::isInFront(WorldObject const* target, float arc) const bool WorldObject::isInBack(WorldObject const* target, float arc) const { - return !HasInArc(2 * M_PI - arc, target); + return !HasInArc(2 * float(M_PI) - arc, target); } void WorldObject::GetRandomPoint(const Position &pos, float distance, float &rand_x, float &rand_y, float &rand_z) const @@ -2002,7 +2002,7 @@ bool WorldObject::CanDetectStealthOf(WorldObject const* obj) const if (distance < combatReach) return true; - if (!HasInArc(M_PI, obj)) + if (!HasInArc(float(M_PI), obj)) return false; GameObject const* go = ToGameObject(); @@ -2670,7 +2670,7 @@ void WorldObject::GetNearPoint(WorldObject const* /*searcher*/, float &x, float float first_z = z; // loop in a circle to look for a point in LoS using small steps - for (float angle = M_PI / 8; angle < M_PI * 2; angle += M_PI / 8) + for (float angle = float(M_PI) / 8; angle < float(M_PI) * 2; angle += float(M_PI) / 8) { GetNearPoint2D(x, y, distance2d + searcher_size, absAngle + angle); z = GetPositionZ(); @@ -2740,20 +2740,20 @@ void WorldObject::MovePosition(Position &pos, float dist, float angle) ground = GetMap()->GetHeight(GetPhaseMask(), destx, desty, MAX_HEIGHT, true); floor = GetMap()->GetHeight(GetPhaseMask(), destx, desty, pos.m_positionZ, true); - 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) + if (std::fabs(pos.m_positionZ - destz) > 6) { destx -= step * std::cos(angle); desty -= step * std::sin(angle); ground = GetMap()->GetHeight(GetPhaseMask(), destx, desty, MAX_HEIGHT, true); floor = GetMap()->GetHeight(GetPhaseMask(), destx, desty, pos.m_positionZ, true); - 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 @@ -2774,7 +2774,7 @@ float NormalizeZforCollision(WorldObject* obj, float x, float y, float z) { float ground = obj->GetMap()->GetHeight(obj->GetPhaseMask(), x, y, MAX_HEIGHT, true); float floor = obj->GetMap()->GetHeight(obj->GetPhaseMask(), x, y, z + 2.0f, true); - float helper = fabs(ground - z) <= fabs(floor - z) ? ground : floor; + float helper = std::fabs(ground - z) <= std::fabs(floor - z) ? ground : floor; if (z > helper) // must be above ground { if (Unit* unit = obj->ToUnit()) @@ -2789,7 +2789,7 @@ float NormalizeZforCollision(WorldObject* obj, float x, float y, float z) if (liquid_status.level > z) // z is underwater return z; else - return fabs(liquid_status.level - z) <= fabs(helper - z) ? liquid_status.level : helper; + return std::fabs(liquid_status.level - z) <= std::fabs(helper - z) ? liquid_status.level : helper; } } return helper; @@ -2818,7 +2818,7 @@ void WorldObject::MovePositionToFirstCollision(Position &pos, float dist, float // move back a bit destx -= CONTACT_DISTANCE * std::cos(angle); desty -= CONTACT_DISTANCE * std::sin(angle); - dist = sqrt((pos.m_positionX - destx)*(pos.m_positionX - destx) + (pos.m_positionY - desty)*(pos.m_positionY - desty)); + dist = std::sqrt((pos.m_positionX - destx)*(pos.m_positionX - destx) + (pos.m_positionY - desty)*(pos.m_positionY - desty)); } // check dynamic collision @@ -2829,7 +2829,7 @@ void WorldObject::MovePositionToFirstCollision(Position &pos, float dist, float { destx -= CONTACT_DISTANCE * std::cos(angle); desty -= CONTACT_DISTANCE * std::sin(angle); - dist = sqrt((pos.m_positionX - destx)*(pos.m_positionX - destx) + (pos.m_positionY - desty)*(pos.m_positionY - desty)); + dist = std::sqrt((pos.m_positionX - destx)*(pos.m_positionX - destx) + (pos.m_positionY - desty)*(pos.m_positionY - desty)); } float step = dist / 10.0f; @@ -2837,7 +2837,7 @@ void WorldObject::MovePositionToFirstCollision(Position &pos, float dist, float 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 * std::cos(angle); desty -= step * std::sin(angle); diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index 108eb3ce0b7..a44c9fa2866 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -263,7 +263,7 @@ class Object void BuildFieldsUpdate(Player*, UpdateDataMapType &) const; void SetFieldNotifyFlag(uint16 flag) { _fieldNotifyFlags |= flag; } - void RemoveFieldNotifyFlag(uint16 flag) { _fieldNotifyFlags &= ~flag; } + void RemoveFieldNotifyFlag(uint16 flag) { _fieldNotifyFlags &= uint16(~flag); } // FG: some hacky helpers void ForceValuesUpdateAtIndex(uint32); @@ -412,19 +412,19 @@ struct Position float GetExactDist2dSq(float x, float y) const { float dx = m_positionX - x; float dy = m_positionY - y; return dx*dx + dy*dy; } float GetExactDist2d(const float x, const float y) const - { return sqrt(GetExactDist2dSq(x, y)); } + { return std::sqrt(GetExactDist2dSq(x, y)); } float GetExactDist2dSq(Position const* pos) const { float dx = m_positionX - pos->m_positionX; float dy = m_positionY - pos->m_positionY; return dx*dx + dy*dy; } float GetExactDist2d(Position const* pos) const - { return sqrt(GetExactDist2dSq(pos)); } + { return std::sqrt(GetExactDist2dSq(pos)); } float GetExactDistSq(float x, float y, float z) const { float dz = m_positionZ - z; return GetExactDist2dSq(x, y) + dz*dz; } float GetExactDist(float x, float y, float z) const - { return sqrt(GetExactDistSq(x, y, z)); } + { return std::sqrt(GetExactDistSq(x, y, z)); } float GetExactDistSq(Position const* pos) const { float dx = m_positionX - pos->m_positionX; float dy = m_positionY - pos->m_positionY; float dz = m_positionZ - pos->m_positionZ; return dx*dx + dy*dy + dz*dz; } float GetExactDist(Position const* pos) const - { return sqrt(GetExactDistSq(pos)); } + { return std::sqrt(GetExactDistSq(pos)); } void GetPositionOffsetTo(Position const & endPos, Position & retOffset) const; @@ -455,11 +455,11 @@ struct Position if (o < 0) { float mod = o *-1; - mod = fmod(mod, 2.0f * static_cast<float>(M_PI)); + mod = std::fmod(mod, 2.0f * static_cast<float>(M_PI)); mod = -mod + 2.0f * static_cast<float>(M_PI); return mod; } - return fmod(o, 2.0f * static_cast<float>(M_PI)); + return std::fmod(o, 2.0f * static_cast<float>(M_PI)); } }; ByteBuffer& operator>>(ByteBuffer& buf, Position::PositionXYZOStreamer const& streamer); @@ -718,8 +718,8 @@ class WorldObject : public Object, public WorldLocation bool IsInRange(WorldObject const* obj, float minRange, float maxRange, bool is3D = true) const; bool IsInRange2d(float x, float y, float minRange, float maxRange) const; bool IsInRange3d(float x, float y, float z, float minRange, float maxRange) const; - bool isInFront(WorldObject const* target, float arc = M_PI) const; - bool isInBack(WorldObject const* target, float arc = M_PI) const; + bool isInFront(WorldObject const* target, float arc = float(M_PI)) const; + bool isInBack(WorldObject const* target, float arc = float(M_PI)) const; bool IsInBetween(WorldObject const* obj1, WorldObject const* obj2, float size = 0) const; diff --git a/src/server/game/Entities/Object/ObjectPosSelector.cpp b/src/server/game/Entities/Object/ObjectPosSelector.cpp index fa7c5dffafa..da2049ac62f 100644 --- a/src/server/game/Entities/Object/ObjectPosSelector.cpp +++ b/src/server/game/Entities/Object/ObjectPosSelector.cpp @@ -21,7 +21,7 @@ ObjectPosSelector::ObjectPosSelector(float x, float y, float size, float dist) : m_center_x(x), m_center_y(y), m_size(size), m_dist(dist) { - m_anglestep = acos(m_dist/(m_dist+2*m_size)); + m_anglestep = std::acos(m_dist/(m_dist+2*m_size)); m_nextUsedPos[USED_POS_PLUS] = m_UsedPosLists[USED_POS_PLUS].end(); m_nextUsedPos[USED_POS_MINUS] = m_UsedPosLists[USED_POS_MINUS].end(); diff --git a/src/server/game/Entities/Object/ObjectPosSelector.h b/src/server/game/Entities/Object/ObjectPosSelector.h index 5bac179880f..44b85dae3dd 100644 --- a/src/server/game/Entities/Object/ObjectPosSelector.h +++ b/src/server/game/Entities/Object/ObjectPosSelector.h @@ -60,10 +60,10 @@ struct ObjectPosSelector float angle_step2 = GetAngle(nextUsedPos.second); float next_angle = nextUsedPos.first; - if (nextUsedPos.second.sign * sign < 0) // last node from diff. list (-pi+alpha) - next_angle = 2*M_PI-next_angle; // move to positive + if (nextUsedPos.second.sign * sign < 0) // last node from diff. list (-pi+alpha) + next_angle = 2 * float(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 @@ -105,7 +105,7 @@ struct ObjectPosSelector // next possible angle angle = m_smallStepAngle[uptype] + m_anglestep * sign; - if (fabs(angle) > M_PI) + if (std::fabs(angle) > float(M_PI)) { m_smallStepOk[uptype] = false; return false; @@ -113,7 +113,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; @@ -136,7 +136,7 @@ struct ObjectPosSelector UsedPosList::value_type const* nextUsedPos(UsedPosType uptype); // angle from used pos to next possible free pos - float GetAngle(UsedPos const& usedPos) const { return acos(m_dist/(usedPos.dist+usedPos.size+m_size)); } + float GetAngle(UsedPos const& usedPos) const { return std::acos(m_dist/(usedPos.dist+usedPos.size+m_size)); } float m_center_x; float m_center_y; diff --git a/src/server/game/Entities/Pet/PetDefines.h b/src/server/game/Entities/Pet/PetDefines.h index f590bef233e..67435c30577 100644 --- a/src/server/game/Entities/Pet/PetDefines.h +++ b/src/server/game/Entities/Pet/PetDefines.h @@ -75,6 +75,6 @@ enum PetTalk }; #define PET_FOLLOW_DIST 1.0f -#define PET_FOLLOW_ANGLE (M_PI/2) +#define PET_FOLLOW_ANGLE float(M_PI/2) #endif diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index a23b9b4b0e2..12050c482f7 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -1668,7 +1668,7 @@ void Player::Update(uint32 p_time) } } //120 degrees of radiant range - else if (!HasInArc(2*M_PI/3, victim)) + else if (!HasInArc(2 * float(M_PI) / 3, victim)) { setAttackTimer(BASE_ATTACK, 100); if (m_swingErrorMsg != 2) // send single time (client auto repeat) @@ -1696,7 +1696,7 @@ void Player::Update(uint32 p_time) { if (!IsWithinMeleeRange(victim)) setAttackTimer(OFF_ATTACK, 100); - else if (!HasInArc(2*M_PI/3, victim)) + else if (!HasInArc(2 * float(M_PI) / 3, victim)) setAttackTimer(OFF_ATTACK, 100); else { @@ -2660,7 +2660,7 @@ void Player::Regenerate(Powers power) return; addvalue += m_powerFraction[powerIndex]; - uint32 integerValue = uint32(fabs(addvalue)); + uint32 integerValue = uint32(std::fabs(addvalue)); if (addvalue < 0.0f) { @@ -7107,7 +7107,7 @@ bool Player::RewardHonor(Unit* victim, uint32 groupsize, int32 honor, bool pvpto else victim_guid = 0; // Don't show HK: <rank> message, only log. - honor_f = ceil(Trinity::Honor::hk_honor_at_level_f(k_level) * (v_level - k_grey) / (k_level - k_grey)); + honor_f = std::ceil(Trinity::Honor::hk_honor_at_level_f(k_level) * (v_level - k_grey) / (k_level - k_grey)); // count the number of playerkills in one day ApplyModUInt32Value(PLAYER_FIELD_KILLS, 1, true); @@ -9087,7 +9087,7 @@ void Player::SendLoot(uint64 guid, LootType loot_type) loot->FillLoot(1, LootTemplates_Creature, this, true); // It may need a better formula // Now it works like this: lvl10: ~6copper, lvl70: ~9silver - bones->loot.gold = uint32(urand(50, 150) * 0.016f * pow(float(pLevel)/5.76f, 2.5f) * sWorld->getRate(RATE_DROP_MONEY)); + bones->loot.gold = uint32(urand(50, 150) * 0.016f * std::pow(float(pLevel) / 5.76f, 2.5f) * sWorld->getRate(RATE_DROP_MONEY)); } if (bones->lootRecipient != this) @@ -11830,39 +11830,42 @@ InventoryResult Player::CanUseItem(ItemTemplate const* proto) const { // Used by group, function NeedBeforeGreed, to know if a prototype can be used by a player - if (proto) - { - if ((proto->Flags2 & ITEM_FLAGS_EXTRA_HORDE_ONLY) && GetTeam() != HORDE) - return EQUIP_ERR_CANT_EQUIP_EVER; + if (!proto) + return EQUIP_ERR_ITEM_NOT_FOUND; - if ((proto->Flags2 & ITEM_FLAGS_EXTRA_ALLIANCE_ONLY) && GetTeam() != ALLIANCE) - return EQUIP_ERR_CANT_EQUIP_EVER; + if ((proto->Flags2 & ITEM_FLAGS_EXTRA_HORDE_ONLY) && GetTeam() != HORDE) + return EQUIP_ERR_CANT_EQUIP_EVER; - if ((proto->AllowableClass & getClassMask()) == 0 || (proto->AllowableRace & getRaceMask()) == 0) - return EQUIP_ERR_CANT_EQUIP_EVER; + if ((proto->Flags2 & ITEM_FLAGS_EXTRA_ALLIANCE_ONLY) && GetTeam() != ALLIANCE) + return EQUIP_ERR_CANT_EQUIP_EVER; - if (proto->RequiredSkill != 0) - { - if (GetSkillValue(proto->RequiredSkill) == 0) - return EQUIP_ERR_PROFICIENCY_NEEDED; - else if (GetSkillValue(proto->RequiredSkill) < proto->RequiredSkillRank) - return EQUIP_ERR_CANT_EQUIP_SKILL; - } + if ((proto->AllowableClass & getClassMask()) == 0 || (proto->AllowableRace & getRaceMask()) == 0) + return EQUIP_ERR_CANT_EQUIP_EVER; - if (proto->RequiredSpell != 0 && !HasSpell(proto->RequiredSpell)) - return EQUIP_ERR_PROFICIENCY_NEEDED; + if (proto->RequiredSkill != 0) + { + if (GetSkillValue(proto->RequiredSkill) == 0) + return EQUIP_ERR_NO_REQUIRED_PROFICIENCY; + else if (GetSkillValue(proto->RequiredSkill) < proto->RequiredSkillRank) + return EQUIP_ERR_CANT_EQUIP_SKILL; + } - if (getLevel() < proto->RequiredLevel) - return EQUIP_ERR_CANT_EQUIP_LEVEL_I; + if (proto->RequiredSpell != 0 && !HasSpell(proto->RequiredSpell)) + return EQUIP_ERR_PROFICIENCY_NEEDED; - // If World Event is not active, prevent using event dependant items - if (proto->HolidayId && !IsHolidayActive((HolidayIds)proto->HolidayId)) - return EQUIP_ERR_CLIENT_LOCKED_OUT; + if (getLevel() < proto->RequiredLevel) + return EQUIP_ERR_CANT_EQUIP_LEVEL_I; - return EQUIP_ERR_OK; - } + // If World Event is not active, prevent using event dependant items + if (proto->HolidayId && !IsHolidayActive((HolidayIds)proto->HolidayId)) + return EQUIP_ERR_CLIENT_LOCKED_OUT; - return EQUIP_ERR_ITEM_NOT_FOUND; + // learning (recipes, mounts, pets, etc.) + if (proto->Spells[0].SpellId == 483 || proto->Spells[0].SpellId == 55884) + if (HasSpell(proto->Spells[1].SpellId)) + return EQUIP_ERR_NONE; + + return EQUIP_ERR_OK; } InventoryResult Player::CanRollForItemInLFG(ItemTemplate const* proto, WorldObject const* lootedObject) const diff --git a/src/server/game/Entities/Transport/Transport.cpp b/src/server/game/Entities/Transport/Transport.cpp index 4d4b28d6082..40e073a1500 100644 --- a/src/server/game/Entities/Transport/Transport.cpp +++ b/src/server/game/Entities/Transport/Transport.cpp @@ -206,7 +206,7 @@ void Transport::Update(uint32 diff) G3D::Vector3 pos, dir; _currentFrame->Spline->evaluate_percent(_currentFrame->Index, t, pos); _currentFrame->Spline->evaluate_derivative(_currentFrame->Index, t, dir); - UpdatePosition(pos.x, pos.y, pos.z, atan2(dir.y, dir.x) + M_PI); + UpdatePosition(pos.x, pos.y, pos.z, std::atan2(dir.y, dir.x) + float(M_PI)); } else { diff --git a/src/server/game/Entities/Unit/StatSystem.cpp b/src/server/game/Entities/Unit/StatSystem.cpp index 6ef74785d16..541a7c711ec 100644 --- a/src/server/game/Entities/Unit/StatSystem.cpp +++ b/src/server/game/Entities/Unit/StatSystem.cpp @@ -750,7 +750,7 @@ void Player::UpdateManaRegen() // SpiritRegen(SPI, INT, LEVEL) = (0.001 + (SPI x sqrt(INT) x BASE_REGEN[LEVEL])) x 5 if (GetStat(STAT_INTELLECT) > 0.0f) - spirit_regen *= sqrt(GetStat(STAT_INTELLECT)); + spirit_regen *= std::sqrt(GetStat(STAT_INTELLECT)); // CombatRegen = 5% of Base Mana float base_regen = GetCreateMana() * 0.01f + GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_POWER_REGEN, POWER_MANA) / 5.0f; diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 9b4e7e5ac45..6742852a481 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -62,7 +62,7 @@ #include "MovementStructures.h" #include "WorldSession.h" -#include <math.h> +#include <cmath> float baseMoveSpeed[MAX_MOVE_TYPE] = { @@ -1322,7 +1322,7 @@ void Unit::DealMeleeDamage(CalcDamageInfo* damageInfo, bool durabilityLoss) // If this is a creature and it attacks from behind it has a probability to daze it's victim if ((damageInfo->hitOutCome == MELEE_HIT_CRIT || damageInfo->hitOutCome == MELEE_HIT_CRUSHING || damageInfo->hitOutCome == MELEE_HIT_NORMAL || damageInfo->hitOutCome == MELEE_HIT_GLANCING) && - GetTypeId() != TYPEID_PLAYER && !ToCreature()->IsControlledByPlayer() && !victim->HasInArc(M_PI, this) + GetTypeId() != TYPEID_PLAYER && !ToCreature()->IsControlledByPlayer() && !victim->HasInArc(float(M_PI), this) && (victim->GetTypeId() == TYPEID_PLAYER || !victim->ToCreature()->isWorldBoss())&& !victim->IsVehicle()) { // -probability is between 0% and 40% @@ -1336,7 +1336,7 @@ void Unit::DealMeleeDamage(CalcDamageInfo* damageInfo, bool durabilityLoss) uint32 VictimDefense = victim->GetMaxSkillValueForLevel(this); uint32 AttackerMeleeSkill = GetMaxSkillValueForLevel(); - Probability *= AttackerMeleeSkill/(float)VictimDefense*0.16; + Probability *= AttackerMeleeSkill/(float)VictimDefense*0.16f; if (Probability < 0) Probability = 0; @@ -1456,7 +1456,7 @@ uint32 Unit::CalcArmorReducedDamage(Unit* victim, const uint32 damage, SpellInfo for (AuraEffectList::const_iterator j = resIgnoreAuras.begin(); j != resIgnoreAuras.end(); ++j) { if ((*j)->GetMiscValue() & SPELL_SCHOOL_MASK_NORMAL) - armor = floor(AddPct(armor, -(*j)->GetAmount())); + armor = std::floor(AddPct(armor, -(*j)->GetAmount())); } // Apply Player CR_ARMOR_PENETRATION rating @@ -1544,7 +1544,7 @@ uint32 Unit::CalcSpellResistance(Unit* victim, SpellSchoolMask schoolMask, Spell 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; } @@ -1932,7 +1932,7 @@ MeleeHitOutcome Unit::RollMeleeOutcomeAgainst (const Unit* victim, WeaponAttackT // Dodge chance // only players can't dodge if attacker is behind - if (victim->GetTypeId() == TYPEID_PLAYER && !victim->HasInArc(M_PI, this) && !victim->HasAuraType(SPELL_AURA_IGNORE_HIT_DIRECTION)) + if (victim->GetTypeId() == TYPEID_PLAYER && !victim->HasInArc(float(M_PI), this) && !victim->HasAuraType(SPELL_AURA_IGNORE_HIT_DIRECTION)) { TC_LOG_DEBUG("entities.unit", "RollMeleeOutcomeAgainst: attack came from behind and victim was a player."); } @@ -1961,7 +1961,7 @@ MeleeHitOutcome Unit::RollMeleeOutcomeAgainst (const Unit* victim, WeaponAttackT // parry & block chances // check if attack comes from behind, nobody can parry or block if attacker is behind - if (!victim->HasInArc(M_PI, this) && !victim->HasAuraType(SPELL_AURA_IGNORE_HIT_DIRECTION)) + if (!victim->HasInArc(float(M_PI), this) && !victim->HasAuraType(SPELL_AURA_IGNORE_HIT_DIRECTION)) TC_LOG_DEBUG("entities.unit", "RollMeleeOutcomeAgainst: attack came from behind."); else { @@ -2139,7 +2139,7 @@ bool Unit::isSpellBlocked(Unit* victim, SpellInfo const* spellProto, WeaponAttac if (spellProto && spellProto->Attributes & SPELL_ATTR0_IMPOSSIBLE_DODGE_PARRY_BLOCK) return false; - if (victim->HasAuraType(SPELL_AURA_IGNORE_HIT_DIRECTION) || victim->HasInArc(M_PI, this)) + if (victim->HasAuraType(SPELL_AURA_IGNORE_HIT_DIRECTION) || victim->HasInArc(float(M_PI), this)) { // Check creatures flags_extra for disable block if (victim->GetTypeId() == TYPEID_UNIT && @@ -2259,7 +2259,7 @@ SpellMissInfo Unit::MeleeSpellHitResult(Unit* victim, SpellInfo const* spellInfo canDodge = false; // only if in front - if (victim->HasInArc(M_PI, this) || victim->HasAuraType(SPELL_AURA_IGNORE_HIT_DIRECTION)) + if (victim->HasInArc(float(M_PI), this) || victim->HasAuraType(SPELL_AURA_IGNORE_HIT_DIRECTION)) { int32 deflect_chance = victim->GetTotalAuraModifier(SPELL_AURA_DEFLECT_SPELLS) * 100; tmp += deflect_chance; @@ -2270,7 +2270,7 @@ SpellMissInfo Unit::MeleeSpellHitResult(Unit* victim, SpellInfo const* spellInfo } // Check for attack from behind - if (!victim->HasInArc(M_PI, this)) + if (!victim->HasInArc(float(M_PI), this)) { if (!victim->HasAuraType(SPELL_AURA_IGNORE_HIT_DIRECTION)) { @@ -2425,7 +2425,7 @@ SpellMissInfo Unit::MagicSpellHitResult(Unit* victim, SpellInfo const* spellInfo return SPELL_MISS_RESIST; // cast by caster in front of victim - if (victim->HasInArc(M_PI, this) || victim->HasAuraType(SPELL_AURA_IGNORE_HIT_DIRECTION)) + if (victim->HasInArc(float(M_PI), this) || victim->HasAuraType(SPELL_AURA_IGNORE_HIT_DIRECTION)) { int32 deflect_chance = victim->GetTotalAuraModifier(SPELL_AURA_DEFLECT_SPELLS) * 100; tmp += deflect_chance; @@ -2918,7 +2918,7 @@ bool Unit::isInFrontInMap(Unit const* target, float distance, float arc) const bool Unit::isInBackInMap(Unit const* target, float distance, float arc) const { - return IsWithinDistInMap(target, distance) && !HasInArc(2 * M_PI - arc, target); + return IsWithinDistInMap(target, distance) && !HasInArc(2 * float(M_PI) - arc, target); } bool Unit::isInAccessiblePlaceFor(Creature const* c) const @@ -9901,7 +9901,7 @@ float Unit::GetPPMProcChance(uint32 WeaponSpeed, float PPM, const SpellInfo* spe if (Player* modOwner = GetSpellModOwner()) modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_PROC_PER_MINUTE, PPM); - return floor((WeaponSpeed * PPM) / 600.0f); // result is chance in percents (probability = Speed_in_sec * (PPM / 60)) + return std::floor((WeaponSpeed * PPM) / 600.0f); // result is chance in percents (probability = Speed_in_sec * (PPM / 60)) } void Unit::Mount(uint32 mount, uint32 VehicleId, uint32 creatureEntry) @@ -15232,7 +15232,7 @@ uint32 Unit::GetModelForTotem(PlayerTotemType totemType) void Unit::JumpTo(float speedXY, float speedZ, bool forward) { - float angle = forward ? 0 : M_PI; + float angle = forward ? 0 : float(M_PI); if (GetTypeId() == TYPEID_UNIT) GetMotionMaster()->MoveJumpTo(angle, speedXY, speedZ); else diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index d80b4697f48..b9d3a287456 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -1919,8 +1919,8 @@ class Unit : public WorldObject uint32 CalculateDamage(WeaponAttackType attType, bool normalized, bool addTotalPct); float GetAPMultiplier(WeaponAttackType attType, bool normalized); - bool isInFrontInMap(Unit const* target, float distance, float arc = M_PI) const; - bool isInBackInMap(Unit const* target, float distance, float arc = M_PI) const; + bool isInFrontInMap(Unit const* target, float distance, float arc = float(M_PI)) const; + bool isInBackInMap(Unit const* target, float distance, float arc = float(M_PI)) const; // Visibility system bool IsVisible() const; diff --git a/src/server/game/Grids/GridDefines.h b/src/server/game/Grids/GridDefines.h index 9ed8549e9a1..04973237365 100644 --- a/src/server/game/Grids/GridDefines.h +++ b/src/server/game/Grids/GridDefines.h @@ -201,8 +201,8 @@ namespace Trinity int x_val = int(x_offset + CENTER_GRID_CELL_ID + 0.5f); int y_val = int(y_offset + CENTER_GRID_CELL_ID + 0.5f); - x_off = (float(x_offset) - x_val + CENTER_GRID_CELL_ID) * SIZE_OF_GRID_CELL; - y_off = (float(y_offset) - y_val + CENTER_GRID_CELL_ID) * SIZE_OF_GRID_CELL; + x_off = (float(x_offset) - float(x_val) + CENTER_GRID_CELL_ID) * SIZE_OF_GRID_CELL; + y_off = (float(y_offset) - float(y_val) + CENTER_GRID_CELL_ID) * SIZE_OF_GRID_CELL; return CellCoord(x_val, y_val); } diff --git a/src/server/game/Handlers/MiscHandler.cpp b/src/server/game/Handlers/MiscHandler.cpp index c9891de3c16..1162622af60 100644 --- a/src/server/game/Handlers/MiscHandler.cpp +++ b/src/server/game/Handlers/MiscHandler.cpp @@ -879,9 +879,9 @@ void WorldSession::HandleAreaTriggerOpcode(WorldPacket& recvData) float dz = player->GetPositionZ() - atEntry->z; float dx = rotPlayerX - atEntry->x; float dy = rotPlayerY - atEntry->y; - if ((fabs(dx) > atEntry->box_x / 2 + delta) || - (fabs(dy) > atEntry->box_y / 2 + delta) || - (fabs(dz) > atEntry->box_z / 2 + delta)) + if ((std::fabs(dx) > atEntry->box_x / 2 + delta) || + (std::fabs(dy) > atEntry->box_y / 2 + delta) || + (std::fabs(dz) > atEntry->box_z / 2 + delta)) { TC_LOG_DEBUG("network", "HandleAreaTriggerOpcode: Player '%s' (GUID: %u) too far (1/2 box X: %f 1/2 box Y: %f 1/2 box Z: %f rotatedPlayerX: %f rotatedPlayerY: %f dZ:%f), ignore Area Trigger ID: %u", player->GetName().c_str(), player->GetGUIDLow(), atEntry->box_x/2, atEntry->box_y/2, atEntry->box_z/2, rotPlayerX, rotPlayerY, dz, triggerId); diff --git a/src/server/game/Handlers/MovementHandler.cpp b/src/server/game/Handlers/MovementHandler.cpp index dabe40e427e..b59f9aca943 100644 --- a/src/server/game/Handlers/MovementHandler.cpp +++ b/src/server/game/Handlers/MovementHandler.cpp @@ -479,7 +479,7 @@ void WorldSession::HandleForceSpeedChangeAck(WorldPacket &recvData) return; } - if (!_player->GetTransport() && fabs(_player->GetSpeed(move_type) - newspeed) > 0.01f) + if (!_player->GetTransport() && std::fabs(_player->GetSpeed(move_type) - newspeed) > 0.01f) { if (_player->GetSpeed(move_type) > newspeed) // must be greater - just correct { diff --git a/src/server/game/Loot/LootMgr.h b/src/server/game/Loot/LootMgr.h index 09809d50b10..09905572aae 100644 --- a/src/server/game/Loot/LootMgr.h +++ b/src/server/game/Loot/LootMgr.h @@ -136,7 +136,7 @@ struct LootStoreItem // Constructor, converting ChanceOrQuestChance -> (chance, needs_quest) // displayid is filled in IsValid() which must be called after LootStoreItem(uint32 _itemid, float _chanceOrQuestChance, uint16 _lootmode, uint8 _group, int32 _mincountOrRef, uint8 _maxcount) - : itemid(_itemid), chance(fabs(_chanceOrQuestChance)), mincountOrRef(_mincountOrRef), lootmode(_lootmode), + : itemid(_itemid), chance(std::fabs(_chanceOrQuestChance)), mincountOrRef(_mincountOrRef), lootmode(_lootmode), group(_group), needs_quest(_chanceOrQuestChance < 0), maxcount(_maxcount) { } diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 61773656642..31b16309fcd 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -2171,7 +2171,7 @@ float Map::GetHeight(float x, float y, float z, bool checkVMap /*= true*/, float // we are already under the surface or vmap height above map heigt // or if the distance of the vmap height is less the land height distance - if (z < mapHeight || vmapHeight > mapHeight || fabs(mapHeight-z) > fabs(vmapHeight-z)) + if (z < mapHeight || vmapHeight > mapHeight || std::fabs(mapHeight - z) > std::fabs(vmapHeight - z)) return vmapHeight; else return mapHeight; // better use .map surface height diff --git a/src/server/game/Maps/TransportMgr.cpp b/src/server/game/Maps/TransportMgr.cpp index ba7d3784157..7df509a6d21 100644 --- a/src/server/game/Maps/TransportMgr.cpp +++ b/src/server/game/Maps/TransportMgr.cpp @@ -139,7 +139,7 @@ void TransportMgr::GeneratePath(GameObjectTemplate const* goInfo, TransportTempl KeyFrame k(node_i); G3D::Vector3 h; orientationSpline.evaluate_derivative(i + 1, 0.0f, h); - k.InitialOrientation = Position::NormalizeOrientation(atan2(h.y, h.x) + M_PI); + k.InitialOrientation = Position::NormalizeOrientation(std::atan2(h.y, h.x) + float(M_PI)); keyFrames.push_back(k); splinePath.push_back(G3D::Vector3(node_i.x, node_i.y, node_i.z)); @@ -213,7 +213,7 @@ void TransportMgr::GeneratePath(GameObjectTemplate const* goInfo, TransportTempl for (size_t j = start; j < i + extra; ++j) { keyFrames[j].Index = j - start + 1; - keyFrames[j].DistFromPrev = spline->length(j - start, j + 1 - start); + keyFrames[j].DistFromPrev = float(spline->length(j - start, j + 1 - start)); if (j > 0) keyFrames[j - 1].NextDistFromPrev = keyFrames[j].DistFromPrev; keyFrames[j].Spline = spline; @@ -276,22 +276,22 @@ void TransportMgr::GeneratePath(GameObjectTemplate const* goInfo, TransportTempl if (keyFrames[i].DistSinceStop < keyFrames[i].DistUntilStop) // is still accelerating { // calculate accel+brake time for this short segment - float segment_time = 2.0f * sqrt((keyFrames[i].DistUntilStop + keyFrames[i].DistSinceStop) / accel); + float segment_time = 2.0f * std::sqrt((keyFrames[i].DistUntilStop + keyFrames[i].DistSinceStop) / accel); // substract acceleration time - keyFrames[i].TimeTo = segment_time - sqrt(2 * keyFrames[i].DistSinceStop / accel); + keyFrames[i].TimeTo = segment_time - std::sqrt(2 * keyFrames[i].DistSinceStop / accel); } else // slowing down - keyFrames[i].TimeTo = sqrt(2 * keyFrames[i].DistUntilStop / accel); + keyFrames[i].TimeTo = std::sqrt(2 * keyFrames[i].DistUntilStop / accel); } else if (keyFrames[i].DistSinceStop < accel_dist) // still accelerating (but will reach full speed) { // calculate accel + cruise + brake time for this long segment float segment_time = (keyFrames[i].DistUntilStop + keyFrames[i].DistSinceStop) / speed + (speed / accel); // substract acceleration time - keyFrames[i].TimeTo = segment_time - sqrt(2 * keyFrames[i].DistSinceStop / accel); + keyFrames[i].TimeTo = segment_time - std::sqrt(2 * keyFrames[i].DistSinceStop / accel); } else if (keyFrames[i].DistUntilStop < accel_dist) // already slowing down (but reached full speed) - keyFrames[i].TimeTo = sqrt(2 * keyFrames[i].DistUntilStop / accel); + keyFrames[i].TimeTo = std::sqrt(2 * keyFrames[i].DistUntilStop / accel); else // at full speed keyFrames[i].TimeTo = (keyFrames[i].DistUntilStop / speed) + (0.5f * speed / accel); } diff --git a/src/server/game/Movement/MotionMaster.cpp b/src/server/game/Movement/MotionMaster.cpp index 72bb0e1d56e..c0d20c20639 100644 --- a/src/server/game/Movement/MotionMaster.cpp +++ b/src/server/game/Movement/MotionMaster.cpp @@ -345,7 +345,7 @@ void MotionMaster::MoveKnockbackFrom(float srcX, float srcY, float speedXY, floa float dist = 2 * moveTimeHalf * speedXY; float max_height = -Movement::computeFallElevation(moveTimeHalf, false, -speedZ); - _owner->GetNearPoint(_owner, x, y, z, _owner->GetObjectSize(), dist, _owner->GetAngle(srcX, srcY) + M_PI); + _owner->GetNearPoint(_owner, x, y, z, _owner->GetObjectSize(), dist, _owner->GetAngle(srcX, srcY) + float(M_PI)); Movement::MoveSplineInit init(_owner); init.MoveTo(x, y, z); @@ -399,7 +399,7 @@ void MotionMaster::MoveFall(uint32 id /*=0*/) } // Abort too if the ground is very near - if (fabs(_owner->GetPositionZ() - tz) < 0.1f) + if (std::fabs(_owner->GetPositionZ() - tz) < 0.1f) return; if (_owner->GetTypeId() == TYPEID_PLAYER) diff --git a/src/server/game/Movement/MovementGenerators/RandomMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/RandomMovementGenerator.cpp index 95c342b70b3..dbe8c8b0329 100644 --- a/src/server/game/Movement/MovementGenerators/RandomMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/RandomMovementGenerator.cpp @@ -61,7 +61,7 @@ void RandomMovementGenerator<Creature>::_setRandomLocation(Creature* creature) if (is_air_ok) // 3D system above ground and above water (flying mode) { // Limit height change - const float distanceZ = float(rand_norm()) * sqrtf(travelDistZ)/2.0f; + const float distanceZ = float(rand_norm()) * std::sqrt(travelDistZ)/2.0f; destZ = respZ + distanceZ; float levelZ = map->GetWaterOrGroundLevel(destX, destY, destZ-2.0f); @@ -73,24 +73,24 @@ void RandomMovementGenerator<Creature>::_setRandomLocation(Creature* creature) else // 2D only { // 10.0 is the max that vmap high can check (MAX_CAN_FALL_DISTANCE) - travelDistZ = travelDistZ >= 100.0f ? 10.0f : sqrtf(travelDistZ); + travelDistZ = travelDistZ >= 100.0f ? 10.0f : std::sqrt(travelDistZ); // The fastest way to get an accurate result 90% of the time. // Better result can be obtained like 99% accuracy with a ray light, but the cost is too high and the code is too long. destZ = map->GetHeight(creature->GetPhaseMask(), destX, destY, respZ+travelDistZ-2.0f, false); - if (fabs(destZ - respZ) > travelDistZ) // Map check + if (std::fabs(destZ - respZ) > travelDistZ) // Map check { // Vmap Horizontal or above destZ = map->GetHeight(creature->GetPhaseMask(), destX, destY, respZ - 2.0f, true); - if (fabs(destZ - respZ) > travelDistZ) + if (std::fabs(destZ - respZ) > travelDistZ) { // Vmap Higher destZ = map->GetHeight(creature->GetPhaseMask(), destX, destY, respZ+travelDistZ-2.0f, true); // let's forget this bad coords where a z cannot be find and retry at next tick - if (fabs(destZ - respZ) > travelDistZ) + if (std::fabs(destZ - respZ) > travelDistZ) return; } } diff --git a/src/server/game/Movement/Spline/MoveSpline.cpp b/src/server/game/Movement/Spline/MoveSpline.cpp index 6e3d7680637..4247197b3b0 100644 --- a/src/server/game/Movement/Spline/MoveSpline.cpp +++ b/src/server/game/Movement/Spline/MoveSpline.cpp @@ -47,7 +47,7 @@ Location MoveSpline::ComputePosition() const if (splineflags.final_angle) c.orientation = facing.angle; else if (splineflags.final_point) - c.orientation = atan2(facing.f.y - c.y, facing.f.x - c.x); + c.orientation = std::atan2(facing.f.y - c.y, facing.f.x - c.x); //nothing to do for MoveSplineFlag::Final_Target flag } else @@ -56,7 +56,7 @@ Location MoveSpline::ComputePosition() const { Vector3 hermite; spline.evaluate_derivative(point_Idx, u, hermite); - c.orientation = atan2(hermite.y, hermite.x); + c.orientation = std::atan2(hermite.y, hermite.x); } if (splineflags.orientationInversed) @@ -226,7 +226,7 @@ bool MoveSplineInitArgs::_checkPathBounds() const for (uint32 i = 1; i < path.size()-1; ++i) { offset = path[i] - middle; - if (fabs(offset.x) >= MAX_OFFSET || fabs(offset.y) >= MAX_OFFSET || fabs(offset.z) >= MAX_OFFSET) + if (std::fabs(offset.x) >= MAX_OFFSET || std::fabs(offset.y) >= MAX_OFFSET || std::fabs(offset.z) >= MAX_OFFSET) { TC_LOG_ERROR("misc", "MoveSplineInitArgs::_checkPathBounds check failed"); return false; diff --git a/src/server/game/Movement/Spline/MovementTypedefs.h b/src/server/game/Movement/Spline/MovementTypedefs.h index 134e7a45425..a69af9e3a83 100644 --- a/src/server/game/Movement/Spline/MovementTypedefs.h +++ b/src/server/game/Movement/Spline/MovementTypedefs.h @@ -69,7 +69,7 @@ namespace Movement typedef counter<uint32, 0xFFFFFFFF> UInt32Counter; - extern double gravity; + extern float gravity; extern UInt32Counter splineIdGen; extern std::string MovementFlags_ToString(uint32 flags); extern std::string MovementFlagsExtra_ToString(uint32 flags); diff --git a/src/server/game/Movement/Spline/MovementUtil.cpp b/src/server/game/Movement/Spline/MovementUtil.cpp index f5bdba378d1..3f629238948 100644 --- a/src/server/game/Movement/Spline/MovementUtil.cpp +++ b/src/server/game/Movement/Spline/MovementUtil.cpp @@ -17,12 +17,12 @@ */ #include "MoveSplineFlag.h" -#include <math.h> +#include <cmath> #include <string> namespace Movement { - double gravity = 19.29110527038574; + float gravity = static_cast<float>(19.29110527038574); UInt32Counter splineIdGen; /// Velocity bounds that makes fall speed limited @@ -45,14 +45,14 @@ namespace Movement if (path_length >= terminal_safeFall_length) time = (path_length - terminal_safeFall_length) / terminalSafefallVelocity + terminal_safeFall_fallTime; else - time = sqrtf(2.0f * path_length / gravity); + time = std::sqrt(2.0f * path_length / gravity); } else { if (path_length >= terminal_length) time = (path_length - terminal_length) / terminalVelocity + terminal_fallTime; else - time = sqrtf(2.0f * path_length / gravity); + time = std::sqrt(2.0f * path_length / gravity); } return time; diff --git a/src/server/game/Movement/Spline/Spline.cpp b/src/server/game/Movement/Spline/Spline.cpp index 6424afc5d6e..b8a028b6fc0 100644 --- a/src/server/game/Movement/Spline/Spline.cpp +++ b/src/server/game/Movement/Spline/Spline.cpp @@ -165,7 +165,7 @@ float SplineBase::SegLengthCatmullRom(index_type index) const curPos = nextPos = p[1]; index_type i = 1; - double length = 0; + float length = 0; while (i <= STEPS_PER_SEGMENT) { C_Evaluate(p, float(i) / float(STEPS_PER_SEGMENT), s_catmullRomCoeffs, nextPos); @@ -188,7 +188,7 @@ float SplineBase::SegLengthBezier3(index_type index) const curPos = nextPos; index_type i = 1; - double length = 0; + float length = 0; while (i <= STEPS_PER_SEGMENT) { C_Evaluate(p, float(i) / float(STEPS_PER_SEGMENT), s_Bezier3Coeffs, nextPos); diff --git a/src/server/game/Movement/Waypoints/Path.h b/src/server/game/Movement/Waypoints/Path.h index 4c275cbc15d..c7e701c49ad 100644 --- a/src/server/game/Movement/Waypoints/Path.h +++ b/src/server/game/Movement/Waypoints/Path.h @@ -63,7 +63,7 @@ class Path float xd = node.x - prev.x; float yd = node.y - prev.y; float zd = node.z - prev.z; - len += sqrtf(xd*xd + yd*yd + zd*zd); + len += std::sqrt(xd*xd + yd*yd + zd*zd); } return len; } @@ -80,7 +80,7 @@ class Path float xd = x - node.x; float yd = y - node.y; float zd = z - node.z; - len += sqrtf(xd*xd + yd*yd + zd*zd); + len += std::sqrt(xd*xd + yd*yd + zd*zd); } return len; diff --git a/src/server/game/Pools/PoolMgr.h b/src/server/game/Pools/PoolMgr.h index d1fcadd40de..dd24cceae07 100644 --- a/src/server/game/Pools/PoolMgr.h +++ b/src/server/game/Pools/PoolMgr.h @@ -33,7 +33,7 @@ struct PoolObject { uint32 guid; float chance; - PoolObject(uint32 _guid, float _chance): guid(_guid), chance(fabs(_chance)) { } + PoolObject(uint32 _guid, float _chance) : guid(_guid), chance(std::fabs(_chance)) { } }; class Pool // for Pool of Pool case diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 5080733bb66..4d8ac65e55d 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -821,13 +821,13 @@ void Spell::SelectSpellTargets() { float speed = m_targets.GetSpeedXY(); if (speed > 0.0f) - m_delayMoment = (uint64)floor(m_targets.GetDist2d() / speed * 1000.0f); + m_delayMoment = uint64(std::floor(m_targets.GetDist2d() / speed * 1000.0f)); } else if (m_spellInfo->Speed > 0.0f) { float dist = m_caster->GetDistance(*m_targets.GetDstPos()); if (!(m_spellInfo->AttributesEx9 & SPELL_ATTR9_SPECIAL_DELAY_CALCULATION)) - m_delayMoment = uint64(floor(dist / m_spellInfo->Speed * 1000.0f)); + m_delayMoment = uint64(std::floor(dist / m_spellInfo->Speed * 1000.0f)); else m_delayMoment = uint64(m_spellInfo->Speed * 1000.0f); } @@ -1104,7 +1104,7 @@ void Spell::SelectImplicitConeTargets(SpellEffIndex effIndex, SpellImplicitTarge SpellTargetObjectTypes objectType = targetType.GetObjectType(); SpellTargetCheckTypes selectionType = targetType.GetCheckType(); ConditionList* condList = m_spellInfo->Effects[effIndex].ImplicitTargetConditions; - float coneAngle = M_PI/2; + float coneAngle = float(M_PI) / 2; float radius = m_spellInfo->Effects[effIndex].CalcRadius(m_caster) * m_spellValue->RadiusMod; if (uint32 containerTypeMask = GetSearcherTypeMask(objectType, condList)) @@ -1465,7 +1465,7 @@ void Spell::SelectImplicitChainTargets(SpellEffIndex effIndex, SpellImplicitTarg float tangent(float x) { - x = tan(x); + x = std::tan(x); //if (x < std::numeric_limits<float>::max() && x > -std::numeric_limits<float>::max()) return x; //if (x >= std::numeric_limits<float>::max()) return std::numeric_limits<float>::max(); //if (x <= -std::numeric_limits<float>::max()) return -std::numeric_limits<float>::max(); @@ -1570,7 +1570,7 @@ void Spell::SelectImplicitTrajTargets(SpellEffIndex effIndex) float sqrt1 = b * b + 4 * a * height; if (sqrt1 > 0) { - sqrt1 = sqrt(sqrt1); + sqrt1 = std::sqrt(sqrt1); dist = (sqrt1 - b) / (2 * a); CHECK_DIST; } @@ -1579,7 +1579,7 @@ void Spell::SelectImplicitTrajTargets(SpellEffIndex effIndex) float sqrt2 = b * b + 4 * a * height; if (sqrt2 > 0) { - sqrt2 = sqrt(sqrt2); + sqrt2 = std::sqrt(sqrt2); dist = (sqrt2 - b) / (2 * a); CHECK_DIST; @@ -1608,7 +1608,7 @@ void Spell::SelectImplicitTrajTargets(SpellEffIndex effIndex) DEBUG_TRAJ(TC_LOG_ERROR("spells", "Initial %f %f %f %f %f", x, y, z, distSq, sizeSq);) if (distSq > sizeSq) { - float factor = 1 - sqrt(sizeSq / distSq); + float factor = 1 - std::sqrt(sizeSq / distSq); x += factor * ((*itr)->GetPositionX() - x); y += factor * ((*itr)->GetPositionY() - y); z += factor * ((*itr)->GetPositionZ() - z); @@ -2075,7 +2075,7 @@ void Spell::AddUnitTarget(Unit* target, uint32 effectMask, bool checkIfValid /*= dist = 5.0f; if (!(m_spellInfo->AttributesEx9 & SPELL_ATTR9_SPECIAL_DELAY_CALCULATION)) - targetInfo.timeDelay = uint64(floor(dist / m_spellInfo->Speed * 1000.0f)); + targetInfo.timeDelay = uint64(std::floor(dist / m_spellInfo->Speed * 1000.0f)); else targetInfo.timeDelay = uint64(m_spellInfo->Speed * 1000.0f); |