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

Unkillable troll (Zork 1) #23

Closed
stephendcofer opened this issue Aug 13, 2023 · 9 comments
Closed

Unkillable troll (Zork 1) #23

stephendcofer opened this issue Aug 13, 2023 · 9 comments

Comments

@stephendcofer
Copy link

stephendcofer commented Aug 13, 2023

s; e; open window; w; take all; w; take all; move rug; open trap door; turn on lamp; d; n; kill troll with sword; kill troll with sword

In Frotz and the original game, this is enough to kill the troll. In mojozork (from current source and the version downloadable in retroarch), it constantly gives you "miss" messages with the occasional "staggered/dropped weapon" statuses, but repeating the command goes back to more "miss" messages. In fact, repeating "kill troll with sword" over and over will never kill the troll.

This behavior is constant on every platform and with libretro as well as every single Zork 1 data file I've tried, including the one you include in this repository, one I had from an Infocom compilation, and the one from Zork Anthology on Steam.

@icculus
Copy link
Owner

icculus commented Aug 13, 2023

This definitely works here, using the latest in this repository with the RetroArch that ships with Steam:

s
e
open window
w
take all
w
take all
move rug
open trap door
turn on lamp
d
n
kill troll with sword
kill troll with sword

image

@icculus
Copy link
Owner

icculus commented Aug 13, 2023

Hmm...what platform are you on? I wonder if the random number generator is doing something unexpected.

@stephendcofer
Copy link
Author

stephendcofer commented Aug 14, 2023

Screenshot 2023-08-13 203708
This was tested with Windows 11, Windows 10 (previously, I've been seeing the same behavior for a while now, even back when I was running Windows 10 on another machine), xxxx. Did a pull today on the source, compiled in Windows 11 on Visual Studio xxxx, and tested both standalone and libretro versions.

Edit: previously stated I tested on Ubuntu, I confused that with something else I was trying. I had tried it on Ubuntu previously and got the same behavior. But I just now tested the source on Debian Bullseye and... it worked? So blame Windows. As usual.

@icculus
Copy link
Owner

icculus commented Aug 14, 2023

Ah, so this uses random and then a bunch of math to get a random number.

BUT, not having random in Visual Studio, we define it to use rand ... which, on Visual Studio, returns a number between 0 and 0x7FFF (way smaller than other platforms, I think it's a holdover from 16-bit Windows or MS-DOS).

So we do this...

        long r = random();
        r = (r >> (sizeof (r) / 2) * 8) ^ r;

I don't know why I'm doing that second line (it might be in the Z-Machine spec?) but when "long" is 32-bits, like it is in Visual Studio, and the largest random number is 0x7FFF, this always results in zero by the time you hit the ^ r at the end, so the random number is always the same.

That's my guess, at least. I'll check for sure soon.

icculus added a commit that referenced this issue Aug 14, 2023
@icculus
Copy link
Owner

icculus commented Aug 14, 2023

When you get a chance, see if the latest in revision control fixes it for you!

@stephendcofer
Copy link
Author

stephendcofer commented Aug 14, 2023

It's fixed in standalone mojozork, but the fact that you axed srandom in mojozork.c broke compilation of mojozork-libretro.c where it still expects it to be defined in mojozork.c. (I just axed libretro build from CMakeLists.txt [set(MOJOZORK_LIBRETRO_DEFAULT OFF)] to test.)

Thanks for the attention to this, by the way.

@icculus
Copy link
Owner

icculus commented Aug 14, 2023

Okay, easy fix, then, I'll correct that shortly.

@icculus
Copy link
Owner

icculus commented Aug 14, 2023

Ok, you should be good to go now!

@stephendcofer
Copy link
Author

Looks good, thank you.

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

No branches or pull requests

2 participants