Making My First Mod, Need Help with Civilization Unique Unit

Dark Kijin

Chieftain
Joined
May 25, 2020
Messages
2
Hi there!
I've been following along with a Civ VI modding tutorial on Youtube but I'm a bit lost when it comes to certain parts of the Unique Unit Code.

Not that it truly matters (but in case anyone wants context), I'm attempting to make a Civilization around Keiki Haniyasushin from Touhou 17. Her unique unit is the Mounted Haniwa Archer, and it has the following attributes

- Light Cavalry unit of the Renaissance Era (So it doesn't replace a unit, sort of like the Malón Raider of the Mapuche)
- Ranged Strength of 55 and Combat Strength of 50
- Gets +15 Ranged Strength against enemy cavalry units
- Can only be purchases with Faith
- Does not required Horses to make

I haven't quite gotten to most of the pieces there, as I'm still stuck on the "Gets +15 Ranged Strength against enemy cavalry units" modifier as the first part I'm working on (I'm using the Civ VI Modding Companion to try and find which built-in modifiers there are, but I wasn't sure if I needed to use the "REQUIREMENT_UNIT_TYPE_MATCHES" or the "REQUIREMENT_OPPONENT_UNIT_TYPE_MATCHES" requirement, and I'm also just generally pretty stumped on the steps I need to take after that.
 
Are you referencing an existing mod that adds a new unit? My usual method is to find something similar to what I want to do and start by piggybacking my additions onto something that I know works. Once I have something functional at a basic level, I can then rebuild it as my own while having a working prototype to reference. Get a generic new unit working first, then worry about details like special abilities.

As far at the new modifier goes, I'd recommend using the RequirementType: REQUIREMENT_OPPONENT_UNIT_PROMOTION_CLASS_MATCHES. The Steel & Thunder unit mod by Deliverator uses that for an effect very similar to what you are looking to do.
 
Hi there!
I've been following along with a Civ VI modding tutorial on Youtube but I'm a bit lost when it comes to certain parts of the Unique Unit Code.

Not that it truly matters (but in case anyone wants context), I'm attempting to make a Civilization around Keiki Haniyasushin from Touhou 17. Her unique unit is the Mounted Haniwa Archer, and it has the following attributes

- Light Cavalry unit of the Renaissance Era (So it doesn't replace a unit, sort of like the Malón Raider of the Mapuche)
- Ranged Strength of 55 and Combat Strength of 50
- Gets +15 Ranged Strength against enemy cavalry units
- Can only be purchases with Faith
- Does not required Horses to make

I haven't quite gotten to most of the pieces there, as I'm still stuck on the "Gets +15 Ranged Strength against enemy cavalry units" modifier as the first part I'm working on (I'm using the Civ VI Modding Companion to try and find which built-in modifiers there are, but I wasn't sure if I needed to use the "REQUIREMENT_UNIT_TYPE_MATCHES" or the "REQUIREMENT_OPPONENT_UNIT_TYPE_MATCHES" requirement, and I'm also just generally pretty stumped on the steps I need to take after that.

Firstly, welcome to the world of modding. I'm new to it, too - and I can say it is very rewarding and don't give up or be discouraged. The first one takes a lot of trial and error and fiddling with code.

Now, onto your actual requirements. Everything below is referencing entries in Units.xml, unless otherwise stated. The good news is that a significant number of the things you're trying to do are all achieved through the main/core Units table definitions. If we use the rudimentary UNIT_HORSEMAN and UNIT_BARBARIAN_HORSE_ARCHER as examples, the entries into the Units table (in the base-game XML) are as below:

Code:
<Row UnitType="UNIT_HORSEMAN" Cost="80" Maintenance="2" BaseMoves="4" BaseSightRange="2" ZoneOfControl="true" Domain="DOMAIN_LAND" Combat="36" StrategicResource="RESOURCE_HORSES" FormationClass="FORMATION_CLASS_LAND_COMBAT" PromotionClass="PROMOTION_CLASS_LIGHT_CAVALRY" AdvisorType="ADVISOR_CONQUEST" Name="LOC_UNIT_HORSEMAN_NAME" Description="LOC_UNIT_HORSEMAN_DESCRIPTION" PurchaseYield="YIELD_GOLD" MandatoryObsoleteTech="TECH_SYNTHETIC_MATERIALS" PrereqTech="TECH_HORSEBACK_RIDING"/>

<Row UnitType="UNIT_BARBARIAN_HORSE_ARCHER" Cost="35" Maintenance="1" BaseMoves="3" BaseSightRange="2" ZoneOfControl="false" Domain="DOMAIN_LAND" Combat="10" RangedCombat="15" Range="1" FormationClass="FORMATION_CLASS_LAND_COMBAT" PromotionClass="PROMOTION_CLASS_RANGED" AdvisorType="ADVISOR_CONQUEST" Name="LOC_UNIT_BARBARIAN_HORSE_ARCHER_NAME" Description="LOC_UNIT_BARBARIAN_HORSE_ARCHER_DESCRIPTION" PurchaseYield="YIELD_GOLD" TraitType="TRAIT_BARBARIAN"/>

The Ranged Strength and Combat Strength are set via the Combat and RangedCombat values. The Faith Purchase is set via the PurchaseYield (value = YIELD_FAITH) value. You will note that there is an entry for the UNIT_HORSEMAN that specifics StrategicResource="RESOURCE_HORSES". Simply omit this and you remove the requirement for Horses. Immediately, you've achieved three of the five items on your list.

While we're looking at the entries for each unit, please note the TraitType (for the UNIT_BARBARIAN_HORSE_ARCHER). You'll use a similar technique to make the Mounted Haniwa Archer unique to your custom civilization. As you're not replacing a unit in the food-chain, simply don't include an entry in the UnitReplaces table.

An entry into the TypeTags table that ties your Unique Unit (I'll call it UNIT_MOUNTED_HANIWA_ARCHER) to the CLASS_LIGHT_CAVALRY will suffice to achieve the first item you mention. In XML, that looks something like:

Code:
<TypeTags>
<Row Type="UNIT_MOUNTED_HANIWA_ARCHER" Tag="CLASS_LIGHT_CAVALRY"/>
</TypeTags>

In SQL, it's along the lines of:

Code:
INSERT INTO TypeTags
(Type, Tag)
VALUES ('UNIT_MOUNTED_HANIWA_ARCHER', 'CLASS_LIGHT_CAVALRY');

I believe all that leaves is the trickiest part - the conditional requirement that grants a ranged combat boost versus units of other specific types. I will revisit this for you tomorrow (sorry to stop short of the full solution), as it's just dawned on me how late it is. Perhaps someone will beat me to it. However, the simplest equivalent function I could find - which is the Spearman's bonus versus cavalary units - seems to use the RequirementType of REQUIREMENT_OPPONENT_UNIT_PROMOTION_CLASS_MATCHES, as Arstahd mentions. However, if it is the same group of unit types you are trying to target, you can just use the RequirementId of OPPONENT_ANTI_CAVALRY_REQUIREMENT, I think. It exists and you don't need to code the remainder of the logic to identify the opponents. The logic for your Modifier's effect on your unit will need to be added in, though.
 
Firstly, welcome to the world of modding. I'm new to it, too - and I can say it is very rewarding and don't give up or be discouraged. The first one takes a lot of trial and error and fiddling with code.

Now, onto your actual requirements. Everything below is referencing entries in Units.xml, unless otherwise stated. The good news is that a significant number of the things you're trying to do are all achieved through the main/core Units table definitions. If we use the rudimentary UNIT_HORSEMAN and UNIT_BARBARIAN_HORSE_ARCHER as examples, the entries into the Units table (in the base-game XML) are as below:

Code:
<Row UnitType="UNIT_HORSEMAN" Cost="80" Maintenance="2" BaseMoves="4" BaseSightRange="2" ZoneOfControl="true" Domain="DOMAIN_LAND" Combat="36" StrategicResource="RESOURCE_HORSES" FormationClass="FORMATION_CLASS_LAND_COMBAT" PromotionClass="PROMOTION_CLASS_LIGHT_CAVALRY" AdvisorType="ADVISOR_CONQUEST" Name="LOC_UNIT_HORSEMAN_NAME" Description="LOC_UNIT_HORSEMAN_DESCRIPTION" PurchaseYield="YIELD_GOLD" MandatoryObsoleteTech="TECH_SYNTHETIC_MATERIALS" PrereqTech="TECH_HORSEBACK_RIDING"/>

<Row UnitType="UNIT_BARBARIAN_HORSE_ARCHER" Cost="35" Maintenance="1" BaseMoves="3" BaseSightRange="2" ZoneOfControl="false" Domain="DOMAIN_LAND" Combat="10" RangedCombat="15" Range="1" FormationClass="FORMATION_CLASS_LAND_COMBAT" PromotionClass="PROMOTION_CLASS_RANGED" AdvisorType="ADVISOR_CONQUEST" Name="LOC_UNIT_BARBARIAN_HORSE_ARCHER_NAME" Description="LOC_UNIT_BARBARIAN_HORSE_ARCHER_DESCRIPTION" PurchaseYield="YIELD_GOLD" TraitType="TRAIT_BARBARIAN"/>

The Ranged Strength and Combat Strength are set via the Combat and RangedCombat values. The Faith Purchase is set via the PurchaseYield (value = YIELD_FAITH) value. You will note that there is an entry for the UNIT_HORSEMAN that specifics StrategicResource="RESOURCE_HORSES". Simply omit this and you remove the requirement for Horses. Immediately, you've achieved three of the five items on your list.

While we're looking at the entries for each unit, please note the TraitType (for the UNIT_BARBARIAN_HORSE_ARCHER). You'll use a similar technique to make the Mounted Haniwa Archer unique to your custom civilization. As you're not replacing a unit in the food-chain, simply don't include an entry in the UnitReplaces table.

An entry into the TypeTags table that ties your Unique Unit (I'll call it UNIT_MOUNTED_HANIWA_ARCHER) to the CLASS_LIGHT_CAVALRY will suffice to achieve the first item you mention. In XML, that looks something like:

Code:
<TypeTags>
<Row Type="UNIT_MOUNTED_HANIWA_ARCHER" Tag="CLASS_LIGHT_CAVALRY"/>
</TypeTags>

In SQL, it's along the lines of:

Code:
INSERT INTO TypeTags
(Type, Tag)
VALUES ('UNIT_MOUNTED_HANIWA_ARCHER', 'CLASS_LIGHT_CAVALRY');

I believe all that leaves is the trickiest part - the conditional requirement that grants a ranged combat boost versus units of other specific types. I will revisit this for you tomorrow (sorry to stop short of the full solution), as it's just dawned on me how late it is. Perhaps someone will beat me to it. However, the simplest equivalent function I could find - which is the Spearman's bonus versus cavalary units - seems to use the RequirementType of REQUIREMENT_OPPONENT_UNIT_PROMOTION_CLASS_MATCHES, as Arstahd mentions. However, if it is the same group of unit types you are trying to target, you can just use the RequirementId of OPPONENT_ANTI_CAVALRY_REQUIREMENT, I think. It exists and you don't need to code the remainder of the logic to identify the opponents. The logic for your Modifier's effect on your unit will need to be added in, though.

Thanks so much (both of you) for your quick responses! That all does clear up a bunch of my problems, and I think I definitely understand the modding process here a lot more than I previously did!
 
Top Bottom