Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/helpers/Position.js
Show First 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | PositionHelper.prototype.PredictTimeToTarget = function(firstPosition, selfSpeed, targetPosition, targetVelocity) | ||||
let disc = b * b - a * c; | let disc = b * b - a * c; | ||||
if (a < 0 || b < 0 && disc >= 0) | if (a < 0 || b < 0 && disc >= 0) | ||||
return c / (Math.sqrt(disc) - b); | return c / (Math.sqrt(disc) - b); | ||||
return false; | return false; | ||||
}; | }; | ||||
/** | |||||
* @param {number} target - EntityID to find the spawn position for. | |||||
* @param {number} entity - EntityID to find the spawn position for. | |||||
* @param {boolean} forced - Optionally whether the spawning is forced. | |||||
* @return {Vector3D} - An appropriate spawning position. | |||||
*/ | |||||
PositionHelper.prototype.GetSpawnPosition = function(target, entity, forced) | |||||
{ | |||||
let cmpFootprint = Engine.QueryInterface(target, IID_Footprint); | |||||
let cmpHealth = Engine.QueryInterface(target, IID_Health); | |||||
let cmpIdentity = Engine.QueryInterface(target, IID_Identity); | |||||
if (!cmpFootprint) | |||||
return null; | |||||
// If the spawner is a sinking ship, restrict the location to the intersection of both passabilities. | |||||
// TODO: should use passability classes to be more generic. | |||||
let pos; | |||||
if ((!cmpHealth || cmpHealth.GetHitpoints() == 0) && cmpIdentity && cmpIdentity.HasClass("Ship")) | |||||
pos = cmpFootprint.PickSpawnPointBothPass(entity); | |||||
else | |||||
pos = cmpFootprint.PickSpawnPoint(entity); | |||||
if (pos.y < 0) | |||||
{ | |||||
if (!forced) | |||||
return null; | |||||
// If ejection is forced, we need to continue, so use center of the entity. | |||||
let cmpPosition = Engine.QueryInterface(target, IID_Position); | |||||
pos = cmpPosition.GetPosition(); | |||||
} | |||||
return pos; | |||||
}; | |||||
Engine.RegisterGlobal("PositionHelper", new PositionHelper()); | Engine.RegisterGlobal("PositionHelper", new PositionHelper()); |
Wildfire Games · Phabricator