mapHandler.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. inline T & operator[](int n)
  36. {
  37. return inver[n+offset];
  38. }
  39. void resize(int rest,int Offset)
  40. {
  41. inver.resize(Offset*2+rest);
  42. offset=Offset;
  43. }
  44. int size() const
  45. {
  46. return inver.size();
  47. }
  48. };
  49. class CMapHandler
  50. {
  51. public:
  52. PseudoV< PseudoV< PseudoV<TerrainTile2> > > ttiles;
  53. int3 sizes;
  54. Mapa * map;
  55. std::set<int> usedHeroes;
  56. CDefHandler * fullHide;
  57. CDefHandler * partialHide;
  58. PseudoV< PseudoV< PseudoV<unsigned char> > > visibility; //true means that pointed place is visible //not used now
  59. //std::vector< std::vector<char> > undVisibility; //true means that pointed place is visible
  60. std::vector<CDefHandler *> roadDefs;
  61. std::vector<CDefHandler *> staticRiverDefs;
  62. std::vector<CDefHandler*> defs;
  63. std::map<std::string, CDefHandler*> loadedDefs; //pointers to loaded defs (key is filename, uppercase)
  64. std::map<int, CGDefInfo*> villages, forts, capitols;
  65. std::vector< std::vector< std::string > > battleBacks; //battleBacks[terType] - vector of possible names for certain terrain type
  66. std::vector< std::string > battleHeroes; //battleHeroes[hero type] - name of def that has hero animation for battle
  67. PseudoV< PseudoV< PseudoV<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile
  68. void loadDefs();
  69. char & visAccess(int x, int y);
  70. char & undVisAccess(int x, int y);
  71. SDL_Surface mirrorImage(SDL_Surface *src); //what is this??
  72. SDL_Surface * getVisBitmap(int x, int y, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap, int lvl);
  73. int getCost(int3 & a, int3 & b, const CGHeroInstance * hero);
  74. std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position
  75. std::vector< CGObjectInstance * > getVisitableObjs(int3 pos); //returns vector of visitable objects at certain position
  76. CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid
  77. std::string getDefName(int id, int subid); //returns name of def for object with given id and subid
  78. bool printObject(CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map
  79. bool hideObject(CGObjectInstance * obj); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist)
  80. bool removeObject(CGObjectInstance * obj); //removes object from each place in VCMI (I hope)
  81. bool recalculateHideVisPos(int3& pos); //recalculates position for hidden / visitable positions
  82. bool recalculateHideVisPosUnderObj(CGObjectInstance * obj, bool withBorder = false); //recalculates position for hidden / visitable positions under given object
  83. void init();
  84. int pickHero(int owner);
  85. std::pair<int,int> pickObject(CGObjectInstance *obj);
  86. void randomizeObject(CGObjectInstance *cur);
  87. void calculateBlockedPos();
  88. void initObjectRects();
  89. void borderAndTerrainBitmapInit();
  90. void roadsRiverTerrainInit();
  91. void prepareFOWDefs();
  92. void randomizeObjects();
  93. 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
  94. SDL_Surface * terrBitmap(int x, int y);
  95. SDL_Surface * undTerrBitmap(int x, int y);
  96. std::string getRandomizedDefName(CGDefInfo* di, CGObjectInstance * obj = NULL); //objinstance needed only for heroes and towns
  97. unsigned char getHeroFrameNum(const unsigned char & dir, const bool & isMoving) const; //terrainRect helper function
  98. void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper
  99. 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]
  100. };
  101. #endif //MAPHANDLER_H