void CDevMode::GotoTagPoint( int i ) { std::vector<STagFileEntry> tags = LoadTagFile(); if (tags.size() > size_t(i)) { STagFileEntry ent = tags[i]; IActor * pActor = CCryAction::GetCryAction()->GetClientActor(); if (!pActor) return; IEntity * pEntity = pActor->GetEntity(); Quat rot; Vec3 pos = ent.pos; // pos loaded is a camera position, we must convert it into the player position. if (IMovementController * pMC = pActor->GetMovementController()) { SMovementState ms; pMC->GetMovementState(ms); pos -= (ms.eyePosition-ms.pos); } rot.SetRotationXYZ( ent.ang ); Vec3 scale = pEntity->GetScale(); pEntity->SetPosRotScale( pos, rot, scale ); pActor->SetViewRotation( rot ); } }
void CAnimatedCharacter::RefreshAnimTarget() { if (m_pMannequinAGState) { IActorSystem* pActorSystem = CCryAction::GetCryAction()->GetIActorSystem(); assert(pActorSystem != NULL); IActor* pActor = pActorSystem->GetActor(GetEntity()->GetId()); IMovementController* pMovementController = pActor->GetMovementController(); m_pAnimTarget = pMovementController->GetExactPositioningTarget(); } }
//------------------------------------------------------------------------ void CTracerManager::Update(float frameTime) { IActor *pActor = g_pGame->GetIGameFramework()->GetClientActor(); if (!pActor) { return; } if (!pActor->GetMovementController()) { return; } SMovementState state; pActor->GetMovementController()->GetMovementState(state); m_actives.swap(m_updating); TTracerIdVector::iterator it, end = m_updating.end(); for (it = m_updating.begin(); it != end; ++it) { CTracer *tracer = m_pool[*it]; if (tracer->Update(frameTime, state.eyePosition)) { m_actives.push_back(*it); } else { if (IEntity *pEntity = gEnv->pEntitySystem->GetEntity(tracer->m_entityId)) { pEntity->Hide(1); pEntity->SetWorldTM(Matrix34::CreateIdentity()); } } } m_updating.resize(0); }
//-------------------------------------------------------------------------------------------------- // Name: SpawnScreenExplosionEffect // Desc: Spawns screen explosion effect //-------------------------------------------------------------------------------------------------- void CExplosionGameEffect::SpawnScreenExplosionEffect(const SExplosionContainer &explosionContainer) { // Disclaimer: this code was originally from GameRulesClientServer::ProcessClientExplosionScreenFX() const ExplosionInfo& explosionInfo = explosionContainer.m_explosionInfo; if(explosionInfo.pressure < 1.0f) return; IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor(); if(pClientActor != NULL && !pClientActor->IsDead()) { CPlayer* pPlayer = static_cast<CPlayer*>(pClientActor); bool hasFlashBangEffect = explosionInfo.blindAmount > 0.0f; // Flashbang friends and self?... if(hasFlashBangEffect) { bool flashBangSelf = true; bool flashBangFriends = false; #ifndef _RELEASE flashBangSelf = g_pGameCVars->g_flashBangSelf != 0; flashBangFriends = g_pGameCVars->g_flashBangFriends != 0; #endif bool ownFlashBang = pPlayer->GetEntityId() == explosionInfo.shooterId; if((!flashBangSelf && ownFlashBang) || // FlashBang self? ((g_pGame->GetGameRules()->GetFriendlyFireRatio()<=0.0f) && (!flashBangFriends) && (!ownFlashBang) && pPlayer->IsFriendlyEntity(explosionInfo.shooterId))) // FlashBang friends? { return; } } // 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) SMovementState state; if(IMovementController *pMV = pClientActor->GetMovementController()) { pMV->GetMovementState(state); } Vec3 eyeToExplosion = explosionInfo.pos - state.eyePosition; Vec3 eyeDir = pClientActor->GetLinkedVehicle() ? pPlayer->GetVehicleViewDir() : state.eyeDirection; eyeToExplosion.Normalize(); float eyeDirectionDP = eyeDir.Dot(eyeToExplosion); bool inFOV = (eyeDirectionDP > 0.68f); // All explosions have radial blur (default 30m radius) const float maxBlurDistance = (explosionInfo.maxblurdistance >0.0f) ? explosionInfo.maxblurdistance : 30.0f; if((maxBlurDistance > 0.0f) && (g_pGameCVars->g_radialBlur > 0.0f) && (explosionInfo.radius > 0.5f)) { if (inFOV && (dist < maxBlurDistance)) { const int intersectionObjTypes = ent_static | ent_terrain; const unsigned int intersectionFlags = rwi_stop_at_pierceable|rwi_colltype_any; m_deferredScreenEffects.RequestRayCast(CDeferredExplosionEffect::eDET_RadialBlur, explosionInfo.pos, -eyeToExplosion, dist, maxBlurDistance, intersectionObjTypes, intersectionFlags, NULL, 0); } } // Flashbang effect if(hasFlashBangEffect && ((dist < (explosionInfo.radius*g_pGameCVars->g_flashBangNotInFOVRadiusFraction)) || (inFOV && (dist < explosionInfo.radius)))) { ray_hit hit; const int intersectionObjTypes = ent_static | ent_terrain; const unsigned int intersectionFlags = rwi_stop_at_pierceable|rwi_colltype_any; const int intersectionMaxHits = 1; int collision = gEnv->pPhysicalWorld->RayWorldIntersection( explosionInfo.pos, -eyeToExplosion*dist, intersectionObjTypes, intersectionFlags, &hit, intersectionMaxHits); // If there was no obstacle between flashbang grenade and player if(!collision) { bool enabled = true; if(enabled) { CCCPOINT (FlashBang_Explode_BlindLocalPlayer); float timeScale = max(0.0f, 1 - (dist/explosionInfo.radius)); float lookingAt = max(g_pGameCVars->g_flashBangMinFOVMultiplier, (eyeDirectionDP + 1)*0.5f); float time = explosionInfo.flashbangScale * timeScale *lookingAt; // time is determined by distance to explosion CRY_ASSERT_MESSAGE(pClientActor->IsPlayer(),"Effect shouldn't be spawned if not a player"); SPlayerStats* pStats = static_cast<SPlayerStats*>(pPlayer->GetActorStats()); NET_BATTLECHATTER(BC_Blinded, pPlayer); if(pClientActor->GetEntityId() == explosionInfo.shooterId) { g_pGame->GetPersistantStats()->IncrementClientStats(EIPS_BlindSelf); } else { g_pGame->GetGameRules()->SuccessfulFlashBang(explosionInfo, time); } pPlayer->StartFlashbangEffects(time, explosionInfo.shooterId); gEnv->p3DEngine->SetPostEffectParam("Flashbang_Time", time); gEnv->p3DEngine->SetPostEffectParam("FlashBang_BlindAmount", explosionInfo.blindAmount); gEnv->p3DEngine->SetPostEffectParam("Flashbang_DifractionAmount", time); gEnv->p3DEngine->SetPostEffectParam("Flashbang_Active", 1.0f); CRecordingSystem *pRecordingSystem = g_pGame->GetRecordingSystem(); if (pRecordingSystem) { pRecordingSystem->OnPlayerFlashed(time, explosionInfo.blindAmount); } } } else { CCCPOINT (FlashBang_Explode_NearbyButBlockedByGeometry); } } 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; if (pClientActor) { static_cast<CActor*>(pClientActor)->AddAngularImpulse(Ang3(cry_random(-angleX*0.5f,angleX),0.0f,cry_random(-angleZ,angleZ)),0.0f,dt*2.0f); } } } } }//-------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------ bool CGameRules::OnInitiate(SHostMigrationInfo& hostMigrationInfo, uint32& state) { if (!g_pGame->GetIGameFramework()->ShouldMigrateNub(hostMigrationInfo.m_session)) { return true; } CryLog("[Host Migration]: CGameRules::OnInitiate() Saving character for host migration started"); m_hostMigrationClientHasRejoined = false; IEntityScriptProxy* pScriptProxy = static_cast<IEntityScriptProxy*>(GetEntity()->GetProxy(ENTITY_PROXY_SCRIPT)); if (pScriptProxy) { if (string(pScriptProxy->GetState()) == "InGame") { m_hostMigrationTimeSinceGameStarted = (m_cachedServerTime - m_gameStartedTime); } } HostMigrationStopAddingPlayers(); if (gEnv->IsClient()) { if (!m_pHostMigrationParams) { m_pHostMigrationParams = new SHostMigrationClientRequestParams(); m_pHostMigrationClientParams = new SHostMigrationClientControlledParams(); } IActor *pPlayer = g_pGame->GetIGameFramework()->GetClientActor(); if (pPlayer) { m_pHostMigrationClientParams->m_viewQuat = pPlayer->GetViewRotation(); m_pHostMigrationClientParams->m_position = pPlayer->GetEntity()->GetPos(); pe_status_living livStat; IPhysicalEntity *pPhysicalEntity = pPlayer->GetEntity()->GetPhysics(); if (pPhysicalEntity != NULL && (pPhysicalEntity->GetType() == PE_LIVING) && (pPhysicalEntity->GetStatus(&livStat) > 0)) { m_pHostMigrationClientParams->m_velocity = livStat.velUnconstrained; m_pHostMigrationClientParams->m_hasValidVelocity = true; CryLog(" velocity={%f,%f,%f}", m_pHostMigrationClientParams->m_velocity.x, m_pHostMigrationClientParams->m_velocity.y, m_pHostMigrationClientParams->m_velocity.z); } IInventory *pInventory = pPlayer->GetInventory(); m_pHostMigrationClientParams->m_numExpectedItems = 0; int numAmmoTypes = 0; m_pHostMigrationClientParams->m_pAmmoParams = new SHostMigrationClientControlledParams::SAmmoParams[numAmmoTypes]; m_pHostMigrationClientParams->m_numAmmoParams = numAmmoTypes; /*CryLog(" player has %i different ammo types", numAmmoTypes); for (int i = 0; i < numAmmoTypes; ++ i) { IEntityClass *pAmmoType = pInventory->GetAmmoType(i); int ammoCount = pInventory->GetAmmoCount(pAmmoType); m_pHostMigrationClientParams->m_pAmmoParams[i].m_pAmmoClass = pAmmoType; m_pHostMigrationClientParams->m_pAmmoParams[i].m_count = ammoCount; CryLog(" %s : %i", pAmmoType->GetName(), ammoCount); }* EntityId holseredItemId = pInventory->GetHolsteredItem(); if (holseredItemId) { IEntity *pHolsteredEntity = gEnv->pEntitySystem->GetEntity(holseredItemId); if (pHolsteredEntity) { m_pHostMigrationClientParams->m_pHolsteredItemClass = pHolsteredEntity->GetClass(); } }*/ IMovementController *pMovementController = pPlayer->GetMovementController(); if(pMovementController) { SMovementState movementState; pMovementController->GetMovementState(movementState); m_pHostMigrationClientParams->m_aimDirection = movementState.aimDirection; } /*CItem *pItem = static_cast<CItem*>(pPlayer->GetCurrentItem()); if (pItem) { m_pHostMigrationClientParams->m_pSelectedItemClass = pItem->GetEntity()->GetClass(); CryLog(" currently using item '%s", pItem->GetEntity()->GetName()); }*/ } else { CRY_ASSERT_MESSAGE(false, "Failed to find client actor when initiating a host migration"); gEnv->pNetwork->TerminateHostMigration(hostMigrationInfo.m_session); return false; } } g_pGame->SetHostMigrationState(CGame::eHMS_WaitingForPlayers); CCCPOINT(HostMigration_OnInitiate); return true; }