From e21f052803af1d297854c8c8abd561ef1aecfd23 Mon Sep 17 00:00:00 2001 From: mimo Date: Sat, 1 Feb 2014 17:55:27 +0000 Subject: [PATCH] prevent error when an animal changes ownership This was SVN commit r14720. --- binaries/data/mods/public/simulation/components/UnitAI.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index 7bed73a48c..d65c3e1263 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -3202,8 +3202,10 @@ UnitAI.prototype.OnOwnershipChanged = function(msg) // If the unit isn't being created or dying, reset stance and clear orders (if not garrisoned). if (msg.to != -1 && msg.from != -1) { - // Switch to an empty state to let states execute their leave handlers. - UnitFsm.SwitchToNextState(this, ""); + // Switch to a virgin state to let states execute their leave handlers. + var index = this.GetCurrentState().indexOf("."); + if (index != -1) + UnitFsm.SwitchToNextState(this, this.GetCurrentState().slice(0,index)); this.SetStance(this.template.DefaultStance); if(!this.isGarrisoned)