The total damage inflicted in an attack is calculated after the following formula:
$ Total Damage=Base Damage*(1+a+b+c+...)*(1-q)*(1-r)*(1-s)*... $, where:
$ Base Damage $ is the damage displayed for every unit in its stats (e.g. 40-50 for a Black Dragon). For a stack of creatures it is calculated as such:
If there are less than 10 creatures in a stack, then a random integer is chosen from the damage range for each creature, and these numbers are added up.
If there are more than 10 creatures in a stack, 10 random integers are chosen from the damage range of the creature type and are added up. The result is multiplied by n/10, where n is the number of creatures in the stack, and rounded down.
The probability that the resulting base damage will be in the lowest/highest 25% is (approximately):
$ a $, $ b $, $ c $,... are damage bonuses
$ q $, $ r $, $ s $,... are damage reductions (both as decimal numbers)