Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Formation.js
Show First 20 Lines • Show All 288 Lines • ▼ Show 20 Lines | Formation.prototype.SetMembers = function(ents) | ||||
{ | { | ||||
var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | ||||
cmpUnitAI.SetFormationController(this.entity); | cmpUnitAI.SetFormationController(this.entity); | ||||
var cmpAuras = Engine.QueryInterface(ent, IID_Auras); | var 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.ApplyFormationAura(ents); | ||||
} | } | ||||
} | } | ||||
this.offsets = undefined; | this.offsets = undefined; | ||||
// Locate this formation controller in the middle of its members | // Locate this formation controller in the middle of its members | ||||
this.MoveToMembersCenter(); | this.MoveToMembersCenter(); | ||||
// Compute the speed etc. of the formation | // Compute the speed etc. of the formation | ||||
Show All 15 Lines | for (var ent of ents) | ||||
var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | ||||
cmpUnitAI.UpdateWorkOrders(); | cmpUnitAI.UpdateWorkOrders(); | ||||
cmpUnitAI.SetFormationController(INVALID_ENTITY); | cmpUnitAI.SetFormationController(INVALID_ENTITY); | ||||
} | } | ||||
for (var ent of this.formationMembersWithAura) | for (var ent of this.formationMembersWithAura) | ||||
{ | { | ||||
var cmpAuras = Engine.QueryInterface(ent, IID_Auras); | var cmpAuras = Engine.QueryInterface(ent, IID_Auras); | ||||
cmpAuras.RemoveFormationBonus(ents); | cmpAuras.RemoveFormationAura(ents); | ||||
// the unit with the aura is also removed from the formation | // the unit with the aura is also removed from the formation | ||||
if (ents.indexOf(ent) !== -1) | if (ents.indexOf(ent) !== -1) | ||||
cmpAuras.RemoveFormationBonus(this.members); | cmpAuras.RemoveFormationAura(this.members); | ||||
} | } | ||||
this.formationMembersWithAura = this.formationMembersWithAura.filter(function(e) { return ents.indexOf(e) == -1; }); | this.formationMembersWithAura = this.formationMembersWithAura.filter(function(e) { return ents.indexOf(e) == -1; }); | ||||
// If there's nobody left, destroy the formation | // If there's nobody left, destroy the formation | ||||
if (this.members.length == 0) | if (this.members.length == 0) | ||||
{ | { | ||||
Engine.DestroyEntity(this.entity); | Engine.DestroyEntity(this.entity); | ||||
Show All 12 Lines | |||||
Formation.prototype.AddMembers = function(ents) | Formation.prototype.AddMembers = function(ents) | ||||
{ | { | ||||
this.offsets = undefined; | this.offsets = undefined; | ||||
this.inPosition = []; | this.inPosition = []; | ||||
for (let ent of this.formationMembersWithAura) | for (let ent of this.formationMembersWithAura) | ||||
{ | { | ||||
let cmpAuras = Engine.QueryInterface(ent, IID_Auras); | let cmpAuras = Engine.QueryInterface(ent, IID_Auras); | ||||
cmpAuras.ApplyFormationBonus(ents); | cmpAuras.ApplyFormationAura(ents); | ||||
} | } | ||||
this.members = this.members.concat(ents); | this.members = this.members.concat(ents); | ||||
for (let ent of ents) | for (let ent of ents) | ||||
{ | { | ||||
let cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | let cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | ||||
cmpUnitAI.SetFormationController(this.entity); | cmpUnitAI.SetFormationController(this.entity); | ||||
let 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(this.members); | cmpAuras.ApplyFormationAura(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 All 23 Lines | Formation.prototype.Disband = function() | ||||
{ | { | ||||
var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | ||||
cmpUnitAI.SetFormationController(INVALID_ENTITY); | cmpUnitAI.SetFormationController(INVALID_ENTITY); | ||||
} | } | ||||
for (var ent of this.formationMembersWithAura) | for (var ent of this.formationMembersWithAura) | ||||
{ | { | ||||
var cmpAuras = Engine.QueryInterface(ent, IID_Auras); | var cmpAuras = Engine.QueryInterface(ent, IID_Auras); | ||||
cmpAuras.RemoveFormationBonus(this.members); | cmpAuras.RemoveFormationAura(this.members); | ||||
} | } | ||||
this.members = []; | this.members = []; | ||||
this.inPosition = []; | this.inPosition = []; | ||||
this.formationMembersWithAura = []; | this.formationMembersWithAura = []; | ||||
this.offsets = undefined; | this.offsets = undefined; | ||||
▲ Show 20 Lines • Show All 571 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator