mapHandler.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #ifndef __MAPHANDLER_H__
  2. #define __MAPHANDLER_H__
  3. #include "global.h"
  4. #include <list>
  5. #include <set>
  6. const int Woff = 14; //width of map's frame
  7. const int Hoff = 10;
  8. /*
  9. * mapHandler.h, part of VCMI engine
  10. *
  11. * Authors: listed in file AUTHORS in main folder
  12. *
  13. * License: GNU General Public License v2.0 or later
  14. * Full text of license available in license.txt file, in main folder
  15. *
  16. */
  17. class CGObjectInstance;
  18. class CGHeroInstance;
  19. struct Mapa;
  20. class CGDefInfo;
  21. class CGObjectInstance;
  22. class CDefHandler;
  23. struct TerrainTile;
  24. struct SDL_Surface;
  25. struct SDL_Rect;
  26. struct TerrainTile2
  27. {
  28. int3 pos;
  29. const TerrainTile *tileInfo;
  30. SDL_Surface * terbitmap; //frames of terrain animation
  31. std::vector<SDL_Surface *> rivbitmap; //frames of river animation
  32. std::vector<SDL_Surface *> roadbitmap; //frames of road animation
  33. std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > objects; //poiters to objects being on this tile with rects to be easier to blit this tile on screen
  34. TerrainTile2();
  35. };
  36. //pathfinder
  37. // map<int,int> iDTerenu=>koszt_pola
  38. // map<int,int> IDdrogi=>koszt_drogi
  39. template <typename T> class PseudoV
  40. {
  41. public:
  42. int offset;
  43. std::vector<T> inver;
  44. PseudoV(){};
  45. PseudoV(std::vector<T> &src, int rest, int Offset, const T& fill)
  46. {
  47. inver.resize(Offset*2+rest);
  48. offset=Offset;
  49. for(int i=0; i<offset;i++)
  50. inver[i] = fill;
  51. for(int i=0;i<src.size();i++)
  52. inver[offset+i] = src[i];
  53. for(int i=src.size(); i<src.size()+offset;i++)
  54. inver[offset+i] = fill;
  55. }
  56. inline T & operator[](const int & n)
  57. {
  58. return inver[n+offset];
  59. }
  60. inline const T & operator[](const int & n) const
  61. {
  62. return inver[n+offset];
  63. }
  64. void resize(int rest,int Offset)
  65. {
  66. inver.resize(Offset*2+rest);
  67. offset=Offset;
  68. }
  69. int size() const
  70. {
  71. return inver.size();
  72. }
  73. };
  74. class CMapHandler
  75. {
  76. public:
  77. PseudoV< PseudoV< PseudoV<TerrainTile2> > > ttiles; //informations about map tiles
  78. int3 sizes; //map size (x - width, y - height, z - number of levels)
  79. Mapa * map;
  80. std::set<int> usedHeroes;
  81. CDefHandler * fullHide; //for Fog of War
  82. CDefHandler * partialHide; //for For of War
  83. std::vector<std::vector<SDL_Surface *> > terrainGraphics; // [terrain id] [view type] [rotation type]
  84. std::vector<CDefHandler *> roadDefs;
  85. std::vector<CDefHandler *> staticRiverDefs;
  86. std::vector<CDefHandler*> defs;
  87. std::map<std::string, CDefHandler*> loadedDefs; //pointers to loaded defs (key is filename, uppercase)
  88. std::vector<std::vector<std::vector<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile
  89. CMapHandler(); //c-tor
  90. ~CMapHandler(); //d-tor
  91. void loadDefs();
  92. SDL_Surface * getVisBitmap(int x, int y, const std::vector< std::vector< std::vector<unsigned char> > > & visibilityMap, int lvl);
  93. int getCost(int3 & a, int3 & b, const CGHeroInstance * hero);
  94. std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position
  95. //std::vector< CGObjectInstance * > getVisitableObjs(int3 pos); //returns vector of visitable objects at certain position
  96. CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid
  97. std::string getDefName(int id, int subid); //returns name of def for object with given id and subid
  98. bool printObject(const CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map
  99. bool hideObject(const CGObjectInstance * obj); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist)
  100. bool removeObject(CGObjectInstance * obj); //removes object from each place in VCMI (I hope)
  101. void initHeroDef(CGHeroInstance * h);
  102. void init();
  103. void calculateBlockedPos();
  104. void initObjectRects();
  105. void borderAndTerrainBitmapInit();
  106. void roadsRiverTerrainInit();
  107. void prepareFOWDefs();
  108. SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, std::vector< std::vector< std::vector<unsigned char> > > * visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect, int moveX, int moveY, bool smooth);
  109. void updateWater();
  110. unsigned char getHeroFrameNum(const unsigned char & dir, const bool & isMoving) const; //terrainRect helper function
  111. void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper
  112. static unsigned char getDir(const int3 & a, const int3 & b); //returns direction number in range 0 - 7 (0 is left top, clockwise) [direction: form a to b]
  113. };
  114. #endif // __MAPHANDLER_H__