Jump to content

Fixing that pesky Settlement Resource Bug


Recommended Posts

Posted

I have no idea if this is the right section for this topic or not. Please yell at me and move it if it isn't ;) Thanks.

Okay, many of us probably know about the age old “settlement resource bug” where the workshop page in the pip-boy reports wrong (usually but not always zero) values for food, water, defense, beds and power while you are not inside the settlement.

These errors are not purely cosmetic, as a settlement will very quickly lose happiness if there are not enough beds reported, even though you have built more than enough. The random settlement attacks will also start to annoy you for a settlement that produces 60 food, has 25 settlers, 40 water and zero defense (even though it should have 150 defense but only the defense rating bugged.)
The background scripts that handle those events (random attacks and happiness over time) all seem to be affected by these wrong numbers reported in the pip-boy.

So where does that bug come from? The internet is full of theories and they're all bullshit. “It is the TV's in your settlements!” Get outta here!

The culprit is the native object reference script function RecalculateResources(). If this function gets called on a workshop while not all cells (or none) of that workshops settlement are fully loaded if will fuck up and return lots of workshop actor values as damaged or plain zero.

The people who wrote the settlement system scripts knew this and never call that function directly. Instead, they call it only through a wrapper function (located at the very bottom of WorkshopScript.psc) called RecalculateWorkshopResources() which is supposed to do a sanity check before actually starting the recalculation process. However, they fucked it up. The employed sanity check doesn't work:
 

; helper function to recalc
; we don't normally want to do this when unloaded or everything will be 0
; TRUE = we did recalc; FALSE = we didn't
bool function RecalculateWorkshopResources(bool bOnlyIfLocationLoaded = true)
    if bOnlyIfLocationLoaded == false || myLocation.IsLoaded()
        ;WorkshopParent.wstrace(self + " RecalculateWorkshopResources=TRUE")
        RecalculateResources()
        return true
    else
        ;WorkshopParent.wstrace(self + " RecalculateWorkshopResources=FALSE")
        return false
    endif
endFunction

Notice the “myLocation.IsLoaded()” part. The intention here is obvious: Prevent calling RecalculateResources() unless the settlement is actually loaded. So far, so good.

However! Citation from the Creation Kit Wiki on the IsLoaded function: “Return Value: Whether this location is loaded or not. A location is loaded if any of its cells are loaded.” Emphasis added by me. And here is the problem. This sanity check doesn't work at all on settlements that span multiple cells because as long as just any one of them is loaded, the whole thing is considered loaded.
Also, from personal experience, I know that IsLoaded() is utterly unreliable and will return TRUE for locations that are no longer loaded but which I have previously visited during the same session.

To fix this problem, the sanity check inside that helper function needs to be changed into something that actually works and reliably prevents running RecalculateResources() on workshops in settlements that aren't fully loaded.

This is where I need your input and help because I have no idea what could actually work. My first idea is to simply check the distance between the workshop object and the player and only allow the recalculation if it less than say, 1000 units.

Then there is (I think) the problem that the RecalculateResources() function doesn't resolve instantly and allows the player to move around while it is running, allowing her to walk away from a settlement, causing the engine to unload needed cells and then fuck up the resource count, which is why the settlement resource bug can also (rarely) affect small, single cell settlements, if you fast-travel away in just the wrong moment.

Any ideas or comments?

 

Posted

Maybe tie the update check so RecalculateResources is only called on the settlement when you exit build mode? It's reasonable to think that exiting build mode means you've made some changes that are worth being recalculated.. And it would also mean the player is nearby since you have to be in the settlement to enter build mode.

 

But I agree with you, this bug is terrible and I don't know why Beth never fixed it. It drives me crazy..

Posted

Can't say much about the coding parts, but i have this bug almost every day on Spectacle Island.

My base of operations is The Castle, so it could be right that it just loads the cells closest to The Castle and ignores the other cells there. The houses i built there are so far apart that the counter only shows the correct values when i enter workshop mode, and walk around the island one time.

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...