Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
2  
Your question is not entirely clear. What kind of "calculation" are you trying to do? Which side wins? That's going to depend on a lot more than the units in the engagement. You need to know terrain. And if your RTS is going to be worth playing, then the player's micro will be needed. Can the guy with 3 archers kite the horsemen? Do they have room to kite them? Does any side have special abilities that affect movement? –  Nicol Bolas Jan 12 '13 at 4:00
1  
I am sorry, I was talking generally because the idea is an php mmo test project so there are not that much details like "room" and some special conditions. Basically, I sent army to an enemy town and that's it. The only condition would be is the battle in my city or in the city of my enemy. If in my city, then my forces would have an advantage but that's another story, it would be easy to add after I have a basic idea how does, for example, Travian work. –  Nikola R. Jan 12 '13 at 4:08
    
It's still not clear what you're asking. Are you asking how to determine who would win? And if it's just two players sending an army against one another and the fight is all automatic... it's not an RTS. –  Nicol Bolas Jan 12 '13 at 4:11
    
Sir, question was about unit damage / defense calculations in an strategy game. It doesnt have to be strategy game at all, same calculation may apply in games such as Heroes of Might and Magic but that's not a part of a question. What I asked for is the idea and possible ways of calculating who is stronger: group 1 or group 2 –  Nikola R. Jan 12 '13 at 4:13
1  
First, please clarify your question to explain that you're trying to find an algorithm to detect which side is stronger. Second, your question is not answerable, because such an algorithm depends on the specific details of the combat system, which you have not explained. You can't just create a generic "who is stronger" function that can just work it all out. It depends very much on the details of how fighting works. And a listing of stats (which you did not explain the meaning of) isn't enough. –  Nicol Bolas Jan 12 '13 at 4:17
show 3 more comments

closed as not a real question by Nicol Bolas, Trevor Powell, ashes999, Josh Petrie, Byte56 Jan 14 '13 at 23:55

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

up vote 0 down vote accepted

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.
share|improve this answer
    
Thank you for a great answer. Attack and Health attributes are great idea. When the battle finishes, maybe I could get total health after battle for a winning group and distribute random units left, based on their health rules. Accepted. –  Nikola R. Jan 12 '13 at 4:17
    
@user1589168 yes, that's what I'm proposing. It's very simple, and easy to understand, but extensible. –  ashes999 Jan 12 '13 at 4:23
add comment

Speaking broadly, I would invent rules for the game I was designing (including, but not limited to, a procedure by which things such as 'damage' would be calculated), and would then implement these rules in a programming language of some sort.

"How to calculate damage" is not a question you can really outsource to StackExchange; it's a core part of your game -- probably the core part of your game. We can't answer it in an objectively correct way. You need to decide for yourself how you want your game to work.

share|improve this answer
    
Sir I was asking for idea, not for a code piece or something. Basically for opinions and maybe some resource link where I can read more about it. –  Nikola R. Jan 12 '13 at 4:09
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.