Ticket #3748: UnitAI_set_isIdle_on_INDIVIDUAL.IDLE.enter_v2.patch
File UnitAI_set_isIdle_on_INDIVIDUAL.IDLE.enter_v2.patch, 3.5 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/simulation/components/UnitAI.js
UnitAI.prototype.UnitFsmSpec = { 1438 1438 if (cmpFormation) 1439 1439 animationName = cmpFormation.GetFormationAnimation(this.entity, animationName); 1440 1440 } 1441 1441 this.SelectAnimation(animationName); 1442 1442 1443 // If we have some orders, it is because we are in an intermediary state1444 // from FinishOrder (SetNextState("IDLE") is only executed when we get1445 // a ProcessMessage), and thus we should not start another order which could1446 // put us in a weird state1447 1443 if (this.orderQueue.length > 0 && !this.IsGarrisoned()) 1448 return false;1444 warn("INDIVIDUAL.IDLE.enter while having orders and not being garrisoned!"); 1449 1445 1450 1446 // If the unit is guarding/escorting, go back to its duty 1451 1447 if (this.isGuardOf) 1452 1448 { 1453 1449 this.Guard(this.isGuardOf, false); 1454 1450 return true; 1455 1451 } 1456 1452 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 1453 // If a unit can heal and attack we first want to heal wounded units, 1465 1454 // so check if we are a healer and find whether there's anybody nearby to heal. 1466 1455 // (If anyone approaches later it'll be handled via LosHealRangeUpdate.) 1467 1456 // If anyone in sight gets hurt that will be handled via LosHealRangeUpdate. 1468 1457 if (this.IsHealer() && this.FindNewHealTargets()) … … UnitAI.prototype.UnitFsmSpec = { 1472 1461 // so immediately check whether there's anybody nearby to attack. 1473 1462 // (If anyone approaches later, it'll be handled via LosRangeUpdate.) 1474 1463 if (this.FindNewTargets()) 1475 1464 return true; // (abort the FSM transition since we may have already switched state) 1476 1465 1466 if (this.isIdle) 1467 warn("INDIVIDUAL.IDLE.enter while isIdle!"); 1468 1477 1469 // Nobody to attack - stay in idle 1470 this.isIdle = true; 1471 Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": true }); 1478 1472 return false; 1479 1473 }, 1480 1474 1481 1475 "leave": function() { 1482 1476 var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 1483 1477 if (this.losRangeQuery) 1484 1478 cmpRangeManager.DisableActiveQuery(this.losRangeQuery); 1485 1479 if (this.losHealRangeQuery) 1486 1480 cmpRangeManager.DisableActiveQuery(this.losHealRangeQuery); 1487 1481 1488 this.StopTimer(); 1482 if (!this.isIdle) 1483 warn("INDIVIDUAL.IDLE.leave while not isIdle!"); 1489 1484 1490 if (this.isIdle) 1491 { 1492 this.isIdle = false; 1493 Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle }); 1494 } 1485 this.isIdle = false; 1486 Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": false }); 1495 1487 }, 1496 1488 1497 1489 "LosRangeUpdate": function(msg) { 1498 1490 if (this.GetStance().targetVisibleEnemies) 1499 1491 { … … UnitAI.prototype.UnitFsmSpec = { 1511 1503 }, 1512 1504 1513 1505 "MoveCompleted": function() { 1514 1506 this.SelectAnimation("idle"); 1515 1507 }, 1516 1517 "Timer": function(msg) {1518 if (!this.isIdle)1519 {1520 this.isIdle = true;1521 Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle });1522 }1523 },1524 1508 }, 1525 1509 1526 1510 "WALKING": { 1527 1511 "enter": function () { 1528 1512 this.SelectAnimation("move");