mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-29 08:33:47 +00:00
feat(Core/Random): port random system from TrinityCore (#5454)
* feat(Core/Random): port random system from TrinityCore * lic * logic correct * MultimapErasePair move * whitespace 17:13:34 1. 'Containers.h'. Replace (1) 17:13:40 2. 'LootMgr.h'. Replace (1) 17:13:44 3. 'World.cpp'. Replace (1) 17:13:47 4. 'instance_scholomance.cpp'. Replace (1) * correct debug build
This commit is contained in:
@@ -71,38 +71,6 @@ uint32 TimeStringToSecs(const std::string& timestring);
|
||||
std::string TimeToTimestampStr(time_t t);
|
||||
std::string TimeToHumanReadable(time_t t);
|
||||
|
||||
/* Return a random number in the range min..max. */
|
||||
int32 irand(int32 min, int32 max);
|
||||
|
||||
/* Return a random number in the range min..max (inclusive). */
|
||||
uint32 urand(uint32 min, uint32 max);
|
||||
|
||||
/* Return a random number in the range 0 .. UINT32_MAX. */
|
||||
uint32 rand32();
|
||||
|
||||
/* Return a random number in the range min..max */
|
||||
float frand(float min, float max);
|
||||
|
||||
/* Return a random double from 0.0 to 1.0 (exclusive). */
|
||||
double rand_norm();
|
||||
|
||||
/* Return a random double from 0.0 to 100.0 (exclusive). */
|
||||
double rand_chance();
|
||||
|
||||
uint32 urandweighted(size_t count, double const* chances);
|
||||
|
||||
/* Return true if a random roll fits in the specified chance (range 0-100). */
|
||||
inline bool roll_chance_f(float chance)
|
||||
{
|
||||
return chance > rand_chance();
|
||||
}
|
||||
|
||||
/* Return true if a random roll fits in the specified chance (range 0-100). */
|
||||
inline bool roll_chance_i(int32 chance)
|
||||
{
|
||||
return chance > irand(0, 99);
|
||||
}
|
||||
|
||||
inline void ApplyPercentModFloatVar(float& var, float val, bool apply)
|
||||
{
|
||||
if (val == -100.0f) // prevent set var to zero
|
||||
@@ -582,21 +550,6 @@ bool CompareValues(ComparisionType type, T val1, T val2)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* SFMT wrapper satisfying UniformRandomNumberGenerator concept for use in <random> algorithms
|
||||
*/
|
||||
class SFMTEngine
|
||||
{
|
||||
public:
|
||||
typedef uint32 result_type;
|
||||
|
||||
static constexpr result_type min() { return std::numeric_limits<result_type>::min(); }
|
||||
static constexpr result_type max() { return std::numeric_limits<result_type>::max(); }
|
||||
result_type operator()() const { return rand32(); }
|
||||
|
||||
static SFMTEngine& Instance();
|
||||
};
|
||||
|
||||
class EventMap
|
||||
{
|
||||
typedef std::multimap<uint32, uint32> EventStore;
|
||||
|
||||
Reference in New Issue
Block a user