mapHandler.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #ifndef MAPHANDLER_H
  2. #define MAPHANDLER_H
  3. #include "hch/CAmbarCendamo.h"
  4. #include "CGameInfo.h"
  5. #include "hch/CDefHandler.h"
  6. #include <boost/logic/tribool.hpp>
  7. #include "hch/CObjectHandler.h"
  8. #include <list>
  9. const int Woff = 12; //width of map's frame
  10. const int Hoff = 8;
  11. struct TerrainTile2
  12. {
  13. int3 pos; //this tile's position
  14. EterrainType terType; //type of terrain tile
  15. Eroad malle; //type of road
  16. unsigned char roaddir; //type of road tile
  17. Eriver nuine; //type of river
  18. unsigned char rivdir; //type of river tile
  19. std::vector<SDL_Surface *> terbitmap; //frames of terrain animation
  20. std::vector<SDL_Surface *> rivbitmap; //frames of river animation
  21. std::vector<SDL_Surface *> roadbitmap; //frames of road animation
  22. bool visitable; //false = not visitable; true = visitable
  23. bool blocked; //false = free; true = blocked;
  24. std::vector < std::pair<CGObjectInstance*,SDL_Rect> > objects; //poiters to objects being on this tile with rects to be easier to blit this tile on screen
  25. std::vector <CGObjectInstance*> visitableObjects; //pointers to objects hero is visiting being on this tile
  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 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[](int n)
  48. {
  49. return inver[n+offset];
  50. }
  51. void resize(int rest,int Offset)
  52. {
  53. inver.resize(Offset*2+rest);
  54. offset=Offset;
  55. }
  56. int size() const
  57. {
  58. return inver.size();
  59. }
  60. };
  61. class CMapHandler
  62. {
  63. public:
  64. PseudoV< PseudoV< PseudoV<TerrainTile2> > > ttiles;
  65. int3 sizes;
  66. Mapa * map;
  67. std::set<int> usedHeroes;
  68. CDefHandler * fullHide;
  69. CDefHandler * partialHide;
  70. std::vector< std::vector< std::vector<unsigned char> > > visibility; //true means that pointed place is visible //not used now
  71. //std::vector< std::vector<char> > undVisibility; //true means that pointed place is visible
  72. std::vector<CDefHandler *> roadDefs;
  73. std::vector<CDefHandler *> staticRiverDefs;
  74. std::vector<CDefHandler*> defs;
  75. std::map<std::string, CDefHandler*> loadedDefs; //pointers to loaded defs (key is filename, uppercase)
  76. std::vector< std::vector< std::string > > battleBacks; //battleBacks[terType] - vector of possible names for certain terrain type
  77. std::vector< std::string > battleHeroes; //battleHeroes[hero type] - name of def that has hero animation for battle
  78. std::vector<std::vector<std::vector<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile
  79. void loadDefs();
  80. char & visAccess(int x, int y);
  81. char & undVisAccess(int x, int y);
  82. SDL_Surface mirrorImage(SDL_Surface *src); //what is this??
  83. SDL_Surface * getVisBitmap(int x, int y, std::vector< std::vector< std::vector<unsigned char> > > & visibilityMap, int lvl);
  84. int getCost(int3 & a, int3 & b, const CGHeroInstance * hero);
  85. std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position
  86. std::vector< CGObjectInstance * > getVisitableObjs(int3 pos); //returns vector of visitable objects at certain position
  87. CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid
  88. std::string getDefName(int id, int subid); //returns name of def for object with given id and subid
  89. bool printObject(CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map
  90. bool hideObject(CGObjectInstance * obj); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist)
  91. bool removeObject(CGObjectInstance * obj); //removes object from each place in VCMI (I hope)
  92. bool recalculateHideVisPos(int3& pos); //recalculates position for hidden / visitable positions
  93. bool recalculateHideVisPosUnderObj(CGObjectInstance * obj, bool withBorder = false); //recalculates position for hidden / visitable positions under given object
  94. void init();
  95. int pickHero(int owner);
  96. std::pair<int,int> pickObject(CGObjectInstance *obj);
  97. void randomizeObject(CGObjectInstance *cur);
  98. void calculateBlockedPos();
  99. void initObjectRects();
  100. void borderAndTerrainBitmapInit();
  101. void roadsRiverTerrainInit();
  102. void prepareFOWDefs();
  103. void randomizeObjects();
  104. 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 = CGI->mh->visibility, bool otherHeroAnim = false, unsigned char heroAnim = 0, SDL_Surface * extSurf = NULL, SDL_Rect * extRect = NULL); //if extSurf is specified, blit to it
  105. SDL_Surface * terrBitmap(int x, int y);
  106. SDL_Surface * undTerrBitmap(int x, int y);
  107. std::string getRandomizedDefName(CGDefInfo* di, CGObjectInstance * obj = NULL); //objinstance needed only for heroes and towns
  108. unsigned char getHeroFrameNum(const unsigned char & dir, const bool & isMoving) const; //terrainRect helper function
  109. void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper
  110. 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]
  111. };
  112. #endif //MAPHANDLER_H