I was poking around in the c++ source file to figure out how food waste was calculated, and in there I noticed a bug in the code, which could explain some weird behavior I had notice in an earlier playthrough.
It is specifically the following line (CvCity.cpp@9037 in version 10573):
The problem is that calculatedWaste might not have been calculated to its end (MAX_SURPLASS-1), which means it will use whatever value was stored in there. This could in principle be any float value, but in practice it will tend to be 0.
This coincide with a phenomenon I experiance where some cities with very high surplus suddenly had much smaller amounts of wasted food, causing them to grow extremely fast.
A solution to this would to replace the array reference with a call to calculate the value if not already calculated (a recursive call to foodWastage).
I also noticed the formula for food wastage per extra surplus assymtotically approaches 1 - wastageGrowthFactor / (1+wastageGrowthFactor) from bellow (and we are VERY close to it by MAX_SURPLASS), but that abovethe maximum we have all food be wasted. It would make more sense to use the assymtotic limit as the efficiency above the amount we will bother to calculate, since the behavior would be extremely close to what we would have gotten if we let MAX_SURPLASS go toward infinity. This also mean we could lower MAX_SURPLASS to around 150-200, since we have less than 1% to a few ppm error in food ratio left after wastage (which is a more meaningfull error than amount of waste, since the limit of food ratio left after wastage is roughly 4.8%.
I therefor recommend we change the line to:
It is specifically the following line (CvCity.cpp@9037 in version 10573):
Code:
return calculatedWaste[MAX_SURPLASS-1] + (surplass - MAX_SURPLASS + 1);
This coincide with a phenomenon I experiance where some cities with very high surplus suddenly had much smaller amounts of wasted food, causing them to grow extremely fast.
A solution to this would to replace the array reference with a call to calculate the value if not already calculated (a recursive call to foodWastage).
I also noticed the formula for food wastage per extra surplus assymtotically approaches 1 - wastageGrowthFactor / (1+wastageGrowthFactor) from bellow (and we are VERY close to it by MAX_SURPLASS), but that abovethe maximum we have all food be wasted. It would make more sense to use the assymtotic limit as the efficiency above the amount we will bother to calculate, since the behavior would be extremely close to what we would have gotten if we let MAX_SURPLASS go toward infinity. This also mean we could lower MAX_SURPLASS to around 150-200, since we have less than 1% to a few ppm error in food ratio left after wastage (which is a more meaningfull error than amount of waste, since the limit of food ratio left after wastage is roughly 4.8%.
I therefor recommend we change the line to:
Code:
return foodWastage(MAX_SURPLASS - 1) + ((float)1.0 - wastageGrowthFactor/((float)1.0+wastageGrowthFactor)) * (surplass - MAX_SURPLASS + 1);