diff options
author | Martin Kiewitz | 2010-08-20 21:59:14 +0000 |
---|---|---|
committer | Martin Kiewitz | 2010-08-20 21:59:14 +0000 |
commit | 1b9d95e43c1dce369d8a929ede4b144290729e96 (patch) | |
tree | 78ad9c66b41fb42f7dc795235edea341a26de79c /engines | |
parent | 769ad3109dfd54a61ffc9ebc02333986d9a3d8a4 (diff) | |
download | scummvm-rg350-1b9d95e43c1dce369d8a929ede4b144290729e96.tar.gz scummvm-rg350-1b9d95e43c1dce369d8a929ede4b144290729e96.tar.bz2 scummvm-rg350-1b9d95e43c1dce369d8a929ede4b144290729e96.zip |
SCI: kRandom now exactly behaving like sierra sci
hoyle4 and lsl5 door code work now
svn-id: r52244
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sci/engine/kmath.cpp | 48 |
1 files changed, 13 insertions, 35 deletions
diff --git a/engines/sci/engine/kmath.cpp b/engines/sci/engine/kmath.cpp index 31f2d419bc..54e91cbcaf 100644 --- a/engines/sci/engine/kmath.cpp +++ b/engines/sci/engine/kmath.cpp @@ -35,41 +35,19 @@ reg_t kRandom(EngineState *s, int argc, reg_t *argv) { return NULL_REG; case 2: { // get random number - // These are unsigned (e.g. in LSL5, this is used for the 5-digit - // door access code with Patty at k rap) - int fromNumber = argv[0].toUint16(); - int toNumber = argv[1].toUint16(); - - // HACK: Hoyle 4 calls this with (0x0, 0xFFFF) in some dialogs for x, - // then it calls it with (0x0, 0x40) and puts x plus the result in y - // to displace view 924 in kDrawCel right afterwards and create a - // semi-random background in those dialogs. With the current code, - // this case isn't handled properly, and the dialog background is - // drawn off-screen. -1 seems to be incorrect here (probably a newly - // added special case), so we just return a 0 for now, till we - // figure out how to handle this. - if (fromNumber == 0 && toNumber == 0xFFFF) { - if (g_sci->getGameId() == GID_HOYLE4) { - warning("HACK: Special case for Hoyle 4 dialogs in kRandom"); - return NULL_REG; - } else { - // Just throw a warning in other games for now, but don't modify - // the result... - warning("kRandom(0x0, 0xFFFF) called - special case?"); - } - - } - - // TODO/CHECKME: It is probably not required to check whether - // toNumber is greater than fromNumber, at least not when one - // goes by their names, but let us be on the safe side and - // allow toNumber to be smaller than fromNumber too. - if (fromNumber > toNumber) - SWAP(fromNumber, toNumber); - - const uint diff = (uint)(toNumber - fromNumber); - - const int randomNumber = fromNumber + (int)g_sci->getRNG().getRandomNumber(diff); + // numbers are definitely unsigned, for example lsl5 door code in k rap radio is random + // and 5-digit - we get called kRandom(10000, 65000) + // some codes in sq4 are also random and 5 digit (if i remember correctly) + const uint16 fromNumber = argv[0].toUint16(); + const uint16 toNumber = argv[1].toUint16(); + uint16 range = toNumber - fromNumber + 1; + // calculating range is exactly how sierra sci did it and is required for hoyle 4 + // where we get called with kRandom(0, -1) and we are supposed to give back values from 0 to 0 + // the returned value will be used as displace-offset for a background cel + if (range) + range--; // the range value was never returned, our random generator gets 0->range, so fix it + + const int randomNumber = fromNumber + (int)g_sci->getRNG().getRandomNumber(range); return make_reg(0, randomNumber); } |