CvTacticalAI::PlotMovesToSafety(bool)
- Defined in
- CvTacticalAI.cpp, line 2412
- Class
- CvTacticalAI
- Hook name
CivHooks::CvTacticalAI_PlotMovesToSafety
Hooks
static bool BeforeCvTacticalAI_PlotMovesToSafety(CvTacticalAI* self, bool bCombatUnits);static void AfterCvTacticalAI_PlotMovesToSafety(CvTacticalAI* self, bool bCombatUnits);static void ReplaceCvTacticalAI_PlotMovesToSafety(void (*original)(CvTacticalAI*, bool), CvTacticalAI* self, bool bCombatUnits);CivRegisterBefore<CivHooks::CvTacticalAI_PlotMovesToSafety>(host, &BeforeCvTacticalAI_PlotMovesToSafety);CivRegisterAfter<CivHooks::CvTacticalAI_PlotMovesToSafety>(host, &AfterCvTacticalAI_PlotMovesToSafety);CivRegisterReplace<CivHooks::CvTacticalAI_PlotMovesToSafety>(host, &ReplaceCvTacticalAI_PlotMovesToSafety);
Code
2411/// Moved endangered units to safe hexes2412void CvTacticalAI::PlotMovesToSafety(bool bCombatUnits)2413{2414 int iDangerLevel;24152416 list<int>::iterator it;2417 m_CurrentMoveUnits.clear();24182419 // Loop through all recruited units2420 for(it = m_CurrentTurnUnits.begin(); it != m_CurrentTurnUnits.end(); it++)2421 {2422 UnitHandle pUnit = m_pPlayer->getUnit(*it);2423 if(pUnit)2424 {2425 // Danger value of plot must be greater than 02426 CvPlot* pPlot = pUnit->plot();24272428 iDangerLevel = m_pPlayer->GetPlotDanger(*pPlot);2429 if(iDangerLevel > 0)2430 {2431 bool bAddUnit = false;2432 if(bCombatUnits)2433 {2434 // If under 100% health, might flee to safety2435 if(pUnit->GetCurrHitPoints() < pUnit->GetMaxHitPoints())2436 {2437#if defined(MOD_AI_SMART_V3)2438 // Everyone else flees at more than 70% damage2439 bool bFlee = MOD_AI_SMART_V3 ? ((pUnit->getDamage()*100)/pUnit->GetMaxHitPoints())>70 : pUnit->IsUnderEnemyRangedAttack() || pUnit->GetBaseCombatStrengthConsideringDamage() * 2 <= pUnit->GetBaseCombatStrength();2440#endif24412442 if(pUnit->isBarbarian())2443 {2444 // Barbarian combat units - only naval units flee (but they flee if have taken ANY damage)2445 if(pUnit->getDomainType() == DOMAIN_SEA)2446 {2447 bAddUnit = true;2448 }2449 }24502451#if defined(MOD_AI_SMART_V3)2452 else if(bFlee)2453#else2454 // Everyone else flees if under enemy fire or if at less than or equal to 50% combat strength2455 else if (pUnit->IsUnderEnemyRangedAttack() || pUnit->GetBaseCombatStrengthConsideringDamage() * 2 <= pUnit->GetBaseCombatStrength())2456#endif2457 {2458 bAddUnit = true;2459 }2460 2461#if defined(MOD_AI_SMART_V3)2462 if (MOD_AI_SMART_V3)2463 {2464 //But not if we're in a city!2465 if(pUnit->plot()->isCity())2466 {2467 bAddUnit = false;2468 }2469 if(pUnit->getArmyID() != -1)2470 {2471 bAddUnit = false;2472 }2473 }2474#endif2475 }24762477 // Also flee if danger is really high in current plot (but not if we're barbarian)2478 else if(!pUnit->isBarbarian())2479 {2480 int iAcceptableDanger;2481 iAcceptableDanger = pUnit->GetBaseCombatStrengthConsideringDamage() * 100;2482 if(iDangerLevel > iAcceptableDanger)2483 {2484 bAddUnit = true;2485 }2486 }2487 }2488 else2489 {2490 // Civilian (or embarked) units always flee from danger2491 if(!pUnit->IsCanDefend())2492 {2493 bAddUnit = true;2494 }2495#if defined(MOD_AI_SMART_V3)2496 //GGs and GAs need to stay in the DANGER ZONE, but only if there are units near it to support it.2497 if(MOD_AI_SMART_V3 && (pUnit->IsGreatAdmiral() || pUnit->IsGreatGeneral()))2498 {2499 if(pUnit->plot()->isCity())2500 {2501 bAddUnit = false;2502 }2503 else if(pUnit->plot()->getNumDefenders(pUnit->getOwner()) > 0)2504 {2505 CvUnit* pUnit2 = pUnit->plot()->getUnitByIndex(0);2506 //Are we under a relatively healthy unit? Alright, let's drill down and see what's around us.2507 if(pUnit2 != NULL && pUnit2->GetCurrHitPoints() > (pUnit2->GetMaxHitPoints() * 2 / 3))2508 {2509 // If there a hex adjacent to city they can airlift to?2510 for (int iI = 0; iI < NUM_DIRECTION_TYPES; iI++)2511 {2512 CvPlot *pLoopPlot = plotDirection(pUnit->getX(), pUnit->getY(), ((DirectionTypes)iI));2513 if (pLoopPlot != NULL)2514 {2515 if(pLoopPlot->getNumDefenders(pUnit->getOwner()) > 0)2516 {2517 bAddUnit = false;2518 break;2519 }2520 }2521 }2522 }2523 }2524 }2525#endif2526 }25272528 if(bAddUnit)2529 {2530 // Just one unit involved in this move to execute2531 CvTacticalUnit unit;2532 unit.SetID(pUnit->GetID());2533 m_CurrentMoveUnits.push_back(unit);2534 }2535 }2536 }2537 }25382539 if(m_CurrentMoveUnits.size() > 0)2540 {2541 ExecuteMovesToSafestPlot();2542 }2543}
Calls
- CustomMods::isAI_SMART_V3()
- CvPlayer::GetPlotDanger(CvPlot &) const
- CvPlayer::getUnit(int)
- CvPlot::getNumDefenders(PlayerTypes) const
- CvPlot::getUnitByIndex(int) const
- CvPlot::isCity() const
- CvTacticalAI::ExecuteMovesToSafestPlot()
- CvTacticalUnit::CvTacticalUnit()
- CvTacticalUnit::SetID(int)
- CvUnit::getArmyID() const
- CvUnit::GetBaseCombatStrength(bool) const
- CvUnit::GetBaseCombatStrengthConsideringDamage() const
- CvUnit::GetCurrHitPoints() const
- CvUnit::getDamage() const
- CvUnit::getDomainType() const
- CvUnit::GetID() const
- CvUnit::GetMaxHitPoints() const
- CvUnit::getOwner() const
- CvUnit::getX() const
- CvUnit::getY() const
- CvUnit::isBarbarian() const
- CvUnit::IsCanDefend(const CvPlot *) const
- CvUnit::IsGreatAdmiral() const
- CvUnit::IsGreatGeneral() const
- CvUnit::IsUnderEnemyRangedAttack() const
- CvUnit::plot() const
FObjectHandle::FObjectHandleFObjectHandle::operator boolFObjectHandle::operator->- plotDirection(int, int, DirectionTypes)
std::list::_Const_iterator::operator!=std::list::_Iterator::_Iteratorstd::list::_Iterator::operator*std::list::_Iterator::operator++std::list::_Iterator::operator=std::list::beginstd::list::endstd::vector::clearstd::vector::push_backstd::vector::size