Civics Allowing Population To Support Units

Cecil Lizard

Chieftain
Joined
Oct 29, 2010
Messages
72
Location
Norwich, Norfolk, UK
In the CivicsInfo XML file, there is something called iFreeMilitaryUnitsPopulationPercent (and a non military specific version). Now I can get that giving a number other the default of 0 will mean running that civic will mean the more population you have, the more units you support for free. But how many per number put there? Say if 3 was entered would that for every 3 population points you could support a unit for free? Or something else?
 
I'll document my code dive a little – since this is also the tutorial subforum, but also because the unit cost mechanics are pretty complicated - and you may want to double check if what I've found makes sense. A search in the DLL source code for an XML tag will at the least find the line that reads the value from XML: CvCivicInfo::read. Usually the C++ variable and getter function have essentially the same name ... "something-FreeMilitaryUnitsPopulationPercent". Searching for that reveals that the percentage eventually gets cached by CvPlayer:: processCivics along with most/all of the other civic effects. Important to note that the cache gets initialized regardless of civics by CvPlayer::init to INITIAL_FREE_MILITARY_UNITS_POPULATION_PERCENT from GlobalDefines.xml, which is 12. The getter function for accessing the cache is again named "getFreeMilitaryUnitsPopulationPercent".

This gets put to use in CvPlayer::calculateUnitCost. The free military units are calculated as a base value plus the player's total population times getFreeMilitaryUnitsPopulationPercent divided by 100. The base value also gets initialized from GlobalDefines – INITIAL_BASE_FREE_MILITARY_UNITS is 2 –, and it can be increased or decreased by civics (<iBaseFreeMilitaryUnits>). Normally, it's 2 free military units plus 12% (rounding down) of the player's total population. A value of 3 for <iFreeMilitaryUnitsPopulationPercent> will instead make it 15%. The AI additionally gets another free military unit for each of its cities as soon as it has met a human player. This is one of a small number of hidden AI advantages. (The BBAI mod disables that, so many of the larger modpacks will have it disabled too.)

Oh, but it seems that this whole free military thing will only matter when a civic sets a <iGoldPerMilitaryUnit> cost, i.e. when in Pacifism. As far as I can tell, CvPlayer::getGoldPerMilitaryUnit will return 0 otherwise. And, even with a high <iFreeMilitaryUnitsPopulationPercent> value, military units will still count fully for the regular unit cost and for away-supply. The gold cost per (any) unit gets initialized from GlobalDefines – INITIAL_GOLD_PER_UNIT is 1 – but there is no corresponding base value for the gold cost per military unit in XML. So, to make <iFreeMilitaryUnitsPopulationPercent> sufficiently relevant, one may need to give several civics a positive <iGoldPerMilitaryUnit>.

<iFreeUnitsPopulationPercent> should work just as the military version, except that all units are counted (regardless of civilian/ military status), and that the gold cost per unit has a base value of 1 (though civics can also affect it through <iGoldPerUnit>), and that the base value for the free units (INITIAL_BASE_FREE_UNITS) is 4 (instead of 2) and modified by civics with nonzero <iBaseFreeUnits>.
 
Wow, thanks a lot! It sounds like for just giving free units I should use the non-militatry one, since the military one only comes into effect with a civic that makes them cost extra. I had just assumed that in the base game, military units cost more support anyway, but I guess I was wrong about that. 😋
 
Top Bottom