Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/Formation.js
Show First 20 Lines • Show All 743 Lines • ▼ Show 20 Lines | Formation.prototype.ComputeFormationOffsets = function(active, positions) | ||||
// calculating offset distances without a zero average makes no sense, as the formation | // calculating offset distances without a zero average makes no sense, as the formation | ||||
// will jump to a different position any time | // will jump to a different position any time | ||||
var avgoffset = Vector2D.average(offsets); | var avgoffset = Vector2D.average(offsets); | ||||
offsets.forEach(function (o) {o.sub(avgoffset);}); | offsets.forEach(function (o) {o.sub(avgoffset);}); | ||||
// sort the available places in certain ways | // sort the available places in certain ways | ||||
// the places first in the list will contain the heaviest units as defined by the order | // the places first in the list will contain the heaviest units as defined by the order | ||||
// of the types list | // of the types list | ||||
if (this.sortingOrder == "fillFromTheSides") | if (sortingOrder == "fillFromTheSides") | ||||
offsets.sort(function(o1, o2) { return Math.abs(o1.x) < Math.abs(o2.x);}); | offsets.sort(function(o1, o2) { return Math.abs(o1.x) < Math.abs(o2.x);}); | ||||
else if (this.sortingOrder == "fillToTheCenter") | else if (sortingOrder == "fillToTheCenter") | ||||
offsets.sort(function(o1, o2) { | offsets.sort(function(o1, o2) { | ||||
return Math.max(Math.abs(o1.x), Math.abs(o1.y)) < Math.max(Math.abs(o2.x), Math.abs(o2.y)); | return Math.max(Math.abs(o1.x), Math.abs(o1.y)) < Math.max(Math.abs(o2.x), Math.abs(o2.y)); | ||||
}); | }); | ||||
// query the 2D position of the formation | // query the 2D position of the formation | ||||
var cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | var cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | ||||
var formationPos = cmpPosition.GetPosition2D(); | var formationPos = cmpPosition.GetPosition2D(); | ||||
▲ Show 20 Lines • Show All 254 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator