9
3

region_map.h 3.8 KB

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