From a29d128bd3b53847de3e89801426dfc19e2ecbc1 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Wed, 8 Oct 2003 18:02:53 +0000 Subject: Use RandomSource instead of rand(). svn-id: r10682 --- sword2/anims.cpp | 2 +- sword2/function.cpp | 6 +++--- sword2/sound.cpp | 8 ++++---- sword2/sword2.h | 1 + 4 files changed, 9 insertions(+), 8 deletions(-) (limited to 'sword2') diff --git a/sword2/anims.cpp b/sword2/anims.cpp index 9ef4f83e1c..988eea2449 100644 --- a/sword2/anims.cpp +++ b/sword2/anims.cpp @@ -24,7 +24,7 @@ // --------------------------------------------------------------------------- #include "stdafx.h" -#include "common/scummsys.h" +#include "bs2/sword2.h" #include "bs2/driver/driver96.h" #include "bs2/driver/d_draw.h" #include "bs2/anims.h" diff --git a/sword2/function.cpp b/sword2/function.cpp index 1d8e588861..b3040eff75 100644 --- a/sword2/function.cpp +++ b/sword2/function.cpp @@ -135,11 +135,11 @@ int32 FN_random(int32 *params) { // Generates a random number between 'min' & 'max' inclusive, and // sticks it in the script flag 'result' - uint32 min = params[0]; - uint32 max = params[1]; + // params: 0 min + // 1 max // return_value = random integer between min and max, inclusive - RESULT = (rand() % (max-min + 1)) + min; + RESULT = g_sword2->_rnd.getRandomNumberRng(params[0], params[1]); // continue script return IR_CONT; diff --git a/sword2/sound.cpp b/sword2/sound.cpp index cd9c5157be..9c6c72aa85 100644 --- a/sword2/sound.cpp +++ b/sword2/sound.cpp @@ -28,6 +28,7 @@ // --------------------------------------------------------------------------- #include "stdafx.h" +#include "bs2/sword2.h" #include "bs2/console.h" #include "bs2/defs.h" // for RESULT #include "bs2/interpreter.h" @@ -78,7 +79,7 @@ void Process_fx_queue(void) { switch (fxq[j].type) { case FX_RANDOM: // 1 in 'delay' chance of this fx occurring - if (rand() % fxq[j].delay == 0) + if (g_sword2->_rnd.getRandomNumber(fxq[j].delay) == 0) Trigger_fx(j); break; case FX_SPOT: @@ -190,9 +191,8 @@ int32 FN_play_fx(int32 *params) { if (fxq[j].type == FX_RANDOM) { // 'delay' param is the intended average no. seconds between - // playing this effect (+1 to avoid divide-by-zero in - // Process_fx_queue) - fxq[j].delay = params[2] * 12 + 1; + // playing this effect + fxq[j].delay = params[2] * 12; } else { // FX_SPOT or FX_LOOP: // 'delay' is no. frames to wait before playing diff --git a/sword2/sword2.h b/sword2/sword2.h index 8d592879ae..0e0fd28447 100644 --- a/sword2/sword2.h +++ b/sword2/sword2.h @@ -71,6 +71,7 @@ public: byte _gameId; char *_game_name; // target name for saves Sound *_sound; + Common::RandomSource _rnd; private: bool _quit; -- cgit v1.2.3