Has anyone gotten a Calculate to work with a custom resource type?

    I've added a custom resource in one my experiments: UnholyMana. I can get it in the game and show it in the resource bar (and collect it), but I can't seem to get it to pick up from a <Calculate/> element. I've tried setting ValueOwner="Player" and a half dozen other things. Has anyone else had any luck with this one?

EDIT: Clarification on what I'm trying to do

    In this specific case, I've added a new Resource to the game: UnholyMana. It's global, not shared, not stored, and visible in the resource strip at the top. I gave my sovereign the ability to provide +1 (per turn, since it's not stored). It displays 1 unit in the resource strip (as expected). The InternalName and "Type" of the resource are both "UnholyMana" (mimicking other resources).

    The goal is to allow the UnholyMana resource to provide a damage bonus to specific spells (much like shards). An example for how I expected this to go looks like this:

----- Note: This doesn't actually work. -----

Code: xml
  1. &lt;GameModifier&gt;
  2.   &lt;ModType&gt;Unit&lt;/ModType&gt;
  3.   &lt;Attribute&gt;CurHealth&lt;/Attribute&gt;
  4.   &lt;Calculate InternalName="EffectStrength" ValueOwner="Player"&gt;
  5.    &lt;Expression&gt;&lt;![CDATA[[UnholyMana] * -5.0]]&gt;&lt;/Expression&gt;
  6.   &lt;/Calculate&gt;
  7.   &lt;Calculate InternalName="Value"&gt;
  8.    &lt;Expression&gt;&lt;![CDATA[[EffectStrength]]]&gt;&lt;/Expression&gt;
  9.   &lt;/Calculate&gt;
  10. &lt;/GameModifier&gt;

----- Note: This doesn't actually work -----

Honestly, I thought it would be a slam-dunk, but it doesn't work. I've tried lots of variations with ValueOwner={Player, PlayerSovereign, CastingUnit, Player_1} and a bunch of other things I saw other places in the XML (even comments). I've tried changing the variable name as well to things like { Resource_UnholyMana, NumShards_UnholyMana, UnitStat_UnholyMana } and more.

It seems like the resource value would be available to you more easily - I've actually done this succesfully with custom unit stats, but I can't seem to make it work with resources.

Any help would be appreciated,
Gnilbert

10,327 views 7 replies
Reply #1 Top

I've mailed the devs about this regarding applying the <calculate> command to traits and abilities and apparently the game doesn't support this function yet but adding this function is something on their "To-Do" list. Right now <calculate> can only be applied to items and spells, temporary values.

Believe me, I've tried almost everything to get them to work for attributes.

Reply #2 Top

I realized I'd better provide more of an explanation of my issue. The OP is updated.
Gnilbert

Reply #3 Top

Just bouncing thoughts here but it seems Gnilbert has made a new "item" in game, along the lines of "Gold" or "Mana". Seeing as how Gold can be Calculated, what might cause a "new item" not to be seen as such?

Perhaps a List of useable "items" is hardcoded?

Reply #4 Top

I think he's trying to copy the effect of internal values like NumIceShards and so on.

Reply #5 Top

Well, I'm almost embarassed to post this, but I found a ... creative ... way to get around the issue. I'll do a better tutorial when I'm back from DragonCon, but for now: The steps go something like this:

1. Create the new ResourceType (UnholyMana): Global=1, Worth=5, Stored=0, Shared=0, ShownInGlobalDisplay=0
2. Create a new UnitStat (UnitStat_UnholyMana): DefaultValue = 1
3. Create a new PlayerAbilityType (A_UnitStat_UnholyMana): UsedAsMultiplier=1

Now, anywhere you do the standard "Add resource production" bit, add the following as well:

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

Then the whole thing works like this: Every unit starts the game with UnitStat_UnholyMana=1, which you can reference handily in the Calculate tags (though you'd really need to use UnitStat_UnholyMana - 1 for the actual value). The game automagically uses the A_UnitStat_UnholyMana player ability as a % modifier to the UnitStat_UnholyMana ability (because of the naming). When you add X to the player ability, it adds X% to the multiplier - in this case, 100%, so all units' UnitStat_UnholyMana values become 2. Adding another 100 to the ability increases all units' stat to 3, etc. It's a bit of a hack, but it'll work.

Gnilbert

+1 Loading…
Reply #6 Top

That is dirty. Well done.

Reply #7 Top

Quoting Gnilbert, reply 5
Well, I'm almost embarassed to post this, but I found a ... creative ... way to get around the issue. I'll do a better tutorial when I'm back from DragonCon, but for now: The steps go something like this:

1. Create the new ResourceType (UnholyMana): Global=1, Worth=5, Stored=0, Shared=0, ShownInGlobalDisplay=0
2. Create a new UnitStat (UnitStat_UnholyMana): DefaultValue = 1
3. Create a new PlayerAbilityType (A_UnitStat_UnholyMana): UsedAsMultiplier=1

Now, anywhere you do the standard "Add resource production" bit, add the following as well:

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

Then the whole thing works like this: Every unit starts the game with UnitStat_UnholyMana=1, which you can reference handily in the Calculate tags (though you'd really need to use UnitStat_UnholyMana - 1 for the actual value). The game automagically uses the A_UnitStat_UnholyMana player ability as a % modifier to the UnitStat_UnholyMana ability (because of the naming). When you add X to the player ability, it adds X% to the multiplier - in this case, 100%, so all units' UnitStat_UnholyMana values become 2. Adding another 100 to the ability increases all units' stat to 3, etc. It's a bit of a hack, but it'll work.

Gnilbert

I think you can correct the automagically % modifer by using <Operator>+</Operator> just above <Value>. So your value would only need to be 1 then instead of 100.  Same effect, just easier to keep track of what is going on with out having to remember that automagical % thingy. Maybe that would work in your spell as well. Maybe not, but would be worth looking into.