Hooks
static bool BeforeCvUnit_move(CvUnit* self, CvPlot& targetPlot, bool bShow);static void AfterCvUnit_move(CvUnit* self, CvPlot& targetPlot, bool bShow);static void ReplaceCvUnit_move(void (*original)(CvUnit*, CvPlot&, bool), CvUnit* self, CvPlot& targetPlot, bool bShow);CivRegisterBefore<CivHooks::CvUnit_move>(host, &BeforeCvUnit_move);CivRegisterAfter<CivHooks::CvUnit_move>(host, &AfterCvUnit_move);CivRegisterReplace<CivHooks::CvUnit_move>(host, &ReplaceCvUnit_move);
Code
3540void CvUnit::move(CvPlot& targetPlot, bool bShow)3541{3542 VALIDATE_OBJECT3543 CvAssert(canMoveOrAttackInto(targetPlot, MOVEFLAG_PRETEND_CORRECT_EMBARK_STATE) || isOutOfAttacks());35443545 CvPlot* pOldPlot = plot();3546 CvAssertMsg(pOldPlot, "pOldPlot needs to have a value");35473548 bool bShouldDeductCost = true;3549 int iMoveCost = targetPlot.movementCost(this, plot());35503551 // we need to get our dis/embarking on3552#if defined(MOD_PATHFINDER_TERRAFIRMA)3553 bool bChangeEmbarkedState = false;35543555#if defined(MOD_PATHFINDER_DEEP_WATER_EMBARKATION)3556 if (pOldPlot && (CanEverEmbark() || (IsHoveringUnit() && IsEmbarkDeepWater()))) {3557#else3558 if (pOldPlot && CanEverEmbark()) {3559#endif3560#if defined(MOD_PATHFINDER_DEEP_WATER_EMBARKATION)3561 if (IsHoveringUnit()) {3562 // Checks for ocean <--> coastal transition3563 bChangeEmbarkedState = (targetPlot.isTerraFirma(this) != pOldPlot->isTerraFirma(this));3564 } else {3565#endif3566 // Standard check for water <--> land transistion3567 if (targetPlot.isWater() != pOldPlot->isWater() || targetPlot.IsAllowsWalkWater() && pOldPlot->isWater() || targetPlot.isWater() && pOldPlot->IsAllowsWalkWater()) {3568 bChangeEmbarkedState = true;3569 }35703571#if defined(MOD_PATHFINDER_CROSS_ICE)3572 if (canCrossIce()) {3573 // Additional checks for land <--> ice, ice <--> ice and water <--> ice transition3574 if ((!targetPlot.isWater() && pOldPlot->isIce()) || (targetPlot.isIce() && !pOldPlot->isWater())) {3575 // CUSTOMLOG("land <--> ice so do NOT change embarked state");3576 bChangeEmbarkedState = false;3577 }3578 else if (targetPlot.isIce() && pOldPlot->isIce()) {3579 // CUSTOMLOG("ice <--> ice so do NOT change embarked state");3580 bChangeEmbarkedState = false;3581 }3582 else if ((targetPlot.isWater() && pOldPlot->isIce()) || (targetPlot.isIce() && pOldPlot->isWater())) {3583 // CUSTOMLOG("water <--> ice so DO change embarked state");3584 bChangeEmbarkedState = true;3585 }3586 }3587#endif3588#if defined(MOD_PATHFINDER_DEEP_WATER_EMBARKATION)3589 }3590#endif3591 }35923593 if (bChangeEmbarkedState)3594#else3595 if (pOldPlot && CanEverEmbark() && (targetPlot.isWater() != pOldPlot->isWater() || targetPlot.IsAllowsWalkWater() && pOldPlot->isWater() ||3596 targetPlot.isWater() && pOldPlot->IsAllowsWalkWater()))3597#endif3598 {3599#if defined(MOD_PATHFINDER_TERRAFIRMA)3600 bool bFromWater = !pOldPlot->isTerraFirma(this) && !pOldPlot->IsAllowsWalkWater();3601 if(bFromWater) // moving from water to something this unit thinks is solid3602#else3603 if(pOldPlot->isWater() && !pOldPlot->IsAllowsWalkWater()) // moving from water to the land3604#endif3605 {3606 if(isEmbarked())3607 {3608 if (m_unitMoveLocs.size()) // If we have some queued moves, execute them now, so that the disembark is done at the proper location visually3609 PublishQueuedVisualizationMoves();36103611 disembark(pOldPlot);3612 }3613 }3614 else3615 {3616 if(!isEmbarked() && canEmbarkOnto(*pOldPlot, targetPlot)) // moving from land to the water3617 {3618 if (m_unitMoveLocs.size()) // If we have some queued moves, execute them now, so that the embark is done at the proper location visually3619 PublishQueuedVisualizationMoves();36203621 embark(pOldPlot);3622 finishMoves();3623 bShouldDeductCost = false;3624 }3625 }3626 }36273628 if(bShouldDeductCost)3629 changeMoves(-iMoveCost);3630 setXY(targetPlot.getX(), targetPlot.getY(), true, true, bShow && targetPlot.isVisibleToWatchingHuman(), bShow);3631}