float CGameRulesRSSpawning::GetScoreFromProximityToEnemiesNoTeams( SUsefulSpawnData& spawnData, const Vec3& potentialSpawnPosition ) { SpawnLogAlways("[SPAWN] > GetScoreFromProximityToEnemiesNoTeams()"); float fScoreFromEnemies = 0.0f; CGameRules::TPlayers players; g_pGame->GetGameRules()->GetPlayers(players); if(players.size() > 1) { const float fScoreOnTopOfEnemy = 200.0f; const float fMultiplierForEnemyDistance = 1.7f; const float fDistanceScoreMultiplier = 200.0f; int i = -1; for(CGameRules::TPlayers::iterator it=players.begin();it!=players.end();++it) { i++; if(*it == spawnData.playerId) continue; const IEntity *pOther = gEnv->pEntitySystem->GetEntity(*it); Vec3 vDiffToEnemy = (pOther->GetWorldPos() - potentialSpawnPosition); vDiffToEnemy.z += max(2.0f * vDiffToEnemy.z, 6.0f); float fDistanceFromEnemy = vDiffToEnemy.len(); float fDistanceScoreFraction = __fres(max(fDistanceFromEnemy - 4.f, 0.001f)); float fScoreForThisEnemy = max(fScoreOnTopOfEnemy - (fDistanceFromEnemy * fMultiplierForEnemyDistance), 0.0f) + (fDistanceScoreFraction * fDistanceScoreMultiplier); SpawnLogAlways("[SPAWN] >>> Score from Enemy %d is %.6f at distance %.1f", i, fScoreForThisEnemy, fDistanceFromEnemy); fScoreFromEnemies = max(fScoreForThisEnemy, fScoreFromEnemies); } SpawnLogAlways("[SPAWN] >> Total Score from Enemies: %.6f", fScoreFromEnemies); } return fScoreFromEnemies; }
//------------------------------------------------------------------------- void CGameRulesStandardState::ChangeState( EGR_GameState newState ) { if (gEnv->bServer) { if (newState == EGRS_InGame) { CCCPOINT(GameRulesStandardState_EnterInGame); #if !defined(_RELEASE) || defined(PERFORMANCE_BUILD) if (m_state != EGRS_InGame) { if (g_pGameCVars->g_gameRules_startCmd[0] != '\0') { gEnv->pConsole->ExecuteString(g_pGameCVars->g_gameRules_startCmd, false, true); } } #endif // #if !defined(_RELEASE) || defined(PERFORMANCE_BUILD) m_pGameRules->ResetGameTime(); IGameRulesStatsRecording *st=m_pGameRules->GetStatsRecordingModule(); if (st) { st->OnInGameBegin(); } } else if (newState == EGRS_PostGame) { m_timeInPostGame = 0.0f; IGameRulesStatsRecording *st=m_pGameRules->GetStatsRecordingModule(); if (st) { st->OnPostGameBegin(); } #if defined(DEDICATED_SERVER) if ( gEnv->bMultiplayer ) { // Stop cvar probes. CGameRules::TPlayers players; m_pGameRules->GetPlayers(players); const int numPlayers = players.size(); for (int i = 0; i < numPlayers; ++ i) { const EntityId playerId = players[i]; IActor * pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(playerId); if ( pActor ) { IGameObject * pGameObject = NULL; INetChannel * pNetChannel = NULL; IDefenceContext * pDefenceContext = NULL; if ( (pGameObject = pActor->GetGameObject()) ) { if ( (pNetChannel = pGameObject->GetNetChannel()) ) { if ( (pDefenceContext = pNetChannel->GetDefenceContext()) ) { pDefenceContext->EndCvarRequests(); } } } } } } #endif CGameLobby *pGameLobby = g_pGame->GetGameLobby(); if (pGameLobby) { CryLog("[GameRules] GameFinished, telling clients"); pGameLobby->SvFinishedGame(0.0f); } } } const bool bIsClient = gEnv->IsClient(); if (bIsClient) { if (newState == EGRS_PostGame) { m_timeInPostGame = 0.0f; EnterPostGameState(ePGS_Starting); } else if (newState == EGRS_InGame) { CHUDEventDispatcher::CallEvent( SHUDEvent(eHUDEvent_OnGameStart) ); } else if (newState == EGRS_Reset) { m_introMessageShown = false; } ClientChangeStateFeedback(newState); } m_state = newState; OnStateEntered_NotifyListeners(); if (newState == EGRS_PostGame) { m_pGameRules->FreezeInput(true); g_pGame->GetUI()->ActivateDefaultState(); // must be after settings newState to pick endgame OnGameEnd_NotifyListeners(); } else if (newState == EGRS_InGame) { OnGameStart_NotifyListeners(); if (bIsClient && g_pGameCVars->g_gameRules_preGame_StartSpawnedFrozen) { g_pGameActions->FilterMPPreGameFreeze()->Enable(false); g_pGame->GetUI()->ActivateDefaultState(); // must be after settings newState } // Have to explicitly call the spawning module, can't use the listener since that would make the modules // dependent on the initialisation order - which comes from xml IGameRulesSpawningModule *pSpawningModule = m_pGameRules->GetSpawningModule(); if (pSpawningModule) { pSpawningModule->OnInGameBegin(); } } if (gEnv->bServer) { CHANGED_NETWORK_STATE(m_pGameRules, STANDARD_STATE_ASPECT); if (m_state == EGRS_InGame) { // Revive players - has to be done after setting m_state since we don't revive players in PreGame IGameRulesSpawningModule *pSpawningModule = m_pGameRules->GetSpawningModule(); if (pSpawningModule) { const bool bOnlyIfDead = (g_pGameCVars->g_gameRules_preGame_StartSpawnedFrozen!=0); pSpawningModule->ReviveAllPlayers(false, bOnlyIfDead); } } } }