mapHandler.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #pragma once
  2. #include "../lib/int3.h"
  3. /*
  4. * mapHandler.h, part of VCMI engine
  5. *
  6. * Authors: listed in file AUTHORS in main folder
  7. *
  8. * License: GNU General Public License v2.0 or later
  9. * Full text of license available in license.txt file, in main folder
  10. *
  11. */
  12. class CGObjectInstance;
  13. class CGHeroInstance;
  14. struct CMap;
  15. class CGDefInfo;
  16. class CGObjectInstance;
  17. class CDefHandler;
  18. struct TerrainTile;
  19. struct SDL_Surface;
  20. struct SDL_Rect;
  21. class CDefEssential;
  22. struct TerrainTile2
  23. {
  24. SDL_Surface * terbitmap; //bitmap of terrain
  25. std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > objects; //pointers to objects being on this tile with rects to be easier to blit this tile on screen
  26. TerrainTile2();
  27. };
  28. template <typename T> class PseudoV
  29. {
  30. public:
  31. int offset;
  32. std::vector<T> inver;
  33. PseudoV(){};
  34. PseudoV(std::vector<T> &src, int rest, int before, int after, const T& fill)
  35. {
  36. inver.resize(before + rest + after);
  37. offset=before;
  38. for(int i=0; i<before;i++)
  39. inver[i] = fill;
  40. for(int i=0;i<src.size();i++)
  41. inver[offset+i] = src[i];
  42. for(int i=src.size(); i<src.size()+after;i++)
  43. inver[offset+i] = fill;
  44. }
  45. inline T & operator[](const int & n)
  46. {
  47. return inver[n+offset];
  48. }
  49. inline const T & operator[](const int & n) const
  50. {
  51. return inver[n+offset];
  52. }
  53. void resize(int rest, int before, int after)
  54. {
  55. inver.resize(before + rest + after);
  56. offset=before;
  57. }
  58. int size() const
  59. {
  60. return inver.size();
  61. }
  62. };
  63. class CMapHandler
  64. {
  65. public:
  66. PseudoV< PseudoV< PseudoV<TerrainTile2> > > ttiles; //informations about map tiles
  67. int3 sizes; //map size (x = width, y = height, z = number of levels)
  68. const CMap * map;
  69. // Max number of tiles that will fit in the map screen. Tiles
  70. // can be partial on each edges.
  71. int tilesW;
  72. int tilesH;
  73. // size of each side of the frame around the whole map, in tiles
  74. int frameH;
  75. int frameW;
  76. // Coord in pixels of the top left corner of the top left tile to
  77. // draw. Values range is [-31..0]. A negative value
  78. // implies that part of the tile won't be displayed.
  79. int offsetX;
  80. int offsetY;
  81. //std::set<int> usedHeroes;
  82. std::vector<std::vector<SDL_Surface *> > terrainGraphics; // [terrain id] [view type] [rotation type]
  83. std::vector<CDefEssential *> roadDefs;
  84. std::vector<CDefEssential *> staticRiverDefs;
  85. std::vector<std::vector<std::vector<ui8> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile
  86. static const bool MARK_BLOCKED_POSITIONS;
  87. static const bool MARK_VISITABLE_POSITIONS;
  88. CMapHandler(); //c-tor
  89. ~CMapHandler(); //d-tor
  90. std::pair<SDL_Surface *, bool> getVisBitmap(const int3 & pos, const std::vector< std::vector< std::vector<ui8> > > & visibilityMap) const; //returns appropriate bitmap and info if alpha blitting is necessary
  91. std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position
  92. void getTerrainDescr(const int3 &pos, std::string & out, bool terName); //if tername == false => empty string when tile is clear
  93. CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid
  94. bool printObject(const CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map
  95. bool hideObject(const CGObjectInstance * obj); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist)
  96. bool removeObject(CGObjectInstance * obj); //removes object from each place in VCMI (I hope)
  97. void initHeroDef(const CGHeroInstance * h);
  98. void init();
  99. void calculateBlockedPos();
  100. void initObjectRects();
  101. void borderAndTerrainBitmapInit();
  102. void roadsRiverTerrainInit();
  103. void prepareFOWDefs();
  104. void terrainRect(int3 top_tile, ui8 anim, const std::vector< std::vector< std::vector<ui8> > > * visibilityMap, bool otherHeroAnim, ui8 heroAnim, SDL_Surface * extSurf, const SDL_Rect * extRect, int moveX, int moveY, bool puzzleMode, int3 grailPosRel) const;
  105. void updateWater();
  106. ui8 getHeroFrameNum(ui8 dir, bool isMoving) const; //terrainRect helper function
  107. void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper
  108. static ui8 getDir(const int3 & a, const int3 & b); //returns direction number in range 0 - 7 (0 is left top, clockwise) [direction: form a to b]
  109. };