the Sim Settlements forums!

Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Probable error in resource redistribution function and an alterative method

cbrgamer2

Well-Known Member
Messages
723
When a player changes from simple or moderate resource complexity to a higher complexity, a function called RedistributeSettlementVirtualResources is called. In some testing I did, I noticed it didn't seem to be working, so I had a poke around. I found an error in the code, but I also have an idea for a better method of redistributing resources (more on that below). First, the error. This is using code from the 1.0.16a Hotfix (the real stuff this time - not decompiled :grin)
1625676494052.png
In this section of code, we can see that fSetValueTo is set to 0 at the start and is only given another value for the cheapest resource in each category. This is correct. However, bIsScrapType is set to false at the start and is also only set to true if the resource is the cheapest in its category. The problem is, the SetSettlementVirtualResource will only run if bIsScrapType is true, which only happens for the cheapest resource. So the cheapest resource is correctly updated, but the others are not set to 0 as intended.
There also seems to be some redundant looping in the function. The virtual resources are looped through to find the cheapest in each category for every single settlement, but as far as I can tell it will always get the same result for every settlement, so it could be done before the settlement loop.

Now, the method used to redistribute is simply to put the entire amount available into the cheapest resource in each category. So if I have 10000 building materials in a settlement with moderate complexity, when I change to complex categories I will have 10000 wood and zero of every other resource. Across my entire network, there would only be wood and no other building material available! I would like to suggest an alternate method that will redistribute the materials a little better than that.

Redistribute the materials based on how much of each material that settlement is producing. So I have that same settlement with 10000 building materials and my plots produce 120 wood, 60 steel and 20 concrete each day (a total of 200 building materials). When that 10000 gets distributed, I get 120/200*10000=6000 wood, 60/200*10000=3000 steel and 20/200*10000=1000 concrete. If a settlement doesn't produce anything in a category it has a stockpile of (maybe because the player donated them), it can spread the materials evenly. Any decimals can be rounded down (so there is scrap lost in the conversion, which seems fine to me. You can't expect these uneducated settlers to be too good at sorting through a pile scrap ...).
Not only is this entirely doable, I've already done it to test the concept (I've tested it and it works for me). Here is a link to the rewritten function. It undoubtedly needs to be cleaned up, but I think the concept is sound and would be much better for a player who wants to start dealing with more complexity with their resources mid game (with the current method, I think if a player did that, their entire network would soon crash).
Alternate redistribute function

EDIT : BTW, I also noticed that in the MCM there are two listings for "Scrap" in the options? Is this intentional so that the correct values are passed for the moderate and complex options? If so, wouldn't it just be better to have one "Scrap" listed and add one to the value passed into the ChangeComplexitySettingFromMCM function? I was certainly confused over why there was two of them and if there was a difference between them.
 
The dual entries for "Scrap" is a hack to deal with a bug in MCM. Clicking either entry does the same thing.
 
I fixed the bug for next patch, will need to do some testing with the new function proposition and won't have time before tomorrow's patch.
 
While testing I did find that Auto Assignments can cause some plots to temp drop and reassign. This causes a temp issues in the total storage totals. If a daily update happens during this debacle resources will get added to the Building Materials category and can allow it to exceed the actual total storage value. Actually @kinggath pointed me to check that as an issue and sure enough auto assign off fixed the plot dropping and reassignment issue.
 
Top