From e95bb23b5b8376fc6b5a52949ea7e0e3e3ec2f37 Mon Sep 17 00:00:00 2001 From: Cong Xu Date: Sun, 19 Aug 2018 15:05:01 +1000 Subject: [PATCH] Fix picking up grenades with wrong ammo (#513) --- src/cdogs/pickup.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cdogs/pickup.c b/src/cdogs/pickup.c index 06637c65a..9bd616840 100644 --- a/src/cdogs/pickup.c +++ b/src/cdogs/pickup.c @@ -265,8 +265,17 @@ static bool HasGunUsingAmmo(const TActor *a, const int ammoId) static bool TryPickupAmmo(TActor *a, const Pickup *p, const char **sound) { + // Don't pickup if not using ammo + if (!ConfigGetBool(&gConfig, "Game.Ammo")) + { + return false; + } // Don't pickup if ammo full - const Ammo *ammo = AmmoGetById(&gAmmo, p->class->u.Ammo.Id); + const Ammo *ammo = AmmoGetById( + &gAmmo, + p->class->Type == PICKUP_AMMO ? + p->class->u.Ammo.Id : + IdWeaponClass(p->class->u.GunId)->AmmoId); const int current = *(int *)CArrayGet(&a->ammo, p->class->u.Ammo.Id); if (current >= ammo->Max) { @@ -294,7 +303,10 @@ static bool TryPickupGun( { return false; } - const WeaponClass *wc = IdWeaponClass(p->class->u.GunId); + const WeaponClass *wc = + p->class->Type == PICKUP_GUN ? + IdWeaponClass(p->class->u.GunId) : + StrWeaponClass(AmmoGetById(&gAmmo, p->class->u.Ammo.Id)->DefaultGun); int ammoDeficit = 0; const Ammo *ammo = NULL;