Hooks
static bool BeforeCvHomelandAI_ExecuteMoveToTarget(CvHomelandAI* self, CvPlot* pTarget);static void AfterCvHomelandAI_ExecuteMoveToTarget(CvHomelandAI* self, CvPlot* pTarget);static void ReplaceCvHomelandAI_ExecuteMoveToTarget(void (*original)(CvHomelandAI*, CvPlot*), CvHomelandAI* self, CvPlot* pTarget);CivRegisterBefore<CivHooks::CvHomelandAI_ExecuteMoveToTarget>(host, &BeforeCvHomelandAI_ExecuteMoveToTarget);CivRegisterAfter<CivHooks::CvHomelandAI_ExecuteMoveToTarget>(host, &AfterCvHomelandAI_ExecuteMoveToTarget);CivRegisterReplace<CivHooks::CvHomelandAI_ExecuteMoveToTarget>(host, &ReplaceCvHomelandAI_ExecuteMoveToTarget);
Code
3182/// Find one unit to move to target, starting with high priority list3183void CvHomelandAI::ExecuteMoveToTarget(CvPlot* pTarget)3184{3185 AI_PERF_FORMAT("Homeland-ExecuteMove-perf.csv", ("ExecuteMoveToTarget, %d, %d, Turn %03d, %s", pTarget->getX(), pTarget->getY(), GC.getGame().getElapsedGameTurns(), m_pPlayer->getCivilizationShortDescription()) );31863187 // Do we have a pre-calcuated 'best' unit?3188 CvUnit *pBestUnit = NULL;3189 if (m_CurrentBestMoveHighPriorityUnit)3190 {3191 // Don't move high priority unit if regular priority unit is closer3192 if (m_CurrentBestMoveUnit && m_iCurrentBestMoveUnitTurns < m_iCurrentBestMoveHighPriorityUnitTurns)3193 pBestUnit = m_CurrentBestMoveUnit;3194 else3195 pBestUnit = m_CurrentBestMoveHighPriorityUnit;3196 }3197 else3198 pBestUnit = m_CurrentBestMoveUnit;31993200 if (pBestUnit)3201 {3202 if(pBestUnit->plot() == pTarget && pBestUnit->canFortify(pBestUnit->plot()))3203 {3204 pBestUnit->PushMission(CvTypes::getMISSION_FORTIFY());3205 pBestUnit->SetFortifiedThisTurn(true);3206 UnitProcessed(pBestUnit->GetID());3207 return;3208 }3209 else3210 {3211 // Best units have already had a full path check to the target, so just add the move3212 pBestUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), pTarget->getX(), pTarget->getY());3213 pBestUnit->finishMoves();3214 UnitProcessed(pBestUnit->GetID());3215 return;3216 }3217 }32183219 MoveUnitsArray::iterator it;32203221 // Start with high priority list3222 for(it = m_CurrentMoveHighPriorityUnits.begin(); it != m_CurrentMoveHighPriorityUnits.end(); ++it)3223 {3224 UnitHandle pUnit = m_pPlayer->getUnit(it->GetID());32253226 // Don't move high priority unit if regular priority unit is closer3227 if(m_CurrentMoveUnits.size() > 0 && m_CurrentMoveUnits.begin()->GetMovesToTarget() < it->GetMovesToTarget())3228 {3229 break;3230 }32313232 if(pUnit)3233 {3234 if(pUnit->plot() == pTarget && pUnit->canFortify(pUnit->plot()))3235 {3236 pUnit->PushMission(CvTypes::getMISSION_FORTIFY());3237 pUnit->SetFortifiedThisTurn(true);3238 UnitProcessed(it->GetID());3239 return;3240 }32413242 else if(it->GetMovesToTarget() < GC.getAI_HOMELAND_ESTIMATE_TURNS_DISTANCE() || TurnsToReachTarget(pUnit, pTarget) != MAX_INT)3243 {3244 pUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), pTarget->getX(), pTarget->getY());3245 pUnit->finishMoves();3246 UnitProcessed(it->GetID());3247 return;3248 }3249 }3250 }32513252 // Then regular priority3253 for(it = m_CurrentMoveUnits.begin(); it != m_CurrentMoveUnits.end(); ++it)3254 {3255 UnitHandle pUnit = m_pPlayer->getUnit(it->GetID());3256 if(pUnit)3257 {3258 if(pUnit->plot() == pTarget && pUnit->canFortify(pUnit->plot()))3259 {3260 pUnit->PushMission(CvTypes::getMISSION_FORTIFY());3261 pUnit->SetFortifiedThisTurn(true);3262 UnitProcessed(it->GetID());3263 return;3264 }32653266 else if(it->GetMovesToTarget() < GC.getAI_HOMELAND_ESTIMATE_TURNS_DISTANCE() || TurnsToReachTarget(pUnit, pTarget) != MAX_INT)3267 {3268 pUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), pTarget->getX(), pTarget->getY());3269 pUnit->finishMoves();3270 UnitProcessed(it->GetID());3271 return;3272 }3273 }3274 }3275}