package pathgame.algorithm; import pathgame.tilemap.TileType; import java.util.ArrayList; /** Class for storing node data for the Dijkstra algorithm * */ public class Node2D { private int weight; private int costSoFar = Integer.MAX_VALUE; private char prevOfPath = '\0'; private int prevBoatPath = -1; private TileType type = TileType.LAND; private boolean isQAdded = false; private boolean hasExtraPaths = false; private boolean isBlocked = false; private boolean isTown = false; private ArrayList extraPaths = new ArrayList<>(); /** Create new Node2D with given weight * * @param weight cost it takes to travel to this node */ public Node2D(int weight) { this.weight = weight; } /** Returns the weight of the node * * @return the weight of the node */ public int getWeight() { return weight; } /** Returns the lowest total cost of travelling to this node from where the algorithm started * * @return lowest cost to get to this node */ public int getCostSoFar() { return costSoFar; } /** Sets the currently lowest total cost of travelling to this node from where the algorithm started * * @param costSoFar currently lowest cost to get to this node */ public void setCostSoFar(int costSoFar) { this.costSoFar = costSoFar; } /** Returns a character indicating the previous node of the shortest path from the algorithm's starting point to this node * * @return direction of previous node */ public char getPrevOfPath() { return prevOfPath; } /** Sets the character indicating the previous node of the shortest path from the algorithm's starting point to this node * * @param prevOfPath direction of previous node */ public void setPrevOfPath(char prevOfPath) { this.prevOfPath = prevOfPath; } /** Returns the list of all ExtraPaths of this node * * @return list of ExtraPaths */ public ArrayList getExtraPaths() { return extraPaths; } /** Creates an ExtraPath using the given parameters and adds it to the node * * @param dest coordinate of the destination of the path * @param pathWeight total weight to travel this path * @param pathCoords list of coordinates of the path */ public void addExtraPath(Coord dest, int pathWeight, ArrayList pathCoords) { hasExtraPaths = true; extraPaths.add(new ExtraPath(dest.getX(), dest.getY(), pathWeight, pathCoords)); } /** Returns hasExtraPaths, which is true, if this node has ExtraPaths * * @return whether node has ExtraPaths */ public boolean hasExtraPaths() { return hasExtraPaths; } /** Returns isQAdded, which is true, if the node has been added to the queue * * @return whether node has been added to the queue */ public boolean isQAdded() { return isQAdded; } /** Sets isQAdded, which is true, if the node has been added to the queue * * @param QAdded whether node has been added to the queue */ public void setQAdded(boolean QAdded) { isQAdded = QAdded; } /** Returns isBlocked, which is true, if this node can't be travelled to from adjacent nodes * * @return whether node is blocked from travel */ public boolean isBlocked() { return isBlocked; } /** Sets isBlocked, which is true, if this node can't be travelled to from adjacent nodes * * @param blocked whether node is blocked from travel */ public void setBlocked(boolean blocked) { isBlocked = blocked; } /** Returns the type of the Tile that is represented by this node * * @return the type of the tile */ public TileType getType() { return type; } /** Sets the type of the Tile that is represented by this node * * @param type the type of the tile */ public void setType(TileType type) { this.type = type; } /** Returns the index of the the previous ExtraPath * * @return the index of the the previous ExtraPath */ public int getPrevBoatPath() { return prevBoatPath; } /** Sets the index of the the previous ExtraPath * * @param prevBoatPath the index of the the previous ExtraPath */ public void setPrevBoatPath(int prevBoatPath) { this.prevBoatPath = prevBoatPath; } /** Returns isTown, which is true if the node is a town * * @return whether node is a town */ public boolean isTown() { return isTown; } /** Sets isTown, which is true if the node is a town * * @param town whether node is a town */ public void setTown(boolean town) { isTown = town; } }