Show the Derivation of Values (Savage)

From HLKitWiki
Revision as of 21:19, 12 January 2009 by Rob (Talk | contribs) (Explain How Derived Traits Are Calculated)

Jump to: navigation, search

Context: HL KitAuthoring Examples … Savage Worlds Walk-Through 

Overview

There are a number of refinements that we can make to the interface, and this is probably a good time to do it. We've got all the fundamental mechanics in place now, so we might as well start pulling everything together more solidly.

Using Bitmaps for Dice

The contents of the attribute and skill incrementers currently show the die-type and any adjustment using the format "d6+2". It would be ideal if we actually showed a bitmap for each die-type, since it would tailor things much more closely to how Savage Worlds works. Fortunately, doing this is quite easy.

The Skeleton data files include an assortment of bitmaps for the various die-types. There are bitmaps for use on the screen and within character sheet output. All of these bitmaps are automatically copied into place for your use when you create a new game system. All you need to do is reference them.

We've already centralized all of the handling for what gets displayed into a single place. The field "trtDisplay" contains the text to be output, and the procedure "FinalRoll" handles synthesizing this text. So all we need to do is modify the "FinalRoll" procedure to incorporate the bitmaps instead of using simple text.

Open the file "procedures.dat" and locate the "FinalRoll" procedure. Within this procedure, there is a line that generates the die-type for display by combining the letter "d" with the numeric value. We can easily change this to use the appropriate bitmap instead.

You can insert the bitmap into the text via the use of encoded text. The syntax for inserting a bitmap via encoded text is "{bmp filename}", where filename is the base name of the file to be inserted. Since the die-type bitmaps intended for use on screen are named in the form "d6_screen.bmp", the corresponding encoded text for a d6 should be "{bmp d6_screen}". This means that we can change one line of script code and get the die-type appearing as a bitmap. The new line of code should be the following.

finaltext = "{bmp d" & dietype & "_screen}"

After a little bit of testing, though, the results aren't quite optimal, and we should probably refine the handling a bit. For example, if there is an adjustment made to the final roll (e.g. "d6+2"), the "+2" is a bit too small now. So we'll start by increasing the font size.

The incrementers for showing die-types all use the "incrDie" style, so we'll need to modify it. Open up the file "styles_ui.aug" and locate the style. It currently uses the "fntincrsim" font resource, which is also used by another incrementer, so we can't simply change it. Instead, we need to define a new font resource, which we'll call "fntincrdie". We can define the new resource as part of the style, and we'll pick a size like 54 as a good balance that hopefully won't overshadow the die-type bitmap. This yields a revised style definition like the one below.

<style
  id="incrDie">
  <style_incrementer
    textcolor="f0f0f0"
    font="fntincrdie"
    editable="no"
    textleft="13" texttop="0" textwidth="44" textheight="20"
    fullwidth="70" fullheight="20"
    plusup="incplusup" plusdown="incplusdn" plusoff="incplusof"
    plusx="59" plusy="0"
    minusup="incminusup" minusdown="incminusdn" minusoff="incminusof"
    minusx="0" minusy="0">
    </style_incrementer>
  <resource
    id="fntincrdie">
    <font
      face="Arial"
      size="54">
      </font>
    </resource>
  </style>

If we add the Ace edge and the Boating skill, we can see what this looks like. Unfortunately, this new size is a little too prominent compared to the die-type bitmap, so we need to make it a little less white. This is achieved by modifying the "textcolor" attribute within the style and dialing down the brightness a little bit. We'll pick a value of "c0c0c0" as a good compromise.

This still doesn't look quite right. The "+" looks good, but the numeric adjustment looks a little too frail. We can change the font resource to be bold, but that results in the "+" looking blocky and ugly. What we need is for the "+" to be non-bold and the numeric value to bold. We can accomplish this by revising the procedure a little bit to carve up the bonus into two pieces. The net result is a revised procedure script that looks like below.

~declare variables that are used to communicate with our caller
var finaldie as number
var finalbonus as number
var finaltext as string

~bound our final die type appropriately
var final as number
final = finaldie
if (final < 2) then
  final = 2
elseif (final > 6) then
  final = 6
  endif

~convert the final value for the trait to the proper die type for display
var dietype as number
dietype = final * 2
finaltext = "{bmp d" & dietype & "_screen}"

~if there are any bonuses or penalties on the roll, append those the final result
if (finalbonus <> 0) then
  var bonus as string
  bonus = signed(finalbonus)
  finaltext &= left(bonus,1) & "{b}" & right(bonus,1)
  endif

We now have something that will work smoothly, shows the die-type as a bitmap, and looks reasonable.

Explain How Derived Traits Are Calculated

The derived traits are shown on the Basics tab. However, these traits are influenced by a variety of factors. When the user sees one of these traits, it would be incredibly helpful to inform the user how the final value was actually derived for the character. So we'll take the time to add this information now.

The first thing we need to do is provide a place to accrue the derivation details for each derived trait. We can do this by defining a new field for the "Derived" component, which can be found in the file "traits.str". We'll name the new field "trtDerived" and make it a text field with adequate storage for multiple adjustments. This yields a field definition that looks like the one below.

<field
  id="trtDerived"
  name="Derivation"
  type="derived"
  maxlength="200">
  </field>

Since we're going to be modifying this field in a variety of places, we might as well make it easy on ourselves. So we'll define a new script macro for this field that works similarly to the "traitbonus" script macro that we already use whenever modifying the value of a derived trait. Open the file "definition.def" and locate the "traitbonus" script macro, then clone that macro. Edit the macro to have the name "traitderived" and operate on the "trtDerived" field, which is a text field. The new macro should look like the one shown below.

<scriptmacro
  name="traitderived"
  param1="trait"
  result="hero.child[#trait].field[trtDerived].text"/>

The next step is to initialize the field to something appropriate for each derived trait. This is easily accomplished by defining the field value within each thing. For example, we can set the initial derivation text for the Pace trait to something like "Base of 6" via the "fieldval" element, as shown below. This should be done for all derived traits within the file "thing_traits.dat".

<fieldval field="trtDerived" value="Base of 6"/>

Throughout the data files, there will be places where each derived field is modified in some way. In each of the locations, the derivation details must be logged at the same time the adjustment is applied. This is achieved by simply appending a suitable, brief description of the adjustment as text. For example, the "Berserk" edge applies a +2 bonus to the character's Toughness and a -2 penalty to the character's Parry. Once the derivation details are added, the new script should look like the one shown below.

if (field[abilActive].value = 0) then
  #traitbonus[trParry] -= 2
  #traitderived[trParry] &= ", Berserk -2"
  #traitroll[skFighting] += 2
  #traitbonus[trTough] += 2
  #traitderived[trTough] &= ", Berserk +2"
  endif

Go through the data files and locate all instances where the derived traits are modified. Every instance should be accompanied by a corresponding "#traitderived" macro that logs what adjustment was applied. Be sure to also track the effects of equipped weapons and shields on the Parry trait, as well as the effects of equipped armor on the Toughness trait.

For two of the derived traits, the final value depends on another trait that can also be modified by other effects. So we need to wait until the end of the evaluation cycle before applying the adjustment for the trait. This requires we define a new Eval script for each of the traits that properly appends the final adjustment description to the derivation field. The two traits that require this are the Parry and Toughness traits, which are based upon the Fighting skill and Vigor attribute, respectively. Putting it all together, the two Eval scripts below should handle things appropriately for these two traits.

<eval index="2" phase="Render" priority="10000"><![CDATA[
  if (hero.childexists[skFighting] <> 0) then
    field[trtDerived].text &= ", Half Fighting +" & #trait[skFighting]
    endif
  ]]></eval>

<eval index="2" phase="Render" priority="10000"><![CDATA[
  field[trtDerived].text &= ", Half Vigor +" & #trait[attrVig]
  ]]></eval>

The derivation explanation should now be getting properly synthesized for each trait, so all we need to do now is make it accessible to the user. Open the file "tab_basics.dat" and locate the "baTrtPick" template that is used to display the various derived traits. Within the template, the "details" portal shows the final value for the trait, and a MouseInfo script is defined that currently just outputs "???". Change the script to return the contents of the "trtDerived" field and the derivation details will be available to the user by simply moving the mouse over the value. The revised portal should look like the one shown below.

<portal
  id="details"
  style="lblLarge">
  <label>
    <labeltext><![CDATA[
      @text = field[trtDisplay].text
      ]]></labeltext>
    </label>
  <mouseinfo mousepos="middle+above"><![CDATA[
    @text = field[trtDerived].text
    ]]></mouseinfo>
  </portal>