Need help with making HCNativeWarriors affect changed resource value

I was trying to make a mod that changes Saxon Cuirassier’s cost from wood to gold:
Saxon Cuirassier Gold Cost for Prince-Electors
It swaps the wood cost with gold once you pick Wettin as an ally after sending Prince Electors, but other cards and techs like “HCNativeWarriorsGerman” that reduce the cost of natives, won’t affect the new gold cost and only reduce the food cost. The mod file looks like this, where I also tried adding a specific modifier for the Saxon Cuirrasier but it doesn’t do anything to the cost despite showing up in the cards tool tip:

Any help would be appreciated!

<techtreemods>
  <tech name="DEGermanAlliesWettin" type="Normal">
    <effects>
      <effect type="Data" amount="0.00" subtype="Cost" resource="Wood" relativity="Assign">
        <target type="ProtoUnit">deNatSaxonCuirassier</target>
      </effect>
      <effect type="Data" amount="150.00" subtype="Cost" resource="Gold" relativity="Assign">
        <target type="ProtoUnit">deNatSaxonCuirassier</target>
      </effect>
    </effects>
  </tech>
  <tech name="HCNativeWarriorsGerman" type="Normal">
    <effects>
      <effect type="Data" amount="0.75" subtype="Cost" resource="Gold" relativity="BasePercent">
        <target type="ProtoUnit">deNatSaxonCuirassier</target>
      </effect>
    </effects>
  </tech>
</techtreemods>

HCNativeWarriorsGerman will affect them, so you don’t need to change that tech at all. However, the order you send the cards matters a lot. If you send the discount card before the cost switch it will apply the discount to the 0 coin cost and then when you switch the cost it’ll add the full coin cost to the unit. What you have now will actually double discount them if you send it after and still do nothing if sent before.

The easiest fix is to add some code like this to “DEGermanAlliesWettin”:

<effect type="Data" amount="0.75" subtype="Cost" resource="Gold" reqtech="HCNativeWarriorsGerman" relativity="BasePercent">
	<target type="ProtoUnit">deNatSaxonCuirassier</target>
</effect>

So if the discount card has already been sent it’ll retroactively add the discount.

If you want to be thorough, you’ll need an effect like this for every potential coin discount tech that could be sent before. For example, the native techs like Ad Mapu or Philhellenism

<effect type="Data" amount="0.90" subtype="Cost" resource="Gold" reqtech="NatXPMapucheAdMapu" relativity="BasePercent">
	<target type="ProtoUnit">deNatSaxonCuirassier</target>
</effect>
<effect type="Data" amount="0.90" subtype="Cost" resource="Gold" reqtech="DENatWittelsbachPhilhellenism" relativity="BasePercent">
	<target type="ProtoUnit">deNatSaxonCuirassier</target>
</effect>

Also note that there are two Saxon Cuirassier units so you might also have to do all this for deNatMercSaxonCuirassier as well.

1 Like

Thanks for helping out M00Z1LLA!
The gold cost is still unaffected with this, when I added the other version “deNatMercSaxonCuirassier” it wouldn’t even change the cost to gold and leave it at wood cost, so I added mergeMode=‘add’ to the lines and the cost changes to gold again, but again when sending “HCNativeWarriorsGerman”, the gold cost stays the same regardless of the order of the sent cards.

<techtreemods>
  <tech name="DEGermanAlliesWettin" type="Normal">
    <effects>
      <effect mergeMode='add' type="Data" amount="0.00" subtype="Cost" resource="Wood" relativity="Assign">
        <target type="ProtoUnit">deNatSaxonCuirassier</target>
      </effect>
      <effect mergeMode='add' type="Data" amount="150.00" subtype="Cost" resource="Gold" relativity="Assign">
        <target type="ProtoUnit">deNatSaxonCuirassier</target>
      </effect>
	  <effect mergeMode='add' type="Data" amount="0.75" subtype="Cost" resource="Gold" reqtech="HCNativeWarriorsGerman" relativity="BasePercent">
		<target type="ProtoUnit">deNatSaxonCuirassier</target>
	  </effect>
	  <effect mergeMode='add' type="Data" amount="0.00" subtype="Cost" resource="Wood" relativity="Assign">
        <target type="ProtoUnit">deNatMercSaxonCuirassier</target>
      </effect>
      <effect mergeMode='add' type="Data" amount="150.00" subtype="Cost" resource="Gold" relativity="Assign">
        <target type="ProtoUnit">deNatMercSaxonCuirassier</target>
      </effect>
	  <effect mergeMode='add' type="Data" amount="0.75" subtype="Cost" resource="Gold" reqtech="HCNativeWarriorsGerman" relativity="BasePercent">
		<target type="ProtoUnit">deNatMercSaxonCuirassier</target>
	  </effect>
    </effects>
  </tech>
</techtreemods>

Not sure what’s going on then. HCNativeWarriorsGerman discounts the coin cost of AbstractNativeWarrior so if you’ve successfully added the coin cost and then send it should work. Maybe using ‘override’ instead of assign to get the coin cost could help. Or just use mergeMode=‘replace’ on the whole tech because sometimes the additive modding stuff is just too jankey.

1 Like

The game is just weird some times, I’ll have another look in the weekend

I doubt any method will work, since this problem also occurs with Leather Soldiers shipment for Mexico, which swaps the gold to wood cost. With the team upgrade Mustangs from Lakota after doing the resource swap, doesn’t discount the wood cost.

I found a fix but it requires to load custom triggers into the map script, however won’t work if the map is a scenario. Since your mod is already non multiplayer, 99% of random map loads a redundant script that been replaced by map specific techs. Make another file that replaces the mercenaries.xs, mod/game/randmaps/mercenaries.xs and add the code in the text file.

I only made the effects for the Native Warrior Card and Wittelsbach tech, but there is plenty. Also it’s like this because there no trigger effect that formulate to x = y * z (which can be used to calculate base percent) , only x = x * z (which only calculate percent), if that was the case, it can easily be done with the rm trigger commands.

mercenaries.txt (3.5 KB)

1 Like

I think I figured out the problem and there are a couple of ways to fix it.

Your issue was that “HCNativeWarriorsGerman” works off ‘basepercent’ but ‘assign’ only changes the current value. So it was applying a discount to the original zero cost which obviously does nothing.

The simplest fix is to use ‘override’ instead of ‘assign’ when setting the coin cost as that should change both the current and original cost.

The other way is to change any of the techs that give a discount (and shadowtechs applied after) from ‘basepercent’ to ‘percent’ (which uses current cost). Though this may slightly change how they work if you apply multiple discounts in different orders.

1 Like

The fix is possible, the devs were just really sloppy in how they implemented the cost switching cards and didn’t add any provision for “HCXPMustangs” for any cost switching tech. Aztec Mining, Leather Soldiers, Landed Gentry, Zinder Kanuris, etc all don’t work with it.

1 Like

Well, that did the trick, it works now. Thanks a lot for helping out! And for the lesson (since I’m really not good at modding, I just change some values around usually, but it’s nice to learn new tricks). It looks like this now, short and clean:

<techtreemods>
  <tech name="DEGermanAlliesWettin" type="Normal">
    <effects>
      <effect mergeMode='add' type="Data" amount="0.00" subtype="Cost" resource="Wood" relativity="Assign">
        <target type="ProtoUnit">deNatSaxonCuirassier</target>
      </effect>
      <effect mergeMode='add' type="Data" amount="150.00" subtype="Cost" resource="Gold" relativity="Override">
        <target type="ProtoUnit">deNatSaxonCuirassier</target>
      </effect>
	  <effect mergeMode='add' type="Data" amount="0.00" subtype="Cost" resource="Wood" relativity="Assign">
        <target type="ProtoUnit">deNatMercSaxonCuirassier</target>
      </effect>
      <effect mergeMode='add' type="Data" amount="150.00" subtype="Cost" resource="Gold" relativity="Override">
        <target type="ProtoUnit">deNatMercSaxonCuirassier</target>
      </effect>
    </effects>
  </tech>
</techtreemods>

The game has this jank problem in general though, they change things in one place making other break in the process because the way some features were implemented was sloppy to begin with.