Common_menu.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "Common_local.h"
  23. /*
  24. ==============
  25. idCommonLocal::InitializeMPMapsModes
  26. ==============
  27. */
  28. void idCommonLocal::InitializeMPMapsModes() {
  29. const char ** gameModes = NULL;
  30. const char ** gameModesDisplay = NULL;
  31. int numModes = game->GetMPGameModes( &gameModes, &gameModesDisplay );
  32. mpGameModes.SetNum( numModes );
  33. for ( int i = 0; i < numModes; i++ ) {
  34. mpGameModes[i] = gameModes[i];
  35. }
  36. mpDisplayGameModes.SetNum( numModes );
  37. for ( int i = 0; i < numModes; i++ ) {
  38. mpDisplayGameModes[i] = gameModesDisplay[i];
  39. }
  40. int numMaps = declManager->GetNumDecls( DECL_MAPDEF );
  41. mpGameMaps.Clear();
  42. for ( int i = 0; i < numMaps; i++ ) {
  43. const idDeclEntityDef * mapDef = static_cast<const idDeclEntityDef *>( declManager->DeclByIndex( DECL_MAPDEF, i ) );
  44. uint32 supportedModes = 0;
  45. for ( int j = 0; j < numModes; j++ ) {
  46. if ( mapDef->dict.GetBool( gameModes[j], false ) ) {
  47. supportedModes |= BIT(j);
  48. }
  49. }
  50. if ( supportedModes != 0 ) {
  51. mpMap_t & mpMap = mpGameMaps.Alloc();
  52. mpMap.mapFile = mapDef->GetName();
  53. mpMap.mapName = mapDef->dict.GetString( "name", mpMap.mapFile );
  54. mpMap.supportedModes = supportedModes;
  55. }
  56. }
  57. }
  58. /*
  59. ==============
  60. idCommonLocal::OnStartHosting
  61. ==============
  62. */
  63. void idCommonLocal::OnStartHosting( idMatchParameters & parms ) {
  64. if ( ( parms.matchFlags & MATCH_REQUIRE_PARTY_LOBBY ) == 0 ) {
  65. return; // This is the party lobby or a SP match
  66. }
  67. // If we were searching for a random match but didn't find one, we'll need to select parameters now
  68. if ( parms.gameMap < 0 ) {
  69. if ( parms.gameMode < 0 ) {
  70. // Random mode means any map will do
  71. parms.gameMap = idLib::frameNumber % mpGameMaps.Num();
  72. } else {
  73. // Select a map which supports the chosen mode
  74. idList<int> supportedMaps;
  75. uint32 supportedMode = BIT( parms.gameMode );
  76. for ( int i = 0; i < mpGameMaps.Num(); i++ ) {
  77. if ( mpGameMaps[i].supportedModes & supportedMode ) {
  78. supportedMaps.Append( i );
  79. }
  80. }
  81. if ( supportedMaps.Num() == 0 ) {
  82. // We don't have any maps which support the chosen mode...
  83. parms.gameMap = idLib::frameNumber % mpGameMaps.Num();
  84. parms.gameMode = -1;
  85. } else {
  86. parms.gameMap = supportedMaps[ idLib::frameNumber % supportedMaps.Num() ];
  87. }
  88. }
  89. }
  90. if ( parms.gameMode < 0 ) {
  91. uint32 supportedModes = mpGameMaps[parms.gameMap].supportedModes;
  92. int8 supportedModeList[32] = {};
  93. int numSupportedModes = 0;
  94. for ( int i = 0; i < 32; i++ ) {
  95. if ( supportedModes & BIT(i) ) {
  96. supportedModeList[numSupportedModes] = i;
  97. numSupportedModes++;
  98. }
  99. }
  100. parms.gameMode = supportedModeList[ ( idLib::frameNumber / mpGameMaps.Num() ) % numSupportedModes ];
  101. }
  102. parms.mapName = mpGameMaps[parms.gameMap].mapFile;
  103. parms.numSlots = session->GetTitleStorageInt("MAX_PLAYERS_ALLOWED", 4 );
  104. }
  105. /*
  106. ==============
  107. idCommonLocal::StartMainMenu
  108. ==============
  109. */
  110. void idCommonLocal::StartMenu( bool playIntro ) {
  111. if ( game && game->Shell_IsActive() ) {
  112. return;
  113. }
  114. if ( readDemo ) {
  115. // if we're playing a demo, esc kills it
  116. UnloadMap();
  117. }
  118. if ( game ) {
  119. game->Shell_Show( true );
  120. game->Shell_SyncWithSession();
  121. }
  122. console->Close();
  123. }
  124. /*
  125. ===============
  126. idCommonLocal::ExitMenu
  127. ===============
  128. */
  129. void idCommonLocal::ExitMenu() {
  130. if ( game ) {
  131. game->Shell_Show( false );
  132. }
  133. }
  134. /*
  135. ==============
  136. idCommonLocal::MenuEvent
  137. Executes any commands returned by the gui
  138. ==============
  139. */
  140. bool idCommonLocal::MenuEvent( const sysEvent_t * event ) {
  141. if ( session->GetSignInManager().ProcessInputEvent( event ) ) {
  142. return true;
  143. }
  144. if ( game && game->Shell_IsActive() ) {
  145. return game->Shell_HandleGuiEvent( event );
  146. }
  147. if ( game ) {
  148. return game->HandlePlayerGuiEvent( event );
  149. }
  150. return false;
  151. }
  152. /*
  153. =================
  154. idCommonLocal::GuiFrameEvents
  155. =================
  156. */
  157. void idCommonLocal::GuiFrameEvents() {
  158. if ( game ) {
  159. game->Shell_SyncWithSession();
  160. }
  161. }