Ticket #3430: ticket3430-v2.patch

File ticket3430-v2.patch, 2.9 KB (added by mimo, 9 years ago)

yes, i forgot to upload my current more complete patch, fixing that warning and another undef which may arise in the AI.

  • binaries/data/mods/public/simulation/ai/common-api/entity.js

     
    721721                res = this._ai._entities.get(this.unitAIOrderData()[0]["target"]);
    722722            else if (this.unitAIOrderData()[1] !== undefined && this.unitAIOrderData()[1]["target"] !== undefined)
    723723                res = this._ai._entities.get(this.unitAIOrderData()[1]["target"]);
    724             if (res === undefined)
    725                 return undefined;
     724            if (!res)
     725                return 0;
     726            let type = res.resourceSupplyType();
     727            if (!type)
     728                return 0;
    726729
    727             let type = res.resourceSupplyType();
    728730            if (type.generic === "treasure")
    729731                return 1000;
    730732
  • binaries/data/mods/public/simulation/components/UnitAI.js

     
    20362036                            // It's probably better in this case, to avoid units getting stuck around a dropsite
    20372037                            // in a "Target is far away, full, nearby are no good resources, return to dropsite" loop
    20382038                            // to order it to GatherNear the resource position.
    2039                             var cmpPosition = Engine.QueryInterface(this.gatheringTarget, IID_Position);
     2039                            var cmpPosition = Engine.QueryInterface(oldTarget, IID_Position);
    20402040                            if (cmpPosition)
    20412041                            {
    20422042                                var pos = cmpPosition.GetPosition();
    20432043                                this.GatherNearPosition(pos.x, pos.z, oldType, oldTemplate);
    20442044                                return true;
    2045                             } else {
     2045                            }
     2046                            else
     2047                            {
    20462048                                // we're kind of stuck here. Return resource.
    20472049                                var nearby = this.FindNearestDropsite(oldType.generic);
    20482050                                if (nearby)
     
    23402342
    23412343                    // If hunting, try to go to the initial herd position to see if we are more lucky
    23422344                    if (herdPos)
     2345                    {
    23432346                        this.GatherNearPosition(herdPos.x, herdPos.z, resourceType, resourceTemplate);
     2347                        return;
     2348                    }
    23442349
    23452350                    // Nothing else to gather - if we're carrying anything then we should
    23462351                    // drop it off, and if not then we might as well head to the dropsite
     
    35303535    }
    35313536    else
    35323537    {
    3533         this.SetNextState("IDLE");
     3538        // We must switch to the idle state immediately (and not do a simple SetNextState)
     3539        // otherwise we may be in a weird state if a ProcessMessage is triggered (by a MoveStarted
     3540        // or MoveCompleted) when starting a new order and before we have set our new state.
     3541        let index = this.GetCurrentState().indexOf(".");
     3542        if (index != -1)
     3543            this.UnitFsm.SwitchToNextState(this, this.GetCurrentState().slice(0,index+1) + "IDLE");
     3544        else
     3545            this.SetNextState("IDLE");  // should never happen
    35343546
    35353547        Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() });
    35363548