Bazaar developer reference

CvUnitCombat::AttackAirSweep(CvUnit &, CvPlot &, ATTACK_OPTION)

Defined in
CvUnitCombat.cpp, line 3496
Class
CvUnitCombat
Hook name
CivHooks::CvUnitCombat_AttackAirSweep

Hooks

static bool BeforeCvUnitCombat_AttackAirSweep(CvUnit& kAttacker, CvPlot& targetPlot, ATTACK_OPTION arg2, CvUnitCombat::ATTACK_RESULT& result);static void AfterCvUnitCombat_AttackAirSweep(CvUnit& kAttacker, CvPlot& targetPlot, ATTACK_OPTION arg2, CvUnitCombat::ATTACK_RESULT& result);static CvUnitCombat::ATTACK_RESULT ReplaceCvUnitCombat_AttackAirSweep(CvUnitCombat::ATTACK_RESULT (*original)(CvUnit&, CvPlot&, ATTACK_OPTION), CvUnit& kAttacker, CvPlot& targetPlot, ATTACK_OPTION arg2);// CivHooks.h gives this hook point no types, so nothing checks these hooks' parameters.host->RegisterHook(host->pluginIndex, CivHooks::CvUnitCombat_AttackAirSweep::ID, CIV_HOOK_BEFORE, (void*)&BeforeCvUnitCombat_AttackAirSweep);host->RegisterHook(host->pluginIndex, CivHooks::CvUnitCombat_AttackAirSweep::ID, CIV_HOOK_AFTER, (void*)&AfterCvUnitCombat_AttackAirSweep);host->RegisterHook(host->pluginIndex, CivHooks::CvUnitCombat_AttackAirSweep::ID, CIV_HOOK_REPLACE, (void*)&ReplaceCvUnitCombat_AttackAirSweep);

Code

3496CvUnitCombat::ATTACK_RESULT CvUnitCombat::AttackAirSweep(CvUnit& kAttacker, CvPlot& targetPlot, ATTACK_OPTION /* eOption */)3497{3498	//VALIDATE_OBJECT3499	CvAssert(kAttacker.getCombatTimer() == 0);35003501	CvUnitCombat::ATTACK_RESULT eResult = CvUnitCombat::ATTACK_ABORTED;35023503	// Can we actually hit the target?3504	if(!kAttacker.canAirSweepAt(targetPlot.getX(), targetPlot.getY()))3505	{3506		return eResult;3507	}35083509	CvUnit* pInterceptor = kAttacker.GetBestInterceptor(targetPlot);3510	kAttacker.SetAutomateType(NO_AUTOMATE);35113512	// Any interceptor to sweep for?3513	if(pInterceptor != NULL)3514	{3515		// CUSTOMLOG("AttackAirSweep: At (%i, %i) Attacker: %i-%i Interceptor: %i-%i", targetPlot.getX(), targetPlot.getY(), kAttacker.getOwner(), kAttacker.GetID(), pInterceptor->getOwner(), pInterceptor->GetID());3516		kAttacker.setMadeAttack(true);3517		CvCombatInfo kCombatInfo;3518		CvUnitCombat::GenerateAirSweepCombatInfo(kAttacker, pInterceptor, targetPlot, &kCombatInfo);3519		CvUnit* pkDefender = kCombatInfo.getUnit(BATTLE_UNIT_DEFENDER);3520		pkDefender->SetAutomateType(NO_AUTOMATE);3521#if defined(MOD_BUGFIX_UNITS_AWAKE_IN_DANGER)3522		if (MOD_BUGFIX_UNITS_AWAKE_IN_DANGER) {3523			pkDefender->SetActivityType(ACTIVITY_AWAKE, false); 3524		}3525#endif3526		CvAssertMsg(!kAttacker.isDelayedDeath() && !pkDefender->isDelayedDeath(), "Trying to battle and one of the units is already dead!");35273528		uint uiParentEventID = 0;3529		bool bDoImmediate = CvPreGame::quickCombat();3530		if(!bDoImmediate)3531		{3532			// Center camera here!3533			bool isTargetVisibleToActivePlayer = targetPlot.isActiveVisible(false);3534			if(isTargetVisibleToActivePlayer)3535			{3536				auto_ptr<ICvPlot1> pDllTargetPlot = GC.WrapPlotPointer(&targetPlot);3537				GC.GetEngineUserInterface()->lookAt(pDllTargetPlot.get(), CAMERALOOKAT_NORMAL);3538			}3539			kCombatInfo.setVisualizeCombat(isTargetVisibleToActivePlayer);35403541			auto_ptr<ICvCombatInfo1> pDllCombatInfo(new CvDllCombatInfo(&kCombatInfo));3542			uiParentEventID = gDLL->GameplayUnitCombat(pDllCombatInfo.get());35433544			// Set the combat units so that other missions do not continue until combat is over.3545			kAttacker.setCombatUnit(pInterceptor, true);3546			pInterceptor->setCombatUnit(&kAttacker, false);3547			eResult = ATTACK_QUEUED;3548		}3549		else3550			eResult = ATTACK_COMPLETED;35513552		ResolveCombat(kCombatInfo, uiParentEventID);3553	}3554	else3555	{3556		// attempted to do a sweep in a plot that had no interceptors3557		// consume the movement and finish its moves3558		if(kAttacker.getOwner() == GC.getGame().getActivePlayer())3559		{3560			Localization::String localizedText = Localization::Lookup("TXT_KEY_AIR_PATROL_FOUND_NOTHING");3561			localizedText << kAttacker.getUnitInfo().GetTextKey();3562			GC.GetEngineUserInterface()->AddMessage(0, kAttacker.getOwner(), false, GC.getEVENT_MESSAGE_TIME(), localizedText.toUTF8());3563			MILITARYLOG(kAttacker.getOwner(), localizedText.toUTF8(), kAttacker.plot(), kAttacker.getOwner());3564		}35653566		// Spend a move for this attack3567		kAttacker.changeMoves(-GC.getMOVE_DENOMINATOR());35683569		// Can't move or attack again3570		if(!kAttacker.canMoveAfterAttacking())3571		{3572			kAttacker.finishMoves();3573		}3574	}35753576	return eResult;3577}

Calls

Called by