Anyone know the formula for determining social policy cost?

Hatsuwr

Chieftain
Joined
May 12, 2020
Messages
11
I've found some for the base game which factor in game speed, difficulty, map size, city count, and current policy count.

I can't find the changes VP makes though, and can't figure out how to adapt the old formula to fit.

*edit* Bonus question I ran across "NumCitiesTourismCostMod" in WorldSizes.sql in the mod files. Seems like it would be used to apply a penalty to tourism based on city count and map size, the same as for social policies. Anyone know if this is implemented, and what the math is for it?

*edit* Here's what I have so far. Off by 5 at times due to rounding issues.

upload_2020-5-16_13-23-56.png
 
Last edited:
I've found some for the base game which factor in game speed, difficulty, map size, city count, and current policy count.

I can't find the changes VP makes though, and can't figure out how to adapt the old formula to fit.

Here's a starting point in the code for you to look at.

Code:
void CvPlayer::recomputePolicyCostModifier()
{
   int iCost = m_pPlayerPolicies->GetNumericModifier(POLICYMOD_POLICY_COST_MODIFIER);
   iCost += GetPolicyCostBuildingModifier();
   iCost += GetPolicyCostMinorCivModifier();
   iCost += GetPlayerTraits()->GetPolicyCostModifier();

   if(iCost < /*-75*/ GC.getPOLICY_COST_DISCOUNT_MAX())
       iCost = /*-75*/ GC.getPOLICY_COST_DISCOUNT_MAX();

   m_iPolicyCostModifier = iCost;
}
 
Here's a starting point in the code for you to look at.

Thanks! I don't much much about programming, but this seems like it is adding up discounts (capping at 75% discount) and applying them to the cost determined by the factors I mentioned before.

From my searching, it looks like the formula to the original game before certain expansions/patches was:

SpeedModifier * DifficultyModifier * (BaseCost + (CountCoefficient * CurrentPolicyCount) ^ Exponent) * (1 + SizeModifier * (CityCount - 1)), rounded up to the next 5

At that time:
SpeedModifier was 3 for marathon, 1.5 for epic, 1 for standard, and .67 for quick
DifficultyModifier was .5 for settler, .67 for chieftain, .85 for warlord, and 1 for any higher
SizeModifier was .15 for huge, .2 for large, and .3 for any smaller

Exponent originally seems to have been 1.7, but was patched to 2.01, and seems to be changed to 2.22 by VP
BaseCost originally was 25 I believe, but changed to 50 by VP
CountCoefficient was 3 and changed to 4 by VP

So for a game with standard speed, above warlord difficulty, and smaller than large map, the code would be:

(50+ (4* CurrentPolicyCount) ^ 2.22) * (1 + .3(CityCount - 1)), rounded up to the next 5


This gets me numbers that are generally higher than what I am observing (though with a single city, my observed values are higher or lower depending on the policy count.)
Here's a bad chart. Darker colors are observed values for 1/2/3/4 cities (red/green/blue/yellow). Lighter colors are for the values from the formula.

upload_2020-5-15_8-27-17.png
 
Getting closer! For standard speed, prince difficulty, and standard map size:
(50+ (4* CurrentPolicyCount) ^ 2.22) * (1 + .07(CityCount - 1)), rounded down to the next 5

Changes I've found are rounding down to the next multiple of 5, and finding new map size multipliers. They are, as I understand them now, .1 for small and below, .07 for standard, and .05 for large and huge.

I believe there is only one element missing. It seems that every five policies adopted, there is an additional increase in policy cost. Here's a chart from the above mentioned settings.

upload_2020-5-15_19-10-6.png
 
Ok, pretty much got it! It turns out that for every 5 policies you acquire, you are essentially adding 1/4 of a policy to your policy count.
Something is very sliiightly off still - seems to be with my rounding. There are a few entries that just miss the rounding threshold and are 5 too high.

So the full formula, which could use some verification for differing speeds/difficulties/map sizes:

S*D*(50+(4*P)^2.22)*(1+M*(C-1))

S = Speed Modifier. 3 for marathon, 1.5 for epic, 1 for normal, 0.67 for quick
D = Difficulty Modifier. 0.9 for settler,1 otherwise
M = Map Size Modifier. 0.05 for large and huge, 0.07 for standard, 0.1 for small and below
C = City Count
P = Modified Policy Count = ExistingPolicies + 0.25 * ⌊ExistingPolicies/5⌋

upload_2020-5-16_3-49-41.png
 
Last edited:
Ok, pretty much got it! It turns out that for every 5 policies you acquire, you are essentially adding 1/4 to your city count.
Something is very sliiightly off still - seems to be with my rounding. There are a few entries that just miss the rounding threshold and are 5 too high.

So the full formula, which could use some verification for differing speeds/difficulties/map sizes:

S*D*(50+(4*P)^2.22)*(1+M*(C-1))

S = Speed Modifier. 3 for marathon, 1.5 for epic, 1 for normal, 0.67 for quick
D = Difficulty Modifier. 0.5 for settler, 0.67 for chieftain, 0.85 for warlord,1 for prince and above
M = Map Size Modifier. 0.05 for large and huge, 0.07 for standard, 0.1 for small and below
C = City Count
P = Modified Policy Count = ExistingPolicies + 0.25 * ⌊ExistingPolicies/5⌋

View attachment 555871

Difficulty in CBP = 0.9 on Settler, 1 otherwise
 
Looks like there is a different amount added for ideological policies. Gotta go hunt that down...

*edit* Looks like ideological tenets count as a normal increase in policy count, but they also add an additional multiplier to the total cost. Level 1 tenets add .02 to this multiplier, level 2 add .04, and level 3 add .06.

Will update the formula in the OP!
 
Last edited:
The calculation is done in stages using integers and therefore gets truncated multiple times. I had a formula for vanilla that needed at least 4 FLOOR operations to be fully accurate.

I don't think this +25% of policies is correct and your observation data looks odd - I don't think there should be those jumps. How are you counting openers, finishers, and free policies?
I believe openers count but the other two don't, but I could be wrong.
 
The calculation is done in stages using integers and therefore gets truncated multiple times. I had a formula for vanilla that needed at least 4 FLOOR operations to be fully accurate.

I don't think this +25% of policies is correct and your observation data looks odd - I don't think there should be those jumps. How are you counting openers, finishers, and free policies?
I believe openers count but the other two don't, but I could be wrong.

Yea, I figured it was going to want a few more floors haha. I wish I could find the formula in the game files and stop just reconstructing it.

I could have worded the part I think you are referring to with the "+25%" a bit better. What happens is that every five policies you unlock, .25 is added to your policy count, not 25%. So when you unlock your 5th policy, your policy count is effectively 5.25. When you unlock your 10th policy, it is 10.5. What looks odd about the observed values?

Adopting a branch, each of the 5 branch policies, and ideological tenets are all treated the same, except that tenets also increase your tenet count.

Free policies do not increase your policy count, will increase the tenet count.

Since I can't make better formatted equations here, here's a screenshot.

upload_2020-5-16_13-23-16.png
 
Last edited:
The jump for the fifth policy looked too big to me, but I'm probably wrong.

Look for routine GetNextPolicyCost here:

https://github.com/LoneGazebo/Commu.../CvGameCoreDLL_Expansion2/CvPolicyClasses.cpp

Thank you, that link saved me a lot of time that would have been spent failing to fix the rounding errors haha. This formula should be completely correct. Sooooo many INTs.

*edit* I was able to simplify it quite a bit! Here is the latest. Any ideas for how to simplify it further while keeping accuracy?

upload_2020-5-17_21-13-3.png



P = Policy Count
C = City Count
M = Map Size Modifier. 0.05 for large and huge, 0.07 for standard, 0.1 for small and below.
E = Eiffel Tower Modifier. 1 if Eiffel Tower is not owned, 0.9 if it is.
S = Speed Modifier. 3 for marathon, 1.5 for epic, 1 for normal, 0.67 for quick.
D = Difficulty Modifier. 0.9 for settler, 1 otherwise.
T = Tenet Count. Level 1 tenets add 1 to the count, level 2 add 2, and level 3 add 3.
 
Last edited:
No need to INT after +50. Otherwise no.
 
That INT is actually for the exponentiation - I just threw the +50 in there with it to save a set of parentheses.
One thing I might do is redefine C as "number of cities in addition to the capital" and remove the -1 from the formula.
Also, INT(.2x)*5 is just rounding down to the next multiple of 5, and I think it might be best to just state that in words rather than have it be part of the formula.
Also means the outermost remaining INT can be removed, since INT(X) rounded down to the next 5 is the same as X rounded down to the next 5.

upload_2020-5-18_11-33-32.png
 
Last edited:
Top Bottom