• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Heroes III Combat System

Status
Not open for further replies.
Level 3
Joined
Mar 5, 2007
Messages
32
Hi,
I'm trying to make a Heroes III combat system. This is just plain math, so you don't have to know the game, I've explained everything I think.


In Heroes III a unit isn't a single unit, but a group of units. The unit (representing a group) has the number of units in the group beside it on the combat screen. The damage dealt has 3 factor; the Damage of the unit, the Attack and the Defence. First the difference between the attacking unit's (group's) Attack and the defending unit's Defence. Defence - Attack. If the Attack is higher than the Defence the damage is increased by 5% per Attack higher (Max 400%). If the Defence is higher the damage is decreased by 2% per Defence higher (Max 30%). When a unit is attacked I don't directly want the hit points of the attacked unit to decrease, seeing that a unit is not just a unit, but a group. I'll add a Floating Text to all the units on the Combat Screen, showing the number of units in the unit group. When an attacker then "kills" a unit, I just want that number to decrease by one or more, depending on the amount of damage dealt. If the attacker doesn't deal enough damage to kill a unit in the group, or does not deal the exact hit points of some units in the group in damage, the unit itself is damaged. (Showing that the top unit of the group has lost hit points.)

So, I'll just apply initials to the different factors:
X = number of units in unit group
A = Attack
D = Defence
HP = Hit Points of defending unit
Dmg = Damage

X*HP = total hit points
X*HP-X*Dmg*(*(A-D)*1.05 or *-1.02)) = Total remaining hit points

OK so what I want is a way to "kill" a number of units in the Floating Text depending on the damage dealt, and then damage the unit itself for the remaining damage. Please tell me if you don't understand.
 
Level 10
Joined
Nov 10, 2004
Messages
351
If i understand you right, then you want to get the amount of units remaining after it has been attacked, while including the remaining hp of the "representing" unit.

When you know what the total remaining hit points is equal to and the amount of hp per unit, then the amount of units left should be:

Remaining HP overall / HP per unit

This will give a real result(with decimals) and you of course don't want to show 6.327 or something like that as the number of units, because there really are 7 units left, where one of them has 32.7% hp left.

To avoid this, we'll first have to check whether the amount of units left is a number with decimals(we'll use the number 6.237 to make it easier) This can be done by simply checking if 6.237 > 6.237(Converted to integer) which is the same as 6.237 > 6.

We basically remove all the decimals when we convert a real to an integer. The reason why we have to know whether 6.327 has any decimals or not, is because if it does have decimals, we have to add 1 onto the 6.327. If it doesn't then it means the "representing" unit has full health.

So since 6.327 does have decimals, we'll add one onto it, so it becomes 7.327. We then convert it to an integer, so we're at 7, which is the amount of units left in the group. We still need to calculate the amount of hp on the "representing" unit however. For this we'll still need the result with decimals(6.327)

To calculate the amount of hp remaining on the "representing" unit, we'll do following:

6.327 - 6.327(converted to integer, meaning no decimals)

So it should look like: 6.327 - 6 = 0.327

Now we have the relative amount of hp left (on the representing unit)

So we just say: 0.327 * Hp per unit.

If every unit in the group has got 100 hp each, then after these calculations there would be 7 units left, where the representing one has got 0.327 * 100 (32.7) hp left.


I know this explaination isn't so easy to understand, so please ask about what you don't understand of it, unless you do understand it all. I hope this atleast gives you an idea of what to do.


I haven't checked this wall of text through so much, so there might be some errors. Please let me know if there are any.

EDIT: Also, i didn't consider attack and defense bonuses in these calculations.
 
Level 3
Joined
Mar 5, 2007
Messages
32
Awesome, that was just the problem :p Ty, I'll test this now :) +rep

Oh, when you convert to integer does it just remove the decimals, even if it's 99,99, so it's 99 ?
 
Status
Not open for further replies.
Top