//----------------------------------------------------------------------------- // Purpose: Set whether the ship is exploding //----------------------------------------------------------------------------- void CShip::SetExploding( bool bExploding ) { // If we are already in the specified state, no need to do the below work if ( m_bExploding == bExploding ) return; Steamworks_TestSecret(); // Track that we are exploding, and disable collision detection m_bExploding = bExploding; SetCollisionDetectionDisabled( m_bExploding ); if ( bExploding ) { for( int i = 0; i < SHIP_DEBRIS_PIECES; ++i ) { CShipDebris * pDebris = new CShipDebris( m_pGameEngine, GetXPos(), GetYPos(), m_dwShipColor ); m_ListDebris.push_back( pDebris ); } } else { std::list<CShipDebris *>::iterator iter; for( iter = m_ListDebris.begin(); iter != m_ListDebris.end(); ++iter ) delete *iter; m_ListDebris.clear(); } }
//----------------------------------------------------------------------------- // Purpose: Main loop code shared between all platforms //----------------------------------------------------------------------------- void RunGameLoop( IGameEngine *pGameEngine, const char *pchServerAddress, const char *pchLobbyID ) { // Make sure it initialized ok if ( pGameEngine->BReadyForUse() ) { // Initialize the game CSpaceWarClient *pGameClient = new CSpaceWarClient( pGameEngine ); // Black background pGameEngine->SetBackgroundColor( 0, 0, 0, 0 ); // If +connect was used to specify a server address, connect now pGameClient->ExecCommandLineConnect( pchServerAddress, pchLobbyID ); // test a user specific secret before entering main loop Steamworks_TestSecret(); pGameClient->RetrieveEncryptedAppTicket(); while( !pGameEngine->BShuttingDown() ) { if ( pGameEngine->StartFrame() ) { pGameEngine->UpdateGameTickCount(); // Run a game frame pGameClient->RunFrame(); pGameEngine->EndFrame(); // Sleep to limit frame rate while( pGameEngine->BSleepForFrameRateLimit( MAX_CLIENT_AND_SERVER_FPS ) ) { // Keep running the network on the client at a faster rate than the FPS limit pGameClient->ReceiveNetworkData(); } } } delete pGameClient; } // Cleanup the game engine delete pGameEngine; }
//========================================================= //========================================================= void C_GameInstructor::FireGameEvent( IGameEvent *event ) { VPROF_BUDGET( "C_GameInstructor::FireGameEvent", "GameInstructor" ); const char *name = event->GetName(); if ( Q_strcmp( name, "gameinstructor_draw" ) == 0 ) { if ( m_bNoDraw ) { if ( gameinstructor_verbose.GetInt() > 0 ) { ConColorMsg( CBaseLesson::m_rgbaVerboseHeader, "[INSTRUCTOR]: " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "Set to draw...\n" ); } m_bNoDraw = false; } } else if ( Q_strcmp( name, "gameinstructor_nodraw" ) == 0 ) { if ( !m_bNoDraw ) { if ( gameinstructor_verbose.GetInt() > 0 ) { ConColorMsg( CBaseLesson::m_rgbaVerboseHeader, "[INSTRUCTOR]: " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "Set to not draw...\n" ); } m_bNoDraw = true; StopAllLessons(); } } else if ( Q_strcmp( name, "round_end" ) == 0 ) { if ( gameinstructor_verbose.GetInt() > 0 ) { ConColorMsg( CBaseLesson::m_rgbaVerboseHeader, "[INSTRUCTOR]: " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "Round ended...\n" ); } CloseAllOpenOpportunities(); if ( IsPC() ) { // Good place to backup our counts WriteSaveData(); } } else if ( Q_strcmp( name, "round_start" ) == 0 ) { if ( gameinstructor_verbose.GetInt() > 0 ) { ConColorMsg( CBaseLesson::m_rgbaVerboseHeader, "[INSTRUCTOR]: " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "Round started...\n" ); } CloseAllOpenOpportunities(); EvaluateLessonsForGameRules(); } else if ( Q_strcmp( name, "player_death" ) == 0 ) { #if !defined(NO_STEAM) && defined(USE_CEG) Steamworks_TestSecret(); Steamworks_SelfCheck(); #endif C_BasePlayer *pLocalPlayer = GetLocalPlayer(); if ( pLocalPlayer && pLocalPlayer == UTIL_PlayerByUserId( event->GetInt( "userid" ) ) ) { if ( gameinstructor_verbose.GetInt() > 0 ) { ConColorMsg( CBaseLesson::m_rgbaVerboseHeader, "[INSTRUCTOR]: " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "Local player died...\n" ); } for ( int i = m_OpenOpportunities.Count() - 1; i >= 0; --i ) { CBaseLesson *pLesson = m_OpenOpportunities[ i ]; CBaseLesson *pRootLesson = pLesson->GetRoot(); if ( !pRootLesson->CanOpenWhenDead() ) CloseOpportunity( pLesson ); } } } else if ( Q_strcmp( name, "player_team" ) == 0 ) { C_BasePlayer *pLocalPlayer = GetLocalPlayer(); if ( pLocalPlayer && pLocalPlayer == UTIL_PlayerByUserId( event->GetInt( "userid" ) ) && ( event->GetInt( "team" ) != event->GetInt( "oldteam" ) || event->GetBool( "disconnect" ) ) ) { if ( gameinstructor_verbose.GetInt() > 0 ) { ConColorMsg( CBaseLesson::m_rgbaVerboseHeader, "[INSTRUCTOR]: " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "Local player changed team (or disconnected)...\n" ); } CloseAllOpenOpportunities(); } EvaluateLessonsForGameRules(); } else if ( Q_strcmp( name, "player_disconnect" ) == 0 ) { C_BasePlayer *pLocalPlayer = GetLocalPlayer(); if ( pLocalPlayer && pLocalPlayer == UTIL_PlayerByUserId( event->GetInt( "userid" ) ) ) { if ( gameinstructor_verbose.GetInt() > 0 ) { ConColorMsg( CBaseLesson::m_rgbaVerboseHeader, "[INSTRUCTOR]: " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "Local player disconnected...\n" ); } CloseAllOpenOpportunities(); } } else if ( Q_strcmp( name, "map_transition" ) == 0 ) { if ( gameinstructor_verbose.GetInt() > 0 ) { ConColorMsg( CBaseLesson::m_rgbaVerboseHeader, "[INSTRUCTOR]: " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "Map transition...\n" ); } CloseAllOpenOpportunities(); if ( m_bNoDraw ) { if ( gameinstructor_verbose.GetInt() > 0 ) { ConColorMsg( Color( 255, 128, 64, 255 ), "[INSTRUCTOR]: " ); ConColorMsg( Color( 64, 128, 255, 255 ), "Set to draw...\n" ); } m_bNoDraw = false; } if ( IsPC() ) { // Good place to backup our counts WriteSaveData(); } } else if ( Q_strcmp( name, "game_newmap" ) == 0 ) { if ( gameinstructor_verbose.GetInt() > 0 ) { ConColorMsg( CBaseLesson::m_rgbaVerboseHeader, "[INSTRUCTOR]: " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "New map...\n" ); } CloseAllOpenOpportunities(); if ( m_bNoDraw ) { if ( gameinstructor_verbose.GetInt() > 0 ) { ConColorMsg( Color( 255, 128, 64, 255 ), "[INSTRUCTOR]: " ); ConColorMsg( Color( 64, 128, 255, 255 ), "Set to draw...\n" ); } m_bNoDraw = false; } if ( IsPC() ) { // Good place to backup our counts WriteSaveData(); } } else if ( Q_strcmp( name, "set_instructor_group_enabled" ) == 0 ) { const char *pszGroup = event->GetString( "group" ); bool bEnabled = event->GetInt( "enabled" ) != 0; if ( pszGroup && pszGroup[0] ) SetLessonGroupEnabled(pszGroup, bEnabled); } }