From 508a731181bec70aec677845a161d733d6b85f50 Mon Sep 17 00:00:00 2001 From: Trust Date: Sat, 21 Jul 2018 16:30:55 -0400 Subject: [PATCH 1/2] Added random graveyard corpse placement within +/- 20 units on X/Y axis to help spread corpses out. --- common/random.h | 27 +++++++++++++++++++++++++++ zone/zonedb.cpp | 6 +++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/common/random.h b/common/random.h index 0c877bfea..8bbc99397 100644 --- a/common/random.h +++ b/common/random.h @@ -97,6 +97,33 @@ namespace EQEmu { Reseed(); } + //generates a psuedo-random float between 0.0 and 0.999... + float randfloat() + { + return rand()/(float(RAND_MAX)+1); + } + + //generates a psuedo-random float between 0.0 and max + float randfloat(float max) + { + return randfloat()*max; + } + + //generates a psuedo-random float between min and max + float randfloat(float min, float max) + { + if (min>max) + return randfloat()*(min-max)+max; + else + return randfloat()*(max-min)+min; + } + + //generates a psuedo-random double between 0.0 and 0.999... + double randdouble() + { + return rand()/(double(RAND_MAX)+1); + } + private: typedef std::uniform_int_distribution::param_type int_param_t; typedef std::uniform_real_distribution::param_type real_param_t; diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index acb06bf19..97e08da78 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -3842,12 +3842,16 @@ uint32 ZoneDatabase::CreateGraveyardRecord(uint32 graveyard_zone_id, const glm:: return 0; } uint32 ZoneDatabase::SendCharacterCorpseToGraveyard(uint32 dbid, uint32 zone_id, uint16 instance_id, const glm::vec4& position) { + + float xcorpse = (position.x + zone->random.randfloat(-20,20)); + float ycorpse = (position.y + zone->random.randfloat(-20,20)); + std::string query = StringFormat("UPDATE `character_corpses` " "SET `zone_id` = %u, `instance_id` = 0, " "`x` = %1.1f, `y` = %1.1f, `z` = %1.1f, `heading` = %1.1f, " "`was_at_graveyard` = 1 " "WHERE `id` = %d", - zone_id, position.x, position.y, position.z, position.w, dbid); + zone_id, xcorpse, ycorpse, position.z, position.w, dbid); QueryDatabase(query); return dbid; } From 7a44521b03214886e6ffaa566eef76a7980f5c32 Mon Sep 17 00:00:00 2001 From: Trust Date: Sat, 21 Jul 2018 23:02:07 -0400 Subject: [PATCH 2/2] rand is bad random.Real is good! --- common/random.h | 27 --------------------------- zone/zonedb.cpp | 4 ++-- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/common/random.h b/common/random.h index 8bbc99397..0c877bfea 100644 --- a/common/random.h +++ b/common/random.h @@ -97,33 +97,6 @@ namespace EQEmu { Reseed(); } - //generates a psuedo-random float between 0.0 and 0.999... - float randfloat() - { - return rand()/(float(RAND_MAX)+1); - } - - //generates a psuedo-random float between 0.0 and max - float randfloat(float max) - { - return randfloat()*max; - } - - //generates a psuedo-random float between min and max - float randfloat(float min, float max) - { - if (min>max) - return randfloat()*(min-max)+max; - else - return randfloat()*(max-min)+min; - } - - //generates a psuedo-random double between 0.0 and 0.999... - double randdouble() - { - return rand()/(double(RAND_MAX)+1); - } - private: typedef std::uniform_int_distribution::param_type int_param_t; typedef std::uniform_real_distribution::param_type real_param_t; diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 97e08da78..f79288126 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -3843,8 +3843,8 @@ uint32 ZoneDatabase::CreateGraveyardRecord(uint32 graveyard_zone_id, const glm:: } uint32 ZoneDatabase::SendCharacterCorpseToGraveyard(uint32 dbid, uint32 zone_id, uint16 instance_id, const glm::vec4& position) { - float xcorpse = (position.x + zone->random.randfloat(-20,20)); - float ycorpse = (position.y + zone->random.randfloat(-20,20)); + double xcorpse = (position.x + zone->random.Real(-20,20)); + double ycorpse = (position.y + zone->random.Real(-20,20)); std::string query = StringFormat("UPDATE `character_corpses` " "SET `zone_id` = %u, `instance_id` = 0, "