NodeLoc.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. *
  21. * @author -Nemesiss-
  22. */
  23. public class NodeLoc extends AbstractNodeLoc
  24. {
  25. private int _x;
  26. private int _y;
  27. private short _geoHeightAndNSWE;
  28. public NodeLoc(int x, int y, short z)
  29. {
  30. _x = x;
  31. _y = y;
  32. _geoHeightAndNSWE = GeoData.getInstance().getHeightAndNSWE(x, y, z);
  33. }
  34. public void set(int x, int y, short z)
  35. {
  36. _x = x;
  37. _y = y;
  38. _geoHeightAndNSWE = GeoData.getInstance().getHeightAndNSWE(x, y, z);
  39. }
  40. public short getNSWE()
  41. {
  42. return (short)(_geoHeightAndNSWE & 0x0f);
  43. }
  44. /**
  45. * @see com.l2jserver.gameserver.pathfinding.AbstractNodeLoc#getX()
  46. */
  47. @Override
  48. public int getX()
  49. {
  50. return (_x << 4) + L2World.MAP_MIN_X;
  51. }
  52. /**
  53. * @see com.l2jserver.gameserver.pathfinding.AbstractNodeLoc#getY()
  54. */
  55. @Override
  56. public int getY()
  57. {
  58. return (_y << 4) + L2World.MAP_MIN_Y;
  59. }
  60. /**
  61. * @see com.l2jserver.gameserver.pathfinding.AbstractNodeLoc#getZ()
  62. */
  63. @Override
  64. public short getZ()
  65. {
  66. short height = (short)(_geoHeightAndNSWE & 0x0fff0);
  67. return (short)(height >> 1);
  68. }
  69. @Override
  70. public void setZ(short z)
  71. {
  72. //
  73. }
  74. /**
  75. * @see com.l2jserver.gameserver.pathfinding.AbstractNodeLoc#getNodeX()
  76. */
  77. @Override
  78. public int getNodeX()
  79. {
  80. return _x;
  81. }
  82. /**
  83. * @see com.l2jserver.gameserver.pathfinding.AbstractNodeLoc#getNodeY()
  84. */
  85. @Override
  86. public int getNodeY()
  87. {
  88. return _y;
  89. }
  90. /**
  91. * @see java.lang.Object#hashCode()
  92. */
  93. @Override
  94. public int hashCode()
  95. {
  96. final int prime = 31;
  97. int result = 1;
  98. result = prime * result + _x;
  99. result = prime * result + _y;
  100. result = prime * result + _geoHeightAndNSWE;
  101. return result;
  102. }
  103. /**
  104. * @see java.lang.Object#equals(java.lang.Object)
  105. */
  106. @Override
  107. public boolean equals(Object obj)
  108. {
  109. if (this == obj)
  110. return true;
  111. if (obj == null)
  112. return false;
  113. if (!(obj instanceof NodeLoc))
  114. return false;
  115. final NodeLoc other = (NodeLoc) obj;
  116. if (_x != other._x)
  117. return false;
  118. if (_y != other._y)
  119. return false;
  120. if (_geoHeightAndNSWE != other._geoHeightAndNSWE)
  121. return false;
  122. return true;
  123. }
  124. }