Bazaar developer reference

CvUnit::IsNearSapper(const CvCity *) const

Defined in
CvUnit.cpp, line 19166
Class
CvUnit
Hook name
CivHooks::CvUnit_IsNearSapper

Hooks

static bool BeforeCvUnit_IsNearSapper(const CvUnit* self, const CvCity* pTargetCity, bool& result);static void AfterCvUnit_IsNearSapper(const CvUnit* self, const CvCity* pTargetCity, bool& result);static bool ReplaceCvUnit_IsNearSapper(bool (*original)(const CvUnit*, const CvCity*), const CvUnit* self, const CvCity* pTargetCity);CivRegisterBefore<CivHooks::CvUnit_IsNearSapper>(host, &BeforeCvUnit_IsNearSapper);CivRegisterAfter<CivHooks::CvUnit_IsNearSapper>(host, &AfterCvUnit_IsNearSapper);CivRegisterReplace<CivHooks::CvUnit_IsNearSapper>(host, &ReplaceCvUnit_IsNearSapper);

Code

19165/// Are we near a friendly unit that is sapping this city?19166bool CvUnit::IsNearSapper(const CvCity* pTargetCity) const19167{19168	VALIDATE_OBJECT1916919170	CvAssertMsg(pTargetCity, "Target city is NULL when checking sapping combat bonus");19171	if (!pTargetCity)19172	{19173		return false;19174	}1917519176	int iSapperRange = GC.getSAPPER_BONUS_RANGE();1917719178	CvPlot* pLoopPlot;19179	IDInfo* pUnitNode;19180	CvUnit* pLoopUnit;1918119182	// Look around this Unit to see if there's a Sapper nearby19183	for(int iX = -iSapperRange; iX <= iSapperRange; iX++)19184	{19185		for(int iY = -iSapperRange; iY <= iSapperRange; iY++)19186		{19187			pLoopPlot = plotXYWithRangeCheck(getX(), getY(), iX, iY, iSapperRange);1918819189			if(pLoopPlot != NULL)19190			{19191				// Units in our plot do not count19192				if (pLoopPlot->getX() == getX() && pLoopPlot->getY() == getY())19193					continue;1919419195				// If there are Units here, loop through them19196				if(pLoopPlot->getNumUnits() > 0)19197				{19198					pUnitNode = pLoopPlot->headUnitNode();1919919200					while(pUnitNode != NULL)19201					{19202						pLoopUnit = ::getUnit(*pUnitNode);19203						pUnitNode = pLoopPlot->nextUnitNode(pUnitNode);1920419205						// Owned by us19206						if(pLoopUnit && pLoopUnit->getOwner() == getOwner())19207						{19208							// Sapper unit19209							if(pLoopUnit->IsSappingCity(pTargetCity))19210							{19211								// Must be same domain19212								if(pLoopUnit->getDomainType() == getDomainType())19213								{19214									return true;19215								}19216							}19217						}19218					}19219				}19220			}19221		}19222	}1922319224	return false;19225}

Calls

Called by