//------------------------------------------------------------------------
void CWeapon::NetSetCurrentAmmoCount(int count)
{
    if (!m_fm)
        return;

    SetAmmoCount(m_fm->GetAmmoType(), count);
}
Beispiel #2
0
//------------------------------------------------------------------------
void CWeapon::OnDroppedByPlayer(IInventory* pPlayerInventory)
{
	CRY_ASSERT(pPlayerInventory);

	TFireModeVector::const_iterator firemodesEndIt = m_firemodes.end();
	for (TFireModeVector::const_iterator firemodeCit = m_firemodes.begin(); firemodeCit != firemodesEndIt ; ++firemodeCit)
	{
		const CFireMode* pFiremode = *firemodeCit;
		if (pFiremode)
		{
			IEntityClass* pFiremodeAmmo = pFiremode->GetAmmoType();
			if (pFiremodeAmmo)
			{
				// Exchange also ammo pool from inventory to bonus ammo map, for next user who picks it up
				int ammoCount = pPlayerInventory->GetAmmoCount(pFiremodeAmmo);
				if (ammoCount > 0)
				{
					if(gEnv->bMultiplayer)
					{
						int currentClipAmount = GetAmmoCount(pFiremodeAmmo);
						int clipSize = pFiremode->GetClipSize();

						int numForClip = clamp_tpl(clipSize - currentClipAmount, 0, ammoCount);
						SetAmmoCount(pFiremodeAmmo, currentClipAmount + numForClip);

						ammoCount -= numForClip;
					}
					
					SetInventoryAmmoCount(pFiremodeAmmo, 0);
					SWeaponAmmoUtils::SetAmmo(m_bonusammo, pFiremodeAmmo, ammoCount);
				}
			}
		}
	}
}
Beispiel #3
0
void CWeapon::TestClipAmmoCountIsValid()
{
	TFireModeVector::iterator itEnd = m_firemodes.end();
	for (TFireModeVector::iterator it = m_firemodes.begin(); it != itEnd; ++it)
	{
		IFireMode* pFM = *it;
		if (pFM && pFM->IsEnabled())
		{
			IEntityClass* pAmmoType = pFM->GetAmmoType();
			if(pAmmoType)
			{
				int clipSize = pFM->GetClipSize();
				const SFireModeParams* pFireModeParams = ((CFireMode*)pFM)->GetShared();
				if (pFireModeParams)
				{
					clipSize += pFireModeParams->fireparams.bullet_chamber;
				}
				const int ammoCount = GetAmmoCount(pAmmoType);
				if (ammoCount > clipSize)
				{
					SetAmmoCount(pAmmoType, clipSize);
					const int excessAmmo = ammoCount - clipSize;
					SetInventoryAmmoCount(pAmmoType, GetInventoryAmmoCount(pAmmoType) + excessAmmo);
				}
			}
		}
	}
}
// RMI receiver in clients for SetAmmoCount. This is needed because ammo changes are not automatically propagated
IMPLEMENT_RMI(CInventory, Cl_SetAmmoCount)
{
	TRMIInventory_Ammo Info(params);
	
	IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass( Info.m_AmmoClass.c_str());
	if (pClass)
	  SetAmmoCount( pClass, Info.m_iAmount );
	return true;
}
Beispiel #5
0
//------------------------------------------------------------------------
IMPLEMENT_RMI(CJaw, SvRequestAmmo)
{
	if (m_fm)
	{
		SetAmmoCount(m_fm->GetAmmoType(), params.m_ammo);
	}
	
	return true;
}
//------------------------------------------------------------------------
void CInventory::SetAmmoCapacity(IEntityClass* pAmmoType, int max)
{
  //
  //CryLog("%s::CInventory::SetAmmoCapacity(%s,%d)", GetEntity()->GetName(),pAmmoType->GetName(), max);
  //
	if(pAmmoType)
	{
		m_stats.ammoInfo[pAmmoType].SetCapacity(max);
		
		if (GetAmmoCount(pAmmoType) > max)
		{
			SetAmmoCount(pAmmoType, max);
		}
	}
}
Beispiel #7
0
void CJaw::PickUp(EntityId pickerId, bool sound, bool select, bool keepHistory, const char* setup)
{
	for (TAmmoVector::iterator it = m_bonusammo.begin(); it != m_bonusammo.end(); ++it)
	{
		SWeaponAmmo& currentBonusAmmo = *it;
		currentBonusAmmo.count = 0;
	}

	IItemSystem* pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem();
	IActor* pPicketActor = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pickerId);
	IInventory* pInventory = pPicketActor->GetInventory();
	bool giveExtraTube = GiveExtraTubeToInventory(pPicketActor, pItemSystem);

	if (pPicketActor->IsClient())
		SetAmmoCount(m_fm->GetAmmoType(), 1);

	BaseClass::PickUp(pickerId,sound,select,keepHistory, setup);

	if (giveExtraTube)
	{
		int numJaws = m_weaponsharedparams->ammoParams.extraItems;
		while(numJaws-- > 0)
		{
			pItemSystem->GiveItem(pPicketActor, GetEntity()->GetClass()->GetName(), false, false, false);
		}
		m_extraTubesAdded = true;
	}

	if(m_auxSlotUsed)
	{
		DrawSlot(eIGS_ThirdPersonAux,false);
		m_auxSlotUsed = false;
	}

	if(GetOwnerActor() && !GetOwnerActor()->IsPlayer())
		m_stats.first_selection = false;
}