Palmyra, Collab Mod

If I didn't screw anything up, this should work.

Unfortunately, GreatPersonExpended only returns the type of Great Person (Artist, Scientist, etc.) and not the specific unit. So we aren't able to get the unit plot from GreatPersonExpended alone. There are ways around that, but first we need to understand the specifics of the Culture bonus in more detail. Is the bonus awarded when the unit is:
  • In a city (on the same plot as a city)?
  • In or next to a city?
  • In the working radius of a city?
  • Anywhere in Palmyran territory?
  • Anywhere on the map?

Answering this will guide how the code is developed.
 
Policy needs to give a the dummy promotion to all Great People. Everything else is blank.
 
Unfortunately, GreatPersonExpended only returns the type of Great Person (Artist, Scientist, etc.) and not the specific unit. So we aren't able to get the unit plot from GreatPersonExpended alone. There are ways around that, but first we need to understand the specifics of the Culture bonus in more detail. Is the bonus awarded when the unit is:
  • In a city (on the same plot as a city)?
  • In or next to a city?
  • In the working radius of a city?
  • Anywhere in Palmyran territory?
  • Anywhere on the map?

Answering this will guide how the code is developed.

It needs to be anywhere in the map and it needs to get the closest Palmyran city.
 
It needs to be anywhere in the map and it needs to get the closest Palmyran city.

Here's what I have. It's untested and I don't have time to test it today. There could be logic or coding errors:


Spoiler :
Code:
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()
				FTcount = FuneraryTowerCountPalmyra(pCity)
			elseif (pPlot:GetWorkingCity() ~= nil) then
				local FTcount = FuneraryTowerCountPalmyra(pPlot:GetWorkingCity())
			else
				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)
				else
					print("No city found, using capital");
					FTcount = FuneraryTowerCountPalmyra(pPlayer:GetCapitalCity())
				end
			end
			bGreatPerson = false
			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
		bGreatPerson = true
	end
end

GameEvents.GreatPersonExpended.Add(PalmyraGPexpended)

function FuneraryTowerCountPalmyra(city)
	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
				end
			end
		end    
	end
	return iFuneraryTowerNum
end

I used some of GPuzzle's code and changed how it looks for the correct city.
 
That didn't actually seem to work.
 
That didn't actually seem to work.

There was an issue with the hand off to the code to count the Funerary Towers. I haven't tested all possibilities yet, but here's the update:

Spoiler :
Code:
-- 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

I also added a bunch of print statements to make troubleshooting easier.
 
Palmyra was retaken from IS. This isn't just a victory in the fight against terror, but also for Syria's culture and archaeology.

I was busy on the weekend, so couldn't test your code, Calcul8or, but this good news is a driving force for me. I'll continue work very soon.
 
Palmyra was retaken from IS. This isn't just a victory in the fight against terror, but also for Syria's culture and archaeology.

I was busy on the weekend, so couldn't test your code, Calcul8or, but this good news is a driving force for me. I'll continue work very soon.

I was happy to see the news about Palmyra as well. No worries, I wouldn't have had time to troubleshoot if something didn't work.
 
I was happy to see the news about Palmyra as well.

I actually cheered when I saw that on the news. My wife shot me a look as if to say, "What's wrong with you?" She just doesn't understand.
 
Spoiler :
QFZUabJ.jpg


DOWNLOAD
 
the Lua for the Tomb Towers still wasn't working and i couldn't see any obvious mistakes.
 
Sorry for my absence. Palmyra is going a lot slower then it could be.

The funerary tower still isn't functioning.
+1 Culture whenever a great person is expended in the city.

Code:
local civID    = GameInfoTypes["CIVILIZATION_FB_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
 
With help from TPangolin
Spoiler :
TtY8g5g.jpg

I created Zenobia herself and placed the buildings in the background. TPangolin made it look 10x better with lighting, blending the background better, and some blur. (I think that's all he did, he can correct me if i'm wrong)

The first one uses the face i made, this one uses a face TPangolin made:
Spoiler :
pjaTJzz.png


Which one do people prefer? TPang thinks mine looks too blurry, which i agree on, but i feel theres something off about his. I wanted other peoples opinions, since i don't want to make the choice off my own opinion (Especially for a collab mod)
 
With help from TPangolin
Spoiler :
TtY8g5g.jpg

I created Zenobia herself and placed the buildings in the background. TPangolin made it look 10x better with lighting, blending the background better, and some blur. (I think that's all he did, he can correct me if i'm wrong)

The first one uses the face i made, this one uses a face TPangolin made:
Spoiler :
pjaTJzz.png


Which one do people prefer? TPang thinks mine looks too blurry, which i agree on, but i feel theres something off about his. I wanted other peoples opinions, since i don't want to make the choice off my own opinion (Especially for a collab mod)

As they are now, I like yours better. However, if the nose and mouth were shrunk down a little bit on Tpang's, it would be near perfect.
 
I uploaded the wrong one. Use this instead.
 
Back
Top Bottom