Bazaar developer reference

CvUnit::GeneratePath(const CvPlot *, int, bool, int *) const

Defined in
CvUnit.cpp, line 23873
Class
CvUnit
Hook name
CivHooks::CvUnit_GeneratePath

Hooks

static bool BeforeCvUnit_GeneratePath(const CvUnit* self, const CvPlot* pToPlot, int iFlags, bool bReuse, int* piPathTurns, bool& result);static void AfterCvUnit_GeneratePath(const CvUnit* self, const CvPlot* pToPlot, int iFlags, bool bReuse, int* piPathTurns, bool& result);static bool ReplaceCvUnit_GeneratePath(bool (*original)(const CvUnit*, const CvPlot*, int, bool, int*), const CvUnit* self, const CvPlot* pToPlot, int iFlags, bool bReuse, int* piPathTurns);CivRegisterBefore<CivHooks::CvUnit_GeneratePath>(host, &BeforeCvUnit_GeneratePath);CivRegisterAfter<CivHooks::CvUnit_GeneratePath>(host, &AfterCvUnit_GeneratePath);CivRegisterReplace<CivHooks::CvUnit_GeneratePath>(host, &ReplaceCvUnit_GeneratePath);

Code

23872/// Use pathfinder to create a path23873bool CvUnit::GeneratePath(const CvPlot* pToPlot, int iFlags, bool bReuse, int* piPathTurns) const23874{23875	VALIDATE_OBJECT23876	// slewis - a bit of baffling logic23877	// we want to catch if the unit is doing a partial move while it is evaluating a mission, because that hoses things23878	CvAssertMsg(!(IsDoingPartialMove() && m_iFlags & UNITFLAG_EVALUATING_MISSION), "Repathing during a partial move will cause serious issues!");2387923880	CvAssertMsg(pToPlot != NULL, "Passed in a NULL destination to GeneratePath");23881	if(pToPlot == NULL)23882		return false;2388323884	bool bSuccess;2388523886	CvTwoLayerPathFinder& kPathFinder = GC.getPathFinder();2388723888	bSuccess = kPathFinder.GenerateUnitPath(this, getX(), getY(), pToPlot->getX(), pToPlot->getY(), iFlags, bReuse);2388923890	// Regardless of whether or not we made it there, keep track of the plot we tried to path to.  This helps in preventing us from trying to re-path to the same unreachable location.23891	m_uiLastPathCacheDest = pToPlot->GetPlotIndex();2389223893	CvAStar::CopyPath(kPathFinder.GetLastNode(), m_kLastPath);2389423895	if(m_kLastPath.size() != 0)23896	{23897		CvMap& kMap = GC.getMap();23898		TeamTypes eTeam = getTeam();2389923900		// Get the state of the plots in the path, they determine how much of the path is re-usable.23901		// KWG: Have the path finder do this for us?23902		for (uint uiIndex = m_kLastPath.size(); uiIndex--; )23903		{23904			CvPathNode& kNode = m_kLastPath[uiIndex];23905			CvPlot* pkPlot = kMap.plotCheckInvalid(kNode.m_iX, kNode.m_iY);23906			if (pkPlot)23907			{23908				if (!pkPlot->isVisible(eTeam))23909				{23910					kNode.SetFlag(CvPathNode::PLOT_INVISIBLE);23911					if (uiIndex < (m_kLastPath.size() - 2))23912						m_kLastPath[uiIndex + 1].SetFlag(CvPathNode::PLOT_ADJACENT_INVISIBLE);2391323914					// Also determine the destination visibility.  This will be checked in UnitPathTo to see if the destination's visibility has changed and do a re-evaluate again if it has.23915					// This will help a unit to stop early in its pathing if the destination is blocked.23916					CvPlot* pkPathDest = kMap.plot(m_kLastPath[0].m_iX, m_kLastPath[0].m_iY);23917					if (pkPathDest != NULL && !pkPathDest->isVisible(eTeam))23918						m_kLastPath[0].SetFlag(CvPathNode::PLOT_INVISIBLE);2391923920					break;	// Anything after is 'in the dark' and should be re-evaluated if trying to move a unit into it.23921				}23922			}23923		}23924	}2392523926	if(piPathTurns != NULL)23927	{23928		*piPathTurns = INT_MAX;2392923930		if(bSuccess)23931		{23932			if(m_kLastPath.size() != 0)23933			{23934				*piPathTurns = m_kLastPath.front().m_iData2;23935			}23936		}23937	}2393823939	return bSuccess;23940}

Calls

Called by