diff --git a/src/common/Utilities/Random.cpp b/src/common/Utilities/Random.cpp index 1f5fe231a3..383a9a289f 100644 --- a/src/common/Utilities/Random.cpp +++ b/src/common/Utilities/Random.cpp @@ -72,15 +72,15 @@ uint32 rand32() return GetRng()->RandomUInt32(); } -double rand_norm() +float rand_norm() { - std::uniform_real_distribution urd; + std::uniform_real_distribution urd; return urd(engine); } -double rand_chance() +float rand_chance() { - std::uniform_real_distribution urd(0.0, 100.0); + std::uniform_real_distribution urd(0.0, 100.0); return urd(engine); } diff --git a/src/common/Utilities/Random.h b/src/common/Utilities/Random.h index 067a9c6ac1..87e73d4c86 100644 --- a/src/common/Utilities/Random.h +++ b/src/common/Utilities/Random.h @@ -41,11 +41,11 @@ TC_COMMON_API Milliseconds randtime(Milliseconds min, Milliseconds max); /* Return a random number in the range min..max */ TC_COMMON_API float frand(float min, float max); -/* Return a random double from 0.0 to 1.0 (exclusive). */ -TC_COMMON_API double rand_norm(); +/* Return a random float from 0.0 to 1.0 (exclusive). */ +TC_COMMON_API float rand_norm(); -/* Return a random double from 0.0 to 100.0 (exclusive). */ -TC_COMMON_API double rand_chance(); +/* Return a random float from 0.0 to 100.0 (exclusive). */ +TC_COMMON_API float rand_chance(); /* Return a random number in the range 0..count (exclusive) with each value having a different chance of happening */ TC_COMMON_API uint32 urandweighted(size_t count, double const* chances); diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index a833b3261e..2d1e061870 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -1549,8 +1549,8 @@ void WorldObject::GetRandomPoint(const Position &pos, float distance, float &ran } // angle to face `obj` to `this` - float angle = (float)rand_norm()*static_cast(2*M_PI); - float new_dist = (float)rand_norm() + (float)rand_norm(); + float angle = rand_norm() * static_cast(2 * M_PI); + float new_dist = rand_norm() + rand_norm(); new_dist = distance * (new_dist > 1 ? new_dist - 2 : new_dist); rand_x = pos.m_positionX + new_dist * std::cos(angle); @@ -3369,7 +3369,7 @@ Position WorldObject::GetFirstCollisionPosition(float dist, float angle) Position WorldObject::GetRandomNearPosition(float radius) { Position pos = GetPosition(); - MovePosition(pos, radius * (float)rand_norm(), (float)rand_norm() * static_cast(2 * M_PI)); + MovePosition(pos, radius * rand_norm(), rand_norm() * static_cast(2 * M_PI)); return pos; } diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 0c1d73e933..ffcc68b57c 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -1591,7 +1591,7 @@ static float GetArmorReduction(float armor, uint8 attackerLevel) discreteResistProbability[i] = std::max(0.5f - 2.5f * std::fabs(0.1f * i - averageResist), 0.0f); } - float roll = float(rand_norm()); + float roll = rand_norm(); float probabilitySum = 0.0f; uint32 resistance = 0; diff --git a/src/server/game/Loot/LootMgr.cpp b/src/server/game/Loot/LootMgr.cpp index 96ce832fd0..404109887e 100644 --- a/src/server/game/Loot/LootMgr.cpp +++ b/src/server/game/Loot/LootMgr.cpp @@ -399,7 +399,7 @@ LootStoreItem const* LootTemplate::LootGroup::Roll(Loot& loot, uint16 lootMode) if (!possibleLoot.empty()) // First explicitly chanced entries are checked { - float roll = (float)rand_chance(); + float roll = rand_chance(); for (LootStoreItemList::const_iterator itr = possibleLoot.begin(); itr != possibleLoot.end(); ++itr) // check each explicitly chanced entry in the template and modify its chance based on quality. { diff --git a/src/server/game/Pools/PoolMgr.cpp b/src/server/game/Pools/PoolMgr.cpp index 5fdd549ea5..ca122172e1 100644 --- a/src/server/game/Pools/PoolMgr.cpp +++ b/src/server/game/Pools/PoolMgr.cpp @@ -300,7 +300,7 @@ void PoolGroup::SpawnObject(SpawnedPoolData& spawns, uint32 limit, uint32 tri // roll objects to be spawned if (!ExplicitlyChanced.empty()) { - float roll = (float)rand_chance(); + float roll = rand_chance(); for (PoolObject& obj : ExplicitlyChanced) { diff --git a/src/server/game/Skills/SkillDiscovery.cpp b/src/server/game/Skills/SkillDiscovery.cpp index 34a05f6a20..ca3e6062b5 100644 --- a/src/server/game/Skills/SkillDiscovery.cpp +++ b/src/server/game/Skills/SkillDiscovery.cpp @@ -173,7 +173,7 @@ uint32 GetExplicitDiscoverySpell(uint32 spellId, Player* player) full_chance += item_iter->chance; float rate = full_chance / 100.0f; - float roll = (float)rand_chance() * rate; // roll now in range 0..full_chance + float roll = rand_chance() * rate; // roll now in range 0..full_chance for (SkillDiscoveryList::const_iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter) { diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 5bf61138e6..f78de43b39 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -1485,7 +1485,7 @@ void Spell::SelectImplicitCasterDestTargets(SpellEffIndex effIndex, SpellImplici float maxDist = m_spellInfo->GetMaxRange(true); float dist = frand(minDist, maxDist); float x, y, z; - float angle = float(rand_norm()) * static_cast(M_PI * 35.0f / 180.0f) - static_cast(M_PI * 17.5f / 180.0f); + float angle = rand_norm() * static_cast(M_PI * 35.0f / 180.0f) - static_cast(M_PI * 17.5f / 180.0f); m_caster->GetClosePoint(x, y, z, DEFAULT_PLAYER_BOUNDING_RADIUS, dist, angle); float ground = m_caster->GetMapHeight(x, y, z); @@ -1573,7 +1573,7 @@ void Spell::SelectImplicitCasterDestTargets(SpellEffIndex effIndex, SpellImplici { case TARGET_DEST_CASTER_RANDOM: if (dist > objSize) - dist = objSize + (dist - objSize) * float(rand_norm()); + dist = objSize + (dist - objSize) * rand_norm(); break; case TARGET_DEST_CASTER_FRONT_LEFT: case TARGET_DEST_CASTER_BACK_LEFT: @@ -1621,7 +1621,7 @@ void Spell::SelectImplicitTargetDestTargets(SpellEffIndex effIndex, SpellImplici float angle = targetType.CalcDirectionAngle(m_spellInfo->Effects[effIndex]); float dist = m_spellInfo->Effects[effIndex].CalcRadius(nullptr, targetIndex); if (targetType.GetTarget() == TARGET_DEST_TARGET_RANDOM) - dist *= float(rand_norm()); + dist *= rand_norm(); Position pos = dest._position; target->MovePositionToFirstCollision(pos, dist, angle); @@ -1657,7 +1657,7 @@ void Spell::SelectImplicitDestDestTargets(SpellEffIndex effIndex, SpellImplicitT float angle = targetType.CalcDirectionAngle(m_spellInfo->Effects[effIndex]); float dist = m_spellInfo->Effects[effIndex].CalcRadius(m_caster, targetIndex); if (targetType.GetTarget() == TARGET_DEST_DEST_RANDOM) - dist *= float(rand_norm()); + dist *= rand_norm(); Position pos = dest._position; m_caster->MovePositionToFirstCollision(pos, dist, angle); diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index 6dd46a0742..9cf1d7b398 100644 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -4914,7 +4914,7 @@ void Spell::EffectTransmitted(SpellEffIndex effIndex) //GO is always friendly to it's creator, get range for friends float min_dis = m_spellInfo->GetMinRange(true); float max_dis = m_spellInfo->GetMaxRange(true); - float dis = (float)rand_norm() * (max_dis - min_dis) + min_dis; + float dis = rand_norm() * (max_dis - min_dis) + min_dis; unitCaster->GetClosePoint(fx, fy, fz, DEFAULT_PLAYER_BOUNDING_RADIUS, dis); fo = unitCaster->GetOrientation(); diff --git a/src/server/game/Spells/SpellInfo.cpp b/src/server/game/Spells/SpellInfo.cpp index 5d9aa89975..652b901a0d 100644 --- a/src/server/game/Spells/SpellInfo.cpp +++ b/src/server/game/Spells/SpellInfo.cpp @@ -121,7 +121,7 @@ float SpellImplicitTargetInfo::CalcDirectionAngle(SpellEffectInfo const& effectI case TARGET_DIR_FRONT_LEFT: return static_cast(M_PI/4); case TARGET_DIR_RANDOM: - return float(rand_norm())*static_cast(2*M_PI); + return rand_norm() * static_cast(2 * M_PI); case TARGET_DIR_SUMMON: // This direction does alter its angle based on what is being summoned. // Creatures are being summoned on the left, gameobjects infront diff --git a/src/server/game/Spells/SpellScript.cpp b/src/server/game/Spells/SpellScript.cpp index d5c0e43e02..3e2925f8d5 100644 --- a/src/server/game/Spells/SpellScript.cpp +++ b/src/server/game/Spells/SpellScript.cpp @@ -242,7 +242,7 @@ WorldLocation const* SpellScript::GetExplTargetDest() const return nullptr; } -void SpellScript::SetExplTargetDest(WorldLocation& loc) +void SpellScript::SetExplTargetDest(WorldLocation const& loc) { m_spell->m_targets.SetDst(loc); } diff --git a/src/server/game/Spells/SpellScript.h b/src/server/game/Spells/SpellScript.h index 250a2a1362..ea8d10abba 100644 --- a/src/server/game/Spells/SpellScript.h +++ b/src/server/game/Spells/SpellScript.h @@ -646,7 +646,7 @@ class TC_GAME_API SpellScript : public _SpellScript // returns: WorldLocation which was selected as a spell destination or nullptr WorldLocation const* GetExplTargetDest() const; - void SetExplTargetDest(WorldLocation& loc); + void SetExplTargetDest(WorldLocation const& loc); // returns: WorldObject which was selected as an explicit spell target or nullptr if there's no target WorldObject* GetExplTargetWorldObject() const; diff --git a/src/server/game/Weather/Weather.cpp b/src/server/game/Weather/Weather.cpp index 9e37ac2ace..79db5eb4ae 100644 --- a/src/server/game/Weather/Weather.cpp +++ b/src/server/game/Weather/Weather.cpp @@ -174,16 +174,16 @@ bool Weather::ReGenerate() } else if (u < 90) { - m_grade = (float)rand_norm() * 0.3333f; + m_grade = rand_norm() * 0.3333f; } else { // Severe change, but how severe? rnd = urand(0, 99); if (rnd < 50) - m_grade = (float)rand_norm() * 0.3333f + 0.3334f; + m_grade = rand_norm() * 0.3333f + 0.3334f; else - m_grade = (float)rand_norm() * 0.3333f + 0.6667f; + m_grade = rand_norm() * 0.3333f + 0.6667f; } // return true only in case weather changes