Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 1,475 Lines • ▼ Show 20 Lines | "GuardedAttacked": function(msg) { | ||||
if (this.CanHeal(this.isGuardOf)) | if (this.CanHeal(this.isGuardOf)) | ||||
this.PushOrderFront("Heal", { "target": this.isGuardOf, "force": false }); | this.PushOrderFront("Heal", { "target": this.isGuardOf, "force": false }); | ||||
else if (this.CanRepair(this.isGuardOf)) | else if (this.CanRepair(this.isGuardOf)) | ||||
this.PushOrderFront("Repair", { "target": this.isGuardOf, "autocontinue": false, "force": false }); | this.PushOrderFront("Repair", { "target": this.isGuardOf, "autocontinue": false, "force": false }); | ||||
return; | return; | ||||
} | } | ||||
// if the attacker is a building and we can repair the guarded, repair it rather than attacking | // if the attacker is a building and we can repair the guarded, repair it rather than attacking | ||||
var cmpBuildingAI = Engine.QueryInterface(msg.data.attacker, IID_BuildingAI); | // TODO: what's exactly the goal of that (should that apply when the attacker of the guarded unit is | ||||
if (cmpBuildingAI && this.CanRepair(this.isGuardOf)) | // a structure or also a ship or a siege tower?). | ||||
var cmpManpowerHolder = Engine.QueryInterface(msg.data.attacker, IID_ManpowerHolder); | |||||
if (cmpManpowerHolder && this.CanRepair(this.isGuardOf)) | |||||
{ | { | ||||
this.PushOrderFront("Repair", { "target": this.isGuardOf, "autocontinue": false, "force": false }); | this.PushOrderFront("Repair", { "target": this.isGuardOf, "autocontinue": false, "force": false }); | ||||
return; | return; | ||||
} | } | ||||
// target the unit | // target the unit | ||||
if (this.CheckTargetVisible(msg.data.attacker)) | if (this.CheckTargetVisible(msg.data.attacker)) | ||||
this.PushOrderFront("Attack", { "target": msg.data.attacker, "force": false, "allowCapture": true }); | this.PushOrderFront("Attack", { "target": msg.data.attacker, "force": false, "allowCapture": true }); | ||||
▲ Show 20 Lines • Show All 463 Lines • ▼ Show 20 Lines | "COMBAT": { | ||||
this.StartTimer(prepare, this.attackTimers.repeat); | this.StartTimer(prepare, this.attackTimers.repeat); | ||||
// TODO: we should probably only bother syncing projectile attacks, not melee | // TODO: we should probably only bother syncing projectile attacks, not melee | ||||
// 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.attackTimers.prepare) ? true : false; | this.resyncAnimation = (prepare != this.attackTimers.prepare) ? true : false; | ||||
this.FaceTowardsTarget(this.order.data.target); | this.FaceTowardsTarget(this.order.data.target); | ||||
var cmpBuildingAI = Engine.QueryInterface(this.entity, IID_BuildingAI); | var cmpManpowerHolder = Engine.QueryInterface(this.entity, IID_ManpowerHolder); | ||||
if (cmpBuildingAI) | if (cmpManpowerHolder) | ||||
cmpBuildingAI.SetUnitAITarget(this.order.data.target); | cmpManpowerHolder.SetUnitAITarget(this.order.data.target); | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
var cmpBuildingAI = Engine.QueryInterface(this.entity, IID_BuildingAI); | var cmpManpowerHolder = Engine.QueryInterface(this.entity, IID_ManpowerHolder); | ||||
if (cmpBuildingAI) | if (cmpManpowerHolder) | ||||
cmpBuildingAI.SetUnitAITarget(0); | cmpManpowerHolder.SetUnitAITarget(0); | ||||
this.StopTimer(); | this.StopTimer(); | ||||
}, | }, | ||||
"Timer": function(msg) { | "Timer": function(msg) { | ||||
var target = this.order.data.target; | var target = this.order.data.target; | ||||
var cmpFormation = Engine.QueryInterface(target, IID_Formation); | var 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 All 24 Lines | "COMBAT": { | ||||
} | } | ||||
} | } | ||||
var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | ||||
this.lastAttacked = cmpTimer.GetTime() - msg.lateness; | this.lastAttacked = cmpTimer.GetTime() - msg.lateness; | ||||
this.FaceTowardsTarget(target); | this.FaceTowardsTarget(target); | ||||
// BuildingAI has it's own attack-routine | // Let ManpowerHolderUnit handle ranged attack | ||||
var cmpBuildingAI = Engine.QueryInterface(this.entity, IID_BuildingAI); | // TODO: Check what should be done here | ||||
if (!cmpBuildingAI) | var cmpManpowerHolder = Engine.QueryInterface(this.entity, IID_ManpowerHolder); | ||||
if (!cmpManpowerHolder && this.order.data.attackType != "Ranged") | |||||
{ | { | ||||
let cmpAttack = Engine.QueryInterface(this.entity, IID_Attack); | let cmpAttack = Engine.QueryInterface(this.entity, IID_Attack); | ||||
cmpAttack.PerformAttack(this.order.data.attackType, target); | cmpAttack.PerformAttack(this.order.data.attackType, target); | ||||
} | } | ||||
// Check we can still reach the target for the next attack | // Check we can still reach the target for the next attack | ||||
if (this.CheckTargetAttackRange(target, this.order.data.attackType)) | if (this.CheckTargetAttackRange(target, this.order.data.attackType)) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 4,115 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator