Merged Lyberta/URS2 into Lyberta/RandomStartWeapons.
authorLyberta <lyberta@lyberta.net>
Tue, 29 Aug 2017 23:42:35 +0000 (02:42 +0300)
committerLyberta <lyberta@lyberta.net>
Tue, 29 Aug 2017 23:42:35 +0000 (02:42 +0300)
1  2 
qcsrc/common/t_items.qc
qcsrc/common/t_items.qh

@@@ -682,115 -682,37 +682,117 @@@ void Item_ScheduleInitialRespawn(entit
        Item_ScheduleRespawnIn(e, max(0, game_starttime - time) + ((e.respawntimestart) ? e.respawntimestart : ITEM_RESPAWNTIME_INITIAL(e)));
  }
  
- float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax)
 +void GiveRandomWeapons(entity receiver, int num_weapons, string weapon_names,
 +      float shells, float bullets, float rockets, float cells, float plasma)
 +{
 +      if (num_weapons == 0)
 +      {
 +              return;
 +      }
 +      int num_potential_weapons = tokenize_console(weapon_names);
 +      for (int i = 0; i < num_weapons; ++i)
 +      {
 +              RandomSelection_Init();
 +              for (int j = 0; j < num_potential_weapons; ++j)
 +              {
 +                      string weapon = argv(j);
 +                      FOREACH(Weapons, it != WEP_Null,
 +                      {
 +                              // Finding a weapon which player doesn't have.
 +                              if (!(receiver.weapons & it.m_wepset) && (it.netname == weapon))
 +                              {
 +                                      RandomSelection_AddEnt(it, 1, 1);
 +                                      break;
 +                              }
 +                      });
 +              }
 +              if (RandomSelection_chosen_ent == NULL)
 +              {
 +                      return;
 +              }
 +              receiver.weapons |= RandomSelection_chosen_ent.m_wepset;
 +              switch (RandomSelection_chosen_ent.ammo_field)
 +              {
 +                      case (ammo_shells):
 +                      {
 +                              if (GetResourceAmount(receiver, RESOURCE_SHELLS) != 0)
 +                              {
 +                                      break;
 +                              }
 +                              GiveResource(receiver, RESOURCE_SHELLS, shells);
 +                              break;
 +                      }
 +                      case (ammo_nails):
 +                      {
 +                              if (GetResourceAmount(receiver, RESOURCE_BULLETS) != 0)
 +                              {
 +                                      break;
 +                              }
 +                              GiveResource(receiver, RESOURCE_BULLETS, bullets);
 +                              break;
 +                      }
 +                      case (ammo_rockets):
 +                      {
 +                              if (GetResourceAmount(receiver, RESOURCE_ROCKETS) != 0)
 +                              {
 +                                      break;
 +                              }
 +                              GiveResource(receiver, RESOURCE_ROCKETS, rockets);
 +                              break;
 +                      }
 +                      case (ammo_cells):
 +                      {
 +                              if (GetResourceAmount(receiver, RESOURCE_CELLS) != 0)
 +                              {
 +                                      break;
 +                              }
 +                              GiveResource(receiver, RESOURCE_CELLS, cells);
 +                              break;
 +                      }
 +                      case (ammo_plasma):
 +                      {
 +                              if (GetResourceAmount(receiver, RESOURCE_PLASMA) != 0)
 +                              {
 +                                      break;
 +                              }
 +                              GiveResource(receiver, RESOURCE_PLASMA, plasma);
 +                              break;
 +                      }
 +              }
 +      }
 +}
 +
+ float Item_GiveAmmoTo(entity item, entity player, int resource_type, float ammomax)
  {
-       if (!item.(ammotype))
+       float amount = GetResourceAmount(item, resource_type);
+       if (amount == 0)
+       {
                return false;
+       }
+       float player_amount = GetResourceAmount(player, resource_type);
        if (item.spawnshieldtime)
        {
-               if ((player.(ammotype) < ammomax) || item.pickup_anyway > 0)
+               if ((player_amount >= ammomax) && (item.pickup_anyway <= 0))
                {
-                       float amount = item.(ammotype);
-                       if ((player.(ammotype) + amount) > ammomax)
-                       {
-                               amount = ammomax - player.(ammotype);
-                       }
-                       GiveResource(player, GetResourceType(ammotype), amount);
-                       return true;
+                       return false;
                }
-       }
-       else if(g_weapon_stay == 2)
-       {
-               float mi = min(item.(ammotype), ammomax);
-               if (player.(ammotype) < mi)
+               if ((player_amount + amount) > ammomax)
                {
-                       GiveResource(player, GetResourceType(ammotype), mi -
-                               player.(ammotype));
+                       amount = ammomax - player_amount;
                }
+               GiveResource(player, resource_type, amount);
                return true;
        }
-       return false;
+       if (g_weapon_stay != 2)
+       {
+               return false;
+       }
+       float mi = min(amount, ammomax);
+       if (player_amount < mi)
+       {
+               GiveResource(player, resource_type, mi - player_amount);
+       }
+       return true;
  }
  
  float Item_GiveTo(entity item, entity player)
@@@ -84,20 -84,7 +84,20 @@@ void Item_ScheduleRespawn(entity e)
  
  void Item_ScheduleInitialRespawn(entity e);
  
- float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax);
 +/// \brief Give several random weapons and ammo to the entity.
 +/// \param[in,out] receiver Entity to give weapons to.
 +/// \param[in] num_weapons Number of weapons to give.
 +/// \param[in] weapon_names Names of weapons to give separated by spaces.
 +/// \param[in] shells Amount of shells to give with shell-based weapon.
 +/// \param[in] bullets Amount of bullets to give with bullet-based weapon.
 +/// \param[in] rockets Amount of rockets to give with rocket-based weapon.
 +/// \param[in] cells Amount of cells to give with cell-based weapon.
 +/// \param[in] plasma Amount of plasma to give with plasma-based weapon.
 +/// \return No return.
 +void GiveRandomWeapons(entity receiver, int num_weapons, string weapon_names,
 +      float shells, float bullets, float rockets, float cells, float plasma);
 +
+ float Item_GiveAmmoTo(entity item, entity player, int resource_type, float ammomax);
  
  float Item_GiveTo(entity item, entity player);