Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Formation.js
Show First 20 Lines • Show All 895 Lines • ▼ Show 20 Lines | Formation.prototype.DoesAngleDifferenceAllowTurning = function(a1, a2) | ||||
return d < this.maxTurningAngle || d > 2 * Math.PI - this.maxTurningAngle; | return d < this.maxTurningAngle || d > 2 * Math.PI - this.maxTurningAngle; | ||||
}; | }; | ||||
/** | /** | ||||
* 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() | ||||
{ | { | ||||
if (!this.members.length) | |||||
return; | |||||
let minSpeed = Infinity; | let minSpeed = Infinity; | ||||
let minAcceleration = Infinity; | let minAcceleration = Infinity; | ||||
let maxClearance = 0; | let maxClearance = 0; | ||||
let maxPassClass; | let maxPassClass = "default"; | ||||
Freagarach: For when we do have members, but they don't have UnitMotion. (Meaning we silently fail then, so… | |||||
const cmpPathfinder = Engine.QueryInterface(SYSTEM_ENTITY, IID_Pathfinder); | const cmpPathfinder = Engine.QueryInterface(SYSTEM_ENTITY, IID_Pathfinder); | ||||
for (let ent of this.members) | for (let ent of this.members) | ||||
{ | { | ||||
const cmpUnitMotion = Engine.QueryInterface(ent, IID_UnitMotion); | const cmpUnitMotion = Engine.QueryInterface(ent, IID_UnitMotion); | ||||
if (!cmpUnitMotion) | if (!cmpUnitMotion) | ||||
continue; | continue; | ||||
minSpeed = Math.min(minSpeed, cmpUnitMotion.GetWalkSpeed()); | minSpeed = Math.min(minSpeed, cmpUnitMotion.GetWalkSpeed()); | ||||
Show All 19 Lines | |||||
{ | { | ||||
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 | ||||
// the formations could collide. | // the formations could collide. | ||||
for (let i = this.twinFormations.length - 1; i >= 0; --i) | for (let i = this.twinFormations.length - 1; i >= 0; --i) | ||||
{ | { | ||||
// Only do the check on one side. | // Only do the check on one side. | ||||
Not Done Inline ActionsThe behaviour @Langbart describes might have to do with this. (The entity which would do the shape update already standing idle.) Freagarach: The behaviour @Langbart describes might have to do with this. (The entity which would do the… | |||||
if (this.twinFormations[i] <= this.entity) | if (this.twinFormations[i] <= this.entity) | ||||
continue; | continue; | ||||
let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | ||||
let cmpOtherPosition = Engine.QueryInterface(this.twinFormations[i], IID_Position); | let cmpOtherPosition = Engine.QueryInterface(this.twinFormations[i], IID_Position); | ||||
let cmpOtherFormation = Engine.QueryInterface(this.twinFormations[i], IID_Formation); | let cmpOtherFormation = Engine.QueryInterface(this.twinFormations[i], IID_Formation); | ||||
if (!cmpPosition || !cmpOtherPosition || !cmpOtherFormation || | if (!cmpPosition || !cmpOtherPosition || !cmpOtherFormation || | ||||
!cmpPosition.IsInWorld() || !cmpOtherPosition.IsInWorld()) | !cmpPosition.IsInWorld() || !cmpOtherPosition.IsInWorld()) | ||||
Done Inline ActionsWe move out of world below to trigger this. Freagarach: We move out of world below to trigger this. | |||||
continue; | continue; | ||||
let thisPosition = cmpPosition.GetPosition2D(); | let thisPosition = cmpPosition.GetPosition2D(); | ||||
let otherPosition = cmpOtherPosition.GetPosition2D(); | let otherPosition = cmpOtherPosition.GetPosition2D(); | ||||
let dx = thisPosition.x - otherPosition.x; | let dx = thisPosition.x - otherPosition.x; | ||||
let dy = thisPosition.y - otherPosition.y; | let dy = thisPosition.y - otherPosition.y; | ||||
let dist = Math.sqrt(dx * dx + dy * dy); | let dist = Math.sqrt(dx * dx + dy * dy); | ||||
▲ Show 20 Lines • Show All 102 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
For when we do have members, but they don't have UnitMotion. (Meaning we silently fail then, so I'm not sure we should default to this.)