Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 1,455 Lines • ▼ Show 20 Lines | "IDLE": { | ||||
if (this.isIdle) | if (this.isIdle) | ||||
{ | { | ||||
this.isIdle = false; | this.isIdle = false; | ||||
Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle }); | Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle }); | ||||
} | } | ||||
}, | }, | ||||
"LosRangeUpdate": function(msg) { | "LosRangeUpdate": function(msg) { | ||||
if (this.GetStance().targetVisibleEnemies) | // Start attacking one of the newly-seen enemy (if any). | ||||
{ | // We check for idleness to prevent an entity to attack only newly seen enemies | ||||
// Start attacking one of the newly-seen enemy (if any) | // when receiving a LosRangeUpdate on the same turn as the entity becomes idle | ||||
// since this.FindNewTargets is called in the timer. | |||||
if (this.isIdle && msg.data.added.length && this.GetStance().targetVisibleEnemies) | |||||
this.AttackEntitiesByPreference(msg.data.added); | this.AttackEntitiesByPreference(msg.data.added); | ||||
} | |||||
}, | }, | ||||
"LosHealRangeUpdate": function(msg) { | "LosHealRangeUpdate": function(msg) { | ||||
// We check for idleness to prevent an entity to heal only newly seen entities | |||||
// when receiving a LosHealRangeUpdate on the same turn as the entity becomes idle | |||||
// since this.FindNewHealTargets is called in the timer. | |||||
if (this.isIdle && msg.data.added.length) | |||||
this.RespondToHealableEntities(msg.data.added); | this.RespondToHealableEntities(msg.data.added); | ||||
}, | }, | ||||
"Timer": function(msg) { | "Timer": function(msg) { | ||||
// If the unit is guarding/escorting, go back to its duty | // If the unit is guarding/escorting, go back to its duty. | ||||
if (this.isGuardOf) | if (this.isGuardOf) | ||||
{ | { | ||||
this.Guard(this.isGuardOf, false); | this.Guard(this.isGuardOf, false); | ||||
return; | return; | ||||
} | } | ||||
// If a unit can heal and attack we first want to heal wounded units, | // If a unit can heal and attack we first want to heal wounded units, | ||||
// so check if we are a healer and find whether there's anybody nearby to heal. | // so check if we are a healer and find whether there's anybody nearby to heal. | ||||
// (If anyone approaches later it'll be handled via LosHealRangeUpdate.) | // (If anyone approaches later it'll be handled via LosHealRangeUpdate.) | ||||
// If anyone in sight gets hurt that will be handled via LosHealRangeUpdate. | // If anyone in sight gets hurt that will be handled via LosHealRangeUpdate. | ||||
if (this.IsHealer() && this.FindNewHealTargets()) | if (this.IsHealer() && this.FindNewHealTargets()) | ||||
return; // (abort the FSM transition since we may have already switched state) | return; | ||||
// If we entered the idle state we must have nothing better to do, | // If we entered the idle state we must have nothing better to do, | ||||
// so immediately check whether there's anybody nearby to attack. | // so immediately check whether there's anybody nearby to attack. | ||||
// (If anyone approaches later, it'll be handled via LosRangeUpdate.) | // (If anyone approaches later, it'll be handled via LosRangeUpdate.) | ||||
if (this.FindNewTargets()) | if (this.FindNewTargets()) | ||||
return; // (abort the FSM transition since we may have already switched state) | return; | ||||
if (this.formationOffset && this.formationController) | if (this.formationOffset && this.formationController) | ||||
{ | { | ||||
this.PushOrder("FormationWalk", { | this.PushOrder("FormationWalk", { | ||||
"target": this.formationController, | "target": this.formationController, | ||||
"x": this.formationOffset.x, | "x": this.formationOffset.x, | ||||
"z": this.formationOffset.z, | "z": this.formationOffset.z, | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 4,581 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator