//------------------------------------------------------------------------
void CGameRulesHoldObjectiveBase::CleanUpEntity(SHoldEntityDetails *pDetails)
{
	CCCPOINT(HoldObjective_CleanUpActiveCaptureEntity);

	if (pDetails->m_localPlayerIsWithinRange)
	{		
		CHUDEventDispatcher::CallEvent(SHUDEvent(eHUDEvent_OnSiteAboutToExplode));
	}

	OnRemoveHoldEntity(pDetails);

	gEnv->pEntitySystem->RemoveEntityEventListener(pDetails->m_id, ENTITY_EVENT_ENTERAREA, this);
	gEnv->pEntitySystem->RemoveEntityEventListener(pDetails->m_id, ENTITY_EVENT_LEAVEAREA, this);

	if (m_spawnPOIType == eSPT_Avoid)
	{
		IGameRulesSpawningModule *pSpawningModule = g_pGame->GetGameRules()->GetSpawningModule();
		if (pSpawningModule)
		{
			pSpawningModule->RemovePOI(pDetails->m_id);
		}
	}

	IEntity *pEntity = gEnv->pEntitySystem->GetEntity(pDetails->m_id);
	if (pEntity)
	{
		IScriptTable *pScript = pEntity->GetScriptTable();
		if (pScript != NULL && pScript->GetValueType("DeactivateCapturePoint") == svtFunction)
		{
			IScriptSystem *pScriptSystem = gEnv->pScriptSystem;
			pScriptSystem->BeginCall(pScript, "DeactivateCapturePoint");
			pScriptSystem->PushFuncParam(pScript);
			pScriptSystem->PushFuncParam(true);
			pScriptSystem->EndCall();
		}

		CGameRules *pGameRules = g_pGame->GetGameRules();
		EGameMode gamemode = pGameRules->GetGameMode();
		if (gamemode == eGM_CrashSite)
		{
			Announce("Destruct", k_announceType_CS_Destruct);
		}
	}

	pDetails->Reset();

	// Fade out effect
	m_effectData.alphaLerp.Set(1.0f,0.0f,0.0f);
}
void CLocalPlayerComponent::Revive()
{
	if(gEnv->bMultiplayer)
	{
		// Reset NotYetSpawned filter.
		IActionFilter* pNYSFilter = g_pGameActions->FilterNotYetSpawned();
		if(pNYSFilter && pNYSFilter->Enabled())
		{
			pNYSFilter->Enable(false);
		}

		// For Modes where we can swap teams per round, refresh everyone else's cloak colour on revive.
		CGameRules *pGameRules = g_pGame->GetGameRules();
		if( pGameRules->GetGameMode()==eGM_Gladiator )
		{
			IActorSystem* pActorSys = g_pGame->GetIGameFramework()->GetIActorSystem();
			CActorManager* pActorManager = CActorManager::GetActorManager();
			pActorManager->PrepareForIteration();
			const int kNumActors = pActorManager->GetNumActors();
			for(int i=0; i<kNumActors; i++)
			{
				SActorData actorData;
				pActorManager->GetNthActorData(i, actorData);		
				if(CActor* pActor = static_cast<CActor*>(pActorSys->GetActor(actorData.entityId)))
				{
					if(pActor->IsCloaked())
					{
						pActor->SetCloakLayer(false);
						pActor->SetCloakLayer(true);
					}
				}
			}
		}
	}

	m_bIsInFreeFallDeath = false;
	m_playedMidHealthSound = false;
}
Esempio n. 3
0
void CPlayerStateUtil::AdjustMovementForEnvironment( const CPlayer& player, Vec3& move, const bool bigWeaponRestrict, const bool crouching )
{
	float mult = (bigWeaponRestrict) 
		? g_pGameCVars->pl_movement.nonCombat_heavy_weapon_speed_scale * player.GetModifiableValues().GetValue(kPMV_HeavyWeaponMovementMultiplier) 
		: 1.0f;

	if (gEnv->bMultiplayer)
	{
		CGameRules *pGameRules = g_pGame->GetGameRules();
		IGameRulesObjectivesModule *pObjectives = pGameRules ? pGameRules->GetObjectivesModule() : NULL;

		if (pObjectives)
		{
			switch(pGameRules->GetGameMode())
			{
				case eGM_Extraction:
				{
					if( pObjectives->CheckIsPlayerEntityUsingObjective(player.GetEntityId()) ) // Carrying a tick
					{
						mult *= g_pGameCVars->mp_extractionParams.carryingTick_SpeedScale;
					}
					break;
				}
				case eGM_CaptureTheFlag:
				{
					if( pObjectives->CheckIsPlayerEntityUsingObjective(player.GetEntityId()) ) // Carrying a flag
					{
						mult *= g_pGameCVars->mp_ctfParams.carryingFlag_SpeedScale;
					}
					break;	
				}
				default:
					break;
			}
		}
	}

	mult *= g_pGameCVars->pl_movement.speedScale;

	if (player.IsSprinting())
	{
		if (bigWeaponRestrict)
		{
			mult *= g_pGameCVars->pl_movement.nonCombat_heavy_weapon_sprint_scale;
		}
		else
		{
			mult *= g_pGameCVars->pl_movement.sprint_SpeedScale;
		}
	}
	else if (crouching)
	{
		if (bigWeaponRestrict)
		{
			mult *= g_pGameCVars->pl_movement.nonCombat_heavy_weapon_crouch_speed_scale;
		}
		else
		{
			mult *= g_pGameCVars->pl_movement.crouch_SpeedScale;
		}
	}

	move *= mult;

}
//------------------------------------------------------------------------
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);
		}
	}
}