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 @@ -2063,11 +2063,15 @@ if (!this.formationAnimationVariant) this.SetAnimationVariant("combat"); + if (Engine.QueryInterface(this.order.data.target, IID_UnitAI)?.IsFleeing()) + this.SetSpeedMultiplier(this.GetRunMultiplier()); + this.StartTimer(1000, 1000); return false; }, "leave": function() { + this.ResetSpeedMultiplier(); this.StopMoving(); this.StopTimer(); }, @@ -2079,14 +2083,15 @@ if (this.GetStance().respondHoldGround) this.WalkToHeldPosition(); + return; } - else - { - this.RememberTargetPosition(); - if (this.order.data.hunting && this.orderQueue.length > 1 && - this.orderQueue[1].type === "Gather") - this.RememberTargetPosition(this.orderQueue[1].data); - } + if (!this.order.data.force && this.FindWalkAndFightTargets(true)) + return; + + this.RememberTargetPosition(); + if (this.order.data.hunting && this.orderQueue.length > 1 && + this.orderQueue[1].type === "Gather") + this.RememberTargetPosition(this.orderQueue[1].data); }, "MovementUpdate": function(msg) { @@ -5143,9 +5148,6 @@ if (!this.AbleToMove()) return false; - if (this.GetStance().respondChase) - return true; - // If we are guarding/escorting, chase at least as long as the guarded unit is in target range of the attacker if (this.isGuardOf) { @@ -5995,7 +5997,11 @@ return this.AttackEntitiesByPreference(cmpRangeManager.ResetActiveQuery(this.losAttackRangeQuery)); }; -UnitAI.prototype.FindWalkAndFightTargets = function() +/** + * @param {boolean} replace - Whether to replace the current order. + * @return {boolean} - Whether we've found a target. + */ +UnitAI.prototype.FindWalkAndFightTargets = function(replace) { if (this.IsFormationController()) return this.CallMemberFunction("FindWalkAndFightTargets", null); @@ -6039,7 +6045,7 @@ "force": false, "allowCapture": this.order?.data?.allowCapture || this.DEFAULT_CAPTURE }; - if (this.IsFormationMember()) + if (replace || this.IsFormationMember()) this.ReplaceOrder("Attack", order); else this.PushOrderFront("Attack", order);