How to code Uniques?

Ajsieg

Warlord
Joined
Nov 15, 2015
Messages
190
Location
Batavia, Illinois
So after getting the basic XML for a civ with some tweaks done, I'm wondering how to code the uniques. I'm basically asking do I use Lua or XML and if it's XML, how do I do it? A friend I'm working with is doing the Lua.

Here's the uniques:

UA: Cities settled on desert gets +15% bonus to their Culture and Unit production. Units gets a bonus attacking cities on desert and conquering a city with a minimum number of citizens gives a free social policy depending on the era you’re in.*

Spoiler :
*
Ancient: 10 Citizens
Classical: 15 Citizens
Medieval: 15 Citizens
Renaissance: 20 Citizens
Industrial: 25 Citizens
Atomic: 30 Citizens
Modern: 30 Citizens
Information: 35 Citizens


UU: Replaces Spearman. Gets double movement in enemy territory and gets gold from attacking cities. (Basically Coastal Raider for naval units)


UB: Replaces Granary. Provides a free copy of Dates, a Luxury Resource. Wheat provides +1 Food and Culture. Farms built on desert get +1 Food. Only provides +1 Food instead of +2. (Note: Wheat bonus are done and so is the +1 Food).

3rd Comp UI: Provides +1 Culture and Faith. Bonuses are doubled if built on a desert hill. Provides +1 Science after researching Archaeology. Can not be built adjacent to each other. If built next to a city, it spawns a free missionary in the city it was built next to.

4th Comp UB: Replaces the Forge. Requires no Iron and provides +1 Iron. Provides +1 Production and Gold to mining resources on flat desert.

Thanks in advance :D.
 
Most of these will honestly require both Lua and XML.
UA: Cities settled on desert gets +15% bonus to their Culture and Unit production. Units gets a bonus attacking cities on desert and conquering a city with a minimum number of citizens gives a free social policy depending on the era you’re in.*
You'd need Lua to check whether or not the City was on Desert, and then use it to assign a dummy building (made through XML) that gives +15% Culture and +15% Production toward all unit domains (DOMAIN_LAND and DOMAIN_SEA; refer to the Hermitage/Broadcast Tower for percent modifiers on Culture, and refer to something like the Forge for percent modifiers on types of units). The bonus for attacking Cities on Desert is pretty difficult to do because it requires using Lua to check at the time of the battle, which is particularly difficult to do with base Firaxis code. The free Social Policy part would need to be done entirely with Lua.
UU: Replaces Spearman. Gets double movement in enemy territory and gets gold from attacking cities. (Basically Coastal Raider for naval units)
The UU itself would obviously be defined in XML, and its promotion for getting Gold from attacking Cities would have to be done in XML as well (refer to the Coastal Raider promotion, as you pointed out, for how this is done). The double Movement in enemy territory would be a combination of Lua and XML; the promotion would give the double Movement itself, but you'd need Lua to check whether or not the unit was in enemy territory and only give it that promotion when it is.

UB: Replaces Granary. Provides a free copy of Dates, a Luxury Resource. Wheat provides +1 Food and Culture. Farms built on desert get +1 Food. Only provides +1 Food instead of +2. (Note: Wheat bonus are done and so is the +1 Food).
New Resources can be done entirely in XML, but it depends on what you mean by "provide a free copy of." Do you mean spawn a copy next to the City (in which case that would need Lua, as well as art definitions for the Dates themselves), or just simply owning the building gives you one copy of Dates? If it's the latter, refer to a building like the Recycling Center for how Civ handles giving copies of Resources outright.
3rd Comp UI: Provides +1 Culture and Faith. Bonuses are doubled if built on a desert hill. Provides +1 Science after researching Archaeology. Can not be built adjacent to each other. If built next to a city, it spawns a free missionary in the city it was built next to.
This is a bit trickier than you might expect. There's no way to modify an Improvement's yield depending on terrain; you need to make two separate copies of the same Improvement, one of which has the normal yields and can be built anywhere but Desert Hills, and the other has the doubled yields and can only be built on Desert Hills. The Missionary spawning would have to be done through Lua.
4th Comp UB: Replaces the Forge. Requires no Iron and provides +1 Iron. Provides +1 Production and Gold to mining resources on flat desert.
There's no easy way to do this in XML because of the terrain requirement. The "Flat Desert" part of this is a stipulation that adds a lot of complications, and you'd need to use Lua to circumvent it. First, it would require a dummy improvement/feature that yields +1 Production and Gold, and then you'd need to use Lua to check for Cities with this building and add that dummy improvement/feature to all Flat Desert tiles with mining Resources on them.
 
Most of these will honestly require both Lua and XML.

You'd need Lua to check whether or not the City was on Desert, and then use it to assign a dummy building (made through XML) that gives +15% Culture and +15% Production toward all unit domains (DOMAIN_LAND and DOMAIN_SEA; refer to the Hermitage/Broadcast Tower for percent modifiers on Culture, and refer to something like the Forge for percent modifiers on types of units). The bonus for attacking Cities on Desert is pretty difficult to do because it requires using Lua to check at the time of the battle, which is particularly difficult to do with base Firaxis code. The free Social Policy part would need to be done entirely with Lua.

Would "Get a bonus to attacking cities when on flat terrain" be any better? Understood everything else. Is there a tutorial on Dummy Buildings? I thought there was.

The UU itself would obviously be defined in XML, and its promotion for getting Gold from attacking Cities would have to be done in XML as well (refer to the Coastal Raider promotion, as you pointed out, for how this is done). The double Movement in enemy territory would be a combination of Lua and XML; the promotion would give the double Movement itself, but you'd need Lua to check whether or not the unit was in enemy territory and only give it that promotion when it is.

Sounds easy enough.

New Resources can be done entirely in XML, but it depends on what you mean by "provide a free copy of." Do you mean spawn a copy next to the City (in which case that would need Lua, as well as art definitions for the Dates themselves), or just simply owning the building gives you one copy of Dates? If it's the latter, refer to a building like the Recycling Center for how Civ handles giving copies of Resources outright.
Yes it is generated in the city. I can take a look at JFD's Belgian mod since he did something similar to what I'm doing.

This is a bit trickier than you might expect. There's no way to modify an Improvement's yield depending on terrain; you need to make two separate copies of the same Improvement, one of which has the normal yields and can be built anywhere but Desert Hills, and the other has the doubled yields and can only be built on Desert Hills. The Missionary spawning would have to be done through Lua.

Would requiring to be on Desert Hills work? I rather have the one improvement instead of two as that would be overly complicated :crazyeye:.

There's no easy way to do this in XML because of the terrain requirement. The "Flat Desert" part of this is a stipulation that adds a lot of complications, and you'd need to use Lua to circumvent it. First, it would require a dummy improvement/feature that yields +1 Production and Gold, and then you'd need to use Lua to check for Cities with this building and add that dummy improvement/feature to all Flat Desert tiles with mining Resources on them.

Hmmm. I'll probably give the +1 gold and production to specific resources (No desert requirement).

Thank you for the help!
 
Is there a tutorial on Dummy Buildings? I thought there was.

Just make a normal building, but make its GreatWorkCount, Cost, and FaithCost -1 and its PrereqTech null, and its building class should have <NoLimit>true</NoLimit> in most cases.
 
Would "Get a bonus to attacking cities when on flat terrain" be any better?
As in the City is on Flat terrain or the unit is? If it's the latter, that's very doable and much easier to do through Lua (just check when a unit moves to see if it's on Flat terrain, give it a promotion that gives extra Strength against Cities if so). The former has the same problem as attacking Cities on Desert. The problem is that there's no way to conditionally give promotions in XML, because as far as the database is concerned, you either have it or you don't. It has to be done through Lua, and if you're predicating your promotion on a certain type of battle (like attacking a City on Desert), then you'll very quickly run into one of the main limitations of Lua in Civ5: it really sucks at monitoring battles.
Is there a tutorial on Dummy Buildings? I thought there was.
What Klisz said is perfectly sufficient for most cases, but for reference, LeeS has written up an incredibly in-depth post on dummy buildings, how to use them, what to be careful of, and their limitations.
Would requiring to be on Desert Hills work? I rather have the one improvement instead of two as that would be overly complicated :crazyeye:.
Yep--refer to the Kasbah and Terrace Farm for how setting certain Terrain requirements works.
 
UA: Cities settled on desert gets +15% bonus to their Culture and Unit production. Units gets a bonus attacking cities on desert and conquering a city with a minimum number of citizens gives a free social policy depending on the era you’re in.*

You'd need Lua to check whether or not the City was on Desert, and then use it to assign a dummy building (made through XML) that gives +15% Culture and +15% Production toward all unit domains (DOMAIN_LAND and DOMAIN_SEA; refer to the Hermitage/Broadcast Tower for percent modifiers on Culture, and refer to something like the Forge for percent modifiers on types of units).

Actually, you don't need Lua for the first part of the UA -- if you put a terrain requirement in for your dummy building (using <NearbyTerrainRequired>TERRAIN_DESERT</NearbyTerrainRequired>), and then use <FreeBuilding>YOUR_DUMMY_BUILDING_HERE</FreeBuilding> in the civ's trait, the game will only spawn the dummy building in cities that meet its terrain requirement. It is, admittedly, about the only condition that the game will actually check when it comes to free buildings, but it does actually work. Presumably because Carthage's trait provides free Harbors, but the game has to make sure they only spawn in coastal cities.
 
Top Bottom