コード例 #1
0
        private static int DistanceToClosestChair(IntVec3 from, IntVec3 step, Map map, int maxDist, CellRect spectateRect)
        {
            int     num    = 0;
            IntVec3 intVec = from;

            while (true)
            {
                intVec += step;
                num++;
                if (!intVec.InBounds(map))
                {
                    break;
                }
                if (SpectatorCellFinder.CorrectlyRotatedChairAt(intVec, map, spectateRect))
                {
                    return(num);
                }
                if (!intVec.Walkable(map))
                {
                    return(-1);
                }
                if (num >= maxDist)
                {
                    return(-1);
                }
            }
            return(-1);
        }
コード例 #2
0
        public static bool TryFindSpectatorCellFor(Pawn p, CellRect spectateRect, Map map, out IntVec3 cell, SpectateRectSide allowedSides = SpectateRectSide.All, int margin = 1, List <IntVec3> extraDisallowedCells = null)
        {
            spectateRect.ClipInsideMap(map);
            if (spectateRect.Area == 0 || allowedSides == SpectateRectSide.None)
            {
                cell = IntVec3.Invalid;
                return(false);
            }
            CellRect            rectWithMargin = spectateRect.ExpandedBy(margin).ClipInsideMap(map);
            Predicate <IntVec3> predicate      = delegate(IntVec3 x)
            {
                if (!x.InBounds(map))
                {
                    return(false);
                }
                if (!x.Standable(map))
                {
                    return(false);
                }
                if (x.Fogged(map))
                {
                    return(false);
                }
                if (rectWithMargin.Contains(x))
                {
                    return(false);
                }
                if ((x.z <= rectWithMargin.maxZ || (allowedSides & SpectateRectSide.Up) != SpectateRectSide.Up) && (x.x <= rectWithMargin.maxX || (allowedSides & SpectateRectSide.Right) != SpectateRectSide.Right) && (x.z >= rectWithMargin.minZ || (allowedSides & SpectateRectSide.Down) != SpectateRectSide.Down) && (x.x >= rectWithMargin.minX || (allowedSides & SpectateRectSide.Left) != SpectateRectSide.Left))
                {
                    return(false);
                }
                IntVec3 intVec3 = spectateRect.ClosestCellTo(x);
                if ((float)intVec3.DistanceToSquared(x) > 210.25f)
                {
                    return(false);
                }
                if (!GenSight.LineOfSight(intVec3, x, map, true, null, 0, 0))
                {
                    return(false);
                }
                if (x.GetThingList(map).Find((Thing y) => y is Pawn && y != p) != null)
                {
                    return(false);
                }
                if (p != null)
                {
                    if (!p.CanReserveAndReach(x, PathEndMode.OnCell, Danger.Some, 1, -1, null, false))
                    {
                        return(false);
                    }
                    Building edifice = x.GetEdifice(map);
                    if (edifice != null && edifice.def.category == ThingCategory.Building && edifice.def.building.isSittable && !p.CanReserve(edifice, 1, -1, null, false))
                    {
                        return(false);
                    }
                    if (x.IsForbidden(p))
                    {
                        return(false);
                    }
                    if (x.GetDangerFor(p, map) != Danger.None)
                    {
                        return(false);
                    }
                }
                if (extraDisallowedCells != null && extraDisallowedCells.Contains(x))
                {
                    return(false);
                }
                if (!SpectatorCellFinder.CorrectlyRotatedChairAt(x, map, spectateRect))
                {
                    int num = 0;
                    for (int k = 0; k < GenAdj.AdjacentCells.Length; k++)
                    {
                        IntVec3 x2 = x + GenAdj.AdjacentCells[k];
                        if (SpectatorCellFinder.CorrectlyRotatedChairAt(x2, map, spectateRect))
                        {
                            num++;
                        }
                    }
                    if (num >= 3)
                    {
                        return(false);
                    }
                    int num2 = SpectatorCellFinder.DistanceToClosestChair(x, new IntVec3(-1, 0, 0), map, 4, spectateRect);
                    if (num2 >= 0)
                    {
                        int num3 = SpectatorCellFinder.DistanceToClosestChair(x, new IntVec3(1, 0, 0), map, 4, spectateRect);
                        if (num3 >= 0 && Mathf.Abs(num2 - num3) <= 1)
                        {
                            return(false);
                        }
                    }
                    int num4 = SpectatorCellFinder.DistanceToClosestChair(x, new IntVec3(0, 0, 1), map, 4, spectateRect);
                    if (num4 >= 0)
                    {
                        int num5 = SpectatorCellFinder.DistanceToClosestChair(x, new IntVec3(0, 0, -1), map, 4, spectateRect);
                        if (num5 >= 0 && Mathf.Abs(num4 - num5) <= 1)
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            };

            if (p != null && predicate(p.Position) && SpectatorCellFinder.CorrectlyRotatedChairAt(p.Position, map, spectateRect))
            {
                cell = p.Position;
                return(true);
            }
            for (int i = 0; i < 1000; i++)
            {
                IntVec3 intVec = rectWithMargin.CenterCell + GenRadial.RadialPattern[i];
                if (predicate(intVec))
                {
                    if (!SpectatorCellFinder.CorrectlyRotatedChairAt(intVec, map, spectateRect))
                    {
                        for (int j = 0; j < 90; j++)
                        {
                            IntVec3 intVec2 = intVec + GenRadial.RadialPattern[j];
                            if (SpectatorCellFinder.CorrectlyRotatedChairAt(intVec2, map, spectateRect) && predicate(intVec2))
                            {
                                cell = intVec2;
                                return(true);
                            }
                        }
                    }
                    cell = intVec;
                    return(true);
                }
            }
            cell = IntVec3.Invalid;
            return(false);
        }
コード例 #3
0
            internal bool <> m__0(IntVec3 x)
            {
                if (!x.InBounds(this.map))
                {
                    return(false);
                }
                if (!x.Standable(this.map))
                {
                    return(false);
                }
                if (x.Fogged(this.map))
                {
                    return(false);
                }
                if (this.rectWithMargin.Contains(x))
                {
                    return(false);
                }
                if ((x.z <= this.rectWithMargin.maxZ || (this.allowedSides & SpectateRectSide.Up) != SpectateRectSide.Up) && (x.x <= this.rectWithMargin.maxX || (this.allowedSides & SpectateRectSide.Right) != SpectateRectSide.Right) && (x.z >= this.rectWithMargin.minZ || (this.allowedSides & SpectateRectSide.Down) != SpectateRectSide.Down) && (x.x >= this.rectWithMargin.minX || (this.allowedSides & SpectateRectSide.Left) != SpectateRectSide.Left))
                {
                    return(false);
                }
                IntVec3 intVec = this.spectateRect.ClosestCellTo(x);

                if ((float)intVec.DistanceToSquared(x) > 210.25f)
                {
                    return(false);
                }
                if (!GenSight.LineOfSight(intVec, x, this.map, true, null, 0, 0))
                {
                    return(false);
                }
                if (x.GetThingList(this.map).Find((Thing y) => y is Pawn && y != this.p) != null)
                {
                    return(false);
                }
                if (this.p != null)
                {
                    if (!this.p.CanReserveAndReach(x, PathEndMode.OnCell, Danger.Some, 1, -1, null, false))
                    {
                        return(false);
                    }
                    Building edifice = x.GetEdifice(this.map);
                    if (edifice != null && edifice.def.category == ThingCategory.Building && edifice.def.building.isSittable && !this.p.CanReserve(edifice, 1, -1, null, false))
                    {
                        return(false);
                    }
                    if (x.IsForbidden(this.p))
                    {
                        return(false);
                    }
                    if (x.GetDangerFor(this.p, this.map) != Danger.None)
                    {
                        return(false);
                    }
                }
                if (this.extraDisallowedCells != null && this.extraDisallowedCells.Contains(x))
                {
                    return(false);
                }
                if (!SpectatorCellFinder.CorrectlyRotatedChairAt(x, this.map, this.spectateRect))
                {
                    int num = 0;
                    for (int i = 0; i < GenAdj.AdjacentCells.Length; i++)
                    {
                        IntVec3 x2 = x + GenAdj.AdjacentCells[i];
                        if (SpectatorCellFinder.CorrectlyRotatedChairAt(x2, this.map, this.spectateRect))
                        {
                            num++;
                        }
                    }
                    if (num >= 3)
                    {
                        return(false);
                    }
                    int num2 = SpectatorCellFinder.DistanceToClosestChair(x, new IntVec3(-1, 0, 0), this.map, 4, this.spectateRect);
                    if (num2 >= 0)
                    {
                        int num3 = SpectatorCellFinder.DistanceToClosestChair(x, new IntVec3(1, 0, 0), this.map, 4, this.spectateRect);
                        if (num3 >= 0 && Mathf.Abs(num2 - num3) <= 1)
                        {
                            return(false);
                        }
                    }
                    int num4 = SpectatorCellFinder.DistanceToClosestChair(x, new IntVec3(0, 0, 1), this.map, 4, this.spectateRect);
                    if (num4 >= 0)
                    {
                        int num5 = SpectatorCellFinder.DistanceToClosestChair(x, new IntVec3(0, 0, -1), this.map, 4, this.spectateRect);
                        if (num5 >= 0 && Mathf.Abs(num4 - num5) <= 1)
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }