int damagecalc(aclass a, aclass b, anotherclass m)//Calculates damage done with one attack
{
int ret_damage; //Final damage
float damage; //Net Damage done
float level; //Level of the attacker
float attack; //Attack stat of the attacker
float defense; //Defense stat of the attacked
float base; //Base damage of the attack
float modifier; //Formula as below
float stab; //Same Type Attack Bonus
float type; //Type Effectiveness
float critical; //Critical Ratio
float other; //Accounts for held items
float randomnum; //A number from 0.85 to 1.00
level=a.level;
attack=a.attack;
defense=b.defense;
base=m.basepower;
if (a.type1==m.type)
stab=1.5;
elseif (a.type2==m.type)
stab=1.5;
else stab=1;
type=typeeffectcalc();
//Critical calcs go here, but for now,
critical=1;
int temp;
temp=((rand()%16)+80)/100;
randomnum=(float)temp;
modifier=stab*type*critical*rand; //Formula for modifier
damage=((((2*level)+10)/250)*(attack/defense)*(base)+2)*modifier;
//Formula (It's harder than it looks) (That's what she said)
ret_damage=(int)damage;
return ret_damage; //Returns net damage
}
So, I'm getting an error: invalid operands of types `float' and `int ()()' to binary `operator*'
and it highlights this line modifier=stab*type*critical*rand;
(this line has been underlined above)
So, what am I doing wrong? All definitions outside of this section of the code are okay. I'm pretty sure that the problem is float multiplication.
Well, any help would be very appreciated.
Thanks,
WJr
Edit: Just a quick note. The components of the formula themselves can have a decimal point (hence the use of float), but the final result is rounded off and returned as an integer.
Edit 2: Just a side question. Is it possible to manually round off a float downwards to an integer? For eg, 2.112 becomes 2, 2.9999 also becomes 2.
In fact, rand is defined in stdlib.h (or cstdlib) as a function which returns an int and requires no parameter.
Essentially, it has type int ()();
(Yes, it's a type. Yes, functions have types. Yes, you can store a pointer to a function as you would with a normal variable)
int temp_min = 80/100; // Int doesn't store floating point. Either 0 or 1.
int temp_max = 96/100; // Same.
Make it go like this:
1 2 3
// Multiplication is usually faster than division.
// Make a good use of math properties, (x * 0.01f) = (x/100.f)
float temp = (((float)rand())+80.f) * 0.01f;