Use transform for changing a formation template.
As noted on the forums by @Ceres (https://wildfiregames.com/forum/topic/44848-proposals-for-formations/?do=findComment&comment=453840) formations change orientation when changing their template. This uses the transform helper to change the template of the formation, which apparently also fixes the rotation issue. With the notion that a different design of transform is preferential (P46). Differential revision: https://code.wildfiregames.com/D4272 Comments by: @Angen, @bb, @Ceres, @wraitii Tested by: @Ceres This was SVN commit r25949.
This commit is contained in:
parent
7670a1835b
commit
56f5cb9e62
@ -1020,38 +1020,16 @@ Formation.prototype.DeleteTwinFormations = function()
|
|||||||
|
|
||||||
Formation.prototype.LoadFormation = function(newTemplate)
|
Formation.prototype.LoadFormation = function(newTemplate)
|
||||||
{
|
{
|
||||||
// Get the old formation info.
|
const newFormation = ChangeEntityTemplate(this.entity, newTemplate);
|
||||||
let members = this.members.slice();
|
return Engine.QueryInterface(newFormation, IID_UnitAI);
|
||||||
let cmpThisUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI);
|
};
|
||||||
let orders = cmpThisUnitAI.GetOrders().slice();
|
|
||||||
|
|
||||||
|
|
||||||
|
Formation.prototype.OnEntityRenamed = function(msg)
|
||||||
|
{
|
||||||
|
const members = clone(this.members);
|
||||||
this.Disband();
|
this.Disband();
|
||||||
|
Engine.QueryInterface(msg.newentity, IID_Formation).SetMembers(members);
|
||||||
let newFormation = Engine.AddEntity(newTemplate);
|
|
||||||
|
|
||||||
// Apply the info from the old formation to the new one.
|
|
||||||
|
|
||||||
let cmpNewOwnership = Engine.QueryInterface(newFormation, IID_Ownership);
|
|
||||||
let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
|
|
||||||
if (cmpOwnership && cmpNewOwnership)
|
|
||||||
cmpNewOwnership.SetOwner(cmpOwnership.GetOwner());
|
|
||||||
|
|
||||||
let cmpNewPosition = Engine.QueryInterface(newFormation, IID_Position);
|
|
||||||
let cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
|
|
||||||
if (cmpPosition && cmpPosition.IsInWorld() && cmpNewPosition)
|
|
||||||
cmpNewPosition.TurnTo(cmpPosition.GetRotation().y);
|
|
||||||
|
|
||||||
let cmpFormation = Engine.QueryInterface(newFormation, IID_Formation);
|
|
||||||
let cmpNewUnitAI = Engine.QueryInterface(newFormation, IID_UnitAI);
|
|
||||||
cmpFormation.SetMembers(members);
|
|
||||||
if (orders.length)
|
|
||||||
cmpNewUnitAI.AddOrders(orders);
|
|
||||||
else
|
|
||||||
cmpNewUnitAI.MoveIntoFormation();
|
|
||||||
|
|
||||||
Engine.PostMessage(this.entity, MT_EntityRenamed, { "entity": this.entity, "newentity": newFormation });
|
|
||||||
|
|
||||||
return cmpNewUnitAI;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Engine.RegisterComponentType(IID_Formation, "Formation", Formation);
|
Engine.RegisterComponentType(IID_Formation, "Formation", Formation);
|
||||||
|
Loading…
Reference in New Issue
Block a user