//------------------------------------------------------------------------ void CScope::InformActorOfScope(bool active) { IActor *pActor=m_pWeapon->GetOwnerActor(); if (pActor && pActor->IsPlayer()) { CPlayer *pPlayer=static_cast<CPlayer*>(pActor); pPlayer->GetActorStats()->isScoped = active; CCCPOINT_IF(active, PlayerWeapon_SniperScopeOn); CCCPOINT_IF(!active, PlayerWeapon_SniperScopeOff); } }
void CLTag::HideGrenadeAttachment( ICharacterInstance* pWeaponCharacter, const char* attachmentName, bool hide ) { CRY_ASSERT(pWeaponCharacter); CCCPOINT_IF(string("newShell") == attachmentName && hide, ltag_hide_newShell); CCCPOINT_IF(string("newShell") == attachmentName && !hide, ltag_show_newShell); CCCPOINT_IF(string("currentShell") == attachmentName && hide, ltag_hide_currentShell); CCCPOINT_IF(string("currentShell") == attachmentName && !hide, ltag_show_currentShell); IAttachment* pAttachment = pWeaponCharacter->GetIAttachmentManager()->GetInterfaceByName(attachmentName); if (pAttachment) { pAttachment->HideAttachment(hide ? 1 : 0); } }
bool CPlayerStateUtil::ShouldJump( CPlayer& player, const SActorFrameMovementParams& movement ) { const bool allowJump = movement.jump && !player.IsJumping(); //m_playerStateJump.IsJumping(); if (allowJump) { // TODO: We need a TryJump (stephenn). // This is needed when jumping while standing directly under something that causes an immediate land, // before and without even being airborne for one frame. // PlayerMovement set m_stats.onGround=0.0f when the jump is triggered, // which prevents the on ground timer from before the jump to be inherited // and incorrectly and prematurely used to identify landing in MP. const SPlayerStats& stats = *player.GetActorStats(); const SActorPhysics& actorPhysics = player.GetActorPhysics(); const float fUnconstrainedZ = actorPhysics.velocityUnconstrained.z; bool jumpFailed = (stats.onGround > 0.0f) && (fUnconstrainedZ <= 0.0f); const float onGroundTime = 0.2f; if( ((stats.onGround > onGroundTime) || player.IsRemote()) ) // && !jumpFailed ) { return true; } else { CCCPOINT_IF(true, PlayerMovement_PressJumpWhileNotAllowedToJump); } } return false; }
//------------------------------------------------------------------------ void CDetonate::StartFire() { if (CanFire(false)) { CActor *pOwner=m_pWeapon->GetOwnerActor(); CCCPOINT(DetonateFireMode_StartFireOK); m_pWeapon->RequireUpdate(eIUS_FireMode); m_detonationTimer = 0.1f; m_pWeapon->PlayAction(GetFragmentIds().fire); m_pWeapon->RequestDetonate(); } else { #if !defined(_RELEASE) IFireMode* pFM = m_pWeapon->GetFireMode(m_pWeapon->GetCurrentFireMode()); EntityId projectileId = pFM ? pFM->GetProjectileId() : 0; IEntity * projectile = gEnv->pEntitySystem->GetEntity(projectileId); CryLog ("[Detonate] Failure to detonate %s '%s' (timer = %.4f, can detonate = %s, fire mode = '%s') projectile = %u (%s '%s')", m_pWeapon->GetEntity()->GetClass()->GetName(), m_pWeapon->GetEntity()->GetName(), m_detonationTimer, m_canDetonate ? "TRUE" : "FALSE", pFM ? pFM->GetName() : "NONE", projectileId, projectile ? projectile->GetClass()->GetName() : "NONE", projectile ? projectile->GetName() : "N/A"); #endif CCCPOINT_IF(m_detonationTimer > 0.0f, DetonateFireMode_CannotFire_TimerNotReachedZero); CCCPOINT(DetonateFireMode_CannotFire); } }
//----------------------------------------------------------------------- void CMelee::PerformMelee(const Vec3 &pos, const Vec3 &dir, bool remote) { CCCPOINT_IF(! remote, Melee_PerformLocal); CCCPOINT_IF(remote, Melee_PerformRemote); MeleeDebugLog ("CMelee<%p> PerformMelee(remote=%s)", this, remote ? "true" : "false"); #if !defined(_RELEASE) if(g_pGameCVars->pl_melee.debug_gfx) { IPersistantDebug *pDebug = g_pGame->GetIGameFramework()->GetIPersistantDebug(); pDebug->Begin("CMelee::PerformMelee", false); pDebug->AddLine(pos, (pos + dir), ColorF(1.f,0.f,0.f,1.f), 15.f); } #endif m_collisionHelper.DoCollisionTest(SCollisionTestParams(pos, dir, GetRange(), m_pWeapon->GetOwnerId(), 0, remote)); }
void CPlayerPlugin_CurrentlyTargetting::Update(float dt) { m_currentTargetTime += dt; //updated locally for all players (so doesn't have to be synced) assert (IsEntered()); if (m_ownerPlayer->IsClient()) { EntityId newTargetId = !m_ownerPlayer->IsDead() ? m_ownerPlayer->GetGameObject()->GetWorldQuery()->GetLookAtEntityId() : 0; if (newTargetId) { IActor * targettedActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(newTargetId); if (targettedActor == NULL || targettedActor->IsDead()) { newTargetId = 0; } } if (m_currentTarget != newTargetId) { m_currentTarget = newTargetId; CCCPOINT_IF(m_currentTarget, PlayerState_LocalPlayerNowTargettingSomebody); CCCPOINT_IF(!m_currentTarget, PlayerState_LocalPlayerNowTargettingNobody); m_currentTargetTime = 0.0f; CHANGED_NETWORK_STATE(m_ownerPlayer, CPlayer::ASPECT_CURRENTLYTARGETTING_CLIENT); } } #if PLAYER_PLUGIN_DEBUGGING IEntity* pEntity = gEnv->pEntitySystem->GetEntity(m_currentTarget); PlayerPluginWatch ("Target e%05d (%s %s) - %.2f", m_currentTarget, pEntity ? pEntity->GetName() : "NULL", pEntity ? pEntity->GetClass()->GetName() : "entity", m_currentTargetTime); #endif }
void CPlayerPlugin_CurrentlyTargetting::NetSerialize(TSerialize ser, EEntityAspects aspect, uint8 profile, int flags) { if(aspect == CPlayer::ASPECT_CURRENTLYTARGETTING_CLIENT) { NET_PROFILE_SCOPE("CurrentlyTargeting", ser.IsReading()); EntityId previousTarget = m_currentTarget; ser.Value("curTargetId", m_currentTarget, 'eid'); if(ser.IsReading()) { if(m_currentTarget != previousTarget) { CCCPOINT_IF(m_currentTarget, PlayerState_RemotePlayerNowTargettingSomebody); CCCPOINT_IF(!m_currentTarget, PlayerState_RemotePlayerNowTargettingNobody); m_currentTargetTime = 0.0f; CGameRules *pGameRules = g_pGame->GetGameRules(); const EntityId clientActorId = g_pGame->GetClientActorId(); if (m_bTargetingLocalPlayer) { SHUDEvent event (eHUDEvent_LocalPlayerTargeted); event.AddData(false); CHUDEventDispatcher::CallEvent(event); m_bTargetingLocalPlayer = false; //m_targetedSignal.Stop(clientActorId); } } } } }
bool CPlayerStateUtil::ShouldSprint( const CPlayer& player, const SActorFrameMovementParams& movement, IItem* pCurrentPlayerItem ) { bool shouldSprint = false; const SPlayerStats& stats = player.m_stats; const bool movingForward = IsMovingForward( player, movement ); bool restrictSprint = player.IsJumping() || stats.bIgnoreSprinting || player.IsSliding() || player.IsCinematicFlagActive(SPlayerStats::eCinematicFlag_RestrictMovement); CWeapon* pWeapon = pCurrentPlayerItem ? static_cast<CWeapon*>(pCurrentPlayerItem->GetIWeapon()) : NULL; bool isZooming = pWeapon ? pWeapon->IsZoomed() && !pWeapon->IsZoomingInOrOut() : false; if (pWeapon && !pWeapon->CanSprint()) restrictSprint = true; restrictSprint = restrictSprint || (player.GetSprintStaminaLevel() <= 0.f); //CryLogAlways(" restrictSprint = %d", restrictSprint); if (player.IsSprinting() == false) { shouldSprint = movingForward && !restrictSprint && !isZooming; CCCPOINT_IF(shouldSprint, PlayerMovement_SprintOn); } else { shouldSprint = movingForward && !restrictSprint && !isZooming; //CryLogAlways(" shouldSprint = %d", shouldSprint); shouldSprint = shouldSprint && (!(player.m_actions & ACTION_CROUCH)); if(!shouldSprint && pWeapon) { pWeapon->ForcePendingActions(); } } CCCPOINT_IF(!player.IsSprinting() && !shouldSprint && (player.m_actions & ACTION_SPRINT), PlayerMovement_SprintRequestIgnored); CCCPOINT_IF(player.IsSprinting() && !shouldSprint, PlayerMovement_SprintOff); //CryLogAlways(" returning (for \"%s\") shouldSprint = %d", m_player.GetEntity()->GetName(), shouldSprint); return shouldSprint; }
//------------------------------------------------------------------------ void CGameRulesKingOfTheHillObjective::Update( float frameTime ) { BaseType::Update(frameTime); CGameRules *pGameRules = g_pGame->GetGameRules(); IGameRulesScoringModule *pScoringModule = pGameRules->GetScoringModule(); const int localTeamId = pGameRules->GetTeam(g_pGame->GetIGameFramework()->GetClientActorId()); for (int i = 0; i < HOLD_OBJECTIVE_MAX_ENTITIES; ++ i) { SHoldEntityDetails *pDetails = &m_entities[i]; if (!pDetails->m_id) { continue; } SKotHEntity *pKotHEntity = static_cast<SKotHEntity *>(pDetails->m_pAdditionalData); CRY_ASSERT(pKotHEntity); if (gEnv->bServer && pScoringModule) { #ifndef _RELEASE if (g_pGameCVars->g_KingOfTheHillObjective_watchLvl) { IEntity *pEntity = gEnv->pEntitySystem->GetEntity(pDetails->m_id); const char *pEntName = pEntity ? pEntity->GetName() : "<NULL>"; if (pDetails->m_controllingTeamId == CONTESTED_TEAM_ID) { CryWatch("KotH entity '%s' is contested", pEntName); } else if (pDetails->m_controllingTeamId == 0) { CryWatch("KotH entity '%s' has no players nearby", pEntName); } else { CryWatch("KotH entity '%s' controlled by team %i, scoreTimerLength='%.2f', timeSinceLastScore='%.2f'", pEntName, pDetails->m_controllingTeamId, pKotHEntity->m_scoreTimerLength, pKotHEntity->m_timeSinceLastScore); } } #endif if (pKotHEntity->m_scoringTeamId) { const int teamIndex = pKotHEntity->m_scoringTeamId - 1; CRY_ASSERT_MESSAGE(teamIndex >= 0 && teamIndex < NUM_TEAMS, "Update() scoringTeamId is out of range"); pKotHEntity->m_timeSinceLastScore += frameTime; if (pKotHEntity->m_timeSinceLastScore >= pKotHEntity->m_scoreTimerLength) { pScoringModule->OnTeamScoringEvent(teamIndex + 1, EGRST_KingOfTheHillObjectiveHeld); pKotHEntity->m_timeSinceLastScore = 0.f; AwardPlayerPoints(&pDetails->m_insideEntities[teamIndex], EGRST_KingOfTheHillObjectiveHeld); CCCPOINT_IF((pKotHEntity->m_scoringTeamId == 1), KingOfTheHillObjective_TeamMarinesScored); CCCPOINT_IF((pKotHEntity->m_scoringTeamId == 2), KingOfTheHillObjective_TeamCellScored); } } } if (gEnv->IsClient()) { if (m_useIcons && pKotHEntity->m_needsIconUpdate) { UpdateIcon(pDetails); } if (pGameRules->GetGameMode() == eGM_CrashSite) { if (pDetails->m_localPlayerIsWithinRange && pDetails->m_controllingTeamId != CONTESTED_TEAM_ID) { CPersistantStats::GetInstance()->IncrementClientStats(EFPS_CrashSiteHeldTime, frameTime); } } if (pKotHEntity->m_bPulseEnabled) { pKotHEntity->m_pulseTime -= frameTime; if (pKotHEntity->m_pulseTime < 0.f) { eRadiusPulseType pulseType = GetPulseType(pDetails); const float radiusEffectScale = pKotHEntity->m_radiusEffectScale * pDetails->m_controlRadius; RadiusEffectPulse(pDetails->m_id, pulseType, radiusEffectScale); pKotHEntity->m_pulseTime = m_pulseTimerLength; } } else { if (!m_shouldDoPulseEffectFunc.empty()) { IEntity *pEntity = gEnv->pEntitySystem->GetEntity(pDetails->m_id); if (pEntity) { IScriptTable *pEntityScript = pEntity->GetScriptTable(); HSCRIPTFUNCTION pulseCheckFunc; if (pEntityScript != NULL && pEntityScript->GetValue(m_shouldDoPulseEffectFunc.c_str(), pulseCheckFunc)) { IScriptSystem *pScriptSystem = gEnv->pScriptSystem; bool result = false; if (Script::CallReturn(pScriptSystem, pulseCheckFunc, pEntityScript, result)) { pKotHEntity->m_bPulseEnabled = result; } } } } } const float fOldScoringSFX = pKotHEntity->m_fScoringSFX; if(pKotHEntity->m_scoringTeamId) { pKotHEntity->m_fScoringSFX = min(pKotHEntity->m_fScoringSFX + (frameTime * 2.0f), 1.0f); } else { pKotHEntity->m_fScoringSFX = max(pKotHEntity->m_fScoringSFX - (frameTime * 1.0f), 0.0f); } if(pKotHEntity->m_fScoringSFX != fOldScoringSFX) UpdateEntityAudio(pDetails); } } }
void CPlayerStateJump::StartJump( CPlayer& player, const bool isHeavyWeapon, const float fVerticalSpeedModifier ) { const SActorPhysics& actorPhysics = player.GetActorPhysics(); const SPlayerStats& stats = *player.GetActorStats(); const float onGroundTime = 0.2f; float g = actorPhysics.gravity.len(); const float jumpHeightScale = 1.0f; const float jumpHeight = player.GetActorParams().jumpHeight * jumpHeightScale; float playerZ = player.GetEntity()->GetWorldPos().z; float expectedJumpEndHeight = playerZ + jumpHeight; pe_player_dimensions dimensions; IPhysicalEntity *pPhysics = player.GetEntity()->GetPhysics(); if (pPhysics && pPhysics->GetParams(&dimensions)) { float physicsBottom = dimensions.heightCollider - dimensions.sizeCollider.z; if (dimensions.bUseCapsule) { physicsBottom -= dimensions.sizeCollider.x; } expectedJumpEndHeight += physicsBottom; } float jumpSpeed = 0.0f; if (g > 0.0f) { jumpSpeed = sqrt_tpl(2.0f*jumpHeight*(1.0f/g)) * g; if( isHeavyWeapon ) { jumpSpeed *= g_pGameCVars->pl_movement.nonCombat_heavy_weapon_speed_scale; } } //this is used to easily find steep ground float slopeDelta = (Vec3Constants<float>::fVec3_OneZ - actorPhysics.groundNormal).len(); SetJumpState(player, JState_Jump); Vec3 jumpVec(ZERO); bool bNormalJump = true; player.PlaySound(CPlayer::ESound_Jump); OnSpecialMove(player, IPlayerEventListener::eSM_Jump); CCCPOINT_IF( player.IsClient(), PlayerMovement_LocalPlayerNormalJump); CCCPOINT_IF(!player.IsClient(), PlayerMovement_NonLocalPlayerNormalJump); { // This was causing the vertical jumping speed to be much slower. float verticalMult = max(1.0f - m_jumpLock, 0.3f); const Quat baseQuat = player.GetBaseQuat(); jumpVec += baseQuat.GetColumn2() * jumpSpeed * verticalMult; jumpVec.z += fVerticalSpeedModifier; #ifdef STATE_DEBUG if (g_pGameCVars->pl_debugInterpolation > 1) { CryWatch("Jumping: vec from player BaseQuat only = (%f, %f, %f)", jumpVec.x, jumpVec.y, jumpVec.z); } #endif if (g_pGameCVars->pl_adjustJumpAngleWithFloorNormal && actorPhysics.groundNormal.len2() > 0.0f) { float vertical = clamp_tpl((actorPhysics.groundNormal.z - 0.25f) / 0.5f, 0.0f, 1.0f); Vec3 modifiedJumpDirection = LERP(actorPhysics.groundNormal, Vec3(0,0,1), vertical); jumpVec = modifiedJumpDirection * jumpVec.len(); } #ifdef STATE_DEBUG if (g_pGameCVars->pl_debugInterpolation > 1) { CryWatch("Jumping (%f, %f, %f)", jumpVec.x, jumpVec.y, jumpVec.z); } #endif } NETINPUT_TRACE(player.GetEntityId(), jumpVec); FinalizeVelocity( player, jumpVec ); if (!player.IsRemote()) { player.HasJumped(player.GetMoveRequest().velocity); } IPhysicalEntity* pPhysEnt = player.GetEntity()->GetPhysics(); if (pPhysEnt != NULL) { SAnimatedCharacterParams params = player.m_pAnimatedCharacter->GetParams(); pe_player_dynamics pd; pd.kAirControl = player.GetAirControl()* g_pGameCVars->pl_jump_control.air_control_scale; pd.kAirResistance = player.GetAirResistance() * g_pGameCVars->pl_jump_control.air_resistance_scale; params.inertia = player.GetInertia() * g_pGameCVars->pl_jump_control.air_inertia_scale; if(player.IsRemote() && (g_pGameCVars->pl_velocityInterpAirControlScale > 0)) { pd.kAirControl = g_pGameCVars->pl_velocityInterpAirControlScale; } pPhysEnt->SetParams(&pd); // Let Animated character handle the inertia player.SetAnimatedCharacterParams(params); } #if 0 if (debugJumping) { Vec3 entityPos = m_player.GetEntity()->GetWorldPos(); gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine(entityPos, ColorB(255,255,255,255), entityPos, ColorB(255,255,0,255), 2.0f); gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine(entityPos+Vec3(0,0,2), ColorB(255,255,255,255), entityPos+Vec3(0,0,2) + desiredVel, ColorB(0,255,0,255), 2.0f); gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine(entityPos, ColorB(255,255,255,255), entityPos + jumpVec, ColorB(0,255,255,255), 2.0f); gEnv->pRenderer->DrawLabel(entityPos - entityRight * 1.0f + Vec3(0,0,3.0f), 1.5f, "Velo[%2.3f = %2.3f, %2.3f, %2.3f]", m_request.velocity.len(), m_request.velocity.x, m_request.velocity.y, m_request.velocity.z); } #endif m_expectedJumpEndHeight = expectedJumpEndHeight; m_bSprintJump = player.IsSprinting(); }