Hooks
static bool BeforeCvHomelandAI_FindUnitsForThisMove(CvHomelandAI* self, AIHomelandMove eMove, bool bFirstTime, bool& result);static void AfterCvHomelandAI_FindUnitsForThisMove(CvHomelandAI* self, AIHomelandMove eMove, bool bFirstTime, bool& result);static bool ReplaceCvHomelandAI_FindUnitsForThisMove(bool (*original)(CvHomelandAI*, AIHomelandMove, bool), CvHomelandAI* self, AIHomelandMove eMove, bool bFirstTime);CivRegisterBefore<CivHooks::CvHomelandAI_FindUnitsForThisMove>(host, &BeforeCvHomelandAI_FindUnitsForThisMove);CivRegisterAfter<CivHooks::CvHomelandAI_FindUnitsForThisMove>(host, &AfterCvHomelandAI_FindUnitsForThisMove);CivRegisterReplace<CivHooks::CvHomelandAI_FindUnitsForThisMove>(host, &ReplaceCvHomelandAI_FindUnitsForThisMove);
Code
5406/// Finds both high and normal priority units we can use for this homeland move (returns true if at least 1 unit found)5407bool CvHomelandAI::FindUnitsForThisMove(AIHomelandMove eMove, bool bFirstTime)5408{5409 bool rtnValue = false;54105411 if(bFirstTime)5412 {5413 ClearCurrentMoveUnits();5414 ClearCurrentMoveHighPriorityUnits();54155416 // Loop through all units available to homeland AI this turn5417 for(list<int>::iterator it = m_CurrentTurnUnits.begin(); it != m_CurrentTurnUnits.end(); ++it)5418 {5419 UnitHandle pLoopUnit = m_pPlayer->getUnit(*it);5420 if(pLoopUnit && !pLoopUnit->isHuman())5421 {5422 // Civilians aren't useful for any of these moves5423 if(!pLoopUnit->IsCombatUnit())5424 {5425 continue;5426 }54275428 // Scouts aren't useful unless recon is entirely shut off5429 if(pLoopUnit->AI_getUnitAIType() == UNITAI_EXPLORE && m_pPlayer->GetEconomicAI()->GetReconState() != RECON_STATE_ENOUGH)5430 {5431 continue;5432 }54335434 bool bSuitableUnit = false;5435 bool bHighPriority = false;54365437 switch(eMove)5438 {5439 case AI_HOMELAND_MOVE_GARRISON:5440 case AI_HOMELAND_MOVE_GARRISON_CITY_STATE:5441 // Want to put ranged units in cities to give them a ranged attack5442 if(pLoopUnit->isRanged() && !pLoopUnit->getUnitInfo().GetUnitAIType(UNITAI_CITY_BOMBARD))5443 {5444 bSuitableUnit = true;5445 bHighPriority = true;5446 }54475448 // Don't use non-combatants5449 else if(pLoopUnit->IsCanAttack())5450 {5451 // Don't put units with a combat strength boosted from promotions in cities, these boosts are ignored5452 if(pLoopUnit->getDefenseModifier() == 0 &&5453 pLoopUnit->getAttackModifier() == 0 &&5454 pLoopUnit->getExtraCombatPercent() == 0)5455 {5456 bSuitableUnit = true;5457 }5458 }5459 break;54605461 case AI_HOMELAND_MOVE_SENTRY:5462 // No ranged units as sentries5463 if(!pLoopUnit->isRanged() && !pLoopUnit->noDefensiveBonus())5464 {5465 bSuitableUnit = true;54665467 // Units with extra sight are especially valuable5468 if(pLoopUnit->getExtraVisibilityRange() > 0)5469 {5470 bHighPriority = true;5471 }5472 }5473 else if(pLoopUnit->noDefensiveBonus() && pLoopUnit->getExtraVisibilityRange() > 0)5474 {5475 bSuitableUnit = true;5476 bHighPriority = true;5477 }5478 break;54795480 case AI_HOMELAND_MOVE_MOBILE_RESERVE:5481 // Ranged units are excellent in the mobile reserve as are fast movers5482 if(pLoopUnit->isRanged() || pLoopUnit->getUnitInfo().GetUnitAIType(UNITAI_FAST_ATTACK))5483 {5484 bSuitableUnit = true;5485 bHighPriority = true;5486 }5487 else if(pLoopUnit->IsCanAttack())5488 {5489 bSuitableUnit = true;5490 }5491 break;54925493 case AI_HOMELAND_MOVE_ANCIENT_RUINS:5494 // Fast movers are top priority5495 if(pLoopUnit->getUnitInfo().GetUnitAIType(UNITAI_FAST_ATTACK))5496 {5497 bSuitableUnit = true;5498 bHighPriority = true;5499 }5500 else if(pLoopUnit->IsCanAttack())5501 {5502 bSuitableUnit = true;5503 }5504 break;5505 }55065507 // If unit was suitable, add it to the proper list5508 if(bSuitableUnit)5509 {5510 CvHomelandUnit unit;5511 unit.SetID(pLoopUnit->GetID());55125513 if(bHighPriority)5514 {5515 m_CurrentMoveHighPriorityUnits.push_back(unit);5516 }5517 else5518 {5519 m_CurrentMoveUnits.push_back(unit);5520 }5521 rtnValue = true;5522 }5523 }5524 }5525 }55265527 // Second time through, just make sure all units are still in list of current units to process5528 else5529 {5530 FStaticVector< CvHomelandUnit, 64, true, c_eCiv5GameplayDLL > tempList;5531 FStaticVector< CvHomelandUnit, 64, true, c_eCiv5GameplayDLL >::iterator it;5532 std::list<int>::iterator it2;55335534 // Normal priority units5535 tempList = m_CurrentMoveUnits;5536 ClearCurrentMoveUnits();5537 for(it = tempList.begin(); it != tempList.end(); ++it)5538 {5539 it2 = find(m_CurrentTurnUnits.begin(), m_CurrentTurnUnits.end(), (int)it->GetID());5540 if(it2 != m_CurrentTurnUnits.end())5541 {5542 m_CurrentMoveUnits.push_back(*it);5543 rtnValue = true;5544 }5545 }55465547 // High priority units5548 tempList = m_CurrentMoveHighPriorityUnits;5549 ClearCurrentMoveHighPriorityUnits();5550 for(it = tempList.begin(); it != tempList.end(); ++it)5551 {5552 it2 = find(m_CurrentTurnUnits.begin(), m_CurrentTurnUnits.end(), (int)it->GetID());5553 if(it2 != m_CurrentTurnUnits.end())5554 {5555 m_CurrentMoveHighPriorityUnits.push_back(*it);5556 rtnValue = true;5557 }5558 }5559 }55605561 return rtnValue;5562}