mapHandler.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * mapHandler.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 "../gui/CIntObject.h"
  12. #include "../../lib/int3.h"
  13. #include "../../lib/spells/ViewSpellInt.h"
  14. #include "../../lib/Rect.h"
  15. #ifdef IN
  16. #undef IN
  17. #endif
  18. #ifdef OUT
  19. #undef OUT
  20. #endif
  21. VCMI_LIB_NAMESPACE_BEGIN
  22. class CGObjectInstance;
  23. class CGHeroInstance;
  24. class CGBoat;
  25. class CMap;
  26. struct TerrainTile;
  27. class PlayerColor;
  28. VCMI_LIB_NAMESPACE_END
  29. struct SDL_Surface;
  30. class CAnimation;
  31. class IImage;
  32. class CFadeAnimation;
  33. class CMapHandler;
  34. class IMapObjectObserver;
  35. enum class EWorldViewIcon
  36. {
  37. TOWN = 0,
  38. HERO,
  39. ARTIFACT,
  40. TELEPORT,
  41. GATE,
  42. MINE_WOOD,
  43. MINE_MERCURY,
  44. MINE_STONE,
  45. MINE_SULFUR,
  46. MINE_CRYSTAL,
  47. MINE_GEM,
  48. MINE_GOLD,
  49. RES_WOOD,
  50. RES_MERCURY,
  51. RES_STONE,
  52. RES_SULFUR,
  53. RES_CRYSTAL,
  54. RES_GEM,
  55. RES_GOLD,
  56. };
  57. enum class EMapObjectFadingType
  58. {
  59. NONE,
  60. IN,
  61. OUT
  62. };
  63. struct TerrainTileObject
  64. {
  65. const CGObjectInstance *obj;
  66. Rect rect;
  67. int fadeAnimKey;
  68. boost::optional<std::string> ambientSound;
  69. TerrainTileObject(const CGObjectInstance *obj_, Rect rect_, bool visitablePos = false);
  70. ~TerrainTileObject();
  71. };
  72. struct TerrainTile2
  73. {
  74. std::vector<TerrainTileObject> objects; //pointers to objects being on this tile with rects to be easier to blit this tile on screen
  75. };
  76. class CMapHandler
  77. {
  78. const CMap * map;
  79. std::vector<IMapObjectObserver *> observers;
  80. public:
  81. explicit CMapHandler(const CMap * map);
  82. const CMap * getMap();
  83. /// returns true if tile is within map bounds
  84. bool isInMap(const int3 & tile);
  85. /// see MapObjectObserver interface
  86. void onObjectFadeIn(const CGObjectInstance * obj);
  87. void onObjectFadeOut(const CGObjectInstance * obj);
  88. void onObjectInstantAdd(const CGObjectInstance * obj);
  89. void onObjectInstantRemove(const CGObjectInstance * obj);
  90. void onHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest);
  91. void onHeroMoved(const CGHeroInstance * obj, const int3 & from, const int3 & dest);
  92. void onHeroRotated(const CGHeroInstance * obj, const int3 & from, const int3 & dest);
  93. /// Add object to receive notifications on any changes in visible map state
  94. void addMapObserver(IMapObjectObserver * observer);
  95. void removeMapObserver(IMapObjectObserver * observer);
  96. /// returns string description for terrain interaction
  97. void getTerrainDescr(const int3 & pos, std::string & out, bool isRMB) const;
  98. /// returns list of ambient sounds for specified tile
  99. std::vector<std::string> getAmbientSounds(const int3 & tile);
  100. /// returns true if tile has hole from grail digging attempt
  101. bool hasObjectHole(const int3 & pos) const;
  102. /// determines if the map is ready to handle new hero movement (not available during fading animations)
  103. bool hasActiveAnimations();
  104. static bool compareObjectBlitOrder(const CGObjectInstance * a, const CGObjectInstance * b);
  105. };