]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
URS: Refactored Item_GiveAmmoTo.
authorLyberta <lyberta@lyberta.net>
Tue, 29 Aug 2017 01:38:48 +0000 (04:38 +0300)
committerLyberta <lyberta@lyberta.net>
Tue, 29 Aug 2017 01:38:48 +0000 (04:38 +0300)
qcsrc/common/t_items.qc
qcsrc/common/t_items.qh

index 3873a455026f2bff402571bee52add777d1147c2..9ea5a6543bdc2ab99432dd587f67806024671d2a 100644 (file)
@@ -682,35 +682,37 @@ void Item_ScheduleInitialRespawn(entity e)
        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)
+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)
@@ -739,14 +741,14 @@ float Item_GiveTo(entity item, entity player)
                        }
                }
        }
-       pickedup |= Item_GiveAmmoTo(item, player, health, item.max_health);
-       pickedup |= Item_GiveAmmoTo(item, player, armorvalue, item.max_armorvalue);
-       pickedup |= Item_GiveAmmoTo(item, player, ammo_shells, g_pickup_shells_max);
-       pickedup |= Item_GiveAmmoTo(item, player, ammo_nails, g_pickup_nails_max);
-       pickedup |= Item_GiveAmmoTo(item, player, ammo_rockets, g_pickup_rockets_max);
-       pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, g_pickup_cells_max);
-       pickedup |= Item_GiveAmmoTo(item, player, ammo_plasma, g_pickup_plasma_max);
-       pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max);
+       pickedup |= Item_GiveAmmoTo(item, player, RESOURCE_HEALTH, item.max_health);
+       pickedup |= Item_GiveAmmoTo(item, player, RESOURCE_ARMOR, item.max_armorvalue);
+       pickedup |= Item_GiveAmmoTo(item, player, RESOURCE_SHELLS, g_pickup_shells_max);
+       pickedup |= Item_GiveAmmoTo(item, player, RESOURCE_BULLETS, g_pickup_nails_max);
+       pickedup |= Item_GiveAmmoTo(item, player, RESOURCE_ROCKETS, g_pickup_rockets_max);
+       pickedup |= Item_GiveAmmoTo(item, player, RESOURCE_CELLS, g_pickup_cells_max);
+       pickedup |= Item_GiveAmmoTo(item, player, RESOURCE_PLASMA, g_pickup_plasma_max);
+       pickedup |= Item_GiveAmmoTo(item, player, RESOURCE_FUEL, g_pickup_fuel_max);
        if (item.itemdef.instanceOfWeaponPickup)
        {
                WepSet w;
index ac77917914d5528b9654883c8a4f8bca2d9bafc6..fa78ff4b334ea9ede118f7817c81f02de9c0387d 100644 (file)
@@ -84,7 +84,7 @@ void Item_ScheduleRespawn(entity e);
 
 void Item_ScheduleInitialRespawn(entity e);
 
-float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax);
+float Item_GiveAmmoTo(entity item, entity player, int resource_type, float ammomax);
 
 float Item_GiveTo(entity item, entity player);