Where once there was an Array there is now a std::Map
Published on December 11, 2009 By ScottTykoski In Elemental Dev Journals
Wow, what a week. A task that I had assumed would take 1.5 days ended up sucking up around 32 hours. While my lack of scheduling foresight sucks, the time was DEFIANTLY worth it to have this vital feature done right...
 
In previous builds, all unit stat handling was done with a basic array of stats.  There was a hard-coded list of what could and could not be stored in it (Strength, Defense, and HP to name a few). It worked, but with several new stats in the pipeline (Magic Attack, Magic Strength, Structural Damage) and the ongoing discussion on other damage types, I figured it was time to rework the system in a data-friendly way.
 
We now store all unit stat data in what are called MAPS, where entries are sorted by a STRING, opposed to a numeric INDEX. Now, instead of using afStats[1] to get hit points, the developers use mapfStats['HitPoints']. We also have a file that defines the given stats for the game...
 
<UnitStatType InternalName="UnitStat_HitPoints">
<DisplayName>Hit Points</DisplayName>
<Icon>Icon_Heart.png</Icon>
<Description>How much damage a unit can endure before kickin' the bucket.</Description>
</UnitStatType>
 
The above would let the game know that 'UnitStat_HitPoints' is a valid unit stat. You could then add a stat type by defining it in XML...
 
<UnitStatType InternalName="UnitStat_BluntAttack">
<DisplayName>Blunt Attack</DisplayName>
<Icon>Icon_Club.png</Icon>
<Description>The blunt damage this unit will deal when attacking.</Description>
</UnitStatType>
 
You then add a stat modifier to a weapon...
 
<GameMod>
<Type>Unit</Type>
<Attribute>UnitStat_BluntAttack</Attribute>
<Value>5<Value>
</GameMod>

And the game will know that any unit with that weapon does 5 points blunt attack.  Hooking this up to the battle system in a data-driven fashion will be another adventure, but at least the raw data is now organized and manageable. A good week...even if I wish I had more to show for it

Comments (Page 4)
4 PagesFirst 2 3 4 
on Dec 16, 2009

Finding a value in a list of n size is a logarithmic algorithm, so long as the list is sorted.  Not going to cause a real performance problem.

on Dec 17, 2009

Ynglaur
Finding a value in a list of n size is a logarithmic algorithm, so long as the list is sorted.  Not going to cause a real performance problem.

What would you look by sorting? In hashtables or tree maps, access is neither logarithmic nor linear but constant. Insertion is slower, but it happens once in a blue so it's rather irrelevant.

4 PagesFirst 2 3 4