ool CvUnit::interceptTest(const CvPlot* pPlot)
{
CvUnit* pInterceptor;
CvWString szBuffer;
int iOurInterceptProb;
int iTheirInterceptProb;
int iOurDamage;
int iTheirDamage;
if (GC.getGameINLINE().getSorenRandNum(100, "Evasion Rand") >= evasionProbability())
{
pInterceptor = bestInterceptor(pPlot);
if (pInterceptor != NULL)
{
iOurInterceptProb = currInterceptionProbability();
iTheirInterceptProb = pInterceptor->currInterceptionProbability();
if (GC.getGameINLINE().getSorenRandNum(100, "Intercept Rand (Air)") < iTheirInterceptProb)
{
iOurDamage = 0;
iTheirDamage = 0;
if ((pInterceptor->getDomainType() == DOMAIN_AIR) && (GC.getGameINLINE().getSorenRandNum(100, "Intercept Rand (Air)") < (iOurInterceptProb / 5)))
{
iTheirDamage = min(100, GC.getGameINLINE().getSorenRandNum(iOurInterceptProb, "Their Interception Damage Rand"));
}
else if (GC.getGameINLINE().getSorenRandNum(100, "Intercept Rand (Air)") < (iTheirInterceptProb / 3))
{
iOurDamage = currHitPoints();
}
else
{
iOurDamage = min(100, (GC.getGameINLINE().getSorenRandNum(iTheirInterceptProb, "Our Interception Damage Rand #1") + GC.getGameINLINE().getSorenRandNum(iTheirInterceptProb, "Our Interception Damage Rand #2")));
}
if (pPlot->isActiveVisible(false))
{
gDLL->getEntityIFace()->RemoveUnitFromBattle(pInterceptor);
CvAirMissionDefinition kAirMission;
kAirMission.eMissionType = MISSION_AIRSTRIKE;
kAirMission.pkUnits[BDU_ATTACKER] = this;
kAirMission.pkUnits[BDU_DEFENDER] = pInterceptor;
kAirMission.iDamage[BDU_ATTACKER] = iOurDamage;
kAirMission.iDamage[BDU_DEFENDER] = iTheirDamage;
kAirMission.pkPlot = pPlot;
kAirMission.fMissionTime = GC.getMissionInfo(MISSION_AIRSTRIKE).getTime() * gDLL->getSecsPerTurn();
gDLL->getEntityIFace()->AddMission(kAirMission);
}
changeDamage(iOurDamage, pInterceptor->getOwnerINLINE());
pInterceptor->changeDamage(iTheirDamage, getOwnerINLINE());
changeMoves(GC.getMOVE_DENOMINATOR());
pInterceptor->setMadeInterception(true);
if (pInterceptor->getDomainType() == DOMAIN_AIR)
{
pInterceptor->finishMoves();
}
if (iTheirDamage > 0)
{
pInterceptor->getGroup()->clearMissionQueue();
}
if (isDead())
{
szBuffer = gDLL->getText("TXT_KEY_MISC_YOU_SHOT_DOWN_ENEMY", pInterceptor->getNameKey(), getNameKey(), GET_PLAYER(getOwnerINLINE()).getCivilizationAdjectiveKey());
gDLL->getInterfaceIFace()->addMessage(pInterceptor->getOwnerINLINE(), false, GC.getDefineINT("EVENT_MESSAGE_TIME"), szBuffer, "AS2D_INTERCEPT", MESSAGE_TYPE_INFO, GC.getUnitInfo(getUnitType()).getButton(), (ColorTypes)GC.getInfoTypeForString("COLOR_GREEN"), pPlot->getX_INLINE(), pPlot->getY_INLINE(), true, true);
szBuffer = gDLL->getText("TXT_KEY_MISC_YOU_UNIT_SHOT_DOWN", getNameKey(), pInterceptor->getNameKey());
gDLL->getInterfaceIFace()->addMessage(getOwnerINLINE(), true, GC.getDefineINT("EVENT_MESSAGE_TIME"), szBuffer, "AS2D_INTERCEPTED", MESSAGE_TYPE_INFO, GC.getUnitInfo(pInterceptor->getUnitType()).getButton(), (ColorTypes)GC.getInfoTypeForString("COLOR_RED"), pPlot->getX_INLINE(), pPlot->getY_INLINE());
}
else if (pInterceptor->isDead())
{
szBuffer = gDLL->getText("TXT_KEY_MISC_YOU_SHOT_DOWN_ENEMY", getNameKey(), pInterceptor->getNameKey(), GET_PLAYER(pInterceptor->getOwnerINLINE()).getCivilizationAdjectiveKey());
gDLL->getInterfaceIFace()->addMessage(getOwnerINLINE(), true, GC.getDefineINT("EVENT_MESSAGE_TIME"), szBuffer, "AS2D_INTERCEPT", MESSAGE_TYPE_INFO, GC.getUnitInfo(pInterceptor->getUnitType()).getButton(), (ColorTypes)GC.getInfoTypeForString("COLOR_GREEN"), pPlot->getX_INLINE(), pPlot->getY_INLINE(), true, true);
szBuffer = gDLL->getText("TXT_KEY_MISC_YOU_UNIT_SHOT_DOWN", pInterceptor->getNameKey(), getNameKey());
gDLL->getInterfaceIFace()->addMessage(pInterceptor->getOwnerINLINE(), false, GC.getDefineINT("EVENT_MESSAGE_TIME"), szBuffer, "AS2D_INTERCEPTED", MESSAGE_TYPE_INFO, GC.getUnitInfo(getUnitType()).getButton(), (ColorTypes)GC.getInfoTypeForString("COLOR_RED"), pPlot->getX_INLINE(), pPlot->getY_INLINE());
}
else if (iOurDamage > 0)
{
szBuffer = gDLL->getText("TXT_KEY_MISC_YOU_HURT_ENEMY_AIR", pInterceptor->getNameKey(), getNameKey(), -(iOurDamage), GET_PLAYER(getOwnerINLINE()).getCivilizationAdjectiveKey());
gDLL->getInterfaceIFace()->addMessage(pInterceptor->getOwnerINLINE(), false, GC.getDefineINT("EVENT_MESSAGE_TIME"), szBuffer, "AS2D_INTERCEPT", MESSAGE_TYPE_INFO, GC.getUnitInfo(getUnitType()).getButton(), (ColorTypes)GC.getInfoTypeForString("COLOR_GREEN"), pPlot->getX_INLINE(), pPlot->getY_INLINE(), true, true);
szBuffer = gDLL->getText("TXT_KEY_MISC_YOU_AIR_UNIT_HURT", getNameKey(), pInterceptor->getNameKey(), -(iOurDamage));
gDLL->getInterfaceIFace()->addMessage(getOwnerINLINE(), true, GC.getDefineINT("EVENT_MESSAGE_TIME"), szBuffer, "AS2D_INTERCEPTED", MESSAGE_TYPE_INFO, GC.getUnitInfo(pInterceptor->getUnitType()).getButton(), (ColorTypes)GC.getInfoTypeForString("COLOR_RED"), pPlot->getX_INLINE(), pPlot->getY_INLINE());
}
else if (iTheirDamage > 0)
{
szBuffer = gDLL->getText("TXT_KEY_MISC_YOU_HURT_ENEMY_AIR", getNameKey(), pInterceptor->getNameKey(), -(iTheirDamage), GET_PLAYER(pInterceptor->getOwnerINLINE()).getCivilizationAdjectiveKey());
gDLL->getInterfaceIFace()->addMessage(getOwnerINLINE(), true, GC.getDefineINT("EVENT_MESSAGE_TIME"), szBuffer, "AS2D_INTERCEPT", MESSAGE_TYPE_INFO, GC.getUnitInfo(pInterceptor->getUnitType()).getButton(), (ColorTypes)GC.getInfoTypeForString("COLOR_GREEN"), pPlot->getX_INLINE(), pPlot->getY_INLINE(), true, true);
szBuffer = gDLL->getText("TXT_KEY_MISC_YOU_AIR_UNIT_HURT", pInterceptor->getNameKey(), getNameKey(), -(iTheirDamage));
gDLL->getInterfaceIFace()->addMessage(pInterceptor->getOwnerINLINE(), false, GC.getDefineINT("EVENT_MESSAGE_TIME"), szBuffer, "AS2D_INTERCEPTED", MESSAGE_TYPE_INFO, GC.getUnitInfo(getUnitType()).getButton(), (ColorTypes)GC.getInfoTypeForString("COLOR_RED"), pPlot->getX_INLINE(), pPlot->getY_INLINE());
}
return true;
}
}
}
return false;