From 6351fe7a66ff2197dd500b5496eaa89baa75210c Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 20 Dec 2018 08:40:04 +0100 Subject: [PATCH] GetEnergy() offers exact energy value optionally (Bug #2043) --- docs/sdk/script/fn/GetEnergy.xml | 13 ++++++++++++- src/object/C4ObjectScript.cpp | 11 +++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/sdk/script/fn/GetEnergy.xml b/docs/sdk/script/fn/GetEnergy.xml index 1f4404a2e..63dd845ab 100644 --- a/docs/sdk/script/fn/GetEnergy.xml +++ b/docs/sdk/script/fn/GetEnergy.xml @@ -7,7 +7,17 @@ GetEnergy Objects 1.0 OC - int + + int + + + bool + exact + If true, the exact energy value is returned. + + + + Returns the current energy value of an object. 100% representing the maximum physical value of 100,000 For living beings, \"energy\" stands for health, in buildings it stands for electrical charge. @@ -15,4 +25,5 @@ jwk2002-06 + Marky2018-12 diff --git a/src/object/C4ObjectScript.cpp b/src/object/C4ObjectScript.cpp index a0ab91830..d94770c68 100644 --- a/src/object/C4ObjectScript.cpp +++ b/src/object/C4ObjectScript.cpp @@ -558,9 +558,16 @@ static long FnGetPhase(C4Object *Obj) return Obj->Action.Phase; } -static long FnGetEnergy(C4Object *Obj) +static long FnGetEnergy(C4Object *Obj, bool fExact) { - return 100*Obj->Energy/C4MaxPhysical; + if (fExact) + { + return Obj->Energy; + } + else + { + return 100*Obj->Energy/C4MaxPhysical; + } } static long FnGetBreath(C4Object *Obj)