コード例 #1
0
        /// <summary>
        /// populates pathOptions with available points and returns the number of options found (args: unused1, currentPoint,
        /// unused2, targetPoint, maxDistance)
        /// </summary>
        private int FindPathOptions(Entity par1Entity, PathPoint par2PathPoint, PathPoint par3PathPoint, PathPoint par4PathPoint, float par5)
        {
            int i = 0;
            int j = 0;

            if (GetVerticalOffset(par1Entity, par2PathPoint.XCoord, par2PathPoint.YCoord + 1, par2PathPoint.ZCoord, par3PathPoint) == 1)
            {
                j = 1;
            }

            PathPoint pathpoint  = GetSafePoint(par1Entity, par2PathPoint.XCoord, par2PathPoint.YCoord, par2PathPoint.ZCoord + 1, par3PathPoint, j);
            PathPoint pathpoint1 = GetSafePoint(par1Entity, par2PathPoint.XCoord - 1, par2PathPoint.YCoord, par2PathPoint.ZCoord, par3PathPoint, j);
            PathPoint pathpoint2 = GetSafePoint(par1Entity, par2PathPoint.XCoord + 1, par2PathPoint.YCoord, par2PathPoint.ZCoord, par3PathPoint, j);
            PathPoint pathpoint3 = GetSafePoint(par1Entity, par2PathPoint.XCoord, par2PathPoint.YCoord, par2PathPoint.ZCoord - 1, par3PathPoint, j);

            if (pathpoint != null && !pathpoint.IsFirst && pathpoint.DistanceTo(par4PathPoint) < par5)
            {
                PathOptions[i++] = pathpoint;
            }

            if (pathpoint1 != null && !pathpoint1.IsFirst && pathpoint1.DistanceTo(par4PathPoint) < par5)
            {
                PathOptions[i++] = pathpoint1;
            }

            if (pathpoint2 != null && !pathpoint2.IsFirst && pathpoint2.DistanceTo(par4PathPoint) < par5)
            {
                PathOptions[i++] = pathpoint2;
            }

            if (pathpoint3 != null && !pathpoint3.IsFirst && pathpoint3.DistanceTo(par4PathPoint) < par5)
            {
                PathOptions[i++] = pathpoint3;
            }

            return(i);
        }
コード例 #2
0
        /// <summary>
        /// Adds a path from start to end and returns the whole path (args: unused, start, end, unused, maxDistance)
        /// </summary>
        private PathEntity AddToPath(Entity par1Entity, PathPoint par2PathPoint, PathPoint par3PathPoint, PathPoint par4PathPoint, float par5)
        {
            par2PathPoint.TotalPathDistance = 0.0F;
            par2PathPoint.DistanceToNext    = par2PathPoint.DistanceTo(par3PathPoint);
            par2PathPoint.DistanceToTarget  = par2PathPoint.DistanceToNext;
            Path.ClearPath();
            Path.AddPoint(par2PathPoint);
            PathPoint pathpoint = par2PathPoint;

            while (!Path.IsPathEmpty())
            {
                PathPoint pathpoint1 = Path.Dequeue();

                if (pathpoint1.Equals(par3PathPoint))
                {
                    return(CreateEntityPath(par2PathPoint, par3PathPoint));
                }

                if (pathpoint1.DistanceTo(par3PathPoint) < pathpoint.DistanceTo(par3PathPoint))
                {
                    pathpoint = pathpoint1;
                }

                pathpoint1.IsFirst = true;
                int i = FindPathOptions(par1Entity, pathpoint1, par4PathPoint, par3PathPoint, par5);
                int j = 0;

                while (j < i)
                {
                    PathPoint pathpoint2 = PathOptions[j];
                    float     f          = pathpoint1.TotalPathDistance + pathpoint1.DistanceTo(pathpoint2);

                    if (!pathpoint2.IsAssigned() || f < pathpoint2.TotalPathDistance)
                    {
                        pathpoint2.Previous          = pathpoint1;
                        pathpoint2.TotalPathDistance = f;
                        pathpoint2.DistanceToNext    = pathpoint2.DistanceTo(par3PathPoint);

                        if (pathpoint2.IsAssigned())
                        {
                            Path.ChangeDistance(pathpoint2, pathpoint2.TotalPathDistance + pathpoint2.DistanceToNext);
                        }
                        else
                        {
                            pathpoint2.DistanceToTarget = pathpoint2.TotalPathDistance + pathpoint2.DistanceToNext;
                            Path.AddPoint(pathpoint2);
                        }
                    }

                    j++;
                }
            }

            if (pathpoint == par2PathPoint)
            {
                return(null);
            }
            else
            {
                return(CreateEntityPath(par2PathPoint, pathpoint));
            }
        }