diff options
author | Matthew Hoops | 2010-02-16 03:01:46 +0000 |
---|---|---|
committer | Matthew Hoops | 2010-02-16 03:01:46 +0000 |
commit | 5fd7dbb4061d808e4bc4c0cfba5e2eabf2687544 (patch) | |
tree | fe996c14b52c9211651a8106fb9637e3822bba80 /engines | |
parent | b3ab83d8c125f8a7d8bafce04a3db11c3cdddec1 (diff) | |
download | scummvm-rg350-5fd7dbb4061d808e4bc4c0cfba5e2eabf2687544.tar.gz scummvm-rg350-5fd7dbb4061d808e4bc4c0cfba5e2eabf2687544.tar.bz2 scummvm-rg350-5fd7dbb4061d808e4bc4c0cfba5e2eabf2687544.zip |
Move Riven variable randomization to initVars() and implement randomization for the dome and prison combinations.
svn-id: r48070
Diffstat (limited to 'engines')
-rw-r--r-- | engines/mohawk/riven.cpp | 5 | ||||
-rw-r--r-- | engines/mohawk/riven.h | 1 | ||||
-rw-r--r-- | engines/mohawk/riven_external.cpp | 25 | ||||
-rw-r--r-- | engines/mohawk/riven_external.h | 1 | ||||
-rw-r--r-- | engines/mohawk/riven_vars.cpp | 28 |
5 files changed, 40 insertions, 20 deletions
diff --git a/engines/mohawk/riven.cpp b/engines/mohawk/riven.cpp index cd1e71564c..d15a082469 100644 --- a/engines/mohawk/riven.cpp +++ b/engines/mohawk/riven.cpp @@ -25,6 +25,7 @@ #include "common/config-manager.h" #include "common/events.h" +#include "common/EventRecorder.h" #include "common/keyboard.h" #include "mohawk/graphics.h" @@ -60,6 +61,7 @@ MohawkEngine_Riven::~MohawkEngine_Riven() { delete[] _vars; delete _loadDialog; delete _optionsDialog; + delete _rnd; _cardData.scripts.clear(); } @@ -79,6 +81,9 @@ Common::Error MohawkEngine_Riven::run() { _loadDialog->setSaveMode(false); _optionsDialog = new RivenOptionsDialog(this); + _rnd = new Common::RandomSource(); + g_eventRec.registerRandomSource(*_rnd, "riven"); + initVars(); // Open extras.mhk for common images (non-existant in the demo) diff --git a/engines/mohawk/riven.h b/engines/mohawk/riven.h index 9cb43ebe9d..2d50fc0db5 100644 --- a/engines/mohawk/riven.h +++ b/engines/mohawk/riven.h @@ -107,6 +107,7 @@ public: RivenGraphics *_gfx; RivenExternal *_externalScriptHandler; + Common::RandomSource *_rnd; Card _cardData; bool _gameOver; diff --git a/engines/mohawk/riven_external.cpp b/engines/mohawk/riven_external.cpp index 51bfcd409d..edabc10946 100644 --- a/engines/mohawk/riven_external.cpp +++ b/engines/mohawk/riven_external.cpp @@ -29,20 +29,16 @@ #include "mohawk/sound.h" #include "mohawk/video/video.h" -#include "common/EventRecorder.h" #include "gui/message.h" +#include "common/events.h" namespace Mohawk { RivenExternal::RivenExternal(MohawkEngine_Riven *vm) : _vm(vm) { setupCommands(); - _rnd = new Common::RandomSource(); - g_eventRec.registerRandomSource(*_rnd, "riven"); } RivenExternal::~RivenExternal() { - delete _rnd; - for (uint32 i = 0; i < _externalCommands.size(); i++) delete _externalCommands[i]; @@ -1052,27 +1048,27 @@ void RivenExternal::xhandlecontrolmid(uint16 argc, uint16 *argv) { void RivenExternal::xjplaybeetle_550(uint16 argc, uint16 *argv) { // Play a beetle animation 25% of the time - *_vm->matchVarToString("jplaybeetle") = (_rnd->getRandomNumberRng(0, 3) == 0) ? 1 : 0; + *_vm->matchVarToString("jplaybeetle") = (_vm->_rnd->getRandomNumberRng(0, 3) == 0) ? 1 : 0; } void RivenExternal::xjplaybeetle_600(uint16 argc, uint16 *argv) { // Play a beetle animation 25% of the time - *_vm->matchVarToString("jplaybeetle") = (_rnd->getRandomNumberRng(0, 3) == 0) ? 1 : 0; + *_vm->matchVarToString("jplaybeetle") = (_vm->_rnd->getRandomNumberRng(0, 3) == 0) ? 1 : 0; } void RivenExternal::xjplaybeetle_950(uint16 argc, uint16 *argv) { // Play a beetle animation 25% of the time - *_vm->matchVarToString("jplaybeetle") = (_rnd->getRandomNumberRng(0, 3) == 0) ? 1 : 0; + *_vm->matchVarToString("jplaybeetle") = (_vm->_rnd->getRandomNumberRng(0, 3) == 0) ? 1 : 0; } void RivenExternal::xjplaybeetle_1050(uint16 argc, uint16 *argv) { // Play a beetle animation 25% of the time - *_vm->matchVarToString("jplaybeetle") = (_rnd->getRandomNumberRng(0, 3) == 0) ? 1 : 0; + *_vm->matchVarToString("jplaybeetle") = (_vm->_rnd->getRandomNumberRng(0, 3) == 0) ? 1 : 0; } void RivenExternal::xjplaybeetle_1450(uint16 argc, uint16 *argv) { // Play a beetle animation 25% of the time as long as the girl is not present - *_vm->matchVarToString("jplaybeetle") = (_rnd->getRandomNumberRng(0, 3) == 0 && *_vm->matchVarToString("jgirl") != 1) ? 1 : 0; + *_vm->matchVarToString("jplaybeetle") = (_vm->_rnd->getRandomNumberRng(0, 3) == 0 && *_vm->matchVarToString("jgirl") != 1) ? 1 : 0; } void RivenExternal::xjlagoon700_alert(uint16 argc, uint16 *argv) { @@ -1375,15 +1371,6 @@ void RivenExternal::xtatrusgivesbooks(uint16 argc, uint16 *argv) { // Give the player Atrus' Journal and the Trap book *_vm->matchVarToString("aatrusbook") = 1; *_vm->matchVarToString("atrapbook") = 1; - - // Randomize the telescope combination - uint32 *teleCombo = _vm->matchVarToString("tcorrectorder"); - for (byte i = 0; i < 5; i++) { - *teleCombo *= 10; - *teleCombo += _rnd->getRandomNumberRng(1, 5); - } - - // TODO: Randomize Dome Combination } // Trap Book is removed from inventory diff --git a/engines/mohawk/riven_external.h b/engines/mohawk/riven_external.h index 2b8a90f8fd..8270a00854 100644 --- a/engines/mohawk/riven_external.h +++ b/engines/mohawk/riven_external.h @@ -41,7 +41,6 @@ public: private: MohawkEngine_Riven *_vm; - Common::RandomSource *_rnd; typedef void (RivenExternal::*ExternalCmd)(uint16 argc, uint16 *argv); diff --git a/engines/mohawk/riven_vars.cpp b/engines/mohawk/riven_vars.cpp index ed540cd82e..3f7cd5a8b6 100644 --- a/engines/mohawk/riven_vars.cpp +++ b/engines/mohawk/riven_vars.cpp @@ -319,6 +319,34 @@ void MohawkEngine_Riven::initVars() { *matchVarToString("bheat") = 1; *matchVarToString("waterenabled") = 1; *matchVarToString("ogehnpage") = 1; + + // Randomize the telescope combination + uint32 *teleCombo = matchVarToString("tcorrectorder"); + for (byte i = 0; i < 5; i++) { + *teleCombo *= 10; + *teleCombo += _rnd->getRandomNumberRng(1, 5); // 5 buttons + } + + // Randomize the prison combination + uint32 *prisonCombo = matchVarToString("pcorrectorder"); + for (byte i = 0; i < 5; i++) { + *prisonCombo *= 10; + *prisonCombo += _rnd->getRandomNumberRng(1, 3); // 3 buttons/sounds + } + + // Randomize the dome combination -- each bit represents a slider position, + // the highest bit (1 << 24) represents 1, (1 << 23) represents 2, etc. + uint32 *domeCombo = matchVarToString("adomecombo"); + for (byte bitsSet = 0; bitsSet < 5;) { + uint32 randomBit = 1 << (24 - _rnd->getRandomNumber(24)); + + // Don't overwrite a bit we already set, and throw out the bottom five bits being set + if (*domeCombo & randomBit || (*domeCombo | randomBit) == 31) + continue; + + *domeCombo |= randomBit; + bitsSet++; + } } } // End of namespace Mohawk |