]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
g_weapon_stay 2: ghost items "refill" ammo only
authorRudolf Polzer <divverent@alientrap.org>
Sat, 17 Dec 2011 16:45:57 +0000 (17:45 +0100)
committerRudolf Polzer <divverent@alientrap.org>
Sat, 17 Dec 2011 16:50:38 +0000 (17:50 +0100)
qcsrc/server/cl_weapons.qc
qcsrc/server/t_items.qc

index c16be3748aca0bb6388b6555b28a347037c177b9..a7592b4cbb67d8e740dc635d791b9c3c75ce6b88 100644 (file)
@@ -220,7 +220,25 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto
                self = oldself;
                if(startitem_failed)
                        return string_null;
-               if(doreduce)
+               if(doreduce && g_weapon_stay == 2)
+               {
+                       for(i = 0, j = 1; i < 24; ++i, j *= 2)
+                       {
+                               if(wa & j)
+                               {
+                                       ammofield = Item_CounterField(j);
+                                       wep.ammofield = 0;
+
+                                       // if our weapon is loaded, give its load back to the player
+                                       if(self.(weapon_load[self.weapon]) > 0)
+                                       {
+                                               own.ammofield += self.(weapon_load[self.weapon]);
+                                               self.(weapon_load[self.weapon]) = -1; // schedule the weapon for reloading
+                                       }
+                               }
+                       }
+               }
+               else if(doreduce)
                {
                        for(i = 0, j = 1; i < 24; ++i, j *= 2)
                        {
index dfe1a5cb0bdd203d9eed0e7ab7faf72309a27159..3715e08c8962e38157f690a47b8ace2bd0ab0082 100644 (file)
@@ -281,6 +281,41 @@ void Item_ScheduleInitialRespawn(entity e)
        Item_ScheduleRespawnIn(e, game_starttime - time + ITEM_RESPAWNTIME_INITIAL(e));
 }
 
+float Item_GiveAmmoTo(entity item, entity player, .float ammofield, float ammomax)
+{
+       if (!item.ammofield)
+               return FALSE;
+
+       if (item.spawnshieldtime)
+       {
+               if ((player.ammofield < ammomax) || item.pickup_anyway)
+               {
+                       player.ammofield = bound(player.ammofield, ammomax, player.ammofield + item.ammo_cells);
+                       goto YEAH;
+               }
+       }
+       else if(g_weapon_stay == 2)
+       {
+               float mi = min(item.ammofield, ammomax);
+               if ((player.ammofield < mi) || item.pickup_anyway)
+               {
+                       player.ammofield = max(player.ammofield, mi);
+                       goto YEAH;
+               }
+       }
+
+       return FALSE;
+
+:YEAH
+       if(ammofield == ammo_fuel)
+               player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
+       if(ammofield == health)
+               player.pauserothealth_finished = max(player.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
+       if(ammofield == armorvalue)
+               player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + autocvar_g_balance_pause_armor_rot);
+       return TRUE;
+}
+
 float Item_GiveTo(entity item, entity player)
 {
        float _switchweapon;
@@ -297,23 +332,8 @@ float Item_GiveTo(entity item, entity player)
        {
                float prevcells = player.ammo_cells;
 
-               if(item.spawnshieldtime)
-               {
-                       if (item.ammo_fuel)
-                       if (player.ammo_fuel < g_pickup_fuel_max)
-                       {
-                               pickedup = TRUE;
-                               player.ammo_fuel = bound(player.ammo_fuel, g_pickup_fuel_max, player.ammo_fuel + item.ammo_fuel);
-                               player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
-                       }
-
-                       if (item.ammo_cells)
-                       if (player.ammo_cells < g_pickup_cells_max)
-                       {
-                               pickedup = TRUE;
-                               player.ammo_cells = bound(player.ammo_cells, g_pickup_cells_max, player.ammo_cells + item.ammo_cells);
-                       }
-               }
+               Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max);
+               Item_GiveAmmoTo(item, player, ammo_cells, 999);
 
                if(player.ammo_cells > prevcells)
                {
@@ -385,40 +405,13 @@ float Item_GiveTo(entity item, entity player)
                if not(player.weapons & W_WeaponBit(player.switchweapon))
                        _switchweapon = TRUE;
 
-               if(item.spawnshieldtime)
-               {
-                       if (item.ammo_shells)
-                       if ((player.ammo_shells < g_pickup_shells_max) || item.pickup_anyway)
-                       {
-                               pickedup = TRUE;
-                               player.ammo_shells = bound(player.ammo_shells, g_pickup_shells_max, player.ammo_shells + item.ammo_shells);
-                       }
-                       if (item.ammo_nails)
-                       if ((player.ammo_nails < g_pickup_nails_max) || item.pickup_anyway)
-                       {
-                               pickedup = TRUE;
-                               player.ammo_nails = bound(player.ammo_nails, g_pickup_nails_max, player.ammo_nails + item.ammo_nails);
-                       }
-                       if (item.ammo_rockets)
-                       if ((player.ammo_rockets < g_pickup_rockets_max) || item.pickup_anyway)
-                       {
-                               pickedup = TRUE;
-                               player.ammo_rockets = bound(player.ammo_rockets, g_pickup_rockets_max, player.ammo_rockets + item.ammo_rockets);
-                       }
-                       if (item.ammo_cells)
-                       if ((player.ammo_cells < g_pickup_cells_max) || item.pickup_anyway)
-                       {
-                               pickedup = TRUE;
-                               player.ammo_cells = bound(player.ammo_cells, g_pickup_cells_max, player.ammo_cells + item.ammo_cells);
-                       }
-                       if (item.ammo_fuel)
-                       if ((player.ammo_fuel < g_pickup_fuel_max) || item.pickup_anyway)
-                       {
-                               pickedup = TRUE;
-                               player.ammo_fuel = bound(player.ammo_fuel, g_pickup_fuel_max, player.ammo_fuel + item.ammo_fuel);
-                               player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
-                       }
-               }
+               Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max);
+               Item_GiveAmmoTo(item, player, ammo_shells, g_pickup_shells_max);
+               Item_GiveAmmoTo(item, player, ammo_nails, g_pickup_nails_max);
+               Item_GiveAmmoTo(item, player, ammo_rockets, g_pickup_rockets_max);
+               Item_GiveAmmoTo(item, player, ammo_cells, g_pickup_cells_max);
+               Item_GiveAmmoTo(item, player, health, item.max_health);
+               Item_GiveAmmoTo(item, player, armorvalue, item.max_armorvalue);
 
                if (item.flags & FL_WEAPON)
                if ((it = item.weapons - (item.weapons & player.weapons)) || (g_pickup_weapons_anyway))
@@ -439,7 +432,7 @@ float Item_GiveTo(entity item, entity player)
                        sprint (player, strcat("You got the ^2", item.netname, "\n"));
                }
 
-                       if (item.strength_finished)
+               if (item.strength_finished)
                {
                        pickedup = TRUE;
                        player.strength_finished = max(player.strength_finished, time) + autocvar_g_balance_powerup_strength_time;
@@ -449,21 +442,6 @@ float Item_GiveTo(entity item, entity player)
                        pickedup = TRUE;
                        player.invincible_finished = max(player.invincible_finished, time) + autocvar_g_balance_powerup_invincible_time;
                }
-
-               if (item.health)
-               if ((player.health < item.max_health) || item.pickup_anyway)
-               {
-                       pickedup = TRUE;
-                       player.health = bound(player.health, item.max_health, player.health + item.health);
-                       player.pauserothealth_finished = max(player.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
-               }
-               if (item.armorvalue)
-               if ((player.armorvalue < item.max_armorvalue) || item.pickup_anyway)
-               {
-                       pickedup = TRUE;
-                       player.armorvalue = bound(player.armorvalue, item.max_armorvalue, player.armorvalue + item.armorvalue);
-                       player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + autocvar_g_balance_pause_armor_rot);
-               }
        }
 
 :skip