Beispiel #1
0
        /// <summary>Adds the given positions as WPs</summary>
        /// <param name="wps"></param>
        public void AddWaypoints(Vector3[] wps)
        {
            if (wps.Length < 1)
            {
                throw new ArgumentException("wps are empty.");
            }
            int     length = wps.Length;
            Vector3 v;

            if (Waypoints.Count > 0)
            {
                v = Waypoints.First.Value.Position;
                WaypointEntry waypointEntry = Waypoints.Last.Value;
                waypointEntry.Orientation = waypointEntry.Position.GetAngleTowards(wps[0]);
            }
            else
            {
                v = wps[0];
            }

            for (int index = 0; index < length; ++index)
            {
                Vector3 wp = wps[index];
                Waypoints.AddLast(index >= length - 1
          ? (index <= 0
            ? CreateWaypoint(wp, Utility.Random(0.0f, 6.283185f))
            : CreateWaypoint(wp, wp.GetAngleTowards(v)))
          : CreateWaypoint(wp, wp.GetAngleTowards(wps[index + 1])));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates a Waypoint but does not add it
        /// </summary>
        public WaypointEntry CreateWaypoint(Vector3 pos, float orientation)
        {
            var           last = Waypoints.Last;
            WaypointEntry entry;

            if (last != null)
            {
                entry = new WaypointEntry
                {
                    Id         = last.Value.Id + 1,
                    SpawnEntry = this,
                };
            }
            else
            {
                entry = new WaypointEntry
                {
                    Id         = 1,
                    SpawnEntry = this,
                };
            }

            entry.Position    = pos;
            entry.Orientation = orientation;
            return(entry);
        }
Beispiel #3
0
        /// <summary>Creates a Waypoint but does not add it</summary>
        public WaypointEntry CreateWaypoint(Vector3 pos, float orientation)
        {
            LinkedListNode <WaypointEntry> last = Waypoints.Last;
            WaypointEntry waypointEntry;

            if (last != null)
            {
                waypointEntry = new WaypointEntry
                {
                    Id         = last.Value.Id + 1U,
                    SpawnEntry = this
                }
            }
            ;
            else
            {
                waypointEntry = new WaypointEntry
                {
                    Id         = 1U,
                    SpawnEntry = this
                }
            };
            waypointEntry.Position    = pos;
            waypointEntry.Orientation = orientation;
            return(waypointEntry);
        }
 private bool GetLastPathStage(WaypointEntry sourceWaypointEntry, IEnumerable <VisibilityVertex> targets, out VertexEntry lastEntry)
 {
     // Final stage: no need to get separate entries to the targets.  And because we send null for the
     // target entry vector, this will return the final vertexEntry of the path.
     lastEntry = this.GetPathStage(sourceWaypointEntry.entryVector, sourceWaypointEntry.waypointVector, null, targets);
     return(lastEntry != null);
 }
Beispiel #5
0
        public WaypointFigurine(MapEditor editor, NPCSpawnPoint spawnPoint, WaypointEntry wp)
            : base(editor, spawnPoint)
        {
            m_Waypoint = wp;

            //GossipMenu = m_SpawnPoint.GossipMenu;
            NPCFlags = NPCFlags.Gossip;
        }
Beispiel #6
0
		public WaypointFigurine(SpawnPoint spawnPoint, WaypointEntry wp)
			: base(spawnPoint.SpawnEntry.Entry)
		{	
			m_SpawnPoint = spawnPoint;
			m_Waypoint = wp;
			m_position = wp.Position;

			GossipMenu = m_SpawnPoint.GossipMenu;
			NPCFlags = NPCFlags.Gossip;
		}
        private bool GetWaypointPathStages(IEnumerator<VisibilityVertex> waypointEnum, List<WaypointEntry> waypointEntries, ref WaypointEntry sourceWaypointEntry) {
            // Get the path stages between each waypoint: send the prior entries to source and get the entries to target.
            while (waypointEnum.MoveNext()) {
                var targetWaypointEntry = new WaypointEntry(waypointEnum.Current);
                waypointEntries.Add(targetWaypointEntry);

                if (null == this.GetPathStage(sourceWaypointEntry.entryVector, sourceWaypointEntry.waypointVector,
                        targetWaypointEntry.entryVector, targetWaypointEntry.waypointVector)) {
                    return false;
                }
                sourceWaypointEntry = targetWaypointEntry;
            }
            return true;
        }
        private bool GetWaypointPathStages(IEnumerator <VisibilityVertex> waypointEnum, List <WaypointEntry> waypointEntries, ref WaypointEntry sourceWaypointEntry)
        {
            // Get the path stages between each waypoint: send the prior entries to source and get the entries to target.
            while (waypointEnum.MoveNext())
            {
                var targetWaypointEntry = new WaypointEntry(waypointEnum.Current);
                waypointEntries.Add(targetWaypointEntry);

                if (null == this.GetPathStage(sourceWaypointEntry.entryVector, sourceWaypointEntry.waypointVector,
                                              targetWaypointEntry.entryVector, targetWaypointEntry.waypointVector))
                {
                    return(false);
                }
                sourceWaypointEntry = targetWaypointEntry;
            }
            return(true);
        }
        /// <summary>
        /// Get the lowest-cost path from one of one or more sources to one of one or more targets, with waypoints.
        /// </summary>
        /// <param name="sources">One or more source vertices</param>
        /// <param name="waypoints">One or more waypoint vertices</param>
        /// <param name="targets">One or more target vertices</param>
        /// <returns>An enumeration of each stage's enumeration of path points</returns>
        internal IEnumerable<IEnumerable<Point>> GetPath(IEnumerable<VisibilityVertex> sources, IEnumerable<VisibilityVertex> waypoints,
                                            IEnumerable<VisibilityVertex> targets) {
            var waypointEntries = new List<WaypointEntry>();

            var waypointEnum = waypoints.GetEnumerator();
            waypointEnum.MoveNext();
            var sourceWaypointEntry = new WaypointEntry(waypointEnum.Current);
            waypointEntries.Add(sourceWaypointEntry);

            VertexEntry lastEntry;
            if (!GetFirstPathStage(sourceWaypointEntry, sources)
                    || !GetWaypointPathStages(waypointEnum, waypointEntries, ref sourceWaypointEntry)
                    || !GetLastPathStage(sourceWaypointEntry, targets, out lastEntry)) {
                return null;
            }
            return RestorePathStages(waypointEntries, lastEntry);
        }
        /// <summary>
        /// Get the lowest-cost path from one of one or more sources to one of one or more targets, with waypoints.
        /// </summary>
        /// <param name="sources">One or more source vertices</param>
        /// <param name="waypoints">One or more waypoint vertices</param>
        /// <param name="targets">One or more target vertices</param>
        /// <returns>An enumeration of each stage's enumeration of path points</returns>
        internal IEnumerable <IEnumerable <Point> > GetPath(IEnumerable <VisibilityVertex> sources, IEnumerable <VisibilityVertex> waypoints,
                                                            IEnumerable <VisibilityVertex> targets)
        {
            var waypointEntries = new List <WaypointEntry>();

            var waypointEnum = waypoints.GetEnumerator();

            waypointEnum.MoveNext();
            var sourceWaypointEntry = new WaypointEntry(waypointEnum.Current);

            waypointEntries.Add(sourceWaypointEntry);

            VertexEntry lastEntry;

            if (!GetFirstPathStage(sourceWaypointEntry, sources) ||
                !GetWaypointPathStages(waypointEnum, waypointEntries, ref sourceWaypointEntry) ||
                !GetLastPathStage(sourceWaypointEntry, targets, out lastEntry))
            {
                return(null);
            }
            return(RestorePathStages(waypointEntries, lastEntry));
        }
 private bool GetFirstPathStage(WaypointEntry sourceWaypointEntry, IEnumerable <VisibilityVertex> sources)
 {
     // Get the first stage: no prior entries to the sources; this target waypoint becomes the first waypoint stage's source.
     return(null != this.GetPathStage(null, sources, sourceWaypointEntry.entryVector, sourceWaypointEntry.waypointVector));
 }
Beispiel #12
0
 public void GoToWaypoint(WaypointEntry waypointEntry)
 {
     this.m_owner.Movement.MoveTo(waypointEntry.Position, false);
 }
Beispiel #13
0
        public LinkedListNode <WaypointEntry> InsertWaypointAfter(WaypointEntry entry, Vector3 pos, float orientation)
        {
            var newWp = CreateWaypoint(pos, orientation);

            return(Waypoints.AddAfter(entry.Node, newWp));
        }
 private bool GetLastPathStage(WaypointEntry sourceWaypointEntry, IEnumerable<VisibilityVertex> targets, out VertexEntry lastEntry) {
     // Final stage: no need to get separate entries to the targets.  And because we send null for the
     // target entry vector, this will return the final vertexEntry of the path.
     lastEntry = this.GetPathStage(sourceWaypointEntry.entryVector, sourceWaypointEntry.waypointVector, null, targets);
     return lastEntry != null;
 }
 private bool GetFirstPathStage(WaypointEntry sourceWaypointEntry, IEnumerable<VisibilityVertex> sources) {
     // Get the first stage: no prior entries to the sources; this target waypoint becomes the first waypoint stage's source.
     return null != this.GetPathStage(null, sources, sourceWaypointEntry.entryVector, sourceWaypointEntry.waypointVector);
 }
Beispiel #16
0
        public LinkedListNode <WaypointEntry> InsertWaypointBefore(WaypointEntry entry, Vector3 pos, float orientation)
        {
            WaypointEntry waypoint = CreateWaypoint(pos, orientation);

            return(Waypoints.AddBefore(entry.Node, waypoint));
        }
Beispiel #17
0
 public WaypointFigurine(MapEditor editor, NPCSpawnPoint spawnPoint, WaypointEntry wp)
     : base(editor, spawnPoint)
 {
     this.m_Waypoint = wp;
     this.NPCFlags   = NPCFlags.Gossip;
 }
Beispiel #18
0
        public LinkedListNode <WaypointEntry> InsertWaypointAfter(WaypointEntry entry, Vector3 pos, float orientation)
        {
            WaypointEntry waypoint = this.CreateWaypoint(pos, orientation);

            return(this.Waypoints.AddAfter(entry.Node, waypoint));
        }