• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Formula does not work as intended!

Status
Not open for further replies.
Level 16
Joined
Aug 20, 2009
Messages
1,552
I have these formulas to determine the player's magical attack damage.

this is written in C.

there is no compiler error, but the values are wrong in-game.

I wrote the formula first in Microsoft Excel, and paste it as the formula.

While I was expecting the same result as the Excel file, it does not go as intended.

unsigned short status_base_matk(const struct status_data* status, int level){ return (status->int_*2)+(status->int_/2)+(status->dex/4)+(status->luk/3)+(level/2); }

float fint = status->int_;
float fdex = status->dex;
float fluk = status->luk;
float flevel = level;
float fbmatk = status_base_matk(status, level);
float fmatkmaxmod = ((fint/3) + (fdex/6) + (fluk/4));
float fmatkminmod = ((fint/4) + (fdex/8) + (fluk/6));

status->matk_max = (flevel + 20 + (fbmatk*((float)(11)/10))) + ((flevel/125) * ((fmatkmaxmod * fbmatk)/18));

status->matk_min = ((flevel/2) + 10 + fbmatk) + ((flevel/150) * ((fmatkmaxmod * fbmatk)/22));

While level is 75, int is 99, dex is 41, and the rest is 1 (Str, luk, agi, vit)

it is supposed to result as (Matk Min) 545 (Matk Max) 716 (As in excel file)

but in-game, it results to around 300. why..?

Someone please help me, it does not fix no matter how much I tried :(

This is really frustrating. :/

Please help!

Original Excel File :
If it helps at all.

http://www.hiveworkshop.com/forums/pastebin.php?id=51iifg


Problem solved!.

After looking the GUI display a few codes ahead,
It was taking status_base_matk directly (thus resulting 310)
rather than taking the min and max of the values.

I am sorry guys, my bad!.

The formula wasn't wrong at all.

Solved.
 
Last edited:
Level 16
Joined
Aug 20, 2009
Messages
1,552
Show us the input for your code, i calculated it with a calculator and it's 761.50.... Thus the only problem can be that the functions get wrong input. Let it display on the console or something.

Thats what I get in calculator and excel too.

I am sure nothing is wrong in the input, as it shows the correct values for other formulas (Its in the excel file).

example :

status->def2 += (int) (((1+((float)level/4)+((float)status->vit/2))+ ( ((float)status->str/7)+((float)status->agi/8)+((float)status->dex/9)+((float)status->int_/7)+((float)status->vit/4) +((float)status->luk/7)*((float)level*((float)(1)/100)))*((float)level*((float)(1)/100))));

This shows the same DEF as in the excel did.

In conclusion, the inputs were right, there is just something wrong in how the math operates. probably conversion wise..?

If you are still curious in the input, the excel shows the same input as in the C.
 
Level 16
Joined
Aug 20, 2009
Messages
1,552
float fint = status->int_;
float fdex = status->dex;
float fluk = status->luk;
float flevel = level;
float fbmatk = status_base_matk(status, level);
float fmatkmaxmod = ((fint/3) + (fdex/6) + (fluk/4));
float fmatkminmod = ((fint/4) + (fdex/8) + (fluk/6));

status->matk_max = (flevel + 20 + (fbmatk*((float)(11)/10))) + ((flevel/125) * ((fmatkmaxmod * fbmatk)/18));
status->matk_min = ((flevel/2) + 10 + fbmatk) + ((flevel/150) * ((fmatkmaxmod * fbmatk)/22));

Simpler code now. as suggested by ghostwolf.

But still gives 310 as value :V

EDIT : Nevermind, I found the mistake, the formula itself is already giving the right values.

I look a few codes ahead and...

O.O

It was the GUI Interface that went wrong.

The display takes status_base_matk directly, rather than taking the Max and Min of the formula.

Sorry guys, my bad!

Thanks anyways guys! No wonder whatever I change the value, nothing changed..!
 
Last edited:
Status
Not open for further replies.
Top