From: terencehill Date: Thu, 21 Feb 2019 18:16:11 +0000 (+0100) Subject: Improve SetResource description. Convert some floats to bools X-Git-Tag: xonotic-v0.8.5~1594 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=0956bbb0845e58e200a91814175f9021eb76e983;p=xonotic%2Fxonotic-data.pk3dir.git Improve SetResource description. Convert some floats to bools --- diff --git a/qcsrc/common/t_items.qc b/qcsrc/common/t_items.qc index 2bea084b2..9edea4fb6 100644 --- a/qcsrc/common/t_items.qc +++ b/qcsrc/common/t_items.qc @@ -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) diff --git a/qcsrc/common/t_items.qh b/qcsrc/common/t_items.qh index f03d3d487..a0321c244 100644 --- a/qcsrc/common/t_items.qh +++ b/qcsrc/common/t_items.qh @@ -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); diff --git a/qcsrc/server/resources.qh b/qcsrc/server/resources.qh index f93db58fc..149ef9b88 100644 --- a/qcsrc/server/resources.qh +++ b/qcsrc/server/resources.qh @@ -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.