Beispiel #1
0
        /// <summary>
        /// Starts the MovementAI
        /// </summary>
        /// <returns>Whether already arrived</returns>
        public bool MoveTo(Vector3 destination, bool findPath = true)
        {
            if (!m_owner.IsInWorld)
            {
                // something's wrong here
                m_owner.DeleteNow();
                return(false);
            }

            m_destination = destination;
            if (IsAtDestination)
            {
                return(true);
            }

            if (findPath)
            {
                // TODO: Consider flying units & liquid levels
                var pos = m_owner.Position;
                pos.Z         += 5;
                m_currentQuery = new PathQuery(pos, ref destination, m_owner.ContextHandler, OnPathQueryReply);

                m_owner.Map.Terrain.FindPath(m_currentQuery);
            }
            else if (m_owner.CanMove)
            {
                // start moving
                MoveToDestination();
            }
            // cannot move
            return(false);
        }
Beispiel #2
0
        public bool GetPathResult(int reference, int[] path, ref int pathSize, int maxPath)
        {
            for (int i = 0; i < MaxQueue; i++)
            {
                if (queue[i].Reference == reference)
                {
                    PathQuery q = queue[i];

                    //free request for reuse
                    q.Reference = Invalid;
                    q.status    = 0;

                    //copy path
                    int n = Math.Min(q.PathCount, maxPath);
                    q.Path.CopyTo(path, 0);
                    pathSize = n;

                    queue[i] = q;

                    return(true);
                }
            }

            return(false);
        }
Beispiel #3
0
        /// <summary>
        /// Starts the MovementAI
        /// </summary>
        /// <returns>Whether already arrived</returns>
        public bool MoveToPoints(List <Vector3> points)
        {
            if (!m_owner.IsInWorld)
            {
                // something's wrong here
                m_owner.DeleteNow();
                return(false);
            }

            m_destination = points[points.Count - 1];
            if (IsAtDestination)
            {
                return(true);
            }


            // TODO: Consider flying units & liquid levels
            var pos = m_owner.Position;

            pos.Z         += 5;
            m_currentQuery = new PathQuery(pos, ref m_destination, m_owner.ContextHandler, OnPathQueryReply);

            m_currentQuery.Path.Reset(points.Count);
            foreach (var point in points)
            {
                m_currentQuery.Path.Add(point);
            }
            m_currentQuery.Reply();

            //m_owner.Map.Terrain.FindPath(m_currentQuery);

            // cannot move
            return(false);
        }
Beispiel #4
0
        public AbstractView Paths(string term)
        {
            IEnumerable <PathQuery> result = new PathQuery[0];

            term = term.ToLower();

            if (term.StartsWith("/sitecore"))
            {
                ISitecoreService service = new SitecoreService("master");

                if (term.EndsWith("/"))
                {
                    result = service.Query <PathQuery>(term + "*");
                }
                else
                {
                    var parts = term.Split('/');

                    var query = parts.Take(parts.Length - 1).Aggregate((x, y) => "{0}/{1}".Formatted(x, y));

                    result = service.Query <PathQuery>(query + "/*");

                    result = result.Where(x => x.value.ToLower().StartsWith(term));
                }
            }

            return(new JsonView(result));
        }
Beispiel #5
0
        /// <summary>Starts the MovementAI</summary>
        /// <returns>Whether already arrived</returns>
        public bool MoveTo(Vector3 destination, bool findPath = true)
        {
            if (!this.m_owner.IsInWorld)
            {
                this.m_owner.DeleteNow();
                return(false);
            }

            this.m_destination = destination;
            if (this.IsAtDestination)
            {
                return(true);
            }
            if (findPath)
            {
                Vector3 position = this.m_owner.Position;
                position.Z         += 5f;
                this.m_currentQuery = new PathQuery(position, ref destination, this.m_owner.ContextHandler,
                                                    new PathQuery.PathQueryCallback(this.OnPathQueryReply));
                this.m_owner.Map.Terrain.FindPath(this.m_currentQuery);
            }
            else if (this.m_owner.CanMove)
            {
                this.MoveToDestination();
            }

            return(false);
        }
Beispiel #6
0
        /// <summary>Starts the MovementAI</summary>
        /// <returns>Whether already arrived</returns>
        public bool MoveTo(Vector3 destination, bool findPath = true)
        {
            if (!m_owner.IsInWorld)
            {
                m_owner.DeleteNow();
                return(false);
            }

            m_destination = destination;
            if (IsAtDestination)
            {
                return(true);
            }
            if (findPath)
            {
                Vector3 position = m_owner.Position;
                position.Z    += 5f;
                m_currentQuery = new PathQuery(position, ref destination, m_owner.ContextHandler,
                                               OnPathQueryReply);
                m_owner.Map.Terrain.FindPath(m_currentQuery);
            }
            else if (m_owner.CanMove)
            {
                MoveToDestination();
            }

            return(false);
        }
Beispiel #7
0
        private static void OnFoundPath(PathQuery query)
        {
            var chr       = (Character)query.ContextHandler;
            var figurines = TerrainVisualizations.ClearVis(chr);

            // spawn figurines along the path
            if (query.Path == null)
            {
                chr.SendSystemMessage("Could not find path");
                return;
            }

            var last = new NavFigurine(chr.Map, query.From);

            foreach (var vert in query.Path)
            {
                var fig = new NavFigurine(chr.Map, vert);

                var v = vert;
                last.SetOrientationTowards(ref v);
                last.ChannelObject = fig;

                figurines.Add(fig);
                last = fig;
            }
        }
Beispiel #8
0
		/// <summary>
		/// Request an empty slot in the path queue
		/// </summary>
		/// <param name="startRef">Start polygon reference</param>
		/// <param name="endRef">End polygon reference</param>
		/// <param name="startPos">Start position</param>
		/// <param name="endPos">End position</param>
		/// <returns>Index of empty slot</returns>
		public int Request(int startRef, int endRef, Vector3 startPos, Vector3 endPos)
		{
			//find empty slot
			int slot = -1;
			for (int i = 0; i < MaxQueue; i++)
			{
				if (queue[i].Reference == Invalid)
				{
					slot = i;
					break;
				}
			}

			//could not find slot
			if (slot == -1)
				return Invalid;

			int reference = nextHandle++;
			if (nextHandle == Invalid) nextHandle++;

			PathQuery q = queue[slot];
			q.Reference = reference;
			q.StartPos = startPos;
			q.StartRef = startRef;
			q.EndPos = endPos;
			q.EndRef = endRef;

			q.status = 0;
			q.PathCount = 0;
			q.KeepAlive = 0;

			queue[slot] = q;

			return reference;
		}
    private void PartySelectedFormationMoveToPosition_FindPath(GameObject partyMember, int count,
                                                               LocAndOffsets from, LocAndOffsets plannedPos, out LocAndOffsets actualPos)
    {
        actualPos = plannedPos;

        if (IsBlocked(plannedPos.ToInches2D(), partyMember.GetRadius()))
        {
            var pq = new PathQuery();
            pq.flags2  = (int)AnimPathDataFlags.UNK_2000;
            pq.flags   = PathQueryFlags.PQF_FORCED_STRAIGHT_LINE | PathQueryFlags.PQF_HAS_CRITTER;
            pq.critter = partyMember;
            pq.from    = from;
            pq.to      = plannedPos;
            pq.flags   = PathQueryFlags.PQF_FORCED_STRAIGHT_LINE | PathQueryFlags.PQF_HAS_CRITTER |
                         PathQueryFlags.PQF_TO_EXACT | PathQueryFlags.PQF_800;
            pq.distanceToTargetMin = count * locXY.INCH_PER_TILE;
            if (!GameSystems.Combat.IsCombatActive())
            {
                pq.flags |= PathQueryFlags.PQF_IGNORE_CRITTERS;
            }

            if (GameSystems.PathX.FindPath(pq, out var pathResult))
            {
                actualPos = pathResult.nodes[pathResult.nodeCount - 1];
            }
        }
    }
Beispiel #10
0
        public bool GetPathResult(int index, PolyId[] path, ref int pathSize, int maxPath)
        {
            for (int i = 0; i < MaxQueue; i++)
            {
                if (queue[i].Index == index)
                {
                    PathQuery q = queue[i];

                    //free request for reuse
                    q.Index  = 0;
                    q.Status = 0;

                    //copy path
                    int n = Math.Min(q.PathCount, maxPath);
                    q.Path.CopyTo(path, 0);
                    pathSize = n;

                    queue[i] = q;

                    return(true);
                }
            }

            return(false);
        }
Beispiel #11
0
        /// <summary>Starts the MovementAI</summary>
        /// <returns>Whether already arrived</returns>
        public bool MoveToPoints(List <Vector3> points)
        {
            if (!m_owner.IsInWorld)
            {
                m_owner.DeleteNow();
                return(false);
            }

            m_destination = points[points.Count - 1];
            if (IsAtDestination)
            {
                return(true);
            }
            Vector3 position = m_owner.Position;

            position.Z    += 5f;
            m_currentQuery = new PathQuery(position, ref m_destination, m_owner.ContextHandler,
                                           OnPathQueryReply);
            m_currentQuery.Path.Reset(points.Count);
            foreach (Vector3 point in points)
            {
                m_currentQuery.Path.Add(point);
            }
            m_currentQuery.Reply();
            return(false);
        }
    public static void LoadScene(int _sceneId)
    {
        Application.LoadLevel(2);

        // Call All Reset Statics
        PlayerChildFSM.ResetStatics();
        PlayerMain.ResetStatics();
        player_control.ResetStatics();
        GameManager.ResetStatics();
        EndGamePanel.ResetStatics();

        PlayerSquadFSM.ResetStatics();
        SquadChildFSM.ResetStatics();

        Wall.ResetStatics();
        WallRenderer.ResetStatics();
        Nutrients.ResetStatics();

        ECPoolManager.ResetStatics();
        ECIdleState.ResetStatics();
        DirectionDatabase.ResetStatics();
        FormationDatabase.ResetStatics();
        PathQuery.ResetStatics();
        PointDatabase.ResetStatics();
        PositionQuery.ResetStatics();
        ECTracker.ResetStatics();

        EnemyMainFSM.ResetStatics();

        Application.LoadLevel(_sceneId);
    }
Beispiel #13
0
        public void Update(int maxIters)
        {
            //update path request until there is nothing left to update
            //or up to maxIters pathfinder iterations have been consumed
            int iterCount = maxIters;

            for (int i = 0; i < MaxQueue; i++)
            {
                PathQuery q = queue[queueHead % MaxQueue];

                //skip inactive requests
                if (q.Index == 0)
                {
                    queueHead++;
                    continue;
                }

                //handle completed request
                if (q.Status == Status.Success || q.Status == Status.Failure)
                {
                    q.KeepAlive++;
                    if (q.KeepAlive > MaxKeepAlive)
                    {
                        q.Index  = 0;
                        q.Status = 0;
                    }

                    queueHead++;
                    continue;
                }

                //handle query start
                if (q.Status == 0)
                {
                    q.Status = navquery.InitSlicedFindPath(ref q.Start, ref q.End, navqueryfilter, FindPathOptions.None).ToStatus();
                }

                //handle query in progress
                if (q.Status == Status.InProgress)
                {
                    int iters = 0;
                    q.Status = navquery.UpdateSlicedFindPath(iterCount, ref iters).ToStatus();

                    iterCount -= iters;
                }

                if (q.Status == Status.Success)
                {
                    q.Status = navquery.FinalizeSlicedFindPath(q.Path).ToStatus();
                }

                if (iterCount <= 0)
                {
                    break;
                }

                queueHead++;
            }
        }
Beispiel #14
0
		public void Update(int maxIters)
		{
			const int MAX_KEEP_ALIVE = 2; //in update ticks

			//update path request until there is nothing left to update
			//or up to maxIters pathfinder iterations have been consumed
			int iterCount = maxIters;

			for (int i = 0; i < MaxQueue; i++)
			{
				PathQuery q = queue[queueHead % MaxQueue];

				//skip inactive requests
				if (q.Reference == Invalid)
				{
					queueHead++;
					continue;
				}

				//handle completed request
				if (q.status == Status.Success || q.status == Status.Failure)
				{
					q.KeepAlive++;
					if (q.KeepAlive > MAX_KEEP_ALIVE)
					{
						q.Reference = Invalid;
						q.status = 0;
					}

					queueHead++;
					continue;
				}

				//handle query start
				if (q.status == 0)
				{
					q.status = navquery.InitSlicedFindPath(new NavPoint(q.StartRef, q.StartPos), new NavPoint(q.EndRef, q.EndPos)).ToStatus();
				}

				//handle query in progress
				if (q.status == Status.InProgress)
				{
					int iters = 0;
					q.status = navquery.UpdateSlicedFindPath(iterCount, ref iters).ToStatus();

					iterCount -= iters;
				}

				if (q.status == Status.Success)
				{
					q.status = navquery.FinalizeSlicedFindPath(q.Path, ref q.PathCount, maxPathSize).ToStatus();
				}

				if (iterCount <= 0)
					break;

				queueHead++;
			}
		}
Beispiel #15
0
 protected void OnPathQueryReply(PathQuery query)
 {
     if (query != m_currentQuery)
     {
         return;
     }
     m_currentQuery = null;
     FollowPath(query.Path);
 }
Beispiel #16
0
 protected void OnPathQueryReply(PathQuery query)
 {
     if (query != this.m_currentQuery)
     {
         return;
     }
     this.m_currentQuery = (PathQuery)null;
     this.FollowPath(query.Path);
 }
Beispiel #17
0
    // TODO: Remove later
    public static void Run()
    {
        PathQuery q = new PathQuery();

        q.critter = GameSystems.Party.GetLeader();
        q.@from   = new LocAndOffsets(509, 457, -9.42809f, -9.42809f);
        q.to      = new LocAndOffsets(511, 456, -1.4142139f, -1.4142139f);
        q.flags   = (PathQueryFlags)0xC0803;
        GameSystems.PathX.FindPath(q, out var r);
    }
    public void Populate(PathQuery pq, Path pqr, float radius)
    {
        if (pqr.mover != null)
        {
            using var objlist = ObjList.ListRadius(pqr.from, locXY.INCH_PER_TILE * 40, ObjectListFilter.OLC_PATH_BLOCKER);
            foreach (var obj in objlist)
            {
                var objFlags = obj.GetFlags();
                var objType  = obj.type;
                if ((objFlags & (ObjectFlag.NO_BLOCK | ObjectFlag.DONTDRAW | ObjectFlag.OFF)) == 0)
                {
                    if (pq.flags.HasFlag(PathQueryFlags.PQF_DOORS_ARE_BLOCKING) || objType != ObjectType.portal)
                    {
                        if (objType.IsCritter())
                        {
                            if (pq.flags.HasFlag(PathQueryFlags.PQF_IGNORE_CRITTERS) ||
                                GameSystems.Critter.IsFriendly(obj, pqr.mover) ||
                                GameSystems.Critter.IsDeadOrUnconscious(obj))
                            {
                                continue;
                            }
                        }

                        if (!pq.flags.HasFlag(PathQueryFlags.PQF_AVOID_AOOS))
                        {
                            Append(obj);
                        }
                        else
                        {
                            var ignoreTarget = pq.critter.ShouldIgnoreTarget(obj);
                            if (!ignoreTarget)
                            {
                                if (obj.HasRangedWeaponEquipped())
                                {
                                    Append(obj);
                                }
                                else
                                {
                                    float objReach  = obj.GetReach();
                                    float objRadius = obj.GetRadius();
                                    Append(obj, objReach + objRadius);
                                }
                            }
                            else
                            {
                                Append(obj);
                            }
                        }
                    }
                }
            }
        }
    }
Beispiel #19
0
 public PathQueue()
 {
     _nextHandle  = 1;
     _maxPathSize = 0;
     _queueHead   = 0;
     _navQuery    = null;
     _queue       = new PathQuery[MaxQueue];
     for (int i = 0; i < MaxQueue; i++)
     {
         _queue[i]      = new PathQuery();
         _queue[i].path = null;
     }
 }
Beispiel #20
0
        public void Update(int maxIters)
        {
            int MaxKeepAlive = 2;
            int iterCount    = maxIters;

            for (int i = 0; i < MaxQueue; i++)
            {
                PathQuery q = _queue[_queueHead % MaxQueue];
                if (q.refId == PathQInvalid)
                {
                    _queueHead++;
                    continue;
                }

                if ((q.status & Status.Success) != 0 || (q.status & Status.Failure) != 0)
                {
                    q.keepAlive++;
                    if (q.keepAlive > MaxKeepAlive)
                    {
                        q.refId  = PathQInvalid;
                        q.status = 0;
                    }

                    _queueHead++;
                    continue;
                }

                if (q.status == 0)
                {
                    q.status = _navQuery.InitSlicedFindPath(q.startRef, q.endRef, q.startPos, q.endPos, q.filter);
                }

                if ((q.status & Status.InProgress) != 0)
                {
                    int iters = 0;
                    q.status   = _navQuery.UpdateSlicedFindPath(iterCount, ref iters);
                    iterCount -= iters;
                }
                if ((q.status & Status.Success) != 0)
                {
                    q.status = _navQuery.FinalizeSlicedFindPath(ref q.path, ref q.npath, _maxPathSize);
                }

                if (iterCount <= 0)
                {
                    break;
                }

                _queueHead++;
            }
        }
Beispiel #21
0
 public Status GetPathResult(long refId, ref long[] path, ref int pathSize, int maxPath)
 {
     for (int i = 0; i < MaxQueue; i++)
     {
         if (_queue[i].refId == refId)
         {
             PathQuery q = _queue[i];
             q.refId  = PathQInvalid;
             q.status = 0;
             int n = Math.Min(q.npath, maxPath);
             Array.Copy(q.path, path, n);
             pathSize = n;
             return(Status.Success);
         }
     }
     return(Status.Failure);
 }
Beispiel #22
0
    public static void SaveStateToFile(this PathQuery query, string path)
    {
        var root      = new Dictionary <string, object>();
        var queryJson = new Dictionary <string, object>();

        queryJson["from"]   = ToJson(query.from);
        queryJson["to"]     = ToJson(query.to);
        queryJson["flags"]  = (int)query.flags;
        queryJson["flags2"] = (int)query.flags2;
        if (query.critter != null)
        {
            queryJson["critterId"]   = ToJson(query.critter.id);
            queryJson["critterName"] = GameSystems.MapObject.GetDisplayName(query.critter);
        }

        root["query"] = queryJson;

        var objPos = new List <object>();

        foreach (var obj in GameSystems.Object.EnumerateNonProtos())
        {
            if (obj.HasFlag(ObjectFlag.OFF) || !obj.id.IsPermanent || obj.HasFlag(ObjectFlag.INVENTORY))
            {
                continue;
            }

            objPos.Add(new Dictionary <string, object>
            {
                { "objectId", ToJson(obj.id) },
                { "objectName", GameSystems.MapObject.GetDisplayName(obj) },
                { "pos", ToJson(obj.GetLocationFull()) }
            });
        }
        root["objects"] = objPos;

        var rootJson = JsonSerializer.SerializeToUtf8Bytes(root, new JsonSerializerOptions {
            WriteIndented = true
        });

        File.WriteAllBytes(path, rootJson);
    }
Beispiel #23
0
        /// <summary>
        /// Request an empty slot in the path queue
        /// </summary>
        /// <param name="start">Start position</param>
        /// <param name="end">End position</param>
        /// <returns>Index of empty slot</returns>
        public int Request(NavPoint start, NavPoint end)
        {
            //find empty slot
            int slot = -1;

            for (int i = 0; i < MaxQueue; i++)
            {
                if (queue[i].Index == 0)
                {
                    slot = i;
                    break;
                }
            }

            //could not find slot
            if (slot == -1)
            {
                return(PathQueue.Invalid);
            }

            int index = nextHandle++;

            if (nextHandle == 0)
            {
                nextHandle++;
            }

            PathQuery q = queue[slot];

            q.Index = index;
            q.Start = start;
            q.End   = end;

            q.Status    = 0;
            q.PathCount = 0;
            q.KeepAlive = 0;

            queue[slot] = q;

            return(index);
        }
Beispiel #24
0
        public long Request(long startRef, long endRef, float[] startPos, float[] endPos, QueryFilter filter)
        {
            int slot = -1;

            for (int i = 0; i < MaxQueue; i++)
            {
                if (_queue[i].refId == PathQInvalid)
                {
                    slot = i;
                    break;
                }
            }

            if (slot == -1)
            {
                return(PathQInvalid);
            }

            long refId = _nextHandle++;

            if (_nextHandle == PathQInvalid)
            {
                _nextHandle++;
            }

            PathQuery q = _queue[slot];

            q.refId = refId;
            Helper.VCopy(ref q.startPos, startPos);
            q.startRef = startRef;
            Helper.VCopy(ref q.endPos, endPos);
            q.endRef = endRef;

            q.status    = 0;
            q.npath     = 0;
            q.filter    = filter;
            q.keepAlive = 0;

            return(refId);
        }
Beispiel #25
0
        public bool GetPathResult(int index, out Path path)
        {
            path = null;

            for (int i = 0; i < MaxQueue; i++)
            {
                if (queue[i].Index == index)
                {
                    PathQuery q = queue[i];

                    //free request for reuse
                    q.Index  = 0;
                    q.Status = 0;

                    path = new Path(q.Path);

                    queue[i] = q;

                    return(true);
                }
            }

            return(false);
        }
Beispiel #26
0
 public static void ResetStatics()
 {
     s_Instance = null;
 }
Beispiel #27
0
 public void FindPath(PathQuery query)
 {
     query.Path.Reset(1);
     query.Path.Add(query.To);
     query.Reply();
 }
Beispiel #28
0
 public void FindPath(PathQuery query)
 {
     FindPath(query.From, query.To, query.Path);
     query.Reply();
 }
Beispiel #29
0
 public static void ResetStatics()
 {
     s_Instance = null;
 }
Beispiel #30
0
 public SquadQuery(RTSSquad s, PathQuery q)
 {
     Squad = s;
     Query = q;
 }