MapReaderH3M.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * MapReaderH3M.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../GameConstants.h"
  12. #include "../ResourceSet.h"
  13. #include "MapFeaturesH3M.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class CBinaryReader;
  16. class CInputStream;
  17. struct MapFormatFeaturesH3M;
  18. class int3;
  19. enum class EMapFormat : uint8_t;
  20. class MapReaderH3M
  21. {
  22. public:
  23. explicit MapReaderH3M(CInputStream * stream);
  24. void setFormatLevel(EMapFormat format, uint8_t hotaVersion);
  25. ArtifactID readArtifact();
  26. ArtifactID readArtifact32();
  27. CreatureID readCreature();
  28. HeroTypeID readHero();
  29. TerrainId readTerrain();
  30. RoadId readRoad();
  31. RiverId readRiver();
  32. SecondarySkill readSkill();
  33. SpellID readSpell();
  34. SpellID readSpell32();
  35. PlayerColor readPlayer();
  36. PlayerColor readPlayer32();
  37. template<class Identifier>
  38. void readBitmask(std::set<Identifier> & dest, int bytesToRead, int objectsToRead, bool invert)
  39. {
  40. std::vector<bool> bitmap;
  41. bitmap.resize(objectsToRead, false);
  42. readBitmask(bitmap, bytesToRead, objectsToRead, invert);
  43. for(int i = 0; i < bitmap.size(); i++)
  44. if(bitmap[i])
  45. dest.insert(static_cast<Identifier>(i));
  46. }
  47. /** Reads bitmask to boolean vector
  48. * @param dest destination vector, shall be filed with "true" values
  49. * @param byteCount size in bytes of bimask
  50. * @param limit max count of vector elements to alter
  51. * @param negate if true then set bit in mask means clear flag in vertor
  52. */
  53. void readBitmask(std::vector<bool> & dest, int bytesToRead, int objectsToRead, bool invert);
  54. /**
  55. * Helper to read map position
  56. */
  57. int3 readInt3();
  58. void skipUnused(size_t amount);
  59. void skipZero(size_t amount);
  60. void readResourses(TResources & resources);
  61. bool readBool();
  62. ui8 readUInt8();
  63. si8 readInt8();
  64. ui16 readUInt16();
  65. si16 readInt16();
  66. ui32 readUInt32();
  67. si32 readInt32();
  68. std::string readBaseString();
  69. CBinaryReader & getInternalReader();
  70. private:
  71. MapFormatFeaturesH3M features;
  72. std::unique_ptr<CBinaryReader> reader;
  73. };
  74. VCMI_LIB_NAMESPACE_END