emeralis00
Chieftain
Hello, I've been working on a new civ (referred to as Yuma from here), and while I am almost complete, the last piece is particularity difficult.
The idea is that when Yuma enters a war, up to two Minor Civ allies of the other party in the war switch sides and become Yuma's ally. I have some of it already implemented, but am not sure how to replicate the effects of a coup, which is exactly what I need. If anyone has some advice on how to perform a coup via lua, or replicate the effect I would greatly appreciate it.
The code I have so far is below. Other parts of the mod use Whoward's DLL so that is an available. It requires BNW.
I can provide other parts of the code if needed, as well as more elaboration on what I want done.
The idea is that when Yuma enters a war, up to two Minor Civ allies of the other party in the war switch sides and become Yuma's ally. I have some of it already implemented, but am not sure how to replicate the effects of a coup, which is exactly what I need. If anyone has some advice on how to perform a coup via lua, or replicate the effect I would greatly appreciate it.
The code I have so far is below. Other parts of the mod use Whoward's DLL so that is an available. It requires BNW.
Code:
local YUMA = GameInfo.Civilizations.CIVILIZATION_CHITOSAN.ID
function yumaWarCoup(iTeam1, iTeam2, bWar)
--print("OnWarStateChanged", iTeam1, iTeam2, bWar)
for _, pPlayer in pairs(Players) do --start finding Yuma
if pPlayer:IsEverAlive() then
if pPlayer:GetCivilizationType() == YUMA then
local fTeamID = pPlayer:GetTeam()
if fTeamID == iTeam1 then
print("Yuma is in a war. playerID is " ..pPlayer:GetID() ..". teamID is " ..fTeamID)
-- the code after this point has not been tested in game
local pEnemyPlayer = Players[iTeam2:GetLeaderID()]
if not pEnemyPlayer:IsMinorCiv() and not pEnemyPlayer:IsBarbarian() then --IsMajorCiv()
local iCoupsRemaining = 2 -- max stealable allies
for i = GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS - 2 do --loop through all Minor Civs
local mPlayer = Players[i]
if mPlayer:GetAlly() == pEnemyPlayer then -- if Major Civ is ally of Minor Civ
-- found allied MinorCiv
if iCoupsRemaining > 0 then -- we can still steal a minor civ
yumaCoupFunction(pPlayer, pEnemyPlayer, mPlayer) -- call for the coup, passing the target Minor Civ, the current Ally, and the Yuma Civ
iCoupsRemaining = iCoupsRemaining - 1 -- one less civ left
end
end
end
end
end
end
end
end
end
Events.WarStateChanged.Add(YumaWarCoup)
function yumaCoupFunction(pYumaPlayer, pEnemyPlayer, pMinorPlayer)
-- make pYumaPlayer the ally of pMinorPlayer, remove pEnemyPlayer status
-- this is essentially a 100% likely coup
end
I can provide other parts of the code if needed, as well as more elaboration on what I want done.