local iGoldenWonder = GameInfoTypes.BUILDING_PUEBLO_BONITO
local iGoldenMultiplier = 4
local pGoldenWonderPlot = nil
function OnGoldenWonderPlayerDoTurn(iPlayer)
if (iPlayer == GameDefines.MAX_PLAYERS-1) then
-- This is the Barbarian's turn (ie the end of the round), so grant the GA points to whomever controls the Golden Wonder
if (pGoldenWonderPlot) then
local pGoldenWonderCity = pGoldenWonderPlot:GetPlotCity()
if (pGoldenWonderCity) then
if (pGoldenWonderCity:IsHasBuilding(iGoldenWonder)) then
local iGolderOwner = pGoldenWonderCity:GetOwner()
if (iGolderOwner < GameDefines.MAX_MAJOR_CIVS) then
local pGoldenOwner = Players[iGolderOwner]
-- Typically you don't accrue GA points during a Golden Age
if (not pGoldenOwner:IsGoldenAge()) then
local iExportedLux = 0
for pResource in GameInfo.Resources() do
local iResource = pResource.ID
if (Game.GetResourceUsageType(iResource) == ResourceUsageTypes.RESOURCEUSAGE_LUXURY) then
if (pGoldenOwner:GetNumResourceAvailable(iResource, true) > 0) then
-- If you only want to count the number of luxury TYPES exported and not the total number of exports, make the next line "+ 1"
iExportedLux = iExportedLux + pGoldenOwner:GetResourceExport(iResource)
end
end
end
pGoldenOwner:ChangeGoldenAgeProgressMeter(iExportedLux * iGoldenMultiplier)
end
else
-- The Golden Wonder is currently controlled by a City State
end
else
-- This can happen if a city is razed on the plot and another immediately founded
GameEvents.PlayerDoTurn.Remove(OnGoldenWonderPlayerDoTurn)
end
else
-- The city on this plot has been razed; the Wonder has been destroyed
GameEvents.PlayerDoTurn.Remove(OnGoldenWonderPlayerDoTurn)
end
else
-- Should never happen
GameEvents.PlayerDoTurn.Remove(OnGoldenWonderPlayerDoTurn)
end
end
end
function OnCityConstructed(iPlayer, iCity, iBuilding)
if (iBuilding == iGoldenWonder) then
-- Don't need to watch for the Golden Wonder being built any more
GameEvents.CityConstructed.Remove(OnCityConstructed)
-- We want the plot and not the city, as the city could change hands
pGoldenWonderPlot = Players[iPlayer]:GetCityByID(iCity):Plot()
GameEvents.PlayerDoTurn.Add(OnGoldenWonderPlayerDoTurn)
end
end
GameEvents.CityConstructed.Add(OnCityConstructed)
-- If loading a game, we need to find the Golden Wonder
function FindGoldenWonder()
for iPlayer = 0, GameDefines.MAX_PLAYERS-2, 1 do -- -2 as the Barbies will never have it!
local pPlayer = Players[iPlayer]
if (pPlayer:IsAlive()) then
for pCity in pPlayer:Cities() do
if (pCity:IsHasBuilding(iGoldenWonder)) then
-- Don't need to watch for the Golden Wonder being built any more
GameEvents.CityConstructed.Remove(OnCityConstructed)
-- Remember the plot it's in
pGoldenWonderPlot = pCity:Plot()
print(string.format("Found the Golden Wonder in %s", pCity:GetName()))
GameEvents.PlayerDoTurn.Add(OnGoldenWonderPlayerDoTurn)
return
end
end
end
end
end
FindGoldenWonder()