[LUA] Influence via Trade Routes

TheLunarArmy

Chieftain
Joined
Jul 9, 2014
Messages
59
Location
South-Africa
Hi guys, it's been a while since I lurked but I'm in the process of making a new civ for my friend.

The civ in question will be Diplomacy based so I would like to make a unique Caravansary that will cause any City-State trading with that City to have a bonus positive influence of 1 each turn (this stacks if you have multiple cities trading with that city state, up to +3).

My CIV5 API is a little rusty, so if anyone has experience in either Trade Routes or Changing city-state influence I would greatly appreciate input from you.

Here is what I have so far:

Code:
-- Establish all the trade routes by player
local myRoutes = Players[player]:GetTradeRoutes();

-- Step through every Route that is deconstructed in an ipair
for me,target in ipairs(myRoutes) do
	if target.ToCity:GetOwner().IsMinorCiv() then
                --Found a connected citystate!
                 target.ToCity:GetOwner():ChangeMinorCivFriendshipWithMajor(player, 1.0)

	end
end

Thanks
 
Figured it out. For anyone interested...

Spoiler :

Code:
local pCARAVANSARY = GameInfoTypes.BUILDING_CARAVANSARY;
local pSpeed = Game.GetGameSpeedType();
local influenceGain = 0.0;
if pSpeed == GameInfo.GameSpeeds['GAMESPEED_QUICK'].ID then
	influenceGain = math.ceil( 1.25 / 2.00 ) ;
elseif pSpeed == GameInfo.GameSpeeds['GAMESPEED_STANDARD'].ID then
	influenceGain = math.ceil( 1.00 / 2.00 );
elseif pSpeed == GameInfo.GameSpeeds['GAMESPEED_EPIC'].ID then
	influenceGain = math.ceil( 0.75 / 2.00 );
elseif pSpeed == GameInfo.GameSpeeds['GAMESPEED_MARATHON'].ID then
	influenceGain = math.ceil( 0.67 / 2.00 );
else
	influenceGain = math.ceil( 0.67 / 2.0 );
end

GameEvents.PlayerDoTurn.Add(function(iPlayer)
	local pPlayer = Players[iPlayer];
	if pPlayer:IsMinorCiv() then return end
	if not pPlayer:IsAlive() then return end
	local pTradeRoutes = pPlayer:GetTradeRoutes();
	--print ("Trade Routes for:", pPlayer:GetName() );
	for _, x in pairs(pTradeRoutes) do
		local pTargetCiv = Players[x.ToCity:GetOwner()];
		local pOriginCity = x.FromCity;
		if ( pTargetCiv:IsMinorCiv() and pOriginCity:IsHasBuilding(pCARAVANSARY) ) then
			--print ( "Success between", x.ToCity:GetName(), x.FromCity:GetName()   )
			pTargetCiv:ChangeMinorCivFriendshipWithMajor(pPlayer, influenceGain);
		end
	end
end)
 
Back
Top Bottom