diff options
-rw-r--r-- | engines/draci/script.cpp | 13 | ||||
-rw-r--r-- | engines/draci/script.h | 2 |
2 files changed, 14 insertions, 1 deletions
diff --git a/engines/draci/script.cpp b/engines/draci/script.cpp index 3a39f61e2d..330fc85d0a 100644 --- a/engines/draci/script.cpp +++ b/engines/draci/script.cpp @@ -117,7 +117,7 @@ void Script::setupCommandList() { /** Functions used by the mathematical evaluator */ static const GPL2Function gplFunctions[] = { { "Not", NULL }, - { "Random", NULL }, + { "Random", &Script::funcRandom }, { "IsIcoOn", NULL }, { "IsIcoAct", NULL }, { "IcoStat", NULL }, @@ -207,6 +207,17 @@ int Script::operMod(int op1, int op2) { return op1 % op2; } +/* GPL functions */ + +int Script::funcRandom(int n) { + +// The function needs to return numbers in the [0..n-1] range so we need to deduce 1 +// (RandomSource::getRandomNumber returns a number in the range [0..n]) + + n -= 1; + return _vm->_rnd.getRandomNumber(n); +} + /* GPL commands */ void Script::load(Common::Queue<int> ¶ms) { diff --git a/engines/draci/script.h b/engines/draci/script.h index 6259f675a5..16bef9c7ff 100644 --- a/engines/draci/script.h +++ b/engines/draci/script.h @@ -115,6 +115,8 @@ private: int operLessOrEqual(int op1, int op2); int operMod(int op1, int op2); + int funcRandom(int n); + void setupCommandList(); const GPL2Command *findCommand(byte num, byte subnum); int handleMathExpression(Common::MemoryReadStream &reader); |