コード例 #1
0
        public static void Run(T startingNode, Func <T, IEnumerable <T> > neighborsGetter, Func <T, T, float> distanceGetter, Dictionary <T, float> outDistances, Dictionary <T, T> outParents = null)
        {
            Dijkstra <T> .singleNodeList.Clear();

            Dijkstra <T> .singleNodeList.Add(startingNode);

            Dijkstra <T> .Run(Dijkstra <T> .singleNodeList, neighborsGetter, distanceGetter, outDistances, outParents);
        }
コード例 #2
0
        public static void Run(IEnumerable <T> startingNodes, Func <T, IEnumerable <T> > neighborsGetter, Func <T, T, float> distanceGetter, Dictionary <T, float> outDistances, Dictionary <T, T> outParents = null)
        {
            Dijkstra <T> .Run(startingNodes, neighborsGetter, distanceGetter, Dijkstra <T> .tmpResult, outParents);

            outDistances.Clear();
            for (int i = 0; i < Dijkstra <T> .tmpResult.Count; i++)
            {
                outDistances.Add(Dijkstra <T> .tmpResult[i].Key, Dijkstra <T> .tmpResult[i].Value);
            }
            Dijkstra <T> .tmpResult.Clear();
        }
コード例 #3
0
        public static bool TryFindBestPawnStandCell(Pawn forPawn, out IntVec3 cell, bool cellByCell = false)
        {
            cell = IntVec3.Invalid;
            int   num    = -1;
            float radius = 10f;

            while (true)
            {
                tmpDistances.Clear();
                tmpParents.Clear();
                Dijkstra <IntVec3> .Run(forPawn.Position, (IntVec3 x) => GetAdjacentCardinalCellsForBestStandCell(x, radius, forPawn), delegate(IntVec3 from, IntVec3 to)
                {
                    float num4 = 1f;
                    if (from.x != to.x && from.z != to.z)
                    {
                        num4 = 1.41421354f;
                    }
                    if (!to.Standable(forPawn.Map))
                    {
                        num4 += 3f;
                    }
                    if (PawnUtility.AnyPawnBlockingPathAt(to, forPawn))
                    {
                        num4 = ((to.GetThingList(forPawn.Map).Find((Thing x) => x is Pawn && x.HostileTo(forPawn)) == null) ? (num4 + 15f) : (num4 + 40f));
                    }
                    Building_Door building_Door = to.GetEdifice(forPawn.Map) as Building_Door;
                    if (building_Door != null && !building_Door.FreePassage)
                    {
                        num4 = ((!building_Door.PawnCanOpen(forPawn)) ? (num4 + 50f) : (num4 + 6f));
                    }
                    return(num4);
                }, tmpDistances, tmpParents);

                if (tmpDistances.Count == num)
                {
                    return(false);
                }
                float num2 = 0f;
                foreach (KeyValuePair <IntVec3, float> tmpDistance in tmpDistances)
                {
                    if ((!cell.IsValid || !(tmpDistance.Value >= num2)) && tmpDistance.Key.Walkable(forPawn.Map) && !PawnUtility.AnyPawnBlockingPathAt(tmpDistance.Key, forPawn))
                    {
                        Building_Door door = tmpDistance.Key.GetDoor(forPawn.Map);
                        if (door == null || door.FreePassage)
                        {
                            cell = tmpDistance.Key;
                            num2 = tmpDistance.Value;
                        }
                    }
                }
                if (cell.IsValid)
                {
                    if (!cellByCell)
                    {
                        return(true);
                    }
                    IntVec3 intVec = cell;
                    int     num3   = 0;
                    while (intVec.IsValid && intVec != forPawn.Position)
                    {
                        num3++;
                        if (num3 >= 10000)
                        {
                            Log.Error("Too many iterations.");
                            break;
                        }
                        if (intVec.Walkable(forPawn.Map))
                        {
                            Building_Door door2 = intVec.GetDoor(forPawn.Map);
                            if (door2 == null || door2.FreePassage)
                            {
                                cell = intVec;
                            }
                        }
                        intVec = tmpParents[intVec];
                    }
                    return(true);
                }
                if (radius > (float)forPawn.Map.Size.x && radius > (float)forPawn.Map.Size.z)
                {
                    break;
                }
                radius *= 2f;
                num     = tmpDistances.Count;
            }
            return(false);
        }