Craig_Sutter
Deity
The following code is supposed to fire if a player has the Apollo Program project constructed and owns London... however, in my recent test, the capital moved to London when London was captured by the player and had not yet built the project.
Can't figure that one out...
PS After looking at the code, it occurs to me that I don't need to loop through the players as I did since PlayerDoTurn does that anyhow. That should not matter as to my actual problem, but it is something that I need to address.
Thanks.
Can't figure that one out...

Code:
--resets capital if London owned by player
function ResetCapital(iPlayer)
for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do
local pPlayer = Players[iPlayer]
local pPlayerTeamID = pPlayer:GetTeam();
local pPlayerTeam = Teams[ pPlayer:GetTeam() ]
if (pPlayerTeam : GetProjectCount( GameInfoTypes["PROJECT_APOLLO_PROGRAM"] > 0 )) then
-- Enumerate cities
for pCity in pPlayer:Cities() do
local oldCapital = pPlayer:GetCapitalCity()
-- City exists and and is London and it is not the current capital?
if pCity ~= nil and pCity:GetName() == "London" and not pCity:IsCapital() then
pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_PALACE"], 1);
oldCapital:SetNumRealBuilding(GameInfoTypes["BUILDING_PALACE"], 0);
return pCity
end
end
end
end
--Operate functions to loop through all players
local function OnAllPlayersDoTurn(iPlayer)
ResetCapital(iPlayer)
end
GameEvents.PlayerDoTurn.Add(OnAllPlayersDoTurn)
PS After looking at the code, it occurs to me that I don't need to loop through the players as I did since PlayerDoTurn does that anyhow. That should not matter as to my actual problem, but it is something that I need to address.
Thanks.