From 13281e230dda590873c1a483a46970923673a4c5 Mon Sep 17 00:00:00 2001 From: quantumstate Date: Wed, 18 Apr 2012 11:30:28 +0000 Subject: [PATCH] Handle updates for foundation progress, resource carrying and resource supply amount for AIProxy. Fixes #1327 This was SVN commit r11547. --- .../public/simulation/components/AIProxy.js | 26 +++++++++++++++++-- .../simulation/components/Foundation.js | 2 ++ .../simulation/components/ResourceGatherer.js | 8 ++++++ .../components/interfaces/Foundation.js | 4 +++ .../components/interfaces/ResourceGatherer.js | 4 +++ 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/AIProxy.js b/binaries/data/mods/public/simulation/components/AIProxy.js index 49e812faa9..83824a97c2 100644 --- a/binaries/data/mods/public/simulation/components/AIProxy.js +++ b/binaries/data/mods/public/simulation/components/AIProxy.js @@ -125,7 +125,7 @@ AIProxy.prototype.OnTrainingQueueChanged = function(msg) var cmpTrainingQueue = Engine.QueryInterface(this.entity, IID_TrainingQueue); this.changes.trainingQueue = cmpTrainingQueue.GetQueue(); -} +}; AIProxy.prototype.OnGarrisonedUnitsChanged = function(msg) { @@ -133,7 +133,25 @@ AIProxy.prototype.OnGarrisonedUnitsChanged = function(msg) var cmpGarrisonHolder = Engine.QueryInterface(this.entity, IID_GarrisonHolder); this.changes.garrisoned = cmpGarrisonHolder.GetEntities(); -} +}; + +AIProxy.prototype.OnResourceSupplyChanged = function(msg) +{ + this.NotifyChange(); + this.changes.resourceSupplyAmount = msg.to; +}; + +AIProxy.prototype.OnResourceCarryingChanged = function(msg) +{ + this.NotifyChange(); + this.changes.resourceCarrying = msg.to; +}; + +AIProxy.prototype.OnFoundationProgressChanged = function(msg) +{ + this.NotifyChange(); + this.changes.foundationProgress = msg.to; +}; // TODO: event handlers for all the other things @@ -198,24 +216,28 @@ AIProxy.prototype.GetFullRepresentation = function() var cmpFoundation = Engine.QueryInterface(this.entity, IID_Foundation); if (cmpFoundation) { + // Updated by OnFoundationProgressChanged ret.foundationProgress = cmpFoundation.GetBuildPercentage(); } var cmpResourceSupply = Engine.QueryInterface(this.entity, IID_ResourceSupply); if (cmpResourceSupply) { + // Updated by OnResourceSupplyChanged ret.resourceSupplyAmount = cmpResourceSupply.GetCurrentAmount(); } var cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); if (cmpResourceGatherer) { + // Updated by OnResourceCarryingChanged ret.resourceCarrying = cmpResourceGatherer.GetCarryingStatus(); } var cmpGarrisonHolder = Engine.QueryInterface(this.entity, IID_GarrisonHolder); if (cmpGarrisonHolder) { + // Updated by OnGarrisonedUnitsChanged ret.garrisoned = cmpGarrisonHolder.GetEntities(); } diff --git a/binaries/data/mods/public/simulation/components/Foundation.js b/binaries/data/mods/public/simulation/components/Foundation.js index 14029da1e1..c29ded5358 100644 --- a/binaries/data/mods/public/simulation/components/Foundation.js +++ b/binaries/data/mods/public/simulation/components/Foundation.js @@ -158,6 +158,8 @@ Foundation.prototype.Build = function(builderEnt, work) this.buildProgress += amount; if (this.buildProgress > 1.0) this.buildProgress = 1.0; + + Engine.PostMessage(this.entity, MT_FoundationProgressChanged, { "to": this.GetBuildPercentage() }); // Add an appropriate proportion of hitpoints var targetHP = Math.max(0, Math.min(this.maxHitpoints, Math.floor(this.maxHitpoints * this.buildProgress))); diff --git a/binaries/data/mods/public/simulation/components/ResourceGatherer.js b/binaries/data/mods/public/simulation/components/ResourceGatherer.js index c18c6293c0..630c84a0b3 100644 --- a/binaries/data/mods/public/simulation/components/ResourceGatherer.js +++ b/binaries/data/mods/public/simulation/components/ResourceGatherer.js @@ -95,6 +95,8 @@ ResourceGatherer.prototype.GiveResources = function(resources) { this.carrying[resource.type] = +(resource.amount); } + + Engine.PostMessage(this.entity, MT_ResourceCarryingChanged, { "to": this.GetCarryingStatus() }); }; /** @@ -193,6 +195,8 @@ ResourceGatherer.prototype.PerformGather = function(target) var cmpStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker); if (cmpStatisticsTracker) cmpStatisticsTracker.IncreaseResourceGatheredCounter(type.generic, status.amount, type.specific); + + Engine.PostMessage(this.entity, MT_ResourceCarryingChanged, { "to": this.GetCarryingStatus() }); // Tell the target we're gathering from it Engine.PostMessage(target, MT_ResourceGather, @@ -269,6 +273,8 @@ ResourceGatherer.prototype.CommitResources = function(types) delete this.carrying[type]; } } + + Engine.PostMessage(this.entity, MT_ResourceCarryingChanged, { "to": this.GetCarryingStatus() }); }; /** @@ -279,6 +285,8 @@ ResourceGatherer.prototype.CommitResources = function(types) ResourceGatherer.prototype.DropResources = function() { this.carrying = {}; + + Engine.PostMessage(this.entity, MT_ResourceCarryingChanged, { "to": this.GetCarryingStatus() }); }; Engine.RegisterComponentType(IID_ResourceGatherer, "ResourceGatherer", ResourceGatherer); diff --git a/binaries/data/mods/public/simulation/components/interfaces/Foundation.js b/binaries/data/mods/public/simulation/components/interfaces/Foundation.js index e81584dd5e..a90730bb9e 100644 --- a/binaries/data/mods/public/simulation/components/interfaces/Foundation.js +++ b/binaries/data/mods/public/simulation/components/interfaces/Foundation.js @@ -5,3 +5,7 @@ Engine.RegisterInterface("Foundation"); // Units can watch for this and change task once it's complete. // Data: { entity: 123, newentity: 234 } Engine.RegisterMessageType("ConstructionFinished"); + +// Message of the form { "to", 59 }, as the percentage complete +// sent whenever the foundations progress changes. +Engine.RegisterMessageType("FoundationProgressChanged"); diff --git a/binaries/data/mods/public/simulation/components/interfaces/ResourceGatherer.js b/binaries/data/mods/public/simulation/components/interfaces/ResourceGatherer.js index 220fde4844..b5f8a50306 100644 --- a/binaries/data/mods/public/simulation/components/interfaces/ResourceGatherer.js +++ b/binaries/data/mods/public/simulation/components/interfaces/ResourceGatherer.js @@ -3,3 +3,7 @@ Engine.RegisterInterface("ResourceGatherer"); // Message sent from ResourceGatherers to a ResourceSupply entity // each time they gather resources from it Engine.RegisterMessageType("ResourceGather"); + +// Message of the form { "to", [ {"type":"wood", "amount":7, "max":10} ] }, +// sent whenever carrying amount changes. +Engine.RegisterMessageType("ResourceCarryingChanged");