Exemple #1
0
        //Select a random new neighbour by the given path
        public IPathElement GetRandomNewNeighbour(List <IPathElement> pathElements)
        {
            int          trys        = 0;
            IPathElement pathElement = this.GetRandomNeighbour();

            while (pathElements.Contains(pathElement) && trys < 20)
            {
                pathElement = this.GetRandomNeighbour();
                trys++;
            }
            return(pathElement);
        }
Exemple #2
0
        //Calculate a random path starting with the given navMesh
        public List <IPathElement> GetWanderingPath()
        {
            //Prepare the path
            List <IPathElement> path = new List <IPathElement>();

            //Add start navMesh to the path
            path.Add(this);

            //If the given navMesh doesn't have a neighbour: Stop
            if (this.GetNeighbours().Count == 0)
            {
                return(path);
            }

            //Select a random neighbour of this navMesh to start
            IPathElement randomNavMesh = this.GetRandomNeighbour();

            //If the random navMesh is null (no neighbours could be selected): Stop
            if (randomNavMesh == null)
            {
                return(path);
            }

            //Add random navMesh to the path
            path.Add(randomNavMesh);

            //Repeat till the path includes 50 stations
            for (int i = path.Count; i < 200; i++)
            {
                //Expand the previous navMesh, select the neighbour by the given directional angle
                IPathElement?pathMesh = path[path.Count - 1].GetRandomNewNeighbourByDirectionAndPath(
                    Vector3Utils.directionalAngle(path[path.Count - 2].Position, path[path.Count - 1].Position), path);

                //If this new station is noll (no neighbours could be selected): Stop
                if (pathMesh == null)
                {
                    return(path);
                }

                //Add this navMesh to the path
                path.Add(pathMesh);
            }

            return(path);
        }