Meteor Defence

Meteor Shower Frequency
A meteor shower spawns after a timer with a random duration expires. The timer is reset each time there is a meteor shower. The timer duration is a random number between 1 and whatever the meteor frequency mod setting is (defaults to 20).

The random time between showers means you can't always be sure that your defences will be recharged before the next one. Although it can be good to have backup defences you need to factor that risk against the constant power draw.

Currently all (occupied) surfaces have meteor showers simultaneously, but this is planned to change.

Meteor Count
The number of meteors is geometrically distributed with parameter 50%, so you have a 50% chance for 1 meteor, 25% for 2 and so on.

The probabilities for each number of meteors are:
 * 1) 50%
 * 2) 25%
 * 3) 12.5%
 * 4) 6.25%
 * 5) 3.125%
 * 6) 1.5625%
 * 7) 0.78125%
 * 8) 0.390625%
 * 9) 0.1953125%
 * 10) 0.09765625%
 * The probability of getting 11 or more meteors is 0.09765625% = (1 - 0.5)10

Meteor Defenses
All meteor defenses need ammunition and power. Then need to charge up before they can fire. While charging the energy requirement is increased. When fully charged there is a passive power draw to keep it ready.

The Meteor Point Defense has a range of radius 64 tiles. This is good and bad. The bad is that it won't protect everything. The good is that it won't waste shots on things that don't matter. It is good for protecting high value locations like reactors, warehouses, and rocket silos. They can also have 4 shots loaded and charged, each with 50% accuracy.

Meteor Defense Installations have unlimited range and 80% accuracy. They will try to protect the entire surface AND orbit. This means they will waste shots on protecting areas that don't matter. Meteor Defense Installations need 2Gj to fully charge to fire. They draw 20Mw when charging then 5Mw passively. Meteor Defense Installations are automatically considered "Disabled by script" until a meteor enters the systems range, when it will become active.

Defenses fire in sequence to see if they hit. If there are still meteors left then the next defense fires until there are no meteors left, or no defenses that can fire. Ammo and energy is not wasted firing at meteors that have already been destroyed.

Installation Confidence
Since there is a geometrically-decreasing chance of large meteor showers, installation effectiveness also drops off. However, since each installation does not have a guaranteed hit a certain buffer is sensible. To this end, here is a table that shows how confident you can be that a given number of installations will block any number of meteors in a shower. Script and calculations shown below.

Python code
from scipy.special import comb

installations = list(range(1, 17))

print("Installation Count\tDefense Chance") print("========================================")

for installation in installations: # Can defend against up to "installation" meteors, after that chance is zero possible_meteors = list(range(1, installation + 1))

# Defense chance is all the ways the given number of installations # can destroy up to the given number of meteors # Since meteor count is strictly equal to or less than the number of installations, # if there are excess meteors those will get through, so this will never return 100% defense_chance = 0 for meteor in possible_meteors: # Chance of this many meteors is 50% per meteor, geometrically meteor_swarm_chance = 0.5 ** meteor # Installation hits must cover at least the number of meteors, up to the maximum # of "installation" available - this assumes each installation can destroy at most one meteor hits = list(range(meteor, installation + 1)) for hit in hits: # How many ways can this many installations have this many hits, # assuming at most one meteor hit per installation (binomial coefficient) combinations = comb(installation, hit) # Chance of successful defense is chance of this many meteors times # count of ways to have enough installations hit a meteor, while the rest miss #print(f"Installations: {installation} with {hit} hits has combinations {combinations}, given {meteor} meteor(s) with swarm chance {meteor_swarm_chance}") #print(round(100 * meteor_swarm_chance * combinations * (0.8 ** hit) * (0.2 ** (installation - hit)), 2)) defense_chance += meteor_swarm_chance * combinations * (0.8 ** hit) * (0.2 ** (installation - hit)) print(f"{installation}\t\t\t{round(defense_chance * 100, 2)}%")

Explanation
The chance for a given number of installations to destroy some number of meteors is given by: Sum of (chance of meteors) x (chance of all meteors being destroyed), for any number of meteors up to the number of installations present

Variables: - I = number of installations - M = number of meteors - H = number of hits (can exceed number of meteors, but not number of installations)

The chance for all meteors being destroyed is equal to summing the following: For M = 1 to I meteors in the storm For H = M to I hits on the meteors (chance of meteors) * (# ways can we have H hits on I installations) * (chance to hit) * (chance of misses)

Reasoning/details:

M = 1 to I: Since each installation can only shoot down one meteor, the probability of completely destroying meteors beyond I is 0

H = M to I: All meteors are required to be destroyed, so the lowest possible hits is equal to the number of meteors Since mathematically every installation has a chance of hitting even though the meteors are already destroyed, the maximum is the number of installations This is required for the binomial distribution to evaluate correctly even though it doesn't make "real-world sense"; if you have three coins and want two heads, statistically you can't ignore the third result just because the first two came up heads.

Chance of meteors   = 0.5^M (as explained above) E.g. 3 installations, two meteors + two hits could result in 3 ways those two meteors are shot down 3 choose 2 = [1 2] [2 3] [1 3] (Since hits are summed from M to I, in the possibility all 3 installations hit the two meteors is also included) Chance to hit       = 80%^H Chance of misses    = 80%^(I-H)
 * 1) ways to get H hits = I choose H - binomial coefficient