mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-23 14:46:57 +00:00
Do not let every entity with UnitAI listen to "OnGlobalConstructionFinished".
All entities with UnitAI wastefully listened to global ConstructionFinished messages. Now the message is only sent to assigned builders. Differential Revision: D2697 Reviewed by: @wraitii. This was SVN commit r23924.
This commit is contained in:
@@ -457,6 +457,15 @@ Foundation.prototype.Build = function(builderEnt, work)
|
||||
{ "entity": this.entity, "newentity": building });
|
||||
Engine.PostMessage(this.entity, MT_EntityRenamed, { "entity": this.entity, "newentity": building });
|
||||
|
||||
// Inform the builders that repairing has finished.
|
||||
// This not done by listening to a global message due to performance.
|
||||
for (let builder of this.GetBuilders())
|
||||
{
|
||||
let cmpUnitAIBuilder = Engine.QueryInterface(builder, IID_UnitAI);
|
||||
if (cmpUnitAIBuilder)
|
||||
cmpUnitAIBuilder.ConstructionFinished({ "entity": this.entity, "newentity": building });
|
||||
}
|
||||
|
||||
Engine.DestroyEntity(this.entity);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -129,7 +129,18 @@ Repairable.prototype.Repair = function(builderEnt, rate)
|
||||
|
||||
// If we repaired all the damage, send a message to entities to stop repairing this building
|
||||
if (amount >= damage)
|
||||
{
|
||||
Engine.PostMessage(this.entity, MT_ConstructionFinished, { "entity": this.entity, "newentity": this.entity });
|
||||
|
||||
// Inform the builders that repairing has finished.
|
||||
// This not done by listening to a global message due to performance.
|
||||
for (let builder of this.GetBuilders())
|
||||
{
|
||||
let cmpUnitAIBuilder = Engine.QueryInterface(builder, IID_UnitAI);
|
||||
if (cmpUnitAIBuilder)
|
||||
cmpUnitAIBuilder.ConstructionFinished({ "entity": this.entity, "newentity": this.entity });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Repairable.prototype.GetRepairRate = function()
|
||||
|
||||
@@ -2857,7 +2857,7 @@ UnitAI.prototype.UnitFsmSpec = {
|
||||
{
|
||||
// The building was already finished/fully repaired before we arrived;
|
||||
// let the ConstructionFinished handler handle this.
|
||||
this.OnGlobalConstructionFinished({"entity": this.repairTarget, "newentity": this.repairTarget});
|
||||
this.ConstructionFinished({ "entity": this.repairTarget, "newentity": this.repairTarget });
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4191,12 +4191,14 @@ UnitAI.prototype.OnMotionUpdate = function(msg)
|
||||
this.UnitFsm.ProcessMessage(this, Object.assign({ "type": "MovementUpdate" }, msg));
|
||||
};
|
||||
|
||||
UnitAI.prototype.OnGlobalConstructionFinished = function(msg)
|
||||
/**
|
||||
* Called directly by cmpFoundation and cmpRepairable to
|
||||
* inform builders that repairing has finished.
|
||||
* This not done by listening to a global message due to performance.
|
||||
*/
|
||||
UnitAI.prototype.ConstructionFinished = function(msg)
|
||||
{
|
||||
// TODO: This is a bit inefficient since every unit listens to every
|
||||
// construction message - ideally we could scope it to only the one we're building
|
||||
|
||||
this.UnitFsm.ProcessMessage(this, {"type": "ConstructionFinished", "data": msg});
|
||||
this.UnitFsm.ProcessMessage(this, { "type": "ConstructionFinished", "data": msg });
|
||||
};
|
||||
|
||||
UnitAI.prototype.OnGlobalEntityRenamed = function(msg)
|
||||
|
||||
@@ -10,6 +10,7 @@ Engine.LoadComponentScript("interfaces/StatisticsTracker.js");
|
||||
Engine.LoadComponentScript("interfaces/TerritoryDecay.js");
|
||||
Engine.LoadComponentScript("interfaces/Trigger.js");
|
||||
Engine.LoadComponentScript("interfaces/Timer.js");
|
||||
Engine.LoadComponentScript("interfaces/UnitAI.js");
|
||||
Engine.LoadComponentScript("AutoBuildable.js");
|
||||
Engine.LoadComponentScript("Foundation.js");
|
||||
Engine.LoadComponentScript("Timer.js");
|
||||
|
||||
Reference in New Issue
Block a user