Ticket #1841: idle.diff

File idle.diff, 1.9 KB (added by mimo, 11 years ago)
  • binaries/data/mods/public/simulation/components/UnitAI.js

     
    11081108            },
    11091109
    11101110            "LosRangeUpdate": function(msg) {
     1111                this.entitiesInLos = undefined;
    11111112                if (this.GetStance().targetVisibleEnemies)
    11121113                {
    11131114                    // Start attacking one of the newly-seen enemy (if any)
    1114                     this.AttackEntitiesByPreference(msg.data.added);
     1115                    var ok = this.AttackEntitiesByPreference(msg.data.added);
     1116                    // if !ok, the attacker is probably too far for our stance
     1117                    // but still we should keep an eye on him
     1118                    if (!ok && msg.data.added.length)
     1119                    {
     1120                        this.entitiesInLos = msg.data;
     1121                        if (!this.timer)
     1122                            this.StartTimer(1000);
     1123                    }
    11151124                }
    11161125            },
    11171126
    11181127            "LosGaiaRangeUpdate": function(msg) {
     1128                this.gaiaEntitiesInLos = undefined;
    11191129                if (this.GetStance().targetVisibleEnemies)
    11201130                {
    11211131                    // Start attacking one of the newly-seen enemy (if any)
    1122                     this.AttackGaiaEntitiesByPreference(msg.data.added);
     1132                    var ok = this.AttackGaiaEntitiesByPreference(msg.data.added);
     1133                    // if !ok, the attacker is probably too far for our stance
     1134                    // but still we should keep an eye on him
     1135                    if (!ok && msg.data.added.length)
     1136                    {
     1137                        this.gaiaEntitiesInLos = msg.data;
     1138                        if (!this.timer)
     1139                            this.StartTimer(1000);
     1140                    }
    11231141                }
    11241142            },
    11251143
     
    11331151                    this.isIdle = true;
    11341152                    Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle });
    11351153                }
     1154                // then check if the detected attackers have come nearer
     1155                if (this.entitiesInLos)
     1156                    UnitFsm.ProcessMessage(this, {"type": "LosRangeUpdate", "data": this.entitiesInLos});
     1157                if (this.gaiaEntitiesInLos)
     1158                    UnitFsm.ProcessMessage(this, {"type": "LosGaiaRangeUpdate", "data": this.gaiaEntitiesInLos});
    11361159            },
    11371160        },
    11381161