-- PalmyraTest
-- Author: calcul8or
-- DateCreated: 3/22/2016 9:37:27 PM
--------------------------------------------------------------
local civID = GameInfoTypes["CIVILIZATION_PALMYRA"];
local iImprovementFuneraryTowerID = GameInfoTypes.IMPROVEMENT_PALMYRA_FUNERARY_TOWER
local bGreatPerson = false
function PalmyraFTbonus(iPlayer, UnitID, UnitType, iX, iY, bDelay, eByPlayer)
local pPlayer = Players[iPlayer]
if (pPlayer:IsAlive() and pPlayer:GetCivilizationType() == civID) then
if bGreatPerson then
print("Great person expended by Palmyra");
local FTcount = 0
local pPlot = Map.GetPlot(iX,iY)
if (pPlot:IsCity()) then
local pCity = pPlot:GetPlotCity()
print("It's a city")
FTcount = FuneraryTowerCountPalmyra(pCity, iPlayer)
elseif (pPlot:GetWorkingCity() ~= nil and pPlot:GetOwner() == iPlayer) then
local FTcount = FuneraryTowerCountPalmyra(pPlot:GetWorkingCity(), iPlayer)
print("Plot worked by city")
--Send to separate function?
else
print("Looking for the right city")
local unitDistance = 9999
local newCity = nil
for iCity in pPlayer:Cities() do
local iNewDistance = Map.PlotDistance(iCity:GetX(), iCity:GetY(), iX, iY)
print("iNewDistance = " .. iNewDistance)
if (iNewDistance < unitDistance) then
newCity = iCity
end
end
if (newCity ~= nil) then
FTcount = FuneraryTowerCountPalmyra(newCity, iPlayer)
else
print("No city found, using capital");
FTcount = FuneraryTowerCountPalmyra(pPlayer:GetCapitalCity(), iPlayer)
end
end
bGreatPerson = false
print("Changing culture by " .. FTcount)
pPlayer:ChangeJONSCulture(FTcount)
if (pPlayer:IsHuman() and FTcount > 0) then
Events.GameplayAlertMessage(Locale.ConvertTextKey("You have gained +{1_Num} Culture from the burial of a great person!", FTcount))
end
end
end
end
GameEvents.UnitPrekill.Add(PalmyraFTbonus)
function PalmyraGPexpended(playerID, iUnit)
local pPlayer = Players[playerID]
if (pPlayer:IsAlive() and pPlayer:GetCivilizationType() == civID) then
print("GP expended in GreatPersonExpended")
bGreatPerson = true
end
end
GameEvents.GreatPersonExpended.Add(PalmyraGPexpended)
function FuneraryTowerCountPalmyra(city, playerID)
local iFuneraryTowerNum = 0
for cityPlot = 0, city:GetNumCityPlots() - 1, 1 do
local plot = city:GetCityIndexPlot(cityPlot)
if plot and plot:GetOwner() == playerID then
if city:IsWorkingPlot(plot) then
if plot:GetImprovementType() == iImprovementFuneraryTowerID then
iFuneraryTowerNum = iFuneraryTowerNum + 1
print("iFuneraryTowerNum is " .. iFuneraryTowerNum)
end
end
end
end
return iFuneraryTowerNum
end