Node.java 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 net.sf.l2j.gameserver.pathfinding;
  16. /**
  17. *
  18. * @author -Nemesiss-
  19. */
  20. public class Node
  21. {
  22. private final AbstractNodeLoc _loc;
  23. private final int _neighborsIdx;
  24. private Node[] _neighbors;
  25. private Node _parent;
  26. private short _cost;
  27. public Node(AbstractNodeLoc Loc, int Neighbors_idx)
  28. {
  29. _loc = Loc;
  30. _neighborsIdx = Neighbors_idx;
  31. }
  32. public void setParent(Node p)
  33. {
  34. _parent = p;
  35. }
  36. public void setCost(int cost)
  37. {
  38. _cost = (short)cost;
  39. }
  40. public void attachNeighbors()
  41. {
  42. if(_loc == null) _neighbors = null;
  43. else _neighbors = PathFinding.getInstance().readNeighbors(this, _neighborsIdx);
  44. }
  45. public Node[] getNeighbors()
  46. {
  47. return _neighbors;
  48. }
  49. public Node getParent()
  50. {
  51. return _parent;
  52. }
  53. public AbstractNodeLoc getLoc()
  54. {
  55. return _loc;
  56. }
  57. public short getCost()
  58. {
  59. return _cost;
  60. }
  61. /**
  62. * @see java.lang.Object#equals(java.lang.Object)
  63. */
  64. @Override
  65. public boolean equals(Object arg0)
  66. {
  67. if(!(arg0 instanceof Node))
  68. return false;
  69. Node n = (Node)arg0;
  70. return _loc.getX() == n.getLoc().getX() && _loc.getY() == n.getLoc().getY()
  71. && _loc.getZ() == n.getLoc().getZ();
  72. }
  73. }