Problem with Golden Age in lua

Craig_Sutter

Deity
Joined
Aug 13, 2002
Messages
2,773
Location
Calgary, Canada
This portion of my code is not longer working with BNW. It worked with G & K. It gives golden age bonuses based upon influence with a particular city state.

I remember reading that ChangeGoldenAgeTurns() has been removed with BNW but my search failed to find the relevant entry.

Can anyone tell me which of the functions I'm using has been altered or removed? And if so, are there BNW equivalents I can use to rework this function?

Code:
local modData = Modding.OpenSaveData()
local modGoldenAgeKey = "GoldenAge"
local haveGoldenAge = (modData.GetValue(modGoldenAgeKey) == 1)

-- Sets up Free Imperial Cities and Holy Roman Empire
-- Determines if FIC is alive
-- Determine bonus level based on alliance status: friend or ally
-- no Golden Age adds bonus to progress and sets mod data to false
-- if Golden Age sets mod data to true and increases Golden Age length

function HREGoldenAges()

local FIC
local iFIC
local HRE
local iHRE

-- find FIC

	for iPlayer=GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do  

	local pFIC = Players[iPlayer]

		if (GameInfo.MinorCivilizations.MINOR_CIV_FREE_IMPERIAL_CITIES.ID == pFIC:GetMinorCivType()) then
	
		FIC = pFIC
		iFIC = iPlayer
		
		end	
	end

--Set up HRE

	for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do

	local pHRE = Players[iPlayer]

   		if (GameInfo.Civilizations.CIVILIZATION_PERSIA.ID == pHRE:GetCivilizationType()) then
	
		HRE = pHRE
		iHRE = iPlayer

		end
	end
	
-- Set up bonus
	
	if ( FIC:IsAlive () ) then

		if not FIC:IsFriends( iHRE ) and not FIC:IsAllies( iHRE ) then	-- at neutral level
		
		local CityBonus = FIC:GetNumCities()
		local Bonus = math.ceil(CityBonus/4)		
		local GoldenAgeProgressBonus = Bonus + (HRE:GetCurrentEra() * Bonus )
		local IsGoldenAge = HRE:IsGoldenAge()

			if not IsGoldenAge then

			HRE:ChangeGoldenAgeProgressMeter( GoldenAgeProgressBonus )
			haveGoldenAge = false
			modData.SetValue(modGoldenAgeKey, 1)
			print (HRE:GetName() ,"is getting",GoldenAgeProgressBonus, "points towards a Golden Age from relations with", FIC:GetName());

			elseif IsGoldenAge then

				if (haveGoldenAge == false) then

				HRE:ChangeGoldenAgeTurns( math.ceil(Bonus/3) )
				haveGoldenAge = true
				modData.SetValue(modGoldenAgeKey, 1)
				print (HRE:GetName() ,"has increased Golden Age by",Bonus,"turns due to friendship with", FIC:GetName());

				end
		
			end

		elseif FIC:IsFriends( iHRE ) and not FIC:IsAllies( iHRE ) then	-- at FRIENDS level
		
		local CityBonus = FIC:GetNumCities()
		local Bonus = math.ceil(CityBonus/3)		
		local GoldenAgeProgressBonus = Bonus + (HRE:GetCurrentEra() * Bonus )
		local IsGoldenAge = HRE:IsGoldenAge()

			if not IsGoldenAge then

			HRE:ChangeGoldenAgeProgressMeter( GoldenAgeProgressBonus )
			haveGoldenAge = false
			modData.SetValue(modGoldenAgeKey, 1)
			print (HRE:GetName() ,"is getting",GoldenAgeProgressBonus, "points towards a Golden Age from friendship with", FIC:GetName());

			elseif IsGoldenAge then

				if (haveGoldenAge == false) then

				HRE:ChangeGoldenAgeTurns( math.ceil(Bonus/2) )
				haveGoldenAge = true
				modData.SetValue(modGoldenAgeKey, 1)
				print (HRE:GetName() ,"has increased Golden Age by",Bonus,"turns due to friendship with", FIC:GetName());

				end
		
			end

		elseif FIC:IsAllies( iHRE ) then
			
		local CityBonus = FIC:GetNumCities()
		local Bonus = math.ceil(CityBonus/2)		
		local GoldenAgeProgressBonus = Bonus + (HRE:GetCurrentEra() * Bonus )
		local IsGoldenAge = HRE:IsGoldenAge()

			if not IsGoldenAge then

			HRE:ChangeGoldenAgeProgressMeter( GoldenAgeProgressBonus )
			haveGoldenAge = false
			modData.SetValue(modGoldenAgeKey, 1)
			print (HRE:GetName() ,"is getting",GoldenAgeProgressBonus, "points towards a Golden Age from alliance with", FIC:GetName());

			elseif IsGoldenAge then

				if (haveGoldenAge == false) then

				HRE:ChangeGoldenAgeTurns( Bonus )
				haveGoldenAge = true
				modData.SetValue(modGoldenAgeKey, 1)
				print (HRE:GetName() ,"has increased Golden Age by ",Bonus, "turns due to alliance with", FIC:GetName());

				end
		
			end

		end
	end
	
end

Events.ActivePlayerTurnEnd.Add( HREGoldenAges )
 
What do the logs tell you? Always look there first!

ChangeGoldenAgeTurns still exist in BnW, so that's no the issue.
 
Logs show the function is not being run (they report no errors). The print statements are not showing up. Other unrelated functions in the file are working and their print statements are working.

Something has to have changed with BNW as the function had previously worked.

I will do some more searching as I do recall a related thread in the last month or so.
 
When in doubt, add more print statements ;)

As far as I can tell ActivePlayerTurnEnd still exist, so the function should be called.
 
Fiddled with my map and added positive diplomatic influence to the Holy Roman Empire with the city state. The function then fired off.

Should still have fired off in any case, even with negative influence. No idea why it did not... have to go through the logic to see what is not working.

should give bonus if not friend and not ally.
else should give bonus+ if friend and not ally.
else should give bonus ++ if ally

Any way that negative influence might not trigger this function?
 
Back
Top Bottom