Detecting a Player's Ideology

LeeS

Imperator
Joined
Jul 23, 2013
Messages
7,241
Location
Illinois, USA
I've done some searching on this sub-forum and have only found information to confirm my conclusion that it is not possible through any lua method to directly detect which (if any) Ideology a player has adopted.

GameEvents.PlayerAdoptPolicyBranch runs for everything except the Ideology Branches so far as I have been able to tell through setting up 'listener' functions and printing the results to the lua.log.

I wrote a detector function that runs off GameEvents.PlayerAdoptPolicy (and GameEvents.PlayerDoTurn for extra re-confirmation) that functions correctly when I use the pPlayer:HasPolicy() method.

Did I miss something simple-Simon here that can directly tell which Ideology the player has?

Spoiler :
The code doesn't actually do anything yet other than detect for Ideology and print to the log. In a 'real' mod I'd want to tweak and tighten up a bit, but here's the basic method I'm using:
Code:
FreedomIdeologyPolicies = { GameInfoTypes.POLICY_OPEN_SOCIETY, GameInfoTypes.POLICY_CREATIVE_EXPRESSION , GameInfoTypes.POLICY_CIVIL_SOCIETY , GameInfoTypes.POLICY_COVERT_ACTION , GameInfoTypes.POLICY_CAPITALISM , GameInfoTypes.POLICY_ECONOMIC_UNION }
OrderIdeologyPolicies = { GameInfoTypes.POLICY_HERO_OF_THE_PEOPLE, GameInfoTypes.POLICY_SOCIALIST_REALISM, GameInfoTypes.POLICY_SKYSCRAPERS, GameInfoTypes.POLICY_PATRIOTIC_WAR, GameInfoTypes.POLICY_DOUBLE_AGENTS, GameInfoTypes.POLICY_YOUNG_PIONEERS }
AutocracyIdeologyPolicies = { GameInfoTypes.POLICY_ELITE_FORCES, GameInfoTypes.POLICY_MOBILIZATION, GameInfoTypes.POLICY_UNITED_FRONT, GameInfoTypes.POLICY_FUTURISM, GameInfoTypes.POLICY_INDUSTRIAL_ESPIONAGE, GameInfoTypes.POLICY_FORTIFIED_BORDERS }

function AdoptPolicyListener(iPlayer, iPolicyID)
	local pPlayer = Players[iPlayer]
	local bFreedom, bOrder, bAutocracy = false, false, false
	for k,v in pairs(FreedomIdeologyPolicies) do
		if pPlayer:HasPolicy(v) then
			bFreedom = true
			break
		end
		if iPolicyID ~= nil and iPolicyID == v then
			bFreedom = true
			break
		end
	end
	for k,v in pairs(OrderIdeologyPolicies) do
		if pPlayer:HasPolicy(v) then
			bOrder = true
			break
		end
		if iPolicyID ~= nil and iPolicyID == v then
			bOrder = true
			break
		end
	end
	for k,v in pairs(AutocracyIdeologyPolicies) do
		if pPlayer:HasPolicy(v) then
			bAutocracy = true
			break
		end
		if iPolicyID ~= nil and iPolicyID == v then
			bAutocracy = true
			break
		end
	end
	print("Player " .. iPlayer .. " has Freedom Ideology is " .. tostring(bFreedom))
	print("Player " .. iPlayer .. " has Order Ideology is " .. tostring(bOrder))
	print("Player " .. iPlayer .. " has Autocracy Ideology is " .. tostring(bAutocracy))
end
GameEvents.PlayerAdoptPolicy.Add(AdoptPolicyListener)
 
I'm pretty sure I tested PlayerAdoptPolicyBranch and, that time, it worked for the ideology branches. In any case, you could do one of two things, depending on whether you want to know if the player has adopted a specific ideology.

First, you could just check for any ideology by checking that the policy has a level set to 1:

Code:
function AdoptPolicyListener(iPlayer, iPolicyID)
	local pPlayer = Players[iPlayer]
	if GameInfo.Policies[policyID].Level == 1 then
           print("player adopted an ideology")
        end
end
GameEvents.PlayerAdoptPolicy.Add(AdoptPolicyListener)

Otherwise,

Code:
function AdoptPolicyListener(iPlayer, iPolicyID)
	local pPlayer = Players[iPlayer]
	if GameInfo.Policies[policyID].PolicyBranchType == "POLICY_BRANCH_AUTOCRACY" then
           print("player adopted autocracy")
        elseif GameInfo.Policies[policyID].PolicyBranchType == "POLICY_BRANCH_FREEDOM" then
           print("player adopted freedom")
        elseif GameInfo.Policies[policyID].PolicyBranchType == "POLICY_BRANCH_ORDER" then
           print("player adopted order")
        end
end
GameEvents.PlayerAdoptPolicy.Add(AdoptPolicyListener)
 
In any event that verifies I'm not missing a direct method. Now I just have to decide whether to detect and store the player's ideology upon adoption, or do an every turn method.

Irksome that Firaxis didn't add a simple player:GetIdeology() when they rolled out BNW.


In any event I'll have to check out the method mentioned by V.V. I obviously looked right past that one.

[edit]Vice Virtuoso for the win! That is soooo much easier to deal with, and works exactly as you describe. It is -1 before adopting an Ideology, and is the Ideology's Policy Branch ID# after adopting an Ideology.

And no, the PlayerAdoptPolicyBranch does not fire when you select an ideology, but the PlayerAdoptPolicy fires when you select any of the 'tenets' (as it ouoght to since they're just policies) -- but there's nothing I like more in the evening-time than a little Firaxis consistency.
 
It essentially is GetIdeology(), just without using the word. Back in vanilla/G&K, Freedom/Order/Autocracy were all still mutually exclusive. It's just recycling the old API function name.

Though no, there isn't anything like GameEvents.PlayerAdoptIdeology. Best to check it with PlayerAdoptPolicy rather than PlayerDoTurn for performance.
 
Back
Top Bottom