New magic shards

How to create new magic shards?

I am curious how you make new magic shards to use with new spell books. The XML files I modified are as follows:

 

CoreResources

CoreShards

 

I've made several random maps and I cannot get my custom shard type to spawn on the map. Are there any other XML files that I need to modify?

21,471 views 21 replies
Reply #1 Top

Can you post an example of the xml of one of the shards you tried to add?

Reply #2 Top

The variants you find in CoreShards.xml are hardcoded, as are the global shard power bonuses.

There should be no problem adding "faux" shards as world resources though. A custom shard power wouldn't be able to boost spells directly, but there is a work-around if you are interested in a bit of tweaking.

 

Reply #3 Top

Here is the code I used in the resource xml:

 

Code: xml
  1. <!-- ***************** -->
  2. <!-- ** Nature Magic ** -->
  3. <!-- ***************** -->
  4. <ResourceType InternalName="NatureMagicType01">
  5. <DisplayName>Nature Magic</DisplayName>
  6. <Type>NatureMagic</Type>
  7. <IconColor>0,0,0</IconColor>
  8. <Icon>Gfx//Icons//Crushing_Stat_Icon.png</Icon>
  9. <ClothIcon>gfx\\TacticalIcons\\MetalOre_1.png</ClothIcon>
  10. <HideInHiergamenon>1</HideInHiergamenon>
  11. <ModelColor>0,0,0</ModelColor>
  12. <Worth>5</Worth>
  13. <Global>1</Global>
  14. <Rarity>0.0</Rarity>
  15. <Shared>0</Shared>
  16. <TradedByCaravans>1</TradedByCaravans>
  17. <Medallions InternalName="Ration_Res_Medallions">
  18. <All>AirCrystal_Medallion.png</All>
  19. </Medallions>
  20. </ResourceType>
  21. <ResourceType InternalName="NatureMana">
  22. <DisplayName>Nature Shard</DisplayName>
  23. <Type>NatureMana</Type>
  24. <IconColor>0,0,0</IconColor>
  25. <Icon>Icon_Nature.png</Icon>
  26. <HideInHiergamenon>1</HideInHiergamenon>
  27. <ShownInGlobalDisplay>1</ShownInGlobalDisplay>
  28. <Global>1</Global>
  29. <Stored>0</Stored>
  30. <Shared>0</Shared>
  31. <TradedByCaravans>0</TradedByCaravans>
  32. <RummagedPerTurn>0.01</RummagedPerTurn>
  33. <!-- AI Info -->
  34. <AIData AIPersonality="AI_General">
  35. <AITag>Shard</AITag>
  36. </AIData>
  37. </ResourceType>

 

I want to create nature shards that spawn during map creation just like other shards. I would like for those to be harvested just like other shards. Finally, I want to create a nature spell line that uses the shards to determine power, like the other spell books. I am not sure where to go from here since the shard file is off limits. 

Should I be making a goodie hut with a similar spawn chance as the shards? Will I be able to tie my spells to these faux shards?

 

Thanks!

 

Reply #4 Top

Yes, but the xml is not going to work exactly the same as normal shard powers because those are hardcoded. The functionality will be the same in-game.

 

First you need a continuous resource. A continuous resource functions like food did in E:wom - world resources produce X each turn, no stockpile is gathered. If you have one, it will say that you have 1 all the time.

   <ResourceType InternalName="rivermod_magmatype_spellres">
        <DisplayName>Magma Forge</DisplayName>
        <Type>MagmaForge</Type>
        <IconColor>0,0,0</IconColor>
        <Icon>Stat_AttackFire_Icon.png</Icon>
        <ClothIcon>gfx\\TacticalIcons\\MetalOre_1.png</ClothIcon>
        <ModelColor>0,0,0</ModelColor>
        <Worth>5</Worth>
        <Global>1</Global>
        <Rarity>0.0</Rarity>
        <Stored>0</Stored>
        <TradedByCaravans>0</TradedByCaravans>
        <ShownInGlobalDisplay>1</ShownInGlobalDisplay>
        <Medallions InternalName="Ration_Res_Medallions">
            <All>Res_Ores_Plains.png</All>
        </Medallions>
</ResourceType>

then you need a world resource

    <ResourceType InternalName="Resource_IronOre">
        <DisplayName>Iron Ore</DisplayName>
        <Type>IronOre</Type>
        <Description>Build a Mine here to produce Metal.</Description>
        <LongDescription>The ground here has been ripped asunder by the cataclysm; rubble is strewn everywhere, some of it rock shot through with veins of reddish and purple stone. This is iron ore in its raw form.  Build a mine here, and extract it to forge powerful weaopns and armor. </LongDescription>
        <BarredTerrain>River</BarredTerrain>
        <BarredTerrain>HillsTerrain</BarredTerrain>
        <PreferredTerrain>Category:Land</PreferredTerrain>
        <MinPerPlayer>3</MinPerPlayer>
        <Rarity>400</Rarity>
        <NeedsToBeUnlocked>0</NeedsToBeUnlocked>
        <HarvestType>Mining</HarvestType>
        <Production>1</Production>
        <Worth>5</Worth>
        <Global>0</Global>
        <Stored>0</Stored>
        <RummagedPerTurn>0.75</RummagedPerTurn>
        <OnSelectSFX>Click_Iron_Mine</OnSelectSFX>
        <GameModifier>
            <ModType>Resource</ModType>
            <Attribute>TileYieldMaterials</Attribute>
            <Value>5</Value>
            <PerTurn>1</PerTurn>
        </GameModifier>
        <AIData AIPersonality="AI_General">
            <AIPriority>3</AIPriority>
        </AIData>
        <Medallions InternalName="">
            <All>Res_Ores_Plains.png</All>
        </Medallions>
        <Icon>Resource_IronOre.png</Icon>
        <IconColor>0,0,0</IconColor>
        <ClothIcon>Resource_IronOre.png</ClothIcon>
        <TileDesign>R_Iron_Ore_01</TileDesign>
        <TileDesignForTerrain>DesertTerrain:R_Lombard_Iron_01</TileDesignForTerrain>
        <TileDesignForTerrain>Imperium:R_Iron_oar_Imperium_01</TileDesignForTerrain>
        <TileDesignForTerrain>Scrapyard:R_Scrapyard_Iron_01</TileDesignForTerrain>
        <ModelColor>0,0,0</ModelColor>
    </ResourceType>

then you need an improvement on the resource. Note below how the <SupportedResourceType>IronOre</SupportedResourceType> in the improvement matches the <Type>IronOre</Type> in the Resourcetype just above this one. Also note that the resource being created (<Attribute>MagmaForge</Attribute>) has to match the <Type>MagmaForge</Type> from the resource definition (the first Resourcetype at the beginning of the post).

    <ImprovementType InternalName="IronMine">
        <DisplayName>Iron Mine</DisplayName>
        <Description>Iron Mines can be built on Iron Ore to produce 1 Metal.</Description>
        <IgnoreDuplicateImpLimit>1</IgnoreDuplicateImpLimit>
        <RequiresResource>1</RequiresResource>
        <SupportedResourceType>IronOre</SupportedResourceType>
        <PreferredTerrain>Category:Land</PreferredTerrain>
        <GameModifier>
            <ModType>ConstructionResourceCost</ModType>
            <Attribute>Gold</Attribute>
            <Value>-10</Value>
        </GameModifier>
        <LaborToBuild>100</LaborToBuild>
        <GameModifier>
            <ModType>Resource</ModType>
            <Attribute>MagmaForge</Attribute>
            <Value>1</Value>
            <PerTurn>1</PerTurn>
            <Provides>+1 Metal</Provides>
        </GameModifier>
        <AIData AIPersonality="AI_General">
            <AIPriority>5</AIPriority>
            <AITag>Mining</AITag>
        </AIData>
        <ArtDef>Art_IronMine</ArtDef>
    </ImprovementType>

 

Now for the final trickery - we also need to be able to use nature shard powers like normal shard powers. That's not possible, so we need to make a work-around.

First, we create a new unitstat. It is going to be default to 1. That means everyone is always going to be walking around with 1 in this (unless you control nature shards - more on that after the unitstat).

  <UnitStatType InternalName="UnitStat_AvalonCalling">
    <DisplayName>ISMdfasasdfOUNTED</DisplayName>
    <DisplayNameShort>DGE</DisplayNameShort>
    <Description>The chance to dodge an attack in battle.</Description>
    <Icon>Stat_Dodge_Icon.png</Icon>
    <Hidden>1</Hidden>
        <UnitStatGrouping>CombatStat</UnitStatGrouping>
        <UnitStatGrouping>UnitDetailsCombatStat</UnitStatGrouping>
    <DefaultValue>1.0</DefaultValue>
  </UnitStatType>

Then, we need to create a way to globally buff this unitstat for all your controlled units. Enabling global buffing of unitstats requires its own xml. Note how the internalname mirrors the internalname of the UnitStatType but with an added "A_", essentially "A_*".

      <PlayerAbilityType InternalName="A_UnitStat_AvalonCalling">
        <DisplayName>Unit Hit Point Bonus</DisplayName>
        <Description>Provides a bonus to the hit points of all units.</Description>
    <Icon>Kingdom_Crest_02.png</Icon>
</PlayerAbilityType>

 

Now we go back to the improvement above and add the following:

      <GameModifier>
        <ModType>Player</ModType>
        <Attribute>AbilityBonus</Attribute>
        <StrVal>A_UnitStat_AvalonCalling</StrVal>
        <Value>100</Value>
      </GameModifier>

The end result is that all units start with 1 in your unitstat. But for each improvement controlled, that value is increased by 100%. If you control 2, it is increased by 200%. So a unit with 5 controlled improvements will have 6 in the unitstat. Then you can use that unitstat for all calculations in spells.

As you have probably figured out by now, the continuous resource we introduced above is actually not used for anything except to give a visual count of how many of that shard is controlled.

 

 PS. You'll need to change a bunch of stuff not to conflict with vanilla game (or my mods), obviously.

PS 2. Since the world resource is not technically a true shard, Corruption spell and Consume spell will not work on them.

Reply #5 Top

Brilliant. I imagine it took quite a while to figure this out. I appreciate all your help. :)

 

I will update you with my results!

Reply #6 Top

I wrestled with this for many hours until I finally broke down and moved it from my mod directory to the game Data\English directory. Just a note for anyone else who attempts to do this in the future, this will not work in the mod directory!

Reply #7 Top

Good to note! Did you perchance get it working correctly with random spawns in game?

Reply #8 Top

Quoting MidnightsFX, reply 8
Good to note! Did you perchance get it working correctly with random spawns in game?

 

Absolutely. For testing I set the spawn chance high, then once I was satisfied it worked correctly, I reduced the spawn chance to be the same as shards. 

They work exactly like regular shards with the only exception being that the indicator for the number of shards you control appears in the upper left instead of the upper right and I had to do the calculations on some spells slightly different.

 

 

Reply #9 Top

Interesting, sounds like it worked out pretty good. Can you not get the indicator to change sides in the UI?

Reply #10 Top

Shards are hardcoded and any resources you make are treated like regular resources. I've thought about redoing the existing shards so that everything appears on one side of the screen. The only thing stopping me is a design decision.

 

I am going to use one of two schemes for magic:

Life

Death

Air

Earth

Water

Fire

Astral

Blood

Nature

(Basically like Dominions 3)

 

Or I am going to use this system:

Life

Death

Chaos

Sorcery

Nature

(A combination of "Magic the Gathering" and "Master of Magic".

 

If I go with the former, I don't know that I want to fool with changing the existing shards just for a very simple visual change, If I go with the latter, I will probably end up changing them. 

Reply #11 Top

Interesting, my question- which might be very obvious but, perhaps I have just not seem addressed. Is, can you just add a resource slot on the opposite side, for a specific type, say your shards. Which fits next to, but not exactly in-line with the other shards? Maybe that requires a lot of work, I have not looked at how the UI is handled in this.

Secondly, as a response to your debate about changing the shards I would say this, if it were me I would take the harder route. If nothing else, I will gain a little knowledge about how the shards are implemented and maybe I could mimic their mechanics in spells easier or whatnot. But, to add to that, probably just work on a single one extra shard type at first, because sometimes the bumps down the road when adding something that big are going to be pretty brutal.

Reply #12 Top

Quoting MidnightsFX, reply 12
Interesting, my question- which might be very obvious but, perhaps I have just not seem addressed. Is, can you just add a resource slot on the opposite side, for a specific type, say your shards. Which fits next to, but not exactly in-line with the other shards? Maybe that requires a lot of work, I have not looked at how the UI is handled in this.

Secondly, as a response to your debate about changing the shards I would say this, if it were me I would take the harder route. If nothing else, I will gain a little knowledge about how the shards are implemented and maybe I could mimic their mechanics in spells easier or whatnot. But, to add to that, probably just work on a single one extra shard type at first, because sometimes the bumps down the road when adding something that big are going to be pretty brutal.

 

Well, I've done that with heavenfall's help. I made nature shards that function exactly like regular shards, with the UI difference. You cannot add shards that are 100% identical to the existing ones because it is hard coded at the moment. But you can mimic them so closely that the UI difference is the only issue. So with that being said, you could take the "hard route" and redo all the shards, eliminating the original ones, and making them look uniform in the UI.

 

There may be a way to modify the UI and do what you are asking, but that is beyond me. Even if you do it the way I am currently doing it, it is barely noticeable. I intend to make it look nice eventually, but I don't want to devote that much time to a visual change this early in modding when I have races, factions, classes, tech trees, spells, etc to worry about and limited time at the moment to mod.

This evening if I get a chance, I will post a screenshot of what it looks like doing it the way I am doing it now.

Reply #13 Top

From what it sounds like if the difference is so minimal I would say to carry on then! I am sure if nothing else by the time of release that someone will figure out how to modify the UI. Applying this to your shards would hopefully be simple! But until then, how about work on the code behind the shards and get your magic system up and running?

Reply #14 Top

This is what it does with the shards, not really that big of a deal at all:

Reply #15 Top


Does Corruption work on your shards?

Reply #16 Top

Quoting seanw3, reply 16

Does Corruption work on your shards?

 

Not inherently, but there may be a way to modify the existing spell and give it an extra effect or create a new spell that does. I plan to throw the spell out anyway so not a biggy for me, but it may be important to people who plan to keep things pretty vanilla.

Reply #17 Top

Didn't check if it works, but kinda surprised it doesn't.

From some expressions in the game-

             <Expression><![CDATA[[TileYieldEssence]]]></Expression>

<Expression><![CDATA[[UnitStat_Tactical_Auto_Defense_Boost]]]></Expression>

 <Expression><![CDATA[[UnitOwner_GetNumLifeShards] + 3]]></Expression>

I'd assume you could take the amount of resources you have as a base for these expressions.

I'll try to see if it's possible to do the work around in an easier way, and report my findings.

Reply #18 Top

Tried but couldn't find an expression that returns anything, such gold or mana. I almost suspect they didn't make such an expression...

Reply #19 Top

Quoting Raledon, reply 19
Tried but couldn't find an expression that returns anything, such gold or mana. I almost suspect they didn't make such an expression...

 

You have to create a hidden unit stat that changes according to the amount of the resource you have. Then that stat can be used in calculations.

I'll post some example code this evening.

Reply #20 Top

For mana you can specifically use <Expression><![CDATA[[UnitOwner_GetMana]]]></Expression> (see manablast). However, there is no way to access new resources dynamically.

UnitOwner_GetNumAllShards...UnitOwner_GetNumDeathShards.UnitOwner_GetNumLifeShards..UnitOwner_GetNumWaterShards.UnitOwner_GetNumFireShards..UnitOwner_GetNumEarthShards.UnitOwner_GetNumAirShards...UnitOwner_GetMana...Unit_GetTroopCount..Unit_GetLevel...Unit_GetCurrentDamage...Unit_GetHPCurrent

hardcoded in the .exe

Reply #21 Top

Here is an example of a spell using a custom shard, notice I used a hidden unit stat in the calculation (Per Heavenfall's instruction in the beginning of the thread).

 

I tried to bold and resize it for you, but the code tags doesn't like it. Look at the part that is blocked with a text style change, that is the relevant part...

Code: xml
  1. &lt;SpellDef InternalName="Regeneration"&gt;
  2. &lt;DisplayName&gt;Regeneration&lt;/DisplayName&gt;
  3. &lt;Description&gt;Regenerates target unit&#39;s health by +2 per turn (+2 per nature shard).&lt;/Description&gt;
  4. &lt;Image&gt;S_Regeneration_Painting.png&lt;/Image&gt;
  5. &lt;IconFG&gt;S_Regeneration_Icon.png&lt;/IconFG&gt;
  6. &lt;IconBG&gt;S_Regeneration_Icon_BG.png&lt;/IconBG&gt;
  7. &lt;IconColor&gt;156,255,59&lt;/IconColor&gt;
  8. &lt;AutoUnlock&gt;1&lt;/AutoUnlock&gt;
  9. &lt;CanStack&gt;0&lt;/CanStack&gt;
  10. &lt;SpellBookSortCategory&gt;Unit&lt;/SpellBookSortCategory&gt;
  11. &lt;SpellBookSortSubCategory&gt;UnitEnchantment&lt;/SpellBookSortSubCategory&gt;
  12. &lt;SpellType&gt;Tactical&lt;/SpellType&gt;
  13. &lt;SpellClass&gt;Defensive&lt;/SpellClass&gt;
  14. &lt;SpellSubClass&gt;Buff&lt;/SpellSubClass&gt;
  15. &lt;SpellTargetType&gt;FriendlyUnit&lt;/SpellTargetType&gt;
  16. &lt;PreventStackingWith&gt;MassRegeneration&lt;/PreventStackingWith&gt;
  17. &lt;Prereq&gt;
  18. &lt;Type&gt;AbilityBonusOption&lt;/Type&gt;
  19. &lt;Attribute&gt;Nature1&lt;/Attribute&gt;
  20. &lt;/Prereq&gt;
  21. &lt;SpellResourceCost&gt;
  22. &lt;Resource&gt;Mana&lt;/Resource&gt;
  23. &lt;Amount&gt;10&lt;/Amount&gt;
  24. &lt;/SpellResourceCost&gt;
  25. &lt;GameModifier&gt;
  26. &lt;ModType&gt;Unit&lt;/ModType&gt;
  27. <span style="font-size: x-small;">&lt;Attribute&gt;AdjustUnitStat&lt;/Attribute&gt;</span>
  28. <span style="font-size: x-small;"> &lt;StrVal&gt;UnitStat_TacticalHealthRegen&lt;/StrVal&gt;</span>
  29. <span style="font-size: x-small;"> &lt;Duration&gt;-1&lt;/Duration&gt;</span>
  30. <span style="font-size: x-small;"> &lt;Calculate InternalName="Calc" ValueOwner="CastingUnit"&gt;</span>
  31. <span style="font-size: x-small;"> &lt;Expression&gt;&lt;![CDATA[[UnitStat_NatureMagic] * 2]]&gt;&lt;/Expression&gt;</span>
  32. <span style="font-size: x-small;"> &lt;/Calculate&gt;</span>
  33. <span style="font-size: x-small;"> &lt;Calculate InternalName="Value"&gt;</span>
  34. <span style="font-size: x-small;"> &lt;Expression&gt;&lt;![CDATA[[Calc]]]&gt;&lt;/Expression&gt;</span>
  35. <span style="font-size: x-small;"> &lt;/Calculate&gt;</span>
  36. &lt;/GameModifier&gt;
  37. &lt;AIData AIPersonality="AI_General"&gt;
  38. &lt;AIPriority&gt;15&lt;/AIPriority&gt;
  39. &lt;/AIData&gt;
  40. &lt;HitSoundFX&gt;Spell_Regeneration_01&lt;/HitSoundFX&gt;
  41. &lt;SpellDefEffect&gt;
  42. &lt;EffectName&gt;S_Regeneration_Particle&lt;/EffectName&gt;
  43. &lt;LocalPosition&gt;0,0,0&lt;/LocalPosition&gt;
  44. &lt;EffectScale&gt;.75&lt;/EffectScale&gt;
  45. &lt;EffectDelay&gt;0&lt;/EffectDelay&gt;
  46. &lt;SnapToTerrain&gt;1&lt;/SnapToTerrain&gt;
  47. &lt;/SpellDefEffect&gt;
  48. &lt;/SpellDef&gt;