9
3

map.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. EQEMu: Everquest Server Emulator
  3. Copyright (C) 2001-2014 EQEMu Development Team (http://eqemulator.net)
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; version 2 of the License.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY except by those people which sell it, which
  9. are required to give you total support for your newly bought product;
  10. without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. */
  16. #ifndef ZONE_MAP_H
  17. #define ZONE_MAP_H
  18. #include "../../common/types.h"
  19. #include "../../common/MiscFunctions.h"
  20. #include "../../common/Mutex.h"
  21. #include "position.h"
  22. #include <stdio.h>
  23. #define BEST_Z_INVALID -99999
  24. struct GridMapBorder {
  25. float m_MinX;
  26. float m_MaxX;
  27. float m_MinY;
  28. float m_MaxY;
  29. float m_MinZ;
  30. float m_MaxZ;
  31. };
  32. class Map
  33. {
  34. public:
  35. Map(string zonename, string filename);
  36. ~Map();
  37. float FindBestZ(glm::vec3 &start, glm::vec3 *result, std::map<int32, bool>* ignored_widgets, uint32 *GridID = 0, uint32* WidgetID = 0);
  38. float FindClosestZ(glm::vec3 &start, glm::vec3 *result, std::map<int32, bool>* ignored_widgets, uint32 *GridID = 0, uint32* WidgetID = 0);
  39. bool LineIntersectsZone(glm::vec3 start, glm::vec3 end, float step, std::map<int32, bool>* ignored_widgets, glm::vec3 *result);
  40. bool LineIntersectsZoneNoZLeaps(glm::vec3 start, glm::vec3 end, float step_mag, std::map<int32, bool>* ignored_widgets, glm::vec3 *result);
  41. bool CheckLoS(glm::vec3 myloc, glm::vec3 oloc, std::map<int32, bool>* ignored_widgets);
  42. bool DoCollisionCheck(glm::vec3 myloc, glm::vec3 oloc, std::map<int32, bool>* ignored_widgets, glm::vec3 &outnorm, float &distance);
  43. bool Load(const std::string& filename);
  44. static Map *LoadMapFile(std::string zonename, std::string file);
  45. std::string GetFileName() { return m_ZoneFile; }
  46. void SetMapLoaded(bool val) {
  47. CheckMapMutex.writelock();
  48. mapLoaded = val;
  49. CheckMapMutex.releasewritelock();
  50. }
  51. bool IsMapLoaded() {
  52. bool isMapLoaded = false;
  53. CheckMapMutex.readlock();
  54. isMapLoaded = mapLoaded;
  55. CheckMapMutex.releasereadlock();
  56. return isMapLoaded;
  57. }
  58. void SetMapLoading(bool val) {
  59. CheckMapMutex.writelock();
  60. mapLoading = val;
  61. CheckMapMutex.releasewritelock();
  62. }
  63. bool IsMapLoading() {
  64. bool isMapLoading = false;
  65. CheckMapMutex.readlock();
  66. isMapLoading = mapLoading;
  67. CheckMapMutex.releasereadlock();
  68. return isMapLoading;
  69. }
  70. float GetMinX() { return m_MinX; }
  71. float GetMaxX() { return m_MaxX; }
  72. float GetMinY() { return m_MinY; }
  73. float GetMaxY() { return m_MaxY; }
  74. float GetMinZ() { return m_MinZ; }
  75. float GetMaxZ() { return m_MaxZ; }
  76. bool isPointWithinMap(double x, double y, double z, double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
  77. return (x >= m_MinX && x <= m_MaxX && y >= m_MinY && y <= m_MaxY && z >= m_MinZ && z <= m_MaxZ);
  78. }
  79. void SetFileName(std::string newfile) { m_FileName = string(newfile); }
  80. void MapMinMaxY(float y);
  81. void MapGridMinMaxBorderArray(GridMapBorder* border, glm::vec3 a, glm::vec3 b, glm::vec3 c);
  82. void MapGridMinMaxBorder(GridMapBorder* border, glm::vec3 a);
  83. bool IsPointInGrid(GridMapBorder* border, glm::vec3 a, float radius);
  84. std::vector<int32> GetGridsByPoint(glm::vec3 a, float radius);
  85. GridMapBorder* GetMapGridBorder(int32 grid_id, bool instantiate_border = true);
  86. std::map<int32, glm::vec3> widget_map;
  87. std::map<int32, GridMapBorder*> grid_map_border;
  88. private:
  89. void RotateVertex(glm::vec3 &v, float rx, float ry, float rz);
  90. void ScaleVertex(glm::vec3 &v, float sx, float sy, float sz);
  91. void TranslateVertex(glm::vec3 &v, float tx, float ty, float tz);
  92. bool LoadV2(FILE *f);
  93. bool LoadV2Deflated(FILE *f);
  94. bool LoadV3Deflated(std::ifstream* file, std::streambuf * const srcbuf);
  95. string m_FileName;
  96. string m_ZoneFile;
  97. string m_ZoneName;
  98. int32 m_CellSize;
  99. float m_MinX;
  100. float m_MinY;
  101. float m_MinZ;
  102. float m_MaxX;
  103. float m_MaxY;
  104. float m_MaxZ;
  105. struct impl;
  106. impl *imp;
  107. bool mapLoaded;
  108. bool mapLoading;
  109. Mutex CheckMapMutex;
  110. };
  111. class MapRange {
  112. public:
  113. MapRange();
  114. ~MapRange();
  115. void Clear();
  116. void AddVersionRange(std::string zoneName);
  117. map<VersionRange*, Map*>::iterator FindVersionRange(int32 min_version, int32 max_version);
  118. map<VersionRange*, Map*>::iterator FindMapByVersion(int32 version);
  119. map<VersionRange*, Map*>::iterator GetRangeEnd() { return version_map.end(); }
  120. private:
  121. std::map<VersionRange*, Map*> version_map;
  122. string name;
  123. };
  124. #endif