Ticket #3726: gatheringTarget.patch

File gatheringTarget.patch, 2.6 KB (added by mimo, 8 years ago)
  • binaries/data/mods/public/simulation/components/UnitAI.js

     
    21432143                    var cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply);
    21442144                    if (cmpSupply)
    21452145                        cmpSupply.RemoveGatherer(this.entity);
    2146                     delete this.gatheringTarget;
     2146                    this.gatheringTarget = undefined;
    21472147                },
    21482148            },
    21492149
     
    22612261                    var cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply);
    22622262                    if (cmpSupply)
    22632263                        cmpSupply.RemoveGatherer(this.entity);
    2264                     delete this.gatheringTarget;
     2264                    this.gatheringTarget = undefined;
    22652265
    22662266                    // Show the carried resource, if we've gathered anything.
    22672267                    this.SetGathererAnimationOverride();
     
    23062306                                {
    23072307                                    // (Keep this Gather order on the stack so we'll
    23082308                                    // continue gathering after returning)
    2309                                     this.PushOrderFront("ReturnResource", { "target": nearby, "force": false });
     2309                                    this.PushOrderFront("ReturnResource", { "target": nearby, "force": false, "supply": this.gatheringTarget });
    23102310                                    return;
    23112311                                }
    23122312
     
    25422542            "APPROACHING": {
    25432543                "enter": function () {
    25442544                    this.SelectAnimation("move");
     2545
     2546                    if (this.order.data.supply)
     2547                    {
     2548                        let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
     2549                        let cmpSupply = Engine.QueryInterface(this.order.data.supply, IID_ResourceSupply);
     2550                        if (cmpSupply)
     2551                            cmpSupply.AddGatherer(cmpOwnership.GetOwner(), this.entity);
     2552                        this.gatheringTarget = this.order.data.supply;
     2553                    }
    25452554                },
    25462555
    25472556                "MoveCompleted": function() {
     
    25802589                    var nearby = this.FindNearestDropsite(genericType);
    25812590                    if (nearby)
    25822591                    {
     2592                        let data = { "target": nearby, "force": false };
     2593                        if (this.order.data.supply)
     2594                            data.supply = this.order.data.supply;
    25832595                        this.FinishOrder();
    2584                         this.PushOrderFront("ReturnResource", { "target": nearby, "force": false });
     2596                        this.PushOrderFront("ReturnResource", data);
    25852597                        return;
    25862598                    }
    25872599
     
    25882600                    // Oh no, couldn't find any drop sites. Give up on returning.
    25892601                    this.FinishOrder();
    25902602                },
     2603
     2604                "leave": function () {
     2605                    if (this.gatheringTarget)
     2606                    {
     2607                        let cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply);
     2608                        if (cmpSupply)
     2609                            cmpSupply.RemoveGatherer(this.entity);
     2610                        this.gatheringTarget = undefined;
     2611                    }
     2612                },
    25912613            },
    25922614        },
    25932615