What to consider for an RPG damage formula?

This topic is 541 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

So I've come up with a damage formula I might use, and I can't find any reason why it wouldn't work. I can only assume this means I need some outside help to see what's wrong with it.
# The base (at 0 defense) difference between attack and defense needed to add/subtract 50% damage
base_d_factor = 10

# Amount added to the base factor for every point of defense over 0
scaled_d_factor = 0.5

# ...(stuff goes here)

dif = attack - defense
if dif:
sign_dif = sign(dif)
scale = 1.0 + (-1.0/(sign_dif + dif/(base_d_factor + defense*scaled_d_factor)) + sign_dif)
return attack * scale
else:
# else we'd be dividing by 0
return attack


Or to summarize, a character's attack value gets multiplied by a number on this curve dependant on how much higher or lower it (the attack value) is than the targets defense.

[sharedmedia=gallery:images:7655]

http://www.gamedev.net/gallery/image/7654-curve/

Anyway, the motivations I was working with when I came up with this nonsense are:

• I wanted the numbers to seem at least a little intuitive. Damage value is always "close" to attack value. If you're fighting an enemy who's roughly the same "level" as you, you'll be doing damage basically equal to your attack value The most damage you'll ever be doing is double what your attack value is.
• I didn't want a relatively super high defense to completely invalidate any attack. If a character has 40 attack, but an enemy has 120 defense, they'll do around 20 damage. Maybe still not much, but you're never doing just 0 or 1 damage.
• I wanted it to be easy to balance. Setting an enemies defense indicates a certain range of where the player is expected to be when they fight them and how much damage they will be able to consistently do... In theory.

So... are there any glaring flaws or heinous crimes against decency that anyone's aware of? Have I created some hideous over-complication of what should be some simple... "Bicubic Factorial Curve" or some such? Have I accidentally made an impossible-to-balance Explosive-Feedback-System? Is my code so unreadable that it'll absorb the soul of anyone who reads it too many times? Or just... is there anything else I should consider?

Share on other sites

What you've got there seems functional.  You'll need to beware the division by zero points, but otherwise it can work.

Sigmoids that are similar to that are one of the go-to curves in game development statistics, so you might consider going that route, just make a reusable sigmoid function.

Share on other sites

I wouldn't sweat it much.  Do test it, since different games need different formulas.

Starcraft (the original), as an example, has very simple methods, but it works for that game.

Share on other sites

The only way of knowing is by testing.

Damage is something you first consider in your game design:
Is it a fast pace game? or is it slower?

Should the fights be long or short?

You can tweak damage in all kind of formulas and conditions, and not just by focuing on a single formula.

But focusing on the design of fights or between fights.

For example let's take your rule of "Never 0-1 damage". Meaning any hit that wasn't dodged has implications, which is good for rewarding players on hits and punishing on dodging. However, how do you implement a tank that way? Someone who has more armor is probably less efficient with weapons, therefore giving him more damage because of that rule make no sense.

Yet again, it all depends on your game design and playing style that you want to put in your game.

Share on other sites

for things like this, the goal is to model the desired behavior as simply as possible.

if what you have yields the desired behavior, and no simpler model / formula / set of rules does, then this is the best choice.

if it does not yield the desired behavior - its useless.

if a simpler model will do, its unnecessary complexity / over-engineering.

so you have to start with the definition of the desired behavior.

Share on other sites

Thanks for all the replies! So I get the impression a big part of it is just testing it out and seeing. Which makes sense. I just wanted to make sure there weren't any obvious foreseeable problems (eg, dividing by 0) or optimizations that I'd missed. Or just any other considerations that might come to mind. Like that it could inhibit the idea of a "tank" character, for example; that's a good observation.

I suppose it's probably worth mentioning that it's specifically a ye olde..... fashioned turn-based (j?)rpg... type game. For the most part. While we are trying to keep everything happening smoothly and with as little breaks in the action as we can, I don't think you could call it fast paced, just by virtue of it being turn-based. Also this won't necessarily be the only part of the equation. I can give "modifiers" to any of the numbers, so like if a character is "defending" I could multiply their defense by 1.5, or if something is weak to some element, multiply the final damage by 2. Stuff like that. Maybe if we did want to incorporate a character being a tank or something I could use this in someway. They subtract some value from all damage they receive or something.

Maybe I need help paring down what the "desired behavior" actually is? It's like...

"Compare an 'attack' value to a 'defense' value to determine an amount of 'damage' to be dealt"

• Given an attack value and defense value, it should be relatively easy to estimate an HP value for a given number-of-hits-needed-to-defeat-someone, or vice-versa.
• I guess the three things I mentioned in the opening post.

... and uh........... that's all I've got.

Well if there's anything else that anyone can think of that I should be considering, let me know. Since it sounds like there's nothing obvious wrong what Ihave, I guess I'll just... use it for a while and see how it works. Thanks again!

Share on other sites
Seems similar to my approach. :)

Just to throw out my two cents, the fundamental problem with “a ratio of the attacker’s attack stat” is that the stat is multiplied with itself, giving it an unfair advantage. Adding one or two points to attack is much stronger than adding one or two points to defense. It may be helpful to separate the “bonus stats” gained from items from “base stats” gained from levels. I don’t have my exact formula, but I think I have something similar to:

/*
Probably totally incorrect:

STR: Strength (base attack)     ATK: Bonus attack
RES: Resistance (base defense)  DEF: Bonus defense

A_STR + max(0,A_ATK - B_DEF)
damage = ----------------------------  x  (A_STR+A_ATK)
A_STR + B_RES + B_DEF
*/

Share on other sites

One thing that's always bothered me about games with medieval warfare and armor and damage calculations is that they rarely ever actually realistically model the effect and purpose of armor.

I remember going to a museum in Finland a few years back and looking at weaponry and armor from 500+ years ago. Knights were covered, head to toe, in steel. Almost nothing could penetrate that. Then they also have a kite shield and sword. A large squad of these guys, slowly marching towards you, was an invincible, inevitable death. The only way you could kill one of these soldiers was to tire them out, lift up their arm, and stab them with a very thin dirk beneath the armor. People didn't wear armor to take LESS damage, they wore it to take NO damage. Even a good scratch or cut could get infected and take months to heal, so people probably spent a lot of effort trying to develop armor which made them impervious to damage and used weaponry specialized against armored opponents. A mere peasant armed with a pitchfork would be minced meat, no matter their martial skill. Armor was expensive though, so not everyone on the battlefield had it. To wear armor was almost a status symbol, and to make it even more of a status symbol, some rich nobles would have their armor inscribed with decorations. One other surprise is in regards to leather armor. Leather armor is HARD. It's not that soft, supple leather which is designed for clothes and couches, it's leather that has been treated differently so that it hardens into a protective shell. It's not as hard as steel, but it will do a very good job of blocking most incoming attacks.

If I ever go and design a game with medieval combat mechanics, I would certainly try to take into account the realism of armor and its functional use. There would be no "Hey, I'm fully armored and yet a single sword swipe cuts me down!" bullshit. What's the point of wearing armor then? Might as walk around the battlefield naked because it's less encumbering and hot. Let's talk about heat and weight a bit too. I don't know about you, but I've had to wear full modern armor before (flak jacket, SAPI plates, kevlar, side SAPI, crotch cover) in the desert. It's bulky. It's uncomfortable. It's HOT. It's like wearing a snow suit in the middle of july. You don't want to move around much because its heavy and tiring. So, designed game mechanics could take advantage of this fact: The temperature, weight and amount of armor contributes to exhaustion, and exhaustion is a function of fighting capability (blocking and delivering blows). A part of battlefield strategy then becomes managing exhaustion, which is what was actually done! Lines would frequently rotate from the front to the back, rest and recover for a bit, move towards the front, and then resume fighting. Gradually, everyone gets really tired and more R&R doesn't help. But then the army which wins is the one which can bring in fresh reserve troops, preferably in a flanking maneuver. The enemy is too tired to fight fresh troops, and they're being flanked, so they either change focus to fight the fresh troops or continue engaging with the tired troops while the flankers mop them up. It's a fascinating mechanic :D

So... damage would be a function of the martial skill, exhaustion, equipped weapon type, sustained injuries, strength. The frequency of attacks would be a function of exhaustion, martial skill, and morale. An incoming attack wouldn't just be subtracted from the armor of the victim. That would be WAY last. First, you'd want to give the defender a chance to dodge, block or parry the attack. This would be a function of their martial skill, morale, exhaustion, equipped weapon type, mental focus, incoming weapon type, and sustained injuries. IF an incoming blow can't be dodged, blocked, or parried, then it is a hit. The hit would be registered somewhere on the body, but the actual damage inflicted would be a function of how armored that body part is and what type of damage we're inflicting (blunt, piercing, slashing, magical, fire, etc). The design goal would to make it so that an armored opponent *could* be near invincible. That's scary, and it should be scary. Nobody fucks with armored guards (see: swiss guard). If you're not prepared to fight an armored opponent, then you lose. Likewise, if nobody is prepared to fight your armored characters, they lose. Game "balance" would be less about balance on the battlefield, and more about access to resources prior to battle, so battlefield victory is partially determined by preparations before battle begins. (man, I want to make this game...)

Share on other sites

Seems similar to my approach. :)

Just to throw out my two cents, the fundamental problem with “a ratio of the attacker’s attack stat” is that the stat is multiplied with itself, giving it an unfair advantage. Adding one or two points to attack is much stronger than adding one or two points to defense.

I'm not multiplying the stat by itself........ am I? And the greater the difference between attack and defense, the less each point would be "worth", right? So if there's a difference, adding n points to whichever one is lower would have a greater impact than adding n points to the higher one.

Share on other sites

First, you'd want to give the defender a chance to dodge, block or parry the attack.

what you describe is similar to what i and the DM i learned from came up with in 1977, except we added a dex based check for a hit in the first place, followed by the dodge/parry/block phase, then hit location, then wpn vs armor, and finally dmg done. we figured out the system but never implemented it. my current project is the first game i've done that includes all those aspects you mentioned as well as a chance to hit influenced by dex.

Share on other sites

A friend of mine long ago created this guide to how Final Fantasy VII calculates damage.
I am sure you will find it more than a little useful.  :wink:
https://www.gamefaqs.com/ps/197341-final-fantasy-vii/faqs/22395

L. Spiro

Share on other sites

. Knights were covered, head to toe, in steel. Almost nothing could penetrate that. Then they also have a kite shield and sword. A large squad of these guys, slowly marching towards you, was an invincible, inevitable death. The only way you could kill one of these soldiers was to tire them out, lift up their arm, and stab them with a very thin dirk beneath the armor.

You could break their neck. Counting up they had extremly reduced agility it was not much of a win.

Share on other sites

. Knights were covered, head to toe, in steel. Almost nothing could penetrate that. Then they also have a kite shield and sword. A large squad of these guys, slowly marching towards you, was an invincible, inevitable death. The only way you could kill one of these soldiers was to tire them out, lift up their arm, and stab them with a very thin dirk beneath the armor.

You could break their neck. Counting up they had extremely reduced agility it was not much of a win.

Actually the plate armor was quite thin (and had amazing sliding slot mechanisms for the overlapping plates) and its attribute was steel strength that resisted cutting of blades and curved surfaces to deflect blows/missile strikes (the long bow arrow had an extremely sharp hard point (high quality steel) to catch on the surface when not straight on and then penetrate cutting through using the force of  that 3 foot (yard) long shaft.   Blunt high impact weapons like warhammers would also cave in such armor.   That kind of armors days were numbered when guns came which (as they improved) could punch through thin metal like butter.

You had to be able to run around in that armor (you would have a heavier version of it if you were mounted and used a huge horses strength)

While still fairly heavy versus no armor, the plate armor generally wasnt heavier (and often lighter) than other types of 'most of body' armor.

--------

For the OP  consider that it can be more than just equations   as :   Many game mechanics hold off player incapacitation/death when at very low HP/health level a bit longer(moments) time to allow the victim to invoke some last-ditch 'ability' before death/whatever.

Dont forget the more complex the armor got, the more of a maintenance crew you needed to apply it and keep it operational and the prep time before it could be used on a battlefield (thus limiting its use to special circumstances much of the time and narrow situation of maximum utility).

Also certain inconveniences like of having to uriniate/defecate once you have that armor on ...

Edited by wodinoneeye

Share on other sites

I think you should start from stats, work out test cased based on those stats, and find, or let the computer find, a formula that interpolates between the desired behaviour in each test case.

For starters, I don't think "attack" and "defense" are actual character stats: they are synthetic values, computed from what really matters to the player for the sole purpose of the damage formula.

Real characters could have:

• general combat training
• innate combat talent,
• familiarity with their weapons and armour
• familiarity with the opponent's weapons and armour
• muscular strength and speed
• quick reflexes
• superiority of weapon/armour types (pairwise or in tiers)
• quality of weapon/armour design (e.g. well balanced)
• weapon/armour technology level (e.g. steel sword vs bronze sword)
• quality of weapon/armour manufacture (e.g. incorrectly tempered steel that is more likely to bend or break)

And in fantasy settings:

• cost/quality/rarity/quantity/strength of spells and magical items that buff of attacks
• cost/quality/rarity/quantity/strength of spells and magical items that provide healing
• cost/quality/rarity/quantity/strength of spells and magical items that protect the user
• favor of the gods
• current burden of hostile spells and curses
• moon phases or other astrological trends and moments
• countless other setting-specific factors and conditions

In a game many of these elements, even if important "in theory", would be deliberately ignored as irrelevant ((e.g. aircraft combat only -> no strength)), not interesting (e.g. metallurgy is considered not heroic) or counterproductive (e.g. weapon types are few and weapons of the same type are assumed to be identical because weapons are scarce and randomly getting a "wrong" or inferior one would be a problem), flattened to irrelevance (e.g. everybody is a knight of similar skill, training and equipment) or simplified (e.g. D&D treats innate combat qualities only in part as stats and mostly as belonging to the Fighter class or similar ones, which fight better than other people in a number of ways).

And some elements would be deliberately emphasized or downplayed, even to unrealistic extremes: in a game about the chosen of the gods, i.e. a kid, going on an epic quest to save the world combat training and experience should not be an important success factor for the protagonist, who should have little to learn and many decisive unique or magical items and resources to collect, while in a game about being the best gladiator in town magical aids should be illegal to begin with and no more than a nuisance for a smarter, stronger and better equipped opponent.

Share on other sites

Blunt high impact weapons like warhammers would also cave in such armor. That kind of armors days were numbered when guns came which (as they improved) could punch through thin metal like butter.

I am not sure even wheather those armors had any days of glory.

To load a crossbow that has more penetrating power than Magnum rifle, firing 3pound+ ridiculous projectiles is doable for even a child (I have "stabbed" my father's summerhouse as 9 years old with french army crossbow, putting naively as wide as three matraces before the wall to not "hurt it" and walking 100m away).

A person, even in more profesional agile armor, is still loosing dogging ability against better strike moves, so for example with a short chain or rope you could get grab such a person around neck or head from behind and pull it so fast they will loose prosperity in absolute manner for like 5 seconds on the ground. I think those armored guys were literaly clauns.

To OP, you must mainly equalize amount of player's investment (time/resources/experience) in a stat to effect of the stat, to be at least a bit sane as a decision - else you will be totaly blown up indie!

Share on other sites

Blunt high impact weapons like warhammers would also cave in such armor. That kind of armors days were numbered when guns came which (as they improved) could punch through thin metal like butter.

I am not sure even wheather those armors had any days of glory.

To load a crossbow that has more penetrating power than Magnum rifle, firing 3pound+ ridiculous projectiles is doable for even a child (I have "stabbed" my father's summerhouse as 9 years old with french army crossbow, putting naively as wide as three matraces before the wall to not "hurt it" and walking 100m away).

A person, even in more profesional agile armor, is still loosing dogging ability against better strike moves, so for example with a short chain or rope you could get grab such a person around neck or head from behind and pull it so fast they will loose prosperity in absolute manner for like 5 seconds on the ground. I think those armored guys were literaly clauns.

To OP, you must mainly equalize amount of player's investment (time/resources/experience) in a stat to effect of the stat, to be at least a bit sane as a decision - else you will be totaly blown up indie!

Oh they did (heyday), but their expense limited their use.   Crossbows (powerful large ones you refer to) were very slow to load (you actually had to use a clumsy mechanical winch to reload it) and not something you could do properly on an active  battlefield (very useful in defensive works where you could take your time loading behind cover)

They also had limited accurate range.

Yes an armored man was at a disadvantage  amongst agile unarmored men, but the trade off was how many of them he could kill before they got him (and if you go to the expense for such armor the user probably would be highly trained in use of their weapons versus the usual cannon-fodder 'levies'.)   Massed armored men who could support each other (protect flanks) still allowed concentrating force on the field and likely with better order/dicipline would have the enemy routed quickly after inflicting their damage on the enemy.

Even into the age of guns 'partial armor' like heavy THICK breastplates were used that were 'proofed' against pistol shots (large numbers of early guns were those) - as always its a matter of being BETTER protection rather than PERFECT protection.

Edited by wodinoneeye

Share on other sites

. Knights were covered, head to toe, in steel. Almost nothing could penetrate that. Then they also have a kite shield and sword. A large squad of these guys, slowly marching towards you, was an invincible, inevitable death. The only way you could kill one of these soldiers was to tire them out, lift up their arm, and stab them with a very thin dirk beneath the armor.

You could break their neck. Counting up they had extremly reduced agility it was not much of a win.

lol, this is kind of laughable. In a 1v1 fight, attempting to snap someones neck *might* be a viable tactic, but I'd say your chances of doing that successfully are probably around 1%. I don't know if you've ever been to a renaissance fair and watched armored men duel each other, but they are actually surprisingly mobile and flexible with full body armor. It barely hampers their fighting ability.

Keep in mind that in battle, people fought in tight formations. It wasn't any of that braveheart BS, where a bunch of dudes just ran out and had a ton of 1v1 fights with other dudes who ran out. The prevailing strategy was to march into battle in formation, lock shields together, and keep the front lines unbroken. If a man gets hurt or tired, he goes to the back to recover and the next one steps forward and resumes the fight. Since everyone is standing shoulder to shoulder, nobody can attack you from anywhere but the front. The best weapons were either nice long pikes, or short swords. Short swords are better than long swords because they're much easier to swing in close proximity. Long pikes are great because the lines behind the front line can also use their pikes to stab at the enemy. Keep in mind, battle is a lot different from what you see in movies and video games. People are pretty much like sacks of blood, waiting to be popped like water balloons. All you need is one or two good pokes or slashes and someone will bleed out and die.

An interesting weapon development was the halberd and bill. They were used like pikes, but could also had a multipurpose function of taking down horse riders and using the hooks to find chinks in armor and tear them off.

Share on other sites

Keep in mind that in battle, people fought in tight formations. It wasn't any of that braveheart BS, where a bunch of dudes just ran out and had a ton of 1v1 fights with other dudes who ran out. The prevailing strategy was to march into battle in formation, lock shields together, and keep the front lines unbroken. If a man gets hurt or tired

Yeah I know, those armored man- usualy AAA high ranks were resistant to cavalry, but tight army formations were extremly voulnerable to canon rolling balls (usualy fired from canons upper a hill devastating what they roll about- taking half of your body orthogonaly away from you). But in an assasination face-to-face , they knew their time had come.

I have spoken about advanced counter unit/individual against armored man. Armored man were surely an reinforcement in a battle front, yet very vulnuarebale while at it.