[Scummvm-git-logs] scummvm master -> f787b482c8ca07271821c7dee7a2c762e2e79b8a
digitall
noreply at scummvm.org
Tue Nov 28 13:22:46 UTC 2023
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
f787b482c8 MOHAWK: RIVEN: Generate dome code as in original game
Commit: f787b482c8ca07271821c7dee7a2c762e2e79b8a
https://github.com/scummvm/scummvm/commit/f787b482c8ca07271821c7dee7a2c762e2e79b8a
Author: vholten (vholten at users.noreply.github.com)
Date: 2023-11-28T13:22:41Z
Commit Message:
MOHAWK: RIVEN: Generate dome code as in original game
In the original game, the dome combination is not completely random;
only the first number is one that can be seen in the school (range 2-10),
two numbers are chosen from the range 11-15, and two are chosen
from the range 16-24. Presumably, this is done so that the code has
approximately equal difficulty for every game.
Until now, scummvm has generated completely random codes,
which results in some games having very easy codes (when most of
the numbers are below 10). Also, there's a 20% chance that
the last number is 25, which is never used in the original game.
Changed paths:
engines/mohawk/riven_vars.cpp
diff --git a/engines/mohawk/riven_vars.cpp b/engines/mohawk/riven_vars.cpp
index 968205b2ab2..ecec405d212 100644
--- a/engines/mohawk/riven_vars.cpp
+++ b/engines/mohawk/riven_vars.cpp
@@ -277,6 +277,22 @@ uint32 &MohawkEngine_Riven::getStackVar(uint32 index) {
return _vars[name];
}
+namespace {
+
+uint32 getTwoRandomDomePositionsRng(Common::RandomSource *rnd, uint min, uint max) {
+ uint first = rnd->getRandomNumberRng(min, max);
+ uint second = rnd->getRandomNumberRng(min, max - 1);
+
+ // Avoid overlap of the two positions
+ if (second >= first) {
+ second++;
+ }
+
+ return 1 << (25 - first) | 1 << (25 - second);
+}
+
+} // End of anonymous namespace
+
void MohawkEngine_Riven::initVars() {
// Most variables just start at 0, it's simpler to do this
for (uint32 i = 0; i < ARRAYSIZE(variableNames); i++)
@@ -337,17 +353,14 @@ void MohawkEngine_Riven::initVars() {
// Randomize the dome combination -- each bit represents a slider position,
// the highest bit (1 << 24) represents 1, (1 << 23) represents 2, etc.
+ // The dome combination is not completely random:
+ // - The first slider position is a random number in the range [2, 10].
+ // - The second and third slider positions are randomly chosen from the interval [11, 15].
+ // - The fourth and fifth slider positions are randomly chosen from the interval [16, 24].
uint32 &domeCombo = _vars["adomecombo"];
- for (byte bitsSet = 0; bitsSet < 5;) {
- uint32 randomBit = 1 << (24 - _rnd->getRandomNumber(24));
-
- // Don't overwrite a bit we already set, and throw out the bottom five bits being set
- if (domeCombo & randomBit || (domeCombo | randomBit) == 31)
- continue;
-
- domeCombo |= randomBit;
- bitsSet++;
- }
+ domeCombo |= 1 << (25 - _rnd->getRandomNumberRng(2, 10));
+ domeCombo |= getTwoRandomDomePositionsRng(_rnd, 11, 15);
+ domeCombo |= getTwoRandomDomePositionsRng(_rnd, 16, 24);
}
} // End of namespace Mohawk
More information about the Scummvm-git-logs
mailing list