In
this thread it has been revealed by Skasi (actually already 2011) and proven by mostly
TheEloIsALie that current overdrive energy distribution is not ideal. Currently OD energy is distributed proportional to squared mex rates as far as the grid allows it. Connecting mexes can reduce total metal rate, which should actually be avoided by the system in any case.
1. Ideal SolutionTheEloIsALie calculated the ideal distribution of OD energies (e_1,...,e_n) in a grid with n mexes with base rates (m_1,...,m_n) and OD energy E. (I use the same variables as
TheEloIsALie and add some more.) Total mex rates are M_i=gamma(e_i)*m_i with the "Lorentz-factor" gamma(e_i)=sqrt(1+e_i/4).
Current distribution is
e_i=E*m_i²/p, where p=sum_i(m_i²).
If the grid doesn't provide as much energy as it "wants", it gets its maximum and the rest has to be recalculated.
The easiest representation of
TheEloIsALie's ideal solution is
e_i = m_i²*q/p - 4, where q = E + 4n.
I have proven that it is correct, so if you want to
see a proof.. The problem is now that it can produce negative e_i. Those e_i have to be set to 0 and the rest must be recalculated. Thanks to
TheEloIsALie the recalculation is not needed, when "you go through the mexes in ascending order of base income and (...)(i)f that e_i is negative, you subtract m_i² from p and 4 from q and continue." If a mex' e_i is not negative, you can be sure that all following mexes' e_i are not negative, too. The current recalculation when grid is maxed is also needed. Former concerns about the algorithmic efficiency of the ideal solution because of many square roots or recalculations have been eliminated.
I had a look at
the source code and it seems as if overdrive does obey emp and disarm, but not slow dmg. Something like "orgMetal*=spGetUnitRulesParam(unitID,"slowRate")" or else should be written there in line 725 and 755 and maybe others. How can allyTeamMexes be sorted by orgMetal after emp, disarm and slow have been applied and then used in another for-structure? Then you only need to replace current
"mexE = allyE*(orgMetal * orgMetal)/ allyMetalSquared"
by the ideal solution and check if you have to change p and q. Maybe you can save a little if you first check if orgMetal of current mex = orgMetal of previous mex, because this will often be true. Then you can just use e_i of previous mex and if it's 0, change p and q.
(Btw why is there "1+mexE/5" instead of "energyToExtraM(mexE)" in lines 761 and 795?)
2. UnderdriveWhen I thought about how to reduce recalculations and sortings due to negative OD energies e_i in
TheEloIsALie's solution, a really crazy idea came to my mind: Why not leave negative e_i as it is? Call it underdrive. This would only require replacing
"mexE = allyE*(orgMetal * orgMetal)/ allyMetalSquared" by
"mexE = (allyE+4*allyTeamMexes.number())*(orgMetal * orgMetal)/ allyMetalSquared - 4" (not sure about .number())
In most cases it would make no difference. Only when small and big mexes are connected in a grid with low energy, small mexes would be underdriven to provide a little OD energy for the big mexes. The theoretical maximum for the underdrive energy a mex can provide is 4, but usually it will be lower. This could give pylons a little more use, but building generators instead will still be better.
3. SymmetrizationNegative e_i is only possible, because negativity of e_i is not equivalent to negativity of the OD Lorentz-factor's radicand gamma(e_i)=sqrt(1+e_i/4). This can be changed with a symmetrization of the OD function gamma_b(e_i):=1+b*sqrt(e_i), where b is a constant factor that determines the effectivity of OD, for example b=0.3. I found the ideal solution for this and it is exactly the currently implemented solution independently of b! So you would only have to change
"return -1+sqrt(1+(energy*0.25))" in line 256 to
"return b*sqrt(energy)" with a certain b.
This would also solve the problem of extreme OD being too effective atm as it would make low OD more effective and high OD less effective than currently without introducing more complex functions than sqrt (like log). b could also be changed at any time for balance reasons. The break even point of energy, where current OD becomes equally efficient as symmetric OD for a single mex, is at e_i= 4b²/(b²-1/4)² or b=(sqrt(1+e_i/4)-1)/sqrt(e_i).
4. Quantum MechanicsThe whole calculation and especially how adding an assymetry term to the energy (which means the existence of mass in a relativistic sense) creates antimatter (underdrive) reminds me a lot of relativistic quantum mechanics. In the early times of quantum mechanics people also struggled a lot for eliminating the negative energy (underdrive) until they finally had to accept that antimatter exists. The symmetrization is the non-relativistic approximation. It is interesting that the current solution solves the "non-relativistic" approx.
So which of the 3 systems do you prefer? The lower a system's number, the less elegant and more difficult to implement (if not too much) it is, but closer to the current system.