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 )
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.
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.