Bazaar developer reference

CvDiplomacyAI::DoUpdateDemands()

Defined in
CvDiplomacyAI.cpp, line 4626
Class
CvDiplomacyAI
Hook name
CivHooks::CvDiplomacyAI_DoUpdateDemands

Hooks

static bool BeforeCvDiplomacyAI_DoUpdateDemands(CvDiplomacyAI* self);static void AfterCvDiplomacyAI_DoUpdateDemands(CvDiplomacyAI* self);static void ReplaceCvDiplomacyAI_DoUpdateDemands(void (*original)(CvDiplomacyAI*), CvDiplomacyAI* self);CivRegisterBefore<CivHooks::CvDiplomacyAI_DoUpdateDemands>(host, &BeforeCvDiplomacyAI_DoUpdateDemands);CivRegisterAfter<CivHooks::CvDiplomacyAI_DoUpdateDemands>(host, &AfterCvDiplomacyAI_DoUpdateDemands);CivRegisterReplace<CivHooks::CvDiplomacyAI_DoUpdateDemands>(host, &ReplaceCvDiplomacyAI_DoUpdateDemands);

Code

4625/// Update out desire to make a demand from a player4626void CvDiplomacyAI::DoUpdateDemands()4627{4628	CvWeightedVector<PlayerTypes, MAX_MAJOR_CIVS, true> veDemandTargetPlayers;46294630	int iWeight;46314632	PlayerTypes eLoopPlayer;4633	for(int iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)4634	{4635		eLoopPlayer = (PlayerTypes) iPlayerLoop;46364637		if(IsPlayerValid(eLoopPlayer))4638		{4639			// Is eLoopPlayer a good target for making a demand?4640			if(IsPlayerDemandAttractive(eLoopPlayer))4641			{4642				iWeight = GC.getGame().getJonRandNumVA(100, "DIPLOMACY_AI: Random weight for player to make demand of. (%d; %d)", (int)GetPlayer()->GetID(), (int)eLoopPlayer);4643				veDemandTargetPlayers.push_back(eLoopPlayer, iWeight);4644			}4645		}4646	}46474648	bool bCancelDemand;46494650	// Any valid possibilities?4651	if(veDemandTargetPlayers.size() > 0)4652	{4653		bCancelDemand = false;46544655		// Only assign a player to be the target if we don't already have one4656		if(GetDemandTargetPlayer() == NO_PLAYER)4657		{4658			veDemandTargetPlayers.SortItems();46594660			int iChanceOfDemand = /*100*/ GC.getDEMAND_RAND();	// Maybe change this later to a lower value (10%?) - leaving it at 100 for now because the AI has a bit of trouble getting everything together to make a demand right now46614662			if(iChanceOfDemand > GC.getGame().getJonRandNum(100, "DIPLOMACY_AI: Should AI make demand of player it's hostile towards?"))4663			{4664				DoStartDemandProcess(veDemandTargetPlayers.GetElement(0));4665			}4666		}4667	}4668	// No one we're hostile towards to make a demand of4669	else4670	{4671		bCancelDemand = true;4672	}46734674	// If we're planning on making a demand, make sure it's still a good idea4675	if(GetDemandTargetPlayer() != NO_PLAYER)4676	{4677		if(!IsPlayerDemandAttractive(GetDemandTargetPlayer()))4678		{4679			bCancelDemand = true;4680		}4681	}46824683	// We're not hostile towards any one so cancel any demand work we have underway (if there's anything going on)4684	if(bCancelDemand)4685	{4686		DoCancelHaltDemandProcess();4687	}46884689	// See If we have a demand ready to make4690	DoTestDemandReady();4691}

Calls

Called by