Editing a unit's sight & combat based on faith per turn

AW Arcaeca

Deus Vult
Joined
Mar 10, 2013
Messages
3,019
Location
Operation Padlock ground zero
As the title says, I would like to know how to make a trait that gives +1 sight for all units for every 30 :c5faith: per turn earned. Additionally, I'm considering adding, for land units only, +1 :c5strength: while defending per 50 :c5faith: per turn, and +1 :c5strength: while attacking per 100 :c5faith: per turn.

But the only thing I can find about unit sight is in the CvUnitLua.cpp file in
C:\Program Files (x86)\Steam\steamapps\common\Sid Meier's Civilization V SDK\CvGameCoreSource\CvGameCoreDLL\Lua .
Miraculously enough, the file also includes data for being in combat defending vs. being in combat attacking. But it's written in C++ (I think) so I don't know how to put that information into a lua file - which I also don't know how to code.

So anyone know how to code something like that? I'm still looking through the code for any data about the faith per turn earned...
 
You can use promotions using those conditions:

(pseudocode)

Code:
function EditSightAndCombatBasedOnFaithPerTurn(iPlayer)

-- loop through Player's units (there is an iterator for that; something like for pUnit in pPlayer:Units())

-- choose land units only and insert them on a table

-- get faith per turn

-- check if faith per turn is bigger than 30; etc
 -- Add +1 Sight promotion to every unit of this civilization
-- same thing
 -- etc

-- make this check every turn

GameEvents.PlayerDoTurn.Add(EditSightAndCombatBasedOnFaithPerTurn)
 
Like this?
Code:
function EditSightAndCombatBasedOnFaithPerTurn (iPlayer)
	local pPlayer = Players[iPlayer]
	local pUnit = pPlayer:Units()
	if (pPlayer:IsAlive()) then
		if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_THIS_CIV) then
			Players[pPlayer]:GetTotalFaithPerTurn()
			if (pPlayer:GetTotalFaithPerTurn() >= 30) then
				Unit.Promote("PROMOTIONTYPE_FAITH_SIGHT_BONUS", "PROMOTION_FAITH_SIGHT_BONUS", 1 pUnit)
			end
			if (pPlayer:GetTotalFaithPerTurn() >= 50) then
				if (pUnit:GetDomainType() == 3) then
					Unit: ??? 1
				end
			if (pPlayer:GetTotalFaithPerTurn() >= 100) then
				if (pUnit:GetDomainType() == 3) then
					Unit: ??? 1
				end
			-- check every turn
		end
	end
GameEvents.PlayerDoTurn.Add(EditSightAndCombatBAsedOnFaithPerTurn)
The ??? represents where the command for adding 1 strength to land units, and I still don't understand how to make the differentiation between adding attack strength and adding defense strength. I did find the API reference to be quite useful though.

That also leaves two more problems: how do you make a promotion that gives +1 sight with XML, and how do you make it loop every turn like Genghis.Khan was saying?
 
Back
Top Bottom