Bazaar developer reference

CvGrandStrategyAI::GetConquestPriority()

Defined in
CvGrandStrategyAI.cpp, line 389
Class
CvGrandStrategyAI
Hook name
CivHooks::CvGrandStrategyAI_GetConquestPriority

Hooks

static bool BeforeCvGrandStrategyAI_GetConquestPriority(CvGrandStrategyAI* self, int& result);static void AfterCvGrandStrategyAI_GetConquestPriority(CvGrandStrategyAI* self, int& result);static int ReplaceCvGrandStrategyAI_GetConquestPriority(int (*original)(CvGrandStrategyAI*), CvGrandStrategyAI* self);CivRegisterBefore<CivHooks::CvGrandStrategyAI_GetConquestPriority>(host, &BeforeCvGrandStrategyAI_GetConquestPriority);CivRegisterAfter<CivHooks::CvGrandStrategyAI_GetConquestPriority>(host, &AfterCvGrandStrategyAI_GetConquestPriority);CivRegisterReplace<CivHooks::CvGrandStrategyAI_GetConquestPriority>(host, &ReplaceCvGrandStrategyAI_GetConquestPriority);

Code

388/// Returns Priority for Conquest Grand Strategy389int CvGrandStrategyAI::GetConquestPriority()390{391	int iPriority = 0;392393	// If Conquest Victory isn't even available then don't bother with anything394	VictoryTypes eVictory = (VictoryTypes) GC.getInfoTypeForString("VICTORY_DOMINATION", true);395	if(eVictory == NO_VICTORY || !GC.getGame().isVictoryValid(eVictory))396	{397		if(!GC.getGame().areNoVictoriesValid())398		{399			return -100;400		}401	}402403	int iGeneralWarlikeness = GetPlayer()->GetDiplomacyAI()->GetPersonalityMajorCivApproachBias(MAJOR_CIV_APPROACH_WAR);404	int iGeneralHostility = GetPlayer()->GetDiplomacyAI()->GetPersonalityMajorCivApproachBias(MAJOR_CIV_APPROACH_HOSTILE);405	int iGeneralDeceptiveness = GetPlayer()->GetDiplomacyAI()->GetPersonalityMajorCivApproachBias(MAJOR_CIV_APPROACH_DECEPTIVE);406	int iGeneralFriendliness = GetPlayer()->GetDiplomacyAI()->GetPersonalityMajorCivApproachBias(MAJOR_CIV_APPROACH_FRIENDLY);407408	int iGeneralApproachModifier = max(max(iGeneralDeceptiveness, iGeneralHostility),iGeneralWarlikeness) - iGeneralFriendliness;409	// Boldness gives the base weight for Conquest (no flavors added earlier)410	iPriority += ((GetPlayer()->GetDiplomacyAI()->GetBoldness() + iGeneralApproachModifier) * (12 - m_pPlayer->GetCurrentEra())); // make a little less likely as time goes on411412	CvTeam& pTeam = GET_TEAM(GetPlayer()->getTeam());413414	// How many turns must have passed before we test for having met nobody?415	if(GC.getGame().getElapsedGameTurns() >= /*20*/ GC.getAI_GS_CONQUEST_NOBODY_MET_FIRST_TURN())416	{417		// If we haven't met any Major Civs yet, then we probably shouldn't be planning on conquering the world418		bool bHasMetMajor = false;419420		for(int iTeamLoop = 0; iTeamLoop < MAX_CIV_TEAMS; iTeamLoop++)421		{422			if(pTeam.GetID() != iTeamLoop && !GET_TEAM((TeamTypes) iTeamLoop).isMinorCiv())423			{424				if(pTeam.isHasMet((TeamTypes) iTeamLoop))425				{426					bHasMetMajor = true;427					break;428				}429			}430		}431		if(!bHasMetMajor)432		{433			iPriority += /*-50*/ GC.getAI_GRAND_STRATEGY_CONQUEST_NOBODY_MET_WEIGHT();434		}435	}436437	// How many turns must have passed before we test for us having a weak military?438	if(GC.getGame().getElapsedGameTurns() >= /*60*/ GC.getAI_GS_CONQUEST_MILITARY_STRENGTH_FIRST_TURN())439	{440		// Compare our military strength to the rest of the world441		int iWorldMilitaryStrength = GC.getGame().GetWorldMilitaryStrengthAverage(GetPlayer()->GetID(), true, true);442443		if(iWorldMilitaryStrength > 0)444		{445			int iMilitaryRatio = (GetPlayer()->GetMilitaryMight() - iWorldMilitaryStrength) * /*100*/ GC.getAI_GRAND_STRATEGY_CONQUEST_POWER_RATIO_MULTIPLIER() / iWorldMilitaryStrength;446447			// Make the likelihood of BECOMING a warmonger lower than dropping the bad behavior448			if(iMilitaryRatio > 0)449				iMilitaryRatio /= 2;450451			iPriority += iMilitaryRatio;	// This will add between -100 and 100 depending on this player's MilitaryStrength relative the world average. The number will typically be near 0 though, as it's fairly hard to get away from the world average452		}453	}454455	// If we're at war, then boost the weight a bit456	if(pTeam.getAtWarCount(/*bIgnoreMinors*/ false) > 0)457	{458		iPriority += /*10*/ GC.getAI_GRAND_STRATEGY_CONQUEST_AT_WAR_WEIGHT();459	}460461	// If our neighbors are cramping our style, consider less... scrupulous means of obtaining more land462	if(GetPlayer()->IsCramped())463	{464		PlayerTypes ePlayer;465		int iNumPlayersMet = 1;	// Include 1 for me!466		int iTotalLandMe = 0;467		int iTotalLandPlayersMet = 0;468469		// Count the number of Majors we know470		for(int iMajorLoop = 0; iMajorLoop < MAX_MAJOR_CIVS; iMajorLoop++)471		{472			ePlayer = (PlayerTypes) iMajorLoop;473474			if(GET_PLAYER(ePlayer).isAlive() && iMajorLoop != GetPlayer()->GetID())475			{476				if(pTeam.isHasMet(GET_PLAYER(ePlayer).getTeam()))477				{478					iNumPlayersMet++;479				}480			}481		}482483		if(iNumPlayersMet > 0)484		{485			// Check every plot for ownership486			for(int iPlotLoop = 0; iPlotLoop < GC.getMap().numPlots(); iPlotLoop++)487			{488				if(GC.getMap().plotByIndexUnchecked(iPlotLoop)->isOwned())489				{490					ePlayer = GC.getMap().plotByIndexUnchecked(iPlotLoop)->getOwner();491492					if(ePlayer == GetPlayer()->GetID())493					{494						iTotalLandPlayersMet++;495						iTotalLandMe++;496					}497					else if(!GET_PLAYER(ePlayer).isMinorCiv() && pTeam.isHasMet(GET_PLAYER(ePlayer).getTeam()))498					{499						iTotalLandPlayersMet++;500					}501				}502			}503504			iTotalLandPlayersMet /= iNumPlayersMet;505506			if(iTotalLandMe > 0)507			{508				if(iTotalLandPlayersMet / iTotalLandMe > 0)509				{510					iPriority += /*20*/ GC.getAI_GRAND_STRATEGY_CONQUEST_CRAMPED_WEIGHT();511				}512			}513		}514	}515516	// if we do not have nukes and we know someone else who does...517	if(GetPlayer()->getNumNukeUnits() == 0)518	{519		for(int iMajorLoop = 0; iMajorLoop < MAX_MAJOR_CIVS; iMajorLoop++)520		{521			PlayerTypes ePlayer = (PlayerTypes) iMajorLoop;522523			if(GET_PLAYER(ePlayer).isAlive() && iMajorLoop != GetPlayer()->GetID())524			{525				if(pTeam.isHasMet(GET_PLAYER(ePlayer).getTeam()))526				{527					if (GET_PLAYER(ePlayer).getNumNukeUnits() > 0)528					{529						iPriority -= 50; 530						break;531					}532				}533			}534		}535	}536537	return iPriority;538}

Calls

Called by