Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 1,775 Lines • ▼ Show 20 Lines | "COMBAT": { | ||||
// Show weapons rather than carried resources. | // Show weapons rather than carried resources. | ||||
this.SetAnimationVariant("combat"); | this.SetAnimationVariant("combat"); | ||||
this.SelectAnimation("move"); | this.SelectAnimation("move"); | ||||
this.StartTimer(1000, 1000); | this.StartTimer(1000, 1000); | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.ResetMoveSpeed(); | |||||
Stan: @wraitii's fix ? :D | |||||
Done Inline Actionsit is related only to code I just added Silier: it is related only to code I just added | |||||
Not Done Inline ActionsOh okay. Stan: Oh okay. | |||||
// Show carried resources when walking. | // Show carried resources when walking. | ||||
this.SetDefaultAnimationVariant(); | this.SetDefaultAnimationVariant(); | ||||
this.StopTimer(); | this.StopTimer(); | ||||
}, | }, | ||||
"Timer": function(msg) { | "Timer": function(msg) { | ||||
if (this.ShouldAbandonChase(this.order.data.target, this.order.data.force, IID_Attack, this.order.data.attackType)) | if (this.ShouldAbandonChase(this.order.data.target, this.order.data.force, IID_Attack, this.order.data.attackType)) | ||||
{ | { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
// Return to our original position | // Return to our original position | ||||
if (this.GetStance().respondHoldGround) | if (this.GetStance().respondHoldGround) | ||||
this.WalkToHeldPosition(); | this.WalkToHeldPosition(); | ||||
} | } | ||||
else if (this.ShouldRunAfterTarget(this.order.data.target)) | |||||
this.SetMoveSpeedRatio(this.GetRunMultiplier()); | |||||
}, | }, | ||||
"MoveCompleted": function() { | "MoveCompleted": function() { | ||||
Not Done Inline ActionsMaybe: let cmpUnitAI = Engine.QueryInterface(this.order.data.target, IID_UnitAI); if (!cmpUnitAI || !cmpUnitAI.IsFleeing()) return; // Run after the fleeing target this.SetMoveSpeedRatio(this.GetRunMultiplier()); Stan: Maybe:
```lang=js
let cmpUnitAI = Engine.QueryInterface(this.order.data.target, IID_UnitAI)… | |||||
if (this.CheckTargetAttackRange(this.order.data.target, this.order.data.attackType)) | if (this.CheckTargetAttackRange(this.order.data.target, this.order.data.attackType)) | ||||
{ | { | ||||
// If the unit needs to unpack, do so | // If the unit needs to unpack, do so | ||||
if (this.CanUnpack()) | if (this.CanUnpack()) | ||||
{ | { | ||||
this.PushOrderFront("Unpack", { "force": true }); | this.PushOrderFront("Unpack", { "force": true }); | ||||
return; | return; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 210 Lines • ▼ Show 20 Lines | "COMBAT": { | ||||
}, | }, | ||||
"CHASING": { | "CHASING": { | ||||
"enter": function() { | "enter": function() { | ||||
// Show weapons rather than carried resources. | // Show weapons rather than carried resources. | ||||
this.SetAnimationVariant("combat"); | this.SetAnimationVariant("combat"); | ||||
this.SelectAnimation("move"); | this.SelectAnimation("move"); | ||||
var cmpUnitAI = Engine.QueryInterface(this.order.data.target, IID_UnitAI); | // Check if we should run after it | ||||
if (cmpUnitAI && cmpUnitAI.IsFleeing()) | if (this.ShouldRunAfterTarget(this.order.data.target)) | ||||
{ | |||||
// Run after a fleeing target | |||||
this.SetMoveSpeedRatio(this.GetRunMultiplier()); | this.SetMoveSpeedRatio(this.GetRunMultiplier()); | ||||
} | |||||
this.StartTimer(1000, 1000); | this.StartTimer(1000, 1000); | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.ResetMoveSpeed(); | this.ResetMoveSpeed(); | ||||
// Show carried resources when walking. | // Show carried resources when walking. | ||||
this.SetDefaultAnimationVariant(); | this.SetDefaultAnimationVariant(); | ||||
this.StopTimer(); | this.StopTimer(); | ||||
}, | }, | ||||
"Timer": function(msg) { | "Timer": function(msg) { | ||||
if (this.ShouldAbandonChase(this.order.data.target, this.order.data.force, IID_Attack, this.order.data.attackType)) | if (this.ShouldAbandonChase(this.order.data.target, this.order.data.force, IID_Attack, this.order.data.attackType)) | ||||
{ | { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
// Return to our original position | // Return to our original position | ||||
if (this.GetStance().respondHoldGround) | if (this.GetStance().respondHoldGround) | ||||
this.WalkToHeldPosition(); | this.WalkToHeldPosition(); | ||||
} | } | ||||
else if (this.ShouldRunAfterTarget(this.order.data.target)) | |||||
this.SetMoveSpeedRatio(this.GetRunMultiplier()); | |||||
}, | }, | ||||
Not Done Inline ActionsSince it's both time the same code, maybe make it a function ? Stan: Since it's both time the same code, maybe make it a function ? | |||||
"MoveCompleted": function() { | "MoveCompleted": function() { | ||||
this.SetNextState("ATTACKING"); | this.SetNextState("ATTACKING"); | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
"GATHER": { | "GATHER": { | ||||
▲ Show 20 Lines • Show All 2,530 Lines • ▼ Show 20 Lines | UnitAI.prototype.RespondToHealableEntities = function(ents) | ||||
var ent = ents.find(ent => this.CanHeal(ent)); | var ent = ents.find(ent => this.CanHeal(ent)); | ||||
if (!ent) | if (!ent) | ||||
return false; | return false; | ||||
this.PushOrderFront("Heal", { "target": ent, "force": false }); | this.PushOrderFront("Heal", { "target": ent, "force": false }); | ||||
return true; | return true; | ||||
}; | }; | ||||
UnitAI.prototype.ShouldRunAfterTarget = function(target) | |||||
{ | |||||
let cmpUnitAI = Engine.QueryInterface(target, IID_UnitAI); | |||||
return cmpUnitAI && cmpUnitAI.IsFleeing(); | |||||
} | |||||
/** | /** | ||||
* Returns true if we should stop following the target entity. | * Returns true if we should stop following the target entity. | ||||
*/ | */ | ||||
UnitAI.prototype.ShouldAbandonChase = function(target, force, iid, type) | 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; | ||||
▲ Show 20 Lines • Show All 1,356 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
@wraitii's fix ? :D