aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/engine/kmath.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sci/engine/kmath.cpp')
-rw-r--r--engines/sci/engine/kmath.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/engines/sci/engine/kmath.cpp b/engines/sci/engine/kmath.cpp
index ef795d7e2f..7570856dff 100644
--- a/engines/sci/engine/kmath.cpp
+++ b/engines/sci/engine/kmath.cpp
@@ -37,6 +37,14 @@ reg_t kRandom(EngineState *s, int argc, reg_t *argv) {
// 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();
+ // Some scripts may request a range in the reverse order (from largest
+ // to smallest). An example can be found in Longbow, room 710, where a
+ // random number is requested from 119 to 83. In this case, we're
+ // supposed to return toNumber (determined by the KQ5CD disasm).
+ // Fixes bug #3413020.
+ if (fromNumber > toNumber)
+ return make_reg(0, toNumber);
+
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