Ticket #3748: UnitAI_set_isIdle_on_INDIVIDUAL.IDLE.enter_v1.patch

File UnitAI_set_isIdle_on_INDIVIDUAL.IDLE.enter_v1.patch, 2.4 KB (added by elexis, 8 years ago)
  • binaries/data/mods/public/simulation/components/UnitAI.js

    UnitAI.prototype.UnitFsmSpec = {  
    14521452                {
    14531453                    this.Guard(this.isGuardOf, false);
    14541454                    return true;
    14551455                }
    14561456
    1457                 // The GUI and AI want to know when a unit is idle, but we don't
    1458                 // want to send frequent spurious messages if the unit's only
    1459                 // idle for an instant and will quickly go off and do something else.
    1460                 // So we'll set a timer here and only report the idle event if we
    1461                 // remain idle
    1462                 this.StartTimer(1000);
    1463 
    14641457                // If a unit can heal and attack we first want to heal wounded units,
    14651458                // so check if we are a healer and find whether there's anybody nearby to heal.
    14661459                // (If anyone approaches later it'll be handled via LosHealRangeUpdate.)
    14671460                // If anyone in sight gets hurt that will be handled via LosHealRangeUpdate.
    14681461                if (this.IsHealer() && this.FindNewHealTargets())
    UnitAI.prototype.UnitFsmSpec = {  
    14721465                // so immediately check whether there's anybody nearby to attack.
    14731466                // (If anyone approaches later, it'll be handled via LosRangeUpdate.)
    14741467                if (this.FindNewTargets())
    14751468                    return true; // (abort the FSM transition since we may have already switched state)
    14761469
     1470                if (!this.isIdle)
     1471                {
     1472                    this.isIdle = true;
     1473                    Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": true });
     1474                }
     1475
    14771476                // Nobody to attack - stay in idle
    14781477                return false;
    14791478            },
    14801479
    14811480            "leave": function() {
    UnitAI.prototype.UnitFsmSpec = {  
    14881487                this.StopTimer();
    14891488
    14901489                if (this.isIdle)
    14911490                {
    14921491                    this.isIdle = false;
    1493                     Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle });
     1492                    Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": false });
    14941493                }
    14951494            },
    14961495
    14971496            "LosRangeUpdate": function(msg) {
    14981497                if (this.GetStance().targetVisibleEnemies)
    UnitAI.prototype.UnitFsmSpec = {  
    15131512            "MoveCompleted": function() {
    15141513                this.SelectAnimation("idle");
    15151514            },
    15161515
    15171516            "Timer": function(msg) {
    1518                 if (!this.isIdle)
    1519                 {
    1520                     this.isIdle = true;
    1521                     Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle });
    1522                 }
    15231517            },
    15241518        },
    15251519
    15261520        "WALKING": {
    15271521            "enter": function () {