Overlapping Minefields Explode

In the 1:1 case, i.e. two hostile minefields overlapping, the following formula is used:

Mines_exploding =
   Min(Units_1, Units_2)
                     ...if Dist = 0
   Units_1           ...if A < 0
   Units_2           ...if A > D
   Units_1 - A^2     ...otherwise
   ...with
      D = Distance between minefield centers
      A = (Units_1 - Units_2 + D^2) / (2*D)
      Units_1, Units_2 =
          Number of mine units contained in both fields

This formula is used with AlternativeMinesDestroyMines enabled when a minefield is laid or enlarged and overlaps an old one.

During the Mines destroy Mines stage of host processing, PHost uses more complicated formulas. The basic ideas are the following: a minefield that overlaps N hostile minefields shrinks at a speed of N minefield units per time unit. For each minefield pair, we can therefore compute the time until the overlap is gone. PHost now computes the minimum such time, and removes N * Time units from all minefields. At least one overlap is gone now. All the speeds are now recomputed, and the algorithm restarts if overlaps remain.

Time_until_overlap_gone =
   Min(U1 / S1, U2 / S2)
                     ...if D=0
                        (i.e. concentric minefields)
   U1 / S1           ...if U2*S1 - U1*S2 ≥ D^2 * S1
                        (i.e. field 2 eliminates field 1 completely)
   U2 / S2           ...if U1*S2 - U2*S1 ≥ D^2 * S2
                        (i.e. field 1 eliminates field 2 completely)
   (U1 - A^2) / S1   ...if S1 = S2
   ((U1-U2-D^2)*S1 - (U1-U2+D^2)*S2 + 2*Sqrt(D^2 * (U2*S1^2 - (U1+U2-D^2)*S1*S2 + U1*S2^2)))
     / (S1 - S2)^2   ...otherwise
   ...with
      D = Distance between minefield centers
      A = (U1 - U2 + D^2) / (2*D)
      U1,U2 = Mine units in both fields (Units_1, Units_2)
      S1,S2 = Shrink speeds, i.e. overlap counts for both fields

The frightening last formula is the solution to Sqrt(U1 - S1*x) + Sqrt(U2 - S2*x) = D obtained using Mathematica.

PHost's actual implementation is heavily optimized for speed. In addition, to guarantee reasonable progress, it always advances time by at least one full unit, which can make a minefield lose a handful more units than required to remove all overlaps.

This is a testing version.
It may be incomplete, and have more bugs (or features) than the public live version at planetscentral.com.