From b2c24dd640eba57c1c2460a027f021118ca44920 Mon Sep 17 00:00:00 2001 From: Denis Kasak Date: Mon, 6 Jul 2009 19:26:53 +0000 Subject: [PATCH] Implemented Script::funcRandom (GPL function). svn-id: r42191 --- engines/draci/script.cpp | 13 ++++++++++++- engines/draci/script.h | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/engines/draci/script.cpp b/engines/draci/script.cpp index 3a39f61e2d0..330fc85d0a8 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 ¶ms) { diff --git a/engines/draci/script.h b/engines/draci/script.h index 6259f675a51..16bef9c7ff6 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);