Issue #22245: WorkshopParentScript - ProduceFood function operates on bogus chance values
This is called by the daily updates on workshop script with a number of food items passed in (this is the 'totalFoodToProduce' value) which the respective workshop is allowed to produce.
The script then has to check which food types exist at the workshop, how many crops exist for each food type and to calculate individual production chances based on these values.
It's actually a very simple calculation: sum up the resources, then calculate individual production chances by dividing the resource count for each food type by the grand total.
Instead however, the vanilla script gets the production chances per division by totalFoodToProduce (it nowhere calculates a grand total of resources, btw):
<code php> while i < WorkshopFoodTypes.Length
ActorValue foodType = WorkshopFoodTypes[i].resourceValue
foodTypeChance[i] = workshopRef.GetValue(foodType)/totalFoodToProduce
wsTrace(self + " " + foodType + "=" + foodTypeChance[i] + " chance"
i += 1
This results in outright wrong chance values. Moreover, the values may easily get over 1 (i.e. 100%). The rest of the function performs a number of random rolls (one for each food item to prodiuce) and compares the roll values with the borked chance values in the array to decide which food type to produce.
The result of this procedure (because it is using bogus chance values) is that the chance for actual production is proportionally higher for food types that are at lower array positions. Since the food types have been filled into the array alphabetically, this means that you're easily drowning in corn and carrots while you rarely have a surplus on tatos. Even Abernathy farm in vanilla conditions (i.e. no new crops planted) will produce significantly more melons than tatos.