--------------------------------------------------------------------
local g_iMitanniPlayer = -1
local g_iMitanniTeam = -1
local g_bMitanniAtWar = false
local g_iPalaceClass = GameInfoTypes.BUILDINGCLASS_PALACE
--------------------------------------------------------------------
function OnCityChange(_, iPlayer, _, iNewPlayer)
if (iPlayer == g_iMitanniPlayer or iNewPlayer == g_iMitanniPlayer) then
UpdateMitanniBonusYields()
end
end
--------------------------------------------------------------------
function OnWarStateChanged(iMyTeam, iTheirTeam, bWar)
-- When our war state changes with a team, recompute our global war state
if (iMyTeam == g_iMitanniTeam and bWar ~= g_bMitanniAtWar) then
g_bMitanniAtWar = AtWarWithAnyMajor(g_iMitanniTeam)
UpdateMitanniBonusYields()
end
end
--------------------------------------------------------------------
function AtWarWithAnyMajor(iTeam)
local pTeam = Teams[iTeam]
for iOtherPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
local pOtherPlayer = Players[iOtherPlayer]
if (pOtherPlayer:IsAlive() and pTeam:IsAtWar(pOtherPlayer:GetTeam())) then
return true
end
end
return false
end
--------------------------------------------------------------------
function UpdateMitanniBonusYields()
local pPlayer = Players[g_iMitanniPlayer]
local pCapital = pPlayer:GetCapitalCity()
local iBoost = pPlayer:GetNumCities()
-- Take away any previous culture bonus
pPlayer:ChangeJONSCulturePerTurnForFree(pCapital:SetBuildingYieldChange(g_iPalaceClass, YieldTypes.YIELD_CULTURE))
-- Update the per turn bonuses
if (g_bMitanniAtWar) then
pCapital:SetBuildingYieldChange(g_iPalaceClass, YieldTypes.YIELD_PRODUCTION, 0)
-- Culture cannot be added this way, but we can use the palace to store how much culture we need to add
pCapital:SetBuildingYieldChange(g_iPalaceClass, YieldTypes.YIELD_CULTURE, 2 * iBoost)
else
pCapital:SetBuildingYieldChange(g_iPalaceClass, YieldTypes.YIELD_PRODUCTION, iBoost)
pCapital:SetBuildingYieldChange(g_iPalaceClass, YieldTypes.YIELD_CULTURE, 0)
end
-- As per turn culture can't be added via the palace, add it directly to the player
pPlayer:ChangeJONSCulturePerTurnForFree(pCapital:SetBuildingYieldChange(g_iPalaceClass, YieldTypes.YIELD_CULTURE))
end
--------------------------------------------------------------------
function Init()
-- Find the player and team IDs for the Mitanni player (if any)
for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
local pPlayer = Players[iPlayer]
if (pPlayer:IsEverAlive()) then
-- if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_MITANNI) then
if (GetTraitInfo(pPlayer).Realpolitik > 0) then
g_iMitanniPlayer = iPlayer
g_iMitanniTeam = pPlayer:GetTeam()
break
end
end
end
-- If the Mitanni are in play, compute their global war state and hook the events
if (g_iMitanniPlayer ~= -1) then
g_bMitanniAtWar = AtWarWithAnyMajor(g_iMitanniTeam)
Events.SerialEventCityCreated.Add(OnCityChange)
Events.SerialEventCityDestroyed.Add(OnCityChange)
Events.SerialEventCityCaptured.Add(OnCityChange)
Events.WarStateChanged.Add(OnWarStateChanged)
print("mitanniUA loaded")
end
end
--------------------------------------------------------------------
Init()