Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using Priority_Queue;
- using System.Collections.Generic;
- public class Waypoint : PriorityQueueNode
- {
- private Vector2 pt;
- public float x;
- public float y;
- public Waypoint next;
- public Waypoint prev;
- public float cost; // movement cost of this waypoint
- public float totalCost; // total movement cost to get to this waypoint from previous ones
- private List<Waypoint> Successors;
- // use this constructor if the waypoint has no previous or future (known) waypoints to go to yet
- public Waypoint(Vector2 point)
- {
- pt = point;
- x = point.x;
- y = point.y;
- next = null;
- prev = null;
- Successors = new List<Waypoint>();
- TileMath tm = TileMath.GetTileMath((int)x, (int)y);
- cost = tm.GetPathfindingHeuristic();
- totalCost = cost;
- }
- // use this constructor to record the waypoint as having a previous waypoint, next one, or both
- public Waypoint(Vector2 point, Waypoint child, Waypoint parent)
- {
- pt = point;
- x = point.x;
- y = point.y;
- next = child;
- prev = parent;
- Successors = new List<Waypoint>();
- TileMath tm = TileMath.GetTileMath((int)x, (int)y);
- cost = tm.GetPathfindingHeuristic();
- totalCost = cost;
- Waypoint temp = this.prev;
- while(temp != null)
- {
- TileMath currWP = TileMath.GetTileMath((int)temp.x, (int)temp.y);
- totalCost = totalCost + currWP.GetPathfindingHeuristic();
- temp = temp.prev;
- }
- }
- public Vector2 GetPoint()
- {
- return pt;
- }
- public List<Waypoint> GetSuccessors()
- {
- Successors.Clear();
- TileMath tm = TileMath.GetTileMath((int)x,(int)y);
- // check LEFT traversability, if it can be walked on, add it to the successor list
- TileMath left = tm.GetLeftNeighbor();
- if(left.GetIsHorizontallyTraversable())
- {
- Waypoint l = new Waypoint(new Vector2(left.GetX(), left.GetY()), null, this);
- Successors.Add(l);
- }
- // check RIGHT traversability, if it can be walked on, add it to the successor list
- TileMath right = tm.GetRightNeighbor();
- if(right.GetIsHorizontallyTraversable())
- {
- Waypoint r = new Waypoint(new Vector2(right.GetX(), right.GetY()), null, this);
- Successors.Add(r);
- }
- return Successors;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement