]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Improve SetResource description. Convert some floats to bools
authorterencehill <piuntn@gmail.com>
Thu, 21 Feb 2019 18:16:11 +0000 (19:16 +0100)
committerterencehill <piuntn@gmail.com>
Thu, 21 Feb 2019 18:16:11 +0000 (19:16 +0100)
qcsrc/common/t_items.qc
qcsrc/common/t_items.qh
qcsrc/server/resources.qh

index 2bea084b20ef5f2e07a6b55e13e3975d1ac04a01..9edea4fb698cc3aaece7449bbb2d47e9c96f25f9 100644 (file)
@@ -732,7 +732,7 @@ void GiveRandomWeapons(entity receiver, int num_weapons, string weapon_names,
        }
 }
 
-float Item_GiveAmmoTo(entity item, entity player, int res_type, float ammomax)
+bool Item_GiveAmmoTo(entity item, entity player, int res_type, float ammomax)
 {
        float amount = GetResource(item, res_type);
        if (amount == 0)
@@ -757,12 +757,9 @@ float Item_GiveAmmoTo(entity item, entity player, int res_type, float ammomax)
        return true;
 }
 
-float Item_GiveTo(entity item, entity player)
+bool Item_GiveTo(entity item, entity player)
 {
-       float pickedup;
-
        // if nothing happens to player, just return without taking the item
-       pickedup = false;
        int _switchweapon = 0;
        // in case the player has autoswitch enabled do the following:
        // if the player is using their best weapon before items are given, they
@@ -783,14 +780,15 @@ float Item_GiveTo(entity item, entity player)
                        }
                }
        }
-       pickedup |= Item_GiveAmmoTo(item, player, RES_HEALTH, item.max_health);
-       pickedup |= Item_GiveAmmoTo(item, player, RES_ARMOR, item.max_armorvalue);
-       pickedup |= Item_GiveAmmoTo(item, player, RES_SHELLS, g_pickup_shells_max);
-       pickedup |= Item_GiveAmmoTo(item, player, RES_BULLETS, g_pickup_nails_max);
-       pickedup |= Item_GiveAmmoTo(item, player, RES_ROCKETS, g_pickup_rockets_max);
-       pickedup |= Item_GiveAmmoTo(item, player, RES_CELLS, g_pickup_cells_max);
-       pickedup |= Item_GiveAmmoTo(item, player, RES_PLASMA, g_pickup_plasma_max);
-       pickedup |= Item_GiveAmmoTo(item, player, RES_FUEL, g_pickup_fuel_max);
+       bool pickedup = false;
+       pickedup = pickedup || Item_GiveAmmoTo(item, player, RES_HEALTH, item.max_health);
+       pickedup = pickedup || Item_GiveAmmoTo(item, player, RES_ARMOR, item.max_armorvalue);
+       pickedup = pickedup || Item_GiveAmmoTo(item, player, RES_SHELLS, g_pickup_shells_max);
+       pickedup = pickedup || Item_GiveAmmoTo(item, player, RES_BULLETS, g_pickup_nails_max);
+       pickedup = pickedup || Item_GiveAmmoTo(item, player, RES_ROCKETS, g_pickup_rockets_max);
+       pickedup = pickedup || Item_GiveAmmoTo(item, player, RES_CELLS, g_pickup_cells_max);
+       pickedup = pickedup || Item_GiveAmmoTo(item, player, RES_PLASMA, g_pickup_plasma_max);
+       pickedup = pickedup || Item_GiveAmmoTo(item, player, RES_FUEL, g_pickup_fuel_max);
        if (item.itemdef.instanceOfWeaponPickup)
        {
                WepSet w;
@@ -853,7 +851,7 @@ float Item_GiveTo(entity item, entity player)
                pickedup = true;
 
        if (!pickedup)
-               return 0;
+               return false;
 
        // crude hack to enforce switching weapons
        if(g_cts && item.itemdef.instanceOfWeaponPickup && !CS(player).cvar_cl_cts_noautoswitch)
@@ -864,7 +862,7 @@ float Item_GiveTo(entity item, entity player)
                        if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
                                W_SwitchWeapon_Force(player, Weapons_from(item.weapon), weaponentity);
                }
-               return 1;
+               return true;
        }
 
        if(_switchweapon)
@@ -878,7 +876,7 @@ float Item_GiveTo(entity item, entity player)
                }
        }
 
-       return 1;
+       return true;
 }
 
 void Item_Touch(entity this, entity toucher)
index f03d3d48702ca166a2eb25377cf0252b48eb3ee4..a0321c2444961234305f7689ef5d32b8d0008685 100644 (file)
@@ -79,12 +79,11 @@ void Item_ScheduleInitialRespawn(entity e);
 /// \param[in] weapon_names Names of weapons to give separated by spaces.
 /// \param[in] ammo Entity containing the ammo amount for each possible weapon.
 /// \return No return.
-void GiveRandomWeapons(entity receiver, int num_weapons, string weapon_names,
-       entity ammo_entity);
+void GiveRandomWeapons(entity receiver, int num_weapons, string weapon_names, entity ammo_entity);
 
-float Item_GiveAmmoTo(entity item, entity player, int res_type, float ammomax);
+bool Item_GiveAmmoTo(entity item, entity player, int res_type, float ammomax);
 
-float Item_GiveTo(entity item, entity player);
+bool Item_GiveTo(entity item, entity player);
 
 void Item_Touch(entity this, entity toucher);
 
index f93db58fc324387b97b50e69da7e8f3319049a9d..149ef9b88e95bff5ce66229bb92272ef759d5f30 100644 (file)
@@ -28,7 +28,8 @@ float GetResource(entity e, int res_type);
 /// \return Boolean for whether the ammo amount was changed
 bool SetResourceExplicit(entity e, int res_type, float amount);
 
-/// \brief Sets the current amount of resource the given entity will have.
+/// \brief Sets the current amount of resource the given entity will have
+/// but limited to the max amount allowed for the resource type.
 /// \param[in,out] e Entity to adjust.
 /// \param[in] res_type Type of the resource (a RES_* constant).
 /// \param[in] amount Amount of resource to set.