Ticket #1843: retarget.diff

File retarget.diff, 2.2 KB (added by mimo, 11 years ago)
  • binaries/data/mods/public/simulation/components/Promotion.js

     
    7878    cmpPromotedUnitAI.Cheer();
    7979    var orders = cmpCurrentUnitAI.GetOrders();
    8080    cmpPromotedUnitAI.AddOrders(orders);
     81    // if any orders were targeted to the current unit, retarget them to the promoted one
     82    cmpCurrentUnitAI.RetargetOrders(promotedUnitEntity);
    8183
    8284    Engine.BroadcastMessage(MT_EntityRenamed, { entity: this.entity, newentity: promotedUnitEntity });
    8385
  • binaries/data/mods/public/simulation/components/Pack.js

     
    162162            if (cmpUnitAI.GetStanceName())
    163163                cmpNewUnitAI.SwitchToStance(cmpUnitAI.GetStanceName());
    164164            cmpNewUnitAI.AddOrders(cmpUnitAI.GetOrders());
     165            // if any orders were targeted to this unit, retarget them to the new one
     166            cmpUnitAI.RetargetOrders(newEntity);
    165167        }
    166168
    167169        Engine.BroadcastMessage(MT_EntityRenamed, { entity: this.entity, newentity: newEntity });
  • binaries/data/mods/public/simulation/components/UnitAI.js

     
    27012701    return orders;
    27022702};
    27032703
     2704UnitAI.prototype.RetargetOrders = function(newEntity)
     2705{
     2706    // We try to retarget orders from this.entity to the new entity
     2707    for each (var ent in Engine.GetEntitiesWithInterface(IID_UnitAI))
     2708    {
     2709        var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
     2710        for (i in cmpUnitAI.orderQueue)
     2711        {
     2712            if (cmpUnitAI.orderQueue[i].data && cmpUnitAI.orderQueue[i].data.target)
     2713            {
     2714                if (cmpUnitAI.orderQueue[i].data.target == this.entity)
     2715                    cmpUnitAI.orderQueue[i].data.target = newEntity;
     2716            }
     2717        }
     2718    }
     2719};
     2720
    27042721UnitAI.prototype.TimerHandler = function(data, lateness)
    27052722{
    27062723    // Reset the timer