Does SetPermanentWarPeace actually work?

Craig_Sutter

Deity
Joined
Aug 13, 2002
Messages
2,773
Location
Calgary, Canada
I use the following code to set a permanent peace between two civs, a major and a minor, which are to be permanently at peace.

The problem is, I am still able to declare war with all its repercussions. This is despite the print statement coming out and no lua.log errors.

Does the function not work??

Code:
--At the end of the first turn, HRE declares war on the FIC.  We want TeamIDs and Teams, not PlayerIDs.
--Then set permanent war, both ways.		
	
function  HREFICPeace()

if Game.GetGameTurn() == 0 then

local HRETeam
local HRETeamID
local FICTeam
local FICTeamID
local HRE
local FIC

-- Set up HRE Player

	for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do 

	local pHRE = Players[iPlayer]

		if (GameInfo.Civilizations.CIVILIZATION_PERSIA.ID == pHRE:GetCivilizationType()) then
	
		HRE = pHRE
		HRETeamID = HRE:GetTeam();
		HRETeam= Teams[ HRE:GetTeam() ]

		end	
	end

-- Set up FIC Player

	for iPlayer=GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do 

	local pFIC = Players[iPlayer]

		if (GameInfo.MinorCivilizations.MINOR_CIV_FREE_IMPERIAL_CITIES.ID == pFIC:GetMinorCivType()) then
	
		FIC = pFIC	
		FICTeamID = FIC:GetTeam();
		FICTeam= Teams[ FIC:GetTeam() ]
	
		end
	end

-- Declare war and set permanent war

	if(FIC:IsAlive() and HRE:IsAlive() ) then
	
	HRETeam:SetPermanentWarPeace(FICTeamID, true);
	FICTeam:SetPermanentWarPeace(HRETeamID, true);
	[COLOR="red"]print (HRE:GetName() ,"...is at peace with... ", FIC:GetName());[/COLOR]

	end

end
end

Events.ActivePlayerTurnEnd.Add(HREFICPeace)
 
It works... for the AI players.

You'll have to hide the war (or peace) button on the CS screen, as the UI does not reflect the situation.

Here is a quick C/P from R.E.D WWII to do that (I've quickly edited it to remove all references from other parts of the mod, so it's not tested, and that mod was made for vanilla civ5)

Spoiler :
Code:
function HideMinorWarPeaceButton( popupInfo )
	
	if( popupInfo.Type ~= ButtonPopupTypes.BUTTONPOPUP_CITY_STATE_DIPLO ) then
		return
	end
	
    local minorPlayerID = popupInfo.Data1	
	local playerID = Game.GetActivePlayer()
	local team = Teams [Players[playerID]:GetTeam()]
	
	local bLocked = false
	local strToolTip = nil

	if team:IsPermanentWarPeace(Players[minorPlayerID]:GetTeam()) then
		bLocked = true
		strToolTip = "War/Peace is locked."
	end

	if ( bLocked ) then
		ContextPtr:LookUpControl("/InGame/CityStateDiploPopup/PeaceButton"):SetDisabled(true)
		if strToolTip then ContextPtr:LookUpControl("/InGame/CityStateDiploPopup/PeaceButton"):SetToolTipString( strToolTip ); end		
		ContextPtr:LookUpControl("/InGame/CityStateDiploPopup/WarButton"):SetDisabled(true)
		if strToolTip then ContextPtr:LookUpControl("/InGame/CityStateDiploPopup/WarButton"):SetToolTipString( strToolTip ); end
	else
		ContextPtr:LookUpControl("/InGame/CityStateDiploPopup/PeaceButton"):SetDisabled(false)
		ContextPtr:LookUpControl("/InGame/CityStateDiploPopup/PeaceButton"):SetToolTipString( "" )
		ContextPtr:LookUpControl("/InGame/CityStateDiploPopup/WarButton"):SetDisabled(false)
		ContextPtr:LookUpControl("/InGame/CityStateDiploPopup/WarButton"):SetToolTipString( "" )
	end
end
Events.SerialEventGameMessagePopup.Add(HideMinorWarPeaceButton)
 
Back
Top Bottom