## Resting outside is nearly always interrupted

### Re: Resting outside is nearly always interrupted

When I changed the variable in vanilla MW, I had to rest, save, and reload to get the "real" new RNG. I got such things as encounters with <=3 until I realized I needed to do that.

paying attention to #1751 #2473 #3609 #3862/#3929 #3807 #4297 #4623

### Re: Resting outside is nearly always interrupted

First, thank you for getting real test data from Morrowind, and the nice table.dteviot wrote:I did some testing of Vanilla, here's my results.

I slept 50 times for a varying number of hours. (1, 2, 3, 4, 5, 6, 12 and 24), counting the number of times I was interupted.

Assuming that the probability of being interupted was purely a function of time sleeping, I think I can regard the data as a Binomial distribution for each time period.

with p = probability of being disturbed, and (1 - p) probability of not being disturbed.

Then, I use http://en.wikipedia.org/wiki/Binomial_p ... e_interval to estimate the 95% probability for the value of p for different hours.

Giving the following table.

Hours Slept Interruptions estimated p error Min(p) Max(p)

1 0 0 0

2 0 0 0

3 0 0 0

4 8 0.16 0.10 0.06 0.26

5 17 0.34 0.13 0.21 0.47

6 18 0.36 0.13 0.23 0.49

12 8 0.16 0.10 0.06 0.26

24 9 0.18 0.11 0.07 0.29

This isn't quite true. There is no integer rounding, which leaves an obvious footprint in the code. Instead there is another bug during resting, in one of the rest/advance time sub-functions.scrawl wrote:My theory is that it's

with the slight alterationCode: Select all

`(x < fSleepRandMod * hoursToWait) //The Current Formula`

That formula gives a couple of data points I have experimentally confirmed in vanilla:Code: Select all

`(x < int(fSleepRandMod * hoursToWait))`

hours: 1 Interruptions: 0/100,000

hours: 2 Interruptions: 0/100,000

hours: 3 Interruptions: 0/100,000

...

hours: 24 Interruptions: 25,034/100,000

Still looking for Hrnchamd's confirmation to see if this is a 100% accurate, but he seems to be busy lately so I'm going to commit this change later today.

interruptAtHoursRemaining is checked every hour against the remaining number of hours to rest, but of course Morrowind forgets to check it on the last hour of rest. In the case interruptAtHoursRemaining == 0, the check is forgotten, and that means zero encounter rate for <= 3 hours rest with default settings. I will update the wiki soon.

Ha ha ha ha. That is true for 50% of these game mechanics.dteviot wrote: My hypothesis is it's a bug in the Vanilla code.

...

But someone screwed up when they wrote the code.

Rolling hoursRested against (probability * hoursRested) is not very clever design either.

### Re: Resting outside is nearly always interrupted

Thanks Hrnchamd, code updated.