Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOHAWK: RIVEN: Generate dome code as in original game #5470

Merged
merged 1 commit into from Nov 28, 2023

Conversation

vholten
Copy link
Contributor

@vholten vholten commented Nov 26, 2023

This pull request updates the code that randomizes the combination for the domes, so that the generated combinations correspond to those in the original game.

In the original game, the dome combination is not completely random; only the first number is one that can be learned in the school (range 2–10), the next two numbers are chosen from the range 11–15, and the last two numbers are chosen from the range 16–24. Presumably, this was 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 never occurs in the original game's dome combinations.

Graphical summary of possible values for each position in the combination:
riven dome number ranges

Research

To find the original game's dome combinations, I played the game from an old Riven executable (version 1.02). I made a script with AutoHotkey that creates a new game and saves it, and does this 2000 times. I then extracted the dome combination from each saved game. I analyzed the list of the 2000 combinations to find the possible numbers for each position, as well as how often these occur. The code in this pull request generates numbers with the same probability distribution as in the original game.

Distributions of the five digits in the 2000 combinations generated in the original game
riven dome number distributions

Further confirmation can be found in old let's play videos or old websites where people posted their dome codes (from when the scummvm implementation did not yet exist). They correspond to the allowed possibilities mentioned above.

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.
@dafioram
Copy link
Contributor

Nice work

@sluicebox
Copy link
Member

I love this, and I don't even know Riven. Reverse engineering with AutoHotkey and graphs is just as legitimate as disassembly, arguably much more fun, and produces better visuals. This is a beautiful PR and excellently written.

How do we trick you into doing more?

@digitall
Copy link
Member

@vholten : This change looks reasonable and self-contained. It is certainly closer to the original than the existing algorithm, if it is not perfectly correct. If someone or yourself wishes to check this against the original assembly later and make any minor adjustments, then merging this does not preclude that.

Thank you for your contribution. Merging as-is.

@digitall digitall merged commit f787b48 into scummvm:master Nov 28, 2023
8 checks passed
@vholten
Copy link
Contributor Author

vholten commented Nov 28, 2023

Thanks everyone for the nice and motivating comments.

How do we trick you into doing more?

No tricks necessary! I'm currently looking into a sound-related issue in Zork: Grand Inquisitor (zvision engine). This may or may not be a bug, I'll need to do some more analysis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants