Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/Formation.js
function Formation() {} | function Formation() {} | ||||
Formation.prototype.Schema = | Formation.prototype.Schema = | ||||
"<element name='FormationName' a:help='Name of the formation'>" + | "<element name='FormationName' a:help='Name of the formation'>" + | ||||
"<text/>" + | "<text/>" + | ||||
"</element>" + | "</element>" + | ||||
"<element name='Icon'>" + | "<element name='Icon'>" + | ||||
"<text/>" + | "<text/>" + | ||||
"</element>" + | "</element>" + | ||||
"<element name='RequiredMemberCount' a:help='Minimum number of entities the formation should contain'>" + | "<element name='RequiredMemberCount' a:help='Minimum number of entities the formation should contain (at least 2)'>" + | ||||
"<data type='nonNegativeInteger'/>" + | "<data type='integer'>" + | ||||
"<param name='minInclusive'>"+ | |||||
"2"+ | |||||
"</param>"+ | |||||
"</data>" + | |||||
"</element>" + | "</element>" + | ||||
"<element name='DisabledTooltip' a:help='Tooltip shown when the formation is disabled'>" + | "<element name='DisabledTooltip' a:help='Tooltip shown when the formation is disabled'>" + | ||||
"<text/>" + | "<text/>" + | ||||
"</element>" + | "</element>" + | ||||
"<element name='SpeedMultiplier' a:help='The speed of the formation is determined by the minimum speed of all members, multiplied with this number.'>" + | "<element name='SpeedMultiplier' a:help='The speed of the formation is determined by the minimum speed of all members, multiplied with this number.'>" + | ||||
"<ref name='nonNegativeDecimal'/>" + | "<ref name='nonNegativeDecimal'/>" + | ||||
"</element>" + | "</element>" + | ||||
"<element name='FormationShape' a:help='Formation shape, currently supported are square, triangle and special, where special will be defined in the source code.'>" + | "<element name='FormationShape' a:help='Formation shape, currently supported are square, triangle and special, where special will be defined in the source code.'>" + | ||||
▲ Show 20 Lines • Show All 294 Lines • ▼ Show 20 Lines | * @param {boolean} rename - Whether the removal was part of an entity rename | ||||
(prevents disbanding of the formation when under the member limit). | (prevents disbanding of the formation when under the member limit). | ||||
*/ | */ | ||||
Formation.prototype.RemoveMembers = function(ents, renamed = false) | Formation.prototype.RemoveMembers = function(ents, renamed = false) | ||||
{ | { | ||||
this.offsets = undefined; | this.offsets = undefined; | ||||
this.members = this.members.filter(function(e) { return ents.indexOf(e) == -1; }); | this.members = this.members.filter(function(e) { return ents.indexOf(e) == -1; }); | ||||
this.inPosition = this.inPosition.filter(function(e) { return ents.indexOf(e) == -1; }); | this.inPosition = this.inPosition.filter(function(e) { return ents.indexOf(e) == -1; }); | ||||
for (var ent of ents) | for (let ent of ents) | ||||
{ | { | ||||
var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | let 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 (let ent of this.formationMembersWithAura) | ||||
{ | { | ||||
var cmpAuras = Engine.QueryInterface(ent, IID_Auras); | let cmpAuras = Engine.QueryInterface(ent, IID_Auras); | ||||
cmpAuras.RemoveFormationAura(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.RemoveFormationAura(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 | ||||
// unless this is a rename where we can have 0 members temporarily. | // unless this is a rename where we can have 0 members temporarily. | ||||
if (this.members.length == 0 && !renamed) | if (this.members.length < +this.template.RequiredMemberCount && !renamed) | ||||
{ | { | ||||
Engine.DestroyEntity(this.entity); | Engine.DestroyEntity(this.entity); | ||||
return; | return; | ||||
} | } | ||||
this.ComputeMotionParameters(); | this.ComputeMotionParameters(); | ||||
if (!this.rearrange) | if (!this.rearrange) | ||||
▲ Show 20 Lines • Show All 661 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator