/// <summary> /// These nodes get used over and over again, so we need to make sure they /// get completely reset between uses. /// </summary> public void Reset() { mTile = null; mPrev = null; mCostFromStart = 0; mCostToEnd = 0; mReached = false; mPathSolved = false; }
/// <summary> /// Clear out the destination that the planner is trying to reach. This doubles as a way /// to stop the planner from trying to advance. /// </summary> public void ClearDestination() { mDestinationTile = null; mSolved = false; // Release the Nodes. We don't need them anymore. If a new destination // is set, we will need to start from scratch anyway. ClearNodeLists(); }
/// <summary> /// Update where this Planner is travelling from. The position is used to look up a tile at that /// position in the world. /// </summary> /// <param name="source">The position in the world that the planner will start at.</param> public void SetSource(Vector2 source) { // Grab the tile at the source position. mGetTileAtPositionMsg.mPosition_In = source; World.WorldManager.pInstance.pCurrentLevel.OnMessage(mGetTileAtPositionMsg); // We only care if they moved enough to make it onto a new tile. if (mSourceTile != mGetTileAtPositionMsg.mTile_Out) { // Update the source incase the GO has moved since the last update. mSource = source; // Update the source tile with the tile the GO has moved to. mSourceTile = mGetTileAtPositionMsg.mTile_Out; // Let the algorithm know that it needs to recalculate. // TODO: With only moving one tile at a time, could this be optimized to // check if this tile is already in the path, or append it to the start // of the path? mPathInvalidated = true; // Since the source has changed, this path can no longer be considered solved. mSolved = false; } }
/// <summary> /// Update the location that the Planner is attempting to reach. The position will be used /// to look up the tile at that position in the world. /// </summary> /// <param name="destination"></param> public void SetDestination(Vector2 destination) { mGetTileAtPositionMsg.mPosition_In = destination; World.WorldManager.pInstance.pCurrentLevel.OnMessage(mGetTileAtPositionMsg); if (mDestinationTile != mGetTileAtPositionMsg.mTile_Out) { mDestination = destination; mPathInvalidated = true; mSolved = false; // We will need to do a couple checks to see if we have found the destination tile, so cache that // now. mDestinationTile = mGetTileAtPositionMsg.mTile_Out; } }
/// <summary> /// Put the Node back into a default state. /// </summary> public override void Reset() { mTile = null; base.Reset(); }
/// <summary> /// Constructor. /// </summary> /// <param name="tile">The Tile at this Node's location in the world.</param> public TileGraphNode(Level.Tile tile) : base() { mTile = tile; }