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

Function AddWeaponToPlayer

Descent3/weapon.cpp:835–868  ·  view source on GitHub ↗

unconditionally adds a weapon and ammo to a player.

Source from the content-addressed store, hash-verified

833
834// unconditionally adds a weapon and ammo to a player.
835int AddWeaponToPlayer(int slot, int weap_index, int ammo) {
836 bool select_new = false;
837
838 LOGFILE((_logfp, "Adding weapon(%d,ammo=%d) to player.\n", weap_index, ammo));
839
840 Players[slot].weapon_flags |= HAS_FLAG(weap_index);
841
842 ship *ship = &Ships[Players[slot].ship_index];
843 otype_wb_info *wb = &ship->static_wb[weap_index];
844 ASSERT(wb != NULL);
845
846 // if secondary or primary that uses ammo, then use the ammo
847 if ((weap_index >= SECONDARY_INDEX) || wb->ammo_usage) {
848 // figure out much ammo to add
849 int added = std::min(ship->max_ammo[weap_index] - Players[slot].weapon_ammo[weap_index], ammo);
850
851 // now add it
852 Players[slot].weapon_ammo[weap_index] += (uint16_t)added;
853 }
854
855 if (slot == Player_num) {
856 if (weap_index < SECONDARY_INDEX)
857 select_new = AutoSelectWeapon(PW_PRIMARY, weap_index);
858 else
859 select_new = AutoSelectWeapon(PW_SECONDARY, weap_index);
860
861 // this should be done in multisafe code now.
862 // if (!select_new) {
863 // AddHUDMessage ("%s!",TXT(Static_weapon_names_msg[weap_index]));
864 //}
865 }
866
867 return 1;
868}
869
870///////////////////////////////////////////////////////////////////////////
871// Weapon selection

Callers 2

msafe_CallFunctionFunction · 0.85
HandleWeaponPowerupsFunction · 0.85

Calls 1

AutoSelectWeaponFunction · 0.85

Tested by

no test coverage detected