115 PolicyAdopted not firing for policy finishers

nextwave

Chieftain
Joined
Oct 15, 2011
Messages
9
Location
Arizona
ThalsUtilities.lua - HasFinishedBranch() always returns false when called from the OnYes function. The player:HasPolicy(branchFinisherID) runs before the finished policy is actually adopted so it is returning false.

This does not bring a player impacting bug present in your mod, but I enjoy editing policies a little bit and noticed this occurring when trying to add MinorInfluence on the patronage finisher and it would never add.

I'm giving some thought over what a good solution would be and if one comes to me I'll respond here with it. :)
 
Thank you for bringing this up; I've fixed it for v117.1 beta. :thumbsup:

I've encountered this situation before. The solution I use is to pass the currently-adopting policy as newPolicyID in the parameter list of HasFinishedBranch. The function now checks for:

PHP:
if (newPolicyID ~= policyInfo.ID) and not player:HasPolicy(policyInfo.ID) then
  return false
end

You can see a similar approach with the LuaEvents.CityOccupied event. For example, look how the isForced parameter is used in the UpdatePuppetOccupyStatus function of CiVUP - Events.lua. The city:IsOccupied() function returns false in the moment the player clicks the Occupy button, so the additional isForced parameter helps pass along the information that the city is in the process of being occupied. This also is used for updating unit promotions the moment a player clicks a unit's Upgrade button.
 
Back
Top Bottom