From 1fac936d685e4db861562a6366c78f55a0dfddc0 Mon Sep 17 00:00:00 2001 From: Badmadblacksad Date: Tue, 17 May 2011 16:26:47 +0000 Subject: [PATCH] fixes a bug related to foundations and animals corpses (previously, when an animal has already been ordered to leave a foundation once, it will not leave the construction site if you place an another building on top of it). This was SVN commit r9531. --- .../public/simulation/components/UnitAI.js | 37 +++++++------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index a325f6d1b8..7d2b2a0fa7 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -186,7 +186,10 @@ var UnitFsmSpec = { if (ok) { // We've started fleeing from the given target - this.SetNextState("INDIVIDUAL.FLEEING"); + if (this.IsAnimal()) + this.SetNextState("ANIMAL.FLEEING"); + else + this.SetNextState("INDIVIDUAL.FLEEING"); } else { @@ -1068,7 +1071,7 @@ var UnitFsmSpec = { this.template.NaturalBehaviour == "passive") { this.MoveToTargetRangeExplicit(msg.data.attacker, +this.template.FleeDistance, +this.template.FleeDistance); - this.SetNextState("FLEEING"); + this.Flee(msg.data.attacker); } else if (this.template.NaturalBehaviour == "violent" || this.template.NaturalBehaviour == "aggressive" || @@ -1138,7 +1141,7 @@ var UnitFsmSpec = { if (msg.data.added.length > 0) { this.MoveToTargetRangeExplicit(msg.data.added[0], +this.template.FleeDistance, +this.template.FleeDistance); - this.SetNextState("FLEEING"); + this.Flee(msg.data.added[0]); return; } } @@ -1183,7 +1186,7 @@ var UnitFsmSpec = { if (msg.data.added.length > 0) { this.MoveToTargetRangeExplicit(msg.data.added[0], +this.template.FleeDistance, +this.template.FleeDistance); - this.SetNextState("FLEEING"); + this.Flee(msg.data.added[0]); return; } } @@ -1201,26 +1204,7 @@ var UnitFsmSpec = { }, }, - "FLEEING": { // TODO: would be nice to share more of this with non-animal units - "enter": function() { - this.PlaySound("panic"); - - // Run quickly - var speed = this.GetRunSpeed(); - this.SelectAnimation("run", false, speed); - this.SetMoveSpeed(speed); - }, - - "leave": function() { - // Reset normal speed - this.SetMoveSpeed(this.GetWalkSpeed()); - }, - - "MoveCompleted": function() { - // When we've run far enough, go back to the roaming state - this.SetNextState("ROAMING"); - }, - }, + "FLEEING": "INDIVIDUAL.FLEEING", // reuse the same fleeing behaviour for animals "COMBAT": "INDIVIDUAL.COMBAT", // reuse the same combat behaviour for animals }, @@ -2073,6 +2057,11 @@ UnitAI.prototype.Repair = function(target, autocontinue, queued) this.AddOrder("Repair", { "target": target, "autocontinue": autocontinue }, queued); }; +UnitAI.prototype.Flee = function(target, queued) +{ + this.AddOrder("Flee", { "target": target }, queued); +}; + UnitAI.prototype.Cheer = function() { this.AddOrder("Cheering", null, false);