Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 1,790 Lines • ▼ Show 20 Lines | "COMBAT": { | ||||
// Go to the last known position and try to find enemies there. | // Go to the last known position and try to find enemies there. | ||||
let lastPos = this.order.data.lastPos; | let lastPos = this.order.data.lastPos; | ||||
this.PushOrder("Walk", { "x": lastPos.x, "z": lastPos.z, "force": false }); | this.PushOrder("Walk", { "x": lastPos.x, "z": lastPos.z, "force": false }); | ||||
this.PushOrder("WalkAndFight", { "x": lastPos.x, "z": lastPos.z, "force": false }); | this.PushOrder("WalkAndFight", { "x": lastPos.x, "z": lastPos.z, "force": false }); | ||||
return; | return; | ||||
} | } | ||||
if (!this.CheckTargetAttackRange(this.order.data.target, this.order.data.attackType)) | if (!this.CheckTargetAttackRange(this.order.data.target, this.order.data.attackType)) | ||||
{ | |||||
// Try moving again, | |||||
// attack range uses a height-related formula and our actual max range might have changed. | |||||
if (!this.MoveToTargetAttackRange(this.order.data.target, this.order.data.attackType)) | |||||
wraitii: For sanity I should check and if false call finish order here. | |||||
this.FinishOrder(); | |||||
return; | return; | ||||
} | |||||
// 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; | ||||
} | } | ||||
this.SetNextState("ATTACKING"); | this.SetNextState("ATTACKING"); | ||||
▲ Show 20 Lines • Show All 2,434 Lines • ▼ Show 20 Lines | UnitAI.prototype.MoveToTargetAttackRange = function(target, type) | ||||
var guessedMaxRange = (range.max + parabolicMaxRange)/2; | var guessedMaxRange = (range.max + parabolicMaxRange)/2; | ||||
var cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); | var cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); | ||||
if (cmpUnitMotion.MoveToTargetRange(target, range.min, guessedMaxRange)) | if (cmpUnitMotion.MoveToTargetRange(target, range.min, guessedMaxRange)) | ||||
return true; | return true; | ||||
// if that failed, try closer | // if that failed, try closer | ||||
return cmpUnitMotion.MoveToTargetRange(target, range.min, Math.min(range.max, parabolicMaxRange)); | return cmpUnitMotion.MoveToTargetRange(target, range.min, Math.min(range.max, parabolicMaxRange)); | ||||
}; | }; | ||||
Done Inline ActionsWill remove the Math.Min and keep guessedMaxRange before committing. wraitii: Will remove the Math.Min and keep guessedMaxRange before committing. | |||||
UnitAI.prototype.MoveToTargetRangeExplicit = function(target, min, max) | UnitAI.prototype.MoveToTargetRangeExplicit = function(target, min, max) | ||||
{ | { | ||||
if (!this.CheckTargetVisible(target)) | if (!this.CheckTargetVisible(target)) | ||||
return false; | return false; | ||||
var cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); | var cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); | ||||
return cmpUnitMotion.MoveToTargetRange(target, min, max); | return cmpUnitMotion.MoveToTargetRange(target, min, max); | ||||
▲ Show 20 Lines • Show All 1,683 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
For sanity I should check and if false call finish order here.