<commit_before>/*
  Universal weapon upgrade code
  sfall 2.0a or higher is required

  by phobos2077 & NovaRain
*/

#ifndef UPGWEAP_H
#define UPGWEAP_H

#define PROTO_WP_MAG_SIZE    (96)

// upgrade weapons but don't reload them with fresh ammo
procedure upgrade_weapon(variable oldPid, variable newPid) begin
   variable ammoCnt, ammoPid, ammoMax;

   restock_obj := obj_carrying_pid_obj(dude_obj, oldPid);
   if (restock_obj) then begin
      ammoCnt := get_weapon_ammo_count(restock_obj);
      if ((critter_inven_obj(dude_obj, INVEN_TYPE_LEFT_HAND) == restock_obj) or (critter_inven_obj(dude_obj, INVEN_TYPE_RIGHT_HAND) == restock_obj)) then begin
         inven_unwield(dude_obj);
      end
      if (obj_item_subtype(restock_obj) == item_type_weapon) then begin
         ammoPid := get_weapon_ammo_pid(restock_obj);
         ammoMax := get_proto_data(newPid, PROTO_WP_MAG_SIZE);
         if (ammoCnt > ammoMax) then ammoCnt := ammoMax; // just in case
      end
      restock_amt := rm_mult_objs_from_inven(dude_obj, restock_obj, 1);
      destroy_object(restock_obj);
   end
   restock_amt := 0;
   restock_obj := create_object(newPid, 0, 0);
   if (ammoPid > 0) then set_weapon_ammo_pid(restock_obj, ammoPid);
   set_weapon_ammo_count(restock_obj, ammoCnt);
   add_mult_objs_to_inven(dude_obj, restock_obj, 1);
end

#endif<commit_msg>Fixed "argument is null" error for UPGWEAP.h.<commit_after>/*
  Universal weapon upgrade code
  sfall 2.0a or higher is required

  by phobos2077 & NovaRain
*/

#ifndef UPGWEAP_H
#define UPGWEAP_H

#define PROTO_WP_MAG_SIZE    (96)

// upgrade weapons but don't reload them with fresh ammo
procedure upgrade_weapon(variable oldPid, variable newPid) begin
   variable ammoCnt, ammoPid, ammoMax;

   restock_obj := obj_carrying_pid_obj(dude_obj, oldPid);
   if (restock_obj) then begin
      ammoCnt := get_weapon_ammo_count(restock_obj);
      if ((critter_inven_obj(dude_obj, INVEN_TYPE_LEFT_HAND) == restock_obj) or (critter_inven_obj(dude_obj, INVEN_TYPE_RIGHT_HAND) == restock_obj)) then begin
         inven_unwield(dude_obj);
      end
      if (obj_item_subtype(restock_obj) == item_type_weapon) then begin
         ammoPid := get_weapon_ammo_pid(restock_obj);
         ammoMax := get_proto_data(newPid, PROTO_WP_MAG_SIZE);
         if (ammoCnt > ammoMax) then ammoCnt := ammoMax; // just in case
      end
      restock_amt := rm_mult_objs_from_inven(dude_obj, restock_obj, 1);
      destroy_object(restock_obj);
   end
   restock_amt := 0;

   restock_obj := create_object(newPid, 0, 0);
   if (restock_obj) then begin
      if (ammoPid > 0) then set_weapon_ammo_pid(restock_obj, ammoPid);
      set_weapon_ammo_count(restock_obj, ammoCnt);
      add_mult_objs_to_inven(dude_obj, restock_obj, 1);
   end
end

#endif
{'fraction_non_alphanumeric': 0.08676789587852494, 'fraction_numerical': 0.01012292118582791, 'mean_word_length': 4.240530303030303, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7294305', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1081, 'n_words': 222}