Skip to content

Commit

Permalink
GetEnergy() offers exact energy value optionally (Bug #2043)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitMarky committed Dec 20, 2018
1 parent 11cfcdd commit 6351fe7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
13 changes: 12 additions & 1 deletion docs/sdk/script/fn/GetEnergy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,23 @@
<title>GetEnergy</title>
<category>Objects</category>
<version>1.0 OC</version>

This comment has been minimized.

Copy link
@lluchs

lluchs Dec 21, 2018

Member

Can you also add <extversion>9.0 OC</extversion> to the version here?

This comment has been minimized.

Copy link
@gitMarky

gitMarky Dec 21, 2018

Author Contributor

Is that displayed as "extended in" then? Also, should it just read 9.0 OC or also explain what was added?

This comment has been minimized.

Copy link
@lluchs

lluchs Dec 21, 2018

Member

Yeah. So it should be <version>1.0 OC<extversion>9.0 OC</extversion></version> in full. I think the usual strategy has been to add something like "(since 9.0 OC)" to the description of the new parameter.

<syntax><rtype>int</rtype></syntax>
<syntax>
<rtype>int</rtype>
<params>
<param>
<type>bool</type>
<name>exact</name>
<desc>If <code>true</code>, the exact energy value is returned.</desc>
<optional />
</param>
</params>
</syntax>
<desc>Returns the current energy value of an object. 100% representing the maximum physical value of 100,000</desc>
<remark>For living beings, \"energy\" stands for health, in buildings it stands for electrical charge.</remark>
<related>
<funclink>DoEnergy</funclink>
</related>
</func>
<author>jwk</author><date>2002-06</date>
<author>Marky</author><date>2018-12</date>
</funcs>
11 changes: 9 additions & 2 deletions src/object/C4ObjectScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6351fe7

Please sign in to comment.