Detecting Ideology Chosen

sm4

Chieftain
Joined
Nov 17, 2013
Messages
27
I am trying to detect when Ideology is chosen. I tried to detect policy branch using the code below, but it doesn't work for any of the ideologies. It works fine for any other policy branch.


Code:
function listener(playerID, policyBranchID)
    print("Policy branch selected by "..tostring(playerID)..", "..tostring(policyBranchID))
end

GameEvents.PlayerAdoptPolicyBranch.Add(listener)

Is there any other way how to detect it? I'd like to know which of the branches were selected and both in case of AI and the player.
 
Try catching PlayerAdoptPolicy instead. The code that chooses an ideology by-passes the branch adoption event, but individual tenets are taken via the same code as policies, so should send the PlayerAdoptPolicy event
 
Try catching PlayerAdoptPolicy instead. The code that chooses an ideology by-passes the branch adoption event, but individual tenets are taken via the same code as policies, so should send the PlayerAdoptPolicy event

I already tried that. I am able to detect the first tenet chosen. But not the ideology. You seem to have a good knowledge of the API. Could you maybe direct me where to look for code that would say something like: "Ideology can be chosen, choose it" for AI? Not specifically, but where would I look for such thing.
 
I already tried that. I am able to detect the first tenet chosen. But not the ideology
You can easily lookup the ideology from the tenet via the database (GameInfo entries). You also know if the ideology is being chosen initially by counting the number of tenets the player has

Could you maybe direct me where to look for code that would say something like: "Ideology can be chosen, choose it" for AI? .

It's all in the C++ source that's part of the SDK - classes of interest are CvPlayer, CvPlayerAI, CvPolicyClasses and CvPolicyAI
 
You can easily lookup the ideology from the tenet via the database (GameInfo entries). You also know if the ideology is being chosen initially by counting the number of tenets the player has



It's all in the C++ source that's part of the SDK - classes of interest are CvPlayer, CvPlayerAI, CvPolicyClasses and CvPolicyAI

I need to detect the moment of ideology choice - because I want to generate a great person at that time. But you gave me an idea: I think I can detect the possible tenets (policies) that are available using GameEvents.PlayerCanAdoptPolicy. From there it should be easy to figure out, which policy was just adopted. I will try it and see whether this even happens on the same turn the ideology is chosen or on the next turn the player has enough culture. Hopefully the former.
 
I need to detect the moment of ideology choice - because I want to generate a great person at that time. But you gave me an idea: I think I can detect the possible tenets (policies) that are available using GameEvents.PlayerCanAdoptPolicy. From there it should be easy to figure out, which policy was just adopted. I will try it and see whether this even happens on the same turn the ideology is chosen or on the next turn the player has enough culture. Hopefully the former.

I use something like to this:

Code:
function IdeologyChosen(playerID, policyTypeID)
	local policyBranchType = GameInfo.Policies[policyTypeID].PolicyBranchType
	local policyLevel = GameInfo.Policies[policyTypeID].Level
	if (policyBranchType == ideologyID and policyLevel == 1) then
		--do stuff
	end
end
GameEvents.PlayerAdoptPolicy.Add(IdeologyChosen)

where ideologyID is set the Branch type that you're looking for.
 
I use something like to this:

Code:
function IdeologyChosen(playerID, policyTypeID)
	local policyBranchType = GameInfo.Policies[policyTypeID].PolicyBranchType
	local policyLevel = GameInfo.Policies[policyTypeID].Level
	if (policyBranchType == ideologyID and policyLevel == 1) then
		--do stuff
	end
end
GameEvents.PlayerAdoptPolicy.Add(IdeologyChosen)

where ideologyID is set the Branch type that you're looking for.

This is unfortunately the same - it will detect the first tenet, which I already can do. However you can adopt ideology without tenets, having tourism and unhappinness effects. So that's what I am looking for. Just the adoption of ideology.
 
This method returns the ID of the ideology 'policy branch' and -1 if there is none.

Players[id]:GetLateGamePolicyTree()

Now I only have to find a hook as soon as possible to trigger what I need. Probably GameEvents.PlayerDoTurn()? Therefore I will be able to generate the great person the next turn after the ideology is chosen.
 
GetLateGamePolicyTree() might be what your looking for. It's used in the dll as
eOtherPlayerIdeology = kOtherPlayer.GetPlayerPolicies()->GetLateGamePolicyTree();
and it looks like it's exported to lua.

Nvm, didn't notice sm4 beat me to it.
 
Back
Top Bottom