/* This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package com.festina.gameserver.pathfinding;

/**
 *
 * @author -Nemesiss-
 */
public class Node
{	
	private final AbstractNodeLoc _Loc;	
	private final int _Neighbors_idx;
	private Node[] _Neighbors;
	private Node _Parent;
	private short _Cost;
	
	
	public Node(AbstractNodeLoc Loc, int Neighbors_idx)
	{
		_Loc = Loc;
		_Neighbors_idx = Neighbors_idx;
	}

	public void setParent(Node p)
	{
		_Parent = p;
	}
	
	public void setCost(int cost)
	{
		_Cost = (short)cost;
	}
	
	public void attacheNeighbors()
	{
		if(_Loc == null) _Neighbors = null;
		else _Neighbors = PathFinding.getInstance().ReadNeighbors(_Loc.getNodeX(),_Loc.getNodeY(), _Neighbors_idx);
	}

	public Node[] getNeighbors()
	{
		return _Neighbors;
	}

	public Node getParent()
	{
		return _Parent;
	}

	public AbstractNodeLoc getLoc()
	{
		return _Loc;
	}
	
	public short getCost()
	{
		return _Cost;
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object arg0)
	{
		if(!(arg0 instanceof Node))
			return false;
		Node n = (Node)arg0;
		//Check if x,y,z are the same
		return _Loc.getX() == n.getLoc().getX() && _Loc.getY() == n.getLoc().getY()
		&& _Loc.getZ() == n.getLoc().getZ();
	}
}
