summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/core.c13
-rw-r--r--src/common/random.c30
-rw-r--r--src/common/random.h30
-rw-r--r--src/map/battle.c2
-rw-r--r--src/map/homunculus.c50
-rw-r--r--src/map/skill.c4
-rw-r--r--src/plugins/HPMHooking.c1
7 files changed, 82 insertions, 48 deletions
diff --git a/src/common/core.c b/src/common/core.c
index 314bdf947..f5860e992 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -25,15 +25,15 @@
#include "common/cbasetypes.h"
#include "common/console.h"
-#include "common/des.h"
#include "common/db.h"
+#include "common/des.h"
#include "common/memmgr.h"
#include "common/mmo.h"
-#include "common/random.h"
+#include "common/nullpo.h"
#include "common/showmsg.h"
#include "common/strlib.h"
#include "common/sysinfo.h"
-#include "common/nullpo.h"
+#include "common/timer.h"
#include "common/utils.h"
#ifndef MINICORE
@@ -42,10 +42,10 @@
# include "common/ers.h"
# include "common/md5calc.h"
# include "common/mutex.h"
+# include "common/random.h"
# include "common/socket.h"
# include "common/sql.h"
# include "common/thread.h"
-# include "common/timer.h"
#endif
#ifndef _WIN32
@@ -264,6 +264,7 @@ void core_defaults(void) {
timer_defaults();
db_defaults();
socket_defaults();
+ rnd_defaults();
md5_defaults();
#endif
}
@@ -515,8 +516,7 @@ int main (int argc, char **argv) {
timer->init();
/* timer first */
- rnd_init();
- srand((unsigned int)timer->gettick());
+ rnd->init();
console->init();
@@ -543,6 +543,7 @@ int main (int argc, char **argv) {
DB->final();
rathread_final();
ers_final();
+ rnd->final();
#endif
cmdline->final();
//sysinfo->final(); Called by iMalloc->final()
diff --git a/src/common/random.c b/src/common/random.c
index ba70a5c1d..dbb2ca830 100644
--- a/src/common/random.c
+++ b/src/common/random.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -27,6 +27,7 @@
#include "common/timer.h" // gettick
#include <mt19937ar/mt19937ar.h> // init_genrand, genrand_int32, genrand_res53
+#include <stdlib.h>
#if defined(WIN32)
# include "common/winapi.h"
@@ -35,6 +36,8 @@
# include <unistd.h>
#endif
+struct rnd_interface rnd_s;
+struct rnd_interface *rnd;
/// Initializes the random number generator with an appropriate seed.
void rnd_init(void)
@@ -53,8 +56,14 @@ void rnd_init(void)
#endif // HAVE_GETTID
#endif
init_genrand(seed);
+
+ // Also initialize the stdlib rng, just in case it's used somewhere.
+ srand((unsigned int)timer->gettick());
}
+void rnd_final(void)
+{
+}
/// Initializes the random number generator.
void rnd_seed(uint32 seed)
@@ -64,7 +73,7 @@ void rnd_seed(uint32 seed)
/// Generates a random number in the interval [0, SINT32_MAX]
-int32 rnd(void)
+int32 rnd_random(void)
{
return (int32)genrand_int31();
}
@@ -74,7 +83,7 @@ int32 rnd(void)
/// NOTE: interval is open ended, so dice_faces is excluded (unless it's 0)
uint32 rnd_roll(uint32 dice_faces)
{
- return (uint32)(rnd_uniform()*dice_faces);
+ return (uint32)(rnd->uniform()*dice_faces);
}
@@ -84,7 +93,7 @@ int32 rnd_value(int32 min, int32 max)
{
if( min >= max )
return min;
- return min + (int32)(rnd_uniform()*(max-min+1));
+ return min + (int32)(rnd->uniform()*(max-min+1));
}
@@ -103,3 +112,16 @@ double rnd_uniform53(void)
{
return genrand_res53();
}
+
+void rnd_defaults(void)
+{
+ rnd = &rnd_s;
+ rnd->init = rnd_init;
+ rnd->final = rnd_final;
+ rnd->seed = rnd_seed;
+ rnd->random = rnd_random;
+ rnd->roll = rnd_roll;
+ rnd->value = rnd_value;
+ rnd->uniform = rnd_uniform;
+ rnd->uniform53 = rnd_uniform53;
+}
diff --git a/src/common/random.h b/src/common/random.h
index 0b5abbcdc..41bdb4083 100644
--- a/src/common/random.h
+++ b/src/common/random.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -21,17 +21,27 @@
#ifndef COMMON_RANDOM_H
#define COMMON_RANDOM_H
-#include "common/cbasetypes.h"
+#include "common/hercules.h"
+
+struct rnd_interface {
+ void (*init) (void);
+ void (*final) (void);
+
+ void (*seed) (uint32);
+
+ int32 (*random) (void);// [0, SINT32_MAX]
+ uint32 (*roll) (uint32 dice_faces);// [0, dice_faces)
+ int32 (*value) (int32 min, int32 max);// [min, max]
+ double (*uniform) (void);// [0.0, 1.0)
+ double (*uniform53) (void);// [0.0, 1.0)
+};
+
+#define rnd() rnd->random()
#ifdef HERCULES_CORE
-void rnd_init(void);
-void rnd_seed(uint32);
-
-int32 rnd(void);// [0, SINT32_MAX]
-uint32 rnd_roll(uint32 dice_faces);// [0, dice_faces)
-int32 rnd_value(int32 min, int32 max);// [min, max]
-double rnd_uniform(void);// [0.0, 1.0)
-double rnd_uniform53(void);// [0.0, 1.0)
+void rnd_defaults(void);
#endif // HERCULES_CORE
+HPShared struct rnd_interface *rnd;
+
#endif /* COMMON_RANDOM_H */
diff --git a/src/map/battle.c b/src/map/battle.c
index 944271efa..76b74a766 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -2431,7 +2431,7 @@ int battle_calc_skillratio(int attack_type, struct block_list *src, struct block
RE_LVL_DMOD(100);
break;
case LG_OVERBRAND_PLUSATK:
- skillratio = 200 * skill_lv + rnd_value( 10, 100);
+ skillratio = 200 * skill_lv + rnd->value(10, 100);
RE_LVL_DMOD(100);
break;
case LG_RAYOFGENESIS:
diff --git a/src/map/homunculus.c b/src/map/homunculus.c
index 66cce23e6..080a314b8 100644
--- a/src/map/homunculus.c
+++ b/src/map/homunculus.c
@@ -356,14 +356,14 @@ bool homunculus_levelup(struct homun_data *hd) {
max = &hd->homunculusDB->gmax;
min = &hd->homunculusDB->gmin;
- growth_max_hp = rnd_value(min->HP, max->HP);
- growth_max_sp = rnd_value(min->SP, max->SP);
- growth_str = rnd_value(min->str, max->str);
- growth_agi = rnd_value(min->agi, max->agi);
- growth_vit = rnd_value(min->vit, max->vit);
- growth_dex = rnd_value(min->dex, max->dex);
- growth_int = rnd_value(min->int_,max->int_);
- growth_luk = rnd_value(min->luk, max->luk);
+ growth_max_hp = rnd->value(min->HP, max->HP);
+ growth_max_sp = rnd->value(min->SP, max->SP);
+ growth_str = rnd->value(min->str, max->str);
+ growth_agi = rnd->value(min->agi, max->agi);
+ growth_vit = rnd->value(min->vit, max->vit);
+ growth_dex = rnd->value(min->dex, max->dex);
+ growth_int = rnd->value(min->int_,max->int_);
+ growth_luk = rnd->value(min->luk, max->luk);
//Aegis discards the decimals in the stat growth values!
growth_str-=growth_str%10;
@@ -432,14 +432,14 @@ bool homunculus_evolve(struct homun_data *hd) {
hom = &hd->homunculus;
max = &hd->homunculusDB->emax;
min = &hd->homunculusDB->emin;
- hom->max_hp += rnd_value(min->HP, max->HP);
- hom->max_sp += rnd_value(min->SP, max->SP);
- hom->str += 10*rnd_value(min->str, max->str);
- hom->agi += 10*rnd_value(min->agi, max->agi);
- hom->vit += 10*rnd_value(min->vit, max->vit);
- hom->int_+= 10*rnd_value(min->int_,max->int_);
- hom->dex += 10*rnd_value(min->dex, max->dex);
- hom->luk += 10*rnd_value(min->luk, max->luk);
+ hom->max_hp += rnd->value(min->HP, max->HP);
+ hom->max_sp += rnd->value(min->SP, max->SP);
+ hom->str += 10*rnd->value(min->str, max->str);
+ hom->agi += 10*rnd->value(min->agi, max->agi);
+ hom->vit += 10*rnd->value(min->vit, max->vit);
+ hom->int_+= 10*rnd->value(min->int_,max->int_);
+ hom->dex += 10*rnd->value(min->dex, max->dex);
+ hom->luk += 10*rnd->value(min->luk, max->luk);
hom->intimacy = 500;
unit->remove_map(&hd->bl, CLR_OUTSIGHT, ALC_MARK);
@@ -848,7 +848,7 @@ bool homunculus_call(struct map_session_data *sd) {
nullpo_retr(false, sd);
if (!sd->status.hom_id) //Create a new homun.
- return homun->creation_request(sd, HM_CLASS_BASE + rnd_value(0, 7));
+ return homun->creation_request(sd, HM_CLASS_BASE + rnd->value(0, 7));
// If homunc not yet loaded, load it
if (!sd->hd)
@@ -1075,14 +1075,14 @@ bool homunculus_shuffle(struct homun_data *hd) {
//Evolved bonuses
struct s_homunculus *hom = &hd->homunculus;
struct h_stats *max = &hd->homunculusDB->emax, *min = &hd->homunculusDB->emin;
- hom->max_hp += rnd_value(min->HP, max->HP);
- hom->max_sp += rnd_value(min->SP, max->SP);
- hom->str += 10*rnd_value(min->str, max->str);
- hom->agi += 10*rnd_value(min->agi, max->agi);
- hom->vit += 10*rnd_value(min->vit, max->vit);
- hom->int_+= 10*rnd_value(min->int_,max->int_);
- hom->dex += 10*rnd_value(min->dex, max->dex);
- hom->luk += 10*rnd_value(min->luk, max->luk);
+ hom->max_hp += rnd->value(min->HP, max->HP);
+ hom->max_sp += rnd->value(min->SP, max->SP);
+ hom->str += 10*rnd->value(min->str, max->str);
+ hom->agi += 10*rnd->value(min->agi, max->agi);
+ hom->vit += 10*rnd->value(min->vit, max->vit);
+ hom->int_+= 10*rnd->value(min->int_,max->int_);
+ hom->dex += 10*rnd->value(min->dex, max->dex);
+ hom->luk += 10*rnd->value(min->luk, max->luk);
}
hd->homunculus.exp = exp;
diff --git a/src/map/skill.c b/src/map/skill.c
index 76ee3d3fd..0b66c1ded 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -8827,9 +8827,9 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin
if (is_boss(bl)) break;
joblvbonus = ( sd ? sd->status.job_level : 50 );
//First we set the success chance based on the caster's build which increases the chance.
- rate = 10 * skill_lv + rnd_value( sstatus->dex / 12, sstatus->dex / 4 ) + joblvbonus + status->get_lv(src) / 10;
+ rate = 10 * skill_lv + rnd->value( sstatus->dex / 12, sstatus->dex / 4 ) + joblvbonus + status->get_lv(src) / 10;
// We then reduce the success chance based on the target's build.
- rate -= rnd_value( tstatus->agi / 6, tstatus->agi / 3 ) + tstatus->luk / 10 + ( dstsd ? (dstsd->max_weight / 10 - dstsd->weight / 10 ) / 100 : 0 ) + status->get_lv(bl) / 10;
+ rate -= rnd->value( tstatus->agi / 6, tstatus->agi / 3 ) + tstatus->luk / 10 + ( dstsd ? (dstsd->max_weight / 10 - dstsd->weight / 10 ) / 100 : 0 ) + status->get_lv(bl) / 10;
//Finally we set the minimum success chance cap based on the caster's skill level and DEX.
rate = cap_value( rate, skill_lv + sstatus->dex / 20, 100);
clif->skill_nodamage(src,bl,skill_id,0,sc_start(src,bl,type,rate,skill_lv,skill->get_time(skill_id,skill_lv)));
diff --git a/src/plugins/HPMHooking.c b/src/plugins/HPMHooking.c
index 0b1b67e61..1c0cec51d 100644
--- a/src/plugins/HPMHooking.c
+++ b/src/plugins/HPMHooking.c
@@ -114,6 +114,7 @@
#include "common/memmgr.h"
#include "common/mutex.h"
#include "common/nullpo.h"
+#include "common/random.h"
#include "common/showmsg.h"
#include "common/socket.h"
#include "common/sql.h"