Hooks
static bool BeforeIgnoreUnitsPathAdd(CvAStarNode* parent, CvAStarNode* node, int data, const void* pointer, CvAStar* finder, int& result);static void AfterIgnoreUnitsPathAdd(CvAStarNode* parent, CvAStarNode* node, int data, const void* pointer, CvAStar* finder, int& result);static int ReplaceIgnoreUnitsPathAdd(int (*original)(CvAStarNode*, CvAStarNode*, int, const void*, CvAStar*), CvAStarNode* parent, CvAStarNode* node, int data, const void* pointer, CvAStar* finder);CivRegisterBefore<CivHooks::IgnoreUnitsPathAdd>(host, &BeforeIgnoreUnitsPathAdd);CivRegisterAfter<CivHooks::IgnoreUnitsPathAdd>(host, &AfterIgnoreUnitsPathAdd);CivRegisterReplace<CivHooks::IgnoreUnitsPathAdd>(host, &ReplaceIgnoreUnitsPathAdd);
Code
1969/// Ignore units path finder - add a new path1970int IgnoreUnitsPathAdd(CvAStarNode* parent, CvAStarNode* node, int data, const void* pointer, CvAStar* finder)1971{1972 int iTurns;19731974 CvUnit* pUnit = ((CvUnit*)pointer);1975 const UnitPathCacheData* pCacheData = reinterpret_cast<const UnitPathCacheData*>(finder->GetScratchBuffer());1976 int iMoves = MAX_INT;19771978 if(data == ASNC_INITIALADD)1979 {1980 iTurns = 1;1981 iMoves = std::min(iMoves, pUnit->movesLeft());1982 }1983 else1984 {1985 CvPlot* pFromPlot = GC.getMap().plotUnchecked(parent->m_iX, parent->m_iY);1986 CvPlot* pToPlot = GC.getMap().plotUnchecked(node->m_iX, node->m_iY);19871988 int iStartMoves = parent->m_iData1;1989 iTurns = parent->m_iData2;19901991 if(iStartMoves == 0)1992 {1993 iTurns++;1994 iStartMoves = pCacheData->baseMoves((pToPlot->isWater() && !pToPlot->IsAllowsWalkWater()) ? DOMAIN_SEA : DOMAIN_LAND) * GC.getMOVE_DENOMINATOR();1995 }19961997 // We can't use maxMoves, because that checks where the unit is currently, and we're plotting a path so we have to see1998 // what the max moves would be like if the unit was already at the desired location.1999 iMoves = std::min(iMoves, std::max(0, iStartMoves - CvUnitMovement::MovementCostNoZOC(pUnit, pFromPlot, pToPlot, pCacheData->baseMoves((pToPlot->isWater() || pCacheData->isEmbarked())?DOMAIN_SEA:pCacheData->getDomainType()), pCacheData->maxMoves())));2000 }20012002 FAssertMsg(iMoves >= 0, "iMoves is expected to be non-negative (invalid Index)");20032004 node->m_iData1 = iMoves;2005 node->m_iData2 = iTurns;20062007 return 1;2008}