Hooks
static bool BeforeCvUnitCombat_AttackCity(CvUnit& kAttacker, CvPlot& plot, CvUnitCombat::ATTACK_OPTION eOption, CvUnitCombat::ATTACK_RESULT& result);static void AfterCvUnitCombat_AttackCity(CvUnit& kAttacker, CvPlot& plot, CvUnitCombat::ATTACK_OPTION eOption, CvUnitCombat::ATTACK_RESULT& result);static CvUnitCombat::ATTACK_RESULT ReplaceCvUnitCombat_AttackCity(CvUnitCombat::ATTACK_RESULT (*original)(CvUnit&, CvPlot&, CvUnitCombat::ATTACK_OPTION), CvUnit& kAttacker, CvPlot& plot, CvUnitCombat::ATTACK_OPTION eOption);// CivHooks.h gives this hook point no types, so nothing checks these hooks' parameters.host->RegisterHook(host->pluginIndex, CivHooks::CvUnitCombat_AttackCity::ID, CIV_HOOK_BEFORE, (void*)&BeforeCvUnitCombat_AttackCity);host->RegisterHook(host->pluginIndex, CivHooks::CvUnitCombat_AttackCity::ID, CIV_HOOK_AFTER, (void*)&AfterCvUnitCombat_AttackCity);host->RegisterHook(host->pluginIndex, CivHooks::CvUnitCombat_AttackCity::ID, CIV_HOOK_REPLACE, (void*)&ReplaceCvUnitCombat_AttackCity);
Code
3580CvUnitCombat::ATTACK_RESULT CvUnitCombat::AttackCity(CvUnit& kAttacker, CvPlot& plot, CvUnitCombat::ATTACK_OPTION eOption)3581{3582 //VALIDATE_OBJECT35833584 ATTACK_RESULT eResult = ATTACK_ABORTED;3585 CvCity* pCity = plot.getPlotCity();3586 CvAssertMsg(pCity != NULL, "If this unit is attacking a NULL city then something funky is goin' down");3587 if(!pCity) return eResult;35883589 kAttacker.SetAutomateType(NO_AUTOMATE);35903591 if(eOption != ATTACK_OPTION_NO_DEFENSIVE_SUPPORT)3592 {3593 // See if the city has some supporting fire to fend off the attacker3594 CvUnit* pFireSupportUnit = GetFireSupportUnit(pCity->getOwner(), pCity->getX(), pCity->getY(), kAttacker.getX(), kAttacker.getY());35953596 ATTACK_RESULT eSupportResult = ATTACK_ABORTED;3597 if(pFireSupportUnit)3598 {3599 eSupportResult = AttackRanged(*pFireSupportUnit, kAttacker.getX(), kAttacker.getY(), CvUnitCombat::ATTACK_OPTION_NO_DEFENSIVE_SUPPORT);3600 // Turn off Fortify Turns, as this is the trigger for whether or not a ranged Unit can provide support fire (in addition to hasMadeAttack)3601 pFireSupportUnit->setFortifyTurns(0);3602 }36033604 if(eSupportResult == ATTACK_QUEUED)3605 {3606 // The supporting unit has queued their attack (against the attacker), we must have the attacker queue its attack.3607 // Also, flag the current mission that the next time through, the defender doesn't get any defensive support.3608 const_cast<MissionData*>(kAttacker.GetHeadMissionData())->iFlags |= MISSION_MODIFIER_NO_DEFENSIVE_SUPPORT;3609 CvUnitMission::WaitFor(&kAttacker, pFireSupportUnit);3610 eResult = ATTACK_QUEUED;3611 }3612 }36133614 if(eResult != ATTACK_QUEUED)3615 {3616 kAttacker.setMadeAttack(true);36173618 // We are doing a non-ranged attack on a city3619 CvCombatInfo kCombatInfo;3620 GenerateMeleeCombatInfo(kAttacker, NULL, plot, &kCombatInfo);3621 CvAssertMsg(!kAttacker.isDelayedDeath(), "Trying to battle and the attacker is already dead!");36223623 // Send the combat message if the target plot is visible.3624 bool isTargetVisibleToActivePlayer = plot.isActiveVisible(false);36253626 uint uiParentEventID = 0;3627 bool bDoImmediate = CvPreGame::quickCombat();3628 if(!bDoImmediate)3629 {3630 // Center camera here!3631 if(isTargetVisibleToActivePlayer)3632 {3633 auto_ptr<ICvPlot1> pDllPlot = GC.WrapPlotPointer(&plot);3634 GC.GetEngineUserInterface()->lookAt(pDllPlot.get(), CAMERALOOKAT_NORMAL);3635 }3636 kCombatInfo.setVisualizeCombat(isTargetVisibleToActivePlayer);36373638 auto_ptr<ICvCombatInfo1> pDllCombatInfo(new CvDllCombatInfo(&kCombatInfo));3639 uiParentEventID = gDLL->GameplayCityCombat(pDllCombatInfo.get());36403641 CvCity* pkDefender = plot.getPlotCity();3642 kAttacker.setCombatCity(pkDefender);3643 if(pkDefender)3644 pkDefender->setCombatUnit(&kAttacker);3645 eResult = ATTACK_QUEUED;3646 }3647 else3648 eResult = ATTACK_COMPLETED;36493650 ResolveCombat(kCombatInfo, uiParentEventID);3651 }3652 return eResult;3653}