Quick Modding Questions Thread

"iAIWeight - The preference given by the AI to this unit, generally for Unique Units."
Al don't want build some units or build that unit much less, if i increase this value <iAIWeight>0</iAIWeight> in CIV4UnitInfos.xml, Al will build more this units. Which is the best value? To be balanced with other units, to build even as other units.
 
AI Weight - I tried using the iCombat value as the weight for this.
 
"iAIWeight - The preference given by the AI to this unit, generally for Unique Units."
Al don't want build some units or build that unit much less, if i increase this value <iAIWeight>0</iAIWeight> in CIV4UnitInfos.xml, Al will build more this units. Which is the best value? To be balanced with other units, to build even as other units.

There is no way of knowing exactly what you should use without looking at the specific unit's characteristics and running them through the algorithm to build a specific unit AI type, and then doing the same for some other units and comparing the values. Different unit AI types produce values in different ranges and consider different factors.

(To just see a general recommendation for a starting point, the next to last paragraph gives one.)

Example: for the basic Attack unit AI type...
let CV be the land unit's "combat value" - this is based on the unit's strength and the number of first strikes and first strike chances it gets all ultimately divided by the
strength of the strongest land unit that any player has ever built in this game. It is, for a land unit,
CV = 100 * S * (((F * 2) + C) * 5 + 100) / 100 / H
where S is this unit type's combat strength, F is number of first strikes inherent to the unit type (not from promotions), C is number of inherent first strike chances, and H is strength of highest strength land unit ever built by anybody so far in the game. (So it increases the value by 10% per first strike and 5% per first strike chance.) Therefore if this is a unit that has a strength equal to the highest strength unit anyone has ever built so far and no built-in first strikes or chances, then it will get a value of 100. Weaker units will be proportional to that (50 for one half that strong, excluding possible first strike related increases). If the unit being evaluated is stronger than any land unit anyone has ever built so far then it will have a CV over 100. A unit with built-in first strikes and/or chances can also end up over 100 (especially if it has a strength that is equal to, or greater than, any that has been built so far).

the basic UNITAI_ATTACK evaluation gives a value via:
let F be 1 if the AI is not using the "fast movers" strategy type, 2 if it is
let M be number of moves the unit gets
let W be the unit's withdrawal chance
let L be the unit's combat limit

start with Value = 1 + iAIWeight

then via integer math (so all fractions are dropped from each step before applying them), to Value:

add CV
add CV * M * F / 2
add CV * W / 100

then if the unit has a combat limit under 100 (so it can't kill its target, like a catapult),
subtract CV * (125 - L) / 100

For the attack and city attack unit AI types, if the AI is evaluating the unit for an overseas attack and the unit starts with a free promotion that has the amphibious property then its Value is increased by 33% (dropping fractions).

Now you finally have the Value assigned to the unit for the attack type unit AI.

Note that this is the basic preliminary value. The evaluation actually runs through everything it can build twice. The first time to get the highest value, then it reevaluates every unit that is at least 67% of this value and considers additional factors that are the same regardless of the unit AI type being evaluated. All of these additional adjustments but one are multipliers to the base value. These factors include how much XP the unit starts with (+10% per free XP, rounded down), a bonus if the unit type gets one or more free promotions from buildings, another if it gets one or more from its inherent properties, and likewise from civics (working out to +15% per category in which it gets one or more free promotions). Each also gets multiplied by a random factor from 1 to 1.49 (in steps of .01), and also gets a bonus if it can currently be rushed without happy cost or if it can't be rushed with the bonus equal to the production cost already invested in that unit type, a penalty related to how many of that unit type it is already building in its cities, and a penalty if it dies when it attacks (suicide flag set), and finally another factor which depends on whether or not rushing causes unhappiness (or if it can't rush) to determine which of two adjustments to make. As you can see, it is somewhat complex and includes a significant random factor...

When being evaluated for a different unit AI type, the same unit will end up with a different value assigned to it except via coincidence.

So...

If you want a general place to start when picking a value for an iAIWeight, I'd suggest that values under 20 will probably have only a very small effect, if any. Values of iAIWeight around 50 would should have a noticeable effect but not hugely shift the preference, and values up around 100 should have a stronger effect but still allow other units to be built for that unit AI type, at least sometimes, unless perhaps all the unit types in question (those that can be built for the specific unit AI type being evaluated) are a lot weaker than the strongest unit type built so far. Values up over 200 should have a large effect and possibly (for some unit AI types) overwhelm the chances of building anything else for that unit AI type unless some other unit gets more moves or some other bonus (like built-in first strikes) or the unit with iAIWeight bonus gets some penalty the others don't (like not being able to kill its target in the case of the attack unit AI type). But, again, each unit AI type uses a different calculation, some with several more factors than the attack AI uses, and therefore the same iAIWeight may give a large shift when the unit is being considered for one unit AI type and a not so large shift when being considered for some other unit AI type. If you assign a unit an iAIWeight that makes it picked a more often for the city attack unit AI, it might also have the side effect of making it always be picked for the attack unit AI type too.

Perhaps giving an iAIWeight of 50 or so and seeing what effect it has would be a good place to start.

If you want to examine the source code where all this is done, the picking of a unit type for a specific unit AI type is done in CvCityAI::AI_bestUnitAI. The basic value generation of a unit type for a unit AI is done in CvPlayerAI::AI_unitValue.
 
I've added a new city specialist type, which is working fine, but I have a problem in the city screen. the top specialist type in the screen (spy) appears but is not clickable. I experimented a bit and discovered it is a function of where the icon is, not the icon itself (ie I made all the icons smaller so they fit in the original space assigned for them and they work that way).

so does anyone know where this space is defined? I've looked all over CvMainInterface.py but no luck so far.
 
The specialist stacker by johny smith should fix the problem.
The underlying problem is that on top of the specialists, there's the panel for the resources, and if you add more specialists, the top ones will be slid under this panel, making them unclickable.
 
thanks for the quick response. I just made the resources panel smaller and it all works great now.
 
Thank you God-Emperor :)

But i have new problem, i put corporations in mod (BTS Corporations with little changes) all works except UNITCLASS_EXECUTIVE_1,2,3...7. When i put Executives units in CIV4UnitInfos.xml and CIV4UnitClassInfos.xml i get Error with Don't Send. What to do?
 
I'm trying to remove all but 1 difficulty level, but I get an xml error saying tag HANDICAP_SETTLER in CIV4ForceControlInfos isn't working but there is no such tag in the CIV4ForceControlInfos file in BtS. (my mod doesn't have a modded version of that file)
 
But i have new problem, i put corporations in mod (BTS Corporations with little changes) all works except UNITCLASS_EXECUTIVE_1,2,3...7. When i put Executives units in CIV4UnitInfos.xml and CIV4UnitClassInfos.xml i get Error with Don't Send. What to do?

What's the error exactly?

I'm trying to remove all but 1 difficulty level, but I get an xml error saying tag HANDICAP_SETTLER in CIV4ForceControlInfos isn't working but there is no such tag in the CIV4ForceControlInfos file in BtS. (my mod doesn't have a modded version of that file)

:hmm: what, you get a XML error? Or is this just in the log?
Because such problems normally occure when there are references to removed stuff in some Python files.
 
At which point? I mean it's not maybe after you've loaded civ, during the map generation? Because in the map there are also sometimes references to the difficulty levels.
(sorry if I sound obtuse, but can't really explain a XML error from that file)

Oh, and do you have a debug dll?
 
I wonder if you can help me on this problem (Is this in the right place?) I have a mod that has a bunch of custom leaderheads and civs (Not yet) like Civ Gold. Suddenly there's no first encounter text when you meet the leaders, even the non-modded ones.

I have the AI_DIPLO_FIRST_CONTACT_LEADER text on the custom leaders filled out and I have the AI_DIPLO_FIRST_CONTACT_LEADER filled in for the custom leaders CIV4DiplomacyInfos file. Do you know what's going on?
 
What's the error exactly?

Problem was very stupid O.o i forgot to put in CIV4ArtDefines_Unit.xml
PHP:
		<UnitArtInfo>
			<Type>ART_DEF_UNIT_CEO_1,2,3....7</Type>
			<Button>,Art/Interface/Buttons/Units/ICBM.dds,Art/Interface/Buttons/Beyond_the_Sword_Atlas.dds,1,13</Button>
			<fScale>0.46</fScale>
			<fInterfaceScale>1.0</fInterfaceScale>
			<bActAsLand>0</bActAsLand>
			<bActAsAir>0</bActAsAir>
			<NIF>Art/Units/CEO/Logos/CEO_Cereal.nif</NIF>
			<KFM>Art/Units/CEO/CEO.kfm</KFM>
			<SHADERNIF>Art/Units/CEO/Logos/CEO_Cereal_FX.nif</SHADERNIF>
			<ShadowDef>
				<ShadowNIF>Art/Units/01_UnitShadows/UnitShadow.nif</ShadowNIF>
				<ShadowAttachNode>BIP Pelvis</ShadowAttachNode>
				<fShadowScale>1.0</fShadowScale>
			</ShadowDef>
			<fBattleDistance>0.35</fBattleDistance>
			<fRangedDeathTime>0.31</fRangedDeathTime>
			<bActAsRanged>0</bActAsRanged>
			<TrainSound>AS2D_UNIT_BUILD_UNIT</TrainSound>
			<AudioRunSounds>
				<AudioRunTypeLoop/>
				<AudioRunTypeEnd/>
			</AudioRunSounds>
		</UnitArtInfo>

and because i get Don't Send Error.
 
Hello!

I would like to make GG leading armies stronger: army leaded by general should get an additional level (so requirements for a level x+1 with general should be the same as for level x without general). What's more if the army dies it should lose the general (so exp needed for next level will be higher) and with 1 HP should appear in capital city instead of being destroyed. As for the last year I've damped cIV I don't really know which files should I change so any help will be appreciated :)

BTW: where I can find a formula determining when does GG spawn?
 
I guess this could help you. The general is not lost when the unit is reborn, but I think that should be not hard to remove (would have to take a look at the code again...).

I wonder if you can help me on this problem (Is this in the right place?) I have a mod that has a bunch of custom leaderheads and civs (Not yet) like Civ Gold. Suddenly there's no first encounter text when you meet the leaders, even the non-modded ones.

I have the AI_DIPLO_FIRST_CONTACT_LEADER text on the custom leaders filled out and I have the AI_DIPLO_FIRST_CONTACT_LEADER filled in for the custom leaders CIV4DiplomacyInfos file. Do you know what's going on?

mmhh...any modular leaders in there?
 
I guess this could help you. The general is not lost when the unit is reborn, but I think that should be not hard to remove (would have to take a look at the code again...).



mmhh...any modular leaders in there?

Yes, the leaders are modular. (And If there any custom civs in there, they'll be modular too.)
 
:hmm:...wait...ah...to make the custom diplomacy texts work, you have to edit the GameInfo\DiplomacyInfos.xml! The game will not automatically grab the right text, it has to be defined there.
And one major disadvantage: IIRC this file cannot be made modular.
 
:hmm:...wait...ah...to make the custom diplomacy texts work, you have to edit the GameInfo\DiplomacyInfos.xml! The game will not automatically grab the right text, it has to be defined there.
And one major disadvantage: IIRC this file cannot be made modular.

Thanks for the reply, The_J.

I found a thread with the same problem. And I found the DiplomacyInfos.xml in Cleopatra's file and I got rid of it. Now the Diplo text works now!

Thanks! :)
 
I guess this could help you. The general is not lost when the unit is reborn, but I think that should be not hard to remove (would have to take a look at the code again...).

Thanks a lot! As I will have no new promotions, just PROMOTION_LEADER will play a role of an "additional life" I think I won't have to change too many things. Still, there is the second question: where can I find formula defining how many exp is needed for spawning GG?
 
Top Bottom