Index: binaries/data/mods/public/simulation/components/UnitAI.js =================================================================== --- binaries/data/mods/public/simulation/components/UnitAI.js +++ binaries/data/mods/public/simulation/components/UnitAI.js @@ -307,7 +307,7 @@ return; } - this.SetHeldPosition(this.order.data.x, this.order.data.z); + this.SetHeldPositionOnEntity(this.entity); this.MoveToPoint(this.order.data.x, this.order.data.z); if (this.IsAnimal()) this.SetNextState("ANIMAL.WALKING"); // WalkAndFight not applicable for animals @@ -464,6 +464,14 @@ return; } + // If we can't reach the target, but are standing ground, then abandon this attack order. + // Unless we're hunting, that's a special case where we should continue attacking our target. + if (this.GetStance().respondStandGround && !this.order.data.force && !this.order.data.hunting || this.IsTurret()) + { + this.FinishOrder(); + return; + } + // For packable units out of attack range: // 1. If packed, we need to move to attack range and then unpack. // 2. If unpacked, we first need to pack, then follow case 1. @@ -473,14 +481,6 @@ return; } - // If we can't reach the target, but are standing ground, then abandon this attack order. - // Unless we're hunting, that's a special case where we should continue attacking our target. - if (this.GetStance().respondStandGround && !this.order.data.force && !this.order.data.hunting || this.IsTurret()) - { - this.FinishOrder(); - return; - } - // Try to move within attack range if (this.MoveToTargetAttackRange(this.order.data.target, this.order.data.attackType)) { @@ -767,7 +767,7 @@ }, "Order.WalkAndFight": function(msg) { - this.CallMemberFunction("SetHeldPosition", [msg.data.x, msg.data.z]); + this.CallMemberFunction("SetHeldPositionOnEntity", [this.entity]); this.MoveToPoint(this.order.data.x, this.order.data.z); this.SetNextState("WALKINGANDFIGHTING"); @@ -803,7 +803,7 @@ }, "Order.Patrol": function(msg) { - this.CallMemberFunction("SetHeldPosition", [msg.data.x, msg.data.z]); + this.CallMemberFunction("SetHeldPositionOnEntity", [this.entity]); this.MoveToPoint(this.order.data.x, this.order.data.z); this.SetNextState("PATROL"); @@ -1044,6 +1044,7 @@ }, "leave": function(msg) { + this.CallMemberFunction("SetHeldPositionOnEntity", [this.entity]); this.StopTimer(); }, @@ -1085,6 +1086,7 @@ "leave": function(msg) { this.StopTimer(); + this.SetHeldPositionOnEntity(this.entity); delete this.patrolStartPosOrder; }, @@ -1583,6 +1585,7 @@ "leave": function(msg) { this.StopTimer(); + this.SetHeldPositionOnEntity(this.entity); this.SetDefaultAnimationVariant(); }, @@ -1615,6 +1618,7 @@ "leave": function() { this.StopTimer(); delete this.patrolStartPosOrder; + this.SetHeldPositionOnEntity(this.entity); this.SetDefaultAnimationVariant(); }, @@ -5410,6 +5414,8 @@ UnitAI.prototype.FindWalkAndFightTargets = function() { + this.SetHeldPositionOnEntity(this.entity); + if (this.IsFormationController()) { var cmpUnitAI; @@ -5437,7 +5443,7 @@ if (targetClasses.vetoEntities && targetClasses.vetoEntities[targ]) continue; } - this.PushOrderFront("Attack", { "target": targ, "force": true, "allowCapture": this.order.data.allowCapture }); + this.PushOrderFront("Attack", { "target": targ, "force": false, "allowCapture": this.order.data.allowCapture }); return true; } } @@ -5463,7 +5469,7 @@ if (targetClasses.vetoEntities && targetClasses.vetoEntities[targ]) continue; } - this.PushOrderFront("Attack", { "target": targ, "force": true, "allowCapture": this.order.data.allowCapture }); + this.PushOrderFront("Attack", { "target": targ, "force": false, "allowCapture": this.order.data.allowCapture }); return true; }