Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/Formation.js
Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | Formation.prototype.variablesToSerialize = [ | ||||
"maxRowsUsed", | "maxRowsUsed", | ||||
"maxColumnsUsed", | "maxColumnsUsed", | ||||
"waitingOnController", | "waitingOnController", | ||||
"columnar", | "columnar", | ||||
"rearrange", | "rearrange", | ||||
"formationMembersWithAura", | "formationMembersWithAura", | ||||
"width", | "width", | ||||
"depth", | "depth", | ||||
"oldOrientation", | |||||
"twinFormations", | "twinFormations", | ||||
"formationSeparation", | "formationSeparation", | ||||
"offsets" | "offsets" | ||||
]; | ]; | ||||
Formation.prototype.Init = function(deserialized = false) | Formation.prototype.Init = function(deserialized = false) | ||||
{ | { | ||||
this.sortingClasses = this.template.SortingClasses.split(/\s+/g); | this.sortingClasses = this.template.SortingClasses.split(/\s+/g); | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | Formation.prototype.Init = function(deserialized = false) | ||||
// Whether we're travelling in column (vs box) formation. | // Whether we're travelling in column (vs box) formation. | ||||
this.columnar = false; | this.columnar = false; | ||||
// Whether we should rearrange all formation members. | // Whether we should rearrange all formation members. | ||||
this.rearrange = true; | this.rearrange = true; | ||||
// Members with a formation aura. | // Members with a formation aura. | ||||
this.formationMembersWithAura = []; | this.formationMembersWithAura = []; | ||||
this.width = 0; | this.width = 0; | ||||
this.depth = 0; | this.depth = 0; | ||||
this.oldOrientation = { "sin": 0, "cos": 0 }; | |||||
this.twinFormations = []; | this.twinFormations = []; | ||||
// Distance from which two twin formations will merge into one. | // Distance from which two twin formations will merge into one. | ||||
this.formationSeparation = 0; | this.formationSeparation = 0; | ||||
if (deserialized) | if (deserialized) | ||||
return; | return; | ||||
Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer) | Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer) | ||||
▲ Show 20 Lines • Show All 352 Lines • ▼ Show 20 Lines | Formation.prototype.MoveMembersIntoFormation = function(moveCenter, force, variant) | ||||
if (columnar != this.columnar) | if (columnar != this.columnar) | ||||
{ | { | ||||
this.columnar = columnar; | this.columnar = columnar; | ||||
this.offsets = undefined; | this.offsets = undefined; | ||||
} | } | ||||
let offsetsChanged = false; | let offsetsChanged = false; | ||||
let newOrientation = this.GetEstimatedOrientation(avgpos); | let newOrientation = this.GetEstimatedOrientation(avgpos); | ||||
let dSin = Math.abs(newOrientation.sin - this.oldOrientation.sin); | if (!this.offsets) | ||||
let dCos = Math.abs(newOrientation.cos - this.oldOrientation.cos); | |||||
// If the formation existed, only recalculate positions if the turning agle is somewhat large. | |||||
if (!this.offsets || dSin > 1 || dCos > 1) | |||||
{ | { | ||||
this.offsets = this.ComputeFormationOffsets(active, positions); | this.offsets = this.ComputeFormationOffsets(active, positions); | ||||
offsetsChanged = true; | offsetsChanged = true; | ||||
} | } | ||||
this.oldOrientation = newOrientation; | |||||
let xMax = 0; | let xMax = 0; | ||||
let yMax = 0; | let yMax = 0; | ||||
let xMin = 0; | let xMin = 0; | ||||
let yMin = 0; | let yMin = 0; | ||||
if (force) | if (force) | ||||
// Reset waitingOnController as FormationWalk is called. | // Reset waitingOnController as FormationWalk is called. | ||||
this.ResetWaitingEntities(); | this.ResetWaitingEntities(); | ||||
▲ Show 20 Lines • Show All 511 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator