function Iska_WaW_HW_CityCaptured(hexPos, playerID, cityID, newPlayerID)
local pPlot = Map.GetPlot( ToGridFromHex( hexPos.x, hexPos.y ) );
if pPlot:GetPlotCity() == nil then return end
local city = pPlot:GetPlotCity()
--if Iska_HW_Debug then print("Pre-start 0 code Iska_WaW_HW_CityCaptured: city: " .. city:GetName()) end
if city:IsHolyCityAnyReligion() then
if Iska_HW_Debug then print("Pre-start 1 code Iska_WaW_HW_CityCaptured: city: " .. city:GetName()) end
local defrel
for row in GameInfo.Religions() do
if city:IsHolyCityForReligion(row.ID) then
defrel = row.ID
break
end
end
--if Iska_HW_Debug then print("Pre-start 2 code Iska_WaW_HW_CityCaptured: city: " .. city:GetName()) end
for row in GameInfo.Religions() do
--if row.ID ~= nil then
--if Game.GetFounder(row.ID, -1) ~= nil then
if Iska_HW_Debug then print("Start code Iska_WaW_HW_CityCaptured: city: " .. city:GetName()) end
if g_PlayerActiveHolyWar[defrel .. "ActiveHolyWarWith" .. row.ID] or g_PlayerActiveHolyWar[row.ID .. "ActiveHolyWarWith" .. defrel] then
Iska_WaW_SetValue(defrel .. "ActiveHolyWarWith" .. row.ID, nil)
g_PlayerActiveHolyWar[defrel .. "ActiveHolyWarWith" .. row.ID] = nil
g_PlayerActiveHolyWar[row.ID .. "ActiveHolyWarWith" .. defrel] = nil
Iska_WaW_SetValue(row.ID .. "ActiveHolyWarWith" .. defrel, nil)
Iska_WaW_SetValue(Game.GetFounder(defrel, -1) .. "ActiveHolyWar", nil)
Iska_WaW_SetValue(Game.GetFounder(row.ID, -1) .. "ActiveHolyWar", nil)
g_PlayerActiveHolyWar[Game.GetFounder(defrel, -1)] = nil
g_PlayerActiveHolyWar[Game.GetFounder(row.ID, -1)] = nil
local hplayer = Players[Game.GetActivePlayer()]
local player = Players[newPlayerID]
local oplayer = Players[playerID]
if Players[newPlayerID]:GetReligionCreatedByPlayer() == row.ID then
local decrel = row.ID
if Iska_HW_Debug then print("The Holy Armies of " .. GameInfo.Religions[decrel].IconString .. " " .. Locale.Lookup(GameInfo.Religions[decrel].Description) .. " have captured " .. city:GetName() .. ", the Holy City of " .. GameInfo.Religions[defrel].IconString .. " " .. Locale.Lookup(GameInfo.Religions[defrel].Description) .. "! The Holy War of " .. GameInfo.Religions[decrel].IconString .. " " .. Locale.Lookup(GameInfo.Religions[decrel].Description) .. " has ended.") end
if player == hplayer or oplayer == hplayer or hplayer:HasReligionInMostCities(oplayer:GetReligionCreatedByPlayer()) or hplayer:HasReligionInMostCities(player:GetReligionCreatedByPlayer())
or Teams[hplayer:GetTeam()]:IsHasMet(player:GetTeam()) or Teams[hplayer:GetTeam()]:IsHasMet(oplayer:GetTeam()) then
local sTitle = Locale.Lookup("TXT_KEY_ISKA_HOLY_WAR_ENDED_TITLE")
local sText = Locale.ConvertTextKey("TXT_KEY_ISKA_HOLY_WAR_ENDED_CAPTURE_OTHER_DESC", city:GetName(), GameInfo.Religions[defrel].IconString, Locale.Lookup(GameInfo.Religions[defrel].Description), GameInfo.Religions[row.ID].IconString, Locale.Lookup(GameInfo.Religions[row.ID].Description))
player:AddNotification(NotificationTypes.NOTIFICATION_RELIGION_FOUNDED, sText, sTitle)
end
Players[newPlayerID]:ChangeFaith(1000)
Events.AddPopupTextEvent(HexToWorld(ToHexFromGrid(Vector2(Players[newPlayerID]:GetCapitalCity():GetX(),Players[newPlayerID]:GetCapitalCity():GetY()))), Locale.Lookup("TXT_KEY_ISKA_HOLY_WAR_ENDED_CELEBRATIONS") .. 1000 .. " [ICON_PEACE] Faith", 0)
else
if Iska_HW_Debug then print("The Holy City of " .. Locale.Lookup(GameInfo.Religions[defrel].Description) .. " has fallen! The Holy War of " .. Locale.Lookup(GameInfo.Religions[row.ID].Description) .. " has ended.") end
local sTitle = Locale.Lookup("TXT_KEY_ISKA_HOLY_WAR_ENDED_TITLE")
local sText = Locale.ConvertTextKey("TXT_KEY_ISKA_HOLY_WAR_ENDED_CAPTURE_PLAYER_DESC", city:GetName(), GameInfo.Religions[defrel].IconString, Locale.Lookup(GameInfo.Religions[defrel].Description), GameInfo.Religions[row.ID].IconString, Locale.Lookup(GameInfo.Religions[row.ID].Description))
if player == hplayer or oplayer == hplayer or hplayer:HasReligionInMostCities(oplayer:GetReligionCreatedByPlayer()) or hplayer:HasReligionInMostCities(player:GetReligionCreatedByPlayer())
or Teams[hplayer:GetTeam()]:IsHasMet(player:GetTeam()) or Teams[hplayer:GetTeam()]:IsHasMet(oplayer:GetTeam()) then
hplayer:AddNotification(NotificationTypes.NOTIFICATION_RELIGION_FOUNDED, sText, sTitle)
end
if Players[newPlayerID]:GetCapitalCity():GetReligiousMajority() == row.ID then
Players[newPlayerID]:ChangeFaith(750)
Events.AddPopupTextEvent(HexToWorld(ToHexFromGrid(Vector2(Players[newPlayerID]:GetCapitalCity():GetX(),Players[newPlayerID]:GetCapitalCity():GetY()))), Locale.Lookup("TXT_KEY_ISKA_HOLY_WAR_ENDED_CELEBRATIONS") .. 750 .. " [ICON_PEACE] Faith", 0)
end
end
end
if Iska_HW_Debug then print("End Iska_WaW_HW_CityCaptured.") end
end
--end
--end
end
end
Events.SerialEventCityCaptured.Add(Iska_WaW_HW_CityCaptured)