Tuesday, January 10, 2017

strategy - RTS game unit damage & defense calculation



How can I model armies attacking each other in an RTS?


I know how I would do it if it is an RPG game. Character has few stats that affect damage/defense and then compare it with enemy character and make calculations.


But what to do when you have an RTS game with lets say 3 kind of units (archers,knights,cavalry).


How would you do a calculation:



eg. 3 archers, 2 horsemen, 4 knights attack 3 knights and 5 horsemen?


One idea I had was to model units as having a certain amount of attack/defense against other units.


eg. Archer - 70% damage against knight, 10% defense against knight (90% damage against horseman (higher chance to hit bigger object)) (10% defense against horseman (if he comes closer))


Knight - 30% damage against archer, 20% defense against archer (50% damage against horseman, 40% defense against horseman)


Horsemen - 90% damage against archer, 20% defense against archer (70% damage against knight, 70% defense against knight)


In my game, players control armies (groups of units), which they send to attack enemy towns. At that point, I need to calculate how much damage the attacking army inflicted on the town (and vice-versa). I'm looking for some sort of formula or algorithm to help determine this.



Answer



One way I would solve this problem (albeit simplistically) is simple math. Assign each unit damage and health, eg:



  • Archer: 3 attack, 2 health


  • Horseman: 7 attack, 5 defense

  • Knight: 4 attack, 4 defense


Then simply total it up and see who wins, eg.


3 archers, 2 horsemen, 4 knights = total of 37 attack, 32 health 3 knights, 5 horsemen = total of 47 attack, 37 health


If (again, simplistic model) both sides inflict damage simultaneously, both armies would die.


If another case occurred where, say, 30/36 health remains in one army, you choose how to distribute that amongst the units to decide which survives and which dies.


This is, as I said, a simple addition/subtraction model; you can add a lot more complexity, such as:



  • Which army attacks first


  • How damage is inflicted (one point to each unit round-robin, or fully on the first unit until it dies, or the strongest, or something else?)

  • Who survives

  • Attack precedence (eg. calculate archer damage first, then knights, then horsemen)

  • etc.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...