From: Mario Date: Sat, 31 Dec 2022 17:49:15 +0000 (+0000) Subject: Clean up ammo_pickupevalfunc to not reference items directly X-Git-Tag: xonotic-v0.8.6~236^2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2ca758ca1e7a31eff9920065fe427d59f79ff4d9;p=xonotic%2Fxonotic-data.pk3dir.git Clean up ammo_pickupevalfunc to not reference items directly --- diff --git a/qcsrc/server/items/items.qc b/qcsrc/server/items/items.qc index 33e6edc01..347e956a3 100644 --- a/qcsrc/server/items/items.qc +++ b/qcsrc/server/items/items.qc @@ -821,24 +821,21 @@ float weapon_pickupevalfunc(entity player, entity item) float ammo_pickupevalfunc(entity player, entity item) { - bool need_shells = false, need_nails = false, need_rockets = false, need_cells = false, need_plasma = false, need_fuel = false; + entity item_resource = NULL; // pointer to the resource that may be associated with the given item entity wpn = NULL; float c = 0; float rating = 0; - // Detect needed ammo + // detect needed ammo if(item.itemdef.instanceOfWeaponPickup) { - entity ammo = NULL; - if(GetResource(item, RES_SHELLS)) { need_shells = true; ammo = ITEM_Shells; } - else if(GetResource(item, RES_BULLETS)) { need_nails = true; ammo = ITEM_Bullets; } - else if(GetResource(item, RES_ROCKETS)) { need_rockets = true; ammo = ITEM_Rockets; } - else if(GetResource(item, RES_CELLS)) { need_cells = true; ammo = ITEM_Cells; } - else if(GetResource(item, RES_PLASMA)) { need_plasma = true; ammo = ITEM_Plasma; } - else if(GetResource(item, RES_FUEL)) { need_fuel = true; ammo = ITEM_JetpackFuel; } - + entity res = item.itemdef.m_weapon.ammo_type; + entity ammo = (res != RES_NONE) ? GetAmmoItem(res) : NULL; if(!ammo) return 0; + if(res != RES_NONE && GetResource(item, res)) + item_resource = res; + wpn = item; rating = ammo.m_botvalue; } @@ -847,15 +844,13 @@ float ammo_pickupevalfunc(entity player, entity item) FOREACH(Weapons, it != WEP_Null, { if(!(STAT(WEAPONS, player) & (it.m_wepset))) continue; + if(it.ammo_type == RES_NONE) + continue; - switch(it.ammo_type) + if(GetResource(item, it.ammo_type)) { - case RES_SHELLS: need_shells = true; break; - case RES_BULLETS: need_nails = true; break; - case RES_ROCKETS: need_rockets = true; break; - case RES_CELLS: need_cells = true; break; - case RES_PLASMA: need_plasma = true; break; - case RES_FUEL: need_fuel = true; break; + item_resource = it.ammo_type; + break; } }); rating = item.bot_pickupbasevalue; @@ -863,23 +858,8 @@ float ammo_pickupevalfunc(entity player, entity item) float noammorating = 0.5; - if ((need_shells) && GetResource(item, RES_SHELLS) && (GetResource(player, RES_SHELLS) < g_pickup_shells_max)) - c = GetResource(item, RES_SHELLS) / max(noammorating, GetResource(player, RES_SHELLS)); - - if ((need_nails) && GetResource(item, RES_BULLETS) && (GetResource(player, RES_BULLETS) < g_pickup_nails_max)) - c = GetResource(item, RES_BULLETS) / max(noammorating, GetResource(player, RES_BULLETS)); - - if ((need_rockets) && GetResource(item, RES_ROCKETS) && (GetResource(player, RES_ROCKETS) < g_pickup_rockets_max)) - c = GetResource(item, RES_ROCKETS) / max(noammorating, GetResource(player, RES_ROCKETS)); - - if ((need_cells) && GetResource(item, RES_CELLS) && (GetResource(player, RES_CELLS) < g_pickup_cells_max)) - c = GetResource(item, RES_CELLS) / max(noammorating, GetResource(player, RES_CELLS)); - - if ((need_plasma) && GetResource(item, RES_PLASMA) && (GetResource(player, RES_PLASMA) < g_pickup_plasma_max)) - c = GetResource(item, RES_PLASMA) / max(noammorating, GetResource(player, RES_PLASMA)); - - if ((need_fuel) && GetResource(item, RES_FUEL) && (GetResource(player, RES_FUEL) < g_pickup_fuel_max)) - c = GetResource(item, RES_FUEL) / max(noammorating, GetResource(player, RES_FUEL)); + if(item_resource && (GetResource(player, item_resource) < GetResourceLimit(player, item_resource))) + c = GetResource(item, item_resource) / max(noammorating, GetResource(player, item_resource)); rating *= min(c, 2); if(wpn)