Bazaar developer reference

CvUnitCombat::GetFireSupportUnit(PlayerTypes, int, int, int, int)

Defined in
CvUnitCombat.cpp, line 3657
Class
CvUnitCombat
Hook name
CivHooks::CvUnitCombat_GetFireSupportUnit

Hooks

static bool BeforeCvUnitCombat_GetFireSupportUnit(PlayerTypes eDefender, int iDefendX, int iDefendY, int iAttackX, int iAttackY, CvUnit*& result);static void AfterCvUnitCombat_GetFireSupportUnit(PlayerTypes eDefender, int iDefendX, int iDefendY, int iAttackX, int iAttackY, CvUnit*& result);static CvUnit* ReplaceCvUnitCombat_GetFireSupportUnit(CvUnit* (*original)(PlayerTypes, int, int, int, int), PlayerTypes eDefender, int iDefendX, int iDefendY, int iAttackX, int iAttackY);CivRegisterBefore<CivHooks::CvUnitCombat_GetFireSupportUnit>(host, &BeforeCvUnitCombat_GetFireSupportUnit);CivRegisterAfter<CivHooks::CvUnitCombat_GetFireSupportUnit>(host, &AfterCvUnitCombat_GetFireSupportUnit);CivRegisterReplace<CivHooks::CvUnitCombat_GetFireSupportUnit>(host, &ReplaceCvUnitCombat_GetFireSupportUnit);

Code

3656//	Return a ranged unit that will defend the supplied location against the attacker at the specified location.3657CvUnit* CvUnitCombat::GetFireSupportUnit(PlayerTypes eDefender, int iDefendX, int iDefendY, int iAttackX, int iAttackY)3658{3659	VALIDATE_OBJECT36603661	if(GC.getFIRE_SUPPORT_DISABLED() == 1)3662		return NULL;36633664	CvPlot* pAdjacentPlot = NULL;3665	CvPlot* pPlot = GC.getMap().plot(iDefendX, iDefendY);36663667	for(int iI = 0; iI < NUM_DIRECTION_TYPES; iI++)3668	{3669		pAdjacentPlot = plotDirection(pPlot->getX(), pPlot->getY(), ((DirectionTypes)iI));36703671		if(pAdjacentPlot != NULL)3672		{3673			for(int iUnitLoop = 0; iUnitLoop < pAdjacentPlot->getNumUnits(); iUnitLoop++)3674			{3675				CvUnit* pLoopUnit = pAdjacentPlot->getUnitByIndex(iUnitLoop);36763677				// Unit owned by same player?3678				if(pLoopUnit->getOwner() == eDefender)3679				{3680					// Can this unit perform a ranged strike on the attacker's plot?3681					if(pLoopUnit->canRangeStrikeAt(iAttackX, iAttackY))3682					{3683						// Range strike would be calculated here, so get the estimated damage3684						return pLoopUnit;3685					}3686				}3687			}3688		}3689	}36903691	return NULL;3692}

Calls

Called by