Bazaar developer reference

CvTechAI::GetTechRatio()

Defined in
CvTechAI.cpp, line 263
Class
CvTechAI
Hook name
CivHooks::CvTechAI_GetTechRatio

Hooks

static bool BeforeCvTechAI_GetTechRatio(CvTechAI* self, float& result);static void AfterCvTechAI_GetTechRatio(CvTechAI* self, float& result);static float ReplaceCvTechAI_GetTechRatio(float (*original)(CvTechAI*), CvTechAI* self);CivRegisterBefore<CivHooks::CvTechAI_GetTechRatio>(host, &BeforeCvTechAI_GetTechRatio);CivRegisterAfter<CivHooks::CvTechAI_GetTechRatio>(host, &AfterCvTechAI_GetTechRatio);CivRegisterReplace<CivHooks::CvTechAI_GetTechRatio>(host, &ReplaceCvTechAI_GetTechRatio);

Code

263float CvTechAI::GetTechRatio()264{265	// create list of all civs with the number of techs they control266	std::vector<LeaderWithNumTechs> aLeaderWithNumTechs;267	for(uint ui = 0; ui < MAX_MAJOR_CIVS; ui++)268	{269		PlayerTypes ePlayer = (PlayerTypes)ui;270		if(!GET_PLAYER(ePlayer).isAlive())271		{272			continue;273		}274275		LeaderWithNumTechs kEvalChunk;276		kEvalChunk.m_iLeader = ui;277		kEvalChunk.m_iNumTechs = GET_TEAM(GET_PLAYER(ePlayer).getTeam()).GetTeamTechs()->GetNumTechsKnown();278		aLeaderWithNumTechs.push_back(kEvalChunk);279	}280281	std::stable_sort(aLeaderWithNumTechs.begin(), aLeaderWithNumTechs.end(), LeaderWithNumTechsEval());282283	int iPlayerIndexInList = -1;284	for(uint ui = 0; ui < aLeaderWithNumTechs.size(); ui++)285	{286		if(aLeaderWithNumTechs[ui].m_iLeader == m_pCurrentTechs->GetPlayer()->GetID())287		{288			iPlayerIndexInList = ui;289			break;290		}291	}292293	CvAssertMsg(iPlayerIndexInList != -1, "Could not find player in list");294	CvAssertMsg(aLeaderWithNumTechs.size() >= 2, "Only one player in the game? Huh?");295	float fTechPositionRatio = 0.0f;296	if(aLeaderWithNumTechs.size() >= 2)297	{298		int iNumerator = iPlayerIndexInList;299		int iDenominator = aLeaderWithNumTechs.size() - 1;300		fTechPositionRatio = iNumerator / (float)iDenominator;301	}302303	return fTechPositionRatio;304}

Calls

Called by