ScottTykoski ScottTykoski

Elemental: Data-Driving the Unit Stats

Elemental: Data-Driving the Unit Stats

Where once there was an Array there is now a std::Map

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 :)
108,946 views 47 replies
Reply #26 Top

More moddability is always good  (Civilization 4 is a nice exampl of this, been playing a lot of mods in it recently), so it's nice ot see that these sorts of things are included.

Reply #27 Top

Hum .. so ... we have "blunt damage". Will armor be able to acts accrodingly ? Like if I have a full plate armor. Will I be able to tell the comp to lessen damage if the armor is an "anti-blunt damge" ?

Reply #28 Top

Hum .. so ... we have "blunt damage". Will armor be able to acts accrodingly ? Like if I have a full plate armor. Will I be able to tell the comp to lessen damage if the armor is an "anti-blunt damge" ?

That's the plan, but since that gets into the 'battle logic' side of things, I don't have many details. But right now, you can (in XML) assaign 'Blunt Attack' to weapons and 'Blunt Defense' to armor. You can even make a spall, potion, or event that raises either of these values.  AH, the joys of data-driven code :)

Reply #29 Top

Good news ! Will we be able to do that .. with spells ? Weapons ?

Will I be able to create a fire elemental that have "fire armor" and "water weakness" ? And add some tag to swords like "water damage" and add to the battle logic that a "fire damage" will be increased versus a "fire weakness" ?

If so, I don't understand the need for separate damage "types" (and all the heated discussion about just "magical" and "mundane" damage), because a simple tag will be able to handle all the jazz about fire elemental, ice sword, earth chickens and wind spoons.

*crosses fingers*

Reply #30 Top

Quoting BoogieBac, reply 28

Hum .. so ... we have "blunt damage". Will armor be able to acts accrodingly ? Like if I have a full plate armor. Will I be able to tell the comp to lessen damage if the armor is an "anti-blunt damge" ?


That's the plan, but since that gets into the 'battle logic' side of things, I don't have many details. But right now, you can (in XML) assaign 'Blunt Attack' to weapons and 'Blunt Defense' to armor. You can even make a spall, potion, or event that raises either of these values.  AH, the joys of data-driven code

Sounds awesome Boogie! It looks like that hardcore strategy gamers can have their fun with the game as well, because of the powerful modding features! :)

Reply #31 Top

Hey Boogie, I understand nothings set in stone until the game ships, I was just curious if you could share Stardocks current plans for overall unit stats in Elemental? Maybe even what ideas you've all been throwing around?

Sorry, missed this one :)

Right now, for all units, we're looking at...
Attack
Range (how far the weapon can reach)
Armor (Defense)
Magic
Magic Resistance
Hit Points
Combat Speed
Moves (per Turn on main map)
Sight


With Heroes and Sovereign units getting a few extra RPG stats that will affect the above base values...
Strength
Intelligence
Wisdon
Charisma
Constitution
Dexterity
Essence

...and all that is subject to change at a moment's notice ;)  But I think we're finally coming to the final set of stats.

 

+1 Loading…
Reply #32 Top

Awesome boogie! thanks for sharing :)

I've seen Morale thrown around in a thread or two, was it cut as a stat? or is it simply a type of bonus or penalty that gets applied to a unit?

Regardless, the stats are looking good.

Reply #33 Top

Do the RPG-style extra stats only give bonuses to the base stats? Or do they do other things?

Reply #34 Top


It is great that Weapon Reach is in.   It'll be very useful stat, relates to flanking and/or first strike.
 
I am proposing a new stat Leadership Cost & Leadership Value, which determine the number of units a hero can improve their base value.    I really like the direction of letting a hero changes unit's base stat.

Reply #35 Top

Where is the morale stat ? won't there be one ? It could really add a lot to the battle mechanism.

Reply #36 Top

I've seen Morale thrown around in a thread or two, was it cut as a stat?

I beleive the current thinking is to have that an army-wide stat, based on various factors (tide of battle, relations, etc.) and only applicable in battle, but it'd be pretty easy to make that a per-unit stat.

Reply #37 Top

Historically, armies didn't always break at the same time, but parts of armies usually did.  I like the idea of a "Discipline" stat, too, but it's probably redundant with Morale.  Basically, I don't want untrained peasants able to form close ranks and march in formation quickly.  Well-trained troops should have advantages in speed, reaction time, and maneuverability.

Boogie - How do you see that type of thing being reflected?  Are unit formations, etc. going to come with tech and be like an "item" used by a given troop type?

Reply #38 Top

I'll be interested in seeing how "base game" morale developes as well (If it is included).

Reply #39 Top

Quoting BoogieBac, reply 36

I've seen Morale thrown around in a thread or two, was it cut as a stat?
I beleive the current thinking is to have that an army-wide stat, based on various factors (tide of battle, relations, etc.) and only applicable in battle, but it'd be pretty easy to make that a per-unit stat.

A whole "morale" thing about the tide of battle is good .. and it should affect the morale checks units would do when they see ding their friends.

Every units with a morale stat should make a roll when too much people die next to them and/or are breaking. The army-wide "morale" could be a bonus/malus to that roll. The discipline of a unit would be a bonus to that check. The "Will" would add a bonus only when the life of the unit is threatened.

What I liked about Medieval total war is the fact that breaking a piece of an army could get a "wave" effect where units near the breaking units would break and so on.

Reply #40 Top

Yeah, the Total War series has replicated the morale effect very effectively since Shogun.  I'll never forget this one battle I had in Shogun: a very large enemy army was advancing up the hill towards me.  I basically had archers and heavy cavalry.  the archers were causing some casualties, but were going to get hit.  So I dispersed them, and then moved my heavy cav through their ranks.  The enemy line wavered visually, and as the heavy cavalry got about half way to them, they broke in an expanding ripple, starting at the center unit and moving to both flanks in a matter of seconds.  It was one of those "that was cool" moments.

Reply #41 Top

Is Armor (Defense) going to be damage reduction or evasion? I hope it is reduction and there is a separate attribute called evasion or dodge. It always kind of bugged me when armor was really evasion in a game instead of actually being armor. 

Reply #42 Top

All this sounds nice, but won't it run slower than a more old-fashioned, hard-wired approach?

PLEASE tell me that no part of this game will run as slowly as the "next-turn" in HOMM5 with max-size maps and max # of AI players.

Reply #43 Top

Quoting Lord, reply 42
All this sounds nice, but won't it run slower than a more old-fashioned, hard-wired approach?

PLEASE tell me that no part of this game will run as slowly as the "next-turn" in HOMM5 with max-size maps and max # of AI players.

Flexibility and performance are trade offs. But is hard to prove that if you have a speed problem, hard-wiring things is the best approach to solve it instead of refactoring code, improving algorithms and other things.

So I wouldn't attack performance issues hard-wiring if is not the last resort, there are plenty of other things that can be tried first.

Reply #44 Top

All this sounds nice, but won't it run slower than a more old-fashioned, hard-wired approach?
  You're still looping through a list of stats, only now that list size is variable. I suppose I could see some miniscule hit to performance if you have 100+ extra stats thrown into the game that it has to sort through, but even then it wouldn't be close to the hit you'd get from something graphical in nature (increasing resolution, switching to 8x AA, etc.).

Reply #45 Top

I'm also in favor of a morale stat. That morale be checked per bunch of units is good, but each formation can make a morale check on its own based on the average morale stat of each of their members.

Reply #46 Top

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.

Reply #47 Top

Quoting Ynglaur, reply 46
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.