Oct 28, 2010 at 6:16pm UTC
hello all im developing a text base MUD and have recently implemented a type of spell that puts a shield on a target and as long as this shield is on the target any damage they take is reduced by 5%.
example:
if( cptr->shield > 0)
{
dmgmod = (dmg * .05);
dmg -= dmgmod;
}
problem im having is it only reduces dmg by 5% if dmg > 100.
can someone point me into the direction of a basic routine where i can avoid this?
Oct 28, 2010 at 6:19pm UTC
if dmg and dmgmod are integers, the result will be truncated
Oct 28, 2010 at 6:29pm UTC
well i tried it several ways even:
INT dmg;
FLOAT dmgmod;
dmg = arnrnd(1,6);
shocst("DMG:","Value Of Damage Is %d".,dmg);
dmgmod = (dmg * .05);
shocst("DMGMOD:","Amount To Reduce By Is: %f",dmgmod);
dmg-=(INT)dmgmod;
shocst("NEW VALUE","DMG Is Now %d",dmg);
anyh elp would be greatly appreciated and thanks for the reply.
Oct 28, 2010 at 6:37pm UTC
Assuming INT is a typedef for int and FLOAT for float, you're still truncating the result because dmg is an int and you're casting dmgmod to be read as an int too.
Oct 28, 2010 at 10:53pm UTC
yeah the dev kit im using using those typedefs.
so in youre experience what way would you reccomend going about reducing dmg by 5%.
from the database dmg=arnrnd(mindam,maxdam); mindam and maxdam are both SHORT integers ranging from 1 - 9999.
Oct 30, 2010 at 9:02pm UTC
ok after ding some playing i came up with:
double damage = 15;
float dmgmod = (damage * .05);
damage = (damage - dmgmod);
outdmg = (INT)damage;
damage is 15.0000
dmgmod is 14.7500
outdmg becomes 14
seems to work for the short haul we'll see in later routines.
so in my game code i go:
if(cptr->shield) dmg = (arnrnd( mindam , maxdam) - dmgmod );
else dmg = arnrnd(mindam , maxdam);