Index: binaries/data/mods/public/simulation/components/Damage.js =================================================================== --- binaries/data/mods/public/simulation/components/Damage.js +++ binaries/data/mods/public/simulation/components/Damage.js @@ -307,6 +307,8 @@ let cmpLooter = Engine.QueryInterface(attacker, IID_Looter); if (cmpLooter) cmpLooter.Collect(target); + + Engine.BroadcastMessage(MT_TargetDeath, { "target": target }); }; Engine.RegisterSystemComponentType(IID_Damage, "Damage", Damage); Index: binaries/data/mods/public/simulation/components/UnitAI.js =================================================================== --- binaries/data/mods/public/simulation/components/UnitAI.js +++ binaries/data/mods/public/simulation/components/UnitAI.js @@ -179,6 +179,10 @@ // ignore }, + "TargetDeath": function() { + // ignore + }, + // Formation handlers: "FormationLeave": function(msg) { @@ -1974,8 +1978,9 @@ this.SetNextState("FINDINGNEWTARGET"); }, - // TODO: respond to target deaths immediately, rather than waiting - // until the next Timer event + "TargetDeath": function(msg) { + this.SetNextState("COMBAT.FINDINGNEWTARGET"); + }, "Attacked": function(msg) { // If we are capturing and are attacked by something that we would not capture, attack that entity instead @@ -3919,6 +3924,12 @@ this.UnitFsm.ProcessMessage(this, {"type": "GuardedAttacked", "data": msg.data}); }; +UnitAI.prototype.OnTargetDeath = function(msg) +{ + if (this.order && this.order.data && this.order.data.target && this.order.data.target == msg.target) + this.UnitFsm.ProcessMessage(this, {"type": "TargetDeath", "target": msg.target}); +}; + UnitAI.prototype.OnHealthChanged = function(msg) { this.UnitFsm.ProcessMessage(this, {"type": "HealthChanged", "from": msg.from, "to": msg.to}); Index: binaries/data/mods/public/simulation/components/interfaces/Damage.js =================================================================== --- binaries/data/mods/public/simulation/components/interfaces/Damage.js +++ binaries/data/mods/public/simulation/components/interfaces/Damage.js @@ -1 +1,7 @@ Engine.RegisterInterface("Damage"); + +/** + * Message of the form { "target": entityID } + * sent from Damage component whenever a target dies. + */ +Engine.RegisterMessageType("TargetDeath");