From 518ae4fcb21f4882f4eaba0e985d96b4c29e699f Mon Sep 17 00:00:00 2001 From: elexis Date: Tue, 15 Mar 2016 04:53:13 +0000 Subject: [PATCH] Lock diplomacy for all players if the locked-teams setting is enabled, fixes #3702. GUI fix in 17e6b316fa, simulation fix here. Remove quadruplicated code! Check in Commands.js as this one handles user input. Don't check in Player.js as the function should be versatile enough to change diplomacy from all components, even if teams are locked or ceasefire active. This was SVN commit r17896. --- .../public/simulation/components/Player.js | 42 +++---------------- .../public/simulation/helpers/Commands.js | 6 +-- 2 files changed, 8 insertions(+), 40 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/Player.js b/binaries/data/mods/public/simulation/components/Player.js index b10cf1ce17..8ae126de59 100644 --- a/binaries/data/mods/public/simulation/components/Player.js +++ b/binaries/data/mods/public/simulation/components/Player.js @@ -409,9 +409,8 @@ Player.prototype.GetDiplomacy = function() Player.prototype.SetDiplomacy = function(dipl) { - // Should we check for teamsLocked here? this.diplomacy = dipl; - Engine.BroadcastMessage(MT_DiplomacyChanged, {"player": this.playerID}); + Engine.BroadcastMessage(MT_DiplomacyChanged, { "player": this.playerID }); }; Player.prototype.SetDiplomacyIndex = function(idx, value) @@ -427,41 +426,12 @@ Player.prototype.SetDiplomacyIndex = function(idx, value) if (this.state != "active" || cmpPlayer.state != "active") return; - // You can have alliances with other players, - if (this.teamsLocked) - { - // but can't stab your team members in the back - if (this.team == -1 || this.team != cmpPlayer.GetTeam()) - { - // Break alliance or declare war - if (Math.min(this.diplomacy[idx],cmpPlayer.diplomacy[this.playerID]) > value) - { - this.diplomacy[idx] = value; - cmpPlayer.SetDiplomacyIndex(this.playerID, value); - } - else - { - this.diplomacy[idx] = value; - } - Engine.BroadcastMessage(MT_DiplomacyChanged, {"player": this.playerID}); - } - } - else - { - // Break alliance or declare war (worsening of relations is mutual) - if (Math.min(this.diplomacy[idx],cmpPlayer.diplomacy[this.playerID]) > value) - { - // This is duplicated because otherwise we get too much recursion - this.diplomacy[idx] = value; - cmpPlayer.SetDiplomacyIndex(this.playerID, value); - } - else - { - this.diplomacy[idx] = value; - } + this.diplomacy[idx] = value; + Engine.BroadcastMessage(MT_DiplomacyChanged, { "player": this.playerID }); - Engine.BroadcastMessage(MT_DiplomacyChanged, {"player": this.playerID}); - } + // Mutual worsening of relations + if (cmpPlayer.diplomacy[this.playerID] > value) + cmpPlayer.SetDiplomacyIndex(this.playerID, value); }; Player.prototype.UpdateSharedLos = function() diff --git a/binaries/data/mods/public/simulation/helpers/Commands.js b/binaries/data/mods/public/simulation/helpers/Commands.js index 62f1b3373b..73183a996a 100644 --- a/binaries/data/mods/public/simulation/helpers/Commands.js +++ b/binaries/data/mods/public/simulation/helpers/Commands.js @@ -84,11 +84,9 @@ var g_Commands = { "diplomacy": function(player, cmd, data) { let cmpCeasefireManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_CeasefireManager); - if (cmpCeasefireManager && cmpCeasefireManager.IsCeasefireActive()) - { - warn("Can't change diplomacy of player " + player + " while ceasefire is active."); + if (data.cmpPlayer.GetLockTeams() || + cmpCeasefireManager && cmpCeasefireManager.IsCeasefireActive()) return; - } switch(cmd.to) {