0
0
Fork 0
mirror of https://github.com/nzp-team/quakec.git synced 2025-04-13 13:32:44 +00:00

Merge pull request from Peter0x44/main

SERVER: Refactor W_Give_Ammo, ensure only the needed ammo gets added to the magazine
This commit is contained in:
cypress 2025-02-11 19:21:54 -08:00 committed by GitHub
commit 70b01aa279
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -280,31 +280,37 @@ void(float side) W_Give_Ammo =
if (self.weapons[0].weapon_reserve == 0)
return;
float ammo_shot, max_mag, loadammo;
float ammo_needed, max_mag, loadammo;
max_mag = getWeaponMag(self.weapon);
// Determine how much ammo is needed to reload the selected side
if (side == S_LEFT) {
ammo_shot = max_mag - self.weapons[0].weapon_magazine_left;
ammo_needed = max_mag - self.weapons[0].weapon_magazine_left;
} else {
ammo_shot = max_mag - self.weapons[0].weapon_magazine;
ammo_needed = max_mag - self.weapons[0].weapon_magazine;
}
if (ammo_shot < self.weapons[0].weapon_reserve)
// Ensure we don't take more ammo than is in the reserve
if (ammo_needed > self.weapons[0].weapon_reserve)
{
self.weapons[0].weapon_reserve = self.weapons[0].weapon_reserve - ammo_shot;
loadammo = self.weapons[0].weapon_reserve;
loadammo = max_mag;
// Deplete reserve
self.weapons[0].weapon_reserve = 0;
}
else
{
loadammo = self.weapons[0].weapon_magazine + self.weapons[0].weapon_reserve;
self.weapons[0].weapon_reserve = 0;
// Load the ammo needed to fill the magazine, and subtract it from the reserve
loadammo = ammo_needed;
self.weapons[0].weapon_reserve -= ammo_needed;
}
// Apply ammo load to the correct side
if (side == S_LEFT) {
self.weapons[0].weapon_magazine_left = loadammo;
self.weapons[0].weapon_magazine_left += loadammo;
} else {
self.weapons[0].weapon_magazine = loadammo;
self.weapons[0].weapon_magazine += loadammo;
}
};
@ -2186,4 +2192,4 @@ void() WeaponCore_ClientLogic =
// Allow Melee to be pressed again
self.semi_actions &= ~SEMIACTION_MELEE;
}
};
};