// // I_InitNetwork // // Returns true if packet server mode might be a good idea. // bool I_InitNetwork (void) { int i; const char *v; memset (&doomcom, 0, sizeof(doomcom)); // set up for network v = Args->CheckValue ("-dup"); if (v) { doomcom.ticdup = clamp (atoi (v), 1, MAXTICDUP); } else { doomcom.ticdup = 1; } if (Args->CheckParm ("-extratic")) doomcom.extratics = 1; else doomcom.extratics = 0; v = Args->CheckValue ("-port"); if (v) { DOOMPORT = atoi (v); Printf ("using alternate port %i\n", DOOMPORT); } // parse network game options, // player 1: -host <numplayers> // player x: -join <player 1's address> if ( (i = Args->CheckParm ("-host")) ) { HostGame (i); } else if ( (i = Args->CheckParm ("-join")) ) { JoinGame (i); } else { // single player game netgame = false; multiplayer = false; doomcom.id = DOOMCOM_ID; doomcom.numplayers = doomcom.numnodes = 1; doomcom.consoleplayer = 0; return false; } if (doomcom.numnodes < 3) { // Packet server mode with only two players is effectively the same as // peer-to-peer but with some slightly larger packets. return false; } return doomcom.numnodes > 3 || !NodesOnSameNetwork(); }
void SSGameLobby::Startup() { // Seed the randomizer const unsigned int randomSeed = static_cast<const unsigned int>( SDL_GetPerformanceCounter() ); g_Randomizer.Seed( randomSeed ); // Register subscriber g_SSMail.RegisterSubscriber( this ); m_UserInterests = MessageTypes::COLOUR_CHANGE | MessageTypes::TEAM_CHANGE | MessageTypes::SPAWN_POINT_CHANGE | MessageTypes::CHANGE_SPAWN_COUNT | MessageTypes::RESERVE_AI_PLAYER; // Set all player slots to not ready for ( int i = 0; i < MAX_PLAYERS; ++i ) m_PlayersReady[i] = false; // Register callback to network engine m_NetworkCallbackHandle = g_NetworkEngine.RegisterCallback( NetworkCallbackEvent::Disconnection, std::bind( &SSGameLobby::OnDisconnection, this, std::placeholders::_1 ) ); // Player colours m_ColourEntries.push_back( ColourEntry { "Green", Colours::KINDA_GREEN, Colours::KINDA_GREEN , -1 } ); m_ColourEntries.push_back( ColourEntry { "Red", Colours::KINDA_RED , Colours::KINDA_RED , -1 } ); m_ColourEntries.push_back( ColourEntry { "Blue", Colours::KINDA_BLUE , Colours::KINDA_BLUE , -1 } ); m_ColourEntries.push_back( ColourEntry { "Pink", Colours::KINDA_PINK , Colours::KINDA_PINK , -1 } ); m_ColourEntries.push_back( ColourEntry { "Yellow", Colours::VERY_YELLOW, Colours::VERY_YELLOW , -1 } ); m_ColourEntries.push_back( ColourEntry { "Cyan", Colours::LTBLUE , Colours::LTBLUE , -1 } ); // Text colour modified m_ColourEntries.push_back( ColourEntry { "Black", Colours::BLACK , glm::vec4(0.4f, 0.4f, 0.4f, 1.0f), -1 } ); g_GameData.SetPlayerColour( 0, Colours::KINDA_GREEN ); g_GameData.SetPlayerColour( 1, Colours::KINDA_RED ); g_GameData.SetPlayerColour( 2, Colours::KINDA_BLUE ); g_GameData.SetPlayerColour( 3, Colours::KINDA_PINK ); // Set up GUI g_GUI.UseFont( FONT_ID_LEKTON_16 ); m_ConnectionState = ConnectionState::EnteringIP; m_ConnectionAttemptFailed = false; g_NetworkEngine.RegisterCallback( NetworkCallbackEvent::ConnectionAttemptSuccess, std::bind( &SSGameLobby::OnConnectionSuccess, this, std::placeholders::_1 ) ); // TODODB: Check against this variable already being set eller nånting. g_NetworkEngine.RegisterCallback( NetworkCallbackEvent::ConnectionAttemptFail, std::bind( &SSGameLobby::OnConnectionFail, this, std::placeholders::_1 ) ); // TODODB: Check against this variable already being set eller nånting. // Button scripts g_Script.Register( m_ScriptNameReady.c_str(), [&] ( IScriptEngine* ) -> int { OnReadyButtonClicked(); return 0; } ); g_Script.Register( m_ScriptNameStartGame.c_str(), [&] ( IScriptEngine* ) -> int { StartGame(); return 0; } ); g_Script.Register(m_ScriptChangeGameSetting.c_str(), [this](IScriptEngine* script) -> int { m_NumberOfSpawns += script->PopInt(); if (m_NumberOfSpawns < 1) m_NumberOfSpawns = 1; if (m_NumberOfSpawns > SQUAD_MAXIMUM_UNIT_COUNT) m_NumberOfSpawns = SQUAD_MAXIMUM_UNIT_COUNT; ChangeSpawnCount( m_NumberOfSpawns ); return 0; } ); GUI::Window* parentWindow = g_GUI.GetWindow( m_WindowNameParent ); glm::ivec2 middleParent = glm::ivec2(parentWindow->GetBoundingBoxRef().X, parentWindow->GetBoundingBoxRef().Y) + parentWindow->GetSize() / 2; glm::ivec2 sizeParent = parentWindow->GetSize( ); { // Enter ip m_WindowEnterIP = g_GUI.AddWindow( m_WindowNameEnterIP, GUI::Rectangle( middleParent.x - m_WidthEnterIP / 2, middleParent.y - m_HeightEnterIP / 2, m_WidthEnterIP, m_HeightEnterIP ), m_WindowNameParent, true ); m_TextBoxEnterIP = g_GUI.AddTextBox( "", GUI::Rectangle( m_WidthButton, m_HeightEnterIP - m_HeightTextBox, m_WidthTextBox, m_HeightTextBox) , m_WindowNameEnterIP); // Connect m_ButtonConnect = g_GUI.AddButton( "", GUI::Rectangle( m_WidthEnterIP - m_WidthButton * 2, m_HeightEnterIP - m_HeightButton, m_WidthButton, m_HeightButton), m_WindowNameEnterIP ); m_ButtonConnect->SetText( "Connect" ); g_Script.Register( m_ScriptNameConnect.c_str(), [this](IScriptEngine*){ ConnectToGame(m_TextBoxEnterIP->GetText()); return 0; } ); m_ButtonConnect->SetClickScript( m_ScriptNameConnect + "()" ); m_ButtonConnect->GetBackgroundRef().Texture = m_TextureNameButtons; // Host m_ButtonHost = g_GUI.AddButton( "", GUI::Rectangle( m_WidthEnterIP - m_WidthButton, m_HeightEnterIP - m_HeightButton, m_WidthButton, m_HeightButton), m_WindowNameEnterIP ); m_ButtonHost->SetText( "Host" ); g_Script.Register( m_ScriptNameHost.c_str(), [this](IScriptEngine*){ HostGame(); return 0; } ); m_ButtonHost->SetClickScript( m_ScriptNameHost + "()" ); m_ButtonHost->GetBackgroundRef().Texture = m_TextureNameButtons; // Text GUI::Text* infoText = g_GUI.AddText( "", GUI::TextDefinition( "Please enter an IP adress to connect to", 0, m_TopPadding, m_WidthEnterIP, m_HeightInfoText ), m_WindowNameEnterIP ); infoText->GetTextDefinitionRef().Alignment = GUI::ALIGNMENT_TOP_CENTER; m_TextError = g_GUI.AddText( "", GUI::TextDefinition( "", 0, m_TopPadding + m_HeightInfoText, m_WidthEnterIP, m_HeightErrorText ), m_WindowNameEnterIP ); // Back button m_ButtonBackEnterIP = g_GUI.AddButton( "", GUI::Rectangle( 0, m_WindowEnterIP->GetSize( ).y - m_HeightButton, m_WidthButton, m_HeightButton ), m_WindowNameEnterIP ); g_Script.Register( m_ScriptNameBackEnterIP.c_str(), [this](IScriptEngine*){ BackFromEnterIP( ); return 0; } ); m_ButtonBackEnterIP->SetClickScript( m_ScriptNameBackEnterIP + "()" ); m_ButtonBackEnterIP->SetText( "Back" ); m_ButtonBackEnterIP->GetBackgroundRef().Texture = m_TextureNameButtons; // Enter ip is default window m_WindowEnterIP->ToggleOpen(); // Default IP CallbackConfig* networkConfig = g_ConfigManager.GetConfig( "network.cfg" ); int defaultPort = networkConfig->GetInt( "DefaultListeningPort", 40606, "Default port for establishing connections" ); rString savedIP = networkConfig->GetString( "SavedIP", "", "The IP of the last successfull connection attempt" ); m_TextBoxEnterIP->SetText( savedIP ); } { // Lobby m_WindowLobby = g_GUI.AddWindow( m_WindowNameLobby, parentWindow->GetBoundingBoxRef(), m_WindowNameParent ); glm::ivec2 sizeLobby = m_WindowLobby->GetSize( ); // Start game (host) m_ButtonStartGame = g_GUI.AddButton( "", GUI::Rectangle( sizeLobby.x - m_WidthButton * 2, sizeLobby.y - m_HeightButton, m_WidthButton, m_HeightButton ), m_WindowNameLobby ); m_ButtonStartGame->SetText( "Start" ); m_ButtonStartGame->SetClickScript( m_ScriptNameStartGame + "()" ); m_ButtonStartGame->SetVisible( false ); m_ButtonStartGame->SetEnabled( false ); m_ButtonStartGame->GetBackgroundRef().Texture = m_TextureNameButtons; // Back button m_ButtonBackLobby = g_GUI.AddButton( "", GUI::Rectangle( 0, sizeLobby.y - m_HeightButton, m_WidthButton, m_HeightButton ), m_WindowNameLobby ); g_Script.Register( m_ScriptNameBackLobby.c_str(), [this](IScriptEngine*) { BackFromLobby(); return 0; } ); m_ButtonBackLobby->SetClickScript( m_ScriptNameBackLobby + "()" ); m_ButtonBackLobby->SetText( "Back" ); m_ButtonBackLobby->GetBackgroundRef().Texture = m_TextureNameButtons; // Ready (client) m_ButtonReady = g_GUI.AddButton( "", GUI::Rectangle( sizeLobby.x - m_WidthButton, sizeLobby.y - m_HeightButton, m_WidthButton, m_HeightButton ), m_WindowNameLobby ); m_ButtonReady->GetBackgroundRef().Texture = m_TextureNameButtons; m_ButtonReady->SetText( "Ready" ); m_ButtonReady->SetClickScript( m_ScriptNameReady + "()" ); { // Connected clients m_WindowConnectedClients = g_GUI.AddWindow( m_WindowNameConnectedClients, GUI::Rectangle( 0, 0, sizeParent.x / 2, sizeParent.y / 2 ), m_WindowNameLobby, true ); m_WindowConnectedClients->ToggleOpen( ); g_GUI.UseFont( FONT_ID_LEKTON_20 ); g_Script.Register( m_ScriptNameColourChange.c_str(), [this](IScriptEngine* script) -> int { int playerID = script->PopInt( ); assert( playerID >= 0 && playerID < MAX_PLAYERS ); int selectedIndex = m_ConnectedPlayerEntries[playerID].Colour->GetSelectedIndex( ); TryChangeColour( selectedIndex, playerID, false ); return 0; } ); g_Script.Register( m_ScriptNameTeamChange.c_str(), [this](IScriptEngine* script) -> int { int playerID = script->PopInt( ); assert( playerID >= 0 && playerID < MAX_PLAYERS ); int selectedIndex = m_ConnectedPlayerEntries[playerID].Team->GetSelectedIndex( ); TryChangeTeam( selectedIndex, playerID, false ); return 0; } ); g_Script.Register( m_ScriptNameKick.c_str( ), [this](IScriptEngine* script) -> int { int playerID = script->PopInt( ); if ( m_ConnectedPlayerEntries[ playerID ].IsAI ) { ChangeReserveAI( playerID, false ); OnDisconnection( &playerID ); } else g_NetworkEngine.RequestDisconnection( playerID ); return 0; } ); g_Script.Register( m_ScriptNameReserveForAI.c_str( ), [this](IScriptEngine* script) -> int { int playerID = script->PopInt( ); if ( !m_ConnectedPlayerEntries[playerID].IsAI ) { OnNewClientConnect( playerID ); } ChangeReserveAI( playerID, true ); g_NetworkEngine.RequestDisconnection( playerID ); return 0; } ); // Players int entryY = m_HeightPlayerEntry * (MAX_PLAYERS - 1) + m_TopPadding; for ( int i = MAX_PLAYERS -1 ; i >= 0; --i ) { int x = m_WindowConnectedClients->GetSize().x - m_WidthReady; ConnectedPlayer& playerEntry = m_ConnectedPlayerEntries[i]; playerEntry.Name = g_GUI.AddText( "", GUI::TextDefinition( "TODOJM", m_LeftPadding, entryY, m_WidthName, m_HeightPlayerEntry ), m_WindowNameConnectedClients ); playerEntry.Ready = g_GUI.AddSprite( "", GUI::SpriteDefinition( m_TextureNameReadySprite, m_WindowConnectedClients->GetSize().x - m_WidthReady, entryY, m_WidthReady, m_HeightPlayerEntry ), m_WindowNameConnectedClients ); x -= m_WidthTeam; playerEntry.Team = g_GUI.AddComboBox( "", GUI::Rectangle( x, entryY, m_WidthTeam, m_HeightPlayerEntry ), m_WindowNameConnectedClients ); playerEntry.Team->AddItem( "Team 1" ); playerEntry.Team->AddItem( "Team 2" ); playerEntry.Team->AddItem( "Team 3" ); playerEntry.Team->AddItem( "Team 4" ); playerEntry.Team->SetClickScript( m_ScriptNameTeamChange + "(" + rToString( i ) + ")"); playerEntry.Team->GetBackgroundRef().Texture = m_TextureNameComboBox; playerEntry.Team->SetItemBackgroundImage( m_TextureNameComboBoxItem ); x -= m_WidthColour; playerEntry.Colour = g_GUI.AddComboBox( "", GUI::Rectangle( x, entryY, m_WidthColour, m_HeightPlayerEntry ), m_WindowNameConnectedClients ); for( auto& colourEntry : m_ColourEntries ) { playerEntry.Colour->AddItem( colourEntry.Text ); playerEntry.Colour->GetItem( playerEntry.Colour->GetNumItems() - 1 ).Text.Colour = colourEntry.TextColour; } playerEntry.Colour->SetClickScript( m_ScriptNameColourChange + "(" + rToString( i ) + ")" ); playerEntry.Colour->GetBackgroundRef().Texture = m_TextureNameComboBox; playerEntry.Colour->SetItemBackgroundImage( m_TextureNameComboBoxItem ); x -= m_WidthKick; playerEntry.Kick = g_GUI.AddButton( "", GUI::Rectangle( x, entryY, m_WidthKick, m_HeightPlayerEntry ), m_WindowNameConnectedClients ); playerEntry.Kick->SetClickScript( m_ScriptNameKick + "(" + rToString( i ) + ")" ); playerEntry.Kick->GetBackgroundRef().Texture = m_TextureNameKickSprite; x -= m_WidthReserveForAI; playerEntry.ReserveForAIBtn = g_GUI.AddButton( "", GUI::Rectangle( x, entryY, m_WidthReserveForAI, m_HeightPlayerEntry ), m_WindowNameConnectedClients ); playerEntry.ReserveForAIBtn->SetClickScript( m_ScriptNameReserveForAI + "(" + rToString( i ) + ")" ); playerEntry.ReserveForAIBtn->GetBackgroundRef().Texture = m_TextureNameButtons; playerEntry.ReserveForAIBtn->GetTextDefinitionRef().Text = "AI"; playerEntry.PlayerID = i; entryY -= m_HeightPlayerEntry; } } { // Select level window m_WindowSelectLevel = g_GUI.AddWindow( m_WindowNameSelectLevel, GUI::Rectangle( sizeLobby.x / 2, 0, sizeLobby.x / 2, sizeLobby.y / 2 ), m_WindowNameLobby, true ); glm::ivec2 slSize = m_WindowSelectLevel->GetSize(); m_WindowSelectLevel->ToggleOpen( ); m_ComboBoxSelectLevel = g_GUI.AddComboBox( "", GUI::Rectangle( 0, m_WindowSelectLevel->GetSize().y - m_HeightComboBoxSelectLevel, m_WindowSelectLevel->GetSize().x, m_HeightComboBoxSelectLevel ), m_WindowNameSelectLevel ); m_ComboBoxSelectLevel->SetBackgroundImage( m_TextureNameSelectLevel ); m_ComboBoxSelectLevel->SetItemBackgroundImage( m_TextureNameSelectLevel ); g_Script.Register( m_ScriptClickLevelChange.c_str(), [this](IScriptEngine*){ SetLevel(m_ComboBoxSelectLevel->GetTextDefinitionRef().Text); return 0; } ); m_ComboBoxSelectLevel->SetClickScript( m_ScriptClickLevelChange + "()" ); m_SizeLevelWindow = std::min(slSize.x, slSize.y - m_HeightComboBoxSelectLevel); m_WindowLevel = g_GUI.AddWindow( m_WindowNameLevel, GUI::Rectangle( (slSize.x / 2) - (m_SizeLevelWindow / 2), 0, m_SizeLevelWindow, m_SizeLevelWindow ), m_WindowNameSelectLevel ); m_WindowLevel->ToggleOpen( ); m_SpriteLevelSelected = g_GUI.AddSprite( "", GUI::SpriteDefinition( "", 0, 0, m_SizeLevelWindow, m_SizeLevelWindow), m_WindowNameLevel ); CreateSpawnPointButtons( ); LoadLevels( ); } { // Gameplay settings int gpsX = sizeLobby.x / 2; int gpsY = sizeLobby.y / 2; int gpsW = sizeLobby.x / 2; int gpsH = sizeLobby.y / 2; int gpsDiff = m_HeightComboBoxSelectLevel; int gpsStartCountW = gpsW - gpsDiff * 4 - gpsDiff * 3; m_WindowGamePlaySettings = g_GUI.AddWindow(m_WindowNameGamePlaySettings, GUI::Rectangle(gpsX, gpsY, gpsW, gpsH -m_HeightButton), m_WindowNameLobby, true); m_WindowGamePlaySettings->ToggleOpen(); // | Starting units count | m_BtnSpawnCount = g_GUI.AddButton("GamePlaySettingStartCount", GUI::Rectangle(gpsDiff, gpsDiff, gpsStartCountW, gpsDiff), m_WindowNameGamePlaySettings); m_BtnSpawnCount->GetBackgroundRef().Texture = m_TextureNameButtons; m_BtnSpawnCount->SetText("Starting units count"); m_BtnSpawnCount->SetEnabled(false); // | Starting units count | - | m_BtnSpawnCountDec = g_GUI.AddButton("GamePlaySettingStartCountModDec", GUI::Rectangle(gpsStartCountW + gpsDiff, gpsDiff, gpsDiff, gpsDiff), m_WindowNameGamePlaySettings); m_BtnSpawnCountDec->GetBackgroundRef().Texture = m_TextureNameButtons; m_BtnSpawnCountDec->SetText("-"); m_BtnSpawnCountDec->SetClickScript(m_ScriptChangeGameSetting + "(-1)"); // | Starting units count | - | X | m_BtnSpawnCountVal = g_GUI.AddButton("GamePlaySettingStartCountVal", GUI::Rectangle(gpsStartCountW + gpsDiff * 2, gpsDiff, gpsDiff, gpsDiff), m_WindowNameGamePlaySettings); m_BtnSpawnCountVal->GetBackgroundRef().Texture = m_TextureNameButtons; m_BtnSpawnCountVal->SetText("X"); m_BtnSpawnCountVal->SetEnabled(false); // | Starting units count | - | X | + | m_BtnSpawnCountInc = g_GUI.AddButton("GamePlaySettingStartCountModInc", GUI::Rectangle(gpsStartCountW + gpsDiff * 3, gpsDiff, gpsDiff, gpsDiff), m_WindowNameGamePlaySettings); m_BtnSpawnCountInc->GetBackgroundRef().Texture = m_TextureNameButtons; m_BtnSpawnCountInc->SetText("+"); m_BtnSpawnCountInc->SetClickScript(m_ScriptChangeGameSetting + "(1)"); } } }
BOOL CALLBACK DlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: { SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER1), TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(4, 10)); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER2), TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(1, 2)); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER3), TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(0, 6)); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER4), TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(0, 6)); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER5), TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(0, 6)); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER6), TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(1, 6)); int nValue; nValue = GetPrivateProfileInt("MoonbaseConsole", "SizeValue", 4, szMoonbaseIniFileG); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER1), TBM_SETPOS, TRUE, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "SizeRandom", FALSE, szMoonbaseIniFileG); CheckDlgButton(hwndDlg, IDC_CHECK1, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "GeneratorValue", 1, szMoonbaseIniFileG); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER2), TBM_SETPOS, TRUE, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "GeneratorRandom", TRUE, szMoonbaseIniFileG); CheckDlgButton(hwndDlg, IDC_CHECK2, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "EnergyValue", 3, szMoonbaseIniFileG); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER3), TBM_SETPOS, TRUE, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "EnergyRandom", TRUE, szMoonbaseIniFileG); CheckDlgButton(hwndDlg, IDC_CHECK3, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "TerrainValue", 3, szMoonbaseIniFileG); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER4), TBM_SETPOS, TRUE, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "TerrainRandom", TRUE, szMoonbaseIniFileG); CheckDlgButton(hwndDlg, IDC_CHECK4, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "WaterValue", 3, szMoonbaseIniFileG); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER5), TBM_SETPOS, TRUE, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "WaterRandom", TRUE, szMoonbaseIniFileG); CheckDlgButton(hwndDlg, IDC_CHECK5, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "TilesetValue", 5, szMoonbaseIniFileG); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER6), TBM_SETPOS, TRUE, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "TilesetRandom", TRUE, szMoonbaseIniFileG); CheckDlgButton(hwndDlg, IDC_CHECK6, nValue); SendMessage(hwndDlg, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hIconG); EnableDialog(hwndDlg, true); return TRUE; } case WM_VSCROLL: { if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER1)) CheckDlgButton(hwndDlg, IDC_CHECK1, BST_UNCHECKED); else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER2)) CheckDlgButton(hwndDlg, IDC_CHECK2, BST_UNCHECKED); else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER3)) CheckDlgButton(hwndDlg, IDC_CHECK3, BST_UNCHECKED); else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER4)) CheckDlgButton(hwndDlg, IDC_CHECK4, BST_UNCHECKED); else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER5)) CheckDlgButton(hwndDlg, IDC_CHECK5, BST_UNCHECKED); else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER6)) CheckDlgButton(hwndDlg, IDC_CHECK6, BST_UNCHECKED); return TRUE; } case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_BUTTON1: // Help { HRSRC hrsrc = FindResource(NULL, MAKEINTRESOURCE(IDR_TXT1), "TXT"); HGLOBAL hgbl = LoadResource(NULL, hrsrc); BYTE *pReadme = (BYTE *)LockResource(hgbl); char sz[MAX_PATH]; strcpy(sz, szMoonbasePathG); strcat(sz, "\\MC_README.TXT"); FILE *pf; pf = fopen(sz, "wb"); fwrite(pReadme, 1, SizeofResource(NULL, hrsrc), pf); fclose(pf); ShellExecute(hwndDlg, "open", "MC_README.TXT", NULL, szMoonbasePathG, SW_SHOWNORMAL); return TRUE; } case IDC_BUTTON3: // Credits MessageBox(hwndDlg, "A lot of people helped in one way or the other. Here are the main contributors (in alphabetical order).\n" "\n" "Katton designed and coded the Katton map generation algorithm. He decoded a lot of the tiles and published what he learned. He also coded the algorithm that puts the \"craters\" on the map and wrote the code that generates the map preview showing the options.\n" "\n" "MYCROFT wrote the tools to rip apart the MAP files so they could be deciphered, decoded the rest of the tiles, defined the format that allows the generators to describe the map without caring about tiles, wrote the code to translate the generator output to a useable map, and did the Windows coding.\n" "\n" "SpacemanSpiff designed and coded the Spiff map generation algorithm. He also contributed to deciphering the map file format.\n" "\n" "Special thanks to Bwappo for his contest-winning thumbnail image.\n" "\n" "A number of other people on the Moonbase Commander forums also contributed to map decoding or beta testing including Bwappo, Covak, florent28, Kamolas, llangford, and YorkdinK.\n", "Moonbase Console Credits", MB_OK); return TRUE; case IDC_BTN_HOST_GAME: if (!DialogBoxParam(hInstanceG, MAKEINTRESOURCE(IDD_DIALOG3), hwndDlg, HostDlgProc, 0)) return TRUE; // bail if they cancel // fall through case IDC_SINGLE_GENERATE: { CGameInfo gi; gi.nVersion = GAMENUM_VERSION; if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_CHECK1)) gi.nMapSize = ((rand() % 5) + 4) * 8; // Don't randomly pick nonstandard map sizes. else gi.nMapSize = SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER1), TBM_GETPOS, 0, 0) * 8; if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_CHECK2)) gi.nGenerator = (rand() % 2) + 1; else gi.nGenerator = SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER2), TBM_GETPOS, 0, 0); if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_CHECK6)) gi.nTileset = (rand() % 6) + 1; else gi.nTileset = 7 - SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER6), TBM_GETPOS, 0, 0);; gi.nIP1 = (unsigned char) FIRST_IPADDRESS(dwIPAddressG); gi.nIP2 = (unsigned char) SECOND_IPADDRESS(dwIPAddressG); gi.nIP3 = (unsigned char) THIRD_IPADDRESS(dwIPAddressG); gi.nIP4 = (unsigned char) FOURTH_IPADDRESS(dwIPAddressG); MBCMIF mif; if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_CHECK3)) gi.nEnergy = (rand() % 3) + 2; // Only use [2, 3, 4] of the legal [0, 1, 2, 3, 4, 5, 6] else gi.nEnergy = 6 - SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER3), TBM_GETPOS, 0, 0); if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_CHECK4)) gi.nTerrain = (rand() % 3) + 2; // Only use [2, 3, 4] of the legal [0, 1, 2, 3, 4, 5, 6] else gi.nTerrain = 6 - SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER4), TBM_GETPOS, 0, 0); if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_CHECK5)) gi.nWater = (rand() % 3) + 2; // Only use [2, 3, 4] of the legal [0, 1, 2, 3, 4, 5, 6] else gi.nWater = 6 - SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER5), TBM_GETPOS, 0, 0); gi.nSeed = rand(); // It is critical that the seed get set right before the generate. srand(gi.nSeed); switch (gi.nGenerator) { case SPIFF_GEN: SpiffGenerate(gi, mif); break; case KATTON_GEN: KattonGenerate(gi, mif); break; } try { BackupSystemMapFile();// TODO: Do single player differently. makewiz(gi.nEnergy, gi.nTerrain, gi.nWater); MakeMap(mif, gi); if (LOWORD(wParam) == IDC_SINGLE_GENERATE) { gi.nIP1 = 192; gi.nIP2 = 168; gi.nIP3 = 1; gi.nIP4 = 1; } else { PublishGameNumber(gi, hwndDlg); // Prompt the user, tell them about the game number, and give them a chance to bail. if (IDCANCEL == MessageBox(hwndDlg, "Your random map has been generated.\n\nThe game number for this map needs to be given to the people that you will be playing with.\nThis number is already on the clipboard, paste it into a message to them.\n\nOnce you have done this, press Ok to start Moonbase Commander or Cancel to abort.", "Moonbase Console Message", MB_OKCANCEL)) { RestoreSystemMapFile(); return TRUE; } } HostGame(hwndDlg, gi); } catch (CMapError e) { RestoreSystemMapFile(); char szErrorHeader[80]; char szError[512]; sprintf(szErrorHeader, "Map Generation Error: Please Report This Information"); sprintf(szError, "%s\n\n" "Generator:\t%s\n" "Seed:\t\t%04X\n" "Size:\t\t%d\n" "nEnergy:\t\t%d\n" "nTerrain:\t\t%d\n" "nWater:\t\t%d\n" "\n(%d, %d)\n" "%d %d %d %d\n" " %c %c %c\n" "%d %d %d %d\n" " %c %c %c\n" "%d %d %d %d\n" " %c %c %c\n" "%d %d %d %d\n", e.m_szErrorDescription, (gi.nGenerator == SPIFF_GEN) ? "SpacemanSpiff" : "Katton", (int)gi.nSeed, (int)gi.nMapSize, gi.nEnergy, gi.nTerrain, gi.nWater, e.m_nX, e.m_nY, mif.TTLLCorner(e.m_nX,e.m_nY), mif.TTLCorner(e.m_nX,e.m_nY), mif.TTRCorner(e.m_nX,e.m_nY), mif.TTRRCorner(e.m_nX,e.m_nY), mif.TLCenter(e.m_nX,e.m_nY), mif.TCenter(e.m_nX,e.m_nY), mif.TRCenter(e.m_nX,e.m_nY), mif.TLLCorner(e.m_nX,e.m_nY), mif.TLCorner(e.m_nX,e.m_nY), mif.TRCorner(e.m_nX,e.m_nY), mif.TRRCorner(e.m_nX,e.m_nY), mif.LCenter(e.m_nX,e.m_nY), mif.aaCenterMap[e.m_nX][e.m_nY], mif.RCenter(e.m_nX,e.m_nY), mif.BLLCorner(e.m_nX,e.m_nY), mif.BLCorner(e.m_nX,e.m_nY), mif.BRCorner(e.m_nX,e.m_nY), mif.BRRCorner(e.m_nX,e.m_nY), mif.BLCenter(e.m_nX,e.m_nY), mif.BCenter(e.m_nX,e.m_nY), mif.BRCenter(e.m_nX,e.m_nY), mif.BBLLCorner(e.m_nX,e.m_nY), mif.BBLCorner(e.m_nX,e.m_nY), mif.BBRCorner(e.m_nX,e.m_nY), mif.BBRRCorner(e.m_nX,e.m_nY)); MessageBox(NULL, szError, szErrorHeader, MB_OK); } catch (CGenericError e) { MessageBox(NULL, e.m_szErrorDescription, "Moonbase Console Error", MB_OK); } return TRUE; } case IDC_BUTTON2: { if (!DialogBoxParam(hInstanceG, MAKEINTRESOURCE(IDD_DIALOG2), hwndDlg, JoinDlgProc, 0)) return TRUE; // bail if they cancel MBCMIF mif; // seed the generator srand(giG.nSeed); switch(giG.nGenerator) { case SPIFF_GEN: SpiffGenerate(giG, mif); break; case KATTON_GEN: KattonGenerate(giG, mif); break; } try { BackupSystemMapFile(); makewiz(giG.nEnergy, giG.nTerrain, giG.nWater); MakeMap(mif, giG); } catch (CGenericError e) { RestoreSystemMapFile(); MessageBox(NULL, e.m_szErrorDescription, "Moonbase Console Error", MB_OK); } catch (...) { // Shouldn't get map generation errors here, only valid keys should be coming in. } JoinGame(hwndDlg, giG); return TRUE; } default: return FALSE; } case WM_CLOSE: { char sz[80]; wsprintf(sz, "%d", SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER1), TBM_GETPOS, 0, 0)); WritePrivateProfileString("MoonbaseConsole", "SizeValue", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", IsDlgButtonChecked(hwndDlg, IDC_CHECK1)); WritePrivateProfileString("MoonbaseConsole", "SizeRandom", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER2), TBM_GETPOS, 0, 0)); WritePrivateProfileString("MoonbaseConsole", "GeneratorValue", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", IsDlgButtonChecked(hwndDlg, IDC_CHECK2)); WritePrivateProfileString("MoonbaseConsole", "GeneratorRandom", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER3), TBM_GETPOS, 0, 0)); WritePrivateProfileString("MoonbaseConsole", "EnergyValue", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", IsDlgButtonChecked(hwndDlg, IDC_CHECK3)); WritePrivateProfileString("MoonbaseConsole", "EnergyRandom", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER4), TBM_GETPOS, 0, 0)); WritePrivateProfileString("MoonbaseConsole", "TerrainValue", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", IsDlgButtonChecked(hwndDlg, IDC_CHECK4)); WritePrivateProfileString("MoonbaseConsole", "TerrainRandom", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER5), TBM_GETPOS, 0, 0)); WritePrivateProfileString("MoonbaseConsole", "WaterValue", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", IsDlgButtonChecked(hwndDlg, IDC_CHECK5)); WritePrivateProfileString("MoonbaseConsole", "WaterRandom", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER6), TBM_GETPOS, 0, 0)); WritePrivateProfileString("MoonbaseConsole", "TilesetValue", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", IsDlgButtonChecked(hwndDlg, IDC_CHECK6)); WritePrivateProfileString("MoonbaseConsole", "TilesetRandom", sz, szMoonbaseIniFileG); DestroyWindow(hwndDlg); return TRUE; } case WM_DESTROY: CleanUpMoonbaseINI(); PostQuitMessage(0); return TRUE; } return FALSE; }
void ClientGame::RenderMainMenu() { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearColor( 0.97f * 0.9f, 0.96f * 0.9f, 0.89f * 0.9f, 0.0f ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); const int titleOffset = 50; glEnable(GL_TEXTURE_2D); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, m_xSize, m_ySize, 0); glColor(0x80FFFFFF); glBindTexture(GL_TEXTURE_2D, m_titleBackgroundTexture.handle); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2i(0, titleOffset); glTexCoord2i(m_xSize / m_titleBackgroundTexture.xSize, 0); glVertex2i(m_xSize, titleOffset); glTexCoord2i(m_xSize / m_titleBackgroundTexture.xSize, 1); glVertex2i(m_xSize, titleOffset + m_titleBackgroundTexture.ySize); glTexCoord2f(0, 1); glVertex2i(0, titleOffset + m_titleBackgroundTexture.ySize); glEnd(); glColor(0xFFFFFFFF); Render_DrawSprite(m_titleTextTexture, (m_xSize - m_titleTextTexture.xSize) / 2, titleOffset + (m_titleBackgroundTexture.ySize - m_titleTextTexture.ySize) / 2); // Draw the buttons. int xButtonSize = 400; int yButtonSize = 50; UI_Begin( m_uiTexture.handle, m_xSize, m_ySize ); #ifdef _DEBUG if (UI_Button(UI_ID, m_font, (m_xSize - xButtonSize) / 2, m_ySize - 300 + (yButtonSize + 10) * 4, xButtonSize, yButtonSize, "Connect to local")) { m_gameState = GameState_WaitingForServer; Connect("localhost", 12345); } #endif if (UI_Button(UI_ID, m_font, (m_xSize - xButtonSize) / 2, m_ySize - 300 + (yButtonSize + 10) * 0, xButtonSize, yButtonSize, "Host a game")) { HostGame(); } for (int i = 0; i < m_lanListener.GetNumServers(); ++i) { const LanListener::Server& server = m_lanListener.GetServer(i); char buffer[256]; sprintf(buffer, "Join '%s'", server.name); if (UI_Button(UI_ID, m_font, (m_xSize - xButtonSize) / 2, m_ySize - 300 + (yButtonSize + 10) * (1 + i), xButtonSize, yButtonSize, buffer)) { char addres[256]; sprintf(addres, "%d.%d.%d.%d", (server.ip >> 24) & 0xFF, (server.ip >> 16) & 0xFF, (server.ip >> 8) & 0xFF, server.ip & 0xFF); m_gameState = GameState_WaitingForServer; Connect(addres, server.port); } }