Getting the AI to build a new improvement

scotchandcake

Chieftain
Joined
Jul 12, 2012
Messages
38
Hey folks,

just a quick question to make my mod work more smoothly:

I added a new improvement, the "Outpost", which uses the Barbarian Camp graphics.
It can be built in forests and jungles, yields +1 Food and also increases defense slightly for units stationed inside.

It all works perfectly well, with one exception: The AI never builds the Outpost at all.
Is there some define, which is used to tell the AI "you want to build this"?
I couldn't find anything that defines a "flavor" for improvements or something like that.

Here is the improvement's xml for reference:

Spoiler :
<GameData>
<Improvements>
<Row>
<Type>IMPROVEMENT_OUTPOST</Type>
<Description>Outpost</Description>
<Civilopedia>Outposts have always played a vital role for the growth of civilizations. They are versatile improvements that can be used for various purposes. Usually, Outposts have some kind of Palisade protection and are well hidden inside Forests or Jungles. They provide additional defense and offer a Food storage for military or civilians who are stationed outside of Cities.[NEWLINE][NEWLINE]The Outpost provides 25% extra defense for military units stationed inside it, and increases the Food output of the tile it is constructed on. After the discovery of Archaeology, the Outpost may also be used for research purposes[NEWLINE]The need of nearby building material requires the Outpost to be constructed in Forest or Jungle. You can construct an Outpost within your territory, or directly adjacent to your territory.</Civilopedia>
<ArtDefineTag>ART_DEF_IMPROVEMENT_BARBARIAN_CAMP</ArtDefineTag>
<RequiresFeature>true</RequiresFeature>
<DestroyedWhenPillaged>true</DestroyedWhenPillaged>
<InAdjacentFriendly>true</InAdjacentFriendly>
<DefenseModifier>25</DefenseModifier>
<PortraitIndex>21</PortraitIndex>
<IconAtlas>TERRAIN_ATLAS</IconAtlas>
</Row>
</Improvements>
<Improvement_Yields>
<Row>
<ImprovementType>IMPROVEMENT_OUTPOST</ImprovementType>
<YieldType>YIELD_FOOD</YieldType>
<Yield>1</Yield>
</Row>
</Improvement_Yields>
<Improvement_ValidFeatures>
<Row>
<ImprovementType>IMPROVEMENT_OUTPOST</ImprovementType>
<FeatureType>FEATURE_JUNGLE</FeatureType>
</Row>
<Row>
<ImprovementType>IMPROVEMENT_OUTPOST</ImprovementType>
<FeatureType>FEATURE_FOREST</FeatureType>
</Row>
</Improvement_ValidFeatures>
<Improvement_TechYieldChanges>
<Row>
<ImprovementType>IMPROVEMENT_OUTPOST</ImprovementType>
<TechType>TECH_ARCHAEOLOGY</TechType>
<YieldType>YIELD_SCIENCE</YieldType>
<Yield>1</Yield>
</Row>
</Improvement_TechYieldChanges>

<Builds>
<Row>
<Type>BUILD_OUTPOST</Type>
<PrereqTech>TECH_SCOUTING</PrereqTech>
<Time>700</Time>
<ImprovementType>IMPROVEMENT_OUTPOST</ImprovementType>
<Description>Construct an Outpost</Description>
<Recommendation>It will increase the tile's [ICON_FOOD] Food output, granting increased Growth for your City. It also provides increased defense for units stationed inside.</Recommendation>
<EntityEvent>ENTITY_EVENT_BUILD</EntityEvent>
<OrderPriority>98</OrderPriority>
<IconIndex>11</IconIndex>
<IconAtlas>TECH_ATLAS_PRE</IconAtlas>
</Row>
</Builds>
<Unit_Builds>
<Row>
<UnitType>UNIT_WORKER</UnitType>
<BuildType>BUILD_OUTPOST</BuildType>
</Row>
</Unit_Builds>
</GameData>


Thanks in advance for help and ideas! :worship:
 
I'm sure builds have flavors, too. Give it a flavor.
 
Builds don't have flavors.

Improvements have flavors:
Code:
	<Table name="Improvement_Flavors">
		<Column name="ImprovementType" type="text" reference="Improvements(Type)"/>
		<Column name="FlavorType" type="text" reference="Flavors(Type)"/>
		<Column name="Flavor" type="integer" notnull="true"/>
	</Table>
But they aren't used. AFAIK the AI considers the value of yields when choosing improvements to build, perhaps it finds other improvements than the Outpost more attractive?
 
Thanks for the replies!

The problem is that there is no other improvements to build.
It's for my Prehistoric Era mod, which adds another 2000 years before the Ancient Era.
The first improvement players can build is the Outpost, and then later on the Farm when researching Agriculture.

The AI just doesn't do anything with their workers. They just stand around like idiots until Farms are available :/

I'll try to add a Flavor and see what happens, I wasn't aware of the improvement flavors...
 
If they don't build anything, then it's a serious problem, which I can encounter when making my mod too... Either the types of improvements that the AI builds are hardcoded (which is a bad thing), or it's some property of your improvement that makes the AI not build it - the defensive bonus, or the ability to construct it adjacent to friendly lands, or "destroyed when pillaged"... I know it sounds stupid that such things would make the AI not build them, but it's worth checking (the flavors are worth checking too).
 
I'd really like to know what you find out, scotchandcake. I'm making my first unique improvement in my current project, so I'd be very interested in seeing what I can do to make sure it works right, including having the AI build it.

PawelS, what makes you think the improvement flavors aren't used? Is it just a hunch based on your experiences, or is there some list out there that says what tags are in the XML but don't actually do anything? I'd be interested in seeing such a list if there is one.
 
I think I found out what the problem is, although it's more a theory.
(Adding a flavor or removing those special attributes didn't change anything,
whenever I put a worker on "automate", they just park themselves in a city)

I suppose the issue is the unit AI.
Every worker is defined with UNITAI_WORKER.
This AI cannot know about new improvements (obviously) and thus workers don't build them.

I had the same problem with a new unit, which could use the "Culture Bomb" ability. Since Great Artists don't have that anymore in G&K, setting the AI of the unit to UNITAI_ARTIST didn't help - the AI just didn't know how to use it.

Unless there is some way to add something to the UNITAI entries, I don't think the AI will be able to build/do new things added by mods.

This is just my theory, anyone else's experience would be great :)
 
PawelS, what makes you think the improvement flavors aren't used? Is it just a hunch based on your experiences, or is there some list out there that says what tags are in the XML but don't actually do anything? I'd be interested in seeing such a list if there is one.

By "unused" I meant that the improvements don't have any flavors in unmodded game - the Improvement_Flavors table is empty. I have no idea if adding flavors has any gameplay effect or not.

I'm going to make a list of XML tags that have no effect, but after the DLL code is released - then it will be easy to check which tags aren't referenced in the code.

I think I found out what the problem is, although it's more a theory.
(Adding a flavor or removing those special attributes didn't change anything,
whenever I put a worker on "automate", they just park themselves in a city)

I suppose the issue is the unit AI.
Every worker is defined with UNITAI_WORKER.
This AI cannot know about new improvements (obviously) and thus workers don't build them.

I had the same problem with a new unit, which could use the "Culture Bomb" ability. Since Great Artists don't have that anymore in G&K, setting the AI of the unit to UNITAI_ARTIST didn't help - the AI just didn't know how to use it.

Unless there is some way to add something to the UNITAI entries, I don't think the AI will be able to build/do new things added by mods.

This is just my theory, anyone else's experience would be great :)

Have you checked if an actual AI builds them, or only the automate option? The behavior of the AI workers and automated workers may differ.

UNITAI_WORKER not building new improvements it what I meant by the list of improvements being hardcoded. If it's true, then we can't do anything about it until we have access to the DLL source code.
 
Have you checked if an actual AI builds them, or only the automate option? The behavior of the AI workers and automated workers may differ

Yes, I tried both. I gave workers and the required tech for the improvement to several AI civs and watched them over ~10 rounds; I also put my own worker on "automate" after researching the required tech.

In both cases, the workers just go to the next city and sit there, idle.

If the UNITAI_WORKER (and any other AI for other types) is responsible for the problem, it might be impossible right now to get AI civs to use new stuff.

In this case, it might be smart to use new stuff that doesnt affect the overall game too much.

Although it's a shame, I don't think it's really problematic if the AI doesn't build an improvement that gives +1 Food to forests and jungles.
Would have been nice, though... :(
 
I just realised that the problem is NOT the UNITAI_WORKER at all.
There is other new improvements which workers do build.
There must be some other problem in the xml, some entry the AI doesn't like.

I tried adding a flavor to the improvement (which does help for other improvements),
but that didn't help either.

If someone discovers a possible problem source, I'd be happy about help :)
 
Can you post the XML code of at least one of the other new improvements?
 
Sure, this is an improvement for a different mod, which does work - i watched AI civs build it:

Spoiler :
<Improvements>
<Row>
<Type>IMPROVEMENT_GRAVEYARD</Type>
<Description>TXT_KEY_IMPROVEMENT_GRAVEYARD</Description>
<Help>TXT_KEY_IMPROVEMENT_GRAVEYARD_HELP</Help>
<Civilopedia>TXT_KEY_IMPROVEMENT_GRAVEYARD_PEDIA</Civilopedia>
<ArtDefineTag>ART_DEF_IMPROVEMENT_GOODY_HUT</ArtDefineTag>
<RequiresFlatlands>true</RequiresFlatlands>
<DestroyedWhenPillaged>true</DestroyedWhenPillaged>
<PillageGold>20</PillageGold>
<PortraitIndex>34</PortraitIndex>
<IconAtlas>TERRAIN_ATLAS</IconAtlas>
</Row>
</Improvements>

<Improvement_Flavors>
<Row>
<ImprovementType>IMPROVEMENT_GRAVEYARD</ImprovementType>
<FlavorType>FLAVOR_CULTURE</FlavorType>
<Flavor>2</Flavor>
</Row>
</Improvement_Flavors>

<Improvement_Yields>
<Row>
<ImprovementType>IMPROVEMENT_GRAVEYARD</ImprovementType>
<YieldType>YIELD_CULTURE</YieldType>
<Yield>1</Yield>
</Row>
</Improvement_Yields>

<Improvement_ValidTerrains>
<Row>
<ImprovementType>IMPROVEMENT_GRAVEYARD</ImprovementType>
<TerrainType>TERRAIN_PLAINS</TerrainType>
</Row>
<Row>
<ImprovementType>IMPROVEMENT_GRAVEYARD</ImprovementType>
<TerrainType>TERRAIN_TUNDRA</TerrainType>
</Row>
<Row>
<ImprovementType>IMPROVEMENT_GRAVEYARD</ImprovementType>
<TerrainType>TERRAIN_GRASS</TerrainType>
</Row>
<Row>
<ImprovementType>IMPROVEMENT_GRAVEYARD</ImprovementType>
<TerrainType>TERRAIN_DESERT</TerrainType>
</Row>
</Improvement_ValidTerrains>

<Builds>
<Row>
<Type>BUILD_GRAVEYARD</Type>
<Time>800</Time>
<ImprovementType>IMPROVEMENT_GRAVEYARD</ImprovementType>
<Description>TXT_KEY_BUILD_GRAVEYARD</Description>
<Recommendation>TXT_KEY_BUILD_GRAVEYARD_REC</Recommendation>
<EntityEvent>ENTITY_EVENT_FORTIFY</EntityEvent>
<OrderPriority>98</OrderPriority>
<IconIndex>52</IconIndex>
<IconAtlas>UNIT_ACTION_ATLAS</IconAtlas>
</Row>
</Builds>
<Unit_Builds>
<Row>
<UnitType>UNIT_SUPER_SHAMAN</UnitType>
<BuildType>BUILD_GRAVEYARD</BuildType>
</Row>
</Unit_Builds>

<Language_en_US>
<Row Tag="TXT_KEY_IMPROVEMENT_GRAVEYARD">
<Text>Graveyard</Text>
</Row>
<Row Tag="TXT_KEY_IMPROVEMENT_GRAVEYARD_HELP">
<Text>Can only be constructed on flat Terrain.</Text>
</Row>
<Row Tag="TXT_KEY_IMPROVEMENT_GRAVEYARD_PEDIA">
<Text>A graveyard is any place set aside for long-term burial of the dead, with or without monuments such as headstones.[NEWLINE](Quoted from en.wikipedia.org/wiki/Graveyard)[NEWLINE][NEWLINE]Graveyards can only be constructed on flat Terrain. They add Culture to the hex's output.</Text>
</Row>
<Row Tag="TXT_KEY_BUILD_GRAVEYARD">
<Text>Construct a Graveyard</Text>
</Row>
<Row Tag="TXT_KEY_BUILD_GRAVEYARD_REC">
<Text>It will add [ICON_CULTURE] Culture to the tile's output, speeding the growth of the city's territory and the civilization's acquisition of Social Policies.</Text>
</Row>
</Language_en_US>
 
Top Bottom