Пример #1
0
/**
 * Rearms this craft weapon's ammo.
 */
void CraftWeapon::rearm()
{
	setAmmo(_ammo + _rules->getRearmRate());
	if (_ammo == _rules->getAmmoMax())
	{
		_rearming = false;
	}
}
Пример #2
0
/**
 * Rearms this craft weapon's ammo.
 * @param available number of clips available.
 * @param clipSize number of rounds in said clips.
 * @return number of clips used.
 */
int CraftWeapon::rearm(const int available, const int clipSize)
{
	int ammoUsed = _rules->getRearmRate();

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

	setAmmo(_ammo + ammoUsed);

	_rearming = _ammo < _rules->getAmmoMax();

	return (clipSize <= 0)? 0 : ammoUsed / clipSize;
}