aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorMartin Kiewitz2010-07-28 21:47:15 +0000
committerMartin Kiewitz2010-07-28 21:47:15 +0000
commitabf53f839a090fe6535390a27142964cd44f2566 (patch)
treebcd3a70f205f7e277714fc82a9f8eea6bea1756f /engines
parent07b67fe44b20f8f1c9dcdf659f5e2666d69834f4 (diff)
downloadscummvm-rg350-abf53f839a090fe6535390a27142964cd44f2566.tar.gz
scummvm-rg350-abf53f839a090fe6535390a27142964cd44f2566.tar.bz2
scummvm-rg350-abf53f839a090fe6535390a27142964cd44f2566.zip
SCI: implement additional variants of kRandom
fixes pq1vga poker game (bug #3036125) svn-id: r51435
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/engine/kernel_tables.h2
-rw-r--r--engines/sci/engine/kmath.cpp25
2 files changed, 23 insertions, 4 deletions
diff --git a/engines/sci/engine/kernel_tables.h b/engines/sci/engine/kernel_tables.h
index db19c8ca28..1dfc1d2134 100644
--- a/engines/sci/engine/kernel_tables.h
+++ b/engines/sci/engine/kernel_tables.h
@@ -407,6 +407,8 @@ static SciKernelMapEntry s_kernelMap[] = {
{ MAP_CALL(Portrait), SIG_EVERYWHERE, "i(.*)", NULL, NULL }, // subop
{ MAP_CALL(PrevNode), SIG_EVERYWHERE, "n", NULL, NULL },
{ MAP_CALL(PriCoord), SIG_EVERYWHERE, "i", NULL, NULL },
+ { MAP_CALL(Random), SIG_SCI11, SIGFOR_ALL, "i(i)(i)", NULL, NULL },
+ // ^^ they actually changed it in SCI1, but it seems its never called that way ffs. kRandom
{ MAP_CALL(Random), SIG_EVERYWHERE, "ii", NULL, NULL },
{ MAP_CALL(ReadNumber), SIG_EVERYWHERE, "r", NULL, NULL },
{ MAP_CALL(ResCheck), SIG_EVERYWHERE, "ii(iiii)", NULL, NULL },
diff --git a/engines/sci/engine/kmath.cpp b/engines/sci/engine/kmath.cpp
index eab964d624..124a64d913 100644
--- a/engines/sci/engine/kmath.cpp
+++ b/engines/sci/engine/kmath.cpp
@@ -29,10 +29,27 @@
namespace Sci {
reg_t kRandom(EngineState *s, int argc, reg_t *argv) {
- int fromNumber = argv[0].toUint16();
- int toNumber = argv[1].toUint16();
- double randomNumber = fromNumber + ((toNumber + 1.0 - fromNumber) * (rand() / (RAND_MAX + 1.0)));
- return make_reg(0, (int)randomNumber);
+ // SCI1 actually supported those argcs as well
+ // SCI0 only supported argc = 1 to reset the seed (no input was used, it was reset to 0)
+ switch (argc) {
+ case 1: // set seed to argv[0]
+ return NULL_REG;
+
+ case 2: { // get random number
+ int fromNumber = argv[0].toUint16();
+ int toNumber = argv[1].toUint16();
+ double randomNumber = fromNumber + ((toNumber + 1.0 - fromNumber) * (rand() / (RAND_MAX + 1.0)));
+ return make_reg(0, (int)randomNumber);
+ }
+
+ case 3: // get seed
+ // Actually we would have to return the previous seed
+ error("kRandom: scripts asked for previous seed");
+ break;
+
+ default:
+ error("kRandom: unsupported argc");
+ }
}
reg_t kAbs(EngineState *s, int argc, reg_t *argv) {