INIMapCache.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program 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. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: INIMapCache.cpp ///////////////////////////////////////////////////////////////////////////
  24. // Author: Matthew D. Campbell, February 2002
  25. // Desc: Parsing MapCache INI entries
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Lib/BaseType.h"
  30. #include "Common/INI.h"
  31. #include "GameClient/MapUtil.h"
  32. #include "GameNetwork/NetworkDefs.h"
  33. #include "Common/NameKeyGenerator.h"
  34. #include "Common/WellKnownKeys.h"
  35. #include "Common/QuotedPrintable.h"
  36. class MapMetaDataReader
  37. {
  38. public:
  39. Region3D m_extent;
  40. Int m_numPlayers;
  41. Bool m_isMultiplayer;
  42. AsciiString m_asciiDisplayName;
  43. Bool m_isOfficial;
  44. WinTimeStamp m_timestamp;
  45. UnsignedInt m_filesize;
  46. UnsignedInt m_CRC;
  47. Coord3D m_waypoints[MAX_SLOTS];
  48. Coord3D m_initialCameraPosition;
  49. Coord3DList m_supplyPositions;
  50. Coord3DList m_techPositions;
  51. static const FieldParse m_mapFieldParseTable[]; ///< the parse table for INI definition
  52. const FieldParse *getFieldParse( void ) const { return m_mapFieldParseTable; }
  53. };
  54. void parseSupplyPositionCoord3D( INI* ini, void * instance, void * /*store*/, const void* /*userData*/ )
  55. {
  56. MapMetaDataReader *mmdr = (MapMetaDataReader *)instance;
  57. Coord3D coord3d;
  58. INI::parseCoord3D(ini, NULL, &coord3d,NULL );
  59. mmdr->m_supplyPositions.push_front(coord3d);
  60. }
  61. void parseTechPositionsCoord3D( INI* ini, void * instance, void * /*store*/, const void* /*userData*/ )
  62. {
  63. MapMetaDataReader *mmdr = (MapMetaDataReader *)instance;
  64. Coord3D coord3d;
  65. INI::parseCoord3D(ini, NULL, &coord3d,NULL );
  66. mmdr->m_techPositions.push_front(coord3d);
  67. }
  68. const FieldParse MapMetaDataReader::m_mapFieldParseTable[] =
  69. {
  70. { "isOfficial", INI::parseBool, NULL, offsetof( MapMetaDataReader, m_isOfficial ) },
  71. { "isMultiplayer", INI::parseBool, NULL, offsetof( MapMetaDataReader, m_isMultiplayer ) },
  72. { "extentMin", INI::parseCoord3D, NULL, offsetof( MapMetaDataReader, m_extent.lo ) },
  73. { "extentMax", INI::parseCoord3D, NULL, offsetof( MapMetaDataReader, m_extent.hi ) },
  74. { "numPlayers", INI::parseInt, NULL, offsetof( MapMetaDataReader, m_numPlayers ) },
  75. { "fileSize", INI::parseUnsignedInt, NULL, offsetof( MapMetaDataReader, m_filesize ) },
  76. { "fileCRC", INI::parseUnsignedInt, NULL, offsetof( MapMetaDataReader, m_CRC ) },
  77. { "timestampLo", INI::parseInt, NULL, offsetof( MapMetaDataReader, m_timestamp.m_lowTimeStamp ) },
  78. { "timestampHi", INI::parseInt, NULL, offsetof( MapMetaDataReader, m_timestamp.m_highTimeStamp ) },
  79. { "displayName", INI::parseAsciiString, NULL, offsetof( MapMetaDataReader, m_asciiDisplayName ) },
  80. { "supplyPosition", parseSupplyPositionCoord3D, NULL, NULL },
  81. { "techPosition", parseTechPositionsCoord3D, NULL, NULL },
  82. { "Player_1_Start", INI::parseCoord3D, NULL, offsetof( MapMetaDataReader, m_waypoints ) },
  83. { "Player_2_Start", INI::parseCoord3D, NULL, offsetof( MapMetaDataReader, m_waypoints ) + sizeof(Coord3D) * 1 },
  84. { "Player_3_Start", INI::parseCoord3D, NULL, offsetof( MapMetaDataReader, m_waypoints ) + sizeof(Coord3D) * 2 },
  85. { "Player_4_Start", INI::parseCoord3D, NULL, offsetof( MapMetaDataReader, m_waypoints ) + sizeof(Coord3D) * 3 },
  86. { "Player_5_Start", INI::parseCoord3D, NULL, offsetof( MapMetaDataReader, m_waypoints ) + sizeof(Coord3D) * 4 },
  87. { "Player_6_Start", INI::parseCoord3D, NULL, offsetof( MapMetaDataReader, m_waypoints ) + sizeof(Coord3D) * 5 },
  88. { "Player_7_Start", INI::parseCoord3D, NULL, offsetof( MapMetaDataReader, m_waypoints ) + sizeof(Coord3D) * 6 },
  89. { "Player_8_Start", INI::parseCoord3D, NULL, offsetof( MapMetaDataReader, m_waypoints ) + sizeof(Coord3D) * 7 },
  90. { "InitialCameraPosition", INI::parseCoord3D, NULL, offsetof( MapMetaDataReader, m_initialCameraPosition ) },
  91. { NULL, NULL, NULL, 0 } // keep this last
  92. };
  93. void INI::parseMapCacheDefinition( INI* ini )
  94. {
  95. const char *c;
  96. AsciiString name;
  97. MapMetaDataReader mdr;
  98. MapMetaData md;
  99. // read the name
  100. c = ini->getNextToken(" \n\r\t");
  101. name.set( c );
  102. name = QuotedPrintableToAsciiString(name);
  103. md.m_waypoints.clear();
  104. ini->initFromINI( &mdr, mdr.getFieldParse() );
  105. md.m_extent = mdr.m_extent;
  106. md.m_isOfficial = mdr.m_isOfficial != 0;
  107. md.m_isMultiplayer = mdr.m_isMultiplayer != 0;
  108. md.m_numPlayers = mdr.m_numPlayers;
  109. md.m_filesize = mdr.m_filesize;
  110. md.m_CRC = mdr.m_CRC;
  111. md.m_timestamp = mdr.m_timestamp;
  112. md.m_waypoints[TheNameKeyGenerator->keyToName(TheKey_InitialCameraPosition)] = mdr.m_initialCameraPosition;
  113. md.m_displayName = QuotedPrintableToUnicodeString(mdr.m_asciiDisplayName);
  114. AsciiString startingCamName;
  115. for (Int i=0; i<md.m_numPlayers; ++i)
  116. {
  117. startingCamName.format("Player_%d_Start", i+1); // start pos waypoints are 1-based
  118. md.m_waypoints[startingCamName] = mdr.m_waypoints[i];
  119. }
  120. Coord3DList::iterator it = mdr.m_supplyPositions.begin();
  121. while( it != mdr.m_supplyPositions.end())
  122. {
  123. md.m_supplyPositions.push_front(*it);
  124. it++;
  125. }
  126. it = mdr.m_techPositions.begin();
  127. while( it != mdr.m_techPositions.end())
  128. {
  129. md.m_techPositions.push_front(*it);
  130. it++;
  131. }
  132. if(TheMapCache && !md.m_displayName.isEmpty())
  133. {
  134. AsciiString lowerName = name;
  135. lowerName.toLower();
  136. md.m_fileName = lowerName;
  137. // DEBUG_LOG(("INI::parseMapCacheDefinition - adding %s to map cache\n", lowerName.str()));
  138. (*TheMapCache)[lowerName] = md;
  139. }
  140. }