Health Point/Hit Point Generator When Leveling

Post here if you need help getting started with Daggerfall Unity or just want to clarify a potential bug. Questions about playing or modding classic Daggerfall should be posted to Community.
DFIronman
Posts: 84
Joined: Sat Aug 24, 2019 12:48 am

Re: Health Point/Hit Point Generator When Leveling

Post by DFIronman »

I know this is already solved, but I had a similar issue as well. Whenever I reloaded a game that was saved in my custom court window (added this functionality so players couldn't escape execution with ALT-F4), I was constantly getting the same punishment. I solved it by re-seeding the random generator on saved game load.

Maybe re-seeding after loading a save is something that should be added to core to prevent other edge cases like this?

User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Health Point/Hit Point Generator When Leveling

Post by Ralzar »

Oh damn. Good thing this thread popped up again. I have been having a problem with LevelUp Adjuster. Which uses Formula Overrides to change the number of points in the pool. Where it has noticably been returning the same number a bit too often.
I'll try adding the same fix to my override code.

User avatar
pango
Posts: 3347
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Health Point/Hit Point Generator When Leveling

Post by pango »

DFIronman wrote: Wed Aug 25, 2021 10:05 pm I know this is already solved, but I had a similar issue as well. Whenever I reloaded a game that was saved in my custom court window (added this functionality so players couldn't escape execution with ALT-F4), I was constantly getting the same punishment. I solved it by re-seeding the random generator on saved game load.

Maybe re-seeding after loading a save is something that should be added to core to prevent other edge cases like this?
Well, if you get always the same pseudo random values by executing some code over and over, it means the random generator is reseeded with the same value somewhere in the "loop" already (otherwise you'll just get a pseudo random sequence).
If that's between the moment the game is reloaded and the moment the pseudo random value is generated, reseeding during reloading will achieve nothing, because the problematic reseeding that comes after will overwrite it. A good reseeding has to be done right before the random values will be generated.

It would be ever better to fix the root issues, but I'm not sure how to determine where poor reseeding happens, to eliminate it or use better reseeding...
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
Interkarma
Posts: 7236
Joined: Sun Mar 22, 2015 1:51 am

Re: Health Point/Hit Point Generator When Leveling

Post by Interkarma »

The root cause in case above was that bonus pool wasn't being seeded at all prior to roll. This has been fixed in below change.

https://github.com/Interkarma/daggerfal ... 4e81165875

Ralzar might have different needs and want to use a different seed method however.

User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Health Point/Hit Point Generator When Leveling

Post by Ralzar »

My behaviour was actually that I was using Ironman Options with a bunch of deadly mods. So I had the experience of:

Make character
Level up to lvl2
Get 1 Attribute point (my mod set it to a 1-9 range instead of 4-6)
Die
Make new character
Level up to lvl2
Get 1 Attribute point
etc

I thought I was rolling a weirdly high amount of 1s...

I have now added your live of code to reseed the randomizer. I'll see if it makes any difference. Usually I would not have noticed because I generally just save after having leveled up. But this time, because of Ironman, I was doing a lot more rolls since I kept making new characters without exiting the game.

DFIronman
Posts: 84
Joined: Sat Aug 24, 2019 12:48 am

Re: Health Point/Hit Point Generator When Leveling

Post by DFIronman »

pango wrote: Wed Aug 25, 2021 10:27 pm Well, if you get always the same pseudo random values by executing some code over and over, it means the random generator is reseeded with the same value somewhere in the "loop" already (otherwise you'll just get a pseudo random sequence).
If that's between the moment the game is reloaded and the moment the pseudo random value is generated, reseeding during reloading will achieve nothing, because the problematic reseeding that comes after will overwrite it. A good reseeding has to be done right before the random values will be generated.

It would be ever better to fix the root issues, but I'm not sure how to determine where poor reseeding happens, to eliminate it or use better reseeding...
Ah, you're right. It probably is best to just re-init the seed right before generation.
Interkarma wrote: Wed Aug 25, 2021 11:14 pm The root cause in case above was that bonus pool wasn't being seeded at all prior to roll. This has been fixed in below change.
👍
Ralzar wrote: Thu Aug 26, 2021 7:27 am I have now added your live of code to reseed the randomizer. I'll see if it makes any difference.
Nice, hope it works.

Post Reply