Index: binaries/data/mods/public/simulation/components/Garrisonable.js
===================================================================
--- binaries/data/mods/public/simulation/components/Garrisonable.js
+++ binaries/data/mods/public/simulation/components/Garrisonable.js
@@ -152,8 +152,23 @@
let holder = this.holder;
this.UnGarrison(true, true);
let cmpGarrisonable = Engine.QueryInterface(msg.newentity, IID_Garrisonable);
- if (cmpGarrisonable)
- cmpGarrisonable.Garrison(holder, true);
+ if (!cmpGarrisonable || !cmpGarrisonable.Garrison(holder, true))
+ {
+ let cmpPositionSelf = Engine.QueryInterface(this.entity, IID_Position);
+ let cmpPositionNew = Engine.QueryInterface(msg.newentity, IID_Position);
+ if (cmpPositionSelf && cmpPositionNew)
+ {
+ if (cmpPositionSelf.IsInWorld())
+ {
+ let pos = cmpPositionSelf.GetPosition2D();
+ cmpPositionNew.JumpTo(pos.x, pos.y);
+ }
+ let rot = cmpPositionSelf.GetRotation();
+ cmpPositionNew.SetYRotation(rot.y);
+ cmpPositionNew.SetXZRotation(rot.x, rot.z);
+ cmpPositionNew.SetHeightOffset(cmpPositionSelf.GetHeightOffset());
+ }
+ }
};
Engine.RegisterComponentType(IID_Garrisonable, "Garrisonable", Garrisonable);
Index: binaries/data/mods/public/simulation/components/Turretable.js
===================================================================
--- binaries/data/mods/public/simulation/components/Turretable.js
+++ binaries/data/mods/public/simulation/components/Turretable.js
@@ -147,8 +147,23 @@
let currentPoint = cmpTurretHolder.GetOccupiedTurretName(this.entity);
this.LeaveTurret(true);
let cmpTurretableNew = Engine.QueryInterface(msg.newentity, IID_Turretable);
- if (cmpTurretableNew)
- cmpTurretableNew.OccupyTurret(holder, currentPoint);
+ if (!cmpTurretableNew || !cmpTurretableNew.OccupyTurret(holder, currentPoint))
+ {
+ let cmpPositionSelf = Engine.QueryInterface(this.entity, IID_Position);
+ let cmpPositionNew = Engine.QueryInterface(msg.newentity, IID_Position);
+ if (cmpPositionSelf && cmpPositionNew)
+ {
+ if (cmpPositionSelf.IsInWorld())
+ {
+ let pos = cmpPositionSelf.GetPosition2D();
+ cmpPositionNew.JumpTo(pos.x, pos.y);
+ }
+ let rot = cmpPositionSelf.GetRotation();
+ cmpPositionNew.SetYRotation(rot.y);
+ cmpPositionNew.SetXZRotation(rot.x, rot.z);
+ cmpPositionNew.SetHeightOffset(cmpPositionSelf.GetHeightOffset());
+ }
+ }
};
Turretable.prototype.OnOwnershipChanged = function(msg)
Index: binaries/data/mods/public/simulation/helpers/Transform.js
===================================================================
--- binaries/data/mods/public/simulation/helpers/Transform.js
+++ binaries/data/mods/public/simulation/helpers/Transform.js
@@ -58,30 +58,6 @@
if (cmpBuilderList && cmpNewBuilderList)
cmpNewBuilderList.AddBuilders(cmpBuilderList.GetBuilders());
- var cmpUnitAI = Engine.QueryInterface(oldEnt, IID_UnitAI);
- var cmpNewUnitAI = Engine.QueryInterface(newEnt, IID_UnitAI);
- if (cmpUnitAI && cmpNewUnitAI)
- {
- let pos = cmpUnitAI.GetHeldPosition();
- if (pos)
- cmpNewUnitAI.SetHeldPosition(pos.x, pos.z);
- if (cmpUnitAI.GetStanceName())
- cmpNewUnitAI.SwitchToStance(cmpUnitAI.GetStanceName());
- if (cmpUnitAI.GetGarrisonHolder() != INVALID_ENTITY)
- cmpNewUnitAI.SetGarrisoned();
- cmpNewUnitAI.AddOrders(cmpUnitAI.GetOrders());
- if (cmpUnitAI.IsGuardOf())
- {
- let guarded = cmpUnitAI.IsGuardOf();
- let cmpGuard = Engine.QueryInterface(guarded, IID_Guard);
- if (cmpGuard)
- {
- cmpGuard.RenameGuard(oldEnt, newEnt);
- cmpNewUnitAI.SetGuardOf(guarded);
- }
- }
- }
-
let cmpPromotion = Engine.QueryInterface(oldEnt, IID_Promotion);
let cmpNewPromotion = Engine.QueryInterface(newEnt, IID_Promotion);
if (cmpPromotion && cmpNewPromotion)
@@ -133,6 +109,27 @@
Engine.PostMessage(oldEnt, MT_EntityRenamed, { "entity": oldEnt, "newentity": newEnt });
+ // UnitAI generally needs other components to be properly initialised.
+ let cmpUnitAI = Engine.QueryInterface(oldEnt, IID_UnitAI);
+ let cmpNewUnitAI = Engine.QueryInterface(newEnt, IID_UnitAI);
+ if (cmpUnitAI && cmpNewUnitAI)
+ {
+ let pos = cmpUnitAI.GetHeldPosition();
+ if (pos)
+ cmpNewUnitAI.SetHeldPosition(pos.x, pos.z);
+ cmpNewUnitAI.AddOrders(cmpUnitAI.GetOrders());
+ let guarded = cmpUnitAI.IsGuardOf();
+ if (guarded)
+ {
+ let cmpGuarded = Engine.QueryInterface(guarded, IID_Guard);
+ if (cmpGuarded)
+ {
+ cmpGuarded.RenameGuard(oldEnt, newEnt);
+ cmpNewUnitAI.SetGuardOf(guarded);
+ }
+ }
+ }
+
if (cmpPosition && cmpPosition.IsInWorld())
cmpPosition.MoveOutOfWorld();
Engine.DestroyEntity(oldEnt);
Index: binaries/data/mods/public/simulation/templates/units/athen/infantry_slinger_a.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/units/athen/infantry_slinger_a.xml
+++ binaries/data/mods/public/simulation/templates/units/athen/infantry_slinger_a.xml
@@ -3,9 +3,11 @@
Advanced
+
units/athen/infantry_slinger_e
+
units/athenians/infantry_slinger_a.xml