Bazaar developer reference

CvUnit::healRate(const CvPlot *) const

Defined in
CvUnit.cpp, line 5734
Class
CvUnit
Hook name
CivHooks::CvUnit_healRate

Hooks

static bool BeforeCvUnit_healRate(const CvUnit* self, const CvPlot* pPlot, int& result);static void AfterCvUnit_healRate(const CvUnit* self, const CvPlot* pPlot, int& result);static int ReplaceCvUnit_healRate(int (*original)(const CvUnit*, const CvPlot*), const CvUnit* self, const CvPlot* pPlot);CivRegisterBefore<CivHooks::CvUnit_healRate>(host, &BeforeCvUnit_healRate);CivRegisterAfter<CivHooks::CvUnit_healRate>(host, &AfterCvUnit_healRate);CivRegisterReplace<CivHooks::CvUnit_healRate>(host, &ReplaceCvUnit_healRate);

Code

5734int CvUnit::healRate(const CvPlot* pPlot) const5735{5736	VALIDATE_OBJECT5737	// Boats can only heal in friendly territory5738	if(getDomainType() == DOMAIN_SEA)5739	{5740		if(!IsInFriendlyTerritory() && !isHealOutsideFriendly())5741		{5742			return 0;5743		}5744	}5745	5746#if defined(MOD_UNITS_HOVERING_LAND_ONLY_HEAL)5747	if (MOD_UNITS_HOVERING_LAND_ONLY_HEAL) {5748		// Hovering units can only heal over land5749		if (IsHoveringUnit() && pPlot->isWater()) {5750			return 0;5751		}5752	}5753#endif57545755	const IDInfo* pUnitNode;5756	CvCity* pCity = pPlot->getPlotCity();5757	CvCity* pClosestCity = NULL;5758	const CvUnit* pLoopUnit;5759	CvPlot* pLoopPlot;57605761	int iExtraHeal = 0;5762	int iExtraFriendlyHeal = getExtraFriendlyHeal();5763	int iExtraNeutralHeal = getExtraNeutralHeal();5764	int iExtraEnemyHeal = getExtraEnemyHeal();57655766	// Heal from religion5767	int iReligionMod = 0;5768	if(!pCity)5769	{5770		pClosestCity = pPlot->GetAdjacentFriendlyCity(getTeam());5771	}5772	else5773	{5774		pClosestCity = pCity;5775	}5776	if(pClosestCity && pClosestCity->getOwner() == getOwner())5777	{5778		ReligionTypes eMajority = pClosestCity->GetCityReligions()->GetReligiousMajority();5779		if(eMajority != NO_RELIGION)5780		{5781			const CvReligion* pReligion = GC.getGame().GetGameReligions()->GetReligion(eMajority, getOwner());5782			if(pReligion)5783			{5784				iReligionMod = pReligion->m_Beliefs.GetFriendlyHealChange();5785				BeliefTypes eSecondaryPantheon = pClosestCity->GetCityReligions()->GetSecondaryReligionPantheonBelief();5786				if (eSecondaryPantheon != NO_BELIEF)5787				{5788					iReligionMod += GC.GetGameBeliefs()->GetEntry(eSecondaryPantheon)->GetFriendlyHealChange();5789				}5790				iExtraFriendlyHeal += iReligionMod;5791			}5792		}5793	}57945795	// Heal from units5796	int iBestHealFromUnits = 0;5797	pUnitNode = pPlot->headUnitNode();5798	while(pUnitNode != NULL)5799	{5800		pLoopUnit = ::getUnit(*pUnitNode);5801		pUnitNode = pPlot->nextUnitNode(pUnitNode);58025803		if(pLoopUnit && pLoopUnit->getTeam() == getTeam())5804		{5805			int iHeal = pLoopUnit->getSameTileHeal();58065807			if(iHeal > iBestHealFromUnits)5808			{5809				iBestHealFromUnits = iHeal;5810			}5811		}5812	}5813	for(int iI = 0; iI < NUM_DIRECTION_TYPES; iI++)5814	{5815		pLoopPlot = plotDirection(pPlot->getX(), pPlot->getY(), ((DirectionTypes)iI));58165817		if(pLoopPlot != NULL)5818		{5819			if(pLoopPlot->area() == pPlot->area())5820			{5821				pUnitNode = pLoopPlot->headUnitNode();58225823				while(pUnitNode != NULL)5824				{5825					pLoopUnit = ::getUnit(*pUnitNode);5826					pUnitNode = pLoopPlot->nextUnitNode(pUnitNode);58275828					if(pLoopUnit && pLoopUnit->getTeam() == getTeam())5829					{5830						int iHeal = pLoopUnit->getAdjacentTileHeal();58315832						if(iHeal > iBestHealFromUnits)5833						{5834							iBestHealFromUnits = iHeal;5835						}5836					}5837				}5838			}5839		}5840	}5841	iExtraHeal += iBestHealFromUnits;58425843	// Heal from territory ownership (friendly, enemy, etc.)5844	int iBaseHeal = 0;5845	if(pPlot->isCity())5846	{5847		iBaseHeal = GC.getCITY_HEAL_RATE();5848		iExtraHeal += (GET_TEAM(getTeam()).isFriendlyTerritory(pPlot->getTeam()) ? iExtraFriendlyHeal : iExtraNeutralHeal);5849		if(pCity)5850		{5851			iExtraHeal += pCity->getHealRate();5852		}5853	}5854	else5855	{5856		if(!IsInFriendlyTerritory())5857		{5858			if(isEnemy(pPlot->getTeam(), pPlot))5859			{5860				iBaseHeal = GC.getENEMY_HEAL_RATE();5861				iExtraHeal += iExtraEnemyHeal;5862			}5863			else5864			{5865				iBaseHeal = GC.getNEUTRAL_HEAL_RATE();5866				iExtraHeal += iExtraNeutralHeal;5867			}5868		}5869		else5870		{5871			iBaseHeal = GC.getFRIENDLY_HEAL_RATE();5872			iExtraHeal += iExtraFriendlyHeal;5873		}5874	}58755876	// Base healing rate mod5877	int iBaseHealMod = GET_PLAYER(getOwner()).getUnitBaseHealModifier();5878	if(iBaseHealMod != 0)5879	{5880		iBaseHeal = ((100 + iBaseHealMod) / 100) * iBaseHeal;5881	}5882	CvAssertMsg(iBaseHeal >= 0, "Base healing rate not expected to be negative!");58835884	int iTotalHeal = iBaseHeal + iExtraHeal;58855886	return iTotalHeal;5887}

Calls

Called by