Implemented Script::funcRandom (GPL function).

svn-id: r42191
This commit is contained in:
Denis Kasak 2009-07-06 19:26:53 +00:00
parent 218a15d890
commit b2c24dd640
2 changed files with 14 additions and 1 deletions

View File

@ -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> &params) {

View File

@ -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);