Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 1,824 Lines • ▼ Show 20 Lines | "COMBAT": { | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
if (!this.formationAnimationVariant) | if (!this.formationAnimationVariant) | ||||
this.SetDefaultAnimationVariant(); | this.SetDefaultAnimationVariant(); | ||||
}, | }, | ||||
"APPROACHING": { | "APPROACHING": { | ||||
"Order.MoveToApproachingPoint": function(msg) { | |||||
if (this.CheckPointRangeExplicit(msg.data.x, msg.data.z, 0, msg.data.max)) | |||||
{ | |||||
this.StopMoving(); | |||||
this.FinishOrder(); | |||||
return; | |||||
} | |||||
this.order.data.relaxed = true; | |||||
this.StopTimer(); | |||||
this.SetNextState("MOVINGTOPOINT"); | |||||
}, | |||||
"enter": function() { | "enter": function() { | ||||
if (!this.MoveToTargetAttackRange(this.order.data.target, this.order.data.attackType)) | if (!this.MoveToTargetAttackRange(this.order.data.target, this.order.data.attackType)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
if (!this.formationAnimationVariant) | if (!this.formationAnimationVariant) | ||||
Show All 19 Lines | "COMBAT": { | ||||
this.WalkToHeldPosition(); | this.WalkToHeldPosition(); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
this.RememberTargetPosition(); | this.RememberTargetPosition(); | ||||
if (this.order.data.hunting && this.orderQueue.length > 1 && | if (this.order.data.hunting && this.orderQueue.length > 1 && | ||||
this.orderQueue[1].type === "Gather") | this.orderQueue[1].type === "Gather") | ||||
this.RememberTargetPosition(this.orderQueue[1].data); | this.RememberTargetPosition(this.orderQueue[1].data); | ||||
if (!this.CheckTargetVisible(this.order.data.target) && this.order.data.lastPos) | |||||
{ | |||||
let lastPos = this.order.data.lastPos; | |||||
let cmpAttack = Engine.QueryInterface(this.entity, IID_Attack); | |||||
this.AddOrder("MoveToApproachingPoint", { | |||||
"x": lastPos.x, | |||||
"z": lastPos.z, | |||||
"max": cmpAttack.GetRange(this.order.data.attackType).max, | |||||
"force": true | |||||
}); | |||||
} | |||||
} | } | ||||
}, | }, | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
if (msg.likelyFailure) | if (msg.likelyFailure) | ||||
{ | { | ||||
// This also handles hunting. | // This also handles hunting. | ||||
if (this.orderQueue.length > 1) | if (this.orderQueue.length > 1) | ||||
Show All 23 Lines | "COMBAT": { | ||||
this.SetNextState("ATTACKING"); | this.SetNextState("ATTACKING"); | ||||
} | } | ||||
else if (msg.likelySuccess) | else if (msg.likelySuccess) | ||||
// Try moving again, | // Try moving again, | ||||
// attack range uses a height-related formula and our actual max range might have changed. | // attack range uses a height-related formula and our actual max range might have changed. | ||||
if (!this.MoveToTargetAttackRange(this.order.data.target, this.order.data.attackType)) | if (!this.MoveToTargetAttackRange(this.order.data.target, this.order.data.attackType)) | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
}, | }, | ||||
"MOVINGTOPOINT": { | |||||
"enter": function() { | |||||
if (!this.MoveTo(this.order.data)) | |||||
{ | |||||
this.FinishOrder(); | |||||
return true; | |||||
} | |||||
return false; | |||||
}, | |||||
"leave": function() { | |||||
this.StopMoving(); | |||||
}, | |||||
"MovementUpdate": function(msg) { | |||||
// If it looks like the path is failing, and we are close enough (3 tiles) from wanted range | |||||
// stop anyways. This avoids pathing for an unreachable goal and reduces lag considerably. | |||||
if (msg.likelyFailure || | |||||
msg.obstructed && this.RelaxedMaxRangeCheck(this.order.data, this.order.data.max + this.DefaultRelaxedMaxRange) || | |||||
!msg.obstructed && this.CheckRange(this.order.data)) | |||||
this.FinishOrder(); | |||||
}, | |||||
}, | |||||
}, | }, | ||||
"ATTACKING": { | "ATTACKING": { | ||||
"enter": function() { | "enter": function() { | ||||
let target = this.order.data.target; | let target = this.order.data.target; | ||||
let cmpFormation = Engine.QueryInterface(target, IID_Formation); | let cmpFormation = Engine.QueryInterface(target, IID_Formation); | ||||
// if the target is a formation, save the attacking formation, and pick a member | // if the target is a formation, save the attacking formation, and pick a member | ||||
if (cmpFormation) | if (cmpFormation) | ||||
▲ Show 20 Lines • Show All 216 Lines • ▼ Show 20 Lines | "COMBAT": { | ||||
this.WalkToHeldPosition(); | this.WalkToHeldPosition(); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
this.RememberTargetPosition(); | this.RememberTargetPosition(); | ||||
if (this.order.data.hunting && this.orderQueue.length > 1 && | if (this.order.data.hunting && this.orderQueue.length > 1 && | ||||
this.orderQueue[1].type === "Gather") | this.orderQueue[1].type === "Gather") | ||||
this.RememberTargetPosition(this.orderQueue[1].data); | this.RememberTargetPosition(this.orderQueue[1].data); | ||||
if (!this.CheckTargetVisible(this.order.data.target) && this.order.data.lastPos) | |||||
{ | |||||
let lastPos = this.order.data.lastPos; | |||||
let cmpAttack = Engine.QueryInterface(this.entity, IID_Attack); | |||||
this.AddOrder("MoveToChasingPoint", { | |||||
"x": lastPos.x, | |||||
"z": lastPos.z, | |||||
"max": cmpAttack.GetRange(this.order.data.attackType).max, | |||||
"force": true | |||||
}); | |||||
} | |||||
} | } | ||||
}, | }, | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
if (msg.likelyFailure) | if (msg.likelyFailure) | ||||
{ | { | ||||
// This also handles hunting. | // This also handles hunting. | ||||
if (this.orderQueue.length > 1) | if (this.orderQueue.length > 1) | ||||
▲ Show 20 Lines • Show All 2,825 Lines • ▼ Show 20 Lines | UnitAI.prototype.ShouldAbandonChase = function(target, force, iid, type) | ||||
// Forced orders shouldn't be interrupted. | // Forced orders shouldn't be interrupted. | ||||
if (force) | if (force) | ||||
return false; | return false; | ||||
// If we are guarding/escorting, don't abandon as long as the guarded unit is in target range of the attacker | // If we are guarding/escorting, don't abandon as long as the guarded unit is in target range of the attacker | ||||
if (this.isGuardOf) | if (this.isGuardOf) | ||||
{ | { | ||||
var cmpUnitAI = Engine.QueryInterface(target, IID_UnitAI); | var cmpUnitAI = Engine.QueryInterface(target, IID_UnitAI); | ||||
var cmpAttack = Engine.QueryInterface(target, IID_Attack); | var cmpAttack = Engine.QueryInterface(target, IID_Attack); | ||||
bb: Fix linter here | |||||
if (cmpUnitAI && cmpAttack && | if (cmpUnitAI && cmpAttack && | ||||
cmpAttack.GetAttackTypes().some(type => cmpUnitAI.CheckTargetAttackRange(this.isGuardOf, type))) | cmpAttack.GetAttackTypes().some(type => cmpUnitAI.CheckTargetAttackRange(this.isGuardOf, type))) | ||||
return false; | return false; | ||||
} | } | ||||
// Stop if we're in hold-ground mode and it's too far from the holding point | // Stop if we're in hold-ground mode and it's too far from the holding point | ||||
if (this.GetStance().respondHoldGround) | if (this.GetStance().respondHoldGround) | ||||
{ | { | ||||
if (!this.CheckTargetDistanceFromHeldPosition(target, iid, type)) | if (!this.CheckTargetDistanceFromHeldPosition(target, iid, type)) | ||||
return true; | return true; | ||||
} | } | ||||
// Stop if it's left our vision range, unless we're especially persistent | // Stop if it's left our vision range, unless we're especially persistent | ||||
if (!this.GetStance().respondChaseBeyondVision) | if (!this.GetStance().respondChaseBeyondVision) | ||||
{ | { | ||||
if (!this.CheckTargetIsInVisionRange(target)) | if (!this.CheckTargetIsInVisionRange(target)) | ||||
return true; | return true; | ||||
} | } | ||||
// (Note that CCmpUnitMotion will detect if the target is lost in FoW, | // (Note that CCmpUnitMotion will detect if the target is lost in FoW, | ||||
// and will continue moving to its last seen position and then stop) | // and will continue moving to its last seen position and then stop) | ||||
Not Done Inline ActionsApparently wrong, @wraitii? Freagarach: Apparently wrong, @wraitii? | |||||
Not Done Inline Actionsbb: Dates back to rP9657, which apparently tried to fix the same issue, but failed to hold the code… | |||||
Not Done Inline ActionsIndeed, unitMotion ignores FOW right now. wraitii: Indeed, unitMotion ignores FOW right now.
Even if it was FOW-aware, I agree that it should… | |||||
return false; | return false; | ||||
}; | }; | ||||
/* | /* | ||||
* Returns whether we should chase the targeted entity, | * Returns whether we should chase the targeted entity, | ||||
* given our current stance. | * given our current stance. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 1,366 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Fix linter here