Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 4,722 Lines • ▼ Show 20 Lines | UnitAI.prototype.MoveToTargetAttackRange = function(target, type) | ||||
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 + Engine.QueryInterface(this.entity, IID_Attack).GetAttackYOrigin(); | ||||
Stan: Sucks that we have to query an extra component each time... | |||||
Done Inline ActionsAye,,, Freagarach: Aye,,, | |||||
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,470 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) | ||||
Done Inline ActionsWhat do you need that funcfion for then? Stan: What do you need that funcfion for then? | |||||
Done Inline ActionsFor other, generic, range calls? Freagarach: For other, generic, range calls? | |||||
Done Inline ActionsMaybe we could have an on other version that takes a cmp as param instead of an iid Stan: Maybe we could have an on other version that takes a cmp as param instead of an iid | |||||
{ | { | ||||
let component = Engine.QueryInterface(this.entity, iid); | let component = Engine.QueryInterface(this.entity, iid); | ||||
if (!component) | if (!component) | ||||
return undefined; | return undefined; | ||||
return component.GetRange(type, target); | return component.GetRange(type, target); | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 283 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Sucks that we have to query an extra component each time...