print("------------------------------------------")
print("--- Ylisse support script initializing ---")
print("------------------------------------------")
iBonusPerTurn = 2 --To be tweaked by playtesting. Put here for easy changing.
warTable = {}
function raiseCityStateInfluence( player )
local pPlayer = Players[player]
if pPlayer:IsEverAlive() and pPlayer:IsAlive() then
print("Turn started for ",pPlayer:GetCivilizationShortDescription())
if pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_YLISSE"] then
iTeam=pPlayer:GetTeam()
pTeam=Teams[iTeam]
atPeace=true
for iOtherTeam, pOtherTeam in pairs(Teams) do
if pTeam:IsAtWar(iOtherTeam) and iOtherTeam~=63 then atPeace=false end --Exclude 63 because that is Barbarians!
end
if (not atPeace) then print("--Ylisse is at war. Influence will not be raised.") end
if atPeace then
print("--raising influence with protected city-states")
for iLoop = GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do
pMinorCiv=Players[iLoop]
if pMinorCiv:IsEverAlive() and pMinorCiv:IsAlive() then
if pPlayer:IsProtectingMinor(iLoop) then
print("--",pMinorCiv:GetCivilizationShortDescription())
pMinorCiv:ChangeMinorCivFriendshipWithMajor(player,iBonusPerTurn)
end
end
end
end
end end
end
function WarDeclared(attacker, defender, declaration)
if (not declaration) then
return
end
if (warTable[attacker] ~= nil) then
warTable[attacker] = nil
else
warTable[defender] = attacker
for iAttackPlayer = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do --need to move from Teams to Players
for iDefendPlayer = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
pAttackPlayer=Players[iAttackPlayer]
pDefendPlayer=Players[iDefendPlayer]
if pAttackPlayer:IsEverAlive() and pAttackPlayer:IsAlive() --basic Is Alive checkups
and pDefendPlayer:IsEverAlive() and pDefendPlayer:IsAlive() then
if pAttackPlayer:GetTeam()==attacker and pDefendPlayer:GetTeam()==defender then --now we can finally get somewhere
print(pAttackPlayer:GetCivilizationShortDescription(),"declared war on",pDefendPlayer:GetCivilizationShortDescription())
if pDefendPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_YLISSE"] then
print("--Reducing city-state influence accordingly")
for iLoop = GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do --go through minor civs
pMinorCiv = Players[iLoop]
if pMinorCiv:IsEverAlive() and pMinorCiv:IsAlive() then
iYlisseInfluence=pMinorCiv:GetMinorCivFriendshipWithMajor(iDefendPlayer)
pMinorCiv:ChangeMinorCivFriendshipWithMajor(iAttackPlayer, (0-iYlisseInfluence))
end
end
end
end
end end end
end
end
Events.WarStateChanged.Add(WarDeclared)
GameEvents.PlayerDoTurn.Add(raiseCityStateInfluence)