Ticket #1670: ticket1670.patch

File ticket1670.patch, 1.9 KB (added by mimo, 8 years ago)
  • binaries/data/mods/public/simulation/components/ResourceGatherer.js

     
    305305ResourceGatherer.prototype.CanCarryMore = function(type)
    306306{
    307307    let amount = (this.carrying[type] || 0);
    308     return (amount < this.GetCapacity(type));
     308    return amount < this.GetCapacity(type);
    309309};
    310310
     311
     312ResourceGatherer.prototype.IsCarrying = function(type)
     313{
     314    let amount = (this.carrying[type] || 0);
     315    return amount > 0;
     316};
     317
    311318/**
    312319 * Returns whether this unit is carrying any resources of a type that is
    313320 * not the requested type. (This is to support cases where the unit is
  • binaries/data/mods/public/simulation/components/UnitAI.js

     
    23472347                    var herdPos = this.order.data.initPos;
    23482348
    23492349                    // Give up on this order and try our next queued order
     2350                    // but first check what is our next order and, if needed, insert a returnResource order
     2351                    let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer);
     2352                    if (cmpResourceGatherer.IsCarrying(resourceType.generic) &&
     2353                        this.orderQueue.length > 1 && this.orderQueue[1] !== "ReturnResource" &&
     2354                        (this.orderQueue[1].type !== "Gather" || this.orderQueue[1].data.type.generic !== resourceType.generic))
     2355                    {
     2356                        let nearby = this.FindNearestDropsite(resourceType.generic);
     2357                        if (nearby)
     2358                            this.orderQueue.splice(1, 0, { "type": "ReturnResource", "data": { "target": nearby, "force": false } });
     2359                    }
    23502360                    if (this.FinishOrder())
    23512361                        return;
    23522362