mapHandler.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef MAPHANDLER_H
  2. #define MAPHANDLER_H
  3. #include "global.h"
  4. #include <SDL.h>
  5. #include <list>
  6. #include <set>
  7. const int Woff = 12; //width of map's frame
  8. const int Hoff = 8;
  9. class CGObjectInstance;
  10. class CGHeroInstance;
  11. struct Mapa;
  12. class CGDefInfo;
  13. class CGObjectInstance;
  14. class CDefHandler;
  15. struct TerrainTile;
  16. struct TerrainTile2
  17. {
  18. int3 pos;
  19. const TerrainTile *tileInfo;
  20. std::vector<SDL_Surface *> terbitmap; //frames of terrain animation
  21. std::vector<SDL_Surface *> rivbitmap; //frames of river animation
  22. std::vector<SDL_Surface *> roadbitmap; //frames of road animation
  23. 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
  24. };
  25. //pathfinder
  26. // map<int,int> iDTerenu=>koszt_pola
  27. // map<int,int> IDdrogi=>koszt_drogi
  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 offset, const T& fill)
  35. {
  36. inver.resize(Offset*2+rest);
  37. offset=Offset;
  38. for(int i=0; i<offset;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()+offset;i++)
  43. inver[offset+i] = fill;
  44. }
  45. inline T & operator[](int n)
  46. {
  47. return inver[n+offset];
  48. }
  49. void resize(int rest,int Offset)
  50. {
  51. inver.resize(Offset*2+rest);
  52. offset=Offset;
  53. }
  54. int size() const
  55. {
  56. return inver.size();
  57. }
  58. };
  59. class CMapHandler
  60. {
  61. public:
  62. PseudoV< PseudoV< PseudoV<TerrainTile2> > > ttiles;
  63. int3 sizes;
  64. Mapa * map;
  65. std::set<int> usedHeroes;
  66. CDefHandler * fullHide;
  67. CDefHandler * partialHide;
  68. std::vector<CDefHandler *> roadDefs;
  69. std::vector<CDefHandler *> staticRiverDefs;
  70. std::vector<CDefHandler*> defs;
  71. std::map<std::string, CDefHandler*> loadedDefs; //pointers to loaded defs (key is filename, uppercase)
  72. std::vector<std::vector<std::vector<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile
  73. void loadDefs();
  74. SDL_Surface * getVisBitmap(int x, int y, std::vector< std::vector< std::vector<unsigned char> > > & visibilityMap, int lvl);
  75. int getCost(int3 & a, int3 & b, const CGHeroInstance * hero);
  76. std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position
  77. //std::vector< CGObjectInstance * > getVisitableObjs(int3 pos); //returns vector of visitable objects at certain position
  78. CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid
  79. std::string getDefName(int id, int subid); //returns name of def for object with given id and subid
  80. bool printObject(CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map
  81. bool hideObject(CGObjectInstance * obj); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist)
  82. bool removeObject(CGObjectInstance * obj); //removes object from each place in VCMI (I hope)
  83. bool recalculateHideVisPos(int3& pos); //recalculates position for hidden / visitable positions
  84. bool recalculateHideVisPosUnderObj(CGObjectInstance * obj, bool withBorder = false); //recalculates position for hidden / visitable positions under given object
  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