Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/Formation.js
Show First 20 Lines • Show All 363 Lines • ▼ Show 20 Lines | Formation.prototype.RemoveMembers = function(ents) | ||||
this.MoveMembersIntoFormation(true, true); | this.MoveMembersIntoFormation(true, true); | ||||
}; | }; | ||||
Formation.prototype.AddMembers = function(ents) | Formation.prototype.AddMembers = function(ents) | ||||
{ | { | ||||
this.offsets = undefined; | this.offsets = undefined; | ||||
this.inPosition = []; | this.inPosition = []; | ||||
for (var ent of this.formationMembersWithAura) | for (let ent of this.formationMembersWithAura) | ||||
{ | { | ||||
var cmpAuras = Engine.QueryInterface(ent, IID_Auras); | let cmpAuras = Engine.QueryInterface(ent, IID_Auras); | ||||
cmpAuras.RemoveFormationBonus(ents); | cmpAuras.ApplyFormationBonus(ents); | ||||
// the unit with the aura is also removed from the formation | |||||
if (ents.indexOf(ent) !== -1) | |||||
cmpAuras.RemoveFormationBonus(this.members); | |||||
} | } | ||||
this.members = this.members.concat(ents); | this.members = this.members.concat(ents); | ||||
for (var ent of this.members) | for (let ent of ents) | ||||
{ | { | ||||
var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | let cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | ||||
cmpUnitAI.SetFormationController(this.entity); | cmpUnitAI.SetFormationController(this.entity); | ||||
var cmpAuras = Engine.QueryInterface(ent, IID_Auras); | let cmpAuras = Engine.QueryInterface(ent, IID_Auras); | ||||
if (cmpAuras && cmpAuras.HasFormationAura()) | if (cmpAuras && cmpAuras.HasFormationAura()) | ||||
{ | { | ||||
this.formationMembersWithAura.push(ent); | this.formationMembersWithAura.push(ent); | ||||
cmpAuras.ApplyFormationBonus(ents); | cmpAuras.ApplyFormationBonus(this.members); | ||||
} | } | ||||
} | } | ||||
this.MoveMembersIntoFormation(true, true); | this.MoveMembersIntoFormation(true, true); | ||||
}; | }; | ||||
/** | /** | ||||
* Called when the formation stops moving in order to detect | * Called when the formation stops moving in order to detect | ||||
▲ Show 20 Lines • Show All 495 Lines • ▼ Show 20 Lines | var minDist = Math.max(thisSize.width / 2, thisSize.depth / 2) + | ||||
Math.max(otherSize.width / 2, otherSize.depth / 2) + | Math.max(otherSize.width / 2, otherSize.depth / 2) + | ||||
this.formationSeparation; | this.formationSeparation; | ||||
if (minDist < dist) | if (minDist < dist) | ||||
continue; | continue; | ||||
// merge the members from the twin formation into this one | // merge the members from the twin formation into this one | ||||
// twin formations should always have exactly the same orders | // twin formations should always have exactly the same orders | ||||
this.AddMembers(cmpOtherFormation.members); | let otherMembers = cmpOtherFormation.members; | ||||
cmpOtherFormation.RemoveMembers(otherMembers); | |||||
this.AddMembers(otherMembers); | |||||
Engine.DestroyEntity(this.twinFormations[i]); | Engine.DestroyEntity(this.twinFormations[i]); | ||||
this.twinFormations.splice(i,1); | this.twinFormations.splice(i,1); | ||||
} | } | ||||
// Switch between column and box if necessary | // Switch between column and box if necessary | ||||
var cmpUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI); | var cmpUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI); | ||||
var walkingDistance = cmpUnitAI.ComputeWalkingDistance(); | var walkingDistance = cmpUnitAI.ComputeWalkingDistance(); | ||||
var columnar = walkingDistance > g_ColumnDistanceThreshold; | var columnar = walkingDistance > g_ColumnDistanceThreshold; | ||||
if (columnar != this.columnar) | if (columnar != this.columnar) | ||||
▲ Show 20 Lines • Show All 97 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator