Civilization II Combat Calculator

FoxAhead

Warlord
Joined
Sep 7, 2017
Messages
204
Greetings!

I invite you to test the online combat calculator:
https://foxahead.github.io/Civ2-Combat-Calculator/

It is based on the decompilation of the game and the information from the @Knighttime 's Combat Guide v2.0.

Inspired by Melth's Civilization 2 Let's Play:

There are no options depending on the difficulty level of the game, the barbarians options and the sneak attack. And I do not know if I should overcomplicate the calculator with such options.

The simulation was initially needed only to confirm the correctness of calculations related to distributions from the theory of probability, and at the moment the simulation data should completely coincide with the calculated ones. Although you can use the simulation button to warm up your processor or drain the battery of your smartphone.

This description will be updated depending on your questions and comments.
 
Last edited:
I need to keep better track of this forum because I keep missing all the best threads. :bowdown:

There are no options depending on the difficulty level of the game, the barbarians options and the sneak attack. And I do not know if I should overcomplicate the calculator with such options.
My reflex is, "If someone can use it, might as well offer it."
 
This is a very interesting tool. And what is known about the algorithm for rotating units on the same cell? How the game chooses the next defender if the previous one was able to repel the attack, but suffered losses in HP.
If this algorithm is known, then a more complex calculator can be made, where the calculation is carried out not for one unit, but for a combat operation, for example, an assault on a city. We set a list of defenders and select the optimal composition of attackers for them. You can also calculate the chance of success with a known attacking army.
 
This is a very interesting tool. And what is known about the algorithm for rotating units on the same cell? How the game chooses the next defender if the previous one was able to repel the attack, but suffered losses in HP.
I figured this out a little while ago, in order to replicate the standard game behaviour in lua. For each unit, compute:

"rank" = (defenseStrength*currentHitPoints)//maxHitPoints

(// represents integer division, that is make the division, then round down to the nearest integer).

Take the unit with the highest "rank" to defend.

This doesn't always produce the best unit to defend. For example, a full health (non vet, non fortified) marine will have a defensive "rank" of 5 = (5*20)//20. However, a tank with 29/30 hitpoints only have a "rank" of 4: (5*29)//30 = 145//30 = floor(4.833) = 4.
EDIT:
I just realised that for full clarity, I should have included the fact that the "base" combat power is multiplied by 8. (This allows for some 50% bonuses to stick even with rounding down after division.) So,

Marine: 5*8*20//20 = 40

Tank at 29/30 HP: (5*8*29)//30 = 1160//30 = floor(38.67) = 38
 
Last edited:
@FoxAhead
I played around with the calculator a bit. Does it take into account only math so far, or additional rules? For example, it now states that a Nuclear Missile has a 47.11% chance against a Veteran Missile Cruiser in a city with SAM. But in practice it is 100% if there is no SDI nearby. The most interesting thing is that outside the city the chance for a Nuclear missile is generally ridiculous - 15.36%. Although it hits the cruiser with 100% efficiency.
It would also be very interesting to be able to connect this calculator to calculate the balance in modifications with new units. I guess it's enough to replace RULES.txt from the repo, but I don't know if it will work locally.
 
@FoxAhead
I played around with the calculator a bit. Does it take into account only math so far, or additional rules? For example, it now states that a Nuclear Missile has a 47.11% chance against a Veteran Missile Cruiser in a city with SAM. But in practice it is 100% if there is no SDI nearby. The most interesting thing is that outside the city the chance for a Nuclear missile is generally ridiculous - 15.36%. Although it hits the cruiser with 100% efficiency.
It would also be very interesting to be able to connect this calculator to calculate the balance in modifications with new units. I guess it's enough to replace RULES.txt from the repo, but I don't know if it will work locally.
Thank you for your feedback!
Added special rules for nuclear attacks (for unit with Att >= 99).
As for custom RULES.TXT, for now you can just select any unit in the list and tweak its main stats such as Attack, Defense, Hit Points and Fire Power. All other abilities (flags) are inherited from the selected unit.
You can test this application locally either using Live Server extension in VS Code, or just opening index.html in browser with allowed local fileuri (in Firefox about:config, security.fileuri.strict_origin_policy = false).
 
I figured this out a little while ago, in order to replicate the standard game behaviour in lua. For each unit, compute:

"rank" = (defenseStrength*currentHitPoints)//maxHitPoints

(// represents integer division, that is make the division, then round down to the nearest integer).

Take the unit with the highest "rank" to defend.

This doesn't always produce the best unit to defend. For example, a full health (non vet, non fortified) marine will have a defensive "rank" of 5 = (5*20)//20. However, a tank with 29/30 hitpoints only have a "rank" of 4: (5*29)//30 = 145//30 = floor(4.833) = 4.
EDIT:
I just realised that for full clarity, I should have included the fact that the "base" combat power is multiplied by 8. (This allows for some 50% bonuses to stick even with rounding down after division.) So,

Marine: 5*8*20//20 = 40

Tank at 29/30 HP: (5*8*29)//30 = 1160//30 = floor(38.67) = 38
Tried to replicate algorithm from the civ2.exe (MGE) code. Now along with the Effective Defense, the Defender Rank is also calculated and displayed. Note that rank is initialized with the value of effective defense before additionals. Therefore, options such as Coastal Fortress or Helicopter flag are not taken into account in the rank calculating at all. Pikemen flag is simplified just to a +1 modifier. Scrambling city Fighter vs Fighter is duplicated with simple rule for Fighter vs Fighter. Etc.
If this algorithm is known, then a more complex calculator can be made, where the calculation is carried out not for one unit, but for a combat operation, for example, an assault on a city. We set a list of defenders and select the optimal composition of attackers for them. You can also calculate the chance of success with a known attacking army.
Well, this should be some sort of "Civ2 Army Battle Calculator". More complicated tool. No plans to do such.
 
Found another interesting case :).
Marines attack on the city. Is the Coastal Fortress or the City Walls operational? The game says Coastal Fortress is activated. This case can be processed if the Marine attack slot is of type Ocean.
 
Found another interesting case :).
Marines attack on the city. Is the Coastal Fortress or the City Walls operational? The game says Coastal Fortress is activated. This case can be processed if the Marine attack slot is of type Ocean.
You mean Marines attack from the sea unit from the ocean. For example from transporter. They make such called "amphibious assault" into the city with Coastal Fortress? And the game says that "Coastal Fortress is activated"?
I tested that case in-game in the MGE version, and there is no such message. Also there is no such rule in the combat guide.
What do you mean?
 
Yes, you are right. I don't remember where I saw it, maybe in the PlayStation version. Or just wrong :)
 
I used a calculator and made a discovery for myself :) It turns out the Howitzer ignores the Fortification outside the city too. I always thought that its effect only works against the City Walls in the city itself. Howitzers are too strong.
 
Howitzers are too strong.
In some sense they need to be: playing around with this, I realized just how scary mech. infantry are on defence. Veterans parked on hills can hold the line against almost anything; on mountains, they're practically invincible.
 
In some sense they need to be: playing around with this, I realized just how scary mech. infantry are on defence. Veterans parked on hills can hold the line against almost anything; on mountains, they're practically invincible.
Yes, the mechanized infantry is very strong in defense. The Howitzer is the most powerful ground unit and is second only to Missiles. If we consider the case with the city in the Mountains, and SAM + SDI, then except for the Howitzer, no one really can take it. Outside the city, we can use missiles. Therefore, I still tend to have the Howitzer break through the City walls, but not the Fortifications. Unfortunately, this cannot be achieved using the modification, but nevertheless :)
 
@FoxAhead
A little more feedback.
1. Land units can attack ships at sea.
2. Submarines can attack ground units.
Actually, I'm not sure if it's worth fixing. You can leave the math and not complicate the rules, the user himself must understand what he wants. Since the number of different combinations can be large. For example, aircraft outside the city can only be attacked by Fighters, but this does not include Air bases.
3. I tried to run the calculator locally for my mod. I cloned the repo and run index.html but got a blank screen with a "Version 36" caption at the bottom. Tested in google chrome.
 
3. I tried to run the calculator locally for my mod. I cloned the repo and run index.html but got a blank screen with a "Version 36" caption at the bottom. Tested in google chrome.
You can try new version 38. It is possible to load your own RULES.TXT now.
If you still want to test the code locally, you either need Live Server in VS Code, or allow local files in your browser. For Chrome you can try Disable same origin policy. However, keep in mind that these restrictions are security related.
 
Greetings!

I invite you to test the online combat calculator:
https://foxahead.github.io/Civ2-Combat-Calculator/

It is based on the decompilation of the game and the information from the @Knighttime 's Combat Guide v2.0.

Inspired by Melth's Civilization 2 Let's Play:

There are no options depending on the difficulty level of the game, the barbarians options and the sneak attack. And I do not know if I should overcomplicate the calculator with such options.

The simulation was initially needed only to confirm the correctness of calculations related to distributions from the theory of probability, and at the moment the simulation data should completely coincide with the calculated ones. Although you can use the simulation button to warm up your processor or drain the battery of your smartphone.

This description will be updated depending on your questions and comments.
This is interesting. But i wonder about something: Why does attacker get a x8 modifier and defender a x4 modifier? What is this relevant to?
 
This is interesting. But i wonder about something: Why does attacker get a x8 modifier and defender a x4 modifier? What is this relevant to?
This is because the rest x2 modifier is in terrain multiplier.
Integer logic works in the code. Therefore, 1.5 for a Forest, for example, is 3/2. And in order to reduce the number of operations, the divisor 2 was transferred in advance to the base coefficient 8. I.e. 8/2 = 4. And now there is only a divisible 3 left for the Forest.

Another equally interesting question is why the base multiplier was chosen exactly 8. Because of such a small value for small attack and defense values, we have the so-called "defender wins ties" problem.
It means that for Warrior 1A against Warrior 1D, the result is 29% - 71%, defender has a better chance of winning.
But if you increase the attack and defense, the chances become more equal. For example, for 10A against 10D it is already 48% to 52%.
If the multiplier had been initially chosen to be greater than 8, then there would not have been such a bias for weak units.
I think this number came from Civ 1, where there was a 16-bit limit. And such a value of 8 was a good compromise in order to have sufficient granularity of calculations on the one hand, and on the other to avoid overflow during calculation.
 
Last edited:
Top Bottom