Bazaar developer reference

CvHomelandAI::FindWorkersInSameArea(CvPlot *, BuildTypes)

Defined in
CvHomelandAI.cpp, line 5366
Class
CvHomelandAI
Hook name
CivHooks::CvHomelandAI_FindWorkersInSameArea

Hooks

static bool BeforeCvHomelandAI_FindWorkersInSameArea(CvHomelandAI* self, CvPlot* pTarget, BuildTypes eBuild, bool& result);static void AfterCvHomelandAI_FindWorkersInSameArea(CvHomelandAI* self, CvPlot* pTarget, BuildTypes eBuild, bool& result);static bool ReplaceCvHomelandAI_FindWorkersInSameArea(bool (*original)(CvHomelandAI*, CvPlot*, BuildTypes), CvHomelandAI* self, CvPlot* pTarget, BuildTypes eBuild);CivRegisterBefore<CivHooks::CvHomelandAI_FindWorkersInSameArea>(host, &BeforeCvHomelandAI_FindWorkersInSameArea);CivRegisterAfter<CivHooks::CvHomelandAI_FindWorkersInSameArea>(host, &AfterCvHomelandAI_FindWorkersInSameArea);CivRegisterReplace<CivHooks::CvHomelandAI_FindWorkersInSameArea>(host, &ReplaceCvHomelandAI_FindWorkersInSameArea);

Code

5365/// Fills m_CurrentMoveUnits with all units in same area5366bool CvHomelandAI::FindWorkersInSameArea(CvPlot* pTarget, BuildTypes eBuild)5367{5368	bool rtnValue = false;5369	ClearCurrentMoveUnits();53705371	// Loop through all units available to homeland AI this turn5372	for(list<int>::iterator it = m_CurrentTurnUnits.begin(); it != m_CurrentTurnUnits.end(); ++it)5373	{5374		UnitHandle pLoopUnit = m_pPlayer->getUnit(*it);5375		if(pLoopUnit)5376		{5377			// Civilians only5378			if(pLoopUnit->IsCanAttack())5379			{5380				continue;5381			}53825383			// Can this worker make the right improvement?5384			if(pLoopUnit->canBuild(pTarget, eBuild))5385			{5386				CvHomelandUnit unit;5387				int iMoves = TurnsToReachTarget(pLoopUnit.pointer(), pTarget);53885389				if(iMoves != MAX_INT)5390				{5391					unit.SetID(pLoopUnit->GetID());5392					unit.SetMovesToTarget(iMoves);5393					m_CurrentMoveUnits.push_back(unit);5394					rtnValue = true;5395				}5396			}5397		}5398	}53995400	// Now sort them in the order we'd like them to move5401	std::stable_sort(m_CurrentMoveUnits.begin(), m_CurrentMoveUnits.end());54025403	return rtnValue;5404}

Calls