From a0e13d96251942bb019aec8e185ed3e924c1232d Mon Sep 17 00:00:00 2001 From: leper Date: Fri, 2 Nov 2012 17:20:32 +0000 Subject: [PATCH] Fix tests. BuildingAI now handles DiplomacyChanged messages. This was SVN commit r12812. --- .../data/mods/public/gui/session/session.xml | 3 +- .../simulation/components/BuildingAI.js | 14 +++++++ .../public/simulation/components/Player.js | 4 ++ .../components/tests/test_GuiInterface.js | 40 ++++++++++++------- 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/binaries/data/mods/public/gui/session/session.xml b/binaries/data/mods/public/gui/session/session.xml index 3e0afb0c0b..9260c12f6b 100644 --- a/binaries/data/mods/public/gui/session/session.xml +++ b/binaries/data/mods/public/gui/session/session.xml @@ -253,8 +253,7 @@ - - + diff --git a/binaries/data/mods/public/simulation/components/BuildingAI.js b/binaries/data/mods/public/simulation/components/BuildingAI.js index a2c59858d6..4c3ddf342a 100644 --- a/binaries/data/mods/public/simulation/components/BuildingAI.js +++ b/binaries/data/mods/public/simulation/components/BuildingAI.js @@ -38,6 +38,17 @@ BuildingAI.prototype.OnOwnershipChanged = function(msg) this.SetupGaiaRangeQuery(msg.to); }; +BuildingAI.prototype.OnDiplomacyChanged = function(msg) +{ + var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); + if (cmpOwnership && cmpOwnership.GetOwner() == msg.player) + { + // Remove maybe now allied/neutral units + this.targetUnits = []; + this.SetupRangeQuery(msg.player); + } +}; + /** * Cleanup on destroy */ @@ -66,7 +77,10 @@ BuildingAI.prototype.SetupRangeQuery = function(owner) var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); if (this.enemyUnitsQuery) + { cmpRangeManager.DestroyActiveQuery(this.enemyUnitsQuery); + this.enemyUnitsQuery = undefined; + } var players = []; var cmpPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(owner), IID_Player); diff --git a/binaries/data/mods/public/simulation/components/Player.js b/binaries/data/mods/public/simulation/components/Player.js index 6388d7a82c..3f82d03441 100644 --- a/binaries/data/mods/public/simulation/components/Player.js +++ b/binaries/data/mods/public/simulation/components/Player.js @@ -300,6 +300,8 @@ Player.prototype.SetDiplomacyIndex = function(idx, value) else { this.diplomacy[idx] = value; + if (this.diplomacy[idx] == cmpPlayer.diplomacy[this.playerID]) + Engine.BroadcastMessage(MT_DiplomacyChanged, {"player": idx}); } Engine.BroadcastMessage(MT_DiplomacyChanged, {"player": this.playerID}); } @@ -317,6 +319,8 @@ Player.prototype.SetDiplomacyIndex = function(idx, value) else { this.diplomacy[idx] = value; + if (this.diplomacy[idx] == cmpPlayer.diplomacy[this.playerID]) + Engine.BroadcastMessage(MT_DiplomacyChanged, {"player": idx}); } Engine.BroadcastMessage(MT_DiplomacyChanged, {"player": this.playerID}); diff --git a/binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js b/binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js index 7242b53fb7..6cc0a5f14d 100644 --- a/binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js +++ b/binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js @@ -67,6 +67,8 @@ AddMock(100, IID_Player, { IsAlly: function() { return false; }, IsNeutral: function() { return false; }, IsEnemy: function() { return true; }, + WantAlly: function() { return false; }, + WantNeutral: function() { return false; }, }); AddMock(100, IID_BuildLimits, { @@ -120,6 +122,8 @@ AddMock(101, IID_Player, { IsAlly: function() { return true; }, IsNeutral: function() { return false; }, IsEnemy: function() { return false; }, + WantAlly: function() { return false; }, + WantNeutral: function() { return false; }, }); AddMock(101, IID_BuildLimits, { @@ -174,9 +178,11 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), { team: -1, teamsLocked: false, phase: "", - isAlly: [false, false, false], - isNeutral: [false, false, false], - isEnemy: [true, true, true], + isAlly: [false, false], + isNeutral: [false, false], + isEnemy: [true, true], + wantAlly: [false, false], + wantNeutral: [false, false], buildLimits: {"Foo": 10}, buildCounts: {"Foo": 5}, techModifications: {}, @@ -194,9 +200,11 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), { team: -1, teamsLocked: false, phase: "village", - isAlly: [true, true, true], - isNeutral: [false, false, false], - isEnemy: [false, false, false], + isAlly: [true, true], + isNeutral: [false, false], + isEnemy: [false, false], + wantAlly: [false, false], + wantNeutral: [false, false], buildLimits: {"Bar": 20}, buildCounts: {"Bar": 0}, techModifications: {}, @@ -219,11 +227,13 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), { trainingBlocked: false, state: "active", team: -1, - teamsLocked:false, + teamsLocked: false, phase: "", - isAlly: [false, false, false], - isNeutral: [false, false, false], - isEnemy: [true, true, true], + isAlly: [false, false], + isNeutral: [false, false], + isEnemy: [true, true], + wantAlly: [false, false], + wantNeutral: [false, false], buildLimits: {"Foo": 10}, buildCounts: {"Foo": 5}, techModifications: {}, @@ -255,11 +265,13 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), { trainingBlocked: false, state: "active", team: -1, - teamsLocked:false, + teamsLocked: false, phase: "village", - isAlly: [true, true, true], - isNeutral: [false, false, false], - isEnemy: [false, false, false], + isAlly: [true, true], + isNeutral: [false, false], + isEnemy: [false, false], + wantAlly: [false, false], + wantNeutral: [false, false], buildLimits: {"Bar": 20}, buildCounts: {"Bar": 0}, techModifications: {},