region_map.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #ifndef EQ2EMU_REGION_MAP_H
  2. #define EQ2EMU_REGION_MAP_H
  3. #include "../../common/types.h"
  4. #include "../../common/MiscFunctions.h"
  5. #include "position.h"
  6. #include <string>
  7. class Client;
  8. class Spawn;
  9. class ZoneServer;
  10. class Region_Node;
  11. class ZBSP_Node;
  12. enum WaterRegionType : int {
  13. RegionTypeUnsupported = -2,
  14. RegionTypeUntagged = -1,
  15. RegionTypeNormal = 0,
  16. RegionTypeWater = 1,
  17. RegionTypeLava = 2,
  18. RegionTypeZoneLine = 3,
  19. RegionTypePVP = 4,
  20. RegionTypeSlime = 5,
  21. RegionTypeIce = 6,
  22. RegionTypeVWater = 7
  23. };
  24. enum WaterRegionClass : int32 {
  25. ClassWaterVolume = 0, // matching .region file type by name "watervol"
  26. ClassWaterRegion = 1, // matching .region file type by name "waterregion"
  27. ClassWaterRegion2 = 2, // represents .region file name "water_region" potentially defunct and just a WaterVolume (0)
  28. ClassWaterOcean = 3, // represents .region file with "ocean" and a select node as a parent
  29. ClassWaterCavern = 4, // represents .region file with matches on name "ocean" and "water"
  30. ClassWaterOcean2 = 5 // represents .region file with matches on name "ocean" without previous matches (no select node parent and no water string match)
  31. };
  32. class RegionMap
  33. {
  34. public:
  35. RegionMap() { }
  36. virtual ~RegionMap() { }
  37. static RegionMap* LoadRegionMapfile(std::string filename, std::string zone_name);
  38. virtual WaterRegionType ReturnRegionType(const glm::vec3& location, int32 gridid=0) const = 0;
  39. virtual bool InWater(const glm::vec3& location, int32 gridid=0) const = 0;
  40. virtual bool InLava(const glm::vec3& location, int32 gridid=0) const = 0;
  41. virtual bool InLiquid(const glm::vec3& location) const = 0;
  42. virtual bool InPvP(const glm::vec3& location) const = 0;
  43. virtual bool InZoneLine(const glm::vec3& location) const = 0;
  44. virtual void IdentifyRegionsInGrid(Client* client, const glm::vec3& location) const = 0;
  45. virtual void MapRegionsNearSpawn(Spawn* spawn, Client* client=0) const = 0;
  46. virtual void UpdateRegionsNearSpawn(Spawn* spawn, Client* client=0) const = 0;
  47. virtual void TicRegionsNearSpawn(Spawn* spawn, Client* client=0) const = 0;
  48. virtual void InsertRegionNode(ZoneServer* zone, int32 version, std::string regionName, std::string envName, uint32 gridID, uint32 triggerWidgetID, float dist = 0.0f) = 0;
  49. virtual void RemoveRegionNode(std::string regionName) = 0;
  50. protected:
  51. virtual bool Load(FILE *fp) { return false; }
  52. };
  53. class RegionMapRange {
  54. public:
  55. RegionMapRange()
  56. {
  57. }
  58. ~RegionMapRange()
  59. {
  60. map<VersionRange*, RegionMap*>::iterator itr;
  61. for (itr = version_map.begin(); itr != version_map.end(); itr++)
  62. {
  63. VersionRange* range = itr->first;
  64. RegionMap* map = itr->second;
  65. delete range;
  66. delete map;
  67. }
  68. version_map.clear();
  69. }
  70. void AddVersionRange(std::string zoneName);
  71. map<VersionRange*, RegionMap*>::iterator FindVersionRange(int32 min_version, int32 max_version)
  72. {
  73. map<VersionRange*, RegionMap*>::iterator itr;
  74. for (itr = version_map.begin(); itr != version_map.end(); itr++)
  75. {
  76. VersionRange* range = itr->first;
  77. // if min and max version are both in range
  78. if (range->GetMinVersion() <= min_version && max_version <= range->GetMaxVersion())
  79. return itr;
  80. // if the min version is in range, but max range is 0
  81. else if (range->GetMinVersion() <= min_version && range->GetMaxVersion() == 0)
  82. return itr;
  83. // if min version is 0 and max_version has a cap
  84. else if (range->GetMinVersion() == 0 && max_version <= range->GetMaxVersion())
  85. return itr;
  86. }
  87. return version_map.end();
  88. }
  89. map<VersionRange*, RegionMap*>::iterator FindRegionByVersion(int32 version)
  90. {
  91. map<VersionRange*, RegionMap*>::iterator enditr = version_map.end();
  92. map<VersionRange*, RegionMap*>::iterator itr;
  93. for (itr = version_map.begin(); itr != version_map.end(); itr++)
  94. {
  95. VersionRange* range = itr->first;
  96. // if min and max version are both in range
  97. if(range->GetMinVersion() == 0 && range->GetMaxVersion() == 0)
  98. enditr = itr;
  99. else if (version >= range->GetMinVersion() && version <= range->GetMaxVersion())
  100. return itr;
  101. }
  102. return enditr;
  103. }
  104. map<VersionRange*, RegionMap*>::iterator GetRangeEnd() { return version_map.end(); }
  105. private:
  106. std::map<VersionRange*, RegionMap*> version_map;
  107. string name;
  108. };
  109. #endif