# Distributing damage across units in an army

I'm working on a game similar to the web game Utopia, insofar as players have a number of units with different values for attack and defense.

Question: how do I distribute damage across units when a conflict plays out?

Let's say I have two units:

• Infantry: 3 attack, 3 defense
• Cavalry: 5 attack, 1 defense

Let's say the player has 100 infantry (300 attack, 300 defense) and 50 cavalry (250 attack, 50 defense); the player now gets hit with an attack of 100 points of damage.

How do I resolve this in a way that doesn't force players to understand damage and micro-optimize, also given that I'm not going to store individual units' health values after the conflict?

• If I distribute damage to weakest units first, 33 infantry will die; but players will spam cavalry and keep a small number of "fodder" infantry around to absorb damage.
• If I distribute damage to strongest units first, 50 cavalry die; but players will spam infantry, thinking that stronger units are "not worth it" because they always die.
• If I distribute damage randomly (eg. some infantry get 1 damage, some get 2, some get 3 and die), I will likely end up with players thinking that conflict is not effective, because a number of units took damage but didn't die (and I don't keep track of damaged units -- they heal afterward).

Is there a distribution algorithm I can use that doesn't have any of these side-effects and appears "fair" to the player? If not, how can I make this make sense so players understand how this should work, without me hindering certain types of strategies?

I wrote an answer to a question here that looks similar, but I explicitly didn't tackle the problem of fairly distributing damage without sabotaging different strategies.

• Your third bullet sounds misguided -- if damage isn't killing enough things, then you tune the system so that more damage is done.
– user64554
Jul 18 '17 at 7:45
• It's not really clear to me what your design goal is. You say you don't want the player to "spam" either infantry or cavalry, so your intention seems to be to get the players to have a mix of units. What would be the "ideal" mix in your opinion and why? Jul 18 '17 at 10:46
• @Philipp I'm not sure if I'm clear on what I want. What I see is that the order of damage resolution may make certain types of units useless, because they end up soaking up most of the damage and becoming cannon fodder. That's what I'm trying to avoid. I think the ideal mix is something like Jimmy's answer: all types of units "fairly" (not equally) absorb some damage. Jul 18 '17 at 11:33
• @ashes999 Why is that necessarily bad? Combining cheap and expendable cannon fodder units with expensive damage dealers is a concept which is used successfully in quite a lot of games. Jul 18 '17 at 11:35
• @Philipp it's not "bad" per se, just not the game design that I want. I think we can do better. I don't want a design that forces the user to have fodder units; I'd rather let them strategize however they want. Distributing damage "fairly" (in some way) facilitates that. Sorry, does that make sense? Jul 18 '17 at 16:12

I'd base the system on three basic principles:

1. each unit type has different HP values that affects its mortality rate.
2. all damage done is lethal (otherwise, just multiply by a scaling factor)
3. each squad takes total damage in proportion to the number of individuals.

1400 infantry   (ea. 50 HP)
500  cavalry    (ea. 100 HP)
500  conscripts (ea. 20 HP)
100  elites     (ea. 200 HP)
2500 total      (total HP pool 150k)


for an enemy army with incoming damage: 30k, Your damage numbers are:

• infantry takes 30k* 14/25 damage, and 336 die
• cavalry takes 30k* 5/25 damage, and 60 die
• conscripts take 30k * 10 / 25 damage and 300 die
• elites take 30k * 1 / 25 damage and 6 die

Further considerations:

1. You'll have to handle when an entire subgroup gets annihilated, applying remaining damage to the rest of the army. For example, in the previous example, if the enemy army did 60k damage, your conscripts would take enough damage to kill 600 guys but there were only 500 to begin this. You have to redistribute the 100 extra damage across the remaining army. Alternatively, just split damage into smaller rounds (like 30 rounds of 2k damage each) and deal with the smaller amounts of overkill per round. You'll have to use floats for the intermediate damage otherwise your elites may just never take enough damage per round to take any casualties.
2. This answer doesn't cover how to calculate the total incoming damage.
• I really like your answer. Thanks for this. It even has scope for more interesting additional rules (eg. some units receive/inflict 2x damage from air units). I'll leave this question open for 24 hours, but if nothing better comes in, I'll accept this. Jul 18 '17 at 2:39
• @Jimmy welcome to 5000+ club on GDSE ;-) Jul 18 '17 at 4:39
• Just wanted to add the possibility, that you receive a damage amount thats to weak to kill anyone, e.g. 9 damage to defense 10 units. That's possible when you split the damage onto the groups. Jul 18 '17 at 7:22
• @PSquall yeah, I ignored the fractional damage because OP mentioned "I don't keep track of damaged units -- they heal afterward", so that seems like desired behavior. However, as I mentioned in Further Consideration #1, you'll have to track partial damage when using multi-round combat. Jul 18 '17 at 15:34
• @Jimmy thanks for that, this is exactly what I asked for -- I'm working on a large-scale (numbers) game where I have thousands of units; tracking individual units is impractical, so in my case, they essentially auto-hael after the battle damage resolves. Jul 20 '17 at 15:14