Let's say we add a modifier,
iSDTotalCitiesPercentEven that defines the number of cities percent out of your cities that needs to be manufacturing the given resource for its supply/demand ratio to be even.
Code:
<xs:element type="xs:byte" name="iSDTotalCitiesPercentEven" minOccurs="0"/>
If I want to have for e.g. Ammunition supply and demand even out and I have 70 cities, I will need to build 35 filling factories to achieve this.
Code:
<BonusInfo>
<Type>BONUS_AMMO</Type>
<Description>TXT_KEY_BONUS_AMMO</Description>
<Civilopedia>TXT_KEY_BONUS_AMMO_PEDIA</Civilopedia>
<BonusClassType>BONUSCLASS_MANUFACTURED</BonusClassType>
<ArtDefineTag>ART_DEF_BONUS_AMMO</ArtDefineTag>
<TechReveal>TECH_EXPLOSIVES</TechReveal>
<TechCityTrade>TECH_EXPLOSIVES</TechCityTrade>
<TechObsolete>NONE</TechObsolete>
<iAITradeModifier>10</iAITradeModifier>
<iAIObjective>0</iAIObjective>
<iHealth>0</iHealth>
<iHappiness>0</iHappiness>
<iPlacementOrder>-1</iPlacementOrder>
<iConstAppearance>0</iConstAppearance>
<iSDTotalCitiesPercentEven>50</iSDTotalCitiesPercentEven>
</BonusInfo>
When I just researched Explosives and built my first filling factory, I will have 1 Ammunition, satisfying ceil(100 * (1 / (TotalCities * iSDTotalCitiesPercentEven)) supply, in the example ceil(100 * 0,0285...) = 3 percent. Let's call it
iSupplyPercent and (100 - iSupplyPercent) as
iDemandPercent
Let's define a resource supply/demand percent modifier,
iSDPercentModifier, to easily allow later tweaking. I assume this can be stored directly per unitclass right after the BonusType, in Civ4UnitInfos.xml ?
Code:
<xs:element type="xs:byte" name="iSDPercentModifier"/>
To accurately represent scarcity of given resource in all the other cities, I want to increase unit costs that need Ammunition by a factor of ceil(iDemandPercent * iSDPercentModifier / 100) , in our case let's assume a 1000 hammer cost for a unit that needs Ammunition. At supply percent equal to 3 the demand will be 97. Assume the percent modifier is 100, you will need 97 percent more hammers, total cost for this unit being built will be 1970. In every city.
By building a second filling factory, ceil(100*2/(70*50)) gives 6 supply and 93 demand. Cost for that unit decreases from 1970 to 1930 hammers.
But what happens when there's more supply than demand? with 5 filling factories in 7 cities you get ceil(100*5/(7*50)) = 143 supply and -43 demand. Take -43 * 100 / 100 = 43 percent less from 1000, which is just 570 hammers! If I want to produce lots of that unit, it's certainly worthwhile building all those.