mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-17 03:08:26 +00:00
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:
+4
-2
@@ -4,6 +4,7 @@
|
||||
#include "../common/rulesys.h"
|
||||
#include "../common/misc_functions.h"
|
||||
#include "../common/string_util.h"
|
||||
#include "../common/random.h"
|
||||
#include "adventure.h"
|
||||
#include "adventure_manager.h"
|
||||
#include "worlddb.h"
|
||||
@@ -14,6 +15,7 @@
|
||||
extern ZSList zoneserver_list;
|
||||
extern ClientList client_list;
|
||||
extern AdventureManager adventure_manager;
|
||||
extern EQEmu::Random emu_random;
|
||||
|
||||
Adventure::Adventure(AdventureTemplate *t)
|
||||
{
|
||||
@@ -392,8 +394,8 @@ void Adventure::MoveCorpsesToGraveyard()
|
||||
|
||||
for (auto iter = dbid_list.begin(); iter != dbid_list.end(); ++iter)
|
||||
{
|
||||
float x = GetTemplate()->graveyard_x + MakeRandomFloat(-GetTemplate()->graveyard_radius, GetTemplate()->graveyard_radius);
|
||||
float y = GetTemplate()->graveyard_y + MakeRandomFloat(-GetTemplate()->graveyard_radius, GetTemplate()->graveyard_radius);
|
||||
float x = GetTemplate()->graveyard_x + emu_random.Real(-GetTemplate()->graveyard_radius, GetTemplate()->graveyard_radius);
|
||||
float y = GetTemplate()->graveyard_y + emu_random.Real(-GetTemplate()->graveyard_radius, GetTemplate()->graveyard_radius);
|
||||
float z = GetTemplate()->graveyard_z;
|
||||
|
||||
query = StringFormat("UPDATE character_corpses "
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "../common/string_util.h"
|
||||
#include "../common/servertalk.h"
|
||||
#include "../common/rulesys.h"
|
||||
#include "../common/random.h"
|
||||
#include "adventure.h"
|
||||
#include "adventure_manager.h"
|
||||
#include "worlddb.h"
|
||||
@@ -14,6 +15,7 @@
|
||||
|
||||
extern ZSList zoneserver_list;
|
||||
extern ClientList client_list;
|
||||
extern EQEmu::Random emu_random;
|
||||
|
||||
AdventureManager::AdventureManager()
|
||||
{
|
||||
@@ -325,7 +327,7 @@ void AdventureManager::CalculateAdventureRequestReply(const char *data)
|
||||
if(eligible_adventures.size() > 0)
|
||||
{
|
||||
ea_iter = eligible_adventures.begin();
|
||||
int c_index = MakeRandomInt(0, (eligible_adventures.size()-1));
|
||||
int c_index = emu_random.Int(0, (eligible_adventures.size()-1));
|
||||
for(int i = 0; i < c_index; ++i)
|
||||
{
|
||||
++ea_iter;
|
||||
|
||||
+11
-9
@@ -15,6 +15,7 @@
|
||||
#include "../common/extprofile.h"
|
||||
#include "../common/string_util.h"
|
||||
#include "../common/clientversions.h"
|
||||
#include "../common/random.h"
|
||||
|
||||
#include "client.h"
|
||||
#include "worlddb.h"
|
||||
@@ -61,6 +62,7 @@ std::vector<RaceClassCombos> character_create_race_class_combos;
|
||||
extern ZSList zoneserver_list;
|
||||
extern LoginServerList loginserverlist;
|
||||
extern ClientList client_list;
|
||||
extern EQEmu::Random emu_random;
|
||||
extern uint32 numclients;
|
||||
extern volatile bool RunLoops;
|
||||
|
||||
@@ -519,7 +521,7 @@ bool Client::HandleGenerateRandomNamePacket(const EQApplicationPacket *app) {
|
||||
char cons[48]="bcdfghjklmnpqrstvwxzybcdgklmnprstvwbcdgkpstrkd";
|
||||
char rndname[17]="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
|
||||
char paircons[33]="ngrkndstshthphsktrdrbrgrfrclcr";
|
||||
int rndnum=MakeRandomInt(0, 75),n=1;
|
||||
int rndnum=emu_random.Int(0, 75),n=1;
|
||||
bool dlc=false;
|
||||
bool vwl=false;
|
||||
bool dbl=false;
|
||||
@@ -540,18 +542,18 @@ bool Client::HandleGenerateRandomNamePacket(const EQApplicationPacket *app) {
|
||||
rndname[0]=vowels[rndnum];
|
||||
vwl=true;
|
||||
}
|
||||
int namlen=MakeRandomInt(5, 10);
|
||||
int namlen=emu_random.Int(5, 10);
|
||||
for (int i=n;i<namlen;i++)
|
||||
{
|
||||
dlc=false;
|
||||
if (vwl) //last char was a vowel
|
||||
{ // so pick a cons or cons pair
|
||||
rndnum=MakeRandomInt(0, 62);
|
||||
rndnum=emu_random.Int(0, 62);
|
||||
if (rndnum>46)
|
||||
{ // pick a cons pair
|
||||
if (i>namlen-3) // last 2 chars in name?
|
||||
{ // name can only end in cons pair "rk" "st" "sh" "th" "ph" "sk" "nd" or "ng"
|
||||
rndnum=MakeRandomInt(0, 7)*2;
|
||||
rndnum=emu_random.Int(0, 7)*2;
|
||||
}
|
||||
else
|
||||
{ // pick any from the set
|
||||
@@ -569,12 +571,12 @@ bool Client::HandleGenerateRandomNamePacket(const EQApplicationPacket *app) {
|
||||
}
|
||||
else
|
||||
{ // select a vowel
|
||||
rndname[i]=vowels[MakeRandomInt(0, 16)];
|
||||
rndname[i]=vowels[emu_random.Int(0, 16)];
|
||||
}
|
||||
vwl=!vwl;
|
||||
if (!dbl && !dlc)
|
||||
{ // one chance at double letters in name
|
||||
if (!MakeRandomInt(0, i+9)) // chances decrease towards end of name
|
||||
if (!emu_random.Int(0, i+9)) // chances decrease towards end of name
|
||||
{
|
||||
rndname[i+1]=rndname[i];
|
||||
dbl=true;
|
||||
@@ -831,7 +833,7 @@ bool Client::HandleEnterWorldPacket(const EQApplicationPacket *app) {
|
||||
QueuePacket(outapp);
|
||||
safe_delete(outapp);
|
||||
|
||||
int MailKey = MakeRandomInt(1, INT_MAX);
|
||||
int MailKey = emu_random.Int(1, INT_MAX);
|
||||
|
||||
database.SetMailKey(charid, GetIP(), MailKey);
|
||||
|
||||
@@ -1242,8 +1244,8 @@ void Client::ZoneUnavail() {
|
||||
|
||||
bool Client::GenPassKey(char* key) {
|
||||
char* passKey=nullptr;
|
||||
*passKey += ((char)('A'+((int)MakeRandomInt(0, 25))));
|
||||
*passKey += ((char)('A'+((int)MakeRandomInt(0, 25))));
|
||||
*passKey += ((char)('A'+((int)emu_random.Int(0, 25))));
|
||||
*passKey += ((char)('A'+((int)emu_random.Int(0, 25))));
|
||||
memcpy(key, passKey, strlen(passKey));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@
|
||||
|
||||
#include "../common/emu_tcp_server.h"
|
||||
#include "../common/patches/patches.h"
|
||||
#include "../common/random.h"
|
||||
#include "zoneserver.h"
|
||||
#include "console.h"
|
||||
#include "login_server.h"
|
||||
@@ -97,6 +98,7 @@ UCSConnection UCSLink;
|
||||
QueryServConnection QSLink;
|
||||
LauncherList launcher_list;
|
||||
AdventureManager adventure_manager;
|
||||
EQEmu::Random emu_random;
|
||||
volatile bool RunLoops = true;
|
||||
uint32 numclients = 0;
|
||||
uint32 numzones = 0;
|
||||
|
||||
+3
-1
@@ -24,10 +24,12 @@
|
||||
#include "world_config.h"
|
||||
#include "../common/servertalk.h"
|
||||
#include "../common/string_util.h"
|
||||
#include "../common/random.h"
|
||||
|
||||
extern uint32 numzones;
|
||||
extern bool holdzones;
|
||||
extern ConsoleList console_list;
|
||||
extern EQEmu::Random emu_random;
|
||||
void CatchSignal(int sig_num);
|
||||
|
||||
ZSList::ZSList()
|
||||
@@ -565,7 +567,7 @@ void ZSList::RebootZone(const char* ip1,uint16 port,const char* ip2, uint32 skip
|
||||
safe_delete(tmp);
|
||||
return;
|
||||
}
|
||||
uint32 z = MakeRandomInt(0, y-1);
|
||||
uint32 z = emu_random.Int(0, y-1);
|
||||
|
||||
ServerPacket* pack = new ServerPacket(ServerOP_ZoneReboot, sizeof(ServerZoneReboot_Struct));
|
||||
ServerZoneReboot_Struct* s = (ServerZoneReboot_Struct*) pack->pBuffer;
|
||||
|
||||
Reference in New Issue
Block a user