mapHandler.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef MAPHANDLER_H
  2. #define MAPHANDLER_H
  3. #include "hch\CAmbarCendamo.h"
  4. #include "hch\CSemiDefHandler.h"
  5. #include "CGameInfo.h"
  6. #include "hch\CDefHandler.h"
  7. #include <boost/logic/tribool.hpp>
  8. #include "hch\CObjectHandler.h"
  9. #include <list>
  10. const int Woff = 12; //width of map's frame
  11. const int Hoff = 8;
  12. struct TerrainTile2
  13. {
  14. int3 pos; //this tile's position
  15. EterrainType terType; //type of terrain tile
  16. Eroad malle; //type of road
  17. unsigned char roaddir; //type of road tile
  18. Eriver nuine; //type of river
  19. unsigned char rivdir; //type of river tile
  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. bool visitable; //false = not visitable; true = visitable
  24. bool blocked; //false = free; true = blocked;
  25. 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
  26. std::vector <CGObjectInstance*> visitableObjects; //pointers to objects hero is visiting being on this tile
  27. };
  28. //pathfinder
  29. // map<int,int> iDTerenu=>koszt_pola
  30. // map<int,int> IDdrogi=>koszt_drogi
  31. template <typename T> class PseudoV
  32. {
  33. public:
  34. int offset;
  35. std::vector<T> inver;
  36. inline T & operator[](int n)
  37. {
  38. return inver[n+offset];
  39. }
  40. void resize(int rest,int Offset)
  41. {
  42. inver.resize(Offset*2+rest);
  43. offset=Offset;
  44. }
  45. int size() const
  46. {
  47. return inver.size();
  48. }
  49. };
  50. class CMapHandler
  51. {
  52. public:
  53. PseudoV< PseudoV< PseudoV<TerrainTile2> > > ttiles;
  54. int3 sizes;
  55. CAmbarCendamo * reader;
  56. std::set<int> usedHeroes;
  57. CDefHandler * fullHide;
  58. CDefHandler * partialHide;
  59. PseudoV< PseudoV< PseudoV<unsigned char> > > visibility; //true means that pointed place is visible //not used now
  60. //std::vector< std::vector<char> > undVisibility; //true means that pointed place is visible
  61. std::vector<CDefHandler *> roadDefs;
  62. std::vector<CDefHandler *> staticRiverDefs;
  63. std::map<std::string, CDefHandler*> loadedDefs; //pointers to loaded defs (key is filename, uppercase)
  64. std::map<int, CGDefInfo*> villages, forts, capitols;
  65. PseudoV< PseudoV< PseudoV<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile
  66. char & visAccess(int x, int y);
  67. char & undVisAccess(int x, int y);
  68. SDL_Surface mirrorImage(SDL_Surface *src); //what is this??
  69. SDL_Surface * getVisBitmap(int x, int y, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap, int lvl);
  70. int getCost(int3 & a, int3 & b, const CGHeroInstance * hero);
  71. std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position
  72. std::vector< CGObjectInstance * > getVisitableObjs(int3 pos); //returns vector of visitable objects at certain position
  73. CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid
  74. std::string getDefName(int id, int subid); //returns name of def for object with given id and subid
  75. bool printObject(CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map
  76. bool hideObject(CGObjectInstance * obj); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist)
  77. bool removeObject(CGObjectInstance * obj); //removes object from each place in VCMI (I hope)
  78. bool recalculateHideVisPos(int3& pos); //recalculates position for hidden / visitable positions
  79. bool recalculateHideVisPosUnderObj(CGObjectInstance * obj, bool withBorder = false); //recalculates position for hidden / visitable positions under given object
  80. void init();
  81. int pickHero(int owner);
  82. std::pair<int,int> pickObject(CGObjectInstance *obj);
  83. void randomizeObject(CGObjectInstance *cur);
  84. void calculateBlockedPos();
  85. void initObjectRects();
  86. void borderAndTerrainBitmapInit();
  87. void roadsRiverTerrainInit();
  88. void prepareFOWDefs();
  89. void randomizeObjects();
  90. SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, PseudoV< PseudoV< PseudoV<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
  91. SDL_Surface * terrBitmap(int x, int y);
  92. SDL_Surface * undTerrBitmap(int x, int y);
  93. std::string getRandomizedDefName(CGDefInfo* di, CGObjectInstance * obj = NULL); //objinstance needed only for heroes and towns
  94. unsigned char getHeroFrameNum(const unsigned char & dir, const bool & isMoving) const; //terrainRect helper function
  95. void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper
  96. 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]
  97. };
  98. #endif //MAPHANDLER_H