2
0

NodeLoc.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.pathfinding.cellnodes;
  16. import com.l2jserver.gameserver.GeoData;
  17. import com.l2jserver.gameserver.model.L2World;
  18. import com.l2jserver.gameserver.pathfinding.AbstractNodeLoc;
  19. /**
  20. * @author -Nemesiss-
  21. */
  22. public class NodeLoc extends AbstractNodeLoc
  23. {
  24. private int _x;
  25. private int _y;
  26. private short _geoHeightAndNSWE;
  27. public NodeLoc(int x, int y, short z)
  28. {
  29. _x = x;
  30. _y = y;
  31. _geoHeightAndNSWE = GeoData.getInstance().getHeightAndNSWE(x, y, z);
  32. }
  33. public void set(int x, int y, short z)
  34. {
  35. _x = x;
  36. _y = y;
  37. _geoHeightAndNSWE = GeoData.getInstance().getHeightAndNSWE(x, y, z);
  38. }
  39. public short getNSWE()
  40. {
  41. return (short) (_geoHeightAndNSWE & 0x0f);
  42. }
  43. /**
  44. * @see com.l2jserver.gameserver.pathfinding.AbstractNodeLoc#getX()
  45. */
  46. @Override
  47. public int getX()
  48. {
  49. return (_x << 4) + L2World.MAP_MIN_X;
  50. }
  51. /**
  52. * @see com.l2jserver.gameserver.pathfinding.AbstractNodeLoc#getY()
  53. */
  54. @Override
  55. public int getY()
  56. {
  57. return (_y << 4) + L2World.MAP_MIN_Y;
  58. }
  59. /**
  60. * @see com.l2jserver.gameserver.pathfinding.AbstractNodeLoc#getZ()
  61. */
  62. @Override
  63. public short getZ()
  64. {
  65. short height = (short) (_geoHeightAndNSWE & 0x0fff0);
  66. return (short) (height >> 1);
  67. }
  68. @Override
  69. public void setZ(short z)
  70. {
  71. //
  72. }
  73. /**
  74. * @see com.l2jserver.gameserver.pathfinding.AbstractNodeLoc#getNodeX()
  75. */
  76. @Override
  77. public int getNodeX()
  78. {
  79. return _x;
  80. }
  81. /**
  82. * @see com.l2jserver.gameserver.pathfinding.AbstractNodeLoc#getNodeY()
  83. */
  84. @Override
  85. public int getNodeY()
  86. {
  87. return _y;
  88. }
  89. /**
  90. * @see java.lang.Object#hashCode()
  91. */
  92. @Override
  93. public int hashCode()
  94. {
  95. final int prime = 31;
  96. int result = 1;
  97. result = (prime * result) + _x;
  98. result = (prime * result) + _y;
  99. result = (prime * result) + _geoHeightAndNSWE;
  100. return result;
  101. }
  102. /**
  103. * @see java.lang.Object#equals(java.lang.Object)
  104. */
  105. @Override
  106. public boolean equals(Object obj)
  107. {
  108. if (this == obj)
  109. {
  110. return true;
  111. }
  112. if (obj == null)
  113. {
  114. return false;
  115. }
  116. if (!(obj instanceof NodeLoc))
  117. {
  118. return false;
  119. }
  120. final NodeLoc other = (NodeLoc) obj;
  121. if (_x != other._x)
  122. {
  123. return false;
  124. }
  125. if (_y != other._y)
  126. {
  127. return false;
  128. }
  129. if (_geoHeightAndNSWE != other._geoHeightAndNSWE)
  130. {
  131. return false;
  132. }
  133. return true;
  134. }
  135. }