Craig_Sutter
Deity
I have cludged together some code to give Golden Age points or extended Golden Ages to a civilization if they are in a Peace Treaty.
The Golden Age code I use in other function and it is working... I am a bit uncertain of the Peace Treaty detection and operation. I borrowed it from another's mod and changed it considerably. The original code installed or took away a building based on the code... mine engages a function. As well, the original function triggered on both PlayerDoTurn and WarStateChanged events... I saw this as unnecessary so removed the latter.
There are also items that I deem unneeded but have left in the code such as the tracking of IsTreaty = 0 or IsTreaty >= 1. I think that could be tightened up.
The code is quite hard to test... so first, I would ask if someone could kindly check the logic to see if I haven't screwed it up when I adjusted the original code. Also, does the code actually do as it is supposed to, or do I need to have kept the double trigger of PlayerDoTurn and WarStateChanged.
Finally, I am not certain if the above code will be additive if more than one treaty exists... I would like it to be, but am not certain how the saving of the GoldenAge items with the text key will react to multiple treaties. Perhaps there being any treaty in place would be better... but I'm not certain what the code will actually do in the end.
Here it is:
Thank-you for your help.
Craig
The Golden Age code I use in other function and it is working... I am a bit uncertain of the Peace Treaty detection and operation. I borrowed it from another's mod and changed it considerably. The original code installed or took away a building based on the code... mine engages a function. As well, the original function triggered on both PlayerDoTurn and WarStateChanged events... I saw this as unnecessary so removed the latter.
There are also items that I deem unneeded but have left in the code such as the tracking of IsTreaty = 0 or IsTreaty >= 1. I think that could be tightened up.
The code is quite hard to test... so first, I would ask if someone could kindly check the logic to see if I haven't screwed it up when I adjusted the original code. Also, does the code actually do as it is supposed to, or do I need to have kept the double trigger of PlayerDoTurn and WarStateChanged.
Finally, I am not certain if the above code will be additive if more than one treaty exists... I would like it to be, but am not certain how the saving of the GoldenAge items with the text key will react to multiple treaties. Perhaps there being any treaty in place would be better... but I'm not certain what the code will actually do in the end.
Here it is:
Code:
-- check to see if Normans have a peace treaty and give Golden Age points if so.
function NormanPeaceBuilding (iPlayer)
local IsNorman = false;
local pPlayer = Players[iPlayer]
local isTreaty = 0
--determine if Player is Norman
if (GameInfo.Civilizations.CIVILIZATION_GREECE.ID == pPlayer:GetCivilizationType()) and pPlayer:IsAlive () and pPlayer:GetNumCities() >= 1 then
IsNorman = true;
end
if (IsNorman == true ) then
for mPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do
local mPlayer = Players[mPlayer];
if mPlayer ~= pPlayer then
if (mPlayer:IsAlive()) then
local pTeam = pPlayer:GetTeam();
local mTeam = mPlayer:GetTeam();
if Teams[pTeam]:IsForcePeace(mTeam) then
print ("Is Treaty!!!!");
isTreaty = isTreaty + 1
end
end
end
end
if isTreaty >= 1 then
NormanGoldenAges(iPlayer)
end
else
end
end
GameEvents.PlayerDoTurn.Add(NormanPeaceBuilding);
local modData = Modding.OpenSaveData()
local modNormanGoldenAgeKey = "NormanGoldenAge"
local haveNormanGoldenAge = (modData.GetValue(modNormanGoldenAgeKey) == 1)
-- Sets up Norman trait
-- Determine bonus level based on number of puppeted cities
-- no Golden Age adds bonus to progress and sets mod data to false
-- if Golden Age sets mod data to true and increases Golden Age length
function NormanGoldenAges(iPlayer)
-- Set up bonus
local pPlayer = Players[iPlayer]
local Bonus = pPlayer:GetNumCities()
local NormanGoldenAgeProgressBonus = Bonus + (pPlayer:GetCurrentEra() * Bonus )
local IsNormanGoldenAge = pPlayer:IsNormanGoldenAge()
if not IsNormanGoldenAge then
pPlayer:ChangeNormanGoldenAgeProgressMeter( NormanGoldenAgeProgressBonus )
haveNormanGoldenAge = false
modData.SetValue(modNormanGoldenAgeKey, 1)
print (pPlayer:GetName() ,"is getting",NormanGoldenAgeProgressBonus, "points towards a Golden Age from Peace Treaties");
elseif IsNormanGoldenAge then
if (haveNormanGoldenAge == false) then
pPlayer:ChangeNormanGoldenAgeTurns( Bonus )
haveNormanGoldenAge = true
modData.SetValue(modNormanGoldenAgeKey, 1)
print (pPlayer:GetName() ,"has increased Golden Age by ",Bonus, "turns from Peace Treaties");
end
end
return
end
Thank-you for your help.
Craig