MapUtil.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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: MapUtil.h /////////////////////////////////////////////////////////
  24. // Author: Matt Campbell, December 2001
  25. // Description: Map utility/convenience routines
  26. ////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __MAPUTIL_H__
  29. #define __MAPUTIL_H__
  30. #include "Common/AsciiString.h"
  31. #include "Common/UnicodeString.h"
  32. #include "Common/STLTypedefs.h"
  33. class GameWindow;
  34. class AsciiString;
  35. struct Coord3D;
  36. struct FileInfo;
  37. class Image;
  38. class DataChunkInput;
  39. struct DataChunkInfo;
  40. // This matches the windows timestamp.
  41. enum { SUPPLY_TECH_SIZE = 15};
  42. typedef std::list <ICoord2D> ICoord2DList;
  43. class TechAndSupplyImages
  44. {
  45. public:
  46. ICoord2DList m_techPosList;
  47. ICoord2DList m_supplyPosList;
  48. };
  49. struct WinTimeStamp
  50. {
  51. UnsignedInt m_lowTimeStamp;
  52. UnsignedInt m_highTimeStamp;
  53. };
  54. class WaypointMap : public std::map<AsciiString, Coord3D>
  55. {
  56. public:
  57. void update( void ); ///< returns the number of multiplayer start spots found
  58. Int m_numStartSpots;
  59. };
  60. typedef std::list <Coord3D> Coord3DList;
  61. class MapMetaData
  62. {
  63. public:
  64. UnicodeString m_displayName;
  65. AsciiString m_nameLookupTag;
  66. Region3D m_extent;
  67. Int m_numPlayers;
  68. Bool m_isMultiplayer;
  69. Bool m_isOfficial;
  70. UnsignedInt m_filesize;
  71. UnsignedInt m_CRC;
  72. WinTimeStamp m_timestamp;
  73. WaypointMap m_waypoints;
  74. Coord3DList m_supplyPositions;
  75. Coord3DList m_techPositions;
  76. AsciiString m_fileName;
  77. };
  78. class MapCache : public std::map<AsciiString, MapMetaData>
  79. {
  80. public:
  81. MapCache() {}
  82. void updateCache( void );
  83. AsciiString getMapDir() const;
  84. AsciiString getUserMapDir() const;
  85. AsciiString getMapExtension() const;
  86. const MapMetaData *findMap(AsciiString mapName);
  87. // allow us to create a set of shippable maps to be in mapcache.ini. For use with -buildMapCache.
  88. void addShippingMap(AsciiString mapName) { mapName.toLower(); m_allowedMaps.insert(mapName); }
  89. private:
  90. Bool clearUnseenMaps( AsciiString dirName );
  91. void loadStandardMaps(void);
  92. Bool loadUserMaps(void); // returns true if we needed to (re)parse a map
  93. // Bool addMap( AsciiString dirName, AsciiString fname, WinTimeStamp timestamp,
  94. // UnsignedInt filesize, Bool isOfficial ); ///< returns true if it had to (re)parse the map
  95. Bool addMap( AsciiString dirName, AsciiString fname, FileInfo *fileInfo, Bool isOfficial); ///< returns true if it had to (re)parse the map
  96. void writeCacheINI( Bool userDir );
  97. static const char * m_mapCacheName;
  98. std::map<AsciiString, Bool> m_seen;
  99. std::set<AsciiString> m_allowedMaps;
  100. };
  101. extern MapCache *TheMapCache;
  102. extern TechAndSupplyImages TheSupplyAndTechImageLocations;
  103. Int populateMapListbox( GameWindow *listbox, Bool useSystemMaps, Bool isMultiplayer, AsciiString mapToSelect = AsciiString::TheEmptyString ); /// Read a list of maps from the run directory and fill in the listbox. Return the selected index
  104. Int populateMapListboxNoReset( GameWindow *listbox, Bool useSystemMaps, Bool isMultiplayer, AsciiString mapToSelect = AsciiString::TheEmptyString ); /// Read a list of maps from the run directory and fill in the listbox. Return the selected index
  105. Bool isValidMap( AsciiString mapName, Bool isMultiplayer ); /// Validate a map
  106. Image *getMapPreviewImage( AsciiString mapName );
  107. AsciiString getDefaultMap( Bool isMultiplayer ); /// Find a valid map
  108. AsciiString getDefaultOfficialMap();
  109. Bool isOfficialMap( AsciiString mapName );
  110. Bool parseMapPreviewChunk(DataChunkInput &file, DataChunkInfo *info, void *userData);
  111. void findDrawPositions( Int startX, Int startY, Int width, Int height, Region3D extent,
  112. ICoord2D *ul, ICoord2D *lr );
  113. Bool WouldMapTransfer( const AsciiString& mapName );
  114. #endif // __MAPUTIL_H__