Advertisement
Guest User

Untitled

a guest
Aug 19th, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. /*
  2. ===================
  3. idGameLocal::NextMap
  4. ===================
  5. */
  6. bool idGameLocal::NextMap( void ) {
  7. const function_t *func;
  8. idThread *thread;
  9. idDict newInfo;
  10. const idKeyValue *keyval, *keyval2;
  11. int i;
  12.  
  13. const char *mapCycleList, *currentMap;
  14. mapCycleList = si_mapCycle.GetString();
  15.  
  16. #ifdef _XENON
  17. //Live()->PickMap();
  18. return true;
  19. #endif
  20.  
  21. nextMap = false;
  22.  
  23. if ( si_rmapCycle.GetBool() ) {
  24.  
  25. idStrList fileList;
  26. idStr mapName;
  27.  
  28. int numMaps = fileSystem->GetNumMaps();
  29. const idDict *dict;
  30. int index = 0;
  31. const char* gameType = si_gameType.GetString();
  32.  
  33. fileList.Clear();
  34.  
  35. for ( i = 0; i < numMaps; i++ ) {
  36. dict = fileSystem->GetMapDecl( i );
  37. if ( dict && idStr::FindText( dict->GetString( "path" ), "mp/") ) {
  38. continue;
  39. }
  40.  
  41. // any MP gametype supported
  42. bool gameTypeMap = false;
  43.  
  44. if ( dict && dict->GetBool( gameType ) && (strcmp( dict->GetString( "path" ), si_map.GetString() )) ) {
  45. gameTypeMap = true;
  46. }
  47.  
  48. if ( gameTypeMap ) {
  49. fileList.AddUnique( va( "%s", dict->GetString( "path" ) ) );
  50. }
  51.  
  52. }
  53.  
  54. if ( fileList.Num() > 0 ) {
  55.  
  56. index = gameLocal.random.RandomInt( fileList.Num() );
  57. mapName = fileList[index].c_str();
  58.  
  59. if ( mapName[0] != '\0' ) {
  60. si_map.SetString( mapName );
  61.  
  62. newInfo = *cvarSystem->MoveCVarsToDict( CVAR_SERVERINFO );
  63. for ( i = 0; i < newInfo.GetNumKeyVals(); i++ ) {
  64. keyval = newInfo.GetKeyVal( i );
  65. keyval2 = serverInfo.FindKey( keyval->GetKey() );
  66. if ( !keyval2 || keyval->GetValue().Icmp( keyval2->GetValue() ) ) {
  67. break;
  68. }
  69. }
  70. return ( i != newInfo.GetNumKeyVals() );
  71. }
  72.  
  73. }
  74.  
  75. return false;
  76.  
  77. } else if ( mapCycleList && strlen( mapCycleList ) ) {
  78.  
  79. idLexer src;
  80. idToken token, firstFound;
  81. int numMaps = 0;
  82. bool foundMap = false;
  83.  
  84. src.FreeSource();
  85. src.SetFlags( LEXFL_NOFATALERRORS | LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT );
  86. src.LoadMemory( mapCycleList, strlen( mapCycleList ), "idGameLocal::NextMap" );
  87.  
  88. if ( src.IsLoaded() ) {
  89.  
  90. currentMap = si_map.GetString();
  91. while( src.ReadToken( &token ) ) {
  92. if ( token == ";" ) {
  93. continue;
  94. }
  95. numMaps++;
  96.  
  97. if ( numMaps == 1 ) {
  98. // guarantee that we use a map no matter what ( or when we wrap )
  99. firstFound = token;
  100. }
  101. if ( foundMap ) {
  102. firstFound = token;
  103. break;
  104. }
  105.  
  106. if ( idStr::Icmp( token, currentMap ) == 0 ) {
  107. foundMap = true;
  108. }
  109. }
  110.  
  111. if ( firstFound != "" ) {
  112. si_map.SetString( firstFound );
  113. return true;
  114. }
  115. }
  116.  
  117. if ( fileSystem->ReadFile( g_mapCycle.GetString(), NULL, NULL ) < 0 ) {
  118. if ( fileSystem->ReadFile( va( "%s.scriptcfg", g_mapCycle.GetString() ), NULL, NULL ) < 0 ) {
  119. Printf( "map cycle script '%s': not found\n", g_mapCycle.GetString() );
  120. return false;
  121. } else {
  122. g_mapCycle.SetString( va( "%s.scriptcfg", g_mapCycle.GetString() ) );
  123. }
  124. }
  125.  
  126. Printf( "map cycle script: '%s'\n", g_mapCycle.GetString() );
  127. func = program.FindFunction( "mapcycle::cycle" );
  128. if ( !func ) {
  129. program.CompileFile( g_mapCycle.GetString() );
  130. func = program.FindFunction( "mapcycle::cycle" );
  131. }
  132. if ( !func ) {
  133. Printf( "Couldn't find mapcycle::cycle\n" );
  134. return false;
  135. }
  136.  
  137. thread = new idThread( func );
  138. thread->Start();
  139. delete thread;
  140.  
  141. newInfo = *cvarSystem->MoveCVarsToDict( CVAR_SERVERINFO );
  142. for ( i = 0; i < newInfo.GetNumKeyVals(); i++ ) {
  143. keyval = newInfo.GetKeyVal( i );
  144. keyval2 = serverInfo.FindKey( keyval->GetKey() );
  145. if ( !keyval2 || keyval->GetValue().Icmp( keyval2->GetValue() ) ) {
  146. break;
  147. }
  148. }
  149. return ( i != newInfo.GetNumKeyVals() );
  150.  
  151. }
  152.  
  153. return false;
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement