From 261fc2f4beb0aef9ab0a32afdedac4a87561f26f Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sat, 3 Mar 2012 13:55:04 +0100 Subject: DREAMWEB: Simplify some uses of randomNumber() Our random number generator isn't restricted to producing numbers between 0 and 255. We can just ask it for the desired range. --- engines/dreamweb/monitor.cpp | 2 +- engines/dreamweb/people.cpp | 2 +- engines/dreamweb/rain.cpp | 16 ++++------------ engines/dreamweb/sprite.cpp | 4 ++-- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/engines/dreamweb/monitor.cpp b/engines/dreamweb/monitor.cpp index cdef60e94d..95aa400c3a 100644 --- a/engines/dreamweb/monitor.cpp +++ b/engines/dreamweb/monitor.cpp @@ -320,7 +320,7 @@ void DreamWebEngine::randomAccess(uint16 count) { for (uint16 i = 0; i < count; ++i) { vSync(); vSync(); - uint16 v = randomNumber() & 15; + uint16 v = _rnd.getRandomNumber(15); if (v < 10) accessLightOff(); else diff --git a/engines/dreamweb/people.cpp b/engines/dreamweb/people.cpp index 316a1689c9..dfb5c62618 100644 --- a/engines/dreamweb/people.cpp +++ b/engines/dreamweb/people.cpp @@ -262,7 +262,7 @@ void DreamWebEngine::gamer(ReelRoutine &routine) { if (checkSpeed(routine)) { uint8 v; do { - v = 20 + randomNumber() % 5; + v = _rnd.getRandomNumberRng(20, 24); } while (v == routine.reelPointer()); routine.setReelPointer(v); } diff --git a/engines/dreamweb/rain.cpp b/engines/dreamweb/rain.cpp index 0a8ee2a38e..7db4744cbf 100644 --- a/engines/dreamweb/rain.cpp +++ b/engines/dreamweb/rain.cpp @@ -104,8 +104,8 @@ void DreamWebEngine::splitIntoLines(uint8 x, uint8 y) { } rain.size = length; - rain.w3 = (randomNumber() << 8) | randomNumber(); - rain.b5 = (randomNumber() & 3) + 4; + rain.w3 = _rnd.getRandomNumber(65535); + rain.b5 = _rnd.getRandomNumberRng(4, 7); _rainList.push_back(rain); } while (x > 0 && y < _mapYSize); } @@ -170,11 +170,7 @@ void DreamWebEngine::initRain() { // start lines of rain from top of screen uint8 x = 4; do { - uint8 delta; - do { - delta = (randomNumber() & 31) + 3; - } while (delta >= rainSpacing); - + uint8 delta = _rnd.getRandomNumberRng(3, rainSpacing - 1); x += delta; if (x >= _mapXSize) break; @@ -185,11 +181,7 @@ void DreamWebEngine::initRain() { // start lines of rain from side of screen uint8 y = 0; do { - uint8 delta; - do { - delta = (randomNumber() & 31) + 3; - } while (delta >= rainSpacing); - + uint8 delta = _rnd.getRandomNumberRng(3, rainSpacing - 1); y += delta; if (y >= _mapYSize) break; diff --git a/engines/dreamweb/sprite.cpp b/engines/dreamweb/sprite.cpp index 4bbc31b54e..3df324abe1 100644 --- a/engines/dreamweb/sprite.cpp +++ b/engines/dreamweb/sprite.cpp @@ -263,8 +263,8 @@ void DreamWebEngine::constant(Sprite *sprite, SetObject *objData) { } void DreamWebEngine::randomSprite(Sprite *sprite, SetObject *objData) { - uint8 r = randomNumber(); - sprite->frameNumber = objData->frames[r&7]; + uint8 r = _rnd.getRandomNumber(7); + sprite->frameNumber = objData->frames[r]; } void DreamWebEngine::doorway(Sprite *sprite, SetObject *objData) { -- cgit v1.2.3