diff options
author | Jesusaves <cpntb1@ymail.com> | 2020-05-15 04:12:18 -0300 |
---|---|---|
committer | Jesusaves <cpntb1@ymail.com> | 2020-05-15 04:12:18 -0300 |
commit | 6cbd6ddfc240f0380cb2ce08b6973fca7a37b44b (patch) | |
tree | 2c835153a87dbdaacf2878c6550ba6a4304171b7 | |
parent | d64597d38a52a9e5aa4423080a343bfa22f55e63 (diff) | |
download | evol-hercules-6cbd6ddfc240f0380cb2ce08b6973fca7a37b44b.tar.gz evol-hercules-6cbd6ddfc240f0380cb2ce08b6973fca7a37b44b.tar.bz2 evol-hercules-6cbd6ddfc240f0380cb2ce08b6973fca7a37b44b.tar.xz evol-hercules-6cbd6ddfc240f0380cb2ce08b6973fca7a37b44b.zip |
New (DANGEROUS) Function for Moubootaur Legends runtime: resetrng()
This will select a new seed (between 0 and 4294967295) and replace it.
Using this command should affect EVERYTHING ingame - from scripts to monsters.
-rw-r--r-- | src/emap/init.c | 2 | ||||
-rw-r--r-- | src/emap/script_buildins.c | 24 | ||||
-rw-r--r-- | src/emap/script_buildins.h | 1 |
3 files changed, 27 insertions, 0 deletions
diff --git a/src/emap/init.c b/src/emap/init.c index 60658db..7c51918 100644 --- a/src/emap/init.c +++ b/src/emap/init.c @@ -17,6 +17,7 @@ #include "common/socket.h" #include "common/strlib.h" #include "common/timer.h" +#include "common/random.h" #include "map/achievement.h" #include "map/battle.h" #include "map/channel.h" @@ -235,6 +236,7 @@ HPExport void plugin_init (void) addScriptCommand("npcshopattach","s?",npcshopattach); addScriptCommand("instanceowner", "i", InstanceOwner); addScriptCommand("aggravate", "i", aggravate); + addScriptCommand("resetrng", "", resetrng); // Overrides addScriptCommand("debugmes","v*",debugmes); diff --git a/src/emap/script_buildins.c b/src/emap/script_buildins.c index 1dce4da..f021658 100644 --- a/src/emap/script_buildins.c +++ b/src/emap/script_buildins.c @@ -6,11 +6,14 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <limits.h> +#include <time.h> #include "common/HPMi.h" #include "common/memmgr.h" #include "common/utils.h" #include "common/timer.h" +#include "common/random.h" #include "map/achievement.h" #include "map/chat.h" #include "map/chrif.h" @@ -3045,3 +3048,24 @@ BUILDIN(aggravate) return true; } + +/*========================================== + * Resets RNG seed + *------------------------------------------*/ +BUILDIN(resetrng) +{ + //rnd->init(); + unsigned int seed; + double tmp; + // Reinitialize the random number generator + srand(time(NULL)); + + // Define a new seed + tmp=1.0 * rand() / RAND_MAX; // Ranges from [0;1] + seed=tmp * UINT_MAX; // Ranges from 0 to 4294967294 (It'll never be 100%) + rnd->seed(seed); + printf("\n\nWARNING\n\nRandomness seed updated to %u\n\n", seed); + script_pushint(st, 0); + return true; +} + diff --git a/src/emap/script_buildins.h b/src/emap/script_buildins.h index bf437c2..73769b9 100644 --- a/src/emap/script_buildins.h +++ b/src/emap/script_buildins.h @@ -120,6 +120,7 @@ BUILDIN(homstatus); BUILDIN(readparam2); BUILDIN(InstanceOwner); BUILDIN(aggravate); +BUILDIN(resetrng); // Overrides BUILDIN(countitem); |