void App::NotifyStartupErrors() { // // Inform the user of any Network difficulties // detected during MetaServer startup if( !MetaServer_IsConnected() ) { char msgtext[1024]; #if defined(RETAIL_BRANDING_UK) sprintf( msgtext, "%s%s", LANGUAGEPHRASE("dialog_metaserver_failedconnect"), LANGUAGEPHRASE("website_support_retail_uk") ); #elif defined(RETAIL_BRANDING) sprintf( msgtext, "%s%s", LANGUAGEPHRASE("dialog_metaserver_failedconnect"), LANGUAGEPHRASE("website_support_retail") ); #elif defined(RETAIL_BRANDING_MULTI_LANGUAGE) sprintf( msgtext, "%s%s", LANGUAGEPHRASE("dialog_metaserver_failedconnect"), LANGUAGEPHRASE("website_support_retail_multi_language") ); #elif defined(TARGET_OS_MACOSX) sprintf( msgtext, "%s%s", LANGUAGEPHRASE("dialog_metaserver_failedconnect"), LANGUAGEPHRASE("website_support_macosx") ); #else sprintf( msgtext, "%s%s", LANGUAGEPHRASE("dialog_metaserver_failedconnect"), LANGUAGEPHRASE("website_support") ); #endif MessageDialog *msg = new MessageDialog( "FAILED TO CONNECT TO METASERVER", msgtext, false, "dialog_metaserver_failedtitle", true ); EclRegisterWindow( msg ); } // // ClientToServer listener opened ok? if( !m_clientToServer->m_listener ) { char msgtext[1024]; #if defined(RETAIL_BRANDING_UK) sprintf( msgtext, "%s%s", LANGUAGEPHRASE("dialog_client_failedconnect"), LANGUAGEPHRASE("website_support_retail_uk") ); #elif defined(RETAIL_BRANDING) sprintf( msgtext, "%s%s", LANGUAGEPHRASE("dialog_client_failedconnect"), LANGUAGEPHRASE("website_support_retail") ); #elif defined(RETAIL_BRANDING_MULTI_LANGUAGE) sprintf( msgtext, "%s%s", LANGUAGEPHRASE("dialog_client_failedconnect"), LANGUAGEPHRASE("website_support_retail_multi_language") ); #elif defined(TARGET_OS_MACOSX) sprintf( msgtext, "%s%s", LANGUAGEPHRASE("dialog_client_failedconnect"), LANGUAGEPHRASE("website_support_macosx") ); #else sprintf( msgtext, "%s%s", LANGUAGEPHRASE("dialog_client_failedconnect"), LANGUAGEPHRASE("website_support") ); #endif MessageDialog *msg = new MessageDialog( "NETWORK ERROR", msgtext, false, "dialog_client_failedtitle", true ); EclRegisterWindow( msg ); } }
void LocationEditor::AdvanceModeLandFlat() { Vector3 mousePos3D = g_app->m_userInput->GetMousePos3d(); int newSelectionId = -1; if ( g_inputManager->controlEvent( ControlTileSelect ) ) { Vector3 mousePos = g_app->m_userInput->GetMousePos3d(); newSelectionId = IsPosInFlattenArea(mousePos); } if (m_selectionId == -1) { // If there isn't currently any selection, then check for a new one if (newSelectionId != -1) { m_selectionId = newSelectionId; m_waitingForRelease = true; EclWindow *cw = EclGetWindow("editor_landscape"); AppDebugAssert(cw); LandscapeFlattenAreaEditWindow *ew = new LandscapeFlattenAreaEditWindow("Flatten Area", newSelectionId); ew->m_w = cw->m_w; ew->m_h = 100; ew->m_x = 0; EclRegisterWindow(ew); ew->m_y = cw->m_y - ew->m_h - 10; } } else { Location *location = g_app->m_location; if ( g_inputManager->controlEvent( ControlTileSelect ) ) { if (newSelectionId == m_selectionId) { // The user "grabs" the landscape at this position LandscapeDef *landscapeDef = &(g_app->m_location->m_levelFile->m_landscape); LandscapeFlattenArea *areaDef = g_app->m_location->m_levelFile->m_landscape.m_flattenAreas.GetData(m_selectionId); m_landscapeGrabX = mousePos3D.x - areaDef->m_centre.x; m_landscapeGrabZ = mousePos3D.z - areaDef->m_centre.z; } else { // The user has deselected the flatten area m_selectionId = newSelectionId; m_waitingForRelease = true; EclRemoveWindow("Flatten Area"); } } else if ( g_inputManager->controlEvent( ControlTileDrag ) ) { // The user "drags" the flatten area around LandscapeFlattenArea *areaDef = g_app->m_location->m_levelFile->m_landscape.m_flattenAreas.GetData(m_selectionId); areaDef->m_centre.x = mousePos3D.x - m_landscapeGrabX; areaDef->m_centre.z = mousePos3D.z - m_landscapeGrabZ; } } }
void MouseUp() { if (m_type == TypeSave) { // // If a MOD hasn't been set, don't allow this to happen // as it will try to save into darwinia/data/levels, which is clearly wrong // for the end user (but allow it for us) #ifndef TARGET_DEBUG if( !g_app->m_resource->IsModLoaded() ) { EclRegisterWindow( new MessageDialog( LANGUAGEPHRASE( "dialog_savelocationsfail1" ), LANGUAGEPHRASE( "dialog_savelocationsfail2" ) ), m_parent ); return; } #endif g_app->m_location->m_levelFile->Save(); return; } g_app->m_locationEditor->RequestMode(m_type); }
void EclRegisterPopup ( EclWindow *window ) { EclRemovePopup(); //DebugAssert( window ); strcpy( popupWindow, window->m_name ); EclRegisterWindow( window ); }
void UnitPlacementButton::MouseUp() { #ifndef NON_PLAYABLE if( g_app->GetWorld()->GetTimeScaleFactor() == 0 ) { return; } if( !m_disabled ) { if( !EclGetWindow( "Placement" ) ) { SidePanel *parent = (SidePanel *)m_parent; parent->m_mode = SidePanel::ModeUnitPlacement; PlacementIconWindow *icon = new PlacementIconWindow( "Placement", m_unitType ); EclRegisterWindow( icon, m_parent ); g_app->GetMapRenderer()->m_showTeam[ g_app->GetWorld()->m_myTeamId ] = true; if( m_unitType == WorldObject::TypeRadarStation ) { g_app->GetMapRenderer()->m_showRadar = true; } InfoWindow *info = (InfoWindow *)EclGetWindow("Info"); if( info ) { info->SwitchInfoDisplay( m_unitType, -1 ); } } else { EclRemoveWindow( "Placement" ); } } #endif }
void MouseUp() { if (stricmp(m_name, LANGUAGEPHRASE("editor_generate")) == 0) { LandscapeDef *def = &g_app->m_location->m_levelFile->m_landscape; g_app->m_location->m_landscape.Init(def); } else if (stricmp(m_name, LANGUAGEPHRASE("editor_randomise")) == 0) { m_def->m_randomSeed = (int)(GetHighResTime() * 1000.0f); InputField *randomSeed = (InputField *)m_parent->GetButton(LANGUAGEPHRASE("editor_seed")); if (randomSeed) { randomSeed->Refresh(); } LandscapeDef *def = &g_app->m_location->m_levelFile->m_landscape; g_app->m_location->m_landscape.Init(def); } else if( stricmp(m_name, LANGUAGEPHRASE("editor_delete")) == 0 ) { int tileId = ((LandscapeTileEditWindow *) m_parent)->m_tileId; g_app->m_location->m_landscape.DeleteTile( tileId ); EclRemoveWindow( m_parent->m_name ); } else if( stricmp(m_name, LANGUAGEPHRASE("editor_clone")) == 0 ) { Vector3 rayStart; Vector3 rayDir; g_app->m_camera->GetClickRay(g_app->m_renderer->ScreenW()/2, g_app->m_renderer->ScreenH()/2, &rayStart, &rayDir); Vector3 _pos; g_app->m_location->m_landscape.RayHit( rayStart, rayDir, &_pos ); LandscapeDef *landscapeDef = &(g_app->m_location->m_levelFile->m_landscape); LandscapeTile *tile = new LandscapeTile(); g_app->m_location->m_levelFile->m_landscape.m_tiles.PutDataAtEnd(tile); tile->m_size = m_def->m_size; tile->m_posX = _pos.x - tile->m_size/2; tile->m_posY = m_def->m_posY; tile->m_posZ = _pos.z - tile->m_size/2; tile->m_fractalDimension = m_def->m_fractalDimension; tile->m_heightScale = m_def->m_heightScale; tile->m_desiredHeight = m_def->m_desiredHeight; tile->m_randomSeed = m_def->m_randomSeed; tile->m_lowlandSmoothingFactor = m_def->m_lowlandSmoothingFactor; tile->m_generationMethod = m_def->m_generationMethod; LandscapeDef *def = &g_app->m_location->m_levelFile->m_landscape; g_app->m_location->m_landscape.Init(def); } else if( stricmp(m_name, LANGUAGEPHRASE("editor_guidegrid")) == 0 ) { int tileId = ((LandscapeTileEditWindow *) m_parent)->m_tileId; LandscapeGuideGridWindow *guide = new LandscapeGuideGridWindow(LANGUAGEPHRASE("editor_guidegrid"), tileId ); guide->SetSize( 300, 300 ); guide->SetPosition( m_parent->m_x + m_parent->m_w + 10, m_parent->m_y ); EclRegisterWindow( guide, m_parent ); } }
bool App::InitServer() { m_server = new Server(); bool result = m_server->Initialise(); // // Inform the user of the problem, and shut it down if( !result ) { delete m_server; m_server = NULL; char msgtext[1024]; #if defined(RETAIL_BRANDING_UK) sprintf( msgtext, "%s%s", LANGUAGEPHRASE("dialog_server_failedconnect"), LANGUAGEPHRASE("website_support_retail_uk") ); #elif defined(RETAIL_BRANDING) sprintf( msgtext, "%s%s", LANGUAGEPHRASE("dialog_server_failedconnect"), LANGUAGEPHRASE("website_support_retail") ); #elif defined(RETAIL_BRANDING_MULTI_LANGUAGE) sprintf( msgtext, "%s%s", LANGUAGEPHRASE("dialog_server_failedconnect"), LANGUAGEPHRASE("website_support_retail_multi_language") ); #elif defined(TARGET_OS_MACOSX) sprintf( msgtext, "%s%s", LANGUAGEPHRASE("dialog_server_failedconnect"), LANGUAGEPHRASE("website_support_macosx") ); #else sprintf( msgtext, "%s%s", LANGUAGEPHRASE("dialog_server_failedconnect"), LANGUAGEPHRASE("website_support") ); #endif MessageDialog *msg = new MessageDialog( "FAILED TO START SERVER", msgtext, false, "dialog_server_failedtitle", true ); EclRegisterWindow( msg ); return false; } // // Everything Ok int len = min<int>( (int) m_game->m_options[0]->m_max, sizeof( m_game->m_options[0]->m_currentString ) ); strncpy( m_game->m_options[0]->m_currentString, g_preferences->GetString( "ServerName1", "" ), len ); m_game->m_options[0]->m_currentString[ len - 1 ] = '\x0'; SafetyString( m_game->m_options[0]->m_currentString ); ReplaceExtendedCharacters( m_game->m_options[0]->m_currentString ); if( strlen( m_game->m_options[0]->m_currentString ) == 0 || strcmp( m_game->m_options[0]->m_currentString, g_languageTable->LookupBasePhrase( "gameoption_New_Game_Server" ) ) == 0 ) { if( g_languageTable->DoesTranslationExist( "gameoption_New_Game_Server" ) || g_languageTable->DoesPhraseExist( "gameoption_New_Game_Server" ) ) { strncpy( m_game->m_options[0]->m_currentString, LANGUAGEPHRASE("gameoption_New_Game_Server"), len ); m_game->m_options[0]->m_currentString[ len - 1 ] = '\x0'; SafetyString( m_game->m_options[0]->m_currentString ); ReplaceExtendedCharacters( m_game->m_options[0]->m_currentString ); } } return true; }
void ColourWidget::MouseUp() { ColourWindow *cw = new ColourWindow( LANGUAGEPHRASE("editor_coloureditor") ); cw->SetSize( 200, 100 ); cw->SetValue( m_value ); cw->SetCallback( m_callback ); EclRegisterWindow( cw, m_parent ); }
void Interface::OpenSetupWindows() { if( !EclGetWindow("Main Menu" ) ) { MainMenu *mainmenu = new MainMenu(); EclRegisterWindow( mainmenu ); } }
void SoundParameterButton::MouseUp() { SoundParameterEditor *editor = new SoundParameterEditor( m_caption ); editor->SetSize( 400.0, 400.0 ); editor->m_parameter = m_parameter; editor->m_minOutput = m_minOutput; editor->m_maxOutput = m_maxOutput; EclRegisterWindow( editor, m_parent ); }
void LocationEditor::AdvanceModeInstantUnit() { Camera *cam = g_app->m_camera; int newSelectionId = -1; if ( g_inputManager->controlEvent( ControlTileSelect ) ) // TODO: Should be something else? { Vector3 rayStart, rayDir; cam->GetClickRay( g_target->X(), g_target->Y(), &rayStart, &rayDir ); newSelectionId = DoesRayHitInstantUnit(rayStart, rayDir); } if (m_selectionId == -1) { if (newSelectionId != -1) { m_selectionId = newSelectionId; EclWindow *cw = EclGetWindow("editor_instantunits"); AppDebugAssert(cw); InstantUnitEditWindow *ew = new InstantUnitEditWindow("editor_instantuniteditor"); ew->m_w = cw->m_w; ew->m_h = 160; ew->m_x = cw->m_x; EclRegisterWindow(ew); ew->m_y = cw->m_y - ew->m_h - 10; m_waitingForRelease = true; } } else { if ( g_inputManager->controlEvent( ControlTileSelect ) ) // TODO: Something else? { if (newSelectionId != m_selectionId) { m_selectionId = -1; EclRemoveWindow("editor_instantuniteditor"); } } else if ( g_inputManager->controlEvent( ControlTileDrag ) ) // TODO: Something else? { InstantUnit *iu = g_app->m_location->m_levelFile->m_instantUnits.GetData(m_selectionId); switch (m_tool) { case ToolMove: { Vector3 mousePos = g_app->m_userInput->GetMousePos3d(); iu->m_posX = mousePos.x; iu->m_posZ = mousePos.z; break; } } } } }
void MouseUp() { AlliancesWindow *parent = (AlliancesWindow *)m_parent; int voteId = parent->m_votes[m_voteIndex]; Vote *vote = g_app->GetWorld()->m_votingSystem.LookupVote( voteId ); if( vote ) { VotingWindow *votingWindow = new VotingWindow(); votingWindow->m_voteId = voteId; EclRegisterWindow( votingWindow, m_parent ); } }
void MouseUp() { AlliancesWindow *parent = (AlliancesWindow *)m_parent; int teamId = parent->m_teamOrder[m_teamIndex]; Team *team = g_app->GetWorld()->GetTeam(teamId); Team *myTeam = g_app->GetWorld()->GetMyTeam(); if( team && team != myTeam && !EclGetWindow( "Share Radar" ) ) { EclRegisterWindow( new ShareRadarWindow( teamId ), m_parent ); } }
LocationEditor::LocationEditor() : m_tool(ToolNone), m_waitingForRelease(false), m_selectionId(-1), m_subSelectionId(-1), m_mode(ModeNone), m_moveBuildingsWithLandscape(1) { MainEditWindow *mainWin = new MainEditWindow("editor_mainedit"); mainWin->m_w = 150; mainWin->m_h = 140; mainWin->m_x = g_app->m_renderer->ScreenW(); mainWin->m_y = 0; EclRegisterWindow(mainWin); }
void App::InitMetaServer() { // // Load our Auth Key #if defined(RETAIL_DEMO) // Anthentication_EnforceDemo(); #endif char authKey[256]; Authentication_LoadKey( authKey, App::GetAuthKeyPath() ); Authentication_SetKey( authKey ); int result = Authentication_SimpleKeyCheck( authKey ); Authentication_RequestStatus( authKey ); if( result < 0 ) { #if defined(RETAIL_DEMO) // char authKeyNew[256]; // Authentication_GenerateKey( authKeyNew, true ); // Authentication_SetKey( authKeyNew ); // Authentication_SaveKey( authKeyNew, App::GetAuthKeyPath() ); // EclRegisterWindow( new WelcomeToDemoWindow() ); #else AuthKeyWindow *window = new AuthKeyWindow(); EclRegisterWindow( window ); #endif } // // Connect to the MetaServer char *metaServerLocation = "metaserver.introversion.co.uk"; //metaServerLocation = "10.0.0.4"; int port = g_preferences->GetInt( PREFS_NETWORKMETASERVER ); MetaServer_Initialise(); MetaServer_Connect( metaServerLocation, PORT_METASERVER_LISTEN, port ); MatchMaker_LocateService( metaServerLocation, PORT_METASERVER_LISTEN ); }
void GameMenu::CreateMenu() { g_app->m_renderer->StartFadeIn(0.25f); // close all currently open windows LList<EclWindow *> *windows = EclGetWindows(); while (windows->Size() > 0) { EclWindow *w = windows->GetData(0); EclRemoveWindow(w->m_name); } // create the actual menu window EclRegisterWindow( new GameMenuWindow() ); // set the camera to a position with a good view of the internet g_app->m_camera->RequestMode(Camera::ModeMainMenu); g_app->m_camera->SetDebugMode(Camera::DebugModeNever); g_app->m_camera->SetTarget(Vector3(-900000, 3000000, 397000), Vector3(0,0.5f,-1)); g_app->m_camera->CutToTarget(); if( g_app->m_tutorial ) { // its possible that the player has loaded the prologue, then returned to the main menu // if so, delete the tutorial delete g_app->m_tutorial; g_app->m_tutorial = NULL; } if( g_app->m_demoEndSequence ) { delete g_app->m_demoEndSequence; g_app->m_demoEndSequence = NULL; } /*if( g_app->m_multiwinia ) { delete g_app->m_multiwinia; g_app->m_multiwinia = NULL; }*/ g_app->m_gameMode = App::GameModeNone; m_menuCreated = true; }
void App::ReinitialiseWindow() { #ifdef TARGET_OS_LINUX // Resolution/Fullscreen switching is broken on linux, pop up a dialog box // asking the user to restart to get the effect. EclRegisterWindow( new MessageDialog( "Restart Required", "dialog_restart_required_caption", true, "dialog_restart_required_title", true ) ); return; #endif g_windowManager->DestroyWin(); g_resource->Restart(); InitialiseWindow(); InitFonts(); m_mapRenderer->Init(); m_interface->Init(); }
void FleetPlacementButton::MouseUp() { if( g_app->GetWorld()->GetTimeScaleFactor() == 0 ) { return; } if( !m_disabled ) { if( !EclGetWindow( "Placement" ) ) { g_app->GetMapRenderer()->m_showTeam[ g_app->GetWorld()->m_myTeamId ] = true; SidePanel *parent = (SidePanel *)m_parent; FleetPlacementIconWindow *icon = new FleetPlacementIconWindow( "Placement", parent->m_currentFleetId ); EclRegisterWindow( icon, m_parent ); } else { EclRemoveWindow( "Placement" ); } } }
void Interface::Update() { START_PROFILE( "EclUpdate" ); EclUpdate(); END_PROFILE( "EclUpdate" ); // // Screenshot? if( g_keyDeltas[KEY_P] && !UsingChatWindow() && g_app->m_gameRunning ) { g_renderer->SaveScreenshot(); if( g_app->GetWorld()->AmISpectating() ) { int teamId = g_app->GetClientToServer()->m_clientId; g_app->GetClientToServer()->SendChatMessageReliably( teamId, 100, LANGUAGEPHRASE("dialog_saved_screenshot"), true ); } else { int teamId = g_app->GetWorld()->m_myTeamId; g_app->GetClientToServer()->SendChatMessageReliably( teamId, 100, LANGUAGEPHRASE("dialog_saved_screenshot"), false ); } } // // Pop up main menu? if( m_escTimer > 0.0f ) { m_escTimer -= g_advanceTime; } if (QuitKeyPressed()) ConfirmExit( NULL ); if (QuitImmediatelyKeyPressed() || g_inputManager->m_quitRequested) { g_inputManager->m_quitRequested = false; AttemptQuitImmediately(); } if (ToggleFullscreenKeyPressed() || s_toggleFullscreen) { g_preferences->SetInt( PREFS_SCREEN_WINDOWED, !g_preferences->GetInt( PREFS_SCREEN_WINDOWED )); g_app->ReinitialiseWindow(); s_toggleFullscreen = false; } if( g_keyDeltas[KEY_ESC] ) { // // panic key (double esc) bool panicKeyEnabled = g_preferences->GetInt(PREFS_INTERFACE_PANICKEY); bool officeMode = (g_app->GetGame()->GetOptionValue("GameMode") == GAMEMODE_OFFICEMODE); if( officeMode ) panicKeyEnabled = true; if( panicKeyEnabled && m_escTimer > 0.0f ) { g_app->HideWindow(); m_escTimer = 0.0f; g_keys[KEY_ESC] = 0; g_keyDeltas[KEY_ESC] = 0; } if( !EclGetWindow( "Main Menu" ) ) { EclRegisterWindow( new MainMenu() ); } else { EclRemoveWindow( "Main Menu" ); } m_escTimer = 0.5f; } if( !g_app->m_gameRunning && EclGetWindows()->Size() == 0 ) { EclRegisterWindow( new MainMenu() ); } }
void LocationEditor::AdvanceModeBuilding() { BuildingEditWindow *ew = (BuildingEditWindow *)EclGetWindow("editor_buildingid"); if (ew && EclMouseInWindow(ew)) return; Camera *cam = g_app->m_camera; // Find the ID of the building the user is clicking on int newSelectionId = -1; if ( g_inputManager->controlEvent( ControlTileSelect ) ) { Vector3 rayStart, rayDir; cam->GetClickRay( g_target->X(), g_target->Y(), &rayStart, &rayDir ); newSelectionId = DoesRayHitBuilding(rayStart, rayDir); } if (m_selectionId == -1) { // If there isn't currently any selection, then check for a new one if (newSelectionId != -1) { m_selectionId = newSelectionId; BuildingsCreateWindow *cw = (BuildingsCreateWindow*)EclGetWindow("editor_buildings"); AppDebugAssert(!ew); AppDebugAssert(cw); BuildingEditWindow *bew = new BuildingEditWindow("editor_buildingid"); bew->m_w = cw->m_w; bew->m_h = 140; bew->m_x = cw->m_x; EclRegisterWindow(bew); bew->m_y = cw->m_y - bew->m_h - 10; m_waitingForRelease = true; Location *location = g_app->m_location; Building *building = location->GetBuilding(m_selectionId); if( building->m_type == Building::TypeTree ) { TreeWindow *tw = new TreeWindow( "editor_treeditor" ); tw->m_w = cw->m_w; tw->m_h = 230; tw->m_y = bew->m_y - tw->m_h - 10; tw->m_x = bew->m_x; EclRegisterWindow( tw ); } } } else { Location *location = g_app->m_location; Building *building = location->GetBuilding(m_selectionId); if ( g_inputManager->controlEvent( ControlTileSelect ) ) // If left mouse is clicked then consider creating a new link { if (newSelectionId == -1) { EclRemoveWindow("editor_buildingid"); m_selectionId = -1; } else if (m_tool == ToolLink) { building->SetBuildingLink(newSelectionId); m_tool = ToolNone; } } else if ( g_inputManager->controlEvent( ControlTileDrag ) && newSelectionId == -1 ) // Otherwise consider rotation and movement { switch (m_tool) { case ToolMove: { Vector3 mousePos = g_app->m_userInput->GetMousePos3d(); building->m_pos = mousePos; break; } case ToolRotate: { Vector3 front = building->m_front; front.RotateAroundY((float)g_target->dX() * 0.01); building->m_front = front; break; } } } } }
void LocationEditor::AdvanceModeLandTile() { Vector3 mousePos3D = g_app->m_userInput->GetMousePos3d(); int newSelectionId = -1; if ( g_inputManager->controlEvent( ControlTileSelect ) ) { newSelectionId = IsPosInLandTile(mousePos3D); } if (m_selectionId == -1) { // No selection Landscape *land = &g_app->m_location->m_landscape; LList<LandscapeTile *> *tiles = &g_app->m_location->m_levelFile->m_landscape.m_tiles; // Has the user selected a tile if (newSelectionId != -1) { LandscapeTile *tile = tiles->GetData(newSelectionId); m_tool = ToolMove; m_selectionId = newSelectionId; m_newLandscapeX = tile->m_posX; m_newLandscapeZ = tile->m_posZ; m_waitingForRelease = true; EclWindow *cw = EclGetWindow("editor_landscape"); AppDebugAssert(cw); LandscapeTileEditWindow *ew = new LandscapeTileEditWindow("editor_landscapetile", newSelectionId); ew->m_w = cw->m_w; ew->m_h = 150; ew->m_x = cw->m_x; EclRegisterWindow(ew); ew->m_y = cw->m_y - ew->m_h - 10; } } if (m_selectionId != -1) { // There is a current selection if( g_inputManager->controlEvent( ControlTileDrop ) ) { // Move the selected landscape to the new position and regenerate it LandscapeTile *tileDef = g_app->m_location->m_levelFile->m_landscape.m_tiles.GetData(m_selectionId); if( m_newLandscapeX != tileDef->m_posX || m_newLandscapeZ != tileDef->m_posZ ) { if( m_moveBuildingsWithLandscape ) { MoveBuildingsInTile( tileDef, m_newLandscapeX - tileDef->m_posX, m_newLandscapeZ - tileDef->m_posZ ); } tileDef->m_posX = m_newLandscapeX; tileDef->m_posZ = m_newLandscapeZ; LandscapeDef *def = &g_app->m_location->m_levelFile->m_landscape; g_app->m_location->m_landscape.Init(def); delete g_app->m_location->m_water; g_app->m_location->m_water = new Water(); } } if( g_inputManager->controlEvent( ControlTileSelect ) ) // TODO: Should this be ControlTileGrab? { if (newSelectionId == m_selectionId) { // The user "grabs" the landscape at this position LandscapeDef *landscapeDef = &(g_app->m_location->m_levelFile->m_landscape); LandscapeTile *tileDef = g_app->m_location->m_levelFile->m_landscape.m_tiles.GetData(m_selectionId); m_landscapeGrabX = mousePos3D.x - tileDef->m_posX; m_landscapeGrabZ = mousePos3D.z - tileDef->m_posZ; } else { // The user has deselected the landscape m_tool = ToolNone; m_selectionId = -1; m_waitingForRelease = true; EclRemoveWindow("editor_landscapetile"); EclRemoveWindow("editor_guidegrid"); } } else if ( g_inputManager->controlEvent( ControlTileDrag ) ) { // The user "drags" the landscape around m_newLandscapeX = mousePos3D.x - m_landscapeGrabX; m_newLandscapeZ = mousePos3D.z - m_landscapeGrabZ; } } }
void LocationEditor::CreateEditWindowForMode(int _mode) { MainEditWindow *mainWin = (MainEditWindow *)EclGetWindow("editor_mainedit"); // Remove existing window if (mainWin->m_currentEditWindow) { EclRemoveWindow(mainWin->m_currentEditWindow->m_name); mainWin->m_currentEditWindow = NULL; } DarwiniaWindow *window = NULL; switch(_mode) { case LocationEditor::ModeLandTile: window = new LandscapeEditWindow("editor_landscape"); window->m_w = 220; break; case LocationEditor::ModeLandFlat: window = new LandscapeEditWindow("editor_landscape"); window->m_w = 220; break; case LocationEditor::ModeLight: window = new LightsEditWindow("editor_lights"); window->m_w = 220; break; case LocationEditor::ModeBuilding: window = new BuildingsCreateWindow("editor_buildings"); window->m_w = 220; break; case LocationEditor::ModeInstantUnit: window = new InstantUnitCreateWindow("editor_instantunits"); window->m_w = 220; break; case LocationEditor::ModeCameraMount: { window = new CameraMountEditWindow("editor_cameramounts"); window->m_w = 320; // DarwiniaWindow *otherWin = new CameraAnimMainEditWindow(LANGUAGEPHRASE("editor_cameraanims")); // otherWin->m_w = 270; // otherWin->m_h = 100; // otherWin->m_x = 340; // otherWin->m_y = g_app->m_renderer->ScreenH() - window->m_h; // EclRegisterWindow(otherWin); } break; case LocationEditor::ModeMultiwinia: window = new MultiwiniaOptionsWindow(); window->m_w = 300; break; case LocationEditor::ModeInvalidCrates: window = new InvalidCratesWindow(); window->m_w = 300; break; } window->m_h = 100; window->m_x = 0; window->m_y = g_app->m_renderer->ScreenH() - window->m_h; EclRegisterWindow(window); mainWin->m_currentEditWindow = window; }
void Interface::OpenGameWindows() { EclRegisterWindow( new WorldStatusWindow( "WorldStatus" ) ); EclRegisterWindow( new ScoresWindow() ); #ifndef TESTBED EclRegisterWindow( new Toolbar() ); // // If there are human opponents open the Chat window bool humanPlayers = false; bool localPlayer = false; 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::TypeRemotePlayer ) { humanPlayers = true; } if( team->m_type == Team::TypeLocalPlayer ) { localPlayer = true; } } if( humanPlayers ) { ChatWindow *chat = new ChatWindow(); EclRegisterWindow( chat ); } // // If tooltips are on, open up the Unit Help window if( g_preferences->GetInt(PREFS_INTERFACE_TOOLTIPS) == 1) { EclRegisterWindow( new InfoWindow() ); } #endif #ifdef TESTBED // Auto-open the Net-stats window if this is a testbed EclRegisterWindow( new NetworkWindow("Network", ) ); #endif // // If the Local Player is participating open up the Units window #ifndef NON_PLAYABLE if( localPlayer ) { SidePanel *sidePanel = new SidePanel("Side Panel"); EclRegisterWindow( sidePanel ); } #endif // // If this is a tutorial game pop up the Tutorial Window if( g_app->GetTutorial() ) { EclRegisterWindow( new TutorialWindow() ); } }
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; }
void Interface::Render() { g_renderer->SetBlendMode( Renderer::BlendModeNormal ); g_renderer->SetFont( "kremlin" ); bool connectionScrewed = EclGetWindow("Connection Status"); if( !connectionScrewed ) { // // Network warning messages int myClientId = g_app->GetClientToServer()->m_clientId; if( !g_app->GetClientToServer()->IsSynchronised( myClientId ) ) { Colour col( 255, 50, 50, 255 ); float size = ( g_windowManager->WindowW() / 20.0f ); float xPos = g_windowManager->WindowW()/2.0f; float yPos = g_windowManager->WindowH()*0.2f; g_renderer->TextCentreSimple( xPos, yPos, col, size, LANGUAGEPHRASE("dialog_synchronisation_error") ); if( !EclGetWindow("Resynchronise" )) { EclRegisterWindow( new ResynchroniseWindow() ); } } if( g_app->GetClientToServer()->IsConnected() && g_app->GetClientToServer()->m_connectionState == ClientToServer::StateConnected ) { Colour col( 255, 50, 50, 255 ); float size = ( g_windowManager->WindowW() / 20.0f ); float xPos = g_windowManager->WindowW()/2.0f; float yPos = g_windowManager->WindowH()*0.3f; float yPos2 = g_windowManager->WindowH()*0.4f; static int s_connectionProblem = 0; // 0=no, 1=yes, 2=recovery static float s_maxLatency = 0.0f; static float s_connProblemDetected = -1.0f; float estimatedLatency = g_app->GetClientToServer()->GetEstimatedLatency(); if( !g_app->m_gameRunning ) s_connProblemDetected = -1.0f; if( s_connectionProblem == 0 && estimatedLatency > 5.0f ) { // Connection problem beginning s_connectionProblem = 1; s_maxLatency = 5.0f; } else if( s_connectionProblem == 1 ) { if( estimatedLatency < 1.0f ) { s_connectionProblem = 0; } else { // Connection problem getting worse float timeNow = GetHighResTime(); if( s_connProblemDetected < 0.0f ) s_connProblemDetected = timeNow; if( timeNow-s_connProblemDetected > 2.0f ) { col.m_a = 255.0f * min( 1.0f, timeNow-s_connProblemDetected-2.0f ); char caption[512]; sprintf( caption, LANGUAGEPHRASE("dialog_connection_problem_seconds") ); LPREPLACEINTEGERFLAG( 'S', int(estimatedLatency), caption ); g_renderer->TextCentreSimple( xPos, yPos, col, size, caption ); } s_maxLatency = max( s_maxLatency, estimatedLatency ); float maxLat = s_maxLatency; float estLat = estimatedLatency; if( estimatedLatency < s_maxLatency - 1.0f ) { s_connectionProblem = 2; if( !EclGetWindow("Connection Status") ) { EclRegisterWindow( new ConnectingWindow() ); } } } } else if( s_connectionProblem == 2 ) { if( estimatedLatency < 1.0f ) { s_connectionProblem = 0; } else { // Connection problem recovering if( estimatedLatency > s_maxLatency + 3 ) { s_connectionProblem = 1; } else if( !EclGetWindow( "Connection Status") ) { s_connectionProblem = 0; s_maxLatency = 0.0f; } } } if( !g_app->GetServer() ) { int packetLoss = g_app->GetClientToServer()->CountPacketLoss(); int totalBad = packetLoss * 4 + estimatedLatency * 10; Clamp( totalBad, 0, 20 ); int red = totalBad*12; int green = 255 - red; col.Set(red,green,0,255); g_renderer->RectFill( 5, 5, 13, 13, col ); g_renderer->SetFont(); float yPos = 20; if( estimatedLatency > 1.0f ) { g_renderer->Text( 5, yPos, Colour(255,0,0,255), 12, LANGUAGEPHRASE("dialog_high_latency") ); yPos += 13; } if( packetLoss > 2 ) { g_renderer->Text( 5, yPos, Colour(255,0,0,255), 12, LANGUAGEPHRASE("dialog_high_packet_loss") ); } g_renderer->SetFont( "kremlin" ); } } if( m_message ) { float timeOnScreen = GetHighResTime() - m_messageTimer; if( timeOnScreen < 5.0f ) { char msg[256]; sprintf( msg, m_message ); float fractionShown = timeOnScreen/1.5f; if( fractionShown < 1.0f ) msg[ int(strlen(msg) * fractionShown) ] = '\x0'; float alpha = 1.0f; if( timeOnScreen > 4.0f ) alpha = 5.0f - timeOnScreen; alpha = max(alpha, 0.0f); alpha *= 255; Colour col( 255, 255, 255, alpha ); float size = ( g_windowManager->WindowW() / 12.0f ); float xPos = g_windowManager->WindowW()/2.0f; float yPos = g_windowManager->WindowH()*0.8f; float textWidth = g_renderer->TextWidth( m_message, size ); if( textWidth > g_windowManager->WindowW() ) { // message is longer than the window size, rescale it size *= g_windowManager->WindowW() / textWidth * 0.95f; textWidth = g_renderer->TextWidth( m_message, size ); } g_renderer->TextSimple( xPos-textWidth/2.0f, yPos, col, size, msg ); } else { delete m_message; m_message = NULL; } } // // Render Defcon counter (if applicable) if( g_app->m_gameRunning && g_app->GetWorld()->GetDefcon() > 1 && !m_message ) { int currentDefcon = g_app->GetWorld()->GetDefcon(); int minutes = g_app->GetWorld()->m_defconTime[ currentDefcon-1 ] - (g_app->GetWorld()->m_theDate.GetMinutes() + 1); int seconds = 60 - g_app->GetWorld()->m_theDate.GetSeconds(); if( seconds == 60 ) { minutes += 1; seconds = 0; } char msg[256]; sprintf( msg, LANGUAGEPHRASE("dialog_defcon_x_in_x_time") ); LPREPLACEINTEGERFLAG( 'D', currentDefcon - 1, msg ); LPREPLACEINTEGERFLAG( 'M', minutes, msg ); char number[32]; sprintf( number, "%02d", seconds ); LPREPLACESTRINGFLAG( 'S', number, msg ); float xPos = g_windowManager->WindowW()/2.0f; float yPos = g_windowManager->WindowH()*0.8f; float size = ( g_windowManager->WindowW() / 30.0f ); g_renderer->TextCentre(xPos, yPos, Colour(255,0,0,255), size, msg ); // If Defcon 3 is nearly here and we still have units left, give us some prompting if( currentDefcon == 4 ) { Team *myTeam = g_app->GetWorld()->GetMyTeam(); if( myTeam ) { int totalUnits = 0; for( int i = 0; i < WorldObject::NumObjectTypes; ++i ) { totalUnits += myTeam->m_unitsAvailable[i]; } if( totalUnits > 0 ) { yPos += size; size *= 0.35f; g_renderer->TextCentre( xPos, yPos, Colour(255,0,0,255), size, LANGUAGEPHRASE("message_placeunits") ); } } } } // // Render victory timer (if applicable) float victoryTimer = g_app->GetGame()->m_victoryTimer.DoubleValue(); if( victoryTimer > 0.0f ) { int minutes = victoryTimer / 60; int seconds = victoryTimer - minutes * 60; float xPos = g_windowManager->WindowW()/2.0f; float yPos = g_windowManager->WindowH()*0.75f; float size = ( g_windowManager->WindowW() / 30.0f ); char caption[256]; sprintf( caption, LANGUAGEPHRASE("dialog_time_remaining") ); LPREPLACEINTEGERFLAG( 'M', minutes, caption ); char number[32]; sprintf( number, "%02d", seconds ); LPREPLACESTRINGFLAG( 'S', number, caption ); g_renderer->TextCentre( xPos, yPos, Colour(255,0,0,255), size, caption ); } else if( victoryTimer == 0.0f ) { float xPos = g_windowManager->WindowW()/2.0f; float yPos = g_windowManager->WindowH()*0.75f; float size = ( g_windowManager->WindowW() / 30.0f ); g_renderer->TextCentre( xPos, yPos, Colour(255,0,0,255), size, LANGUAGEPHRASE("dialog_gameover") ); } if( g_app->m_gameRunning ) { if( g_app->GetWorld()->GetTimeScaleFactor() == 0 && g_app->GetGame()->m_winner == -1 ) { float xPos = g_windowManager->WindowW()/2.0f; float yPos = g_windowManager->WindowH()*0.5f; float size = ( g_windowManager->WindowW() / 20.0f ); g_renderer->TextCentreSimple( xPos, yPos, White, size, LANGUAGEPHRASE("dialog_paused") ); } } if( g_app->m_gameRunning && g_app->GetMapRenderer()->GetAutoCam() ) { g_renderer->TextSimple( 10.0f, 10.0f, White, 20, LANGUAGEPHRASE("dialog_autocam") ); } } // // Test Bed stuff #ifdef TESTBED if( g_app->GetServer() ) { float xPos = g_windowManager->WindowW()/2.0f; float yPos = g_windowManager->WindowH()*0.4f; float size = ( g_windowManager->WindowW() / 12.0f ); char *modPath = g_preferences->GetString( "ModPath" ); g_renderer->TextCentreSimple( xPos, yPos, White, size, "SERVER" ); g_renderer->TextCentreSimple( xPos, yPos+size, White, size/3, modPath ); ProfiledElement *element = g_profiler->m_rootElement->m_children.GetData( "Server Main Loop" ); if( element && element->m_lastNumCalls > 0 ) { float percent = element->m_lastNumCalls * 10.0f; g_renderer->TextCentre( xPos, yPos + size*3, White, size, "%d%%", (int)percent ); } } #endif // // Version //if( !g_app->m_gameRunning ) //{ // char caption[256]; // sprintf( caption, "%s %s", APP_NAME, APP_VERSION ); // float width = g_renderer->TextWidth( caption, 12 ); // g_renderer->RectFill( 18, 3, 4+width, 15, Colour(0,0,0,150) ); // g_renderer->SetFont(); // g_renderer->TextSimple( 20, 5, White, 12, caption ); // g_renderer->SetFont( "kremlin" ); //} #ifdef NON_PLAYABLE g_renderer->Text( 10, 40,Colour(255,50,50,255), 20, LANGUAGEPHRASE("dialog_non_playable_demo") ); #endif if( g_preferences->GetInt( PREFS_NETWORKTRACKSYNCRAND )) { g_renderer->Text( 10, 60, Colour(255,50,50,255), 20, LANGUAGEPHRASE("dialog_tracking_synchronisation") ); } g_renderer->SetFont(); }
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 VotingSystem::RegisterNewVote( int _createTeamId, int _voteType, int _voteData ) { // // Game over? if( g_app->GetGame()->m_winner != -1 ) { return; } // // Does this vote already exist? for( int i = 0; i < m_votes.Size(); ++i ) { if( m_votes.ValidIndex(i) ) { Vote *vote = m_votes[i]; if( vote->m_result == Vote::VoteUnknown && vote->m_createTeamId == _createTeamId && vote->m_voteType == _voteType && vote->m_voteData == _voteData ) { // Already exists sucker return; } } } Vote *vote = new Vote(); vote->m_createTeamId = _createTeamId; vote->m_voteType = _voteType; vote->m_voteData = _voteData; if( _voteType == Vote::VoteTypeKickPlayer || _voteType == Vote::VoteTypeLeaveAlliance ) { vote->m_votes[_createTeamId] = Vote::VoteYes; } int voteId = m_votes.PutData( vote ); Team *myTeam = g_app->GetWorld()->GetMyTeam(); bool canSeeVote = false; if( myTeam ) { switch( vote->m_voteType ) { case Vote::VoteTypeJoinAlliance: if( myTeam->m_teamId == vote->m_createTeamId ) { canSeeVote = true; } else if( myTeam->m_allianceId == vote->m_voteData ) { canSeeVote = true; } break; case Vote::VoteTypeKickPlayer: { Team *kickTeam = g_app->GetWorld()->GetTeam(vote->m_voteData); if( myTeam->m_teamId == vote->m_createTeamId ) { canSeeVote = true; // We made this kick vote, update stats } else if( myTeam->m_allianceId == kickTeam->m_allianceId && myTeam->m_teamId != kickTeam->m_teamId ) { canSeeVote = true; } break; } } } if( canSeeVote ) { if( !EclGetWindow("Alliances") ) { EclRegisterWindow( new AlliancesWindow() ); } VotingWindow *vote = (VotingWindow *) EclGetWindow("Vote"); if( !vote || vote->m_voteId != voteId ) { VotingWindow *window = new VotingWindow(); window->m_voteId = voteId; EclRegisterWindow( window ); } } }
bool ProcessServerLetters( Directory *letter ) { if( strcmp( letter->m_name, NET_DEFCON_MESSAGE ) != 0 || !letter->HasData( NET_DEFCON_COMMAND ) ) { AppDebugOut( "Client received bogus message, discarded (4)\n" ); return true; } char *cmd = letter->GetDataString( NET_DEFCON_COMMAND ); if( strcmp( cmd, NET_DEFCON_CLIENTHELLO ) == 0 ) { int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID); if( clientId == g_app->GetClientToServer()->m_clientId ) { g_app->GetClientToServer()->m_connectionState = ClientToServer::StateConnected; AppDebugOut( "CLIENT : Received HelloClient from Server\n" ); if( !g_app->GetTutorial() ) { g_app->GetClientToServer()->RequestTeam( Team::TypeLocalPlayer ); } } // If this is a Demo client, make a note of that if( letter->HasData( NET_DEFCON_CLIENTISDEMO ) ) { g_app->GetClientToServer()->SetClientDemo( clientId ); } // This might be a client rejoining the game // Need to give him his teams back g_app->GetWorld()->ReassignTeams( clientId ); return true; } else if( strcmp( cmd, NET_DEFCON_CLIENTGOODBYE ) == 0 ) { int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID); int reason = letter->GetDataInt(NET_DEFCON_DISCONNECT); AppDebugOut( "CLIENT : Client %d left the game\n", clientId ); g_app->GetWorld()->RemoveTeams( clientId, reason ); g_app->GetWorld()->RemoveSpectator( clientId ); g_app->GetClientToServer()->SetSyncState( clientId, true ); return true; } else if( strcmp( cmd, NET_DEFCON_CLIENTID ) == 0 ) { int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID); AppDebugOut( "CLIENT : Received ClientID of %d\n", clientId ); if( g_app->GetClientToServer()->m_clientId != -1 ) { AppAssert( g_app->GetClientToServer()->m_clientId == clientId ); return true; } g_app->GetClientToServer()->m_clientId = clientId; g_app->GetClientToServer()->m_connectionState = ClientToServer::StateHandshaking; g_lastProcessedSequenceId = -1; if( letter->HasData( NET_DEFCON_VERSION, DIRECTORY_TYPE_STRING ) ) { char *serverVersion = letter->GetDataString( NET_DEFCON_VERSION ); strcpy( g_app->GetClientToServer()->m_serverVersion, serverVersion ); AppDebugOut( "CLIENT : Server version is %s\n", serverVersion ); } if( !VersionManager::DoesSupportModSystem( g_app->GetClientToServer()->m_serverVersion ) ) { // This server is too old to support Mods, so make sure we de-activate any critical ones g_modSystem->DeActivateAllCriticalMods(); if( g_modSystem->CommitRequired() ) { g_modSystem->Commit(); g_app->RestartAmbienceMusic(); } } return true; } else if( strcmp( cmd, NET_DEFCON_TEAMASSIGN ) == 0 ) { int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID); int teamId = letter->GetDataInt(NET_DEFCON_TEAMID); int teamType = letter->GetDataInt(NET_DEFCON_TEAMTYPE); if( teamType != Team::TypeAI && clientId != g_app->GetClientToServer()->m_clientId ) { teamType = Team::TypeRemotePlayer; } g_app->GetWorld()->InitialiseTeam(teamId, teamType, clientId ); return true; } else if( strcmp( cmd, NET_DEFCON_SPECTATORASSIGN ) == 0 ) { int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID); g_app->GetWorld()->InitialiseSpectator(clientId); if( clientId == g_app->GetClientToServer()->m_clientId ) { AppDebugOut( "CLIENT: I am a spectator\n" ); } return true; } else if( strcmp( cmd, NET_DEFCON_NETSYNCERROR ) == 0 ) { int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID); AppDebugOut( "SYNCERROR Server informed us that Client %d is out of Sync\n", clientId ); g_app->GetClientToServer()->SetSyncState( clientId, false ); char *syncId = letter->GetDataString( NET_DEFCON_SYNCERRORID ); DumpSyncLogs(syncId); return true; } else if( strcmp( cmd, NET_DEFCON_NETSYNCFIXED ) == 0 ) { int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID); AppDebugOut( "SYNCFIXED Server informed us that Client %d has repaired his Sync Error\n", clientId ); g_app->GetClientToServer()->SetSyncState( clientId, true ); return true; } else if( strcmp( cmd, NET_DEFCON_DISCONNECT ) == 0 ) { if( g_app->GetClientToServer()->m_connectionState > ClientToServer::StateDisconnected ) { g_app->ShutdownCurrentGame(); if ( EclGetWindow("LOBBY") ) EclRemoveWindow( "LOBBY" ); if ( EclGetWindow("Comms Window") ) EclRemoveWindow( "Comms Window" ); if ( EclGetWindow("Preparing Game...") ) EclRemoveWindow("Preparing Game..." ); g_app->GetInterface()->OpenSetupWindows(); char *reason; char *reasonLanguagePhrase; int reasonDisconnectInt = letter->GetDataInt(NET_DEFCON_DISCONNECT); switch( reasonDisconnectInt ) { case Disconnect_ClientLeave: reason = "You have left the game"; reasonLanguagePhrase = "dialog_disconnect_client_leave"; break; case Disconnect_ServerShutdown: reason = "The server has shutdown"; reasonLanguagePhrase = "dialog_disconnect_server_shutdown"; break; case Disconnect_InvalidKey: reason = "You are using an invalid key"; reasonLanguagePhrase = "dialog_disconnect_invalid_key"; break; case Disconnect_DuplicateKey: reason = "You are using a duplicate key"; reasonLanguagePhrase = "dialog_disconnect_duplicate_key"; break; case Disconnect_KeyAuthFailed: reason = "Key authentication failed"; reasonLanguagePhrase = "dialog_disconnect_key_auth_failed"; break; case Disconnect_BadPassword: reason = "Invalid Password Entered"; reasonLanguagePhrase = "dialog_disconnect_bad_password"; break; case Disconnect_GameFull: reason = "Game is already full"; reasonLanguagePhrase = "dialog_disconnect_game_full"; break; case Disconnect_KickedFromGame: reason = "Kicked by the Server"; reasonLanguagePhrase = "dialog_disconnect_kicked_from_game"; break; case Disconnect_DemoFull: reason = "Too many Demo Players already"; reasonLanguagePhrase = "dialog_disconnect_demo_full"; break; default: reason = "Unknown"; reasonLanguagePhrase = "dialog_disconnect_unknown"; break; } if( reasonDisconnectInt == Disconnect_KeyAuthFailed || reasonDisconnectInt == Disconnect_InvalidKey || reasonDisconnectInt == Disconnect_DuplicateKey ) { char authKey[256]; if( Authentication_IsKeyFound() ) { Authentication_GetKey( authKey ); } else { sprintf( authKey, LANGUAGEPHRASE("dialog_authkey_not_found") ); } BadKeyWindow *badKey = new BadKeyWindow(); sprintf( badKey->m_extraMessage, LANGUAGEPHRASE("dialog_auth_error") ); LPREPLACESTRINGFLAG( 'E', LANGUAGEPHRASE(reasonLanguagePhrase), badKey->m_extraMessage ); LPREPLACESTRINGFLAG( 'K', authKey, badKey->m_extraMessage ); EclRegisterWindow(badKey); } else if( reasonDisconnectInt == Disconnect_DemoFull ) { int maxGameSize; int maxDemoPlayers; bool allowDemoServers; g_app->GetClientToServer()->GetDemoLimitations( maxGameSize, maxDemoPlayers, allowDemoServers ); BadKeyWindow *badKey = new BadKeyWindow(); sprintf( badKey->m_extraMessage, LANGUAGEPHRASE("dialog_server_demo_restricted") ); LPREPLACEINTEGERFLAG( 'N', maxDemoPlayers, badKey->m_extraMessage ); badKey->m_offerDemo = false; EclRegisterWindow(badKey); } else { MessageDialog *dialog = new MessageDialog( "Disconnected", reasonLanguagePhrase, true, "dialog_disconnected", true ); EclRegisterWindow( dialog ); } AppDebugOut( "CLIENT : Received Disconnect from server : %s\n", reason ); #ifdef TESTBED if( letter->GetDataInt(NET_DEFCON_DISCONNECT) == Disconnect_ServerShutdown ) { RestartTestBed(1, "Client Disconnect"); } #endif } return true; } else if( strcmp( cmd, NET_DEFCON_SETMODPATH ) == 0 ) { char *modPath = letter->GetDataString( NET_DEFCON_SETMODPATH ); AppDebugOut( "Server has set the MOD path: '%s'\n", modPath ); if( !g_modSystem->IsCriticalModPathSet( modPath ) ) { if( g_modSystem->CanSetModPath( modPath ) ) { g_modSystem->DeActivateAllCriticalMods(); g_modSystem->SetModPath( modPath ); } else { char reason[8192]; sprintf( reason, LANGUAGEPHRASE("dialog_error_mod_path_caption") ); char modPathCopy[4096]; strcpy( modPathCopy, modPath ); LList<char *> *tokens = g_modSystem->ParseModPath( modPathCopy ); for( int i = 0; i < tokens->Size(); i+=2 ) { char *modName = tokens->GetData(i); char *version = tokens->GetData(i+1); strcat( reason, modName ); strcat( reason, " " ); strcat( reason, version ); if( !g_modSystem->IsModInstalled( modName, version ) ) { strcat( reason, " " ); strcat( reason, LANGUAGEPHRASE("dialog_mod_not_installed") ); } strcat( reason, "\n" ); } delete tokens; MessageDialog *dialog = new MessageDialog( "Error setting MOD path", reason, false, "dialog_error_mod_path_title", true ); EclRegisterWindow( dialog ); } } return true; } else { return false; } }
void ConnectingWindow::Render( bool _hasFocus ) { InterfaceWindow::Render( _hasFocus ); float yPos = m_y + 40; // // Render our connection state g_renderer->SetFont( "kremlin" ); float fraction = 0.0f; char *caption = NULL; Colour col; switch( g_app->GetClientToServer()->m_connectionState ) { case ClientToServer::StateDisconnected: col.Set(255,0,0,255); caption = LANGUAGEPHRASE("dialog_state_disconnected"); fraction = 0.0f; break; case ClientToServer::StateConnecting: col.Set(255,255,0,255); caption = LANGUAGEPHRASE("dialog_state_connecting"); fraction = 0.5f; break; case ClientToServer::StateHandshaking: case ClientToServer::StateConnected: col.Set(0,255,0,255); caption = LANGUAGEPHRASE("dialog_state_connected"); fraction = 1.0f; break; } g_renderer->TextCentreSimple( m_x+m_w/2, yPos, col, 20, caption ); yPos += 20; if( fraction > 0.0f ) { g_renderer->RectFill( m_x + 30, yPos, (m_w-60)*fraction, 20, col ); g_renderer->Rect( m_x+30, yPos, (m_w-60), 20, White ); int numConnectionAttempts = g_app->GetClientToServer()->m_connectionAttempts; if( fraction < 1.0f && numConnectionAttempts > 0 ) { char caption[512]; sprintf( caption, LANGUAGEPHRASE("dialog_state_attempts") ); LPREPLACEINTEGERFLAG( 'A', numConnectionAttempts, caption ); g_renderer->TextCentreSimple( m_x + m_w/2, m_y + m_h - 60, White, 14, caption ); } } // // Render our sync status (ie receiving all data from the server) yPos += 40; if( g_app->GetClientToServer()->IsConnected() ) { if( m_stage == 0 ) { m_stage = 1; m_stageStartTime = GetHighResTime(); } int serverSeqId = g_app->GetClientToServer()->m_serverSequenceId; int latestSeqId = g_app->GetClientToServer()->m_lastValidSequenceIdFromServer; int numRemaining = serverSeqId-latestSeqId; numRemaining--; if( numRemaining > m_maxUpdatesRemaining ) { m_maxUpdatesRemaining = numRemaining; } if( m_maxUpdatesRemaining > 0 ) { fraction = numRemaining / (float) m_maxUpdatesRemaining; } else { fraction = 0.0f; } Clamp( fraction, 0.0f, 1.0f ); fraction = 1.0f - fraction; col.Set( (1-fraction)*255, fraction*255, 0, 255 ); const char *caption = numRemaining > 5 ? LANGUAGEPHRASE("dialog_state_receiving") : LANGUAGEPHRASE("dialog_state_received"); g_renderer->TextCentreSimple( m_x+m_w/2, yPos, col, 20, caption ); yPos += 20; g_renderer->RectFill( m_x+30, yPos, (m_w-60)*fraction, 20, col ); g_renderer->Rect( m_x+30, yPos, (m_w-60), 20, White ); if( m_stage == 1 ) { RenderTimeRemaining(fraction); } // // Render how much of the received data we have successfully parsed int lagRemaining = 0; if( g_lastProcessedSequenceId > 0 && numRemaining < 10 ) { if( m_stage != 2 ) { m_stage = 2; m_stageStartTime = GetHighResTime(); } yPos += 40; int serverSeqId = g_app->GetClientToServer()->m_serverSequenceId; lagRemaining = serverSeqId - g_lastProcessedSequenceId; lagRemaining --; if( lagRemaining > m_maxLagRemaining ) { m_maxLagRemaining = lagRemaining; } fraction = lagRemaining / (float) m_maxLagRemaining; Clamp( fraction, 0.0f, 1.0f ); fraction = 1.0f - fraction; col.Set( (1-fraction)*255, fraction*255, 0, 255 ); const char *caption = lagRemaining > 5 ? LANGUAGEPHRASE("dialog_state_synchronising") : LANGUAGEPHRASE("dialog_state_synchronised"); g_renderer->TextCentreSimple( m_x+m_w/2, yPos, col, 20, caption ); yPos += 20; g_renderer->RectFill( m_x+30, yPos, (m_w-60)*fraction, 20, col ); g_renderer->Rect( m_x+30, yPos, (m_w-60), 20, White ); if( m_stage == 2 ) { RenderTimeRemaining( fraction ); } } // // Connection is done, we can shut down now // Pop up lobby if we were asked to do so if( g_app->GetClientToServer()->m_connectionState == ClientToServer::StateConnected ) { if( m_popupLobbyAtEnd ) { if( !EclGetWindow( "LOBBY" ) ) { LobbyWindow *lobby = new LobbyWindow(); ChatWindow *chat = new ChatWindow(); chat->SetPosition( g_windowManager->WindowW()/2 - chat->m_w/2, g_windowManager->WindowH() - chat->m_h - 30 ); EclRegisterWindow( chat ); float lobbyX = g_windowManager->WindowW()/2 - lobby->m_w/2; float lobbyY = chat->m_y - lobby->m_h - 30; lobbyY = std::max( lobbyY, 0.0f ); lobby->SetPosition(lobbyX, lobbyY); EclRegisterWindow( lobby ); } } if( numRemaining < 5 && lagRemaining < 5 ) { EclRemoveWindow(m_name); } } } else { if( g_app->GetClientToServer()->m_connectionState == ClientToServer::StateDisconnected ) { EclRemoveWindow(m_name); } } g_renderer->SetFont(); }
void App::InitialiseWindow() { int screenW = g_preferences->GetInt( PREFS_SCREEN_WIDTH ); int screenH = g_preferences->GetInt( PREFS_SCREEN_HEIGHT ); int colourDepth = g_preferences->GetInt( PREFS_SCREEN_COLOUR_DEPTH ); int screenRefresh = g_preferences->GetInt( PREFS_SCREEN_REFRESH ); int zDepth = g_preferences->GetInt( PREFS_SCREEN_Z_DEPTH ); int antiAlias = g_preferences->GetInt( PREFS_SCREEN_ANTIALIAS, 0 ); bool windowed = g_preferences->GetInt( PREFS_SCREEN_WINDOWED ); if( screenW == 0 || screenH == 0 ) { g_windowManager->SuggestDefaultRes( &screenW, &screenH, &screenRefresh, &colourDepth ); g_preferences->SetInt( PREFS_SCREEN_WIDTH, screenW ); g_preferences->SetInt( PREFS_SCREEN_HEIGHT, screenH ); g_preferences->SetInt( PREFS_SCREEN_REFRESH, screenRefresh ); g_preferences->SetInt( PREFS_SCREEN_COLOUR_DEPTH, colourDepth ); } if(m_gameRunning && m_game->GetOptionValue("GameMode") == GAMEMODE_OFFICEMODE ) { windowed = true; } bool success = g_windowManager->CreateWin( screenW, screenH, windowed, colourDepth, screenRefresh, zDepth, antiAlias, "DEFCON" ); if( !success ) { // Safety values int safeScreenW = 800; int safeScreenH = 600; bool safeWindowed = 1; int safeColourDepth = 16; int safeZDepth = 16; int safeScreenRefresh = 60; char caption[512]; sprintf( caption, LANGUAGEPHRASE("dialog_screen_error_caption") ); LPREPLACEINTEGERFLAG( 'W', screenW, caption ); LPREPLACEINTEGERFLAG( 'H', screenH, caption ); ReplaceStringFlagColorBit( caption, 'C', colourDepth ); ReplaceStringFlagWindowed( caption, 'S', windowed ); LPREPLACEINTEGERFLAG( 'w', safeScreenW, caption ); LPREPLACEINTEGERFLAG( 'h', safeScreenH, caption ); ReplaceStringFlagColorBit( caption, 'c', safeColourDepth ); ReplaceStringFlagWindowed( caption, 's', safeWindowed ); MessageDialog *dialog = new MessageDialog( "Screen Error", caption, false, "dialog_screen_error_title", true ); EclRegisterWindow( dialog ); dialog->m_x = 100; dialog->m_y = 100; // Go for safety values screenW = safeScreenW; screenH = safeScreenH; windowed = safeWindowed; colourDepth = safeColourDepth; zDepth = safeZDepth; screenRefresh = safeScreenRefresh; antiAlias = 0; success = g_windowManager->CreateWin(screenW, screenH, windowed, colourDepth, screenRefresh, zDepth, antiAlias, "DEFCON"); AppReleaseAssert( success, "Failed to set screen mode" ); g_preferences->SetInt( PREFS_SCREEN_WIDTH, screenW ); g_preferences->SetInt( PREFS_SCREEN_HEIGHT, screenH ); g_preferences->SetInt( PREFS_SCREEN_WINDOWED, windowed ); g_preferences->SetInt( PREFS_SCREEN_COLOUR_DEPTH, colourDepth ); g_preferences->SetInt( PREFS_SCREEN_Z_DEPTH, zDepth ); g_preferences->SetInt( PREFS_SCREEN_REFRESH, screenRefresh ); g_preferences->Save(); } #ifdef TARGET_MSVC WindowManagerWin32 *wm32 = (WindowManagerWin32*) g_windowManager; DWORD dwStyle = GetWindowLong( wm32->m_hWnd, GWL_STYLE ); dwStyle &= ~(WS_MAXIMIZEBOX); SetWindowLong( wm32->m_hWnd, GWL_STYLE, dwStyle ); HICON hIcon = LoadIcon( wm32->GethInstance(), MAKEINTRESOURCE(IDI_ICON1) ); //SendMessage( wm32->m_hWnd, (UINT)WM_SETICON, ICON_SMALL, (LPARAM)hIcon ); SendMessage( wm32->m_hWnd, (UINT)WM_SETICON, ICON_BIG, (LPARAM)hIcon ); #endif // TARGET_MSVC g_windowManager->HideMousePointer(); SetMousePointerVisible(true); }