Example #1
0
        public bool TryCompletePath(out Vector currTarget)//path through all the cookies one by one and to the exit
        {
            CurrPath.Clear();
            currTarget = new Vector(-1, -1);
            if (AllPath == null)
            {
                AllPath = new List <WayPoint> {
                    new WayPoint(ModelUsage.MurphLoc, 0)
                };
                Targets.Clear();
            }
            TypeOfMap = MapedPoints.Count == 0 ? MapType.MapRoom : MapType.MapTarget;
            Target    = null;
            Map(new WayPoint(ModelUsage.MurphLoc, 0));
            if (Target == null)//no target - no way
            {
                return(false);
            }
            AddPoint(Target);
            if (!RestorePath(Target))
            {
                return(false);
            }
            TypeOfMap = MapType.MapCheck;
            Map(new WayPoint(ModelUsage.MurphLoc, 0));
            foreach (var pathPoint in OptimalPath)
            {
                ModelUsage.TryMoving(pathPoint);
                AllPath.Add(pathPoint);
            }

            PathValue  = GetPathValue();
            currTarget = Target.Location;
            return(true);
        }
Example #2
0
    // if "ignoreObstacle" is true, pathfinding will ignore all obstacles except GRID_VALUE_CANNOT, grid is only by GRID_VALUE_CANNOT or by GRID_VALUE_GOOD
    public bool FindWalkPath(bool _ignoreObstacle, GameObject Obj)
    {
        if (USE_FAST)
        {
            mPathFinder = new PathFinderFast(mMapData);
        }
        else
        {
            mPathFinder = new PathFinder(mMapData);
        }

        mPathFinder.Formula = HeuristicFormula.Manhattan;

        mPathFinder.Diagonals = true;

        mPathFinder.HeavyDiagonals = true;

        mPathFinder.HeuristicEstimate = 3;

        mPathFinder.PunishChangeDirection = false;

        mPathFinder.TieBreaker = false;

        mPathFinder.SearchLimit = 10000;

        List <PathFinderNode> path = mPathFinder.FindPath(mStart, mEnd, _ignoreObstacle);

        if (path == null)
        {
            mPathFinder    = null;
            mPathCondition = PathCondition.eNoWay;
            return(false);
        }
        else
        {
            Point mFirstPoint = new Point(0, 0);
            int   pathCount   = path.Count;
            mPathData      = new Point[pathCount];
            mPathCondition = PathCondition.eGood;
            for (int i = 0; i < pathCount; i++)
            {
                int pathX = path[pathCount - 1 - i].X;
                int pathY = path[pathCount - 1 - i].Y;
                mPathData[i] = new Point(pathX, pathY);

                // define the first wall the path met
                if (!_ignoreObstacle &&
                    mPathCondition == PathCondition.eGood &&
                    mMapData[pathX, pathY] != PathManager.GRID_VALUE_GOOD)
                {
                    mPathCondition = PathCondition.eWallInPath;

                    if (mFirstWall == null)
                    {
                        mFirstWall      = new Point(pathX, pathY);
                        mFirstWallIndex = i - 1;
                    }
                }
            }
            // ForTest(mPathData.Length,mPathData,null,Obj);
            mPathFinder = null;
            return(true);
        }
    }