- Code:
//Base damage is the unit attack strength + AttackHorse if the enemy is mounted
Damage := gRes.UnitDat[fUnit.UnitType].Attack;
if (fOpponent.UnitType in [low(UnitGroups) .. high(UnitGroups)]) and (UnitGroups[fOpponent.UnitType] = gt_Mounted) then
Damage := Damage + gRes.UnitDat[fUnit.UnitType].AttackHorse;
Damage := Damage * (GetDirModifier(fUnit.Direction,fOpponent.Direction)+1); //Direction modifier
//Defence modifier
Damage := Damage div Math.max(gRes.UnitDat[fOpponent.UnitType].Defence, 1); //Not needed, but animals have 0 defence
IsHit := (Damage >= KaMRandom(101)); //Damage is a % chance to hit
if IsHit then
fOpponent.HitPointsDecrease(1, fUnit);
Translation:
The damage variable is the Attack of the unit (see the chart above for the correct number)
Next it checks if the enemy unit is mounted, if so it adds the modifier of AttackHorse.
Then it takes in consideration the direction
Finally it divides the damage with the defence modifier.
Now it checks with a RNG if there is a hit. If this is the case it decreases the unit's health by 1.
For example:
We have a Militia and a Knight fighting. The Militia looks south and the Knight looks north.
Militia:
Health: 2
Attack: 35
Horse: 0
Defence: 1
Knight:
Health: 4
Attack: 55
Horse: 0
Defence: 3
The damage formula for the Militia:
Damage = Attack = 35
Damage = Damage+AttackHorse = 35+0
Damage = Damage*Direction modifier = 35*1
Damage = Damage/Defence Knight = 35/3
Damage = 11,6
The damage formula for the Knight:
Damage = Attack = 55
Damage = Damage+AttackHorse = 55+0
Damage = Damage*Direction modifier = 55*1
Damage = Damage/Defence Militia = 55/1
Damage = 55
So the Militia it's damage is 11,6 and the Knight's damage is 55. I guess that KamRandom just generates a number between 0 and 101.
So if on a hit the Militia's damage (11,6) is higher than the generated number say for example 10, the Knight gets -1 hitpoint so it has 3 health left.
Practically the Knight will win but in theory the Militia can win aswell. It all depends on RNG/luck. But as you can see, the Knight has a significant higher chance to win. Hopefully this helps you guys.
If my interpretation of the formula is wrong, please correct me.