Hmm, so he want threshold reductions to act differently from threshold increases, I initially though Raledon's suggestion was only about reducing rounding errors. With that in mind I would have written it like this:
Code:
int CvCity::growthThreshold() const
{
int iThreshold = GET_PLAYER(getOwnerINLINE()).getGrowthThreshold(getPopulation());
int iDenominator = 1;
int iNumerator = 1;
int iThresholdModifier = GET_PLAYER(getOwnerINLINE()).getPopulationgrowthratepercentage();
if ( iThresholdModifier < 0 )
{
iDenominator *= iThresholdModifier * -1 + 100;
iNumerator *= 100
}
else if ( iThresholdModifier > 0 )
{
iNumerator *= iThresholdModifier + 100;
iDenominator *= 100;
}
iThresholdModifier = getPopulationgrowthratepercentage();
if ( iThresholdModifier < 0 )
{
iDenominator *= iThresholdModifier * -1 + 100;
iNumerator *= 100
}
else if ( iThresholdModifier > 0 )
{
iNumerator *= iThresholdModifier + 100;
iDenominator *= 100;
}
if (getNumCityPlots() == NUM_CITY_PLOTS)
{
iThresholdModifier = GC.getDefineINT("CITY_THIRD_RING_EXTRA_GROWTH_THRESHOLD_PERCENT");
if ( iThresholdModifier < 0 )
{
iDenominator *= iThresholdModifier * -1 + 100;
iNumerator *= 100
}
else if ( iThresholdModifier > 0 )
{
iNumerator *= iThresholdModifier + 100;
iDenominator *= 100;
}
}
if ( isHominid() )
{
iDenominator *= 2; // Those barbarians are just so damned fecund!
}
iThreshold *= iNumerator / iDenominator
return std::max(1,iThreshold);
}
I know it looks a bit scarier, but it isn't all that difficult to grasp what is done mathematically.
I check if the modifiers are below 0 right away while Raledon multiply all the modifiers together and then check if the result is below 0.
I found the possible flip flopping between negative and positive value for the iThresholdModifier as somewhat confusing. ^^
This line is the only place where a rounding error would occur: iThreshold *= iNumerator / iDenominator
In Raledon's initial example there was two rounding error spots:
iThresholdModifier /= iDivide;
iThreshold /= iThresholdModifier;