void App::ShutdownCurrentGame() { // // Stop the MetaServer registration if( MetaServer_IsRegisteringOverLAN() ) { MetaServer_StopRegisteringOverLAN(); } if( MetaServer_IsRegisteringOverWAN() ) { MetaServer_StopRegisteringOverWAN(); } if( m_gameRunning ) { EclRemoveAllWindows(); } // // If there is a client, shut it down now if( m_world ) { delete m_world; m_world = NULL; } if( m_clientToServer->IsConnected() ) { m_clientToServer->ClientLeave(true); } else { m_clientToServer->ClientLeave(false); } // // If there is a server, shut it down now if( m_server ) { m_server->Shutdown(); delete m_server; m_server = NULL; } if( m_tutorial ) { delete m_tutorial; m_tutorial = NULL; } m_gameRunning = false; delete m_game; m_game = new Game(); g_startTime = FLT_MAX; g_gameTime = 0.0f; g_advanceTime = 0.0f; g_lastServerAdvance = 0.0f; g_predictionTime = 0.0f; g_lastProcessedSequenceId = -2; // -2=not yet ready to begin. -1=ready for first update (id=0) g_soundSystem->StopAllSounds( SoundObjectId(), "StartMusic StartMusic" ); g_app->GetMapRenderer()->m_renderEverything = false; m_gameStartTimer = -1.0f; GetInterface()->SetMouseCursor(); SetMousePointerVisible(true); }
void RestartTestBed( int result, char *notes ) { if( g_app->GetServer() ) { // // Log result FILE *file = fopen("testbed-results.txt", "a"); if( file ) { char *resultString = NULL; switch( result ) { case -1: resultString = "FAILED"; break; case 1: resultString = "SUCCESS"; break; } time_t theTimeT = time(NULL); tm *theTime = localtime(&theTimeT); char *modPath = g_preferences->GetString( "ModPath" ); fprintf( file, "%02d-%02d-%02d %02d:%02d.%02d %15s %s %s\n", 1900+theTime->tm_year, theTime->tm_mon+1, theTime->tm_mday, theTime->tm_hour, theTime->tm_min, theTime->tm_sec, modPath, resultString, notes ); fclose( file ); } // // Shut down game g_app->ShutdownCurrentGame(); EclRemoveAllWindows(); g_app->GetInterface()->OpenSetupWindows(); // // Start some random Mods TestBedSetupMods(); // // New game LobbyWindow *lobby = new LobbyWindow(); lobby->StartNewServer(); EclRegisterWindow( lobby ); } else { // // We are a client // Shut down game // Remember the server we were connected to char serverIp[256]; int serverPort=0; int numTeams = 0; g_app->GetClientToServer()->GetServerDetails( serverIp, &serverPort ); g_app->ShutdownCurrentGame(); EclRemoveAllWindows(); g_app->GetInterface()->OpenSetupWindows(); Sleep(3000); // // Parse the settings file FILE *file = fopen( "testbed.txt", "rt" ); if( file ) { fscanf( file, "IP %s\n", serverIp ); fscanf( file, "PORT %d\n", &serverPort ); fscanf( file, "TEAMS %d\n", &numTeams ); fclose(file); } // // Attempt rejoin // Connect to the new server // Open up game windows g_app->GetClientToServer()->ClientJoin( serverIp, serverPort ); g_app->InitWorld(); ConnectingWindow *connectWindow = new ConnectingWindow(); connectWindow->m_popupLobbyAtEnd = true; EclRegisterWindow( connectWindow ); } }
void App::StartGame() { int numSpectators = g_app->GetGame()->GetOptionValue( "MaxSpectators" ); if( numSpectators == 0 ) { m_clientToServer->StopIdentifying(); } bool connectingWindowOpen = EclGetWindow( "Connection Status" ); EclRemoveAllWindows(); g_soundSystem->TriggerEvent( "Music", "StartMusic" ); m_interface->OpenGameWindows(); if( connectingWindowOpen ) EclRegisterWindow( new ConnectingWindow() ); int randSeed = 0; for( int i = 0; i < m_world->m_teams.Size(); ++i ) { randSeed += m_world->m_teams[i]->m_randSeed; } syncrandseed( randSeed ); AppDebugOut( "App RandSeed = %d\n", randSeed ); GetWorld()->LoadNodes(); GetWorld()->AssignCities(); if( GetGame()->GetOptionValue("GameMode") == GAMEMODE_OFFICEMODE ) { g_soundLibrary3d->SetMasterVolume(0); if( !g_windowManager->Windowed() ) { ReinitialiseWindow(); } } if( GetGame()->GetOptionValue("MaxGameRealTime") != 0.0f ) { GetGame()->m_maxGameTime = GetGame()->GetOptionValue("MaxGameRealTime"); GetGame()->m_maxGameTime *= 60; } // // Set radar sharing and ceasefire defaults for( int i = 0; i < g_app->GetWorld()->m_teams.Size(); ++i ) { Team *firstTeam = g_app->GetWorld()->m_teams[i]; for( int j = 0; j < g_app->GetWorld()->m_teams.Size(); ++j ) { if( i != j ) { Team *secondTeam = g_app->GetWorld()->m_teams[j]; if( g_app->GetWorld()->IsFriend(firstTeam->m_teamId, secondTeam->m_teamId) ) { firstTeam->m_sharingRadar[secondTeam->m_teamId] = true; firstTeam->m_ceaseFire[secondTeam->m_teamId] = true; firstTeam->m_alwaysSolo = false; } } } } // // Set game speeds int minSpeedSetting = g_app->GetGame()->GetOptionValue("SlowestSpeed"); int minSpeed = ( minSpeedSetting == 0 ? 0 : minSpeedSetting == 1 ? 1 : minSpeedSetting == 2 ? 5 : minSpeedSetting == 3 ? 10 : minSpeedSetting == 4 ? 25 : 25 ); //changed from 20 and 20 for( int i = 0; i < g_app->GetWorld()->m_teams.Size(); ++i ) { Team *team = g_app->GetWorld()->m_teams[i]; if( team->m_type != Team::TypeAI ) { team->m_desiredGameSpeed = max( team->m_desiredGameSpeed, minSpeed ); } } m_gameRunning = true; }