Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Attack.js
Show First 20 Lines • Show All 713 Lines • ▼ Show 20 Lines | |||||||||
}; | }; | ||||||||
/** | /** | ||||||||
* @param {number} - The entity ID of the target to check. | * @param {number} - The entity ID of the target to check. | ||||||||
* @return {boolean} - Whether this entity is in range of its target. | * @return {boolean} - Whether this entity is in range of its target. | ||||||||
*/ | */ | ||||||||
Attack.prototype.IsTargetInRange = function(target, type) | Attack.prototype.IsTargetInRange = function(target, type) | ||||||||
{ | { | ||||||||
let range = this.GetRange(type); | const range = this.GetRange(type); | ||||||||
if (type == "Ranged") | return Engine.QueryInterface(SYSTEM_ENTITY, IID_ObstructionManager).IsInTargetParabolicRange( | ||||||||
Stan: Isn't it always >= 0 ? Since you math.maxed it ?
Wonder if we shouldn't have a function for… | |||||||||
Done Inline Actionswe shouldn't do math.max in the first place The only gain of such a cpp function for now is one less ccp/js conversion. Ideally we did be avoiding sqrt's too bb: we shouldn't do math.max in the first place
The only gain of such a cpp function for now is… | |||||||||
{ | this.entity, | ||||||||
let cmpPositionTarget = Engine.QueryInterface(target, IID_Position); | target, | ||||||||
if (!cmpPositionTarget || !cmpPositionTarget.IsInWorld()) | range.min, | ||||||||
return false; | range.max, | ||||||||
range.elevationBonus, | |||||||||
Not Done Inline Actions
Freagarach: | |||||||||
let cmpPositionSelf = Engine.QueryInterface(this.entity, IID_Position); | false); | ||||||||
if (!cmpPositionSelf || !cmpPositionSelf.IsInWorld()) | |||||||||
return false; | |||||||||
let positionSelf = cmpPositionSelf.GetPosition(); | |||||||||
let positionTarget = cmpPositionTarget.GetPosition(); | |||||||||
let heightDifference = positionSelf.y + range.elevationBonus - positionTarget.y; | |||||||||
range.max = Math.sqrt(Math.square(range.max) + 2 * range.max * heightDifference); | |||||||||
if (range.max < 0) | |||||||||
return false; | |||||||||
} | |||||||||
let cmpObstructionManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ObstructionManager); | |||||||||
return cmpObstructionManager.IsInTargetRange(this.entity, target, range.min, range.max, false); | |||||||||
}; | }; | ||||||||
Attack.prototype.OnValueModification = function(msg) | Attack.prototype.OnValueModification = function(msg) | ||||||||
{ | { | ||||||||
if (msg.component != "Attack") | if (msg.component != "Attack") | ||||||||
return; | return; | ||||||||
let cmpUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI); | let cmpUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI); | ||||||||
Show All 27 Lines |
Wildfire Games · Phabricator
Isn't it always >= 0 ? Since you math.maxed it ?
Wonder if we shouldn't have a function for isintargetparabolicrange in c++