//------------------------------------------------------------------------ void CProjectile::EndScaledEffect(const SScaledEffectParams *pScaledEffect) { if(!pScaledEffect || m_scaledEffectval == 0.0f) return; IActor *local = gEnv->pGame->GetIGameFramework()->GetClientActor(); if(local) { if(pScaledEffect->fadeOutTime > 0.0f) { CActor *act = (CActor *)local; CScreenEffects *pSE = act->GetScreenEffects(); if(pSE) { IBlendedEffect *blur = CBlendedEffect<CPostProcessEffect>::Create(CPostProcessEffect(local->GetEntityId(),pScaledEffect->ppname, 0.0f)); IBlendType *linear = CBlendType<CLinearBlend>::Create(CLinearBlend(1.0f)); pSE->StartBlend(blur, linear, 1.0f/pScaledEffect->fadeOutTime, CScreenEffects::eSFX_GID_SmokeBlur); } } else { gEnv->p3DEngine->SetPostEffectParam(pScaledEffect->ppname, 0.0f); } } }
//------------------------------------------------------------------------ void CRapid::StopFire() { m_startedToFire = false; if (m_pWeapon->IsBusy() && !m_pWeapon->IsZoomingInOrOut()) { return; } if (m_zoomtimeout > 0.0f) { CActor *pActor = m_pWeapon->GetOwnerActor(); CScreenEffects *pSE = pActor ? pActor->GetScreenEffects() : NULL; if (pSE) { float speed = 1.0f / .1f; pSE->ResetBlendGroup(CScreenEffects::eSFX_GID_ZoomIn); pSE->ResetBlendGroup(CScreenEffects::eSFX_GID_ZoomOut); IBlendedEffect *fov = CBlendedEffect<CFOVEffect>::Create(CFOVEffect(pActor->GetEntityId(), 1.0f)); IBlendType *blend = CBlendType<CLinearBlend>::Create(CLinearBlend(1.0f)); pSE->StartBlend(fov, blend, speed, CScreenEffects::eSFX_GID_ZoomOut); } m_zoomtimeout = 0.0f; } if(m_acceleration >= 0.0f) { Accelerate(m_pShared->rapidparams.deceleration); if (m_pWeapon->IsDestroyed()) { FinishDeceleration(); } } SpinUpEffect(false); if(m_firing) { SmokeEffect(); } m_pWeapon->RequestStopFire(); }
//------------------------------------------------------------------------ void CAutomatic::StopFire() { if(m_zoomtimeout > 0.0f) { CActor *pActor = m_pWeapon->GetOwnerActor(); CScreenEffects *pSE = pActor?pActor->GetScreenEffects():NULL; if(pSE) { pSE->ResetBlendGroup(CScreenEffects::eSFX_GID_ZoomIn); // this is so we will zoom out always at the right speed //float speed = (1.0f/.1f) * (1.0f - pActor->GetScreenEffects()->GetCurrentFOV())/(1.0f - .75f); //speed = fabs(speed); float speed = 1.0f/.1f; //if (pActor->GetScreenEffects()->HasJobs(pActor->m_autoZoomOutID)) // speed = pActor->GetScreenEffects()->GetAdjustedSpeed(pActor->m_autoZoomOutID); pSE->ResetBlendGroup(CScreenEffects::eSFX_GID_ZoomOut); IBlendedEffect *fov = CBlendedEffect<CFOVEffect>::Create(CFOVEffect(pActor->GetEntityId(),1.0f)); IBlendType *blend = CBlendType<CLinearBlend>::Create(CLinearBlend(1.0f)); pSE->StartBlend(fov, blend, speed, CScreenEffects::eSFX_GID_ZoomOut); } m_zoomtimeout = 0.0f; } if(m_firing) SmokeEffect(); m_firing = false; if(m_soundId) { m_pWeapon->StopSound(m_soundId); m_soundId = INVALID_SOUNDID; } }
//------------------------------------------- void CGameRules::ProcessClientExplosionScreenFX(const ExplosionInfo &explosionInfo) { IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor(); if (pClientActor) { //Distance float dist = (pClientActor->GetEntity()->GetWorldPos() - explosionInfo.pos).len(); //Is the explosion in Player's FOV (let's suppose the FOV a bit higher, like 80) CActor *pActor = (CActor *)pClientActor; SMovementState state; if (IMovementController *pMV = pActor->GetMovementController()) { pMV->GetMovementState(state); } Vec3 eyeToExplosion = explosionInfo.pos - state.eyePosition; eyeToExplosion.Normalize(); bool inFOV = (state.eyeDirection.Dot(eyeToExplosion) > 0.68f); // if in a vehicle eyeDirection is wrong if(pActor && pActor->GetLinkedVehicle()) { Vec3 eyeDir = static_cast<CPlayer*>(pActor)->GetVehicleViewDir(); inFOV = (eyeDir.Dot(eyeToExplosion) > 0.68f); } //All explosions have radial blur (default 30m radius, to make Sean happy =)) float maxBlurDistance = (explosionInfo.maxblurdistance>0.0f)?explosionInfo.maxblurdistance:30.0f; if (maxBlurDistance>0.0f && g_pGameCVars->g_radialBlur>0.0f && m_explosionScreenFX && explosionInfo.radius>0.5f) { if (inFOV && dist < maxBlurDistance) { ray_hit hit; int col = gEnv->pPhysicalWorld->RayWorldIntersection(explosionInfo.pos , -eyeToExplosion*dist, ent_static | ent_terrain, rwi_stop_at_pierceable|rwi_colltype_any, &hit, 1); //If there was no obstacle between flashbang grenade and player if(!col) { if (CScreenEffects* pSE = pActor->GetScreenEffects()) { float blurRadius = (-1.0f/maxBlurDistance)*dist + 1.0f; gEnv->p3DEngine->SetPostEffectParam("FilterRadialBlurring_Radius", blurRadius); gEnv->p3DEngine->SetPostEffectParam("FilterRadialBlurring_Amount", 1.0f); IBlendedEffect *pBlur = CBlendedEffect<CPostProcessEffect>::Create(CPostProcessEffect(pClientActor->GetEntityId(),"FilterRadialBlurring_Amount", 0.0f)); IBlendType *pLinear = CBlendType<CLinearBlend>::Create(CLinearBlend(1.0f)); pSE->StartBlend(pBlur, pLinear, 1.0f, CScreenEffects::eSFX_GID_RBlur); pSE->SetUpdateCoords("FilterRadialBlurring_ScreenPosX","FilterRadialBlurring_ScreenPosY", explosionInfo.pos); } float distAmp = 1.0f - (dist / maxBlurDistance); if (gEnv->pInput) gEnv->pInput->ForceFeedbackEvent( SFFOutputEvent(eDI_XI, eFF_Rumble_Basic, 0.5f, distAmp*3.0f, 0.0f)); } } } //Flashbang effect if(dist<explosionInfo.radius && inFOV && (!strcmp(explosionInfo.effect_class,"flashbang") || !strcmp(explosionInfo.effect_class,"FlashbangAI"))) { ray_hit hit; int col = gEnv->pPhysicalWorld->RayWorldIntersection(explosionInfo.pos , -eyeToExplosion*dist, ent_static | ent_terrain, rwi_stop_at_pierceable|rwi_colltype_any, &hit, 1); //If there was no obstacle between flashbang grenade and player if(!col) { float power = explosionInfo.flashbangScale; power *= max(0.0f, 1 - (dist/explosionInfo.radius)); float lookingAt = (eyeToExplosion.Dot(state.eyeDirection.normalize()) + 1)*0.5f; power *= lookingAt; SAFE_GAMEAUDIO_SOUNDMOODS_FUNC(AddSoundMood(SOUNDMOOD_EXPLOSION,MIN(power*40.0f,100.0f))); gEnv->p3DEngine->SetPostEffectParam("Flashbang_Time", 1.0f + (power * 4)); gEnv->p3DEngine->SetPostEffectParam("FlashBang_BlindAmount",explosionInfo.blindAmount); gEnv->p3DEngine->SetPostEffectParam("Flashbang_DifractionAmount", (power * 2)); gEnv->p3DEngine->SetPostEffectParam("Flashbang_Active", 1); } } else if(inFOV && (dist < explosionInfo.radius)) { if (explosionInfo.damage>10.0f || explosionInfo.pressure>100.0f) { //Add some angular impulse to the client actor depending on distance, direction... float dt = (1.0f - dist/explosionInfo.radius); dt = dt * dt; float angleZ = gf_PI*0.15f*dt; float angleX = gf_PI*0.15f*dt; pActor->AddAngularImpulse(Ang3(Random(-angleX*0.5f,angleX),0.0f,Random(-angleZ,angleZ)),0.0f,dt*2.0f); } } float fDist2=(pClientActor->GetEntity()->GetWorldPos()-explosionInfo.pos).len2(); if (fDist2<250.0f*250.0f) { if (fDist2<sqr(SAFE_GAMEAUDIO_BATTLESTATUS_FUNC_RET(GetBattleRange()))) SAFE_GAMEAUDIO_BATTLESTATUS_FUNC(TickBattleStatus(1.0f)); } } }
// (jh) this function is called on any input dispatching it to a relevant method and eventually to Lua onAction method void CPlayerInput::OnAction( const ActionId& actionId, int activationMode, float value ) { FUNCTION_PROFILER(GetISystem(), PROFILE_GAME); if (g_pGame->GetHostMigrationState() != CGame::eHMS_NotMigrating) { Reset(); return; } m_pPlayer->GetGameObject()->ChangedNetworkState( INPUT_ASPECT ); m_lastActions=m_actions; //this tell if OnAction have to be forwarded to scripts, now its true by default, only high framerate actions are ignored bool filterOut = true; m_checkZoom = false; const CGameActions& actions = g_pGame->Actions(); IVehicle* pVehicle = m_pPlayer->GetLinkedVehicle(); bool canMove = CanMove(); // disable movement while standing up if (!canMove) m_deltaMovement.zero(); // try to dispatch action to OnActionHandlers bool handled; { FRAME_PROFILER("New Action Processing", GetISystem(), PROFILE_GAME); handled = s_actionHandler.Dispatch(this, m_pPlayer->GetEntityId(), actionId, activationMode, value, filterOut); } { FRAME_PROFILER("Regular Action Processing", GetISystem(), PROFILE_GAME); if (!handled) { filterOut = true; if (!m_pPlayer->m_stats.spectatorMode) { if (actions.ulammo==actionId && m_pPlayer->m_pGameFramework->CanCheat() && gEnv->pSystem->IsDevMode()) { g_pGameCVars->i_unlimitedammo = 1; } else if (actions.debug_ag_step == actionId) { gEnv->pConsole->ExecuteString("ag_step"); } else if(actions.voice_chat_talk == actionId) { if(gEnv->bMultiplayer) { if(activationMode == eAAM_OnPress) g_pGame->GetIGameFramework()->EnableVoiceRecording(true); else if(activationMode == eAAM_OnRelease) g_pGame->GetIGameFramework()->EnableVoiceRecording(false); } } } } if (!m_pPlayer->m_stats.spectatorMode) { IInventory* pInventory = m_pPlayer->GetInventory(); if (!pInventory) return; bool scope = false; EntityId itemId = pInventory->GetCurrentItem(); CWeapon *pWeapon = 0; if (itemId) { pWeapon = m_pPlayer->GetWeapon(itemId); if (pWeapon) { scope = (pWeapon->IsZoomed() && pWeapon->GetMaxZoomSteps()>1); } } if (pVehicle) { if (m_pPlayer->m_pVehicleClient && !m_pPlayer->IsFrozen()) m_pPlayer->m_pVehicleClient->OnAction(pVehicle, m_pPlayer->GetEntityId(), actionId, activationMode, value); //FIXME:not really good m_actions = 0; m_deltaMovement.Set(0,0,0); } else if (m_pPlayer->GetHealth() > 0 && !m_pPlayer->m_stats.isFrozen.Value() && !m_pPlayer->m_stats.inFreefall.Value() && !m_pPlayer->m_stats.isOnLadder && !m_pPlayer->m_stats.isStandingUp && m_pPlayer->GetGameObject()->GetAspectProfile(eEA_Physics)!=eAP_Sleep) { m_pPlayer->CActor::OnAction(actionId, activationMode, value); if ((!scope || actionId == actions.use)) { COffHand* pOffHand = static_cast<COffHand*>(m_pPlayer->GetWeaponByClass(CItem::sOffHandClass)); if (pOffHand) { pOffHand->OnAction(m_pPlayer->GetEntityId(), actionId, activationMode, value); } if ((!pWeapon || !pWeapon->IsMounted())) { if ((actions.drop==actionId) && itemId) { float impulseScale=1.0f; if (activationMode==eAAM_OnPress) m_buttonPressure=2.5f; if (activationMode==eAAM_OnRelease) { m_buttonPressure=CLAMP(m_buttonPressure, 0.0f, 2.5f); impulseScale=1.0f+(1.0f-m_buttonPressure/2.5f)*15.0f; if (m_pPlayer->DropItem(itemId, impulseScale, true) && pOffHand && pOffHand->IsSelected()) { if (EntityId fistsId = pInventory->GetItemByClass(CItem::sFistsClass)) { m_pPlayer->SelectItem(fistsId, false); } pOffHand->PreExecuteAction(eOHA_REINIT_WEAPON, eAAM_OnPress); CItem* pItem = static_cast<CItem*>(m_pPlayer->GetCurrentItem()); if (pItem) { pItem->SetActionSuffix("akimbo_"); pItem->PlayAction(g_pItemStrings->idle); } } } } else if (actions.nextitem==actionId) m_pPlayer->SelectNextItem(1, true, 0); else if (actions.previtem==actionId) m_pPlayer->SelectNextItem(-1, true, 0); else if (actions.handgrenade==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.explosive==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.utility==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.small==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.medium==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.heavy==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.debug==actionId) { if (g_pGame) { if (!m_pPlayer->GetInventory()->GetItemByClass(CItem::sDebugGunClass)) g_pGame->GetWeaponSystem()->DebugGun(0); if (!m_pPlayer->GetInventory()->GetItemByClass(CItem::sRefWeaponClass)) g_pGame->GetWeaponSystem()->RefGun(0); } m_pPlayer->SelectNextItem(1, true, actionId.c_str()); } } } else { if (actions.handgrenade==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.explosive==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.utility==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.small==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.medium==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.heavy==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.drop==actionId && activationMode == eAAM_OnRelease && itemId) m_pPlayer->DropItem(itemId, 1.0f, true); } } if (m_checkZoom) { if (pWeapon) { IZoomMode *zm = pWeapon->GetZoomMode(pWeapon->GetCurrentZoomMode()); CScreenEffects* pScreenEffects = m_pPlayer->GetScreenEffects(); if (zm && !zm->IsZoomingInOrOut() && !zm->IsZoomed() && pScreenEffects != 0) { if (!m_moveButtonState && m_pPlayer->IsClient()) { IBlendedEffect *fovEffect = CBlendedEffect<CFOVEffect>::Create(CFOVEffect(m_pPlayer->GetEntityId(),1.0f)); IBlendType *blend = CBlendType<CLinearBlend>::Create(CLinearBlend(1.0f)); pScreenEffects->ResetBlendGroup(CScreenEffects::eSFX_GID_ZoomIn, false); pScreenEffects->ResetBlendGroup(CScreenEffects::eSFX_GID_ZoomOut, false); pScreenEffects->StartBlend(fovEffect, blend, 1.0f/.25f, CScreenEffects::eSFX_GID_ZoomIn); } else { pScreenEffects->EnableBlends(true, CScreenEffects::eSFX_GID_ZoomIn); pScreenEffects->EnableBlends(true, CScreenEffects::eSFX_GID_ZoomOut); pScreenEffects->EnableBlends(true, CScreenEffects::eSFX_GID_HitReaction); } } } } } } bool hudFilterOut = true; // FIXME: temporary method to dispatch Actions to HUD (it's not yet possible to register) hudFilterOut = true; //Filter must take into account offHand too COffHand* pOffHand = static_cast<COffHand*>(m_pPlayer->GetWeaponByClass(CItem::sOffHandClass)); if(pOffHand && pOffHand->IsSelected()) filterOut = false; //send the onAction to scripts, after filter the range of actions. for now just use and hold if (filterOut && hudFilterOut) { FRAME_PROFILER("Script Processing", GetISystem(), PROFILE_GAME); HSCRIPTFUNCTION scriptOnAction(NULL); IScriptTable *scriptTbl = m_pPlayer->GetEntity()->GetScriptTable(); if (scriptTbl) { scriptTbl->GetValue("OnAction", scriptOnAction); if (scriptOnAction) { char *activation = 0; switch(activationMode) { case eAAM_OnHold: activation = "hold"; break; case eAAM_OnPress: activation = "press"; break; case eAAM_OnRelease: activation = "release"; break; default: activation = ""; break; } Script::Call(gEnv->pScriptSystem,scriptOnAction,scriptTbl,actionId.c_str(),activation, value); } } gEnv->pScriptSystem->ReleaseFunc(scriptOnAction); } }