Hooks
static bool BeforePathAdd(CvAStarNode* parent, CvAStarNode* node, int data, const void* pointer, CvAStar* finder, int& result);static void AfterPathAdd(CvAStarNode* parent, CvAStarNode* node, int data, const void* pointer, CvAStar* finder, int& result);static int ReplacePathAdd(int (*original)(CvAStarNode*, CvAStarNode*, int, const void*, CvAStar*), CvAStarNode* parent, CvAStarNode* node, int data, const void* pointer, CvAStar* finder);CivRegisterBefore<CivHooks::PathAdd>(host, &BeforePathAdd);CivRegisterAfter<CivHooks::PathAdd>(host, &AfterPathAdd);CivRegisterReplace<CivHooks::PathAdd>(host, &ReplacePathAdd);
Code
1550/// Standard path finder - add a new path1551int PathAdd(CvAStarNode* parent, CvAStarNode* node, int data, const void* pointer, CvAStar* finder)1552{1553 int iMoves = MAX_INT;1554 CvUnit* pUnit = ((CvUnit*)pointer);1555 const UnitPathCacheData* pCacheData = reinterpret_cast<const UnitPathCacheData*>(finder->GetScratchBuffer());15561557 int iTurns;15581559 if(data == ASNC_INITIALADD)1560 {1561 iTurns = 1;1562 iMoves = std::min(iMoves, pUnit->movesLeft());1563 }1564 else1565 {1566 CvMap& kMap = GC.getMap();1567 CvPlot* pFromPlot = kMap.plotUnchecked(parent->m_iX, parent->m_iY);1568 CvPlot* pToPlot = kMap.plotUnchecked(node->m_iX, node->m_iY);15691570 int iStartMoves = parent->m_iData1;1571 iTurns = parent->m_iData2;15721573 if(iStartMoves == 0)1574 {1575 iTurns++;1576 iStartMoves = pCacheData->baseMoves((pToPlot->isWater() && !pToPlot->IsAllowsWalkWater()) ? DOMAIN_SEA : DOMAIN_LAND) * GC.getMOVE_DENOMINATOR();1577 }15781579 // We can't use maxMoves, because that checks where the unit is currently, and we're plotting a path so we have to see1580 // what the max moves would be like if the unit was already at the desired location.1581 if (CvUnitMovement::ConsumesAllMoves(pUnit, pFromPlot, pToPlot) || CvUnitMovement::IsSlowedByZOC(pUnit, pFromPlot, pToPlot))1582 {1583 iMoves = 0;1584 }1585 else1586 {1587 iMoves = std::min(iMoves, std::max(0, iStartMoves - CvUnitMovement::MovementCost(pUnit, pFromPlot, pToPlot, pCacheData->baseMoves((pToPlot->isWater() || pCacheData->isEmbarked())?DOMAIN_SEA:pCacheData->getDomainType()), pCacheData->maxMoves(), iStartMoves)));1588 }1589 }15901591 FAssertMsg(iMoves >= 0, "iMoves is expected to be non-negative (invalid Index)");15921593 node->m_iData1 = iMoves;1594 node->m_iData2 = iTurns;15951596 return 1;1597}