Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/Formation.js
Show First 20 Lines • Show All 853 Lines • ▼ Show 20 Lines | Formation.prototype.GetRealOffsetPositions = function(offsets, pos) | ||||
// Calculate the world positions. | // Calculate the world positions. | ||||
for (let o of offsets) | for (let o of offsets) | ||||
offsetPositions.push(new Vector2D(pos.x + o.y * sin + o.x * cos, pos.y + o.y * cos - o.x * sin)); | offsetPositions.push(new Vector2D(pos.x + o.y * sin + o.x * cos, pos.y + o.y * cos - o.x * sin)); | ||||
return offsetPositions; | return offsetPositions; | ||||
}; | }; | ||||
/** | /** | ||||
* Calculate the estimated rotation of the formation | * Calculate the estimated rotation of the formation based on the current rotation. | ||||
* based on the first unitAI target position when ordered to walk, | |||||
* based on the current rotation in other cases. | |||||
* Return the sine and cosine of the angle. | * Return the sine and cosine of the angle. | ||||
*/ | */ | ||||
Formation.prototype.GetEstimatedOrientation = function(pos) | Formation.prototype.GetEstimatedOrientation = function(pos) | ||||
{ | { | ||||
let cmpUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI); | let r = {}; | ||||
let r = { "sin": 0, "cos": 1 }; | |||||
let unitAIState = cmpUnitAI.GetCurrentState(); | |||||
if (unitAIState == "FORMATIONCONTROLLER.WALKING" || unitAIState == "FORMATIONCONTROLLER.COMBAT.APPROACHING") | |||||
{ | |||||
let targetPos = cmpUnitAI.GetTargetPositions(); | |||||
if (!targetPos.length) | |||||
return r; | |||||
let d = targetPos[0].sub(pos).normalize(); | |||||
if (!d.x && !d.y) | |||||
return r; | |||||
r.cos = d.y; | |||||
r.sin = d.x; | |||||
} | |||||
else | |||||
{ | |||||
let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | ||||
if (!cmpPosition) | if (!cmpPosition) | ||||
return r; | return r; | ||||
let rot = cmpPosition.GetRotation().y; | let rot = cmpPosition.GetRotation().y; | ||||
r.sin = Math.sin(rot); | r.sin = Math.sin(rot); | ||||
r.cos = Math.cos(rot); | r.cos = Math.cos(rot); | ||||
} | |||||
return r; | return r; | ||||
}; | }; | ||||
/** | /** | ||||
* 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() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 161 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator