Example #1
0
        public void ScoreSpot_Pather(Spot spotLinkedToCurrent, Spot destinationSpot, int currentSearchID, ILocationHeuristics locationHeuristics, PriorityQueue <Spot, float> prioritySpotQueue)
        {
            //score spots
            float currentSearchSpotScore = currentSearchSpot.SearchScoreGet(currentSearchID);
            float linkedSpotScore        = 1E30f;
            float new_score = currentSearchSpotScore + currentSearchSpot.GetDistanceTo(spotLinkedToCurrent) + TurnCost(currentSearchSpot, spotLinkedToCurrent);

            if (locationHeuristics != null)
            {
                new_score += locationHeuristics.Score(currentSearchSpot.X, currentSearchSpot.Y, currentSearchSpot.Z);
            }
            if (spotLinkedToCurrent.IsFlagSet(Spot.FLAG_WATER))
            {
                new_score += 30;
            }

            if (spotLinkedToCurrent.SearchScoreIsSet(currentSearchID))
            {
                linkedSpotScore = spotLinkedToCurrent.SearchScoreGet(currentSearchID);
            }

            if (new_score < linkedSpotScore)
            {
                // shorter path to here found
                spotLinkedToCurrent.traceBack = currentSearchSpot;
                spotLinkedToCurrent.SearchScoreSet(currentSearchID, new_score);
                prioritySpotQueue.Enqueue(spotLinkedToCurrent, -(new_score + spotLinkedToCurrent.GetDistanceTo(destinationSpot) * heuristicsFactor));
            }
        }
Example #2
0
        public void ScoreSpot_A_Star_With_Model_And_Gradient_Avoidance(Spot spotLinkedToCurrent, Spot destinationSpot, int currentSearchID, ILocationHeuristics locationHeuristics, PriorityQueue <Spot, float> prioritySpotQueue)
        {
            //score spot
            float G_Score = currentSearchSpot.traceBackDistance + currentSearchSpot.GetDistanceTo(spotLinkedToCurrent); //  the movement cost to move from the starting point A to a given square on the grid, following the path generated to get there.
            float H_Score = spotLinkedToCurrent.GetDistanceTo2D(destinationSpot) * heuristicsFactor;                    // the estimated movement cost to move from that given square on the grid to the final destination, point B. This is often referred to as the heuristic, which can be a bit confusing. The reason why it is called that is because it is a guess. We really don�t know the actual distance until we find the path, because all sorts of things can be in the way (walls, water, etc.). You are given one way to calculate H in this tutorial, but there are many others that you can find in other articles on the web.
            float F_Score = G_Score + H_Score;

            if (spotLinkedToCurrent.IsFlagSet(Spot.FLAG_WATER))
            {
                F_Score += 30;
            }

            int score = GetTriangleClosenessScore(spotLinkedToCurrent.location);

            score   += GetTriangleGradiantScore(spotLinkedToCurrent.location, gradiantMax);
            F_Score += score * 2;

            if (!spotLinkedToCurrent.SearchScoreIsSet(currentSearchID) || F_Score < spotLinkedToCurrent.SearchScoreGet(currentSearchID))
            {
                // shorter path to here found
                spotLinkedToCurrent.traceBack         = currentSearchSpot;
                spotLinkedToCurrent.traceBackDistance = G_Score;
                spotLinkedToCurrent.SearchScoreSet(currentSearchID, F_Score);
                prioritySpotQueue.Enqueue(spotLinkedToCurrent, -F_Score);
            }
        }
Example #3
0
        // Connect according to MPQ data
        public Spot AddAndConnectSpot(Spot s)
        {
            s = AddSpot(s);
            List <Spot> close = FindAllSpots(s.location, MaxStepLength);

            if (!s.IsFlagSet(Spot.FLAG_MPQ_MAPPED))
            {
                foreach (Spot cs in close)
                {
                    if (cs.HasPathTo(this, s) && s.HasPathTo(this, cs) || cs.IsBlocked())
                    {
                    }
                    else if (!triangleWorld.IsStepBlocked(s.X, s.Y, s.Z, cs.X, cs.Y, cs.Z, toonHeight, toonSize, null))
                    {
                        float mid_x = (s.X + cs.X) / 2;
                        float mid_y = (s.Y + cs.Y) / 2;
                        float mid_z = (s.Z + cs.Z) / 2;
                        float stand_z;
                        int   flags;
                        if (triangleWorld.FindStandableAt(mid_x, mid_y, mid_z - WantedStepLength * .75f, mid_z + WantedStepLength * .75f, out stand_z, out flags, toonHeight, toonSize))
                        {
                            s.AddPathTo(cs);
                            cs.AddPathTo(s);
                        }
                    }
                }
            }
            return(s);
        }
Example #4
0
        public Spot TryAddSpot(Spot wasAt, Location isAt)
        {
            //if (IsUnderwaterOrInAir(isAt)) { return wasAt; }
            Spot isAtSpot = FindClosestSpot(isAt, WantedStepLength);

            if (isAtSpot == null)
            {
                isAtSpot = GetSpot(isAt);
                if (isAtSpot == null)
                {
                    Spot s = new Spot(isAt);
                    s        = AddSpot(s);
                    isAtSpot = s;
                }
                if (isAtSpot.IsFlagSet(Spot.FLAG_BLOCKED))
                {
                    isAtSpot.SetFlag(Spot.FLAG_BLOCKED, false);
                    Log("Cleared blocked flag");
                }
                if (wasAt != null)
                {
                    wasAt.AddPathTo(isAtSpot);
                    isAtSpot.AddPathTo(wasAt);
                }

                List <Spot> sl        = FindAllSpots(isAtSpot.location, MaxStepLength);
                int         connected = 0;
                foreach (Spot other in sl)
                {
                    if (other != isAtSpot)
                    {
                        other.AddPathTo(isAtSpot);
                        isAtSpot.AddPathTo(other);
                        connected++;
                        // Log("  connect to " + other.location);
                    }
                }
                Log("Learned a new spot at " + isAtSpot.location + " connected to " + connected + " other spots");
                wasAt = isAtSpot;
            }
            else
            {
                if (wasAt != null && wasAt != isAtSpot)
                {
                    // moved to an old spot, make sure they are connected
                    wasAt.AddPathTo(isAtSpot);
                    isAtSpot.AddPathTo(wasAt);
                }
                wasAt = isAtSpot;
            }

            return(wasAt);
        }
Example #5
0
 public void CreateSpotsAroundSpot(Spot currentSearchSpot)
 {
     CreateSpotsAroundSpot(currentSearchSpot, currentSearchSpot.IsFlagSet(Spot.FLAG_MPQ_MAPPED));
 }