mapHandler.h 4.1 KB

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