SRL Archive - Research & Development Lounge

Complex Energy Calculation | Function EnergyCalc: Extended;


Nadeem

2009-05-31 20:58:43

Hi,

This is I guess just for fun. I just recently started taking interest in physics and stuff, so I first wanted to apply Einstein's famous equation (E = mc^2) but guess RS just wasn't as real :P This took me a good 4 hours almost to figure out and use the correct numbers/formulas + a hint from RuneHQ's calc, to calculate energy restoration in RuneScape. Its been pretty damn accurate for me so far, testing on 2 accounts, 1 with agil close to 80ish and the other at 1. Please let me know how well it works for you :) ~ Thanks!

[HOW TO USE:]

var
E: Extended;

{ Returns seconds left to reach 100% energy. Since ALevel is defined 0, it will check your agility level for you. }
E := EnergyCalc(1, 0);
Writeln(FloatToStr(E));

{ Returns second it takes you to regenerate 1%. With your entered ALevel equaling 32 }
E := EnergyCalc(2, 32);
Writeln(FloatToStr(E));

{ Returns seconds it takes for you to regenerate 100% Energy, from 0%. Since ALevel is defined 0, it will check your agility level for you. }
E := EnergyCalc(3, 0);
Writeln(FloatToStr(E));

[THE FUNCTION:]

{×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
× Function : EnergyCalc: Extended; | v1.2
× Author : Nadeem
× Desc. : Checks and returns a complex calculation of runescape's
Energy information.
- TypeID -
1: Returns seconds left to reach 100% energy.
2: Returns second it takes you to regenerate 1%.
3: Returns seconds it takes for you to regenerate 100%
Energy, from 0%.
×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××}
function EnergyCalc(TypeID, ALevel: Integer): Extended;
var
G: string;
A: Integer;
E, M, C: Extended;
begin
if (ALevel <= 0) then
A := GetSkillInfo('Agility', True)
else
A := ALevel;
C := 3.0 * Pow(10, -4);
E := Pow(A, 2) * C + (0319 * Pow(10, -3) - 0.19) * A + 7.75;
M := (6000 div E) div 100;
case TypeID of
1 : E := M * (100 - GetMMLevels('run', G));
2 : E := M;
3 : E := M * 100;
else
E := -1.0;
end;
Result := Abs(E);
end;



~NS

Cazax

2009-05-31 21:02:38

People with level 1 in agility wouldn't want to change tabs, no? Make a parameter to see if the account is member or not, to avoid looking for agility. Apart from that good job :)

Nadeem

2009-05-31 21:07:25

From: Cazax
People with level 1 in agility wouldn't want to change tabs, no? Make a parameter to see if the account is member or not, to avoid looking for agility. Apart from that good job :)

Thank you :) - Well I'll just add in another param for their agility level, if the enter 0 then it'll switch tabs to check else just use that :D

Edit: Updated!



~NS

Sandstorm

2009-05-31 22:24:00

You only use the variable S (GetMMLevels('run', G)) once. Put it in the case function, to save a few milliseconds xD.

Just my suggestions.

~Sandstorm

senrath

2009-05-31 22:26:21

Whats the point of R := E? Why not just use E?

Nadeem

2009-05-31 22:33:56

From: Sandstorm
You only use the variable S (GetMMLevels('run', G)) once. Put it in the case function, to save a few milliseconds xD.

Just my suggestions.

~Sandstorm

Doesn't really matter much, takes 0-16ms to do all the calculation without using SRL functions. Although will take it into consideration and apply it :) - Thanks!

From: senrath
Whats the point of R := E? Why not just use E?

lol, nothing much really but once again, will take into consideration and apply it. - Thanks!


Edit: Updated!
~NS

ian.

2009-05-31 23:04:34

I don't see why you have to declare the level if you look for it if it's more than 1.. :p I don't think it's detectable to check your levels at all ;] I think it should do it no matter what.. and it should do all those options no matter what. Just Writeln('You can run for '+IntToStr(Whatever)+'… blah blah blah'); :] That'd be nice. No options.. <3 haha

Nadeem

2009-06-01 05:11:55

From: 99_
I don't see why you have to declare the level if you look for it if it's more than 1.. :p I don't think it's detectable to check your levels at all ;] I think it should do it no matter what.. and it should do all those options no matter what. Just Writeln('You can run for '+IntToStr(Whatever)+'… blah blah blah'); :] That'd be nice. No options.. <3 haha


lol, I have no idea what your saying at all xD

From what I understand:
It only checks for the level if you don't declare your agility level, and leave it as either 0 or less than 0. Its just that it takes longer in total if it goes to check your level due to the mouse movement. All of what options..? The TypeID's? You mean like do them all and return a var for each? :P



~NS

ian.

2009-06-01 05:28:20

I don't remember what I was talking about. Ha ha ha :D


{×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
× Function : EnergyCalc: Extended; | v1.2
× Author : Nadeem
× Desc. : Checks and returns a complex calculation of runescape's
Energy information.
- TypeID -
1: Returns seconds left to reach 100% energy.
2: Returns second it takes you to regenerate 1%.
3: Returns seconds it takes for you to regenerate 100%
Energy, from 0%.
×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××}
function EnergyCalc: Extended;
var
G: string;
A: Integer;
E, M, C: Extended;
begin
A := GetSkillInfo('Agility', True)
else
A := ALevel;
C := 3.0 * Pow(10, -4);
E := Pow(A, 2) * C + (0319 * Pow(10, -3) - 0.19) * A + 7.75;
M := (6000 div E) div 100;
E1 := M * (100 - GetMMLevels('run', G));
E2 := M;
E3 := M * 100;
Writeln(E1 + E2 + E3);//Too lazy to read :p Don't remember what each of these are but I think it should show all :]
end;

mrpickle

2009-06-01 05:50:29

someone likes math =)

Da 0wner

2009-06-01 06:00:34

Don't you regenerate energy slower whilst you are running?

ian.

2009-06-01 06:03:23

I believe that's only if you stop running.

Nadeem

2009-06-01 08:01:27

@mrpickle: lol, why yes xP

@Da 0wner: You only regenerate energy while walking or standing still, never while running. I might make a new calculation with how much energy you use per second depending on your mass + agility level if anyone likes to see :P

@99_: Writeln(E1 + E2 + E3); ~ LOL, First of all, they are Extended values, therefore FloatToStr() is needed, Second, are you trynna add all the values together? :P BUT I think your trynna say, why not just make the function write to debug a sentence of the entire energy structure?

Ex: You will restore 100% energy in ##.## seconds. You restore 1% energy in roughly #.## seconds. You restore 100% energy in roughly ###.## seconds.



~NS

senrath

2009-06-01 08:03:23

From: Nadeem
You only regenerate energy while walking or standing still, never while running. I might make a new calculation with how much energy you use per second depending on your mass + agility level if anyone likes to see :P

BTW 99_: Writeln(E1 + E2 + E3); ~ LOL, First of all, they are Extended values, therefore FloatToStr() is needed, Second, are you trynna add all the values together? :P BUT I think your trynna say, why not just make the function write to debug a sentence of the entire energy structure?

Ex: You will restore 100% energy in ##.## seconds. You restore 1% energy in roughly #.## seconds. You restore 100% energy in roughly ###.## seconds.

~NS




He's using 3.20d, which automatically wraps things like Extendeds and Integers with their proper string conversion.

Nadeem

2009-06-01 08:06:19

From: senrath
He's using 3.20d, which automatically wraps things like Extendeds and Integers with their proper string conversion.


say wurdd lol I never knew that, and I'm using 3.20d too :O



~NS

ian.

2009-06-01 08:06:27

From: senrath
He's using 3.20d, which automatically wraps things like Extendeds and Integers with their proper string conversion.


yeah. :] I know what I'm sezzing! kinda.

marpis

2009-06-01 10:22:50

+ (0319 * Pow(10, -3) - 0.19) *
3.0 * Pow(10, -4);

these are constants, why calculate them?
but very nice job, i might test if it works ;)

Nadeem

2009-06-01 19:26:13

From: marpis
+ (0319 * Pow(10, -3) - 0.19) *
3.0 * Pow(10, -4);

these are constants, why calculate them?
but very nice job, i might test if it works ;)


What do you mean? If no calculation is done, then whats the point..? xP
Thank you! :D



~NS

Shuttleu

2009-06-01 19:33:35

From: 99_
I don't remember what I was talking about. Ha ha ha :D


{×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
× Function : EnergyCalc: Extended; | v1.2
× Author : Nadeem
× Desc. : Checks and returns a complex calculation of runescape's
Energy information.
- TypeID -
1: Returns seconds left to reach 100% energy.
2: Returns second it takes you to regenerate 1%.
3: Returns seconds it takes for you to regenerate 100%
Energy, from 0%.
×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××}
function EnergyCalc: Extended;
var
G: string;
A: Integer;
E, M, C: Extended;
begin
A := GetSkillInfo('Agility', True)
else
A := ALevel;
C := 3.0 * Pow(10, -4);
E := Pow(A, 2) * C + (0319 * Pow(10, -3) - 0.19) * A + 7.75;
M := (6000 div E) div 100;
E1 := M * (100 - GetMMLevels('run', G));
E2 := M;
E3 := M * 100;
Writeln(E1 + E2 + E3);//Too lazy to read :p Don't remember what each of these are but I think it should show all :]
end;

you know what your saying huh?
then where is E1, E2, and E3 declared?

~shut

Nadeem

2009-06-01 19:54:41

lol I think he was just trynna give me and idea of what he was saying, it doesn't have to be the right code :) He is also missing the if then after begin :P



~NS

ZephyrsFury

2009-06-01 20:25:12

From: Nadeem
What do you mean? If no calculation is done, then whats the point..? xP
Thank you! :D



~NS


I think he means why are you using Pow(10, -4) * whatever etc when you could replace that with just a number. I guess its all about accuracy and getting exact answers right?

ShowerThoughts

2009-06-01 21:52:55

From: ZephyrsFury
I think he means why are you using Pow(10, -4) * whatever etc when you could replace that with just a number. I guess its all about accuracy and getting exact answers right?


If you have to change some value's it's harder to edit.
You can always keep shortening code but sometimes it's better to do not shorten because then you will understand what you're doing, although if you make it to long it's not good either.

Nadeem

2009-06-01 23:14:56

From: ZephyrsFury
I think he means why are you using Pow(10, -4) * whatever etc when you could replace that with just a number. I guess its all about accuracy and getting exact answers right?

Correct :) It is more precise and accurate, unless ofcourse you just want a really rough idea, then the powering is not really needed. Although it really does not matter that much since its not affecting the function speed if not at all.

From: Hermen
If you have to change some value's it's harder to edit.
You can always keep shortening code but sometimes it's better to do not shorten because then you will understand what you're doing, although if you make it to long it's not good either.

Its good to keep it short and sweet, but too short will make it not so healthy of a function, therefore you are also correct :)



~NS

marpis

2009-06-02 17:59:14

From: Nadeem
Correct :) It is more precise and accurate, unless ofcourse you just want a really rough idea, then the powering is not really needed. Although it really does not matter that much since its not affecting the function speed if not at all.


Its good to keep it short and sweet, but too short will make it not so healthy of a function, therefore you are also correct :)

~NS


(0319 * Pow(10, -3) - 0.19) = 0.129
(3.0 * Pow(10, -4)) = 0.0003

these are 100% accurate and make calculations easier to read. but its your function…

Metagen

2009-06-02 18:29:54

From: Cazax
People with level 1 in agility wouldn't want to change tabs, no? Make a parameter to see if the account is member or not, to avoid looking for agility. Apart from that good job :)


Agility is, in fact, the only member skill to benifit nonmembers.