Resting outside is nearly always interrupted

Everything about development and the OpenMW source code.
User avatar
scrawl
Posts: 2152
Joined: 18 Feb 2012, 11:51

Re: Resting outside is nearly always interrupted

Post by scrawl » 15 Aug 2015, 16:16

Actually I was wrong... But i don't get why I was right last night...
Make sure to disable the Tribunal assassins before testing. These are scripted and can always interrupt you regardless of the discussed formula.

Code: Select all

stopscript tribunalmain
stopscript dbattackscript

User avatar
Jyby
Posts: 408
Joined: 10 Dec 2013, 04:16

Re: Resting outside is nearly always interrupted

Post by Jyby » 16 Aug 2015, 03:50

Scrawl, I realized this a few nights ago. I was testing this by disabling the entire expansions. I figure disabling the scripts is a safer option.

Do we support the game without the expansions? Or are those required?
Macbook Air 2013 - 1.7GHz Intel i7 - 8 GB - 512 GB SSD - Intel HD 5000
Windows 10 PC - 4GHz Intel i7 - 16 GB - 512 GB SSD - EVGA GTX 1060 SSC

User avatar
psi29a
Posts: 4881
Joined: 29 Sep 2011, 10:13
Location: Belgium
Gitlab profile: https://gitlab.com/psi29a/
Contact:

Re: Resting outside is nearly always interrupted

Post by psi29a » 16 Aug 2015, 07:10

The expansions are not required. You can load Morrowind with and without the two others. During installation the wizard will ask you if you want to install them or not.

ahehalftalftow
Posts: 9
Joined: 27 Jul 2015, 19:48

Re: Resting outside is nearly always interrupted

Post by ahehalftalftow » 18 Aug 2015, 02:43

I am not going to argue with scrawl, he is seemingly right with the (x < int(fSleepRandMod*housToWait)), but i do not understand why bethesda would make it so resting 4 hours gives you a higher chance to get an interruption than resting 23 hours..
//(x < int(fSleepRandMod*hoursToWait))
hours: 1 Interruptions: 0/100,000
hours: 2 Interruptions: 0/100,000
hours: 3 Interruptions: 0/100,000
hours: 4 Interruptions: 24910/100,000
hours: 5 Interruptions: 20089/100,000
hours: 6 Interruptions: 16773/100,000
hours: 7 Interruptions: 14274/100,000
hours: 8 Interruptions: 25032/100,000
hours: 9 Interruptions: 22480/100,000
hours: 10 Interruptions: 19861/100,000
hours: 11 Interruptions: 18092/100,000
hours: 12 Interruptions: 24922/100,000
hours: 13 Interruptions: 23044/100,000
hours: 14 Interruptions: 21390/100,000
hours: 15 Interruptions: 19921/100,000
hours: 16 Interruptions: 24972/100,000
hours: 17 Interruptions: 23428/100,000
hours: 18 Interruptions: 22177/100,000
hours: 19 Interruptions: 21085/100,000
hours: 20 Interruptions: 25268/100,000
hours: 21 Interruptions: 23906/100,000
hours: 22 Interruptions: 22699/100,000
hours: 23 Interruptions: 21754/100,000
hours: 24 Interruptions: 25034/100,000
In terms of mirroring Vanilla Morrowind, The formula is excellent, but I don't understand why the odds should behave like this in the first place.

as a side note, since the odds are pretty much set at 25% regardless of how long you sleep, there is no real reason to take the hoursToWait into consideration in the formula, sans the first 3 hours.

Code: Select all

x=rand()/(RAND_MAX+1)
if (hoursToWait > 3 && x < fSleepRandMod){
//prep for interrupt
}

//
hours: 1 Interruptions: 0/100,000
hours: 2 Interruptions: 0/100,000
hours: 3 Interruptions: 0/100,000
hours: 4 Interruptions: 25046/100,000
hours: 5 Interruptions: 24930/100,000
hours: 6 Interruptions: 25170/100,000
hours: 7 Interruptions: 25063/100,000
hours: 8 Interruptions: 24888/100,000
hours: 9 Interruptions: 24969/100,000
hours: 10 Interruptions: 24998/100,000
hours: 11 Interruptions: 25069/100,000
hours: 12 Interruptions: 24852/100,000
hours: 13 Interruptions: 25145/100,000
hours: 14 Interruptions: 24871/100,000
hours: 15 Interruptions: 24817/100,000
hours: 16 Interruptions: 24702/100,000
hours: 17 Interruptions: 25123/100,000
hours: 18 Interruptions: 24850/100,000
hours: 19 Interruptions: 25241/100,000
hours: 20 Interruptions: 25164/100,000
hours: 21 Interruptions: 24955/100,000
hours: 22 Interruptions: 24912/100,000
hours: 23 Interruptions: 25143/100,000
hours: 24 Interruptions: 25138/100,000
This is a little less wonky than the new current formula, and probably more simplistic in terms of calculations.

although, you already have the rollDice() function set, so In terms of simplicity you might as well keep it as it is. it's just two relatively unnecessary multiplication.

also, scrawls formula has the benefit of preserving fSleepRandMod=1.0 causing 100% interrupts when sleeping outside, I think there's a mod that does that, IIRC. So it's likely best to stick with that.

User avatar
Jyby
Posts: 408
Joined: 10 Dec 2013, 04:16

Re: Resting outside is nearly always interrupted

Post by Jyby » 18 Aug 2015, 20:45

psi29a wrote:The expansions are not required. You can load Morrowind with and without the two others. During installation the wizard will ask you if you want to install them or not.
Sorry, I meant for development. it's probably a good idea to have the expansions installed and disable scripts to test than not include a big part of the game.
Macbook Air 2013 - 1.7GHz Intel i7 - 8 GB - 512 GB SSD - Intel HD 5000
Windows 10 PC - 4GHz Intel i7 - 16 GB - 512 GB SSD - EVGA GTX 1060 SSC

User avatar
psi29a
Posts: 4881
Joined: 29 Sep 2011, 10:13
Location: Belgium
Gitlab profile: https://gitlab.com/psi29a/
Contact:

Re: Resting outside is nearly always interrupted

Post by psi29a » 18 Aug 2015, 21:56

I don't understand your question then, as you don't need Morrowind to develop OpenMW. :)

User avatar
Jyby
Posts: 408
Joined: 10 Dec 2013, 04:16

Re: Resting outside is nearly always interrupted

Post by Jyby » 19 Aug 2015, 01:17

psi29a wrote:I don't understand your question then, as you don't need Morrowind to develop OpenMW. :)
Haha oh come on :P
Macbook Air 2013 - 1.7GHz Intel i7 - 8 GB - 512 GB SSD - Intel HD 5000
Windows 10 PC - 4GHz Intel i7 - 16 GB - 512 GB SSD - EVGA GTX 1060 SSC

dteviot
Posts: 144
Joined: 17 Dec 2014, 20:29

Re: Resting outside is nearly always interrupted

Post by dteviot » 19 Aug 2015, 04:22

ahehalftalftow wrote:I am not going to argue with scrawl, he is seemingly right with the (x < int(fSleepRandMod*hoursToWait)), but i do not understand why bethesda would make it so resting 4 hours gives you a higher chance to get an interruption than resting 23 hours..
My hypothesis is it's a bug in the Vanilla code.
It was meant to be
(x < (fSleepRandMod*hoursToWait))

But someone screwed up when they wrote the code.
Specifically, I suspect they tried to use integer maths (to make it run faster than floating point), and forgot the effect of truncating a float to an integer. So, they wound up with:

(x < int(fSleepRandMod*hoursToWait))

Which means that as long as fSleepRandMod*hoursToWait is less than 1 (i.e. hours to wait < (1 / fSleepRandMod)) you won't be interupted.

ahehalftalftow
Posts: 9
Joined: 27 Jul 2015, 19:48

Re: Resting outside is nearly always interrupted

Post by ahehalftalftow » 19 Aug 2015, 09:34

dteviot wrote:My hypothesis is it's a bug in the Vanilla code.
You're probably right, It just doesn't make sense to me haha. one of the nice things about the code for the wait dialog is that the game is paused when you're in it, making that code 10ms faster shouldn't have much of an impact. it's also just a couple lines of code, which isn't repeated too fast or frequently.

The beauty of this being an Open engine, is that I can just modify the source as i see fit, so I have no right to complain. I modded the formula to be a natural logarithm (because that made the most sense to me, in terms of gameplay). my formula doesn't preserve 100% of fSleepRandMod's functionality, but since i am the only one playing my modification, this doesn't bother me.

//1 hour will always be a 0% chance.
//if i change fSleepRandMod to 0, it'll still be a 0% chance, but if fSleepRandMod is 1, it'll only be 100% chance on 24 hours. with my formula, fSleepRandMod sets the probability of a 24 hour rest resulting in a battle, instead of all hoursToWait's probabilities being set by fSleepRandMod.
Spoiler: Show
//wouldn't it be more efficient to use this:
//if (rolldice(hoursToWait) < int(...) ){
//as this would not require a variable to be declared? is `int x` ever used after the if statement? albeit, simplicity also applies to the code's legibility, I suppose. and as i stated earlier, this is a single line of code that isn't called too terribly often.

I am not suggesting this for openMW's dev team, though. it's just my personal modification for my own purposes. I have nothing but respect for #openmw, and you guys are better at developing than I am.
I did catch one small problem with scrawls formula though, a specific case, where fSleepRandMod is small, but not zero.
Also, I think This opens another option to help prove that scrawl has the right formula that bethesda used in vanilla.
take for instance:
fSleepRandMod == 0.01;
Spoiler: Show
Spoiler: Show
I made an ESP that set fSleepRandMod to 0.0400, and got interrupted after about 15-20 24 hour rests. that formula is still a little off.

ahehalftalftow
Posts: 9
Joined: 27 Jul 2015, 19:48

Re: Resting outside is nearly always interrupted

Post by ahehalftalftow » 19 Aug 2015, 12:47

after some testing with vanilla, I did catch a couple things.
as I stated in my previous (needlessly long) post, the case of fSleepRandMod >0 < 0.05 is special.
In Scrawl's Formula, it would result in a 0% encounter rate. in Vanilla morrowind, fSleepRandMod==0.04 results in interruptions.

also, the case fSleepRandMod==1 is special.
In Scrawl's formula, fSleepRandMod==1 would result in a battle 100% of the time, regardless of time slept.
In Vanilla MW, fSleepRandMod==1 does not result in battles for the cases hoursToWait==1 through 3

as such, I propose:
x=rand()/double(RAND_MAX+1)
if(x < fSleepRandMod && hoursToWait > 3)
//do interruption
}

This fixes the following issues:
fSleepRandMod being small (0 < fSleepRandMod < 0.05).
fSleepRandMod being abnormally large (1.0).
the wonky odds of getting into battles(it makes the odds consistent, without needing to use hoursToWait in the odds
fSleepRandMod being REALLY small (fSleepRandMod < 0.01)

dteviot wrote:( hours to wait < (1 / fSleepRandMod)) you won't be interupted.
this is certainly true in OpenMW, but I question whether it is true in VanillaMW, based on my tests :)
thanks, you helped me catch these two issues

Post Reply