//------------------------------------------------------------------------ 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); } } } } }
void CSpammer::UpdateLoadIn(float frameTime) { const int currentAmmoCount = GetAmmoCount(); const bool infiniteAmmo = (GetClipSize() < 0); if ((!infiniteAmmo) && (m_numLoadedRockets >= currentAmmoCount)) { GetWeapon()->PlayAction(GetFragmentIds().empty_clip); StopFire(); return; } const SSpammerParams& params = GetShared()->spammerParams; const float loadInTime = 1.0f / (params.loadInRate / 60.0f); m_timer -= frameTime; while (m_timer < 0.0f && m_numLoadedRockets < params.maxNumRockets) { m_timer += loadInTime; AddTarget(); GetWeapon()->PlayAction(GetFragmentIds().c**k); } if (m_numLoadedRockets != m_targetsAssigned.GetNumLockOns()) { EntityId nextTarget = GetNextLockOnTarget(); if (nextTarget != 0) m_targetsAssigned.LockOn(nextTarget); } }
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); } } } } }
//----------------------------------------------------------------------------- // Purpose: Returns whether or not we can switch to the given weapon. // Input : pWeapon - //----------------------------------------------------------------------------- bool CBaseCombatCharacter::Weapon_CanSwitchTo( CBaseCombatWeapon *pWeapon ) { if (IsPlayer()) { CBasePlayer *pPlayer = (CBasePlayer *)this; #if !defined( CLIENT_DLL ) IServerVehicle *pVehicle = pPlayer->GetVehicle(); #else IClientVehicle *pVehicle = pPlayer->GetVehicle(); #endif if (pVehicle && !pPlayer->UsingStandardWeaponsInVehicle()) return false; } if ( !pWeapon->HasAnyAmmo() && !GetAmmoCount( pWeapon->m_iPrimaryAmmoType ) ) return false; if ( !pWeapon->CanDeploy() ) return false; if ( m_hActiveWeapon ) { if ( !m_hActiveWeapon->CanHolster() ) return false; } return true; }
bool CJaw::CanPickUp(EntityId userId) const { CActor *pActor = GetActor(userId); IInventory *pInventory=GetActorInventory(pActor); if (m_sharedparams->params.pickable && m_stats.pickable && !m_stats.flying && (!m_owner.GetId() || m_owner.GetId()==userId) && !m_stats.selected && !GetEntity()->IsHidden()) { if (pInventory && pInventory->FindItem(GetEntityId())!=-1) return false; } else return false; if(GetAmmoCount(m_fm->GetAmmoType())<=0) { return false; } uint8 uniqueId = m_pItemSystem->GetItemUniqueId(GetEntity()->GetClass()->GetName()); int maxNumRockets = GetWeaponSharedParams()->ammoParams.capacityAmmo[0].count; if(pInventory && (pInventory->GetCountOfUniqueId(uniqueId)>=maxNumRockets)) { if(pActor->IsClient()) { SHUDEventWrapper::DisplayInfo(eInfo_Warning, 0.5f, "@mp_CannotCarryMoreLAW"); } return false; } return true; }
//------------------------------------------------------------------------ int CWeapon::NetGetCurrentAmmoCount() const { if (!m_fm) return 0; return GetAmmoCount(m_fm->GetAmmoType()); }
//------------------------------------------------------------------------ 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); } } }
void CLTag::UpdateGrenades() { if (!m_fm) return; ICharacterInstance* pWeaponCharacter = GetEntity()->GetCharacter(eIGS_FirstPerson); if (!pWeaponCharacter) return; const char* newChell = "newShell"; const char* currentShell = "currentShell"; const int ammoCount = GetAmmoCount(m_fm->GetAmmoType()); HideGrenadeAttachment(pWeaponCharacter, currentShell, ammoCount <= 2); HideGrenadeAttachment(pWeaponCharacter, newChell, ammoCount <= 1); }
//----------------------------------------------------------------------------- // Purpose: Returns whether or not we can switch to the given weapon. // Input : pWeapon - //----------------------------------------------------------------------------- bool CBaseCombatCharacter::Weapon_CanSwitchTo( CBaseCombatWeapon *pWeapon ) { if ( !pWeapon->HasAnyAmmo() && !GetAmmoCount( pWeapon->m_iPrimaryAmmoType ) ) return false; if ( !pWeapon->CanDeploy() ) return false; if ( m_hActiveWeapon ) { if ( !m_hActiveWeapon->CanHolster() ) return false; } return true; }
void CRocketLauncher::PostDropAnim() { CWeapon::Drop(5.0f,true); if(m_fm && GetAmmoCount(m_fm->GetAmmoType())<=0) { Pickalize(false,true); if(m_smokeEffectSlot==-1) { IParticleEffect * pEffect = gEnv->pParticleManager->FindEffect(m_sEmptySmokeEffect.c_str()); if(pEffect) m_smokeEffectSlot = GetEntity()->LoadParticleEmitter(-1,pEffect); } } }
float CRapid::GetAmmoSoundParam() { float ammo = 1.0f; int clipSize = GetClipSize(); int ammoCount = GetAmmoCount(); if(clipSize > 0 && ammoCount >= 0) { ammo = (float) ammoCount / clipSize; } #if !defined(_RELEASE) if (g_pGameCVars->i_debug_sounds) { CryWatch("ammo_left param %.2f", ammo); } #endif return ammo; };
void CJaw::NetSetCurrentAmmoCount( int count ) { //If the client has successfully fired a rocket at the point of host migration then the new server will //end up sending wrong information regarding their ammo, yet the rocket will remain fired if(!gEnv->bServer && m_firedRockets) { if (m_owner.GetId() == g_pGame->GetClientActorId()) { const int currentCount = GetAmmoCount(m_fm->GetAmmoType()); if(count == currentCount + m_firedRockets) { count = currentCount; SRequestAmmoParams params; params.m_ammo = currentCount; GetGameObject()->InvokeRMI(SvRequestAmmo(), params, eRMI_ToServer); } } } BaseClass::NetSetCurrentAmmoCount(count); }
//================================================= void CRocketLauncher::AutoDrop() { if(m_zm && m_zm->IsZoomed()) { GetScheduler()->TimerAction(GetCurrentAnimationTime(eIGS_FirstPerson), CSchedulerAction<EndZoomOutAction>::Create(EndZoomOutAction(this)), true); } else if(m_fm) { m_firedRockets--; CActor* pOwner = GetOwnerActor(); // no need to auto-drop for AI if(pOwner && !pOwner->IsPlayer()) return; if((GetAmmoCount(m_fm->GetAmmoType()) + GetInventoryAmmoCount(m_fm->GetAmmoType()) <= 0)&&(m_firedRockets<=0)) { PlayAction(g_pItemStrings->deselect); GetScheduler()->TimerAction(GetCurrentAnimationTime(eIGS_FirstPerson), CSchedulerAction<EndDropAction>::Create(EndDropAction(this)), true); } } }
void CJaw::DoAutoDrop() { if(!m_playedDropAction && m_fm) { m_firedRockets--; CActor* pOwner = GetOwnerActor(); // no need to auto-drop for AI if(pOwner && !pOwner->IsPlayer()) return; if((GetAmmoCount(m_fm->GetAmmoType())<=0)&&(m_firedRockets<=0)) { if( pOwner ) { uint8 uniqueId = m_pItemSystem->GetItemUniqueId(GetEntity()->GetClass()->GetName()); bool selectNext = pOwner->GetInventory()->GetCountOfUniqueId(uniqueId) <= 1; PlayAction(GetFragmentIds().drop); m_playedDropAction = true; } } } }
//----------------------------------------------------------------------------- // Purpose: Returns the amount of ammunition of the specified type the character's carrying //----------------------------------------------------------------------------- int CBaseCombatCharacter::GetAmmoCount( char *szName ) const { return GetAmmoCount( GetAmmoDef()->Index(szName) ); }
//------------------------------------------------------------------------ void CWeapon::OnDropped(EntityId actorId, bool ownerWasAI) { BROADCAST_WEAPON_EVENT(OnDropped, (this, actorId)); BaseClass::OnDropped(actorId, ownerWasAI); IEntity * pEntity = GetEntity(); if(gEnv->bServer) { bool removeWeapon = true; if(gEnv->bMultiplayer && GetParams().check_clip_size_after_drop) { TFireModeVector::const_iterator firemodesEndIt = m_firemodes.end(); for (TFireModeVector::const_iterator firemodeCit = m_firemodes.begin(); firemodeCit != firemodesEndIt && removeWeapon; ++firemodeCit) { const CFireMode* pFiremode = *firemodeCit; if (pFiremode) { IEntityClass* pFiremodeAmmo = pFiremode->GetAmmoType(); if (pFiremodeAmmo) { //only check the main ammo type given with the weapon if(SWeaponAmmoUtils::FindAmmoConst(m_weaponsharedparams->ammoParams.ammo, pFiremodeAmmo)) { int currentClipAmount = GetAmmoCount(pFiremodeAmmo); int clipSize = pFiremode->GetClipSize(); if(currentClipAmount > 0 && currentClipAmount >= clipSize) { removeWeapon = false; } } } } } } else { const bool outOfAmmo = OutOfAmmo(true) && !ownerWasAI; const bool removeOnDrop = GetSharedItemParams()->params.remove_on_drop; removeWeapon = !gEnv->pSystem->IsSerializingFile() && (outOfAmmo && removeOnDrop); } if(removeWeapon && GetParams().check_bonus_ammo_after_drop) { for(unsigned int i = 0; i < m_bonusammo.size(); ++i) { if(m_bonusammo[i].count > 0) { removeWeapon = false; break; } } } if(removeWeapon) { if(gEnv->IsEditor()) { pEntity->Hide(true); } else { gEnv->pEntitySystem->RemoveEntity(pEntity->GetId()); } } } uint32 flags = pEntity->GetFlags(); flags &= ~ENTITY_FLAG_NO_PROXIMITY; pEntity->SetFlags(flags); m_expended_ammo = 0; if(gEnv->bMultiplayer && (g_pGameCVars->i_highlight_dropped_weapons == 2) || (IsHeavyWeapon() && g_pGameCVars->i_highlight_dropped_weapons == 1)) { HighlightWeapon(true, true); } }
//------------------------------------------------------------------------ IMPLEMENT_RMI(CWeapon, SvRequestShootEx) { CHECK_OWNER_REQUEST(); bool ok=true; CActor *pActor=GetActorByNetChannel(pNetChannel); if (!pActor || pActor->IsDead()) { ok=false; } #ifdef SERVER_CHECKS CAntiCheatManager * pAntiCheatManager = static_cast<CAntiCheatManager*>(g_pGame->GetAntiCheatManager()); bool validatePrediction = pAntiCheatManager ? pAntiCheatManager->GetAntiCheatVar(eAV_IP_UseTest_ValidatePredicatedSpawn, 1) != 0 : false; if(ok && validatePrediction && params.predictionHandle) { CFireMode *pFireMode = (CFireMode*)GetFireMode(params.fireModeId); if (pFireMode) { const SFireModeParams *pFireModeParams = pFireMode->GetShared(); if(pFireModeParams) { IEntityClass *pAmmoClass = pFireModeParams->fireparams.ammo_type_class; if(pAmmoClass) { int totalAmmoCount = GetAmmoCount(pAmmoClass) + GetInventoryAmmoCount(pAmmoClass); if(totalAmmoCount <= 0) { CryLog("actor %s does not have enough ammo for predicted spawn of %s, not spawning...", pActor->GetEntity()->GetName(), pAmmoClass->GetName()); ok = false; } } } } } #endif if (ok) { m_fireCounter++; m_expended_ammo++; IActor *pLocalActor=m_pGameFramework->GetClientActor(); bool isLocal = pLocalActor && (pLocalActor->GetChannelId() == pActor->GetChannelId()); if (!isLocal) { NetShootEx(params.pos, params.dir, params.vel, params.hit, params.extra, params.predictionHandle, params.fireModeId); } CHANGED_NETWORK_STATE(this, ASPECT_STREAM); } else { if(params.predictionHandle) { CGameRules::SPredictionParams predictionParams(params.predictionHandle); g_pGame->GetGameRules()->GetGameObject()->InvokeRMI(CGameRules::ClPredictionFailed(), predictionParams, eRMI_ToClientChannel, m_pGameFramework->GetGameChannelId(pNetChannel)); } } return true; }