Switch random function to std::mt19937

Added class EQEmu::Random
Functions:
EQEmu::Random::Int(int low, int high)
EQEmu::Random::Real(double low, double high)
EQEmu::Random::Roll(int required)
EQEmu::Random::Roll(double required)
EQEmu::Random::Reseed()

For zone, you will access the random object through the zone object
ex.
	zone->random.Int(0, 100);

Int returns a random int between low and high
Real returns a random double between low and high
Roll(int) returns true if Int(0, 99) < required is true
Roll(double) returns true if Real(0.0, 1.0) <= required is true
This commit is contained in:
Michael Cook (mackal)
2014-12-01 18:13:12 -05:00
parent a59cdc2c89
commit 395be050a3
42 changed files with 683 additions and 799 deletions
+6 -6
View File
@@ -144,7 +144,7 @@ void Trap::Trigger(Mob* trigger)
{
if ((tmp = database.GetNPCType(effectvalue)))
{
NPC* new_npc = new NPC(tmp, 0, x-5+MakeRandomInt(0, 10), y-5+MakeRandomInt(0, 10), z-5+MakeRandomInt(0, 10), MakeRandomInt(0, 249), FlyMode3);
NPC* new_npc = new NPC(tmp, 0, x-5+zone->random.Int(0, 10), y-5+zone->random.Int(0, 10), z-5+zone->random.Int(0, 10), zone->random.Int(0, 249), FlyMode3);
new_npc->AddLootTable();
entity_list.AddNPC(new_npc);
new_npc->AddToHateList(trigger,1);
@@ -165,7 +165,7 @@ void Trap::Trigger(Mob* trigger)
{
if ((tmp = database.GetNPCType(effectvalue)))
{
NPC* new_npc = new NPC(tmp, 0, x-2+MakeRandomInt(0, 5), y-2+MakeRandomInt(0, 5), z-2+MakeRandomInt(0, 5), MakeRandomInt(0, 249), FlyMode3);
NPC* new_npc = new NPC(tmp, 0, x-2+zone->random.Int(0, 5), y-2+zone->random.Int(0, 5), z-2+zone->random.Int(0, 5), zone->random.Int(0, 249), FlyMode3);
new_npc->AddLootTable();
entity_list.AddNPC(new_npc);
new_npc->AddToHateList(trigger,1);
@@ -185,10 +185,10 @@ void Trap::Trigger(Mob* trigger)
{
EQApplicationPacket* outapp = new EQApplicationPacket(OP_Damage, sizeof(CombatDamage_Struct));
CombatDamage_Struct* a = (CombatDamage_Struct*)outapp->pBuffer;
int dmg = MakeRandomInt(effectvalue, effectvalue2);
int dmg = zone->random.Int(effectvalue, effectvalue2);
trigger->SetHP(trigger->GetHP() - dmg);
a->damage = dmg;
a->sequence = MakeRandomInt(0, 1234567);
a->sequence = zone->random.Int(0, 1234567);
a->source = GetHiddenTrigger()!=nullptr ? GetHiddenTrigger()->GetID() : trigger->GetID();
a->spellid = 0;
a->target = trigger->GetID();
@@ -197,7 +197,7 @@ void Trap::Trigger(Mob* trigger)
safe_delete(outapp);
}
}
respawn_timer.Start((respawn_time + MakeRandomInt(0, respawn_var)) * 1000);
respawn_timer.Start((respawn_time + zone->random.Int(0, respawn_var)) * 1000);
chkarea_timer.Disable();
disarmed = true;
}
@@ -250,7 +250,7 @@ Mob* EntityList::GetTrapTrigger(Trap* trap) {
if ((xdiff*xdiff + ydiff*ydiff) <= maxdist
&& zdiff < trap->maxzdiff)
{
if (MakeRandomInt(0,100) < trap->chance)
if (zone->random.Roll(trap->chance))
return(cur);
else
savemob = cur;