Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/helpers/Attacking.js
Show First 20 Lines • Show All 297 Lines • ▼ Show 20 Lines | |||||
* @param {Vector2D} origin - The point to check around. | * @param {Vector2D} origin - The point to check around. | ||||
* @param {number} radius - The radius around the point to check. | * @param {number} radius - The radius around the point to check. | ||||
* @param {number[]} players - The players of which we need to check entities. | * @param {number[]} players - The players of which we need to check entities. | ||||
* @return {number[]} The id's of the entities in range of the given point. | * @return {number[]} The id's of the entities in range of the given point. | ||||
*/ | */ | ||||
Attacking.prototype.EntitiesNearPoint = function(origin, radius, players) | Attacking.prototype.EntitiesNearPoint = function(origin, radius, players) | ||||
{ | { | ||||
// If there is insufficient data return an empty array. | // If there is insufficient data return an empty array. | ||||
if (!origin || !radius || !players) | if (!origin || !radius || !players || !players.length) | ||||
return []; | return []; | ||||
let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | ||||
// Return all entities, except for Gaia: IID_Health is required to avoid returning trees and such. | // Return all entities, except for Gaia: IID_Health is required to avoid returning trees and such. | ||||
let gaiaEntities = []; | let gaiaEntities = []; | ||||
let gaiaIndex = players.indexOf(0); | let gaiaIndex = players.indexOf(0); | ||||
if (gaiaIndex !== -1) | if (gaiaIndex !== -1) | ||||
{ | |||||
Silier: remove change | |||||
// splice() modifies players in-place and returns [0] | // splice() modifies players in-place and returns [0] | ||||
gaiaEntities = gaiaEntities.concat(cmpRangeManager.ExecuteQueryAroundPos(origin, 0, radius, players.splice(gaiaIndex, 1), IID_Health)); | gaiaEntities = gaiaEntities.concat(cmpRangeManager.ExecuteQueryAroundPos(origin, 0, radius, players.splice(gaiaIndex, 1), IID_Health)); | ||||
if (!players.length) | |||||
return gaiaEntities; | |||||
} | |||||
return cmpRangeManager.ExecuteQueryAroundPos(origin, 0, radius, players, 0).concat(gaiaEntities); | return cmpRangeManager.ExecuteQueryAroundPos(origin, 0, radius, players, 0).concat(gaiaEntities); | ||||
Done Inline Actionsthis line needs to be guarded against players.length. Silier: this line needs to be guarded against players.length. | |||||
}; | }; | ||||
/** | /** | ||||
* Called when a unit kills something (another unit, building, animal etc). | * Called when a unit kills something (another unit, building, animal etc). | ||||
* @param {number} attacker - The entity id of the killer. | * @param {number} attacker - The entity id of the killer. | ||||
* @param {number} target - The entity id of the target. | * @param {number} target - The entity id of the target. | ||||
* @param {number} attackerOwner - The player id of the attacker. | * @param {number} attackerOwner - The player id of the attacker. | ||||
*/ | */ | ||||
Show All 22 Lines |
Wildfire Games · Phabricator
remove change