Making players declare war -- am I missing something fundamental here ?

LeeS

Imperator
Joined
Jul 23, 2013
Messages
7,241
Location
Illinois, USA
I wrote a function to make all major players declare war on each other once they meet. I had understood that there were "issues" involved in trying to do this forcified war condition, but it seemed to work without a hitch. So Am I missing something fundamental that is about to bite me later ?

Code:
function EveryoneHatesEveryone(iPlayer)
	local pPlayer = Players[iPlayer]
	if not pPlayer:IsAlive() then return end
	local pPlayersTeam = pPlayer:GetTeam()
	for iMajPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1 do
		if Players[iMajPlayer] ~= pPlayer then
			local OtherPlayer = Players[iMajPlayer]
			if OtherPlayer:IsAlive() then
				local OtherPlayerTeam = OtherPlayer:GetTeam()
				if Teams[pPlayersTeam]:IsHasMet(OtherPlayerTeam) then
					if Teams[pPlayersTeam]:CanDeclareWar(OtherPlayerTeam) then
						Teams[pPlayersTeam]:DeclareWar(OtherPlayerTeam)
						Teams[pPlayersTeam]:SetPermanentWarPeace(OtherPlayerTeam, true)
					end
				end
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(EveryoneHatesEveryone)
 
if CanDeclareWar return false when you're already at war (I'm not sure about that), then some civs will not have the PermanentWarPeace flag and could ask for peace later.
 
if CanDeclareWar return false when you're already at war (I'm not sure about that), then some civs will not have the PermanentWarPeace flag and could ask for peace later.
I think I'll throw a couple of print statements into the code to 'catch' what conditions cause CanDeclareWar to return false.
 
if it's the case, just add:

Code:
Teams[OtherPlayerTeam]:SetPermanentWarPeace(pPlayersTeam, true)

after

Code:
Teams[pPlayersTeam]:SetPermanentWarPeace(OtherPlayerTeam, true)


BTW, I know that I'm not in a good position to make this kind of remark knowing that my own code is a bad example, but for consistency you should use iPlayersTeam and iOtherPlayerTeam for those variables name.
 
if CanDeclareWar return false when you're already at war (I'm not sure about that), then some civs will not have the PermanentWarPeace flag and could ask for peace later.

It does if you're already at war with the target team. The other conditions that return false are if one of the teams isn't alive, the teams haven't met, the other team is set to force peace or can't change war/peace, and the game is set to always peace.
 
Back
Top Bottom