Hooks
static bool BeforeCvAIOperationDestroyBarbarianCamp_ArmyInPosition(CvAIOperationDestroyBarbarianCamp* self, CvArmyAI* pArmy, bool& result);static void AfterCvAIOperationDestroyBarbarianCamp_ArmyInPosition(CvAIOperationDestroyBarbarianCamp* self, CvArmyAI* pArmy, bool& result);static bool ReplaceCvAIOperationDestroyBarbarianCamp_ArmyInPosition(bool (*original)(CvAIOperationDestroyBarbarianCamp*, CvArmyAI*), CvAIOperationDestroyBarbarianCamp* self, CvArmyAI* pArmy);CivRegisterBefore<CivHooks::CvAIOperationDestroyBarbarianCamp_ArmyInPosition>(host, &BeforeCvAIOperationDestroyBarbarianCamp_ArmyInPosition);CivRegisterAfter<CivHooks::CvAIOperationDestroyBarbarianCamp_ArmyInPosition>(host, &AfterCvAIOperationDestroyBarbarianCamp_ArmyInPosition);CivRegisterReplace<CivHooks::CvAIOperationDestroyBarbarianCamp_ArmyInPosition>(host, &ReplaceCvAIOperationDestroyBarbarianCamp_ArmyInPosition);
Code
2346/// Same as default version except if just gathered forces, check to see if a better target has presented itself2347bool CvAIOperationDestroyBarbarianCamp::ArmyInPosition(CvArmyAI* pArmy)2348{2349 bool bStateChanged = false;23502351 switch(m_eCurrentState)2352 {2353 // If we were gathering forces, let's make sure a better target hasn't presented itself2354 case AI_OPERATION_STATE_GATHERING_FORCES:2355 {2356 // First do base case processing2357 bStateChanged = CvAIOperation::ArmyInPosition(pArmy);23582359 // Now revisit target2360 CvPlot* possibleBetterTarget;2361 possibleBetterTarget = FindBestTarget();23622363 // If no target left, abort2364 if(possibleBetterTarget == NULL)2365 {2366 m_eCurrentState = AI_OPERATION_STATE_ABORTED;2367 m_eAbortReason = AI_ABORT_LOST_TARGET;2368 }23692370 // If target changed, reset to this new one2371 else if(possibleBetterTarget != GetTargetPlot())2372 {2373 // If we're traveling on a single continent, set our destination to be a few plots shy of the final target2374 if (pArmy->GetArea() == possibleBetterTarget->getArea())2375 {2376 CvPlot* pDeployPt = GC.getStepFinder().GetXPlotsFromEnd(GetOwner(), GetEnemy(), pArmy->Plot(), possibleBetterTarget, GC.getAI_OPERATIONAL_BARBARIAN_CAMP_DEPLOY_RANGE(), false);2377 if(pDeployPt != NULL)2378 {2379 pArmy->SetGoalPlot(pDeployPt);2380 SetTargetPlot(possibleBetterTarget);2381 }2382 }23832384 // Coming in from the sea. Just head to the camp2385 else2386 {2387 pArmy->SetGoalPlot(possibleBetterTarget);2388 SetTargetPlot(possibleBetterTarget);2389 }2390 }2391 }2392 break;23932394 // See if reached our target, if so give control of these units to the tactical AI2395 case AI_OPERATION_STATE_MOVING_TO_TARGET:2396 {2397 if (plotDistance(pArmy->GetX(), pArmy->GetY(), pArmy->GetGoalX(), pArmy->GetGoalY()) <= 1)2398 {2399 // Notify tactical AI to focus on this area2400 CvTemporaryZone zone;2401 zone.SetX(GetTargetPlot()->getX());2402 zone.SetY(GetTargetPlot()->getY());2403 zone.SetTargetType(AI_TACTICAL_TARGET_BARBARIAN_CAMP);2404 zone.SetLastTurn(GC.getGame().getGameTurn() + GC.getAI_TACTICAL_MAP_TEMP_ZONE_TURNS());2405 GET_PLAYER(m_eOwner).GetTacticalAI()->AddTemporaryZone(zone);24062407 m_eCurrentState = AI_OPERATION_STATE_SUCCESSFUL_FINISH;2408 }2409 }2410 break;24112412 // In all other cases use base class version2413 case AI_OPERATION_STATE_ABORTED:2414 case AI_OPERATION_STATE_RECRUITING_UNITS:2415 case AI_OPERATION_STATE_AT_TARGET:2416 return CvAIOperation::ArmyInPosition(pArmy);2417 break;2418 };24192420 return bStateChanged;2421}