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 , 8 years ago) |
---|
-
binaries/data/mods/public/simulation/components/UnitAI.js
UnitAI.prototype.UnitFsmSpec = { 1452 1452 { 1453 1453 this.Guard(this.isGuardOf, false); 1454 1454 return true; 1455 1455 } 1456 1456 1457 // The GUI and AI want to know when a unit is idle, but we don't1458 // want to send frequent spurious messages if the unit's only1459 // 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 we1461 // remain idle1462 this.StartTimer(1000);1463 1464 1457 // If a unit can heal and attack we first want to heal wounded units, 1465 1458 // so check if we are a healer and find whether there's anybody nearby to heal. 1466 1459 // (If anyone approaches later it'll be handled via LosHealRangeUpdate.) 1467 1460 // If anyone in sight gets hurt that will be handled via LosHealRangeUpdate. 1468 1461 if (this.IsHealer() && this.FindNewHealTargets()) … … UnitAI.prototype.UnitFsmSpec = { 1472 1465 // so immediately check whether there's anybody nearby to attack. 1473 1466 // (If anyone approaches later, it'll be handled via LosRangeUpdate.) 1474 1467 if (this.FindNewTargets()) 1475 1468 return true; // (abort the FSM transition since we may have already switched state) 1476 1469 1470 if (!this.isIdle) 1471 { 1472 this.isIdle = true; 1473 Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": true }); 1474 } 1475 1477 1476 // Nobody to attack - stay in idle 1478 1477 return false; 1479 1478 }, 1480 1479 1481 1480 "leave": function() { … … UnitAI.prototype.UnitFsmSpec = { 1488 1487 this.StopTimer(); 1489 1488 1490 1489 if (this.isIdle) 1491 1490 { 1492 1491 this.isIdle = false; 1493 Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle });1492 Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": false }); 1494 1493 } 1495 1494 }, 1496 1495 1497 1496 "LosRangeUpdate": function(msg) { 1498 1497 if (this.GetStance().targetVisibleEnemies) … … UnitAI.prototype.UnitFsmSpec = { 1513 1512 "MoveCompleted": function() { 1514 1513 this.SelectAnimation("idle"); 1515 1514 }, 1516 1515 1517 1516 "Timer": function(msg) { 1518 if (!this.isIdle)1519 {1520 this.isIdle = true;1521 Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle });1522 }1523 1517 }, 1524 1518 }, 1525 1519 1526 1520 "WALKING": { 1527 1521 "enter": function () {