diff options
-rw-r--r-- | engines/adl/adl_v2.cpp | 20 | ||||
-rw-r--r-- | engines/adl/adl_v2.h | 10 |
2 files changed, 27 insertions, 3 deletions
diff --git a/engines/adl/adl_v2.cpp b/engines/adl/adl_v2.cpp index 7560504c3c..3a938b3ae5 100644 --- a/engines/adl/adl_v2.cpp +++ b/engines/adl/adl_v2.cpp @@ -20,12 +20,19 @@ * */ +#include "common/random.h" + #include "adl/adl_v2.h" namespace Adl { +AdlEngine_v2::~AdlEngine_v2() { + delete _random; +} + AdlEngine_v2::AdlEngine_v2(OSystem *syst, const AdlGameDescription *gd) : AdlEngine(syst, gd) { + _random = new Common::RandomSource("adl"); } typedef Common::Functor1Mem<ScriptEnv &, int, AdlEngine_v2> OpcodeV2; @@ -39,8 +46,8 @@ void AdlEngine_v2::setupOpcodeTables() { SetOpcodeTable(_condOpcodes); // 0x00 OpcodeUnImpl(); - OpcodeUnImpl(); - OpcodeUnImpl(); + Opcode(o2_isFirstTime); + Opcode(o2_isRandomGT); Opcode(o2_isItemInRoom); // 0x04 Opcode(o2_isNounNotInRoom); @@ -104,6 +111,15 @@ int AdlEngine_v2::o2_isFirstTime(ScriptEnv &e) { return 0; } +int AdlEngine_v2::o2_isRandomGT(ScriptEnv &e) { + byte rnd = _random->getRandomNumber(255); + + if (e.arg(1) >= rnd) + return -1; + + return 1; +} + int AdlEngine_v2::o2_isItemInRoom(ScriptEnv &e) { byte room = e.arg(2); diff --git a/engines/adl/adl_v2.h b/engines/adl/adl_v2.h index 61c811b02f..5513da38a8 100644 --- a/engines/adl/adl_v2.h +++ b/engines/adl/adl_v2.h @@ -28,11 +28,15 @@ #define IDI_CUR_ROOM 0xfc #define IDI_VOID_ROOM 0xfd +namespace Common{ +class RandomSource; +} + namespace Adl { class AdlEngine_v2 : public AdlEngine { public: - virtual ~AdlEngine_v2() { } + virtual ~AdlEngine_v2(); protected: AdlEngine_v2(OSystem *syst, const AdlGameDescription *gd); @@ -40,10 +44,14 @@ protected: virtual void setupOpcodeTables(); int o2_isFirstTime(ScriptEnv &e); + int o2_isRandomGT(ScriptEnv &e); int o2_isItemInRoom(ScriptEnv &e); int o2_isNounNotInRoom(ScriptEnv &e); int o2_moveItem(ScriptEnv &e); + +private: + Common::RandomSource *_random; }; } // End of namespace Adl |