View Single Post
Mathias
Senior Member
Lone Wolf Staff
 
Join Date: May 2005
Posts: 13,213

Old February 23rd, 2009, 08:56 AM
Now, I'll discuss setting up the basic mechanics of the Cortex system within HL. They're called traits in the skeleton files I'm using as a starting point for my files, and there are entirely too many references to them for me to change the name used, so I'll have to live with the trait/Trait confusion - the end user won't see the confusion if I can help it though.

I'll use the same basic mechanics as the skeleton files, and I'll be drawing on what Rob describes in the Savage Worlds walkthrough on how to convert number-based mechanics to dice-based mechanics.

So, my stats will go from 0-8, representing d0 - d12+d4 (base value * 2). I'm also being careful not to have any elements in the code itself that restrict the top limit - the max value of 8 is a field, and can be changed from inside a script if it needs to go higher or lower. That way, if someone writes a superhero game using the Cortex rules, your strongman can have a STR of 16, and HL will display it as 2d12+d4.

Steps are very easy to handle with the attributes as dice - adding +1 automatically becomes adding +1 steps. I'll re-name the various macros within HL to reflect the game's naming conventions, though. For example, the #trtinplay[] defined in the skeleton files will be renamed #steps[].

Handling dice additions is more complex, though. I'm going to need to record an arbitrary number of each type of die - that's what an array is for. I'll have an array, numbered from 0-6 (d0 - d12), with each number in the array representing the number of that size die.

Since this is the sort of thing that's likely to be useful to later data file designers:

Code:
 
<!-- Store a count of the dice used as an array -->
<field
id="trtArray"
name="Dice Used"
type="derived"
style="array"
arrayrows="7" > <!-- 6 dice + 0 -->
</field>
Code:
 
<!-- Calculate the trtDisplay field -->
<eval index="2" phase="Render" priority="5000" name="Calc trtDisplay">
<after name="Calc trtFinal"/><![CDATA[
~if this is a derived trait but not a rolls trait, our display text is the final value
if (tagis[component.Derived] - tagis[component.Rolls] <> 0) then
field[trtDisplay].text = field[trtFinal].value
done
endif
 
var display as string
var i as number
var dietype as number
i = 6
 
~Going from d12 - d0
while (i >= 0)
 
~If there are dice in the array
if (field[trtArray].arrayvalue[i] > 0 ) then
~add a "+" if this isn't the first things we've output
if (empty(display) = 0) then
display &= "+"
endif
~ if we're greater than 1, append the number
if (field[trtArray].arrayvalue[i] > 1) then
display &= field[trtArray].arrayvalue[i]
endif
 
~Append the value with a d in front
dietype = i * 2
display &= "d" & dietype
endif
i -= 1
loop
~put the final result into the proper field
field[trtDisplay].text = display
]]></eval>
Code:
 
<eval phase="Traits" priority="3500" name="Calc trtArray">
<after name="Calc trtFinal"/><![CDATA[
var dietype as number 
var dieremain as number
var diecount as number
 
dietype = field[trtFinal].value
~These values are not being multiplied by two before calculation
 
~diecount = the number of d12s used (so that trtFinal can go to infinity and still be handled)
diecount = round(dietype / 6, 0, -1)
diecount = maximum(diecount, 1)
 
~If our value isn't evenly divisible by 6 (if we don't have an exact multiple of d12s), add the remainder as a secon die
if (dietype >= 6) then
if (dietype % 6 <> 0) then
dieremain = dietype % 6
field[trtArray].arrayvalue[dieremain] = 1
endif
endif
 
~now that everything's calculated, bound dietype at d12
if (dietype > 6) then
dietype = 6
endif
 
~for low values, put 1 in the dietype, for high values, add the correct number of d12s
field[trtArray].arrayvalue[dietype] += diecount
 
]]></eval>
So, for the talented Unarmed/Melee d4 asset, it'll find the Unarmed and Melee skills, and add +1 to box 2 (d4) of their trtArray. When those skills are displaying themselves, they'll calculate their trtFinal value, add it to the existing trtArray, with the d4 already there, and trtDisplay will output 2d4 (the base Unarmed Skill + the Talented asset).

Last edited by Mathias; February 24th, 2009 at 02:29 PM. Reason: Copying a bugfix in my files to here
Mathias is online now   #4 Reply With Quote