]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'Lyberta/URS2' into Lyberta/RandomStartWeapons
authorLyberta <lyberta@lyberta.net>
Wed, 30 Aug 2017 05:07:32 +0000 (08:07 +0300)
committerLyberta <lyberta@lyberta.net>
Wed, 30 Aug 2017 05:07:32 +0000 (08:07 +0300)
1  2 
qcsrc/common/t_items.qc

diff --combined qcsrc/common/t_items.qc
index ba168fd6f51f64573f3cb10f7c8143f3dab27044,4fc2e38219c144e2a5801129419847e2444c4808..454965ed658e67f515f85226ecdd88a6b344fb71
@@@ -682,86 -682,6 +682,86 @@@ void Item_ScheduleInitialRespawn(entit
        Item_ScheduleRespawnIn(e, max(0, game_starttime - time) + ((e.respawntimestart) ? e.respawntimestart : ITEM_RESPAWNTIME_INITIAL(e)));
  }
  
 +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)
  {
        float amount = GetResourceAmount(item, resource_type);
                {
                        return false;
                }
-               if ((player_amount + amount) > ammomax)
-               {
-                       amount = ammomax - player_amount;
-               }
-               GiveResource(player, resource_type, amount);
+               GiveResourceWithLimit(player, resource_type, amount, ammomax);
                return true;
        }
        if (g_weapon_stay != 2)
        {
                return false;
        }
-       float mi = min(amount, ammomax);
-       if (player_amount < mi)
-       {
-               GiveResource(player, resource_type, mi - player_amount);
-       }
+       GiveResourceWithLimit(player, resource_type, amount, min(amount, ammomax));
        return true;
  }