Timestamp:
Apr 12, 2021, 8:51:39 AM (3 years ago)
Author:
Freagarach
Message:

Attack using cmpAttack instead of UnitAI.

Keep responsibilities separated, allow easier modding of attacking behaviour.
Ideally the BuildingAI attacking routine would be merged in here as well, but not done for now.

Part of #5810
Differential revision: D3816
Comments by: @smiley, @Stan

File:
1 edited

Legend:

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

    r25206 r25235  
    218218ResourceGatherer.prototype.StopGathering = function(reason)
    219219{
    220     if (this.timer)
    221     {
    222         let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
    223         cmpTimer.CancelTimer(this.timer);
    224         delete this.timer;
    225     }
    226 
    227     if (this.target)
    228     {
    229         let cmpResourceSupply = Engine.QueryInterface(this.target, IID_ResourceSupply);
    230         if (cmpResourceSupply)
    231             cmpResourceSupply.RemoveGatherer(this.entity);
    232         this.RemoveFromPlayerCounter();
    233         delete this.target;
    234     }
     220    if (!this.target)
     221        return;
     222
     223    let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
     224    cmpTimer.CancelTimer(this.timer);
     225    delete this.timer;
     226
     227    let cmpResourceSupply = Engine.QueryInterface(this.target, IID_ResourceSupply);
     228    if (cmpResourceSupply)
     229        cmpResourceSupply.RemoveGatherer(this.entity);
     230    this.RemoveFromPlayerCounter();
     231
     232    delete this.target;
    235233
    236234    let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual);
     
    238236        cmpVisual.SelectAnimation("idle", false, 1.0);
    239237
    240     // The callerIID component may start gathering again,
     238    // The callerIID component may start again,
    241239    // replacing the callerIID, hence save that.
    242240    let callerIID = this.callerIID;
Note: See TracChangeset for help on using the changeset viewer.