1. When a player chooses to attack, you send in certain attack options.

2. The game will calculate the total amount of destruction that can be made by the players chosen units, while our code also takes into account the type of units they send, their attacks (which depends on the units level and attack bonuses (for their current civilization).

Then the game calculates the amount of destruction that can be made by siege. It takes into account all 3 types of siege, which then calculates the level of each siege used.


The calculations are made: amount times the (attacklevel + attack bonus) and then it sums up for all units and sieges. (I cannot give you the actual calculation as that is part of the game for you to figure out, so please do not ask).

3. The destruction that can be made by the units of the defender are calculating in the same manner as in the point 2. The game calculates the amount of destructions that can be made by the siege (same as in point 2), but we take into account only siege 1 and siege 3.

By the same formula the amount of destruction which can be made by the buildings are calculated too (we take into account towers and castles).

4. The calculating of destruction of units of defender after the attack:

    4.1 The game calculates the amount of types of units of the defender.
    4.2 Then the game calculates the amount of destruction of defender for one type of units by the formula :
    amount-of-destructions-made-by-units-of-attacker divided by the amount-of-types-of-units-of-defender
    4.3. Then the game calculates the amount of hitpoints by each type of units. By the formula: amount-of-hitpoints-of-this-unit times (100+bonus-hitpoints-of-this-unit) divided by 100. Also the hitpoints for each siege are calculated by the same formula.
    4.4. Then the game calculates the amount of units who stay alive by each type by formula: (hitpoints-by-each-type-of-units – the-amount-of-destructions-of-the-defender-for-one-sort-of-unit) divided by hitpoints-of-this-unit times (100+bonus-hitpoints-of-this-unit) divided by 100
    4.5. Then the amount of killed units of the defender by each type of units is calculated by the formula: amount-of-units-before-attack minus amount-of-stay-alive-after-attack If the amount of killed is more then the amount of units before the attack, the amount of killed became equal to the amount of units before the attack for each type of units of the defender.

5. If the amount of the destruction which the attacker can make with the siege is greater the zero, then:

    5.1. The amount of types of buildings of the defender is calculated.
    5.2. Then the amount of destruction of the defender per one type of unit is calculated by the formula: the-amount-of-the-destructions-made-by-the-siege-of-the-attacker divided by the amount-of-types-of-buildings-of-the-defender
    5.3. Then the game calculate hitpoints per each type of buildings. By this formula: amount-of-buildings-of-one-type times hitpoints-of-this-building times (100+bonus-hitpoints-of-this-building) divided by 100. Then the hitpoints per each siege is calculated by the same formula.
    5.4. The game detects the amount of the survived after the attack buildings of the defender by the formula: (hitpoints-per-each-type-of-building minus the-amount-of-destructions-per-one-type-of-building) divided by hitpoints-of-this-building minus (100+bonus-hitpoints-of-this-building) divided by 100
    5.5. The game detect the amount of the destroyed buildings of the defender per each type by the formula: the-amount-of-buildings-before-attack minus the-amount-of-the-survive-buildings. If the amount of the destroyed buildings is greater then the amount of buildings before the attack, the amount of destroyed became equal to the amount of buildings before the attack per each type of buildings of the defender.

6. By the same formulas as in point 4. the amount of survived units of the attacker is calculated.

7. The data about killed units of the defender by each type of units is displayed, if there are killed units in this type.

8. The data about destroyed buildings of the defender by each type of buildings is displayed, if there are destroyed buildings of this type.

9. The game calculates the amount of the converted villagers of the defender by the monks of the attacker.

10. The amount of the alive and and killed units of the attacker by each type of the unit is displayed.

11. The calculation of the amount of the villagers after the attack.

    11.1. If the amount of the converted villagers is greater then zero, then
    11.1.1 If the amount of the converter villagers is greater the then the amount of idle villagers of the defender then:

From the amount of idle villagers of the defenders the game subtracts the amount of the converted by the attacker and then goes to the next type of villagers. If the amount of the converted villagers is greater then the defender has idle villagers, then the amount of the converted is decreasing on the amount of the idle villagers and the amount of the idle villagers of the defender becomes equal to zero.
Else: from the amount of idle villagers the game subtracts the amount of converted villagers and amount of the converted becomes equal to zero. And then the same things for sminer, lumberjack, gminer, farmer.

12. The amount of the survive units and buildings is calculated by the formula: was-before-attack minus was-lost-because-of-attack.

13. The game checks that the amount by every type of unit and every type of building be greater then zero. If this condition is ok then the changed data for defender is moved to DB , i.e. the amount of units per each type and the amount of buildings per each type of buildings.

14. Same as in point 13 for units of the attacker.

15. The data about the made attack is formed for the defender with sending him a message.

16. The data for defender about mostVillagers and mostWarunits is recalculated.

17. The data for attacker about mostWarunits is recalculated.