Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 6,108 Lines • ▼ Show 20 Lines | |||||
UnitAI.prototype.CanHeal = function(target) | UnitAI.prototype.CanHeal = function(target) | ||||
{ | { | ||||
// Formation controllers should always respond to commands | // Formation controllers should always respond to commands | ||||
// (then the individual units can make up their own minds) | // (then the individual units can make up their own minds) | ||||
if (this.IsFormationController()) | if (this.IsFormationController()) | ||||
return true; | return true; | ||||
// Verify that we're able to respond to Heal commands | let cmpHeal = Engine.QueryInterface(this.entity, IID_Heal); | ||||
var cmpHeal = Engine.QueryInterface(this.entity, IID_Heal); | return cmpHeal && cmpHeal.CanHeal(target); | ||||
if (!cmpHeal) | |||||
return false; | |||||
// Verify that the target is alive | |||||
if (!this.TargetIsAlive(target)) | |||||
return false; | |||||
// Verify that the target is owned by the same player as the entity or of an ally | |||||
var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | |||||
if (!cmpOwnership || !(IsOwnedByPlayer(cmpOwnership.GetOwner(), target) || IsOwnedByAllyOfPlayer(cmpOwnership.GetOwner(), target))) | |||||
return false; | |||||
// Verify that the target is not unhealable (or at max health) | |||||
var cmpHealth = Engine.QueryInterface(target, IID_Health); | |||||
if (!cmpHealth || cmpHealth.IsUnhealable()) | |||||
return false; | |||||
// Verify that the target has no unhealable class | |||||
var cmpIdentity = Engine.QueryInterface(target, IID_Identity); | |||||
if (!cmpIdentity) | |||||
return false; | |||||
if (MatchesClassList(cmpIdentity.GetClassesList(), cmpHeal.GetUnhealableClasses())) | |||||
return false; | |||||
// Verify that the target is a healable class | |||||
if (MatchesClassList(cmpIdentity.GetClassesList(), cmpHeal.GetHealableClasses())) | |||||
return true; | |||||
return false; | |||||
}; | }; | ||||
UnitAI.prototype.CanReturnResource = function(target, checkCarriedResource) | UnitAI.prototype.CanReturnResource = function(target, checkCarriedResource) | ||||
{ | { | ||||
if (this.IsTurret()) | if (this.IsTurret()) | ||||
return false; | return false; | ||||
// Formation controllers should always respond to commands | // Formation controllers should always respond to commands | ||||
// (then the individual units can make up their own minds) | // (then the individual units can make up their own minds) | ||||
▲ Show 20 Lines • Show All 225 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator