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,105 Lines • ▼ Show 20 Lines | "PATROL": { | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return; | return; | ||||
} | } | ||||
if (!this.patrolStartPosOrder) | if (!this.patrolStartPosOrder) | ||||
{ | { | ||||
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.StartTimer(0, 1000); | this.StartTimer(0, 1000); | ||||
}, | }, | ||||
"Timer": function(msg) { | "Timer": function(msg) { | ||||
// Check if there are no enemies to attack | // Check if there are no enemies to attack | ||||
this.FindWalkAndFightTargets(); | this.FindWalkAndFightTargets(); | ||||
▲ Show 20 Lines • Show All 511 Lines • ▼ Show 20 Lines | "PATROL": { | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return; | return; | ||||
} | } | ||||
if (!this.patrolStartPosOrder) | if (!this.patrolStartPosOrder) | ||||
{ | { | ||||
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.StartTimer(0, 1000); | this.StartTimer(0, 1000); | ||||
this.SelectAnimation("move"); | this.SelectAnimation("move"); | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopTimer(); | this.StopTimer(); | ||||
delete this.patrolStartPosOrder; | delete this.patrolStartPosOrder; | ||||
}, | }, | ||||
"Timer": function(msg) { | "Timer": function(msg) { | ||||
this.FindWalkAndFightTargets(); | this.FindWalkAndFightTargets(); | ||||
}, | }, | ||||
"MoveCompleted": function() { | "MoveCompleted": function() { | ||||
if (this.orderQueue.length == 1) | if (this.orderQueue.length == 1) | ||||
this.PushOrder("Patrol",this.patrolStartPosOrder); | this.PushOrder("Patrol", this.patrolStartPosOrder); | ||||
this.PushOrder(this.order.type, this.order.data); | this.PushOrder(this.order.type, this.order.data); | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
}, | }, | ||||
}, | }, | ||||
"GUARD": { | "GUARD": { | ||||
"RemoveGuard": function() { | "RemoveGuard": function() { | ||||
▲ Show 20 Lines • Show All 3,398 Lines • ▼ Show 20 Lines | UnitAI.prototype.WalkToTarget = function(target, queued) | ||||
this.AddOrder("WalkToTarget", { "target": target, "force": true }, queued); | this.AddOrder("WalkToTarget", { "target": target, "force": true }, queued); | ||||
}; | }; | ||||
/** | /** | ||||
* Adds walk-and-fight order to queue, this only occurs in response | * Adds walk-and-fight order to queue, this only occurs in response | ||||
* to a player order, and so is forced. | * to a player order, and so is forced. | ||||
* If targetClasses is given, only entities matching the targetClasses can be attacked. | * If targetClasses is given, only entities matching the targetClasses can be attacked. | ||||
*/ | */ | ||||
UnitAI.prototype.WalkAndFight = function(x, z, targetClasses, queued) | UnitAI.prototype.WalkAndFight = function(x, z, targetClasses, allowCapture = true, queued = false) | ||||
{ | { | ||||
this.AddOrder("WalkAndFight", { "x": x, "z": z, "targetClasses": targetClasses, "force": true }, queued); | this.AddOrder("WalkAndFight", { "x": x, "z": z, "targetClasses": targetClasses, "allowCapture": allowCapture, "force": true }, queued); | ||||
}; | }; | ||||
UnitAI.prototype.Patrol = function(x, z, targetClasses, queued) | UnitAI.prototype.Patrol = function(x, z, targetClasses, allowCapture = true, queued = false) | ||||
{ | { | ||||
if (!this.CanPatrol()) | if (!this.CanPatrol()) | ||||
{ | { | ||||
this.Walk(x, z, queued); | this.Walk(x, z, queued); | ||||
return; | return; | ||||
} | } | ||||
this.AddOrder("Patrol", { "x": x, "z": z, "targetClasses": targetClasses, "force": true }, queued); | this.AddOrder("Patrol", { "x": x, "z": z, "targetClasses": targetClasses, "allowCapture": allowCapture, "force": true }, queued); | ||||
}; | }; | ||||
/** | /** | ||||
* Adds leave foundation order to queue, treated as forced. | * Adds leave foundation order to queue, treated as forced. | ||||
*/ | */ | ||||
UnitAI.prototype.LeaveFoundation = function(target) | UnitAI.prototype.LeaveFoundation = function(target) | ||||
{ | { | ||||
// If we're already being told to leave a foundation, then | // If we're already being told to leave a foundation, then | ||||
// ignore this new request so we don't end up being too indecisive | // ignore this new request so we don't end up being too indecisive | ||||
// to ever actually move anywhere | // to ever actually move anywhere | ||||
// Ignore also the request if we are packing | // Ignore also the request if we are packing | ||||
if (this.order && (this.order.type == "LeaveFoundation" || (this.order.type == "Flee" && this.order.data.target == target) || this.IsPacking())) | if (this.order && (this.order.type == "LeaveFoundation" || (this.order.type == "Flee" && this.order.data.target == target) || this.IsPacking())) | ||||
return; | return; | ||||
this.PushOrderFront("LeaveFoundation", { "target": target, "force": true }); | this.PushOrderFront("LeaveFoundation", { "target": target, "force": true }); | ||||
}; | }; | ||||
/** | /** | ||||
* Adds attack order to the queue, forced by the player. | * Adds attack order to the queue, forced by the player. | ||||
*/ | */ | ||||
UnitAI.prototype.Attack = function(target, queued, allowCapture) | UnitAI.prototype.Attack = function(target, allowCapture = true, queued = false) | ||||
{ | { | ||||
if (!this.CanAttack(target)) | if (!this.CanAttack(target)) | ||||
{ | { | ||||
// We don't want to let healers walk to the target unit so they can be easily killed. | // We don't want to let healers walk to the target unit so they can be easily killed. | ||||
// Instead we just let them get into healing range. | // Instead we just let them get into healing range. | ||||
if (this.IsHealer()) | if (this.IsHealer()) | ||||
this.MoveToTargetRange(target, IID_Heal); | this.MoveToTargetRange(target, IID_Heal); | ||||
else | else | ||||
▲ Show 20 Lines • Show All 420 Lines • ▼ Show 20 Lines | for (var ent of cmpFormation.members) | ||||
continue; | continue; | ||||
if (targetClasses.avoid && cmpIdentity | if (targetClasses.avoid && cmpIdentity | ||||
&& MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.avoid)) | && MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.avoid)) | ||||
continue; | continue; | ||||
// Only used by the AIs to prevent some choices of targets | // Only used by the AIs to prevent some choices of targets | ||||
if (targetClasses.vetoEntities && targetClasses.vetoEntities[targ]) | if (targetClasses.vetoEntities && targetClasses.vetoEntities[targ]) | ||||
continue; | continue; | ||||
} | } | ||||
this.PushOrderFront("Attack", { "target": targ, "force": true, "allowCapture": true }); | this.PushOrderFront("Attack", { "target": targ, "force": true, "allowCapture": this.order.data.allowCapture }); | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
var targets = this.GetTargetsFromUnit(); | var targets = this.GetTargetsFromUnit(); | ||||
for (var targ of targets) | for (var targ of targets) | ||||
Show All 9 Lines | if (this.order.data.targetClasses) | ||||
continue; | continue; | ||||
if (cmpIdentity && targetClasses.avoid | if (cmpIdentity && targetClasses.avoid | ||||
&& MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.avoid)) | && MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.avoid)) | ||||
continue; | continue; | ||||
// Only used by the AIs to prevent some choices of targets | // Only used by the AIs to prevent some choices of targets | ||||
if (targetClasses.vetoEntities && targetClasses.vetoEntities[targ]) | if (targetClasses.vetoEntities && targetClasses.vetoEntities[targ]) | ||||
continue; | continue; | ||||
} | } | ||||
this.PushOrderFront("Attack", { "target": targ, "force": true, "allowCapture": true }); | this.PushOrderFront("Attack", { "target": targ, "force": true, "allowCapture": this.order.data.allowCapture }); | ||||
return true; | return true; | ||||
} | } | ||||
// healers on a walk-and-fight order should heal injured units | // healers on a walk-and-fight order should heal injured units | ||||
if (this.IsHealer()) | if (this.IsHealer()) | ||||
return this.FindNewHealTargets(); | return this.FindNewHealTargets(); | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 512 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator