Manco Capac
Friday,13 June,I Collapse
- Joined
- Mar 1, 2010
- Messages
- 8,051
Yeah, I think I have serious mental issues...
Have been gone through >30 straight hours on a big report and now I am finished, I'm rushing for more work. Looks like I'm more of a mental person.
Putting that aside, here is my dabble into AI_baseBonusVal(), which is the main and biggest function. That child function is called by AI_BonusVal() just like AI_corporationBonusVal() and AI_BonusVal() is indeed the pillar of the final parent function AI_bonusTradeVal().
Let's start with CvPlayerAI::AI_baseBonusVal()
I reproduce the schematic of the function with spoilers...
It starts off with seeing if there are resources with undefined values
Then it rolls through non obsoleted resources
Happy and Health resources cases are often simple. It follows the simple rule that each point of happiness of health given by the resource gives 100 points. For example, let imagine gems give in some obscure mod +2
, then the resource is worth 200 points...supposing it hasn't any effects on units, buildings, projects or routes. In regular BTS, both ivory and gold are special cases for touching other parts than just happiness.
It can be divided into six subfunctions where there are in fact four categories (units, buildings, projects and routes).
Those four subfunctions consider both the existence and situation. Because it is simply in the game, it increases the bonus value. It's rather ugly, but it's like that. (I guess that's to avoid buying the resource in advance and the AI doesn't reevaluate for a while...) And the situation is evidently the availability, the modifiers it bring, the contextual era, etc.
It attempts to find the first coastal city in the list of coastal cities (by acquirement dates)
A coastal city is defined by MIN_WATER_SIZE_FOR_OCEAN, which is 10 water tiles. Indeed, over 9 tiles define the passage from a fresh water lake to an sea or ocean.
It basically checks if there is at least one coastal city linked to the capital. If found, the function is stopped there (break).
Otherwise, while still finding the first connected to capital coastal city, other coastal cities are categorized as unconnectedcoastal cities.
That function usefulness is rather obscure. It's for the case of no coastal cities connected to the capital were found, but all coastal cities are unconnected.
If such situation happens, it forces the status of coastal city to the unconnected coastal city, which makes me wonder what was the purpose of the first function in the end....
That regards the values of bonuses affecting UNITS
The first part concerns the value of resources regarding units that simply exist (is defined in XML).
1) For units that can be trained with access of TWO or more resources, those units add +50 each for that resource. Let imagine for iron while defiling the XML unit file!
2) For units that can be trained with EITHER one or another resource (or a third in some obscure mod as Firaxis created its code for mod's sake, hence the weird flexible functions), then those units add +40 each for that resource. There are only 4 units that can be built by either one or another resource in BTS: Axeman, Spear, Mace and another one I don't know.
3) Then, it adds to the pool of points the effect of a resource as a modifier on a unit. If I recall, there is none in regular BTS. But it works as *iModifier/10 . Thus, if in some obscure mod, it was 100%, then it's +100/10=10 more points.
4) Then it goes to the function regarding water units (and hence the use of the two first weird functions about coastal cities). Mustn't be a national unit or world unit. It's a modifier that affects water units one by one. For instance, ironclad needs both iron and coal, thus it gets +50 already. No production modifier by resources with that unit. Then that +50 will undergo a the modifier that goes by the weight of coastal cities.
In words, it basically says if the number of coastal cities is less than half of empire city count, then the past value of the water unit will start to shrink. It's really logical!
The modifier is mathematically choosing the smallest number between NumCoastalCities*2 and CityCount then dividing by CityCount. For example if there is 1 coastal city for an empire of 4 cities, then the modifier gets to 1*2/4=0.5, that is 50%. Thus +50 of the iron will get to +25. And if there is no coastal cities, the value of the resource collapse to 0. So getting iron or coal from inland civs is cheaper!
5) The next situational condition regards water units available but no coastal cities OR those water units are obsoleted or simply other type of units that are obsolete. For units that satisfy those conditions, then the value collapse to 2. Yeah, pretty random value, but it's incredibly cheap.
Otherwise, if the units can be trained, the modifier goes by 2. For an ironclad, it would go by now to 25*2, returning to the original 50.
6) Finally, we end with the era condition. Indeed, points to certain resources affected units from older era will decrease as era goes.
It starts by doing the difference.
FYI:
Ancient Age: 0
Classical Age:1
Medieval Age:2
Renaissance:3
Industrial Age:4
Modern Era:5
Future Era:6
If the units is from Ancient Ages and the AI is in the Middles Ages, then the difference in absolute values is 2. And the point pool for that unit just got a negative modifier of Points/DiffOfEra.
If the unit pertains to the present era in which the AI is, then the modifier is 1.5, thus an additionnal 50%. For our case of the ironclad while the AI is industrial Ages: it's 50*1.5=75.
And that ends the section bonuses vs units.
In résumé:
1) Adds 50 points to units unlocked by more than one resource
2) Adds 40 points to units unlocked by either one or other resources
3) Adds the first modifier to the pool of points if the bonus concerned give unit production multiplier
4) Another modifier, but concerning only water units. If the count of coastal cities is less than the empire city count, then the modifier diminishes the base points pool (either the +50 or +40 from point (1) )
5) Units that can be trained gets a modifier of 2 while units that can't be trained are now worth as cheap as 2 points.
6) Era effects on units from older eras.
That regards the values of bonuses affecting BUILDINGS
Again, it goes through the building list from the XML file about buildings.
1) For buildings enabled with more than one resource, adds +30
2) For buildings enabled with either one or another resource, adds +20
3) The points modifier when the resource gives a production multipler. It's *ProdMultiplier/10 again. Now, there are buildings affected by resources like the walls or the castles.
4) If the resource provides power to certain buildings, adds +60.
5) If the resource augments the yield modifier of a building, the it's +Yield/2. Additionally, if the building provides yield modifier from power now, it's +YieldModifierFromPower to the points pool. The IronWorks is the sole case of building having a yield modifier from a resource accessibility (coal and iron).
6) Now joins the situational conditions not to make future buildings affecting the value of a resource before its time. If build-able, then the points pool for the resource case of a case of a building is doubled. Otherwise, the value collapses. So buildings don't increase their cost of a resource just because it exists.
7) Impact of a heavy coastal empire on water buildings enabled by a resource. Let imagine a coastal building already having 80 points. The modifier is the number of coastal cities divided by the cityCount/2 is the modifier. Thus if more than 50% of cities are coastal, the modifier is a gain.
8) The exact same effect from era. Revisit the unit section for the formula. It's the exact same.
That regards the values of bonuses affecting PROJECTS
1) First points pool is the productionModifier brought by a resource on a project. It adds +ProdModifier/10. Think about copper on Internet or Aluminium on Apollo Project or SS parts.
2) If the project isn't yet built or simply enabled, another modifier of *2. Otherwise, if not available or gone, the previous value from ProdModifier collapses to 0.
3) The exact same era dependent effect, but in BTS, it's mostly irrelevant as the projects are in moderns times and the sole next era is future. The diff is 1 and the present points pool for a build and resource divided by one is the same value. Thus, era is irrelevant for base BTS.
That regards the values of bonuses affecting ROUTES (the improvements)
1) If the bonus enables a type of route, then adds +80. There are only the roads and railroads in BTS. Thus it's +80 for the railroads since it needs coal.
2) If the type of route is enabled by either one or another resource, then adds +40. If railroads were either enabled by coal or iron, that would fit the +40. Does it?
3) Let's imagine a mod where there are multiple types of routes enabled by resources (RI has paved roads enabled by stone), for a given resource, older types (it is defined as lower value; railroads are iValue=2 and roads are iValue=1 in the respective XML file) of routes get their value halved while the superior route is remained intact. No era effects here.
At the very last, the final pool of points from units, buildings, projects and routes are added altogether and divided by a factor 10. That is the final value FOR a GIVEN resource.
I'll work about the parents functions later. I'm getting sleepy. Hope it helps.

Have been gone through >30 straight hours on a big report and now I am finished, I'm rushing for more work. Looks like I'm more of a mental person.
Putting that aside, here is my dabble into AI_baseBonusVal(), which is the main and biggest function. That child function is called by AI_BonusVal() just like AI_corporationBonusVal() and AI_BonusVal() is indeed the pillar of the final parent function AI_bonusTradeVal().
Let's start with CvPlayerAI::AI_baseBonusVal()
I reproduce the schematic of the function with spoilers...
It starts off with seeing if there are resources with undefined values
Spoiler :
Then it rolls through non obsoleted resources
Happy and Health resources cases are often simple. It follows the simple rule that each point of happiness of health given by the resource gives 100 points. For example, let imagine gems give in some obscure mod +2

Spoiler :
It can be divided into six subfunctions where there are in fact four categories (units, buildings, projects and routes).
Those four subfunctions consider both the existence and situation. Because it is simply in the game, it increases the bonus value. It's rather ugly, but it's like that. (I guess that's to avoid buying the resource in advance and the AI doesn't reevaluate for a while...) And the situation is evidently the availability, the modifiers it bring, the contextual era, etc.
It attempts to find the first coastal city in the list of coastal cities (by acquirement dates)
Spoiler :
A coastal city is defined by MIN_WATER_SIZE_FOR_OCEAN, which is 10 water tiles. Indeed, over 9 tiles define the passage from a fresh water lake to an sea or ocean.
It basically checks if there is at least one coastal city linked to the capital. If found, the function is stopped there (break).
Otherwise, while still finding the first connected to capital coastal city, other coastal cities are categorized as unconnectedcoastal cities.
That function usefulness is rather obscure. It's for the case of no coastal cities connected to the capital were found, but all coastal cities are unconnected.
Spoiler :
If such situation happens, it forces the status of coastal city to the unconnected coastal city, which makes me wonder what was the purpose of the first function in the end....
That regards the values of bonuses affecting UNITS
Spoiler :
The first part concerns the value of resources regarding units that simply exist (is defined in XML).
Code:
Notice it can be mixing, but that function [B][COLOR="Green"]AI_baseBonusVal()[/COLOR][/B] is entirely rolled for one resource CASE per CASE.
When it relates to units unlocked by multiple resources, one of the resource must be the present case.
1) For units that can be trained with access of TWO or more resources, those units add +50 each for that resource. Let imagine for iron while defiling the XML unit file!

2) For units that can be trained with EITHER one or another resource (or a third in some obscure mod as Firaxis created its code for mod's sake, hence the weird flexible functions), then those units add +40 each for that resource. There are only 4 units that can be built by either one or another resource in BTS: Axeman, Spear, Mace and another one I don't know.
3) Then, it adds to the pool of points the effect of a resource as a modifier on a unit. If I recall, there is none in regular BTS. But it works as *iModifier/10 . Thus, if in some obscure mod, it was 100%, then it's +100/10=10 more points.
4) Then it goes to the function regarding water units (and hence the use of the two first weird functions about coastal cities). Mustn't be a national unit or world unit. It's a modifier that affects water units one by one. For instance, ironclad needs both iron and coal, thus it gets +50 already. No production modifier by resources with that unit. Then that +50 will undergo a the modifier that goes by the weight of coastal cities.
In words, it basically says if the number of coastal cities is less than half of empire city count, then the past value of the water unit will start to shrink. It's really logical!
The modifier is mathematically choosing the smallest number between NumCoastalCities*2 and CityCount then dividing by CityCount. For example if there is 1 coastal city for an empire of 4 cities, then the modifier gets to 1*2/4=0.5, that is 50%. Thus +50 of the iron will get to +25. And if there is no coastal cities, the value of the resource collapse to 0. So getting iron or coal from inland civs is cheaper!
5) The next situational condition regards water units available but no coastal cities OR those water units are obsoleted or simply other type of units that are obsolete. For units that satisfy those conditions, then the value collapse to 2. Yeah, pretty random value, but it's incredibly cheap.
Otherwise, if the units can be trained, the modifier goes by 2. For an ironclad, it would go by now to 25*2, returning to the original 50.
6) Finally, we end with the era condition. Indeed, points to certain resources affected units from older era will decrease as era goes.
It starts by doing the difference.
FYI:
Spoiler :
Ancient Age: 0
Classical Age:1
Medieval Age:2
Renaissance:3
Industrial Age:4
Modern Era:5
Future Era:6
If the units is from Ancient Ages and the AI is in the Middles Ages, then the difference in absolute values is 2. And the point pool for that unit just got a negative modifier of Points/DiffOfEra.
If the unit pertains to the present era in which the AI is, then the modifier is 1.5, thus an additionnal 50%. For our case of the ironclad while the AI is industrial Ages: it's 50*1.5=75.
And that ends the section bonuses vs units.
In résumé:
1) Adds 50 points to units unlocked by more than one resource
2) Adds 40 points to units unlocked by either one or other resources
3) Adds the first modifier to the pool of points if the bonus concerned give unit production multiplier
4) Another modifier, but concerning only water units. If the count of coastal cities is less than the empire city count, then the modifier diminishes the base points pool (either the +50 or +40 from point (1) )
5) Units that can be trained gets a modifier of 2 while units that can't be trained are now worth as cheap as 2 points.
6) Era effects on units from older eras.
That regards the values of bonuses affecting BUILDINGS
Spoiler :
Again, it goes through the building list from the XML file about buildings.
1) For buildings enabled with more than one resource, adds +30
2) For buildings enabled with either one or another resource, adds +20
3) The points modifier when the resource gives a production multipler. It's *ProdMultiplier/10 again. Now, there are buildings affected by resources like the walls or the castles.
4) If the resource provides power to certain buildings, adds +60.
5) If the resource augments the yield modifier of a building, the it's +Yield/2. Additionally, if the building provides yield modifier from power now, it's +YieldModifierFromPower to the points pool. The IronWorks is the sole case of building having a yield modifier from a resource accessibility (coal and iron).
6) Now joins the situational conditions not to make future buildings affecting the value of a resource before its time. If build-able, then the points pool for the resource case of a case of a building is doubled. Otherwise, the value collapses. So buildings don't increase their cost of a resource just because it exists.
7) Impact of a heavy coastal empire on water buildings enabled by a resource. Let imagine a coastal building already having 80 points. The modifier is the number of coastal cities divided by the cityCount/2 is the modifier. Thus if more than 50% of cities are coastal, the modifier is a gain.
8) The exact same effect from era. Revisit the unit section for the formula. It's the exact same.
That regards the values of bonuses affecting PROJECTS
Spoiler :
1) First points pool is the productionModifier brought by a resource on a project. It adds +ProdModifier/10. Think about copper on Internet or Aluminium on Apollo Project or SS parts.
2) If the project isn't yet built or simply enabled, another modifier of *2. Otherwise, if not available or gone, the previous value from ProdModifier collapses to 0.
3) The exact same era dependent effect, but in BTS, it's mostly irrelevant as the projects are in moderns times and the sole next era is future. The diff is 1 and the present points pool for a build and resource divided by one is the same value. Thus, era is irrelevant for base BTS.
That regards the values of bonuses affecting ROUTES (the improvements)
Spoiler :
1) If the bonus enables a type of route, then adds +80. There are only the roads and railroads in BTS. Thus it's +80 for the railroads since it needs coal.
2) If the type of route is enabled by either one or another resource, then adds +40. If railroads were either enabled by coal or iron, that would fit the +40. Does it?
3) Let's imagine a mod where there are multiple types of routes enabled by resources (RI has paved roads enabled by stone), for a given resource, older types (it is defined as lower value; railroads are iValue=2 and roads are iValue=1 in the respective XML file) of routes get their value halved while the superior route is remained intact. No era effects here.
At the very last, the final pool of points from units, buildings, projects and routes are added altogether and divided by a factor 10. That is the final value FOR a GIVEN resource.
I'll work about the parents functions later. I'm getting sleepy. Hope it helps.