Changeset 25243

Timestamp:
Apr 12, 2021, 2:50:17 PM (3 years ago)
Author:
Freagarach
Message:

Minor fixes after Gathering refactoring.

  • initPos was used wrong.
  • There were two CanGather functions in cmpResourceGatherer.
  • Reduced some duplication in the ReturnResource order.

Differential revision: D3838.

Location:
ps/trunk/binaries/data/mods/public/simulation/components
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/binaries/data/mods/public/simulation/components/ResourceGatherer.js

    r25235 r25243  
    331331
    332332/**
    333  * @param {number} target - The entity ID of the target to check.
    334  * @return {boolean} - Whether we can gather from the target.
    335  */
    336 ResourceGatherer.prototype.CanGather = function(target)
    337 {
    338     return this.GetTargetGatherRate(target) > 0;
    339 };
    340 
    341 /**
    342333 * Returns whether this unit can carry more of the given type of resource.
    343334 * (This ignores whether the unit is actually able to gather that
  • ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js

    r25240 r25243  
    559559
    560560    "Order.ReturnResource": function(msg) {
    561         let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer);
    562         if (this.CheckTargetRange(msg.data.target, IID_ResourceGatherer) &&
    563             this.CanReturnResource(msg.data.target, true, cmpResourceGatherer))
    564         {
    565             cmpResourceGatherer.CommitResources(msg.data.target);
    566             this.SetDefaultAnimationVariant();
    567 
    568             // Our next order should always be a Gather,
    569             // so just switch back to that order.
    570             this.FinishOrder();
    571         }
     561        if (this.CheckTargetRange(msg.data.target, IID_ResourceGatherer))
     562            this.SetNextState("RETURNRESOURCE.DROPPINGRESOURCES");
    572563        else if (this.AbleToMove())
    573             this.SetNextState("INDIVIDUAL.RETURNRESOURCE.APPROACHING");
     564            this.SetNextState("RETURNRESOURCE.APPROACHING");
    574565        else
    575566            return this.FinishOrder();
     
    24382429
    24392430                "MovementUpdate": function(msg) {
    2440                     // If we failed, the GATHERING timer will handle finding a valid resource.
    24412431                    if (msg.likelyFailure || msg.obstructed && this.RelaxedMaxRangeCheck(this.order.data, this.DefaultRelaxedMaxRange) ||
    24422432                         this.CheckRange(this.order.data))
    2443                         this.SetNextState("GATHERING");
     2433                        this.SetNextState("");
    24442434                },
    24452435            },
     
    25582548                        initPos = { 'x': pos.X, 'z': pos.Z };
    25592549                    else if (!nearbyResource)
    2560                         nearbyResource = this.FindNearbyResource(new Vector2D(initPos.X, initPos.Z), filter);
     2550                        nearbyResource = this.FindNearbyResource(new Vector2D(initPos.), filter);
    25612551
    25622552                    if (nearbyResource)
     
    27282718                        this.SetDefaultAnimationVariant();
    27292719
    2730                         // Our next order should always be a Gather,
    2731                         // so just switch back to that order.
    27322720                        this.FinishOrder();
    27332721                        return true;
     
    43194307        if (!this.CanGather(ent) || !this.CheckTargetVisible(ent))
    43204308            return false;
    4321         let cmpResourceSupply = Engine.QueryInterface(ent, IID_ResourceSupply);
    4322         let type = cmpResourceSupply.GetType();
    4323         let amount = cmpResourceSupply.GetCurrentAmount();
    43244309
    43254310        let template = cmpTemplateManager.GetCurrentTemplateName(ent);
     
    43274312            template = template.slice(9);
    43284313
    4329         return amount > 0 && cmpResourceSupply.IsAvailableTo(this.entity) && filter(ent, type, template);
     4314        let cmpResourceSupply = Engine.QueryInterface(ent, IID_ResourceSupply);
     4315        let type = cmpResourceSupply.GetType();
     4316        return cmpResourceSupply.IsAvailableTo(this.entity) && filter(ent, type, template);
    43304317    });
    43314318};
Note: See TracChangeset for help on using the changeset viewer.