Custom UA Trait confusion

Aqueries

Chieftain
Joined
Apr 3, 2016
Messages
4
Location
California, United States
Hey all. This is my first time making a post here. Happy to be a part of this great community!

Anyway, I'm trying my hand at making my first modded civ. The UA I want gives +1 Faith and +1 Culture for every resource of wheat (improved or unimproved). But as far as I can tell, there is no combination of things in CIV5Traits.xml to accomplish that. I can change the yields for forest or other unimproved features, but as far as I can tell, nothing in the xml allows me to change the yields for non-strategic resources.

Any ideas on how I can implement this?

Many thanks. -Aq
 
You're correct; there is no way, through Traits in the default game, to improve yields for specific resources, only improvements (like the Hunnic +1 Production from Pastures) or all of a certain type of resource (like Russian +1 Production from Strategics).

The way this is typically done is to create an invisible building in all of the Civ's cities that does the job for you. A very simple building definition for accomplishing what you're looking for would look like this:
Code:
<Buildings>
	<Row>
		<Type>BUILDING_FAITH_CULTURE_WHEAT</Type>
		<GreatWorkCount>-1</GreatWorkCount> <!-- this makes the building invisible -->
		<Cost>-1</Cost> <!-- this makes the building unbuildable -->
		<NeverCapture>true</NeverCapture> <!-- so other Civs don't get access to this bonus when conquering your cities -->
	</Row>
</Buildings>
<Building_ResourceYieldChanges>
	<Row>
		<BuildingType>BUILDING_FAITH_CULTURE_WHEAT</BuildingType>
		<ResourceType>RESOURCE_WHEAT</ResourceType>
		<YieldType>YIELD_CULTURE</YieldType>
		<Yield>1</Yield>
	</Row>
	<Row>
		<BuildingType>BUILDING_FAITH_CULTURE_WHEAT</BuildingType>
		<ResourceType>RESOURCE_WHEAT</ResourceType>
		<YieldType>YIELD_FAITH</YieldType>
		<Yield>1</Yield>
	</Row>
</Building_ResourceYieldChanges>
(Note: this code is incomplete and will cause problems, refer to post 4 for the proper, corrected version)

The other part of this is the more complex part: how you give the Civ this building. Because it needs to be dynamically managed (say you lose a City and conquer it back; with just this code, you wouldn't get this invisible building back and thus wouldn't get the benefits in that city), I would recommend doing it with Lua, but as I suspect you've just started modding, that may be a bit much.

Another way of doing it, though I'm not entirely sure if it would work as intended, is to do it through your Civ's trait, using <FreeBuilding> and <FreeBuildingOnConquest>:
Code:
<FreeBuilding>BUILDING_FAITH_CULTURE_WHEAT</FreeBuilding>
<FreeBuildingOnConquest>BUILDING_FAITH_CULTURE_WHEAT</FreeBuildingOnConquest>
This way, the building will be provided for free in all Cities you settle and in all Cities you conquer. Because of its <NeverCapture> field, other Civs won't get it from conquering your Cities.
 
That's a very cool idea, with the dummy building. But will setting the great work count to -1 actually remove a slot for having great works?

Also, does <NeverCapture> prevent the building from getting transferred if a city gets traded or given in a peace deal (i.e. a peaceful takeover)?

Thanks so much for the help, you are the best.
 
That's a very cool idea, with the dummy building. But will setting the great work count to -1 actually remove a slot for having great works?

Nope. It just bugs out the UI (since it tries to display a negative amount of Great Work slots) and causes the building to not appear.

Also, does <NeverCapture> prevent the building from getting transferred if a city gets traded or given in a peace deal (i.e. a peaceful takeover)?

Yes. Any change of control will destroy the building.

EDIT: I forgot a crucial part of adding the dummy building in my haste to answer the question; you need to add a BuildingClass to go along with it. Nothing fancy, just:
Code:
<BuildingClasses>
	<Row>
		<Type>BUILDINGCLASS_WHEAT_DUMMY</Type>
		<DefaultBuilding>BUILDING_CULTURE_FAITH_WHEAT</DefaultBuilding>
		<Description>TXT_KEY_BUILDING_CULTURE_FAITH_WHEAT</Description>
	</Row>
</BuildingClasses>
This is pretty important; using a new building without defining its class can cause a CTD. You should also add the class to the building definition. Also, since I forgot it initially: set the PrereqTech to NULL (so it doesn't show up in the tech tree), set NukeImmune to true (so getting nuked doesn't destroy it), as well as add description tag, portrait, and icon atlas. You shouldn't be able to see it, but not adding the description/portrait can cause problems with the Civilopedia:
Code:
<Buildings>
	<Row>
		<Type>BUILDING_FAITH_CULTURE_WHEAT</Type>
		<Description>TXT_KEY_BUILDING_CULTURE_FAITH_WHEAT</Description>
		<BuildingClass>BUILDINGCLASS_WHEAT_DUMMY</BuildingClass>
		<GreatWorkCount>-1</GreatWorkCount> <!-- this makes the building invisible -->
		<Cost>-1</Cost> <!-- this makes the building unbuildable -->
		<PrereqTech>NULL</PrereqTech> <!-- this makes the building not show in the tech tree -->
		<NeverCapture>true</NeverCapture> <!-- so other Civs don't get access to this bonus when conquering your cities -->
		<NukeImmune>true</NukeImmune> <!-- so getting nuked doesn't nullify your bonus -->
		<PortraitIndex>0</PortraitIndex>
		<IconAtlas>BW_ATLAS_1</IconAtlas>
	</Row>
</Buildings>
 
Top Bottom