mapHandler.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. std::vector<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. };
  26. //pathfinder
  27. // map<int,int> iDTerenu=>koszt_pola
  28. // map<int,int> IDdrogi=>koszt_drogi
  29. template <typename T> class PseudoV
  30. {
  31. public:
  32. int offset;
  33. std::vector<T> inver;
  34. PseudoV(){};
  35. PseudoV(std::vector<T> &src, int rest, int Offset, const T& fill)
  36. {
  37. inver.resize(Offset*2+rest);
  38. offset=Offset;
  39. for(int i=0; i<offset;i++)
  40. inver[i] = fill;
  41. for(int i=0;i<src.size();i++)
  42. inver[offset+i] = src[i];
  43. for(int i=src.size(); i<src.size()+offset;i++)
  44. inver[offset+i] = fill;
  45. }
  46. inline T & operator[](int n)
  47. {
  48. return inver[n+offset];
  49. }
  50. void resize(int rest,int Offset)
  51. {
  52. inver.resize(Offset*2+rest);
  53. offset=Offset;
  54. }
  55. int size() const
  56. {
  57. return inver.size();
  58. }
  59. };
  60. class CMapHandler
  61. {
  62. public:
  63. PseudoV< PseudoV< PseudoV<TerrainTile2> > > ttiles;
  64. int3 sizes;
  65. Mapa * map;
  66. std::set<int> usedHeroes;
  67. CDefHandler * fullHide;
  68. CDefHandler * partialHide;
  69. std::vector<CDefHandler *> roadDefs;
  70. std::vector<CDefHandler *> staticRiverDefs;
  71. std::vector<CDefHandler*> defs;
  72. std::map<std::string, CDefHandler*> loadedDefs; //pointers to loaded defs (key is filename, uppercase)
  73. std::vector<std::vector<std::vector<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile
  74. void loadDefs();
  75. SDL_Surface * getVisBitmap(int x, int y, std::vector< std::vector< std::vector<unsigned char> > > & visibilityMap, int lvl);
  76. int getCost(int3 & a, int3 & b, const CGHeroInstance * hero);
  77. std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position
  78. //std::vector< CGObjectInstance * > getVisitableObjs(int3 pos); //returns vector of visitable objects at certain position
  79. CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid
  80. std::string getDefName(int id, int subid); //returns name of def for object with given id and subid
  81. bool printObject(const CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map
  82. bool hideObject(const CGObjectInstance * obj); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist)
  83. bool removeObject(CGObjectInstance * obj); //removes object from each place in VCMI (I hope)
  84. void initHeroDef(CGHeroInstance * h);
  85. void init();
  86. void calculateBlockedPos();
  87. void initObjectRects();
  88. void borderAndTerrainBitmapInit();
  89. void roadsRiverTerrainInit();
  90. void prepareFOWDefs();
  91. 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
  92. unsigned char getHeroFrameNum(const unsigned char & dir, const bool & isMoving) const; //terrainRect helper function
  93. void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper
  94. 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]
  95. };
  96. #endif //MAPHANDLER_H