Modding a Unit

Aheadatime

Prince
Joined
Dec 21, 2009
Messages
325
So I'm trying to learn how to modify units, which is something completely new to me. I decided to start with the Spanish Conquistador. Found this line of code, and attempted to mod it. Here's original;

Spoiler :
Code:
<Units>

    -<InsertOrAbort>

        <Class>UNITCLASS_KNIGHT</Class>
        <Type>UNIT_SPANISH_CONQUISTADOR</Type>
        <PrereqTech>TECH_CHIVALRY</PrereqTech>
        <Combat>20</Combat>
        <Cost>135</Cost>
        <FaithCost>270</FaithCost>
        <RequiresFaithPurchaseEnabled>true</RequiresFaithPurchaseEnabled>
        <Moves>4</Moves>
        <CombatClass>UNITCOMBAT_MOUNTED</CombatClass>
        <Domain>DOMAIN_LAND</Domain>
        <DefaultUnitAI>UNITAI_ATTACK</DefaultUnitAI>
        <Description>TXT_KEY_UNIT_SPANISH_CONQUISTADOR</Description>
        <Civilopedia>TXT_KEY_CIV5_SPAIN_CONQUISTADOR_TEXT</Civilopedia>
        <Strategy>TXT_KEY_CIV5_SPAIN_CONQUISTADOR_STRATEGY</Strategy>
        <Help>TXT_KEY_CIV5_SPAIN_CONQUISTADOR_HELP</Help>
        <FoundAbroad>true</FoundAbroad>
        <MilitarySupport>true</MilitarySupport>
        <MilitaryProduction>true</MilitaryProduction>
        <Pillage>true</Pillage>
        <ObsoleteTech>TECH_MILITARY_SCIENCE</ObsoleteTech/>
        <GoodyHutUpgradeUnitClass>UNITCLASS_CAVALRY</GoodyHutUpgradeUnitClass>
        <AdvancedStartCost>25</AdvancedStartCost>
        <XPValueAttack>3</XPValueAttack>
        <XPValueDefense>3</XPValueDefense>
        <UnitArtInfo>ART_DEF_UNIT_U_SPANISH_CONQUISTADOR</UnitArtInfo>
        <IconAtlas>DLC02_UNIT_ATLAS</IconAtlas>
        <UnitFlagAtlas>DLC02_UNIT_FLAG_ATLAS</UnitFlagAtlas>
        <UnitFlagIconOffset>1</UnitFlagIconOffset>
        <PortraitIndex>1</PortraitIndex>

    </InsertOrAbort>

</Units>

My attempt was simple;

Spoiler :
Code:
	<Units>

		<Delete Type="UNIT_SPANISH_CONSQUISTADOR"/>
		
		<InsertOrAbort>
			<Class>UNITCLASS_HORSEMAN</Class>
			<Type>UNIT_SPANISH_CONQUISTADOR</Type>
			<PrereqTech>TECH_HORSEBACK_RIDING</PrereqTech>
			<Combat>12</Combat>
			<Cost>80</Cost>
			<FaithCost>160</FaithCost>
			<RequiresFaithPurchaseEnabled>true</RequiresFaithPurchaseEnabled>
			<Moves>4</Moves>
			<CombatClass>UNITCOMBAT_MOUNTED</CombatClass>
			<Domain>DOMAIN_LAND</Domain>
			<DefaultUnitAI>UNITAI_ATTACK</DefaultUnitAI>
			<Description>TXT_KEY_UNIT_SPANISH_CONQUISTADOR</Description>
			<Civilopedia>TXT_KEY_CIV5_SPAIN_CONQUISTADOR_TEXT</Civilopedia>
			<Strategy>TXT_KEY_CIV5_SPAIN_CONQUISTADOR_STRATEGY</Strategy>
			<Help>TXT_KEY_CIV5_SPAIN_CONQUISTADOR_HELP</Help>
			<Found>true</Found>
			<MilitarySupport>true</MilitarySupport>
			<MilitaryProduction>true</MilitaryProduction>
			<Pillage>true</Pillage>
			<ObsoleteTech>TECH_CHIVALRY</ObsoleteTech>
			<GoodyHutUpgradeUnitClass>UNITCLASS_KNIGHT</GoodyHutUpgradeUnitClass>
			<AdvancedStartCost>25</AdvancedStartCost>
			<XPValueAttack>3</XPValueAttack>
			<XPValueDefense>3</XPValueDefense>
			<UnitArtInfo>ART_DEF_UNIT_U_SPANISH_CONQUISTADOR</UnitArtInfo>
			<IconAtlas>DLC02_UNIT_ATLAS</IconAtlas>
			<UnitFlagAtlas>DLC02_UNIT_FLAG_ATLAS</UnitFlagAtlas>
			<UnitFlagIconOffset>1</UnitFlagIconOffset>
			<PortraitIndex>1</PortraitIndex>
		</InsertOrAbort>
		
	</Units>

So was this a correct way to try this? It didn't work btw. I also have no idea what the 'InsertOrAbort' thing is, as that's usually where I see the term 'Row'.
 
Ended up using the <Update> and <Where/Set> tags, and ran into something strange. Goal was to make the Conquistador available at Horseback, replacing the Horseman. Currently, at Horseback, the generic 'Horseman' icon is still there and if I build a horseman, I have to upgrade it to get the Conquistador properties. What's up with this?
 
because Horseman will not be affected by anything you do with the Conquistador. Making the Conquistador (a Knight-class unit which Horseman-Class units upgrade to) available at Horseback Riding (which allows Horseman-Class units to be trained) is bound to cause odd-seeming behaviors in some way or another.

If you want the Conquistador to be considered a Horseman-Class unit, then you need to change its Unit-Class along with its PreReqtech, and you need to alter the <Civilization_UnitClassOverrides> for Spain to account for this alteration of the Conquistador from a Knight to a Horseman.
 
I've already changed the Unit-Class and PrereqTech, along with ObsoleteTech and GoodyUpgrade. What I meant by my earlier post was that *even though I don't have Chivalry researched yet*, I can upgrade a basic horseman to Conquistador, which tells me that Conquistador is a now a horseman class, but there's a step I'm missing here. I'll browse the files for the UnitClassOverrides you mention.
 
I can upgrade a basic horseman to Conquistador, which tells me that Conquistador is a now a horseman class, but there's a step I'm missing here.
This is what you're missing: the fact the Horseman can upgrade to a Conquistador doesn't tell you the latter is the same class as the former.

Search for this subtable:
Code:
<Table name="Unit_ClassUpgrades">
	<Column name="UnitType" type="text" reference="Units(Type)"/>
	<Column name="UnitClassType" type="text" reference="UnitClasses(Type)"/>
</Table>

This is where it is defined which unit upgrades to which, meaning that if A can upgrade to B, they AREN'T of the same class (since it references an UnitClass as the new unit).
 
@bane Odd behavior. I didn't have Chivalry researched, so I should not have been able to upgrade if it's class was still set to Knight. Yet, it wasn't set to Horseman, since I was building default horsemen. In any case, the override that Lee suggested did the trick, but there's an issue. I have the 'Cost' set to 100, which I assumed was the hammer cost. However, in-game, the cost is more expensive, I think at 180 or something ridiculous. Here's the code I have so far;

Spoiler :
Code:
	<Civilization_UnitClassOverrides>

		<Delete CivilizationType="CIVILIZATION_SPAIN"/>

		<Replace>
			<CivilizationType>CIVILIZATION_SPAIN</CivilizationType>
			<UnitClassType>UNITCLASS_MUSKETMAN</UnitClassType>
			<UnitType>UNIT_SPANISH_TERCIO</UnitType>
		</Replace>

		<Replace>
			<CivilizationType>CIVILIZATION_SPAIN</CivilizationType>
			<UnitClassType>UNITCLASS_HORSEMAN</UnitClassType>
			<UnitType>UNIT_SPANISH_CONQUISTADOR</UnitType>
		</Replace>
		
	</Civilization_UnitClassOverrides>

	
	<Units>

		<Update>
			<Where Type="UNIT_SPANISH_CONQUISTADOR"/>
			<Set Class="UNITCLASS_HORSEMAN" PrereqTech="TECH_HORSEBACK_RIDING" Combat="12" Cost="100" FaithCost="200" Found="True" ObsoleteTech="TECH_CHIVALRY" GoodyHutUpgradeUnitClass="UNITCLASS_KNIGHT"/>
		</Update>
		
	</Units>
 
Yes but to my knowledge, the default 'Cost' is set to Normal, so 70 cost should mean 70 hammers on normal speed, which is the speed I playtested on.
 
Oh I think I know what's going on. I set the Conquistador to <Found>true, so that I could settle them anywhere on the map instead of only on foreign lands. The 106 hammer cost of settlers is getting added to whatever cost I set the Conquistador to, which is super interesting. I wonder what's going on with that.

Edit - Yeah I didn't explain fully lol, sorry bane.
 
Yeah odd behavior indeed. So I was correct about the +106 production for having the Found attribute. I thought perhaps 100 hammers was a reasonable price, and so set the cost at -6. This worked, but the production cost disappeared in the city menu for the unit. It seems that if the value is 106 or less, the production cost disappears, which I don't like.

Another oddity is the gold cost. Settlers are set to 106 hammers with a gold cost of 500. This Conquistador is set to 110 hammers (with cost at 4), but only costs 430 gold. Since I'm new at modding units, I'm at a loss as to how to fix these two issues.

1. Modding gold cost separately from hammer cost.
2. Either;
A) Modding hammer cost to show up somehow, even if its 106 or below.
B) Adding a layer of text to the cost window set to what I set the production to (overriding option A)

Any advice?
 
Gold cost is a direct function of hammer cost UNLESS the unit has Found=true when a completely separate additional cost is added.

The additional cost is a function of the game starting era, the number of free buildings received by a city for that era, the starting population for a city in that era, and a few other factors.

If you want the full formula look in CvPlayer:: getNewCityProductionValue()

Whatever fudge-factor you work out will break for a different start era and game speed.

Firaxis only intended civilian settlers to be able to found cities ... "the most modable civ yet!"
 
Well dang. I couldn't feel comfortable playing or releasing a mod where a 4 movement, extra sight settler costs less gold to buy than a standard settler. If you two aren't confident in a work-around, I might have to just give the unit back it's FoundAbroad trait, and remove the generalized Found trait.
 
Well dang. I couldn't feel comfortable playing or releasing a mod where a 4 movement, extra sight settler costs less gold to buy than a standard settler. If you two aren't confident in a work-around, I might have to just give the unit back it's FoundAbroad trait, and remove the generalized Found trait.
There's even more fun to be had because in the hands of an AI player, they will never use a combat unit to found a city, whether you use "Found" or "FoundAbroad". It's the same issue with AI Samauri never make fishing boats, etc.
 
Top Bottom