Graphics Reference
In-Depth Information
// if the selected weapon is already this one, drop out!
if(slotNum==lastSelectedWeaponSlot)
return;
As a new weapon is about to be made active, the current weapon is disabled by a call
to the function DisableCurrentWeapon():
// disable the current weapon
DisableCurrentWeapon();
selectedWeaponSlot is an index used to store the currently active weapon slot. Here
it is set to the incoming parameter value of slotNum:
// set our current weapon to the one passed in
selectedWeaponSlot= slotNum;
The new value of selectedWeaponSlot is then validated to make sure that it is not
less than zero or more than the total number of occupied slots taking away one (since the
weaponSlots array of weapons starts at zero, we take one of the total to find the last entry).
During the validation, if the value of slotNum is found to be outside what is allowed, it
will be set to the nearest valid number—that way, the function will not fail in setting the
weapon because of a bad value in slotNum but will choose the wrong weapon instead:
// make sure sensible values are getting passed in
if(selectedWeaponSlot<0)
selectedWeaponSlot= weaponSlots.Count-1;
// make sure that the weapon slot isn't higher than the
// total number of weapons in our list
if(selectedWeaponSlot>weaponSlots.Count-1)
selectedWeaponSlot=weaponSlots.Count-1;
Now that selectedWeaponSlot has been set, lastSelectedWeaponSlot needs updating
to the latest slot number:
// we store this selected slot to use to prevent duplicate
// weapon slot setting
lastSelectedWeaponSlot= selectedWeaponSlot;
A call to EnableCurrentWeapon() will take the value of selectedWeaponSlot and acti-
vate the currently selected weapon:
// enable the newly selected weapon
EnableCurrentWeapon();
}
The NextWeaponSlot() takes a Boolean parameter to tell the function whether or not
to loop around from the last weapon to the first. If the shouldLoop parameter is false,
and the current weapon is already set to the last available weapon, it will return the same
weapon instead of looping around to zero and returning the weapon from the first slot:
public virtual void NextWeaponSlot (bool shouldLoop)
{
Search WWH ::




Custom Search