Bazaar developer reference

CvGrandStrategyAI::DoGuessOtherPlayersActiveGrandStrategy()

Defined in
CvGrandStrategyAI.cpp, line 877
Class
CvGrandStrategyAI
Hook name
CivHooks::CvGrandStrategyAI_DoGuessOtherPlayersActiveGrandStrategy

Hooks

static bool BeforeCvGrandStrategyAI_DoGuessOtherPlayersActiveGrandStrategy(CvGrandStrategyAI* self);static void AfterCvGrandStrategyAI_DoGuessOtherPlayersActiveGrandStrategy(CvGrandStrategyAI* self);static void ReplaceCvGrandStrategyAI_DoGuessOtherPlayersActiveGrandStrategy(void (*original)(CvGrandStrategyAI*), CvGrandStrategyAI* self);CivRegisterBefore<CivHooks::CvGrandStrategyAI_DoGuessOtherPlayersActiveGrandStrategy>(host, &BeforeCvGrandStrategyAI_DoGuessOtherPlayersActiveGrandStrategy);CivRegisterAfter<CivHooks::CvGrandStrategyAI_DoGuessOtherPlayersActiveGrandStrategy>(host, &AfterCvGrandStrategyAI_DoGuessOtherPlayersActiveGrandStrategy);CivRegisterReplace<CivHooks::CvGrandStrategyAI_DoGuessOtherPlayersActiveGrandStrategy>(host, &ReplaceCvGrandStrategyAI_DoGuessOtherPlayersActiveGrandStrategy);

Code

876/// Runs every turn to try and figure out what other known Players' Grand Strategies are877void CvGrandStrategyAI::DoGuessOtherPlayersActiveGrandStrategy()878{879	CvWeightedVector<int, 5, true> vGrandStrategyPriorities;880	FStaticVector< int, 5, true, c_eCiv5GameplayDLL >  vGrandStrategyPrioritiesForLogging;881882	GuessConfidenceTypes eGuessConfidence = NO_GUESS_CONFIDENCE_TYPE;883884	int iGrandStrategiesLoop = 0;885	AIGrandStrategyTypes eGrandStrategy = NO_AIGRANDSTRATEGY;886	CvAIGrandStrategyXMLEntry* pGrandStrategy = 0;887	CvString strGrandStrategyName;888889	CvTeam& pTeam = GET_TEAM(GetPlayer()->getTeam());890891	int iMajorLoop = 0;892	PlayerTypes eMajor = NO_PLAYER;893894	int iPriority = 0;895896	// Establish world Military strength average897	int iWorldMilitaryAverage = GC.getGame().GetWorldMilitaryStrengthAverage(GetPlayer()->GetID(), true, true);898899	// Establish world culture and tourism averages900	int iNumPlayersAlive = 0;901	int iWorldCultureAverage = 0;902	int iWorldTourismAverage = 0;903	for(iMajorLoop = 0; iMajorLoop < MAX_MAJOR_CIVS; iMajorLoop++)904	{905		eMajor = (PlayerTypes) iMajorLoop;906907		if(GET_PLAYER(eMajor).isAlive())908		{909			iWorldCultureAverage += GET_PLAYER(eMajor).GetJONSCultureEverGenerated();910			iWorldTourismAverage += GET_PLAYER(eMajor).GetCulture()->GetTourism();911			iNumPlayersAlive++;912		}913	}914	iWorldCultureAverage /= iNumPlayersAlive;915	iWorldTourismAverage /= iNumPlayersAlive;916917	// Establish world Tech progress average918	iNumPlayersAlive = 0;919	int iWorldNumTechsAverage = 0;920	TeamTypes eTeam;921	for(int iTeamLoop = 0; iTeamLoop < MAX_MAJOR_CIVS; iTeamLoop++)	// Looping over all MAJOR teams922	{923		eTeam = (TeamTypes) iTeamLoop;924925		if(GET_TEAM(eTeam).isAlive())926		{927			iWorldNumTechsAverage += GET_TEAM(eTeam).GetTeamTechs()->GetNumTechsKnown();928			iNumPlayersAlive++;929		}930	}931	iWorldNumTechsAverage /= iNumPlayersAlive;932933	// Look at every Major we've met934	for(iMajorLoop = 0; iMajorLoop < MAX_MAJOR_CIVS; iMajorLoop++)935	{936		eMajor = (PlayerTypes) iMajorLoop;937938		if(GET_PLAYER(eMajor).isAlive() && iMajorLoop != GetPlayer()->GetID())939		{940			if(pTeam.isHasMet(GET_PLAYER(eMajor).getTeam()))941			{942				for(iGrandStrategiesLoop = 0; iGrandStrategiesLoop < GetAIGrandStrategies()->GetNumAIGrandStrategies(); iGrandStrategiesLoop++)943				{944					eGrandStrategy = (AIGrandStrategyTypes) iGrandStrategiesLoop;945					pGrandStrategy = GetAIGrandStrategies()->GetEntry(iGrandStrategiesLoop);946					strGrandStrategyName = (CvString) pGrandStrategy->GetType();947948					if(strGrandStrategyName == "AIGRANDSTRATEGY_CONQUEST")949					{950						iPriority = GetGuessOtherPlayerConquestPriority(eMajor, iWorldMilitaryAverage);951					}952					else if(strGrandStrategyName == "AIGRANDSTRATEGY_CULTURE")953					{954						iPriority = GetGuessOtherPlayerCulturePriority(eMajor, iWorldCultureAverage, iWorldTourismAverage);955					}956					else if(strGrandStrategyName == "AIGRANDSTRATEGY_UNITED_NATIONS")957					{958						iPriority = GetGuessOtherPlayerUnitedNationsPriority(eMajor);959					}960					else if(strGrandStrategyName == "AIGRANDSTRATEGY_SPACESHIP")961					{962						iPriority = GetGuessOtherPlayerSpaceshipPriority(eMajor, iWorldNumTechsAverage);963					}964965					vGrandStrategyPriorities.push_back(iGrandStrategiesLoop, iPriority);966					vGrandStrategyPrioritiesForLogging.push_back(iPriority);967				}968969				if(vGrandStrategyPriorities.size() > 0)970				{971					// Add "No Grand Strategy" in case we just don't have enough info to go on972					iPriority = /*40*/ GC.getAI_GRAND_STRATEGY_GUESS_NO_CLUE_WEIGHT();973974					vGrandStrategyPriorities.push_back(NO_AIGRANDSTRATEGY, iPriority);975					vGrandStrategyPrioritiesForLogging.push_back(iPriority);976977					vGrandStrategyPriorities.SortItems();978979					eGrandStrategy = (AIGrandStrategyTypes) vGrandStrategyPriorities.GetElement(0);980					iPriority = vGrandStrategyPriorities.GetWeight(0);981					eGuessConfidence = NO_GUESS_CONFIDENCE_TYPE;982983					// How confident are we in our Guess?984					if(eGrandStrategy != NO_AIGRANDSTRATEGY)985					{986						if(iPriority >= /*120*/ GC.getAI_GRAND_STRATEGY_GUESS_POSITIVE_THRESHOLD())987						{988							eGuessConfidence = GUESS_CONFIDENCE_POSITIVE;989						}990						else if(iPriority >= /*70*/ GC.getAI_GRAND_STRATEGY_GUESS_LIKELY_THRESHOLD())991						{992							eGuessConfidence = GUESS_CONFIDENCE_LIKELY;993						}994						else995						{996							eGuessConfidence = GUESS_CONFIDENCE_UNSURE;997						}998					}9991000					SetGuessOtherPlayerActiveGrandStrategy(eMajor, eGrandStrategy, eGuessConfidence);10011002					LogGuessOtherPlayerGrandStrategy(vGrandStrategyPrioritiesForLogging, eMajor);1003				}10041005				vGrandStrategyPriorities.clear();1006				vGrandStrategyPrioritiesForLogging.clear();1007			}1008		}1009	}1010}

Calls

Called by