Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 4,706 Lines • ▼ Show 20 Lines | if (cmpFormation) | ||||
target = cmpFormation.GetClosestMember(this.entity); | target = cmpFormation.GetClosestMember(this.entity); | ||||
if (type != "Ranged") | if (type != "Ranged") | ||||
return this.MoveToTargetRange(target, IID_Attack, type); | return this.MoveToTargetRange(target, IID_Attack, type); | ||||
if (!this.CheckTargetVisible(target)) | if (!this.CheckTargetVisible(target)) | ||||
return false; | return false; | ||||
let range = this.GetRange(IID_Attack, type, target); | const cmpAttack = Engine.QueryInterface(this.entity, IID_Attack); | ||||
if (!range) | if (!cmpAttack) | ||||
return false; | return false; | ||||
const range = cmpAttack.GetRange(type); | |||||
let thisCmpPosition = Engine.QueryInterface(this.entity, IID_Position); | let thisCmpPosition = Engine.QueryInterface(this.entity, IID_Position); | ||||
if (!thisCmpPosition.IsInWorld()) | if (!thisCmpPosition.IsInWorld()) | ||||
return false; | return false; | ||||
let s = thisCmpPosition.GetPosition(); | let s = thisCmpPosition.GetPosition(); | ||||
let targetCmpPosition = Engine.QueryInterface(target, IID_Position); | let targetCmpPosition = Engine.QueryInterface(target, IID_Position); | ||||
if (!targetCmpPosition || !targetCmpPosition.IsInWorld()) | if (!targetCmpPosition || !targetCmpPosition.IsInWorld()) | ||||
return false; | return false; | ||||
// Parabolic range compuation is the same as in BuildingAI's FireArrows. | // Parabolic range compuation is the same as in BuildingAI's FireArrows. | ||||
let t = targetCmpPosition.GetPosition(); | let t = targetCmpPosition.GetPosition(); | ||||
// h is positive when I'm higher than the target | // h is positive when I'm higher than the target | ||||
let h = s.y - t.y + range.elevationBonus; | const h = s.y - t.y + cmpAttack.GetAttackYOrigin(type); | ||||
let parabolicMaxRange = Math.sqrt(Math.square(range.max) + 2 * range.max * h); | let parabolicMaxRange = Math.sqrt(Math.square(range.max) + 2 * range.max * h); | ||||
// No negative roots please | // No negative roots please | ||||
if (h <= -range.max / 2) | if (h <= -range.max / 2) | ||||
// return false? Or hope you come close enough? | // return false? Or hope you come close enough? | ||||
parabolicMaxRange = 0; | parabolicMaxRange = 0; | ||||
// The parabole changes while walking so be cautious: | // The parabole changes while walking so be cautious: | ||||
▲ Show 20 Lines • Show All 1,475 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* General getter for ranges. | * General getter for ranges. | ||||
* | * | ||||
* @param {number} iid | * @param {number} iid | ||||
* @param {number} target - [Optional] | * @param {number} target - [Optional] | ||||
* @param {string} type - [Optional] | * @param {string} type - [Optional] | ||||
* @return {Object | undefined} - The range in the form | * @return {Object | undefined} - The range in the form | ||||
* { "min": number, "max": number } | * { "min": number, "max": number } | ||||
* Object."elevationBonus": number may be present when iid == IID_Attack. | |||||
* Returns undefined when the entity does not have the requested component. | * Returns undefined when the entity does not have the requested component. | ||||
*/ | */ | ||||
UnitAI.prototype.GetRange = function(iid, type, target) | UnitAI.prototype.GetRange = function(iid, type, target) | ||||
{ | { | ||||
let component = Engine.QueryInterface(this.entity, iid); | let component = Engine.QueryInterface(this.entity, iid); | ||||
if (!component) | if (!component) | ||||
return undefined; | return undefined; | ||||
▲ Show 20 Lines • Show All 286 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator