Function to Allocate Scenario VP based on GameSpeed

Craig_Sutter

Deity
Joined
Aug 13, 2002
Messages
2,773
Location
Calgary, Canada
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:

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.
 
I have been working on this code and for some reason, am not making any progress...

The first code works and gives expected results:

Code:
function ScenarioOne(iPlayer)


	local pPlayer = Players[iPlayer]
	local isLondon = false
	local LondonVP = 0
	local iEarldom = GameInfoTypes.BUILDING_EARLDOM
	local NumEarldoms = pPlayer:CountNumBuildings(iEarldom)
	local EarldomsVP = math.floor(NumEarldoms*.5)

	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 + EarldomsVP
		pPlayer:ChangeScoreFromScenario1(iChange)

		if iChange > 0 then
		print("added VP for London and Earldoms = ", iChange)
		end

	end	

end

GameEvents.PlayerDoTurn.Add(ScenarioOne)

However, I decided that I wanted the victory points to scale with game speed. So I created the following function... it is not working.

I suspect I'm missing something simple. It may be the way that I am using Game Speed turn as a divisor to look for a remainder of 0 as the gateway to the victory point allocation. I am getting no errors in lua but the print statements are also not being seen. I know that the lua page works as I simple overwrote the first code with the second. Perhaps Game Speed Turn is not a number, but text, although I doubt it... or the remainder function I am using is not available in the Civ 5 version of Lua.


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

-- Victory point processing for possession of Earldoms
-- .5 VP per Earldom rounded down.

function ScenarioOneVPProcessing (iPlayer)	
	
	local pPlayer = Players[iPlayer]
	
	if pPlayer:IsAlive() and not pPlayer:IsMinorCiv() then	
	
		local GameSpeed = Game.GetGameSpeedType()
		if Game.GetGameTurn()>= 1 then

			local iEarldom = GameInfoTypes.BUILDING_EARLDOM
			local NumEarldoms = pPlayer:CountNumBuildings(iEarldom)
			local EarldomsVP = math.floor(NumEarldoms*.5)
			local iChange = EarldomsVP

			if GameSpeed == 0 then -- Marathon
				if math.fmod (Game.GetGameTurn(), 5) == 0 then
				pPlayer:ChangeScoreFromScenario1(iChange)
				print("added VP for Earldoms, Marathon", iChange)
				end
		
			elseif GameSpeed == 1 then -- Epic
				if math.fmod (Game.GetGameTurn(), 3) == 0 then
				pPlayer:ChangeScoreFromScenario1(iChange)	
				print("added VP for Earldoms, Epic", iChange)	
				end

			elseif GameSpeed == 2 then -- Standard
				if math.fmod (Game.GetGameTurn(), 2) == 0 then
				pPlayer:ChangeScoreFromScenario1(iChange)
				print("added VP for Earldoms, Standard", iChange)	
				end

			elseif GameSpeed == 3 then -- Quick			
				pPlayer:ChangeScoreFromScenario1(iChange)
				print("added VP for Earldoms, Quick", iChange)	

			else

			return	

			end
		end
	end
end

GameEvents.PlayerDoTurn.Add(ScenarioOneVPProcessing)

-- Victory point processing for possession of London
-- 1 VP for control of London

function ScenarioTwoVPProcessing (iPlayer)	
	
	local pPlayer = Players[iPlayer]	
	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

			LondonVP = 1
				
			end

		end

		local GameSpeed = Game.GetGameSpeedType()
		if Game.GetGameTurn()>= 1 then
			
			local iChange = LondonVP

			if GameSpeed == 0 then -- Marathon
				if math.fmod (Game.GetGameTurn(), 5) == 0 then
				pPlayer:ChangeScoreFromScenario2(iChange)
				print("added VP for London, Marathon", iChange)
				end
		
			elseif GameSpeed == 1 then -- Epic
				if math.fmod (Game.GetGameTurn(), 3) == 0 then
				pPlayer:ChangeScoreFromScenario2(iChange)	
				print("added VP for London, Epic", iChange)	
				end

			elseif GameSpeed == 2 then -- Standard
				if math.fmod (Game.GetGameTurn(), 2) == 0 then
				pPlayer:ChangeScoreFromScenario2(iChange)
				print("added VP for London, Standard", iChange)	
				end

			elseif GameSpeed == 3 then -- Quick			
				pPlayer:ChangeScoreFromScenario2(iChange)
				print("added VP for London, Quick", iChange)	

			else

			return	

			end
		end
	end
end

GameEvents.PlayerDoTurn.Add(ScenarioTwoVPProcessing)

I am also using the following XML... it works as expected but only shows VP resulting from the first function, but not the second.

Code:
<Language_en_US>
		<Update>
			<Where Tag="TXT_KEY_VP_SCENARIO1"/>
			<Set Text="Earldoms"/>
		</Update>
		<Update>
			<Where Tag="TXT_KEY_VP_SCENARIO2"/>
			<Set Text="Control of London"/>
		</Update>
	</Language_en_US>

Any advice would be appreciated.
 
Must be something else you've done (which is why we ask for the actual mod and not just snippets of it)

If I put that code into the "My - Changes" mod (changing BUILDING_EARLDOM for BUILDING_MONUMENT) and start a game as Lizzie, I get all the prints you'd expect and my score changes as well
 
Thank-you... here is the zipped mod.

The file in question is Victory.lua in LUA folder.

I am surprised it isn't working when it works for you. It was a simple copy-paste over a working function, so I don't see how it is not activated.

Anyhow, here it is from my Dropbox (too big to upload to this site)...

Code:
https://www.dropbox.com/s/c3dbtc9im2h7xu3/The%20Viking%20Age%20for%20BNW%20%28v%206%29.zip?dl=0

Thank-you.
 
I have tried a couple of things...

I added print statements after the game turn check as in:

print("VP for Earldoms intitiated")

and

print("VP for London intitiated")

These printed out as expected.

I also changed the file name from Victory.lua to VictoryProcessing.lua, thinking there might be a file naming conflict (Victory.lua is such a name that it might be used in the Civ game itself and perhaps cause a conflict).

I am still not getting the VP additions when testing nor are any of the added VP checks printing.

It could be something wrong with the buildings... but that doesn't come out in the DB log and the buildings do exist in the cities. As well, this would not affect the London VP check which just depends upon possession of the city.

And my first function (that worked) checks both for London and Earldoms.

So I am still stymied.

The mod is posted in the previous post (without the print check noted in this post). It is 50 MB in size and is in my Dropbox.

In the meantime, I am going to add a few more print checks to see where the problem begins. The file is activated and the function fires off until I start checking against the turn division.

Thanks.
 
Sorry for not getting back to you on this, but I spent the entire weekend fixing a bug in my own (DLL) mod ... and now I have to work for a living until next weekend :(
 
I fixed it...

Turns out I was incorrectly using the GameSpeed ID as the type... for example...

using 1 for GameInfoTypes["GAMESPEED_STANDARD"] instead of GameInfoTypes["1"]. So I used the naming convention instead of the ID numbers and the code works.

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

-- Victory point processing for possession of Earldoms
-- .5 VP per Earldom rounded down.

function ScenarioOneVPProcessing (iPlayer)	
	
	local pPlayer = Players[iPlayer]
	
	if pPlayer:IsAlive() and not pPlayer:IsMinorCiv() and not pPlayer:IsBarbarian() then	
	
		local GameSpeed = Game.GetGameSpeedType()
		if Game.GetGameTurn()>= 1 then

			--print("VP for Earldoms intitiated")

			local iEarldom = GameInfoTypes.BUILDING_EARLDOM
			local NumEarldoms = pPlayer:CountNumBuildings(iEarldom)
			local EarldomsVP = math.floor(NumEarldoms*.5)
			local iChange = EarldomsVP

			if GameSpeed == GameInfoTypes["GAMESPEED_MARATHON"] then -- Marathon

				--print("Marathon check")

				if math.fmod (Game.GetGameTurn(), 5) == 0 then
				pPlayer:ChangeScoreFromScenario1(iChange)
				--print("added VP for Earldoms, Marathon", iChange)
				end
		
			elseif GameSpeed == GameInfoTypes["GAMESPEED_EPIC"] then -- Epic

				--print("Epic check")

				if math.fmod (Game.GetGameTurn(), 3) == 0 then
				pPlayer:ChangeScoreFromScenario1(iChange)	
				--print("added VP for Earldoms, Epic", iChange)	
				end

			elseif GameSpeed == GameInfoTypes["GAMESPEED_STANDARD"] then -- Standard

				--print("Standard check")

				if math.fmod (Game.GetGameTurn(), 2) == 0 then
				pPlayer:ChangeScoreFromScenario1(iChange)
				--print("added VP for Earldoms, Standard", iChange)	
				end

			elseif GameSpeed == GameInfoTypes["GAMESPEED_QUICK"] then -- Quick	
			
				--print("Quick check")
					
				pPlayer:ChangeScoreFromScenario1(iChange)
				--print("added VP for Earldoms, Quick", iChange)	

			else

			return	

			end
		end
	end
end

GameEvents.PlayerDoTurn.Add(ScenarioOneVPProcessing)

-- Victory point processing for possession of London
-- 1 VP for control of London

function ScenarioTwoVPProcessing (iPlayer)	
	
	local pPlayer = Players[iPlayer]	
	local LondonVP = 0	

	if pPlayer:IsAlive() and not pPlayer:IsMinorCiv() and not pPlayer:IsBarbarian() then
		
		-- check cities owned for London

		for pCity in pPlayer:Cities() do 

			if pCity:GetName() == "London" then

			LondonVP = 1
				
			end

		end

		local GameSpeed = Game.GetGameSpeedType()
		if Game.GetGameTurn()>= 1 then

			--print("VP for London intitiated")
			local iChange = LondonVP

			if GameSpeed == GameInfoTypes["GAMESPEED_MARATHON"] then -- Marathon

				--print("Marathon London check")

				if math.fmod (Game.GetGameTurn(), 5) == 0 then
				pPlayer:ChangeScoreFromScenario2(iChange)
				--print("added VP for London, Marathon", iChange)
				end
		
			elseif GameSpeed == GameInfoTypes["GAMESPEED_EPIC"] then -- Epic

				--print("Epic London check")

				if math.fmod (Game.GetGameTurn(), 3) == 0 then
				pPlayer:ChangeScoreFromScenario2(iChange)	
				--print("added VP for London, Epic", iChange)	
				end

			elseif GameSpeed == GameInfoTypes["GAMESPEED_STANDARD"] then -- Standard

				--print("Standard London check")

				if math.fmod (Game.GetGameTurn(), 2) == 0 then
				pPlayer:ChangeScoreFromScenario2(iChange)
				--print("added VP for London, Standard", iChange)	
				end

			elseif GameSpeed == GameInfoTypes["GAMESPEED_QUICK"] then -- Quick

				pPlayer:ChangeScoreFromScenario2(iChange)
				--print("added VP for London, Quick", iChange)	

			else

			return	

			end
		end
	end
end

GameEvents.PlayerDoTurn.Add(ScenarioTwoVPProcessing)

In any case, thank-you. Ready to move on to the next problem :) .
 
Back
Top Bottom