MapUtil.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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: 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. Region3D m_extent;
  66. Int m_numPlayers;
  67. Bool m_isMultiplayer;
  68. Bool m_isOfficial;
  69. UnsignedInt m_filesize;
  70. UnsignedInt m_CRC;
  71. WinTimeStamp m_timestamp;
  72. WaypointMap m_waypoints;
  73. Coord3DList m_supplyPositions;
  74. Coord3DList m_techPositions;
  75. AsciiString m_fileName;
  76. };
  77. class MapCache : public std::map<AsciiString, MapMetaData>
  78. {
  79. public:
  80. MapCache() {}
  81. void updateCache( void );
  82. AsciiString getMapDir() const;
  83. AsciiString getUserMapDir() const;
  84. AsciiString getMapExtension() const;
  85. const MapMetaData *findMap(AsciiString mapName);
  86. // allow us to create a set of shippable maps to be in mapcache.ini. For use with -buildMapCache.
  87. void addShippingMap(AsciiString mapName) { mapName.toLower(); m_allowedMaps.insert(mapName); }
  88. private:
  89. Bool clearUnseenMaps( AsciiString dirName );
  90. void loadStandardMaps(void);
  91. Bool loadUserMaps(void); // returns true if we needed to (re)parse a map
  92. // Bool addMap( AsciiString dirName, AsciiString fname, WinTimeStamp timestamp,
  93. // UnsignedInt filesize, Bool isOfficial ); ///< returns true if it had to (re)parse the map
  94. Bool addMap( AsciiString dirName, AsciiString fname, FileInfo *fileInfo, Bool isOfficial); ///< returns true if it had to (re)parse the map
  95. void writeCacheINI( Bool userDir );
  96. static const char * m_mapCacheName;
  97. std::map<AsciiString, Bool> m_seen;
  98. std::set<AsciiString> m_allowedMaps;
  99. };
  100. extern MapCache *TheMapCache;
  101. extern TechAndSupplyImages TheSupplyAndTechImageLocations;
  102. 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
  103. 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
  104. Bool isValidMap( AsciiString mapName, Bool isMultiplayer ); /// Validate a map
  105. Image *getMapPreviewImage( AsciiString mapName );
  106. AsciiString getDefaultMap( Bool isMultiplayer ); /// Find a valid map
  107. Bool parseMapPreviewChunk(DataChunkInput &file, DataChunkInfo *info, void *userData);
  108. void findDrawPositions( Int startX, Int startY, Int width, Int height, Region3D extent,
  109. ICoord2D *ul, ICoord2D *lr );
  110. Bool WouldMapTransfer( const AsciiString& mapName );
  111. #endif // __MAPUTIL_H__