Bazaar developer reference

CvStepPathFinder::GetXPlotsFromEnd(PlayerTypes, PlayerTypes, CvPlot *, CvPlot *, int, bool) const

Defined in
CvAStar.cpp, line 3008
Class
CvStepPathFinder
Hook name
CivHooks::CvStepPathFinder_GetXPlotsFromEnd

Hooks

static bool BeforeCvStepPathFinder_GetXPlotsFromEnd(const CvStepPathFinder* self, PlayerTypes ePlayer, PlayerTypes eEnemy, CvPlot* pStartPlot, CvPlot* pEndPlot, int iPlotsFromEnd, bool bLeaveEnemyTerritory, CvPlot*& result);static void AfterCvStepPathFinder_GetXPlotsFromEnd(const CvStepPathFinder* self, PlayerTypes ePlayer, PlayerTypes eEnemy, CvPlot* pStartPlot, CvPlot* pEndPlot, int iPlotsFromEnd, bool bLeaveEnemyTerritory, CvPlot*& result);static CvPlot* ReplaceCvStepPathFinder_GetXPlotsFromEnd(CvPlot* (*original)(const CvStepPathFinder*, PlayerTypes, PlayerTypes, CvPlot*, CvPlot*, int, bool), const CvStepPathFinder* self, PlayerTypes ePlayer, PlayerTypes eEnemy, CvPlot* pStartPlot, CvPlot* pEndPlot, int iPlotsFromEnd, bool bLeaveEnemyTerritory);CivRegisterBefore<CivHooks::CvStepPathFinder_GetXPlotsFromEnd>(host, &BeforeCvStepPathFinder_GetXPlotsFromEnd);CivRegisterAfter<CivHooks::CvStepPathFinder_GetXPlotsFromEnd>(host, &AfterCvStepPathFinder_GetXPlotsFromEnd);CivRegisterReplace<CivHooks::CvStepPathFinder_GetXPlotsFromEnd>(host, &ReplaceCvStepPathFinder_GetXPlotsFromEnd);

Code

3007/// Get the plot X from the end of the step path3008CvPlot* CvStepPathFinder::GetXPlotsFromEnd(PlayerTypes ePlayer, PlayerTypes eEnemy, CvPlot* pStartPlot, CvPlot* pEndPlot, int iPlotsFromEnd, bool bLeaveEnemyTerritory) const3009{3010	CvAStarNode* pNode;3011	CvPlot* currentPlot = NULL;3012	int iNumSteps;3013	int iPathLen;30143015	// Generate step path3016	iPathLen = GC.getStepFinder().GetStepDistanceBetweenPoints(ePlayer, eEnemy, pStartPlot, pEndPlot);3017	iNumSteps = ::min(iPlotsFromEnd, iPathLen);30183019	if(iNumSteps != -1)3020	{3021		pNode = GC.getStepFinder().GetLastNode();30223023		if(pNode != NULL)3024		{3025			// Starting at the end, loop the correct number of times back3026			for(int i = 0; i < iNumSteps; i++)3027			{3028				if(pNode->m_pParent != NULL)3029				{3030					// Move to the previous plot on the path3031					pNode = pNode->m_pParent;3032				}3033			}30343035			CvMap& kMap = GC.getMap();3036			currentPlot = kMap.plotUnchecked(pNode->m_iX, pNode->m_iY);30373038			// Was an enemy specified and we don't want this plot to be in enemy territory?3039			if (eEnemy != NO_PLAYER && bLeaveEnemyTerritory)3040			{3041				// Loop until we leave enemy territory3042				for (int i = 0; i < (iPathLen - iNumSteps) && currentPlot->getOwner() == eEnemy; i++)3043				{3044					if (pNode->m_pParent != NULL)3045					{3046						// Move to the previous plot on the path3047						pNode = pNode->m_pParent;3048						currentPlot = kMap.plotUnchecked(pNode->m_iX, pNode->m_iY);3049					}3050					else3051					{3052						break;3053					}3054				}3055			}3056		}3057	}30583059	return currentPlot;3060}

Calls

Called by