Skip to content

Commit

Permalink
fix of reloading bug #878
Browse files Browse the repository at this point in the history
  • Loading branch information
redv committed Feb 6, 2015
1 parent 76b0d50 commit 247915f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Savegame/CraftWeapon.cpp
Expand Up @@ -130,15 +130,14 @@ void CraftWeapon::setRearming(bool rearming)
*/
int CraftWeapon::rearm(const int available, const int clipSize)
{
int needed = 0;
int ammoUsed = _rules->getRearmRate();

if (clipSize > 0)
{ // +(clipSize - 1) for correct rounding up
needed = std::min(_rules->getRearmRate(), _rules->getAmmoMax() - _ammo + clipSize - 1) / clipSize;
{ // +(clipSize - 1) correction for rounding up
int needed = std::min(_rules->getRearmRate(), _rules->getAmmoMax() - _ammo + clipSize - 1) / clipSize;
ammoUsed = ((needed > available)? available : needed) * clipSize;
}

int ammoUsed = (available >= needed)? _rules->getRearmRate() : available * clipSize;

setAmmo(_ammo + ammoUsed);

_rearming = _ammo < _rules->getAmmoMax();
Expand Down

0 comments on commit 247915f

Please sign in to comment.