[Lua] Adding Culture and Faith depending on Gold from Trade Routes

Genghis.Khan

Person
Joined
Jun 9, 2012
Messages
934
Location
Somewhere
Basically, for the Armenian Civilization to be included in the UnOfficial Expansion: Rise and Fall of Empires Project, the Trait idea was to add Culture and Faith Based on Trade Routes.

I have chosen to add Culture and Faith depending on the Gold generated by Trade Routes, as it takes in account various factors, such as Population or Distance.

My knowdlege of Lua is very limited, but I can follow most of Lua logic, and I can probably do this, if I can undesetand how to do what I want to do.

My Progress


1. It is clear that. the first step is to only execute the Code if the Civilization is Armenia, requiring the Player:GetCivilizationType() Method.

2. Obviously, the second step would be to Calculate the Gold from Trade Routes. After some research on the CivFanatics Modiki I found how that can be accomplished via Player:GetCityConnectionGold().

3. Finnaly, I would have to Add Culture and Faith based on the Gold Per Turn Generation of Trade Routes.

Current Code:

Code:
[COLOR="DarkSlateBlue"]if[/COLOR] (pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_ARMENIA"]) [COLOR="DarkSlateBlue"]then[/COLOR]
  Player:GetCityConnectionGold()
    [COLOR="DarkSlateBlue"]if[/COLOR] Player:GetCityConnectionGold() > 1 [COLOR="DarkSlateBlue"]then[/COLOR]
       [COLOR="SeaGreen"]-- Player:ChangeJONSCulture(0.25 * iGoldFromTradeRoutes)
       --Player:ChangeFaith(0.10* iGoldFromTradeRoutes)[/COLOR]
     [COLOR="DarkSlateBlue"]end
end[/COLOR]

An Example of the Use of Something Similiar can be found in DLC/Expansion/Scenarios/FallOfRomeScenario/TurnsRemaining.lua

Spoiler :
Code:
GameEvents.PlayerDoTurn.Add(function(iPlayer) 
	
	--if (iPlayer ~= nil) then
	--	print("GameEvents.PlayerDoTurn.Add, iPlayer: " .. iPlayer);
	--else
	--	print("GameEvents.PlayerDoTurn.Add, iPlayer: nil");
	--end

	local savedData = Modding.OpenSaveData();
	local iCitiesCaptured = 0;
	if (IsWesternRoman(iPlayer)) then
		iCitiesCaptured = savedData.GetValue("WesternRomeCitiesCaptured");
		savedData.SetValue("WesternRomeCitiesCaptured", 0);
	elseif (IsEasternRoman(iPlayer)) then
		iCitiesCaptured = savedData.GetValue("EasternRomeCitiesCaptured")
		savedData.SetValue("EasternRomeCitiesCaptured", 0);
	end
	
	print("GameEvents.PlayerDoTurn.Add, iCitiesCaptured: " .. iCitiesCaptured);
	if (iCitiesCaptured > 0) then
		print("GameEvents.PlayerDoTurn.Add, rewarding culture");
		Players[iPlayer]:ChangeJONSCulture(20 * iCitiesCaptured);
	end



Main Questions:

1. Is this possible with Faith?
2. What else do I have to do for Adding Culture based on that iSomething?


Please, post full code, because as I said my knowdlege of Lua is very limited

Sorry fot bothering

- Genghis.Khan
 
Basically, for the Armenian Civilization to be included in the UnOfficial Expansion: Rise and Fall of Empires Project, the Trait idea was to add Culture and Faith Based on Trade Routes.

I have chosen to add Culture and Faith depending on the Gold generated by Trade Routes, as it takes in account various factors, such as Population or Distance.

My knowdlege of Lua is very limited, but I can follow most of Lua logic, and I can probably do this, if I can undesetand how to do what I want to do.

My Progress


1. It is clear that. the first step is to only execute the Code if the Civilization is Armenia, requiring the Player:GetCivilizationType() Method.

2. Obviously, the second step would be to Calculate the Gold from Trade Routes. After some research on the CivFanatics Modiki I found how that can be accomplished via Player:GetCityConnectionGold().

3. Finnaly, I would have to Add Culture and Faith based on the Gold Per Turn Generation of Trade Routes.

Current Code:

Code:
[COLOR="DarkSlateBlue"]if[/COLOR] (pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_ARMENIA"]) [COLOR="DarkSlateBlue"]then[/COLOR]
  Player:GetCityConnectionGold()
    [COLOR="DarkSlateBlue"]if[/COLOR] Player:GetCityConnectionGold() > 1 [COLOR="DarkSlateBlue"]then[/COLOR]
       [COLOR="SeaGreen"]-- Player:ChangeJONSCulture(0.25 * iGoldFromTradeRoutes)
       --Player:ChangeFaith(0.10* iGoldFromTradeRoutes)[/COLOR]
     [COLOR="DarkSlateBlue"]end
end[/COLOR]

An Example of the Use of Something Similiar can be found in DLC/Expansion/Scenarios/FallOfRomeScenario/TurnsRemaining.lua

Spoiler :
Code:
GameEvents.PlayerDoTurn.Add(function(iPlayer) 
	
	--if (iPlayer ~= nil) then
	--	print("GameEvents.PlayerDoTurn.Add, iPlayer: " .. iPlayer);
	--else
	--	print("GameEvents.PlayerDoTurn.Add, iPlayer: nil");
	--end

	local savedData = Modding.OpenSaveData();
	local iCitiesCaptured = 0;
	if (IsWesternRoman(iPlayer)) then
		iCitiesCaptured = savedData.GetValue("WesternRomeCitiesCaptured");
		savedData.SetValue("WesternRomeCitiesCaptured", 0);
	elseif (IsEasternRoman(iPlayer)) then
		iCitiesCaptured = savedData.GetValue("EasternRomeCitiesCaptured")
		savedData.SetValue("EasternRomeCitiesCaptured", 0);
	end
	
	print("GameEvents.PlayerDoTurn.Add, iCitiesCaptured: " .. iCitiesCaptured);
	if (iCitiesCaptured > 0) then
		print("GameEvents.PlayerDoTurn.Add, rewarding culture");
		Players[iPlayer]:ChangeJONSCulture(20 * iCitiesCaptured);
	end



Main Questions:

1. Is this possible with Faith?
2. What else do I have to do for Adding Culture based on that iSomething?


Please, post full code, because as I said my knowdlege of Lua is very limited

Sorry fot bothering

- Genghis.Khan

Change faith is undocumented. SetFaith isn't. I'd use GetFaith/SetFaith.

I am not sure what you mean by full code. Do you want me to make a working turotial like mod? It already looks like you've got all the right parts.
 
Change faith is undocumented.

If you count usage in official code, it's "documented" - see "C:\Program Files (x86)\Steam\SteamApps\common\Sid Meier's Civilization V\Debug\Active Player.ltp"

Works like all the others - basically adds to whatever is there
 
Back
Top Bottom