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,268 Lines • ▼ Show 20 Lines | "IDLE": { | ||||
return true; | return true; | ||||
}, | }, | ||||
}, | }, | ||||
"WALKING": { | "WALKING": { | ||||
"enter": function() { | "enter": function() { | ||||
let cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); | let cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); | ||||
cmpUnitMotion.MoveToFormationOffset(this.order.data.target, this.order.data.x, this.order.data.z); | cmpUnitMotion.MoveToFormationOffset(this.order.data.target, this.order.data.x, this.order.data.z); | ||||
this.SelectAnimation("move"); | |||||
}, | }, | ||||
// Occurs when the unit has reached its destination and the controller | // Occurs when the unit has reached its destination and the controller | ||||
// is done moving. The controller is notified. | // is done moving. The controller is notified. | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
// We can only finish this order if the move was really completed. | // We can only finish this order if the move was really completed. | ||||
if (!this.CheckRange(this.order.data) || msg.error) | if (!this.CheckRange(this.order.data) || msg.error) | ||||
return; | return; | ||||
if (this.FinishOrder()) | if (this.FinishOrder()) | ||||
return; | return; | ||||
let cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation); | let cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation); | ||||
if (cmpFormation) | if (cmpFormation) | ||||
cmpFormation.SetInPosition(this.entity); | cmpFormation.SetInPosition(this.entity); | ||||
}, | }, | ||||
}, | }, | ||||
// Special case used by Order.LeaveFoundation | // Special case used by Order.LeaveFoundation | ||||
"WALKINGTOPOINT": { | "WALKINGTOPOINT": { | ||||
"enter": function() { | "enter": function() { | ||||
var cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation); | var cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation); | ||||
if (cmpFormation) | if (cmpFormation) | ||||
cmpFormation.UnsetInPosition(this.entity); | cmpFormation.UnsetInPosition(this.entity); | ||||
if (!this.MoveTo(this.order.data)) | if (!this.MoveTo(this.order.data)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
this.SelectAnimation("move"); | |||||
}, | }, | ||||
"MovementUpdate": function() { | "MovementUpdate": function() { | ||||
if (!this.CheckRange(this.order.data)) | if (!this.CheckRange(this.order.data)) | ||||
return; | return; | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | "IDLE": { | ||||
this.AttackEntitiesByPreference(msg.data.added); | this.AttackEntitiesByPreference(msg.data.added); | ||||
} | } | ||||
}, | }, | ||||
"LosHealRangeUpdate": function(msg) { | "LosHealRangeUpdate": function(msg) { | ||||
this.RespondToHealableEntities(msg.data.added); | this.RespondToHealableEntities(msg.data.added); | ||||
}, | }, | ||||
"MoveCompleted": function() { | |||||
this.SelectAnimation("idle"); | |||||
}, | |||||
"Timer": function(msg) { | "Timer": function(msg) { | ||||
if (!this.isIdle) | if (!this.isIdle) | ||||
{ | { | ||||
this.isIdle = true; | this.isIdle = true; | ||||
Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle }); | Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle }); | ||||
} | } | ||||
}, | }, | ||||
}, | }, | ||||
"WALKING": { | "WALKING": { | ||||
"enter": function() { | "enter": function() { | ||||
if (!this.MoveTo(this.order.data)) | if (!this.MoveTo(this.order.data)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
this.SelectAnimation("move"); | |||||
}, | }, | ||||
"leave": function () { | "leave": function () { | ||||
this.SelectAnimation("idle"); | |||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function() { | "MovementUpdate": function() { | ||||
if (this.CheckRange(this.order.data)) | if (this.CheckRange(this.order.data)) | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
}, | }, | ||||
}, | }, | ||||
"WALKINGANDFIGHTING": { | "WALKINGANDFIGHTING": { | ||||
"enter": function() { | "enter": function() { | ||||
if (!this.MoveTo(this.order.data)) | if (!this.MoveTo(this.order.data)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
// Show weapons rather than carried resources. | // Show weapons rather than carried resources. | ||||
this.SetAnimationVariant("combat"); | this.SetAnimationVariant("combat"); | ||||
this.StartTimer(0, 1000); | this.StartTimer(0, 1000); | ||||
this.SelectAnimation("move"); | |||||
}, | }, | ||||
"Timer": function(msg) { | "Timer": function(msg) { | ||||
this.FindWalkAndFightTargets(); | this.FindWalkAndFightTargets(); | ||||
}, | }, | ||||
"leave": function(msg) { | "leave": function(msg) { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
Show All 22 Lines | "PATROL": { | ||||
{ | { | ||||
this.patrolStartPosOrder = cmpPosition.GetPosition(); | this.patrolStartPosOrder = cmpPosition.GetPosition(); | ||||
this.patrolStartPosOrder.targetClasses = this.order.data.targetClasses; | this.patrolStartPosOrder.targetClasses = this.order.data.targetClasses; | ||||
this.patrolStartPosOrder.allowCapture = this.order.data.allowCapture; | this.patrolStartPosOrder.allowCapture = this.order.data.allowCapture; | ||||
} | } | ||||
this.StartTimer(0, 1000); | this.StartTimer(0, 1000); | ||||
this.SetAnimationVariant("combat"); | this.SetAnimationVariant("combat"); | ||||
this.SelectAnimation("move"); | |||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.StopTimer(); | this.StopTimer(); | ||||
delete this.patrolStartPosOrder; | delete this.patrolStartPosOrder; | ||||
this.SetDefaultAnimationVariant(); | this.SetDefaultAnimationVariant(); | ||||
}, | }, | ||||
Show All 27 Lines | "GUARD": { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
// Show weapons rather than carried resources. | // Show weapons rather than carried resources. | ||||
this.SetAnimationVariant("combat"); | this.SetAnimationVariant("combat"); | ||||
this.StartTimer(0, 1000); | this.StartTimer(0, 1000); | ||||
this.SelectAnimation("move"); | |||||
this.SetHeldPositionOnEntity(this.isGuardOf); | this.SetHeldPositionOnEntity(this.isGuardOf); | ||||
return false; | return false; | ||||
}, | }, | ||||
"Timer": function(msg) { | "Timer": function(msg) { | ||||
// Check the target is alive | // Check the target is alive | ||||
if (!this.TargetIsAlive(this.isGuardOf)) | if (!this.TargetIsAlive(this.isGuardOf)) | ||||
{ | { | ||||
Show All 31 Lines | "GUARD": { | ||||
}, | }, | ||||
"GUARDING": { | "GUARDING": { | ||||
"enter": function() { | "enter": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.StartTimer(1000, 1000); | this.StartTimer(1000, 1000); | ||||
this.SetHeldPositionOnEntity(this.entity); | this.SetHeldPositionOnEntity(this.entity); | ||||
this.SetAnimationVariant("combat"); | this.SetAnimationVariant("combat"); | ||||
this.SelectAnimation("idle"); | |||||
return false; | return false; | ||||
}, | }, | ||||
"LosRangeUpdate": function(msg) { | "LosRangeUpdate": function(msg) { | ||||
// Start attacking one of the newly-seen enemy (if any) | // Start attacking one of the newly-seen enemy (if any) | ||||
if (this.GetStance().targetVisibleEnemies) | if (this.GetStance().targetVisibleEnemies) | ||||
this.AttackEntitiesByPreference(msg.data.added); | this.AttackEntitiesByPreference(msg.data.added); | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | "FLEEING": { | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
this.PlaySound("panic"); | this.PlaySound("panic"); | ||||
// Run quickly | // Run quickly | ||||
this.SelectAnimation("move"); | |||||
this.SetSpeedMultiplier(this.GetRunMultiplier()); | this.SetSpeedMultiplier(this.GetRunMultiplier()); | ||||
}, | }, | ||||
"HealthChanged": function() { | "HealthChanged": function() { | ||||
this.SetSpeedMultiplier(this.GetRunMultiplier()); | this.SetSpeedMultiplier(this.GetRunMultiplier()); | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
Show All 29 Lines | "COMBAT": { | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
// Show weapons rather than carried resources. | // Show weapons rather than carried resources. | ||||
this.SetAnimationVariant("combat"); | this.SetAnimationVariant("combat"); | ||||
this.SelectAnimation("move"); | |||||
this.StartTimer(1000, 1000); | this.StartTimer(1000, 1000); | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
// Show carried resources when walking. | // Show carried resources when walking. | ||||
this.SetDefaultAnimationVariant(); | this.SetDefaultAnimationVariant(); | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.StopTimer(); | this.StopTimer(); | ||||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | "COMBAT": { | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
let cmpBuildingAI = Engine.QueryInterface(this.entity, IID_BuildingAI); | let cmpBuildingAI = Engine.QueryInterface(this.entity, IID_BuildingAI); | ||||
if (cmpBuildingAI) | if (cmpBuildingAI) | ||||
cmpBuildingAI.SetUnitAITarget(0); | cmpBuildingAI.SetUnitAITarget(0); | ||||
this.StopTimer(); | this.StopTimer(); | ||||
this.SetDefaultAnimationVariant(); | this.SetDefaultAnimationVariant(); | ||||
this.ResetAnimation(); | |||||
}, | }, | ||||
"Timer": function(msg) { | "Timer": function(msg) { | ||||
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 103 Lines • ▼ Show 20 Lines | "COMBAT": { | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
// Show weapons rather than carried resources. | // Show weapons rather than carried resources. | ||||
this.SetAnimationVariant("combat"); | this.SetAnimationVariant("combat"); | ||||
this.SelectAnimation("move"); | |||||
var cmpUnitAI = Engine.QueryInterface(this.order.data.target, IID_UnitAI); | var cmpUnitAI = Engine.QueryInterface(this.order.data.target, IID_UnitAI); | ||||
if (cmpUnitAI && cmpUnitAI.IsFleeing()) | if (cmpUnitAI && cmpUnitAI.IsFleeing()) | ||||
{ | { | ||||
// Run after a fleeing target | // Run after a fleeing target | ||||
this.SetSpeedMultiplier(this.GetRunMultiplier()); | this.SetSpeedMultiplier(this.GetRunMultiplier()); | ||||
} | } | ||||
this.StartTimer(1000, 1000); | this.StartTimer(1000, 1000); | ||||
}, | }, | ||||
Show All 37 Lines | "GATHER": { | ||||
if ((!cmpMirage || !cmpMirage.Mirages(IID_ResourceSupply)) && | if ((!cmpMirage || !cmpMirage.Mirages(IID_ResourceSupply)) && | ||||
(!cmpSupply || !cmpSupply.AddGatherer(cmpOwnership.GetOwner(), this.entity)) || | (!cmpSupply || !cmpSupply.AddGatherer(cmpOwnership.GetOwner(), this.entity)) || | ||||
!this.MoveTo(this.order.data, IID_ResourceGatherer)) | !this.MoveTo(this.order.data, IID_ResourceGatherer)) | ||||
{ | { | ||||
// The GATHERING timer will handle finding a valid resource. | // The GATHERING timer will handle finding a valid resource. | ||||
this.SetNextState("GATHERING"); | this.SetNextState("GATHERING"); | ||||
return true; | return true; | ||||
} | } | ||||
this.SelectAnimation("move"); | |||||
return false; | return false; | ||||
}, | }, | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
// The GATHERING timer will handle finding a valid resource. | // The GATHERING timer will handle finding a valid resource. | ||||
this.SetNextState("GATHERING"); | this.SetNextState("GATHERING"); | ||||
}, | }, | ||||
Show All 15 Lines | "GATHER": { | ||||
// Walking to a good place to gather resources near, used by GatherNearPosition | // Walking to a good place to gather resources near, used by GatherNearPosition | ||||
"WALKING": { | "WALKING": { | ||||
"enter": function() { | "enter": function() { | ||||
if (!this.MoveTo(this.order.data)) | if (!this.MoveTo(this.order.data)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
this.SelectAnimation("move"); | |||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
// If we failed, the GATHERING timer will handle finding a valid resource. | // If we failed, the GATHERING timer will handle finding a valid resource. | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | "GATHER": { | ||||
// don't use ownership because this is called after a conversion/resignation | // don't use ownership because this is called after a conversion/resignation | ||||
// and the ownership would be invalid then. | // and the ownership would be invalid then. | ||||
var cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply); | var cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply); | ||||
if (cmpSupply) | if (cmpSupply) | ||||
cmpSupply.RemoveGatherer(this.entity); | cmpSupply.RemoveGatherer(this.entity); | ||||
delete this.gatheringTarget; | delete this.gatheringTarget; | ||||
// Show the carried resource, if we've gathered anything. | // Show the carried resource, if we've gathered anything. | ||||
this.ResetAnimation(); | |||||
this.SetDefaultAnimationVariant(); | this.SetDefaultAnimationVariant(); | ||||
}, | }, | ||||
"Timer": function(msg) { | "Timer": function(msg) { | ||||
let resourceTemplate = this.order.data.template; | let resourceTemplate = this.order.data.template; | ||||
let resourceType = this.order.data.type; | let resourceType = this.order.data.type; | ||||
let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | ||||
▲ Show 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | "HEAL": { | ||||
} | } | ||||
if (!this.MoveTo(this.order.data, IID_Heal)) | if (!this.MoveTo(this.order.data, IID_Heal)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
this.SelectAnimation("move"); | |||||
this.StartTimer(1000, 1000); | this.StartTimer(1000, 1000); | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.StopTimer(); | this.StopTimer(); | ||||
}, | }, | ||||
Show All 34 Lines | "HEAL": { | ||||
// If using a non-default prepare time, re-sync the animation when the timer runs. | // If using a non-default prepare time, re-sync the animation when the timer runs. | ||||
this.resyncAnimation = (prepare != this.healTimers.prepare) ? true : false; | this.resyncAnimation = (prepare != this.healTimers.prepare) ? true : false; | ||||
this.FaceTowardsTarget(this.order.data.target); | this.FaceTowardsTarget(this.order.data.target); | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.ResetAnimation(); | |||||
this.StopTimer(); | this.StopTimer(); | ||||
}, | }, | ||||
"Timer": function(msg) { | "Timer": function(msg) { | ||||
var target = this.order.data.target; | var target = this.order.data.target; | ||||
// Check the target is still alive and healable | // Check the target is still alive and healable | ||||
if (this.TargetIsAlive(target) && this.CanHeal(target)) | if (this.TargetIsAlive(target) && this.CanHeal(target)) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
"RETURNRESOURCE": { | "RETURNRESOURCE": { | ||||
"APPROACHING": { | "APPROACHING": { | ||||
"enter": function() { | "enter": function() { | ||||
if (!this.MoveTo(this.order.data, IID_ResourceGatherer)) | if (!this.MoveTo(this.order.data, IID_ResourceGatherer)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
this.SelectAnimation("move"); | |||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
// Switch back to idle animation to guarantee we won't | this.StopMoving(); | ||||
// get stuck with the carry animation after stopping moving | |||||
this.SelectAnimation("idle"); | |||||
}, | }, | ||||
"MovementUpdate": function() { | "MovementUpdate": function() { | ||||
// Check the dropsite is in range and we can return our resource there | // Check the dropsite is in range and we can return our resource there | ||||
// (we didn't get stopped before reaching it) | // (we didn't get stopped before reaching it) | ||||
if (this.CheckTargetRange(this.order.data.target, IID_ResourceGatherer) && this.CanReturnResource(this.order.data.target, true)) | if (this.CheckTargetRange(this.order.data.target, IID_ResourceGatherer) && this.CanReturnResource(this.order.data.target, true)) | ||||
{ | { | ||||
var cmpResourceDropsite = Engine.QueryInterface(this.order.data.target, IID_ResourceDropsite); | var cmpResourceDropsite = Engine.QueryInterface(this.order.data.target, IID_ResourceDropsite); | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | "TRADE": { | ||||
"APPROACHINGMARKET": { | "APPROACHINGMARKET": { | ||||
"enter": function() { | "enter": function() { | ||||
if (!this.MoveToMarket(this.order.data.target)) | if (!this.MoveToMarket(this.order.data.target)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
this.SelectAnimation("move"); | |||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
if (!msg.error && !this.CheckTargetRange(this.order.data.target, IID_Trader)) | if (!msg.error && !this.CheckTargetRange(this.order.data.target, IID_Trader)) | ||||
Show All 23 Lines | |||||
"REPAIR": { | "REPAIR": { | ||||
"APPROACHING": { | "APPROACHING": { | ||||
"enter": function() { | "enter": function() { | ||||
if (!this.MoveTo(this.order.data, IID_Builder)) | if (!this.MoveTo(this.order.data, IID_Builder)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
this.SelectAnimation("move"); | |||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function() { | "MovementUpdate": function() { | ||||
this.SetNextState("REPAIRING"); | this.SetNextState("REPAIRING"); | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | "REPAIR": { | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
let cmpBuilderList = QueryBuilderListInterface(this.repairTarget); | let cmpBuilderList = QueryBuilderListInterface(this.repairTarget); | ||||
if (cmpBuilderList) | if (cmpBuilderList) | ||||
cmpBuilderList.RemoveBuilder(this.entity); | cmpBuilderList.RemoveBuilder(this.entity); | ||||
delete this.repairTarget; | delete this.repairTarget; | ||||
this.StopTimer(); | this.StopTimer(); | ||||
this.ResetAnimation(); | |||||
}, | }, | ||||
"Timer": function(msg) { | "Timer": function(msg) { | ||||
// Check we can still reach and repair the target | // Check we can still reach and repair the target | ||||
if (!this.CanRepair(this.repairTarget)) | if (!this.CanRepair(this.repairTarget)) | ||||
{ | { | ||||
// No longer owned by ally, or it doesn't exist any more | // No longer owned by ally, or it doesn't exist any more | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | "GARRISON": { | ||||
"APPROACHING": { | "APPROACHING": { | ||||
"enter": function() { | "enter": function() { | ||||
if (!this.MoveToGarrisonRange(this.order.data.target)) | if (!this.MoveToGarrisonRange(this.order.data.target)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
this.SelectAnimation("move"); | |||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function() { | "MovementUpdate": function() { | ||||
this.SetNextState("GARRISONED"); | this.SetNextState("GARRISONED"); | ||||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | "CHEERING": { | ||||
cmpDamageReceiver.SetInvulnerability(true); | cmpDamageReceiver.SetInvulnerability(true); | ||||
this.SelectAnimation("promotion"); | this.SelectAnimation("promotion"); | ||||
this.StartTimer(2800, 2800); | this.StartTimer(2800, 2800); | ||||
return false; | return false; | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopTimer(); | this.StopTimer(); | ||||
this.ResetAnimation(); | |||||
var cmpDamageReceiver = Engine.QueryInterface(this.entity, IID_DamageReceiver); | var cmpDamageReceiver = Engine.QueryInterface(this.entity, IID_DamageReceiver); | ||||
cmpDamageReceiver.SetInvulnerability(false); | cmpDamageReceiver.SetInvulnerability(false); | ||||
}, | }, | ||||
"Timer": function(msg) { | "Timer": function(msg) { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
}, | }, | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
"PICKUP": { | "PICKUP": { | ||||
"APPROACHING": { | "APPROACHING": { | ||||
"enter": function() { | "enter": function() { | ||||
if (!this.MoveTo(this.order.data)) | if (!this.MoveTo(this.order.data)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
this.SelectAnimation("move"); | |||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function() { | "MovementUpdate": function() { | ||||
this.SetNextState("LOADING"); | this.SetNextState("LOADING"); | ||||
}, | }, | ||||
"PickupCanceled": function() { | "PickupCanceled": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
}, | }, | ||||
}, | }, | ||||
"LOADING": { | "LOADING": { | ||||
"enter": function() { | "enter": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.SelectAnimation("idle"); | |||||
var cmpGarrisonHolder = Engine.QueryInterface(this.entity, IID_GarrisonHolder); | var cmpGarrisonHolder = Engine.QueryInterface(this.entity, IID_GarrisonHolder); | ||||
if (!cmpGarrisonHolder || cmpGarrisonHolder.IsFull()) | if (!cmpGarrisonHolder || cmpGarrisonHolder.IsFull()) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | "IDLE": { | ||||
this.SetNextState("FEEDING"); | this.SetNextState("FEEDING"); | ||||
return true; | return true; | ||||
}, | }, | ||||
}, | }, | ||||
"ROAMING": { | "ROAMING": { | ||||
"enter": function() { | "enter": function() { | ||||
// Walk in a random direction | // Walk in a random direction | ||||
this.SelectAnimation("move", false, 1); | |||||
this.SetFacePointAfterMove(false); | this.SetFacePointAfterMove(false); | ||||
this.MoveRandomly(+this.template.RoamDistance); | this.MoveRandomly(+this.template.RoamDistance); | ||||
// Set a random timer to switch to feeding state | // Set a random timer to switch to feeding state | ||||
this.StartTimer(randIntInclusive(+this.template.RoamTimeMin, +this.template.RoamTimeMax)); | this.StartTimer(randIntInclusive(+this.template.RoamTimeMin, +this.template.RoamTimeMax)); | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
Show All 36 Lines | "FEEDING": { | ||||
"enter": function() { | "enter": function() { | ||||
// Stop and eat for a while | // Stop and eat for a while | ||||
this.SelectAnimation("feeding"); | this.SelectAnimation("feeding"); | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.StartTimer(randIntInclusive(+this.template.FeedTimeMin, +this.template.FeedTimeMax)); | this.StartTimer(randIntInclusive(+this.template.FeedTimeMin, +this.template.FeedTimeMax)); | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.ResetAnimation(); | |||||
this.StopTimer(); | this.StopTimer(); | ||||
}, | }, | ||||
"LosRangeUpdate": function(msg) { | "LosRangeUpdate": function(msg) { | ||||
if (this.template.NaturalBehaviour == "skittish") | if (this.template.NaturalBehaviour == "skittish") | ||||
{ | { | ||||
if (msg.data.added.length > 0) | if (msg.data.added.length > 0) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 1,007 Lines • ▼ Show 20 Lines | if (type) | ||||
this.SetAnimationVariant(typename); | this.SetAnimationVariant(typename); | ||||
return; | return; | ||||
} | } | ||||
this.SetAnimationVariant(""); | this.SetAnimationVariant(""); | ||||
}; | }; | ||||
UnitAI.prototype.SelectAnimation = function(name, once = false, speed = 1.0) | UnitAI.prototype.ResetAnimation = function() | ||||
{ | { | ||||
let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); | let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); | ||||
if (!cmpVisual) | if (!cmpVisual) | ||||
return; | return; | ||||
// Special case: the "move" animation gets turned into a special | cmpVisual.SelectAnimation("idle", false, 1.0); | ||||
// movement mode that deals with speeds and walk/run automatically | }; | ||||
if (name == "move") | |||||
UnitAI.prototype.SelectAnimation = function(name, once = false, speed = 1.0) | |||||
{ | { | ||||
// Speed to switch from walking to running animations | let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); | ||||
cmpVisual.SelectMovementAnimation(this.GetWalkSpeed()); | if (!cmpVisual) | ||||
return; | return; | ||||
} | |||||
cmpVisual.SelectAnimation(name, once, speed); | cmpVisual.SelectAnimation(name, once, speed); | ||||
}; | }; | ||||
UnitAI.prototype.SetAnimationSync = function(actiontime, repeattime) | UnitAI.prototype.SetAnimationSync = function(actiontime, repeattime) | ||||
{ | { | ||||
var cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); | var cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); | ||||
if (!cmpVisual) | if (!cmpVisual) | ||||
▲ Show 20 Lines • Show All 1,814 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator