Am I understanding RandomEncounters.cs correctly?

Discuss coding questions, pull requests, and implementation details.
Post Reply
Odyzinomin
Posts: 3
Joined: Mon Jan 23, 2023 11:23 pm

Am I understanding RandomEncounters.cs correctly?

Post by Odyzinomin »

I see there has been discussion of this topic in the past, but not quite my particular area of concern.

First off, I'm not entirely clear on whether this is the "classic" mode or the "alternate."

Regardless of which it is, here's how I understand it:

A dice roll is made from 1-100. A roll of 1-80 results in picking from the encounter table slots equal to the player level -3 to the player level +3, a range of six slots.
A roll of 81-95 means picking from slot 0 to a slot equal to the player level +1. And a roll of 96-100 uses the entire table after Level 5. Essentially, particularly at higher levels, it is much more random and the two special results combined allow the player to encounter enemies from below their normal range that otherwise no longer spawn, and there is a roughly 20% chance of this occurring.

The problem, as I see it, is in the code for for the 81-95 range. At Level 18, the code will set the minimum to 0 and the maximum to 19, creating the same result as if a 96 or higher had been rolled. But at Level 19, this will set the maximum to 20. And later in the code on lines 1508-1512, this means the maximum will be adjusted back to 19. All well and good, but then on line 1510 the minimum is ALSO changed, to 14. In other words starting at Level 19, a player's chance of seeing the full encounter list is reduced from 20% to 5%.

Do I have this right and if so, is this intentional?

(Either way I'm not clear on whether this calculation is made on a per enemy/encounter basis or per dungeon/area.)

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

Re: Am I understanding RandomEncounters.cs correctly?

Post by pango »

Odyzinomin wrote: Tue Jan 24, 2023 12:02 am First off, I'm not entirely clear on whether this is the "classic" mode or the "alternate."
That's classic. (I tried to understand what alternate does, quite some time ago, I found it less interesting).
Odyzinomin wrote: Tue Jan 24, 2023 12:02 am Regardless of which it is, here's how I understand it:
[...]
But at Level 19, [....] a player's chance of seeing the full encounter list is reduced from 20% to 5%.
I come to the same conclusions, if I specialize the code with playerLevel = 18 I get

Code: Select all

if (roll > 80)
{
    min = 0;
    max = 19;
}
else
{
    min = 14;
    max = 19;
}
And if I specialize code with playerLevel = 19 I get

Code: Select all

if (roll > 95)
{
    min = 0;
    max = 19;
}
else
{
    min = 14;
    max = 19;
}
Odyzinomin wrote: Tue Jan 24, 2023 12:02 am Do I have this right and if so, is this intentional?
On one hard enemies are less diverse, on the other hand it focuses more on late game enemies. Is that on purpose? Hard to tell, first because this is reverse-engineered code, so we don't get to read comments or documentation about the rationale behind the code; And second, I guess the guy who did that reverse-engineering is no longer working on DFU, so he's most likely not reading this thread to comment either.
Odyzinomin wrote: Tue Jan 24, 2023 12:02 am (Either way I'm not clear on whether this calculation is made on a per enemy/encounter basis or per dungeon/area.)
It's only used when you're resting or loitering is interrupted, and that the game spawns a new enemy. So that's by enemy/encounter, I guess?
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

Odyzinomin
Posts: 3
Joined: Mon Jan 23, 2023 11:23 pm

Re: Am I understanding RandomEncounters.cs correctly?

Post by Odyzinomin »

pango wrote: Tue Jan 24, 2023 11:47 pm On one hard enemies are less diverse, on the other hand it focuses more on late game enemies. Is that on purpose? Hard to tell, first because this is reverse-engineered code, so we don't get to read comments or documentation about the rationale behind the code; And second, I guess the guy who did that reverse-engineering is no longer working on DFU, so he's most likely not reading this thread to comment either.
Well it's disappointing to learn that that information has been lost to the mists of time, but I suppose it really shouldn't be unexpected given this game is going to be 30 years old in a few years (I feel old.)
pango wrote: Tue Jan 24, 2023 11:47 pm It's only used when your resting or loitering is interrupted, and that the game spawns a new enemy. So that's by enemy/encounter, I guess?
Hmm, what determines dungeon enemy distribution then?

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

Re: Am I understanding RandomEncounters.cs correctly?

Post by pango »

That's mentioned in more details in the thread linked above for the alternate algorithm.
But in short, they're 17 dungeon types (if you include cemeteries and lost cemeteries) that each have a 20 slots array of enemies (they're additional similar arrays for outside environments); The index min/max from the algorithm is used to pick a slot off those arrays.
That's how enemies distribution depends on the dungeon type you're in, and your level.
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

Odyzinomin
Posts: 3
Joined: Mon Jan 23, 2023 11:23 pm

Re: Am I understanding RandomEncounters.cs correctly?

Post by Odyzinomin »

pango wrote: Wed Jan 25, 2023 7:53 am That's mentioned in more details in the thread linked above for the alternate algorithm.
But in short, they're 17 dungeon types (if you include cemeteries and lost cemeteries) that each have a 20 slots array of enemies (they're additional similar arrays for outside environments); The index min/max from the algorithm is used to pick a slot off those arrays.
That's how enemies distribution depends on the dungeon type you're in, and your level.
Oh. I must have misunderstood what you meant earlier then. What is it that's only used when resting/loitering? Is the dice roll made only once when you enter a dungeon, or for every enemy generated? If the former, does it roll again if you leave/re-enter?

User avatar
Jay_H
Posts: 4062
Joined: Tue Aug 25, 2015 1:54 am
Contact:

Re: Am I understanding RandomEncounters.cs correctly?

Post by Jay_H »

You could probably benefit from reading this page: https://en.uesp.net/wiki/Daggerfall_Mod ... Generation

Post Reply