The AI doesn't want to upgrade a unit

Maniac

Apolyton Sage
Joined
Nov 27, 2004
Messages
5,603
Location
Gent, Belgium
There's this completely useless I created. Its only use is that it can immediately at the start of the game be upgraded to a variety of more useful units. Yet the AI refuses to upgrade the unit. It just sits in its capital for the entire game.

Does anyone know how to entice the AI to upgrade a unit??

Code:
		<UnitInfo>
			<Class>UNITCLASS_UNITY_SUPPLIES</Class>
			<Type>UNIT_UNITY_SUPPLIES</Type>
			<Description>TXT_KEY_UNIT_UNITY_SUPPLIES</Description>
			<Civilopedia>TXT_KEY_UNIT_UNITY_SUPPLIES_PEDIA</Civilopedia>
			<Strategy>TXT_KEY_UNIT_UNITY_SUPPLIES_STRATEGY</Strategy>
			<Advisor>ADVISOR_ECONOMY</Advisor>
			<Domain>DOMAIN_LAND</Domain>
			<DefaultUnitAI>UNITAI_ENGINEER</DefaultUnitAI>
			<bMilitarySupport>0</bMilitarySupport>
			<bMilitaryProduction>0</bMilitaryProduction>
			<UnitClassUpgrades>
				<UnitClassUpgrade>
					<UnitClassUpgradeType>UNITCLASS_AQUAFORMER</UnitClassUpgradeType>
					<bUnitClassUpgrade>1</bUnitClassUpgrade>
				</UnitClassUpgrade>
				<UnitClassUpgrade>
					<UnitClassUpgradeType>UNITCLASS_FORMER</UnitClassUpgradeType>
					<bUnitClassUpgrade>1</bUnitClassUpgrade>
				</UnitClassUpgrade>
				<UnitClassUpgrade>
					<UnitClassUpgradeType>UNITCLASS_TRANSPORT_FOIL</UnitClassUpgradeType>
					<bUnitClassUpgrade>1</bUnitClassUpgrade>
				</UnitClassUpgrade>
				<UnitClassUpgrade>
					<UnitClassUpgradeType>UNITCLASS_UNITY_FOIL</UnitClassUpgradeType>
					<bUnitClassUpgrade>1</bUnitClassUpgrade>
				</UnitClassUpgrade>
				<UnitClassUpgrade>
					<UnitClassUpgradeType>UNITCLASS_UNITY_ROVER</UnitClassUpgradeType>
					<bUnitClassUpgrade>1</bUnitClassUpgrade>
				</UnitClassUpgrade>
			</UnitClassUpgrades>
			<UnitAIs>
				<UnitAI>
					<UnitAIType>UNITAI_ENGINEER</UnitAIType>
					<bUnitAI>1</bUnitAI>
				</UnitAI>
			</UnitAIs>
			<PrereqTech>TECH_NEVER</PrereqTech>
			<iCost>60</iCost>
			<iMinAreaSize>-1</iMinAreaSize>
			<iMoves>1</iMoves>
			<iXPValueAttack>4</iXPValueAttack>
			<iXPValueDefense>2</iXPValueDefense>
			<iAsset>1</iAsset>
			<iPower>2</iPower>
			<UnitMeshGroups>
				<iGroupSize>1</iGroupSize>
				<fMaxSpeed>0.2</fMaxSpeed>
				<fPadTime>1</fPadTime>
				<iMeleeWaveSize>1</iMeleeWaveSize>
				<iRangedWaveSize>0</iRangedWaveSize>
				<UnitMeshGroup>
					<iRequired>1</iRequired>
					<EarlyArtDefineTag>ART_DEF_UNIT_UNITY_SUPPLIES</EarlyArtDefineTag>
				</UnitMeshGroup>
			</UnitMeshGroups>
			<FormationType>FORMATION_TYPE_DEFAULT</FormationType>
			<Special>NONE</Special>
			<Capture>NONE</Capture>
			<iWorkRate>0</iWorkRate>
			<iNukeRange>-1</iNukeRange>
		</UnitInfo>
 
AI needs to place some value on the new units, more than they place on the current one. Current unit looks really bland, so either there is nothing about the new units which the AI likes, or the UnitAI of engineer makes the AI think that this is a great person and thus cranks up their value of it artificially.
 
Yea, I would try giving it no Advisor and change the DefaultUnitAI to something like UNITAI_UNKNOWN. Also toward the bottom of the UnitInfo entry, look for the Asset and Power tags and make sure those are set to 0. Asset and Power tags are the two root ways the AI knows how much weight to give each unit.
 
Setting unitai to unknown or asset and power value to 0 don't solve the problem. I don't see any reference to asset and power in the ai_unitvalue code btw.

As a test, I gave the Unity Supplies unitai_worker as default unit ai, and also added four other unit AIs to <UnitAIs>, corresponding to the other possible unit upgrades' default unit AIs.

Now the Unity Supplies does upgrade to the Former. Hurray!

I'm wondering though... I don't really understand the AI_upgrade() and AI_unitValue code, when they're talking about which unit's AI and stuff.

So does anyone understand how and if the Default Unit AI and the other <UnitAIs> of the unit to be upgraded and the possible units to upgrade to affect the upgrading decision?? :confused:
 
Asset and Power are only used to determine Scores for the Graphs in the F9 (F8?) menu IIRC.


The AI for each Civilization will first decide what it's main agenda is. Culture Victory, Building up for a War, Expansion, Huddling for Defense.... Once it decides that, then it is given a "shopping list" of what type of Unit AI's it requires, generally weighted on other factors as well, like how many Civs they have met, or how many Cities they own.

The value it places on each Unit will be adjusted by what the Unit AI is, and how many of that Unit AI the current objective requires.



All of this is from memory of what I saw in the code and discussed with people earlier though, not quite enough time to poke through the DLL at the moment, but wanted to stimulate further responses if I am wrong (and help if I am right) :)



As for the difference between the Default Unit AI and the array of Unit AIs, I still haven't looked into understanding that one. I assume that the default one is what it is going to be considered as before being built, and those listed in the array are the most likely ones to be selected if the unit ever re-evaluates it's AI decision process. And the Not Unit AIs would be forbidden to the unit.
 
Back
Top Bottom