PDA

View Full Version : Makedo GetRunEnergy Function



mxtrix
04-19-2014, 10:51 AM
Hey guys, I have just begun writing an updated air runecrafter and found that the getrunenergy function was non-existent (it has not yet been updated). I have created a make-do function which can be used to approximate it pretty accurately (within 5%). Here is the function if it would be of use to anyone:


// GET THE RUN ENERGY PERCENTAGE
function GetRunEnergy: Integer;
var
TPA1, TPA2 : TPointArray;
k, p, h, c, percApprox : integer;
j : TBox;
begin
findColorsTolerance(TPA1, 1126294,761, 21, 791, 50, 30); // Creates a TPointArray of matching points in the run icon area
//smartImage.debugTPA(TPA1);
j := GetTPABounds(TPA1); // Convert the TPArray bounds to a TBox
c := j.getHeight(); // Find the height of the TBox
percApprox := Round(3.846*c); // Thus, find the percentage- 100% was ~26
WriteLn(percApprox); // Print the approximate percentage
Result := percApprox; // Make the result equal to the percentage
end;

I understand that this needs some work but it does its job.

masterBB
04-19-2014, 02:40 PM
Hey guys, I have just begun writing an updated air runecrafter and found that the getrunenergy function was non-existent (it has not yet been updated). I have created a make-do function which can be used to approximate it pretty accurately (within 5%). Here is the function if it would be of use to anyone:

I understand that this needs some work but it does its job.

Updated it in browser to srl 6 standards. Can you add it to lib/interfaces/minimap.simba and test it?

If it works:

create a github account
Go to https://github.com/SRL/SRL-6/blob/master/lib/interfaces/minimap.simba
Click edit
Edit it and push it to the main branch


Olly or another srl dev will review it, and probably add it. Mention me if you need help with that.

(*
TRSMinimap.getRunEnergy
~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: pascal

function TRSMinimap.getRunEnergy(): Integer;

Returns the percentage of run energy left.

.. note::

- by mxtrix
- Last Updated: 19 April 2014 by mxtrix

Example:

.. code-block:: pascal

if (minimap.GetRunEnergy() > 50) then
minimap.toggleRun(True);
*)
function minimap.getRunEnergy(): Integer;
const
HEIGHTPERRATIO = 3.846; //height of yellow run energy to percentage ratio
ENERGYCOLOUR = 1126294; //Yellow energy colour
TOLERANCE = 30; //Yellow energy colour tolerance
var
YellowPts: TPointArray;
h, percApprox : integer;
j : TBox;
begin
findColorsTolerance(YellowPts, ENERGYCOLOUR, self.button[MM_BUTTON_RUN].bounds, TOLERANCE ); // Creates a TPointArray of matching points in the run icon area
j := GetTPABounds(YellowPts); // Convert the TPArray bounds to a TBox
h := j.getHeight(); // Find the height of the TBox
percApprox := Round(HEIGHTPERRATIO * h); // Thus, find the percentage- 100% was ~26
Result := percApprox; // Make the result equal to the percentage
end;

Smidqe
04-19-2014, 04:09 PM
I cleaned your code and removed the unnecessary variables. In lape you can chain type functions so it can make your code cleaner. Haven't tested if this works, but if it does then do what masterBB instructed you in his post.



(*
TRSMinimap.getRunEnergy
~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: pascal

function TRSMinimap.getRunEnergy(): Integer;

Returns the percentage of run energy left.

.. note::

- by mxtrix
- Last Updated: 19 April 2014 by mxtrix

Example:

.. code-block:: pascal

if (minimap.GetRunEnergy() > 50) then
minimap.toggleRun(True);
*)
function TRSMinimap.getRunEnergy(): integer;
const
HEIGHTPERRATIO = 3.846; //height of yellow run energy to percentage ratio
ENERGYCOLOUR = 1126294; //Yellow energy colour
TOLERANCE = 30; //Yellow energy colour tolerance
var
yellow : TPointArray; //I'm not entirely sure how SRL6 variable naming goes.
begin
findColorsTolerance(yellow, ENERGYCOLOUR, self.button[MM_BUTTON_RUN].bounds, TOLERANCE);

result := (round(HEIGHTPERRATIO * (yellow.getBounds().getHeight())));
end;