levelInfo.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. //------------------------------------------------------------------------------
  23. // Loading info is text displayed on the client side while the mission
  24. // is being loaded. This information is extracted from the mission file
  25. // and sent to each the client as it joins.
  26. //------------------------------------------------------------------------------
  27. //------------------------------------------------------------------------------
  28. // clearLoadInfo
  29. //
  30. // Clears the mission info stored
  31. //------------------------------------------------------------------------------
  32. function clearLoadInfo()
  33. {
  34. if (isObject(theLevelInfo))
  35. theLevelInfo.delete();
  36. }
  37. //------------------------------------------------------------------------------
  38. // buildLoadInfo
  39. //
  40. // Extract the map description from the .mis file
  41. //------------------------------------------------------------------------------
  42. function buildLoadInfo( %mission )
  43. {
  44. clearLoadInfo();
  45. %infoObject = "";
  46. %file = new FileObject();
  47. if ( %file.openForRead( %mission ) ) {
  48. %inInfoBlock = false;
  49. while ( !%file.isEOF() ) {
  50. %line = %file.readLine();
  51. %line = trim( %line );
  52. if( %line $= "new ScriptObject(MissionInfo) {" )
  53. %inInfoBlock = true;
  54. else if( %line $= "new LevelInfo(theLevelInfo) {" )
  55. %inInfoBlock = true;
  56. else if( %inInfoBlock && %line $= "};" ) {
  57. %inInfoBlock = false;
  58. %infoObject = %infoObject @ %line;
  59. break;
  60. }
  61. if( %inInfoBlock )
  62. %infoObject = %infoObject @ %line @ " ";
  63. }
  64. %file.close();
  65. }
  66. else
  67. error("Level file " @ %mission @ " not found.");
  68. // Will create the object "MissionInfo"
  69. eval( %infoObject );
  70. %file.delete();
  71. }
  72. //------------------------------------------------------------------------------
  73. // dumpLoadInfo
  74. //
  75. // Echo the mission information to the console
  76. //------------------------------------------------------------------------------
  77. function dumpLoadInfo()
  78. {
  79. echo( "Level Name: " @ theLevelInfo.name );
  80. echo( "Level Description:" );
  81. for( %i = 0; theLevelInfo.desc[%i] !$= ""; %i++ )
  82. echo (" " @ theLevelInfo.desc[%i]);
  83. }
  84. //------------------------------------------------------------------------------
  85. // sendLoadInfoToClient
  86. //
  87. // Sends mission description to the client
  88. //------------------------------------------------------------------------------
  89. function sendLoadInfoToClient( %client )
  90. {
  91. messageClient( %client, 'MsgLoadInfo', "", theLevelInfo.levelName );
  92. // Send Mission Description a line at a time
  93. for( %i = 0; theLevelInfo.desc[%i] !$= ""; %i++ )
  94. messageClient( %client, 'MsgLoadDescripition', "", theLevelInfo.desc[%i] );
  95. messageClient( %client, 'MsgLoadInfoDone' );
  96. }
  97. // A function used in order to easily parse the MissionGroup for classes . I'm pretty
  98. // sure at this point the function can be easily modified to search the any group as well.
  99. function parseMissionGroup( %className, %childGroup )
  100. {
  101. if( getWordCount( %childGroup ) == 0)
  102. %currentGroup = "MissionGroup";
  103. else
  104. %currentGroup = %childGroup;
  105. for(%i = 0; %i < (%currentGroup).getCount(); %i++)
  106. {
  107. if( (%currentGroup).getObject(%i).getClassName() $= %className )
  108. return true;
  109. if( (%currentGroup).getObject(%i).getClassName() $= "SimGroup" )
  110. {
  111. if( parseMissionGroup( %className, (%currentGroup).getObject(%i).getId() ) )
  112. return true;
  113. }
  114. }
  115. }
  116. //
  117. function parseMissionGroupForIds( %className, %childGroup )
  118. {
  119. if( getWordCount( %childGroup ) == 0)
  120. %currentGroup = $Game::MissionGroup;
  121. else
  122. %currentGroup = %childGroup;
  123. for(%i = 0; %i < (%currentGroup).getCount(); %i++)
  124. {
  125. if( (%currentGroup).getObject(%i).getClassName() $= %className )
  126. %classIds = %classIds @ (%currentGroup).getObject(%i).getId() @ " ";
  127. if( (%currentGroup).getObject(%i).getClassName() $= "SimGroup" )
  128. %classIds = %classIds @ parseMissionGroupForIds( %className, (%currentGroup).getObject(%i).getId());
  129. }
  130. return %classIds;
  131. }
  132. function getLevelInfo( %missionFile )
  133. {
  134. clearLoadInfo();
  135. %file = new FileObject();
  136. %LevelInfoObject = "";
  137. if ( %file.openForRead( %missionFile ) ) {
  138. %inInfoBlock = false;
  139. while ( !%file.isEOF() ) {
  140. %line = %file.readLine();
  141. %line = trim( %line );
  142. if( %line $= "new ScriptObject(LevelInfo) {" )
  143. %inInfoBlock = true;
  144. else if( %line $= "new LevelInfo(theLevelInfo) {" )
  145. %inInfoBlock = true;
  146. else if( %inInfoBlock && %line $= "};" ) {
  147. %inInfoBlock = false;
  148. %LevelInfoObject = %LevelInfoObject @ %line;
  149. break;
  150. }
  151. if( %inInfoBlock )
  152. %LevelInfoObject = %LevelInfoObject @ %line @ " ";
  153. }
  154. %file.close();
  155. }
  156. %file.delete();
  157. if( %LevelInfoObject !$= "" )
  158. {
  159. %LevelInfoObject = "%LevelInfoObject = " @ %LevelInfoObject;
  160. eval( %LevelInfoObject );
  161. return %LevelInfoObject;
  162. }
  163. // Didn't find our LevelInfo
  164. return 0;
  165. }