From: Lyberta Date: Tue, 29 Aug 2017 01:38:48 +0000 (+0300) Subject: URS: Refactored Item_GiveAmmoTo. X-Git-Tag: xonotic-v0.8.5~2488^2~6 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=af0f63ab02ec6a3d1dcde4244a3193d26fedbac2;p=xonotic%2Fxonotic-data.pk3dir.git URS: Refactored Item_GiveAmmoTo. --- diff --git a/qcsrc/common/t_items.qc b/qcsrc/common/t_items.qc index 3873a4550..9ea5a6543 100644 --- a/qcsrc/common/t_items.qc +++ b/qcsrc/common/t_items.qc @@ -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; diff --git a/qcsrc/common/t_items.qh b/qcsrc/common/t_items.qh index ac7791791..fa78ff4b3 100644 --- a/qcsrc/common/t_items.qh +++ b/qcsrc/common/t_items.qh @@ -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);