Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/Formation.js
Show First 20 Lines • Show All 897 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Set formation controller's speed based on its current members. | * Set formation controller's speed based on its current members. | ||||
*/ | */ | ||||
Formation.prototype.ComputeMotionParameters = function() | Formation.prototype.ComputeMotionParameters = function() | ||||
{ | { | ||||
let minSpeed = Infinity; | let minSpeed = Infinity; | ||||
let minAcceleration = Infinity; | let minAcceleration = Infinity; | ||||
let maxClearance = 0; | |||||
let maxPassClass; | |||||
const cmpPathfinder = Engine.QueryInterface(SYSTEM_ENTITY, IID_Pathfinder); | |||||
for (let ent of this.members) | for (let ent of this.members) | ||||
{ | { | ||||
let cmpUnitMotion = Engine.QueryInterface(ent, IID_UnitMotion); | const cmpUnitMotion = Engine.QueryInterface(ent, IID_UnitMotion); | ||||
if (cmpUnitMotion) | if (!cmpUnitMotion) | ||||
{ | continue; | ||||
minSpeed = Math.min(minSpeed, cmpUnitMotion.GetWalkSpeed()); | minSpeed = Math.min(minSpeed, cmpUnitMotion.GetWalkSpeed()); | ||||
minAcceleration = Math.min(minAcceleration, cmpUnitMotion.GetAcceleration()); | minAcceleration = Math.min(minAcceleration, cmpUnitMotion.GetAcceleration()); | ||||
const passClass = cmpUnitMotion.GetPassabilityClassName(); | |||||
const clearance = cmpPathfinder.GetClearance(cmpPathfinder.GetPassabilityClass(passClass)); | |||||
if (clearance > maxClearance) | |||||
{ | |||||
maxClearance = clearance; | |||||
maxPassClass = passClass; | |||||
} | } | ||||
} | } | ||||
minSpeed *= this.GetSpeedMultiplier(); | minSpeed *= this.GetSpeedMultiplier(); | ||||
let cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); | const cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); | ||||
cmpUnitMotion.SetSpeedMultiplier(minSpeed / cmpUnitMotion.GetWalkSpeed()); | cmpUnitMotion.SetSpeedMultiplier(minSpeed / cmpUnitMotion.GetWalkSpeed()); | ||||
cmpUnitMotion.SetAcceleration(minAcceleration); | cmpUnitMotion.SetAcceleration(minAcceleration); | ||||
cmpUnitMotion.SetPassabilityClassName(maxPassClass); | |||||
}; | }; | ||||
Formation.prototype.ShapeUpdate = function() | Formation.prototype.ShapeUpdate = function() | ||||
{ | { | ||||
if (!this.rearrange) | if (!this.rearrange) | ||||
return; | return; | ||||
// Check the distance to twin formations, and merge if | // Check the distance to twin formations, and merge if | ||||
▲ Show 20 Lines • Show All 121 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator