]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/t_items.qc
Merge branch 'Lyberta/URS2' into Lyberta/RandomStartWeapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / t_items.qc
index 4fc2e38219c144e2a5801129419847e2444c4808..454965ed658e67f515f85226ecdd88a6b344fb71 100644 (file)
@@ -682,6 +682,86 @@ void Item_ScheduleInitialRespawn(entity e)
        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);