Afforess
The White Wizard
Improved Air interception rewrites the standard BTS air interception formula. Normally, the air interception chance of a given tile is just the best unit's interception chance. So, if you have 5 fighters with 20% interception each, your interception chance is 20%. This is the way BTS works.
Improved Air Interception changes the formula to be dependent on the number of units present and the interception of said units. In the same example as above, with 5 units that have 20% interception chance each, the total interception chance would be 1.0 - 0.80^5. (For those without a calculator, that is ~ 67.232%)
As aircraft become more damaged, their air interception abilities drop, as a factor of their health. A unit with 20% interception, but only 50% health would have an effective interception chance of 10%; and this is correctly reflected in the above formula.
Improved Air Interception does not alter the way combat works, nor the actual results of combat, it just changes the chances of interception.
The changes are too small to be worth a full download. If you do include Improved Air Interception in your mod, please give me credit.
Code:
CvUnit.cpp:
Modified:
Add this function to the end of CvUnit, it is a new addition.
CvUnit.h:
(Functionally, this can go wherever you want in CvUnit.h)
And to the end of GlobalAltDefines.XML:
There are no known bugs, it has been tested and works, and is provided "As Is" with no further support from me. For those who want to try it out first hand w/o compiling a new DLL are welcome to try out my Rise of Mankind Expansion Project, A New Dawn.
Improved Air Interception changes the formula to be dependent on the number of units present and the interception of said units. In the same example as above, with 5 units that have 20% interception chance each, the total interception chance would be 1.0 - 0.80^5. (For those without a calculator, that is ~ 67.232%)
As aircraft become more damaged, their air interception abilities drop, as a factor of their health. A unit with 20% interception, but only 50% health would have an effective interception chance of 10%; and this is correctly reflected in the above formula.
Improved Air Interception does not alter the way combat works, nor the actual results of combat, it just changes the chances of interception.
The changes are too small to be worth a full download. If you do include Improved Air Interception in your mod, please give me credit.

Code:
Spoiler :
CvUnit.cpp:
Modified:
Code:
bool CvUnit::interceptTest(const CvPlot* pPlot)
{
if (GC.getGameINLINE().getSorenRandNum(100, "Evasion Rand") >= evasionProbability())
{
CvUnit* pInterceptor = bestInterceptor(pPlot);
if (pInterceptor != NULL)
{
/************************************************************************************************/
/* Afforess Start 03/6/10 */
/* */
/* Better Air Interception */
/************************************************************************************************/
int iInterceptionOdds = pInterceptor->currInterceptionProbability();
if (GC.getDefineINT("BETTER_AIR_INTERCEPTION"))
iInterceptionOdds = interceptionChance(pPlot);
/************************************************************************************************/
/* Afforess END */
/************************************************************************************************/
if (GC.getGameINLINE().getSorenRandNum(100, "Intercept Rand (Air)") < iInterceptionOdds)
{
fightInterceptor(pPlot, false);
return true;
}
}
}
return false;
}
Add this function to the end of CvUnit, it is a new addition.
Code:
int CvUnit::interceptionChance(const CvPlot* pPlot) const
{
int iValue;
int iLoop;
int iI;
int iNoInterceptionChanceTimes100 = 10000;
CvUnit* pLoopUnit;
for (iI = 0; iI < MAX_PLAYERS; iI++)
{
if (GET_PLAYER((PlayerTypes)iI).isAlive())
{
if (isEnemy(GET_PLAYER((PlayerTypes)iI).getTeam()) && !isInvisible(GET_PLAYER((PlayerTypes)iI).getTeam(), false, false))
{
for(pLoopUnit = GET_PLAYER((PlayerTypes)iI).firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = GET_PLAYER((PlayerTypes)iI).nextUnit(&iLoop))
{
if (pLoopUnit->canAirDefend())
{
if (!pLoopUnit->isMadeInterception())
{
if ((pLoopUnit->getDomainType() != DOMAIN_AIR) || !(pLoopUnit->hasMoved()))
{
if ((pLoopUnit->getDomainType() != DOMAIN_AIR) || (pLoopUnit->getGroup()->getActivityType() == ACTIVITY_INTERCEPT))
{
if (plotDistance(pLoopUnit->getX_INLINE(), pLoopUnit->getY_INLINE(), pPlot->getX_INLINE(), pPlot->getY_INLINE()) <= pLoopUnit->airRange())
{
iValue = pLoopUnit->currInterceptionProbability();
if (iValue > 0 && iValue < 100)
{
iNoInterceptionChanceTimes100 *= (100 - iValue);
iNoInterceptionChanceTimes100 /= 100;
}
else if (iValue >= 100)
return 100;
}
}
}
}
}
}
}
}
}
return 100 - (iNoInterceptionChanceTimes100 / 100);
}
CvUnit.h:
(Functionally, this can go wherever you want in CvUnit.h)
Code:
int interceptionChance(const CvPlot* pPlot) const;
And to the end of GlobalAltDefines.XML:
Code:
<!--Afforess:
Enables Air Interception chances being Multiplicitive. 3 Planes with 20% intercept chance would intercept incoming planes at .80^3 of the time. The Firaxis method is to intercept at highest intercept chance on the tile.-->
<Define>
<DefineName>BETTER_AIR_INTERCEPTION</DefineName>
<iDefineIntVal>1</iDefineIntVal>
</Define>
There are no known bugs, it has been tested and works, and is provided "As Is" with no further support from me. For those who want to try it out first hand w/o compiling a new DLL are welcome to try out my Rise of Mankind Expansion Project, A New Dawn.