Hooks
static bool BeforeCvTacticalAI_MoveToUsingSafeEmbark(CvTacticalAI* self, UnitHandle pUnit, CvPlot* pTargetPlot, bool & bMoveWasSafe, bool& result);static void AfterCvTacticalAI_MoveToUsingSafeEmbark(CvTacticalAI* self, UnitHandle pUnit, CvPlot* pTargetPlot, bool & bMoveWasSafe, bool& result);static bool ReplaceCvTacticalAI_MoveToUsingSafeEmbark(bool (*original)(CvTacticalAI*, UnitHandle, CvPlot*, bool &), CvTacticalAI* self, UnitHandle pUnit, CvPlot* pTargetPlot, bool & bMoveWasSafe);CivRegisterBefore<CivHooks::CvTacticalAI_MoveToUsingSafeEmbark>(host, &BeforeCvTacticalAI_MoveToUsingSafeEmbark);CivRegisterAfter<CivHooks::CvTacticalAI_MoveToUsingSafeEmbark>(host, &AfterCvTacticalAI_MoveToUsingSafeEmbark);CivRegisterReplace<CivHooks::CvTacticalAI_MoveToUsingSafeEmbark>(host, &ReplaceCvTacticalAI_MoveToUsingSafeEmbark);
Code
9907/// Low-level wrapper on CvUnit::PushMission() for move to missions that avoids embarking if dangerous. Returns true if any move made9908bool CvTacticalAI::MoveToUsingSafeEmbark(UnitHandle pUnit, CvPlot* pTargetPlot, bool &bMoveWasSafe)9909{9910 bMoveWasSafe = true;99119912 // Move right away if not a land unit9913 if (pUnit->getDomainType() != DOMAIN_LAND)9914 {9915 pUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), pTargetPlot->getX(), pTargetPlot->getY());9916 return true;9917 }99189919 // If a land unit, get path to target9920 if(!pUnit->GeneratePath(pTargetPlot))9921 {9922 // No path this may happen if a unit has moved up and blocked our path to our target plot9923 // If calling routine is moving a bunch of units like this it should retry these units9924 bMoveWasSafe = false;9925 return false;9926 }99279928 else9929 {9930 CvPlot *pMovePlot = pUnit->GetPathEndTurnPlot();9931 9932 // On land? If so go ahead and move there9933 if (!pMovePlot->isWater())9934 {9935 pUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), pTargetPlot->getX(), pTargetPlot->getY());9936 return true;9937 }99389939 // How dangerous is this plot?9940 else9941 {9942 bool bDangerous = false;99439944#if defined(MOD_AI_SMART_V3)9945 CvPlot* pTacticalPlot = MOD_AI_SMART_V3 ? pMovePlot : pTargetPlot;9946 int iPlotIndex = GC.getMap().plotNum(pTacticalPlot->getX(), pTacticalPlot->getY());9947#else9948 int iPlotIndex = GC.getMap().plotNum(pTargetPlot->getX(), pTargetPlot->getY());9949#endif9950 CvTacticalAnalysisCell *pCell = m_pMap->GetCell(iPlotIndex);9951 if (pCell->IsSubjectToAttack())9952 {9953 // Enemy naval unit can definitely attack this plot9954 bDangerous = true;9955 }99569957 else9958 {9959#if defined(MOD_AI_SMART_V3)9960 if (GC.getGame().GetTacticalAnalysisMap()->IsInEnemyDominatedZone(pTacticalPlot))9961#else9962 if (GC.getGame().GetTacticalAnalysisMap()->IsInEnemyDominatedZone(pTargetPlot))9963#endif9964 {9965 // Also dangerous in an enemy dominated naval zone9966 bDangerous = true;9967 }9968 }99699970 // Not dangerous, proceed9971 if (!bDangerous)9972 {9973 pUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), pTargetPlot->getX(), pTargetPlot->getY());9974 return true; 9975 }99769977 // Dangerous - try to move just on land9978 else9979 {9980 if(!pUnit->GeneratePath(pTargetPlot, CvUnit::MOVEFLAG_STAY_ON_LAND))9981 {9982 // No land path so just risk move to sea9983 pUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), pTargetPlot->getX(), pTargetPlot->getY());99849985 // Hopefully the calling routine might be able to pull escort over to stack with this unit9986 bMoveWasSafe = false;9987 return true; 9988 }9989 else9990 {9991 pUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), pTargetPlot->getX(), pTargetPlot->getY(), CvUnit::MOVEFLAG_STAY_ON_LAND);9992 return true; 9993 }9994 }9995 }9996 }9997}