Ticket #4015: UnitAI.js.2.patch

File UnitAI.js.2.patch, 1.8 KB (added by Ágoston Sipos, 7 years ago)
  • binaries/data/mods/public/simulation/components/UnitAI.js

     
    38353835    // Special cases of orders that shouldn't be replaced:
    38363836    // 1. Cheering - we're invulnerable, add order after we finish
    38373837    // 2. Packing/unpacking - we're immobile, add order after we finish (unless it's cancel)
     3838    // 2./1. If order is a move (or out of range attack), we cancel packing immediately and then add the moving order
    38383839    // TODO: maybe a better way of doing this would be to use priority levels
    38393840    if (this.order && this.order.type == "Cheering")
    38403841    {
     
    38423843        var cheeringOrder = this.orderQueue.shift();
    38433844        this.orderQueue = [cheeringOrder, order];
    38443845    }
    3845     else if (this.IsPacking() && type != "CancelPack" && type != "CancelUnpack")
     3846    else if (this.IsPacking() && type != "CancelPack" && type != "CancelUnpack" && this.ShouldPack(type, data))
    38463847    {
    38473848        var order = { "type": type, "data": data };
    38483849        var packingOrder = this.orderQueue.shift();
    38493850        this.orderQueue = [packingOrder, order];
    38503851    }
     3852    else if (this.IsPacking() && !this.ShouldPack(type, data))
     3853    {
     3854        this.orderQueue = [];
     3855        this.PushOrder("CancelUnpack", { "force": true });
     3856        this.PushOrder(type, data);
     3857    }
    38513858    else
    38523859    {
    38533860        this.orderQueue = [];
     
    59605967    return (cmpPack && cmpPack.IsPacking());
    59615968};
    59625969
     5970UnitAI.prototype.ShouldPack = function(type, data)
     5971{
     5972    return type == "Attack" && this.CheckTargetAttackRange(data.target, this.GetBestAttackAgainst(data.target, false));
     5973};
     5974
    59635975//// Formation specific functions ////
    59645976
    59655977UnitAI.prototype.IsAttackingAsFormation = function()