MapReaderH3M.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. CreatureID readCreature();
  27. HeroTypeID readHero();
  28. TerrainId readTerrain();
  29. RoadId readRoad();
  30. RiverId readRiver();
  31. SecondarySkill readSkill();
  32. SpellID readSpell();
  33. SpellID readSpell32();
  34. PlayerColor readPlayer();
  35. PlayerColor readPlayer32();
  36. template<class Identifier>
  37. void readBitmask(std::set<Identifier> & dest, int bytesToRead, int objectsToRead, bool invert)
  38. {
  39. std::vector<bool> bitmap;
  40. bitmap.resize(objectsToRead, false);
  41. readBitmask(bitmap, bytesToRead, objectsToRead, invert);
  42. for(int i = 0; i < bitmap.size(); i++)
  43. if(bitmap[i])
  44. dest.insert(static_cast<Identifier>(i));
  45. }
  46. /** Reads bitmask to boolean vector
  47. * @param dest destination vector, shall be filed with "true" values
  48. * @param byteCount size in bytes of bimask
  49. * @param limit max count of vector elements to alter
  50. * @param negate if true then set bit in mask means clear flag in vertor
  51. */
  52. void readBitmask(std::vector<bool> & dest, int bytesToRead, int objectsToRead, bool invert);
  53. /**
  54. * Helper to read map position
  55. */
  56. int3 readInt3();
  57. void skipUnused(size_t amount);
  58. void skipZero(size_t amount);
  59. void readResourses(TResources & resources);
  60. bool readBool();
  61. ui8 readUInt8();
  62. si8 readInt8();
  63. ui16 readUInt16();
  64. si16 readInt16();
  65. ui32 readUInt32();
  66. si32 readInt32();
  67. std::string readBaseString();
  68. CBinaryReader & getInternalReader();
  69. private:
  70. MapFormatFeaturesH3M features;
  71. std::unique_ptr<CBinaryReader> reader;
  72. };
  73. VCMI_LIB_NAMESPACE_END