Bazaar developer reference

CvTacticalAI::CommandeerUnits()

Defined in
CvTacticalAI.cpp, line 357
Class
CvTacticalAI
Hook name
CivHooks::CvTacticalAI_CommandeerUnits

Hooks

static bool BeforeCvTacticalAI_CommandeerUnits(CvTacticalAI* self);static void AfterCvTacticalAI_CommandeerUnits(CvTacticalAI* self);static void ReplaceCvTacticalAI_CommandeerUnits(void (*original)(CvTacticalAI*), CvTacticalAI* self);CivRegisterBefore<CivHooks::CvTacticalAI_CommandeerUnits>(host, &BeforeCvTacticalAI_CommandeerUnits);CivRegisterAfter<CivHooks::CvTacticalAI_CommandeerUnits>(host, &AfterCvTacticalAI_CommandeerUnits);CivRegisterReplace<CivHooks::CvTacticalAI_CommandeerUnits>(host, &ReplaceCvTacticalAI_CommandeerUnits);

Code

356/// Mark all the units that will be under tactical AI control this turn357void CvTacticalAI::CommandeerUnits()358{359	UnitHandle pLoopUnit;360	int iLoop;361362	m_CurrentTurnUnits.clear();363364	// Loop through our units365	for(pLoopUnit = m_pPlayer->firstUnit(&iLoop); pLoopUnit; pLoopUnit = m_pPlayer->nextUnit(&iLoop))366	{367		// Never want immobile/dead units, explorers, ones that have already moved or automated human units368#if defined(MOD_AI_SMART_V3)369		bool bInnerNotNeeded = MOD_AI_SMART_V3 ? ((pLoopUnit->AI_getUnitAIType() == UNITAI_EXPLORE || pLoopUnit->AI_getUnitAIType() == UNITAI_EXPLORE_SEA) && pLoopUnit->getArmyID() == FFreeList::INVALID_INDEX) : pLoopUnit->AI_getUnitAIType() == UNITAI_EXPLORE;370		bool bNotNeeded = pLoopUnit->TurnProcessed() || pLoopUnit->isDelayedDeath() || pLoopUnit->AI_getUnitAIType() == UNITAI_UNKNOWN || bInnerNotNeeded || !pLoopUnit->canMove() || pLoopUnit->isHuman();371		if(bNotNeeded)372#else373		if(pLoopUnit->TurnProcessed() || pLoopUnit->isDelayedDeath() || pLoopUnit->AI_getUnitAIType() == UNITAI_UNKNOWN ||  pLoopUnit->AI_getUnitAIType() == UNITAI_EXPLORE || !pLoopUnit->canMove() || pLoopUnit->isHuman())374#endif375		{376			continue;377		}378379		// We want ALL the barbarians and air units (that are combat ready)380		else if(pLoopUnit->isBarbarian() || (pLoopUnit->getDomainType() == DOMAIN_AIR && pLoopUnit->getDamage() < 50 && !m_pPlayer->GetMilitaryAI()->WillAirUnitRebase(pLoopUnit.pointer())))381		{382			pLoopUnit->setTacticalMove((TacticalAIMoveTypes)m_CachedInfoTypes[eTACTICAL_UNASSIGNED]);383			m_CurrentTurnUnits.push_back(pLoopUnit->GetID());384		}385386		// Now down to land and sea units ... in these groups our unit must have a base combat strength ... or be a great general387		else if(!pLoopUnit->IsCombatUnit() && !pLoopUnit->IsGreatGeneral())388		{389			continue;390		}391392		else393		{394			// Is this one in an operation we can't interrupt?395			int iArmyID = pLoopUnit->getArmyID();396			const CvArmyAI* army = m_pPlayer->getArmyAI(iArmyID);397			if(iArmyID != FFreeList::INVALID_INDEX && NULL != army && !army->CanTacticalAIInterruptUnit(pLoopUnit->GetID()))398			{399				pLoopUnit->setTacticalMove(NO_TACTICAL_MOVE);400			}401402			else403			{404				// Non-zero danger value, near enemy, or deploying out of an operation?405				int iDanger = m_pPlayer->GetPlotDanger(*(pLoopUnit->plot()));406				if(iDanger > 0 || NearVisibleEnemy(pLoopUnit, m_iRecruitRange) ||407				        pLoopUnit->GetDeployFromOperationTurn() + GC.getAI_TACTICAL_MAP_TEMP_ZONE_TURNS() >= GC.getGame().getGameTurn())408				{409					pLoopUnit->setTacticalMove((TacticalAIMoveTypes)m_CachedInfoTypes[eTACTICAL_UNASSIGNED]);410					m_CurrentTurnUnits.push_back(pLoopUnit->GetID());411				}412				else if (pLoopUnit->canParadrop(pLoopUnit->plot(),false))413				{414					pLoopUnit->setTacticalMove((TacticalAIMoveTypes)m_CachedInfoTypes[eTACTICAL_UNASSIGNED]);415					m_CurrentTurnUnits.push_back(pLoopUnit->GetID());416				}417			}418		}419	}420}

Calls

Called by