slot ranges 0-4
| 912 | |
| 913 | // slot ranges 0-4 |
| 914 | void SelectPrimaryWeapon(int slot) { |
| 915 | // get slot of currently selected weapon |
| 916 | int oldslot; |
| 917 | int nw_low, nw_high; |
| 918 | unsigned avail_flags; |
| 919 | player *plr = &Players[Player_num]; |
| 920 | |
| 921 | avail_flags = plr->weapon_flags; |
| 922 | oldslot = plr->weapon[PW_PRIMARY].index % NUM_PRIMARY_SLOTS; |
| 923 | |
| 924 | // do selection. if we are selecting the same slot of weapon, then we select to the next |
| 925 | // level of weapon. when going from highest level, go to lowest |
| 926 | if (oldslot == slot) { |
| 927 | uint16_t nw_low = (plr->weapon[PW_PRIMARY].index + NUM_PRIMARY_SLOTS) % MAX_PRIMARY_WEAPONS; |
| 928 | |
| 929 | if (is_weapon_available(avail_flags, nw_low)) { |
| 930 | // toggle class of weapon in specified slot (save for selection) |
| 931 | SetPrimaryWeapon(nw_low, slot); |
| 932 | } else { |
| 933 | AddHUDMessage(TXT_WPNNOTAVAIL); |
| 934 | Sound_system.Play2dSound(SOUND_DO_NOT_HAVE_IT); |
| 935 | |
| 936 | ain_hear hear; |
| 937 | hear.f_directly_player = true; |
| 938 | hear.hostile_level = 0.1f; |
| 939 | hear.curiosity_level = 0.5f; |
| 940 | hear.max_dist = AI_SOUND_SHORT_DIST; |
| 941 | AINotify(&Objects[Players[Player_num].objnum], AIN_HEAR_NOISE, (void *)&hear); |
| 942 | } |
| 943 | |
| 944 | return; |
| 945 | } else { |
| 946 | // we are selecting a new weapon slot. |
| 947 | nw_low = slot % NUM_PRIMARY_SLOTS; |
| 948 | nw_high = nw_low + NUM_PRIMARY_SLOTS; |
| 949 | |
| 950 | if (Weapon_slot_mask & (1 << slot)) { |
| 951 | // we think we have a higher class of weapon. |
| 952 | if (is_weapon_available(avail_flags, nw_high)) { |
| 953 | // if this slot had the higher class of weapon then check if we still have the higher class weapon. |
| 954 | // toggle class of weapon in specified slot (save for selection) |
| 955 | SetPrimaryWeapon(nw_high, slot); |
| 956 | } else if (is_weapon_available(avail_flags, nw_low)) { |
| 957 | // check if we have the lower class. |
| 958 | // toggle class of weapon in specified slot (save for selection) |
| 959 | SetPrimaryWeapon(nw_low, slot); |
| 960 | } else { |
| 961 | AddHUDMessage(TXT_WPNNOTAVAIL); |
| 962 | Sound_system.Play2dSound(SOUND_DO_NOT_HAVE_IT); |
| 963 | |
| 964 | ain_hear hear; |
| 965 | hear.f_directly_player = true; |
| 966 | hear.hostile_level = 0.1f; |
| 967 | hear.curiosity_level = 0.5f; |
| 968 | hear.max_dist = AI_SOUND_SHORT_DIST; |
| 969 | AINotify(&Objects[Players[Player_num].objnum], AIN_HEAR_NOISE, (void *)&hear); |
| 970 | } |
| 971 | } else { |
no test coverage detected