Bazaar developer reference

CvUnit::canHeal(const CvPlot *, bool) const

Defined in
CvUnit.cpp, line 5612
Class
CvUnit
Hook name
CivHooks::CvUnit_canHeal

Hooks

static bool BeforeCvUnit_canHeal(const CvUnit* self, const CvPlot* pPlot, bool bTestVisible, bool& result);static void AfterCvUnit_canHeal(const CvUnit* self, const CvPlot* pPlot, bool bTestVisible, bool& result);static bool ReplaceCvUnit_canHeal(bool (*original)(const CvUnit*, const CvPlot*, bool), const CvUnit* self, const CvPlot* pPlot, bool bTestVisible);CivRegisterBefore<CivHooks::CvUnit_canHeal>(host, &BeforeCvUnit_canHeal);CivRegisterAfter<CivHooks::CvUnit_canHeal>(host, &AfterCvUnit_canHeal);CivRegisterReplace<CivHooks::CvUnit_canHeal>(host, &ReplaceCvUnit_canHeal);

Code

5612bool CvUnit::canHeal(const CvPlot* pPlot, bool bTestVisible) const5613{5614	VALIDATE_OBJECT56155616	// No barb healing5617	if(isBarbarian())5618	{5619		return false;5620	}56215622	if(!IsHurt())5623	{5624		return false;5625	}56265627	if(isWaiting())5628	{5629		return false;5630	}56315632	if(healRate(pPlot) <= 0)5633	{5634		return false;5635	}5636	5637	// JON - This should change when one-unit-per-plot city stuff is handled better5638	// Unit Healing in cities56395640	if(isHuman())5641	{5642		if(plot()->isCity() && getDomainType() != DOMAIN_AIR)5643		{5644#if defined(MOD_BUGFIX_MINOR)5645			// Civilians can heal in cities5646			if (!IsCivilianUnit())5647			{5648#endif56495650				CvUnit* pUnit;5651				int iBestDefenderValue = 0;5652				int iBestDefenderID = 0;56535654				for(int iUnitLoop = 0; iUnitLoop < plot()->getNumUnits(); iUnitLoop++)5655				{5656					pUnit = plot()->getUnitByIndex(iUnitLoop);56575658					// Only check land Units vs one another, Naval Units vs one another, etc.5659					if(pUnit->getDomainType() == getDomainType())5660					{5661						if(pUnit->GetBaseCombatStrength() > iBestDefenderValue)5662						{5663							iBestDefenderValue = pUnit->GetBaseCombatStrength();5664							iBestDefenderID = pUnit->GetID();5665						}5666					}5667				}56685669				// This is NOT the defending unit, it's in storage, so it can't heal5670				if(iBestDefenderID != GetID())5671				{5672					return false;5673				}5674#if defined(MOD_BUGFIX_MINOR)5675			}5676#endif5677		}5678	}56795680	// Unit now has to be able to Fortify to Heal (since they're very similar states, and Heal gives a defense bonus)5681	if(!bTestVisible)5682	{5683		// Embarked Units can't heal5684		if(isEmbarked())5685		{5686			return false;5687		}56885689		// Boats can only heal in friendly territory (without promotion)5690		if(getDomainType() == DOMAIN_SEA)5691		{5692			if(!IsInFriendlyTerritory() && !isHealOutsideFriendly())5693			{5694				return false;5695			}5696		}5697	}56985699	return true;5700}

Calls

Called by