Craig_Sutter
Deity
Scenario VP can be added to the timed victory screen using lua. This VP value accumulates each time the function is fired. I would like to allocate VP based on GameSpeed and have created a function that does so... it fires off every 5/3/2/1 turns based upon the game speed.
Here it is:
My only question is, are there any obvious problems with the code for this? Could someone look it over to see that I'm not neglecting anything?
Thanks.
Here it is:
Code:
-- to allocate additional Scenario VP based upon gamespeed.
-- Every 5 turns for Marathon/ 3 turns for Epic/ 2 turns for Standard/ 1 turn for Quick
local GameSpeed = Game.GetGameSpeedType()
function VictoryPointProcessing (iPlayer)
if Game.GetGameTurn()>= 1 then
if GameSpeed == 0 then -- Marathon
if math.fmod (Game.GetGameTurn(), 5) == 0 then
ScenarioOne(iPlayer)
ScenarioTwo(iPlayer)
end
elseif GameSpeed == 1 then -- Epic
if math.fmod (Game.GetGameTurn(), 3) == 0 then
ScenarioOne(iPlayer)
ScenarioTwo(iPlayer)
end
elseif GameSpeed == 2 then -- Standard
if math.fmod (Game.GetGameTurn(), 2) == 0 then
ScenarioOne(iPlayer)
ScenarioTwo(iPlayer)
end
elseif GameSpeed == 3 then -- Quick
ScenarioOne(iPlayer)
ScenarioTwo(iPlayer)
else
return
end
end
end
GameEvents.PlayerDoTurn.Add(VictoryPointProcessing)
-- Victory point processing for possession of Earldoms
-- .5 VP per Earldom rounded down.
function ScenarioOne(iPlayer)
local pPlayer = Players[iPlayer]
local iEarldom = GameInfoTypes.BUILDING_EARLDOM
local NumEarldoms = pPlayer:CountNumBuildings(iEarldom)
local EarldomsVP = math.floor(NumEarldoms*.5)
if pPlayer:IsAlive() and not pPlayer:IsMinorCiv() then
local iChange = EarldomsVP
pPlayer:ChangeScoreFromScenario1(iChange)
if iChange > 0 then
print("added VP for Earldoms = ", iChange)
end
end
end
-- Victory point processing for possession of London
-- 1 VP for control of London
function ScenarioTwo(iPlayer)
local pPlayer = Players[iPlayer]
local isLondon = false
local LondonVP = 0
if pPlayer:IsAlive() and not pPlayer:IsMinorCiv() then
-- check cities owned for London
for pCity in pPlayer:Cities() do
if pCity:GetName() == "London" then
isLondon = true
end
end
if isLondon then
LondonVP = 1
end
local iChange = LondonVP
pPlayer:ChangeScoreFromScenario2(iChange)
if iChange > 0 then
print("added VP for London", iChange)
end
end
end
My only question is, are there any obvious problems with the code for this? Could someone look it over to see that I'm not neglecting anything?
Thanks.