From 9fa7273c2c1e130ec552148202b1e9450d58ecff Mon Sep 17 00:00:00 2001 From: wraitii Date: Sun, 23 Dec 2012 10:31:39 +0000 Subject: [PATCH] Backport from API v3 to API v2 that should fix a bug happening with sheeps. fixes #1754 This was SVN commit r13012. --- .../simulation/ai/common-api-v2/entity.js | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/binaries/data/mods/public/simulation/ai/common-api-v2/entity.js b/binaries/data/mods/public/simulation/ai/common-api-v2/entity.js index 1016b97231..749c6ae4eb 100644 --- a/binaries/data/mods/public/simulation/ai/common-api-v2/entity.js +++ b/binaries/data/mods/public/simulation/ai/common-api-v2/entity.js @@ -59,10 +59,24 @@ var EntityTemplate = Class({ return 0; // this should never happen }, - maxHitpoints: function() { return this._template.Health.Max; }, - isHealable: function() { return this._template.Health.Unhealable !== "true"; }, - isRepairable: function() { return this._template.Health.Repairable === "true"; }, - + maxHitpoints: function() + { + if (this._template.Health !== undefined) + return this._template.Health.Max; + return 0; + }, + isHealable: function() + { + if (this._template.Health !== undefined) + return this._template.Health.Unhealable !== "true"; + return false; + }, + isRepairable: function() + { + if (this._template.Health !== undefined) + return this._template.Health.Repairable === "true"; + return false; + }, armourStrengths: function() { if (!this._template.Armour) @@ -276,7 +290,7 @@ var Entity = Class({ unitAIState: function() { return this._entity.unitAIState; }, unitAIOrderData: function() { return this._entity.unitAIOrderData; }, - hitpoints: function() { return this._entity.hitpoints; }, + hitpoints: function() { if (this._entity.hitpoints !== undefined) return this._entity.hitpoints; return undefined; }, isHurt: function() { return this.hitpoints() < this.maxHitpoints(); }, needsHeal: function() { return this.isHurt() && this.isHealable(); }, needsRepair: function() { return this.isHurt() && this.isRepairable(); },