Craig_Sutter
Deity
This code is meant to add buildings to a Player's Capital when it is Allies or Friends to a particular city state (The Jomsvikings) and they have TECH_THEOCRACY.
The building(s) are going to be adding particular strategic resources to the capital by way of dummy buildings. I am looking at 7 strategic resources for Allied and 2 for Friends... so the buildings will provide 5/2 resources respectively.
Below is a rough setup for said code... it does not include the code for determining the Capital and installing the buildings, but that is something I am familiar with.
My question is whether the below code is the most efficient. I can't help feeling that there is a better way to do this code... perhaps multiple copies of the same building rather than 2 separate buildings might be better. And I feel that looping through iPlayer every turn when the situation probably remains relatively static from turn to turn seems inefficient.
As well, are there any significant errors in the code below and is the set up as efficient as it could be?
Thank-you for your advice.
The building(s) are going to be adding particular strategic resources to the capital by way of dummy buildings. I am looking at 7 strategic resources for Allied and 2 for Friends... so the buildings will provide 5/2 resources respectively.
Below is a rough setup for said code... it does not include the code for determining the Capital and installing the buildings, but that is something I am familiar with.
My question is whether the below code is the most efficient. I can't help feeling that there is a better way to do this code... perhaps multiple copies of the same building rather than 2 separate buildings might be better. And I feel that looping through iPlayer every turn when the situation probably remains relatively static from turn to turn seems inefficient.
As well, are there any significant errors in the code below and is the set up as efficient as it could be?
Thank-you for your advice.
Code:
--After gaining Theocracy, when Player is Allied with Jomsvikings add 2 buildings to its capital. If Friends with Jomsvikings add only 1 building.
--We want TeamIDs and Teams, not PlayerIDs.
function eCivJomsviking(iPlayer)
local pPlayer
local pJomsviking
local iJomsviking
local eCivTeamID
local eCivTeam
-- Set up Player
local pPlayer = Players[iPlayer]
local eCivTeamID = pPlayer:GetTeam();
local eCivTeam= Teams[ pPlayer:GetTeam() ]
if (eCivTeam:GetTeamTechs():HasTech( GameInfoTypes["TECH_THEOLOGY"] )) then
-- Set up Jomsviking Player
for IDPlayer=GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do
local pJomsviking = Players[IDPlayer]
if (GameInfo.MinorCivilizations.MINOR_CIV_JOMSVIKING.ID == pJomsviking:GetMinorCivType()) then
--Check if Player and Jomsvikings exist
if (pJomsviking:IsAlive() and pPlayer:IsAlive()) then
--Check if Player and Jomsvikings are Allies.
local pCity = pPlayer:GetCapitalCity()
if pJomsviking:IsAllies(iPlayer) then
--(install building #1)
--(install building #2)
--Check if Player and Jomsvikings are Friends.
elseif pJomsviking:IsFriends(iPlayer) then
--(remove building #1)
--(install building #2)
--Check if Player and Jomsvikings are neither Allies not Friends.
elseif not pJomsviking:IsAllies(iPlayer) and not pJomsviking:IsFriends(iPlayer) then
--(remove building #1)
--(remove building #2)
end
end
end
end
end
end
--Operate functions to loop through all players
local function OnAllPlayersDoTurn(iPlayer)
eCivJomsviking(iPlayer)
end
GameEvents.PlayerDoTurn.Add(OnAllPlayersDoTurn)