Index: binaries/data/mods/public/simulation/components/Formation.js =================================================================== --- binaries/data/mods/public/simulation/components/Formation.js +++ binaries/data/mods/public/simulation/components/Formation.js @@ -378,6 +378,10 @@ } this.ComputeMotionParameters(); + + if (!this.rearrange) + return; + this.MoveMembersIntoFormation(true, true); }; @@ -917,26 +921,18 @@ Formation.prototype.OnGlobalEntityRenamed = function(msg) { - if (this.members.indexOf(msg.entity) != -1) - { - this.offsets = undefined; - var cmpNewUnitAI = Engine.QueryInterface(msg.newentity, IID_UnitAI); - if (cmpNewUnitAI) - { - this.members[this.members.indexOf(msg.entity)] = msg.newentity; - this.memberPositions[msg.newentity] = this.memberPositions[msg.entity]; - } - - var cmpOldUnitAI = Engine.QueryInterface(msg.entity, IID_UnitAI); - cmpOldUnitAI.SetFormationController(INVALID_ENTITY); - - if (cmpNewUnitAI) - cmpNewUnitAI.SetFormationController(this.entity); + if (this.members.indexOf(msg.entity) == -1) + return; - // Because the renamed entity might have different characteristics, - // (e.g. packed vs. unpacked siege), we need to recompute motion parameters - this.ComputeMotionParameters(); - } + // Save rearranging to temporarily set it to false. + let temp = this.rearrange; + this.rearrange = false; + + // First add the new member to prevent disbanding the formation when + // on the member disband limit. + this.AddMembers([msg.newentity]); + this.RemoveMembers([msg.entity]); + this.rearrange = temp; }; Formation.prototype.RegisterTwinFormation = function(entity)