function GreatPersonEffect( iHRE, pHRE, GreatPersonBonus )
--print(string.format("GreatPersonBonus of %d for %s:", GreatPersonBonus, pHRE:GetName()))
if GreatPersonBonus >= 6 then
local pCapital = pHRE:GetCapitalCity()
if pCapital ~= nil then
local Remainder = GreatPersonBonus % 6
GreatPersonBonus = GreatPersonBonus - Remainder
local CapitalExtraBonus = GreatPersonBonus / 6
local ClosestGP = 0
local GPAmount = 0
-- Determine the GP for which the progress is currently the highest
for specialist in GameInfo.Specialists() do
--print(string.format("%s: %d", pCapital:GetName(), specialist.ID))
-- GP with ID one is the citizen specialist, which isn't a proper specialist, so should always be trumped by another
if ClosestGP == 0 and specialist.ID ~= 0 then
ClosestGP = specialist.ID
--print(string.format(" ClosestGP in %s was citizen specialist (default), now %d", pCapital:GetName(), specialist.ID))
elseif ( pCapital:GetSpecialistGreatPersonProgressTimes100( specialist.ID ) > pCapital:GetSpecialistGreatPersonProgressTimes100( ClosestGP ) and specialist.ID ~= 0 ) then
ClosestGP = specialist.ID
--print(string.format(" new ClosestGP in %s: %d", pCapital:GetName(), specialist.ID))
end
GPAmount = specialist.ID
end
-- Apply bonus to that GP
if pCapital:GetSpecialistGreatPersonProgressTimes100( ClosestGP ) ~= 0 then
pCapital:ChangeSpecialistGreatPersonProgressTimes100( ClosestGP, CapitalExtraBonus * 100 )
--print(string.format(" GreatPersonBonus applied! (%s, %s) - %d points left", pHRE:GetName(), pCapital:GetName(), GreatPersonBonus - CapitalExtraBonus + Remainder))
else
ClosestGP = Game.Rand( GPAmount, "random GP" ) + 1 -- "+ 1" to avoid picking the citizen specialist
pCapital:ChangeSpecialistGreatPersonProgressTimes100( ClosestGP, CapitalExtraBonus * 100 )
--print(string.format(" GreatPersonBonus applied! (%s, %s) - %d points left (random pick)", pHRE:GetName(), pCapital:GetName(), GreatPersonBonus - CapitalExtraBonus + Remainder))
end
GreatPersonBonus = GreatPersonBonus - CapitalExtraBonus + Remainder
end
end
repeat
for pCity in pHRE:Cities() do
if GreatPersonBonus > 0 then
local ClosestGP = 0
local GPAmount = 0
-- Determine the GP for which the progress is currently the highest
for specialist in GameInfo.Specialists() do
--print(string.format("%s: %d", pCity:GetName(), specialist.ID))
-- GP with ID one is the citizen specialist, which isn't a proper specialist, so should always be trumped by another
if ClosestGP == 0 and specialist.ID ~= 0 then
ClosestGP = specialist.ID
--print(string.format(" ClosestGP in %s was citizen specialist (default), now %d", pCity:GetName(), specialist.ID))
elseif ( pCity:GetSpecialistGreatPersonProgressTimes100( specialist.ID ) > pCity:GetSpecialistGreatPersonProgressTimes100( ClosestGP ) and specialist.ID ~= 0 ) then
ClosestGP = specialist.ID
--print(string.format(" new ClosestGP in %s: %d", pCity:GetName(), specialist.ID))
end
GPAmount = specialist.ID
end
-- Apply bonus to that GP
if pCity:GetSpecialistGreatPersonProgressTimes100( ClosestGP ) ~= 0 then
pCity:ChangeSpecialistGreatPersonProgressTimes100( ClosestGP, 100 )
GreatPersonBonus = GreatPersonBonus - 1
--print(string.format(" GreatPersonBonus applied! (%s, %s) - %d points left", pHRE:GetName(), pCity:GetName(), GreatPersonBonus))
else
ClosestGP = Game.Rand( GPAmount, "random GP" ) + 1 -- "+ 1" to avoid picking the citizen specialist
pCity:ChangeSpecialistGreatPersonProgressTimes100( ClosestGP, 100 )
GreatPersonBonus = GreatPersonBonus - 1
--print(string.format(" GreatPersonBonus applied! (%s, %s) - %d points left (random pick)", pHRE:GetName(), pCity:GetName(), GreatPersonBonus))
end
end
end
until GreatPersonBonus < 1
end
-- Sets up Holy Roman Empire
-- Determines if HRE is alive
-- Determine bonus level based puppeted cities
-- Distribute points to Capital and then other cities
function HREGoldBonus(iPlayer)
--Set up HRE
local pHRE = Players[iPlayer]
local civHRE = false
if (GameInfo.Civilizations.CIVILIZATION_PERSIA.ID == pHRE:GetCivilizationType()) then
civHRE = true
end
-- Set up bonus
if ( pHRE:IsAlive () ) and civHRE == true then
local CityBonus = pHRE:GetNumCities()
local RathausBonus = pHRE:CountNumBuildings(GameInfoTypes["BUILDING_RATHAUS"])
local Bonus = (CityBonus+1)*2 + RathausBonus --palace +1
local GoldBonus = (Bonus*2) + math.ceil(pHRE:GetCurrentEra() * (Bonus))
pHRE:ChangeGold( GoldBonus )
--print (pHRE:GetName() ,"has increased Gold by ",GoldBonus, "gold due to Imperial tribute");
else
end
return
end
local modData = Modding.OpenSaveData()
local modGoldenAgeKey = "GoldenAge"
local haveGoldenAge = (modData.GetValue(modGoldenAgeKey) == 1)
-- Sets up Holy Roman Empire
-- Determines if HRE is alive
-- Determine bonus level based on number of puppeted cities
-- 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(iPlayer)
--Set up HRE
local pHRE = Players[iPlayer]
local civHRE = false
if (GameInfo.Civilizations.CIVILIZATION_PERSIA.ID == pHRE:GetCivilizationType()) then
civHRE = true
end
-- Set up bonus
if ( pHRE:IsAlive () ) and civHRE == true then
local CityBonus = pHRE:GetNumCities()
local Bonus = math.ceil(CityBonus/2)
local iGoldenAgePercent = GameInfo.GameSpeeds[Game.GetGameSpeedType()].GoldenAgePercent/ 100
local BonusMod = math.ceil(iGoldenAgePercent*Bonus)
local GoldenAgeProgressBonus = Bonus + (pHRE:GetCurrentEra() * Bonus )
local IsGoldenAge = pHRE:IsGoldenAge()
if not IsGoldenAge then
pHRE:ChangeGoldenAgeProgressMeter( GoldenAgeProgressBonus )
haveGoldenAge = false
modData.SetValue(modGoldenAgeKey, 1)
--print (pHRE:GetName() ,"is getting",GoldenAgeProgressBonus, "points towards a Golden Age from Free Imperial Cities");
elseif IsGoldenAge then
if (haveGoldenAge == false) then
pHRE:ChangeGoldenAgeTurns( BonusMod )
haveGoldenAge = true
modData.SetValue(modGoldenAgeKey, 1)
--print (pHRE:GetName() ,"has increased Golden Age by ",Bonus, "turns from Free Imperial Cities");
end
end
else
end
return
end
--Operate functions to loop through all players
local function OnAllPlayersDoTurn(iPlayer)
HREGreatPersons(iPlayer)
HREGoldBonus(iPlayer)
HREGoldenAges(iPlayer)
end
GameEvents.PlayerDoTurn.Add(OnAllPlayersDoTurn)