MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / SelectSecondaryWeapon

Function SelectSecondaryWeapon

Descent3/weapon.cpp:997–1071  ·  view source on GitHub ↗

slot ranges 5-9

Source from the content-addressed store, hash-verified

995
996// slot ranges 5-9
997void SelectSecondaryWeapon(int slot) {
998 // get slot of currently selected weapon
999 int oldslot;
1000 int nw_low, nw_high;
1001 unsigned avail_flags;
1002 player *plr = &Players[Player_num];
1003
1004 avail_flags = plr->weapon_flags;
1005 oldslot = (plr->weapon[PW_SECONDARY].index % NUM_SECONDARY_SLOTS) + NUM_PRIMARY_SLOTS;
1006
1007 // do selection. if we are selecting the same slot of weapon, then we select to the next
1008 // level of weapon. when going from highest level, go to lowest
1009 if (oldslot == slot) {
1010 nw_low = SECONDARY_INDEX + ((plr->weapon[PW_SECONDARY].index + NUM_SECONDARY_SLOTS) % MAX_SECONDARY_WEAPONS);
1011
1012 if (is_weapon_available(avail_flags, nw_low, plr->weapon_ammo[nw_low])) {
1013 // toggle class of weapon in specified slot (save for selection)
1014 SetSecondaryWeapon(nw_low, slot);
1015 } else {
1016 AddHUDMessage(TXT_WPNNOTAVAIL);
1017 Sound_system.Play2dSound(SOUND_DO_NOT_HAVE_IT);
1018
1019 ain_hear hear;
1020 hear.f_directly_player = true;
1021 hear.hostile_level = 0.1f;
1022 hear.curiosity_level = 0.5f;
1023 hear.max_dist = AI_SOUND_SHORT_DIST;
1024 AINotify(&Objects[Players[Player_num].objnum], AIN_HEAR_NOISE, (void *)&hear);
1025 }
1026 return;
1027 }
1028
1029 // we are selecting a new weapon slot.
1030 nw_low = (slot % NUM_SECONDARY_SLOTS) + SECONDARY_INDEX;
1031 nw_high = nw_low + NUM_SECONDARY_SLOTS;
1032
1033 if (Weapon_slot_mask & (1 << slot)) {
1034 // we think we have a higher class of weapon.
1035 if (is_weapon_available(avail_flags, nw_high, plr->weapon_ammo[nw_high])) {
1036 // if this slot had the higher class of weapon then check if we still have the higher class weapon.
1037 SetSecondaryWeapon(nw_high, slot);
1038 } else if (is_weapon_available(avail_flags, nw_low, plr->weapon_ammo[nw_low])) {
1039 SetSecondaryWeapon(nw_low, slot);
1040 } else {
1041 AddHUDMessage(TXT_WPNNOTAVAIL);
1042 Sound_system.Play2dSound(SOUND_DO_NOT_HAVE_IT);
1043
1044 ain_hear hear;
1045 hear.f_directly_player = true;
1046 hear.hostile_level = 0.1f;
1047 hear.curiosity_level = 0.5f;
1048 hear.max_dist = AI_SOUND_SHORT_DIST;
1049 AINotify(&Objects[Players[Player_num].objnum], AIN_HEAR_NOISE, (void *)&hear);
1050 }
1051 } else {
1052 // if this is a lower class of weapon, make sure this slot is flagged as having the lower version
1053 if (is_weapon_available(avail_flags, nw_low, plr->weapon_ammo[nw_low])) {
1054 // if this slot had the higher class of weapon then check if we still have the higher class weapon.

Callers 1

SelectWeaponFunction · 0.85

Calls 5

is_weapon_availableFunction · 0.85
SetSecondaryWeaponFunction · 0.85
AddHUDMessageFunction · 0.85
AINotifyFunction · 0.85
Play2dSoundMethod · 0.80

Tested by

no test coverage detected