Game Development Reference
In-Depth Information
double mBaseAccuracy; // Base (max) accuracy
double mAccDecayExp; // Decay formula exponent
USHORT mAccDecayDiv; // Decay formula divisor
USHORT mAccDecayShift; // Decay formula shift (horiz.)
};
The member variables for the weapons hold the numbers that we used for the
damage and accuracy calculations. For both damage and accuracy, we have a base,
a decay exponent, a decay divisor, and a decay shift. Based on the formulas we laid
out above, those are the only figures that we need to define the appropriate curves.
By calling GetDamage() and GetAccuracy() with the distance and any modi-
fiers (e.g., the accuracy modifiers for the different types of Dudes), we receive the
appropriate damage value or accuracy percentage. These two functions operate
very simply.
double CWeapon::GetAccuracy( USHORT Dist /*= 0*/,
double Modifier /*= 0.0 */ )
{
double Accuracy = mBaseAccuracy + Modifier -
(pow(( Dist - mAccDecayShift ), mAccDecayExp )) / mAccDecayDiv;
if ( Accuracy < 0 ) { Accuracy = 0; }
return Accuracy;
}
double CWeapon::GetDamage( USHORT Dist /*= 0*/,
double Modifier /*= 0.0 */ )
{
double Damage = mBaseDamage + Modifier -
(pow(( Dist - mDmgDecayShift ), mDmgDecayExp )) / mDmgDecayDiv;
if ( Damage < 0 ) { Damage = 0; }
return Damage;
}
Search WWH ::




Custom Search