]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/t_items.qc
Added random start weapons.
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / t_items.qc
index 1e5f8284cb3b2bcdd5c9da1fd841dfc5a86a90f3..4c0125afb687c923ac92e1fcd068232e03e19482 100644 (file)
@@ -648,6 +648,150 @@ void Item_ScheduleInitialRespawn(entity e)
        Item_ScheduleRespawnIn(e, max(0, game_starttime - time) + ((e.respawntimestart) ? e.respawntimestart : ITEM_RESPAWNTIME_INITIAL(e)));
 }
 
+void GivePlayerHealth(entity player, float amount)
+{
+       if (amount == 0)
+       {
+               return;
+       }
+       player.health = bound(player.health, player.health + amount,
+                g_pickup_healthmega_max);
+       player.pauserothealth_finished = max(player.pauserothealth_finished, time +
+               autocvar_g_balance_pause_health_rot);
+}
+
+void GivePlayerArmor(entity player, float amount)
+{
+       if (amount == 0)
+       {
+               return;
+       }
+       player.armorvalue = bound(player.armorvalue, player.armorvalue + amount,
+                g_pickup_armormega_max);
+       player.pauserotarmor_finished = max(player.pauserotarmor_finished, time +
+               autocvar_g_balance_pause_armor_rot);
+}
+
+void GivePlayerAmmo(entity player, .float ammotype, float amount)
+{
+       float maxvalue = 999;
+       switch (ammotype)
+       {
+               case ammo_shells:
+               {
+                       maxvalue = g_pickup_shells_max;
+                       break;
+               }
+               case ammo_cells:
+               {
+                       maxvalue = g_pickup_cells_max;
+                       break;
+               }
+               case ammo_rockets:
+               {
+                       maxvalue = g_pickup_rockets_max;
+                       break;
+               }
+               case ammo_plasma:
+               {
+                       maxvalue = g_pickup_plasma_max;
+                       break;
+               }
+               case ammo_nails:
+               {
+                       maxvalue = g_pickup_nails_max;
+                       break;
+               }
+               case ammo_fuel:
+               {
+                       maxvalue = g_pickup_fuel_max;
+                       break;
+               }
+       }
+       player.(ammotype) = min(player.(ammotype) + amount, maxvalue);
+}
+
+void GivePlayerRandomWeapons(entity player, 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 (!(player.weapons & it.m_wepset) && (it.netname == weapon))
+                               {
+                                       RandomSelection_AddEnt(it, 1, 1);
+                                       break;
+                               }
+                       });
+               }
+               if (RandomSelection_chosen_ent == NULL)
+               {
+                       return;
+               }
+               player.weapons |= RandomSelection_chosen_ent.m_wepset;
+               switch (RandomSelection_chosen_ent.ammo_field)
+               {
+                       case (ammo_shells):
+                       {
+                               if (player.ammo_shells != 0)
+                               {
+                                       break;
+                               }
+                               GivePlayerAmmo(player, ammo_shells, shells);
+                               break;
+                       }
+                       case (ammo_nails):
+                       {
+                               if (player.ammo_nails != 0)
+                               {
+                                       break;
+                               }
+                               GivePlayerAmmo(player, ammo_nails, bullets);
+                               break;
+                       }
+                       case (ammo_rockets):
+                       {
+                               if (player.ammo_rockets != 0)
+                               {
+                                       break;
+                               }
+                               GivePlayerAmmo(player, ammo_rockets, rockets);
+                               break;
+                       }
+                       case (ammo_cells):
+                       {
+                               if (player.ammo_cells != 0)
+                               {
+                                       break;
+                               }
+                               GivePlayerAmmo(player, ammo_cells, cells);
+                               break;
+                       }
+                       case (ammo_plasma):
+                       {
+                               if (player.ammo_plasma != 0)
+                               {
+                                       break;
+                               }
+                               GivePlayerAmmo(player, ammo_plasma, plasma);
+                               break;
+                       }
+               }
+       }
+}
+
 float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax, float mode)
 {
        if (!item.(ammotype))
@@ -702,7 +846,7 @@ float Item_GiveTo(entity item, entity player)
        // if the player is using their best weapon before items are given, they
        // probably want to switch to an even better weapon after items are given
 
-       if(player.autoswitch)
+       if(CS(player).autoswitch)
        {
                for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
                {
@@ -1373,7 +1517,7 @@ spawnfunc(item_rockets)
 
 spawnfunc(item_bullets)
 {
-       if(!weaponswapping && autocvar_sv_q3acompat_machineshotgunswap && 
+       if(!weaponswapping && autocvar_sv_q3acompat_machineshotgunswap &&
           (this.classname != "droppedweapon"))
        {
                weaponswapping = true;
@@ -1730,7 +1874,7 @@ float GiveItems(entity e, float beginarg, float endarg)
 
        int _switchweapon = 0;
 
-       if(e.autoswitch)
+       if(CS(e).autoswitch)
        {
                for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
                {