Game Development Reference
In-Depth Information
Notice that, because our formulas can generate values that are less than 0, we
must clamp the minimum on both values to 0. We can't do
negative
damage, and we
can't have
less than
a 0% chance of hitting our target. Other than that, the formulas
for calculating the values are familiar as code-ese translations of their mathematical
versions we expressed above.
We define an array of
CWeapon
objects in the
CWeaponCollection
as follows:
#define MAX_WEAPONS 4
CWeapon mWeapons[MAX_WEAPONS]; // Array of all weapons
CWeaponCollection
also has accessors for looking up information about any
of the members of its array by index. These accessors simply pass the request on to
the matching accessor of the referenced object.
The important function that
CWeaponCollection
performs, however, is to ini-
tialize the array with the four weapons we have defined in our game. We do this
through the function
InitOneWeapon()
.
void CWeaponCollection::InitOneWeapon( WEAPON_TYPE Type,
char* Name,
USHORT MaxRange,
USHORT BaseDamage,
double DmgDecayExp,
USHORT DmgDecayDiv,
USHORT DmgDecayShift,
double BaseAccuracy,
double AccDecayExp,
USHORT AccDecayDiv,
USHORT AccDecayShift )
{
mWeapons[Type].SetMaxRange( MaxRange );
mWeapons[Type].SetBaseDamage( BaseDamage );
mWeapons[Type].SetDmgDecayExp( DmgDecayExp );
mWeapons[Type].SetDamageDecayDiv( DmgDecayDiv );
mWeapons[Type].SetDamageDecayShift( DmgDecayShift );
mWeapons[Type].SetBaseAccuracy( BaseAccuracy );
mWeapons[Type].SetAccDecayExp( AccDecayExp );