Bazaar developer reference

CvHomelandAI::FindArchaeologistTarget(CvUnit *)

Defined in
CvHomelandAI.cpp, line 5864
Class
CvHomelandAI
Hook name
CivHooks::CvHomelandAI_FindArchaeologistTarget

Hooks

static bool BeforeCvHomelandAI_FindArchaeologistTarget(CvHomelandAI* self, CvUnit * pUnit, CvPlot*& result);static void AfterCvHomelandAI_FindArchaeologistTarget(CvHomelandAI* self, CvUnit * pUnit, CvPlot*& result);static CvPlot* ReplaceCvHomelandAI_FindArchaeologistTarget(CvPlot* (*original)(CvHomelandAI*, CvUnit *), CvHomelandAI* self, CvUnit * pUnit);CivRegisterBefore<CivHooks::CvHomelandAI_FindArchaeologistTarget>(host, &BeforeCvHomelandAI_FindArchaeologistTarget);CivRegisterAfter<CivHooks::CvHomelandAI_FindArchaeologistTarget>(host, &AfterCvHomelandAI_FindArchaeologistTarget);CivRegisterReplace<CivHooks::CvHomelandAI_FindArchaeologistTarget>(host, &ReplaceCvHomelandAI_FindArchaeologistTarget);

Code

5863/// Find best target for this archaeologist5864CvPlot* CvHomelandAI::FindArchaeologistTarget(CvUnit *pUnit)5865{5866	CvPlot *pBestTarget = NULL;5867	int iBestTurns = MAX_INT;58685869	// Reverse the logic from most of the Homeland moves; for this we'll loop through units and find the best targets for them (instead of vice versa)5870	std::vector<CvHomelandTarget>::iterator it;5871	for (it = m_TargetedAntiquitySites.begin(); it != m_TargetedAntiquitySites.end(); it++)5872	{5873		CvPlot* pTarget = GC.getMap().plot(it->GetTargetX(), it->GetTargetY());5874		if (m_pPlayer->GetPlotDanger(*pTarget) == 0)5875		{5876			int iTurns = TurnsToReachTarget(pUnit, pTarget);58775878			if (iTurns < iBestTurns)5879			{5880				pBestTarget = pTarget;5881				iBestTurns = iTurns;5882			}5883		}5884	}58855886	// Erase this site from future contention5887	if (pBestTarget)5888	{5889		for (it = m_TargetedAntiquitySites.begin(); it != m_TargetedAntiquitySites.end(); it++)5890		{5891			if (it->GetTargetX() == pBestTarget->getX() && it->GetTargetY() == pBestTarget->getY())5892			{5893				m_TargetedAntiquitySites.erase(it);5894				break;5895			}5896		}5897	}58985899	return pBestTarget;5900}

Calls

Called by