Beispiel #1
0
        public override void Init()
        {
            base.Init();
            Data.spectateRect = CellRect.CenteredOn(spot, 0);
            Rot4             rotation       = spot.GetFirstThing <Building_Throne>(organizer.MapHeld).Rotation;
            SpectateRectSide asSpectateSide = rotation.Opposite.AsSpectateSide;

            Data.spectateRectAllowedSides  = (SpectateRectSide.All & ~asSpectateSide);
            Data.spectateRectPreferredSide = rotation.AsSpectateSide;
        }
Beispiel #2
0
 public static bool ValidSingleSide(this SpectateRectSide side)
 {
     return(side switch
     {
         SpectateRectSide.Up => true,
         SpectateRectSide.Right => true,
         SpectateRectSide.Down => true,
         SpectateRectSide.Left => true,
         _ => false,
     });
        // Token: 0x06000833 RID: 2099 RVA: 0x00043630 File Offset: 0x00041A30
        public override void Init()
        {
            base.Init();
            this.Data.spectateRect = this.CalculateSpectateRect();
            SpectateRectSide allowedSides = SpectateRectSide.All;

            if (this.Data.spectateRect.Width > this.Data.spectateRect.Height)
            {
                allowedSides = SpectateRectSide.Vertical;
            }
            else if (this.Data.spectateRect.Height > this.Data.spectateRect.Width)
            {
                allowedSides = SpectateRectSide.Horizontal;
            }
            this.Data.spectateRectAllowedSides = SpectatorCellFinder.FindSingleBestSide(this.Data.spectateRect, base.Map, allowedSides, 1);
        }
        public static int AsInt(this SpectateRectSide side)
        {
            switch (side)
            {
            case SpectateRectSide.Up:
                return(0);

            case SpectateRectSide.Right:
                return(1);

            case SpectateRectSide.Down:
                return(2);

            case SpectateRectSide.Left:
                return(3);

            default:
                return(0);
            }
        }
        public static Rot4 AsRot4(this SpectateRectSide side)
        {
            switch (side)
            {
            case SpectateRectSide.Up:
                return(Rot4.North);

            case SpectateRectSide.Right:
                return(Rot4.East);

            case SpectateRectSide.Down:
                return(Rot4.South);

            case SpectateRectSide.Left:
                return(Rot4.West);

            default:
                return(Rot4.Invalid);
            }
        }
        public static bool ValidSingleSide(this SpectateRectSide side)
        {
            switch (side)
            {
            case SpectateRectSide.Up:
                return(true);

            case SpectateRectSide.Right:
                return(true);

            case SpectateRectSide.Down:
                return(true);

            case SpectateRectSide.Left:
                return(true);

            default:
                return(false);
            }
        }
        public static void DebugFlashPotentialSpectatorCells(CellRect spectateRect, Map map, SpectateRectSide allowedSides = SpectateRectSide.All, int margin = 1)
        {
            List <IntVec3> list = new List <IntVec3>();
            int            num  = 50;

            for (int i = 0; i < num; i++)
            {
                IntVec3 intVec;
                if (!SpectatorCellFinder.TryFindSpectatorCellFor(null, spectateRect, map, out intVec, allowedSides, margin, list))
                {
                    break;
                }
                list.Add(intVec);
                float    a   = Mathf.Lerp(1f, 0.08f, (float)i / (float)num);
                Material mat = SolidColorMaterials.SimpleSolidColorMaterial(new Color(0f, 0.8f, 0f, a), false);
                map.debugDrawer.FlashCell(intVec, mat, (i + 1).ToString(), 50);
            }
            SpectateRectSide spectateRectSide = SpectatorCellFinder.FindSingleBestSide(spectateRect, map, allowedSides, margin);
            IntVec3          centerCell       = spectateRect.CenterCell;

            switch (spectateRectSide)
            {
            case SpectateRectSide.Up:
                centerCell.z += spectateRect.Height / 2 + 10;
                break;

            case SpectateRectSide.Right:
                centerCell.x += spectateRect.Width / 2 + 10;
                break;

            case SpectateRectSide.Down:
                centerCell.z -= spectateRect.Height / 2 + 10;
                break;

            case SpectateRectSide.Left:
                centerCell.x -= spectateRect.Width / 2 + 10;
                break;
            }
            map.debugDrawer.FlashLine(spectateRect.CenterCell, centerCell, 50);
        }
        private static void FlashSpectatorsCells()
        {
            Action <bool> act = delegate(bool bestSideOnly)
            {
                DebugTool tool        = null;
                IntVec3   firstCorner = default(IntVec3);
                tool = new DebugTool("first watch rect corner...", delegate
                {
                    firstCorner        = UI.MouseCell();
                    DebugTools.curTool = new DebugTool("second watch rect corner...", delegate
                    {
                        IntVec3 second                = UI.MouseCell();
                        CellRect spectateRect         = CellRect.FromLimits(firstCorner, second).ClipInsideMap(Find.CurrentMap);
                        SpectateRectSide allowedSides = SpectateRectSide.All;
                        if (bestSideOnly)
                        {
                            allowedSides = SpectatorCellFinder.FindSingleBestSide(spectateRect, Find.CurrentMap);
                        }
                        SpectatorCellFinder.DebugFlashPotentialSpectatorCells(spectateRect, Find.CurrentMap, allowedSides);
                        DebugTools.curTool = tool;
                    }, firstCorner);
                });
                DebugTools.curTool = tool;
            };
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            list.Add(new DebugMenuOption("All sides", DebugMenuOptionMode.Action, delegate
            {
                act(obj: false);
            }));
            list.Add(new DebugMenuOption("Best side only", DebugMenuOptionMode.Action, delegate
            {
                act(obj: true);
            }));
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
        public static SpectateRectSide FindSingleBestSide(CellRect spectateRect, Map map, SpectateRectSide allowedSides = SpectateRectSide.All, int margin = 1)
        {
            for (int i = 0; i < SpectatorCellFinder.scorePerSide.Length; i++)
            {
                SpectatorCellFinder.scorePerSide[i] = 0f;
            }
            SpectatorCellFinder.usedCells.Clear();
            int      num      = 30;
            CellRect cellRect = spectateRect.ExpandedBy(margin).ClipInsideMap(map);

            for (int j = 0; j < num; j++)
            {
                IntVec3 intVec;
                if (!SpectatorCellFinder.TryFindSpectatorCellFor(null, spectateRect, map, out intVec, allowedSides, margin, SpectatorCellFinder.usedCells))
                {
                    break;
                }
                SpectatorCellFinder.usedCells.Add(intVec);
                float    num2 = Mathf.Lerp(1f, 0.35f, (float)j / (float)num);
                float    num3 = num2;
                Building correctlyRotatedChairAt = SpectatorCellFinder.GetCorrectlyRotatedChairAt(intVec, map, spectateRect);
                if (intVec.z > cellRect.maxZ && (allowedSides & SpectateRectSide.Up) == SpectateRectSide.Up)
                {
                    SpectatorCellFinder.scorePerSide[0] += num3;
                    if (correctlyRotatedChairAt != null && correctlyRotatedChairAt.Rotation == Rot4.South)
                    {
                        SpectatorCellFinder.scorePerSide[0] += 1.2f * num2;
                    }
                }
                if (intVec.x > cellRect.maxX && (allowedSides & SpectateRectSide.Right) == SpectateRectSide.Right)
                {
                    SpectatorCellFinder.scorePerSide[1] += num3;
                    if (correctlyRotatedChairAt != null && correctlyRotatedChairAt.Rotation == Rot4.West)
                    {
                        SpectatorCellFinder.scorePerSide[1] += 1.2f * num2;
                    }
                }
                if (intVec.z < cellRect.minZ && (allowedSides & SpectateRectSide.Down) == SpectateRectSide.Down)
                {
                    SpectatorCellFinder.scorePerSide[2] += num3;
                    if (correctlyRotatedChairAt != null && correctlyRotatedChairAt.Rotation == Rot4.North)
                    {
                        SpectatorCellFinder.scorePerSide[2] += 1.2f * num2;
                    }
                }
                if (intVec.x < cellRect.minX && (allowedSides & SpectateRectSide.Left) == SpectateRectSide.Left)
                {
                    SpectatorCellFinder.scorePerSide[3] += num3;
                    if (correctlyRotatedChairAt != null && correctlyRotatedChairAt.Rotation == Rot4.East)
                    {
                        SpectatorCellFinder.scorePerSide[3] += 1.2f * num2;
                    }
                }
            }
            float num4 = 0f;
            int   num5 = -1;

            for (int k = 0; k < SpectatorCellFinder.scorePerSide.Length; k++)
            {
                if (SpectatorCellFinder.scorePerSide[k] != 0f)
                {
                    if (num5 < 0 || SpectatorCellFinder.scorePerSide[k] > num4)
                    {
                        num5 = k;
                        num4 = SpectatorCellFinder.scorePerSide[k];
                    }
                }
            }
            SpectatorCellFinder.usedCells.Clear();
            switch (num5)
            {
            case 0:
                return(SpectateRectSide.Up);

            case 1:
                return(SpectateRectSide.Right);

            case 2:
                return(SpectateRectSide.Down);

            case 3:
                return(SpectateRectSide.Left);

            default:
                return(SpectateRectSide.None);
            }
        }
        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);
        }
        public static SpectateRectSide FindSingleBestSide(CellRect spectateRect, Map map, SpectateRectSide allowedSides = SpectateRectSide.All, int margin = 1)
        {
            for (int i = 0; i < SpectatorCellFinder.scorePerSide.Length; i++)
            {
                SpectatorCellFinder.scorePerSide[i] = 0f;
            }
            SpectatorCellFinder.usedCells.Clear();
            int      num      = 30;
            CellRect cellRect = spectateRect.ExpandedBy(margin).ClipInsideMap(map);
            int      num2     = 0;
            IntVec3  intVec   = default(IntVec3);

            while (num2 < num && SpectatorCellFinder.TryFindSpectatorCellFor((Pawn)null, spectateRect, map, out intVec, allowedSides, margin, SpectatorCellFinder.usedCells))
            {
                SpectatorCellFinder.usedCells.Add(intVec);
                float    num3 = Mathf.Lerp(1f, 0.35f, (float)num2 / (float)num);
                float    num4 = num3;
                Building correctlyRotatedChairAt = SpectatorCellFinder.GetCorrectlyRotatedChairAt(intVec, map, spectateRect);
                if (intVec.z > cellRect.maxZ && (allowedSides & SpectateRectSide.Up) == SpectateRectSide.Up)
                {
                    SpectatorCellFinder.scorePerSide[0] += num4;
                    if (correctlyRotatedChairAt != null && correctlyRotatedChairAt.Rotation == Rot4.South)
                    {
                        SpectatorCellFinder.scorePerSide[0] += (float)(1.2000000476837158 * num3);
                    }
                }
                if (intVec.x > cellRect.maxX && (allowedSides & SpectateRectSide.Right) == SpectateRectSide.Right)
                {
                    SpectatorCellFinder.scorePerSide[1] += num4;
                    if (correctlyRotatedChairAt != null && correctlyRotatedChairAt.Rotation == Rot4.West)
                    {
                        SpectatorCellFinder.scorePerSide[1] += (float)(1.2000000476837158 * num3);
                    }
                }
                if (intVec.z < cellRect.minZ && (allowedSides & SpectateRectSide.Down) == SpectateRectSide.Down)
                {
                    SpectatorCellFinder.scorePerSide[2] += num4;
                    if (correctlyRotatedChairAt != null && correctlyRotatedChairAt.Rotation == Rot4.North)
                    {
                        SpectatorCellFinder.scorePerSide[2] += (float)(1.2000000476837158 * num3);
                    }
                }
                if (intVec.x < cellRect.minX && (allowedSides & SpectateRectSide.Left) == SpectateRectSide.Left)
                {
                    SpectatorCellFinder.scorePerSide[3] += num4;
                    if (correctlyRotatedChairAt != null && correctlyRotatedChairAt.Rotation == Rot4.East)
                    {
                        SpectatorCellFinder.scorePerSide[3] += (float)(1.2000000476837158 * num3);
                    }
                }
                num2++;
            }
            float num5 = 0f;
            int   num6 = -1;

            for (int j = 0; j < SpectatorCellFinder.scorePerSide.Length; j++)
            {
                if (SpectatorCellFinder.scorePerSide[j] != 0.0 && (num6 <0 || SpectatorCellFinder.scorePerSide[j]> num5))
                {
                    num6 = j;
                    num5 = SpectatorCellFinder.scorePerSide[j];
                }
            }
            SpectatorCellFinder.usedCells.Clear();
            switch (num6)
            {
            case 0:
                return(SpectateRectSide.Up);

            case 1:
                return(SpectateRectSide.Right);

            case 2:
                return(SpectateRectSide.Down);

            case 3:
                return(SpectateRectSide.Left);

            default:
                return(SpectateRectSide.None);
            }
        }
Beispiel #12
0
        public static SpectateRectSide FindSingleBestSide_NewTemp(CellRect spectateRect, Map map, SpectateRectSide allowedSides = SpectateRectSide.All, int margin = 1, Func <IntVec3, SpectateRectSide, int, float> scoreOffset = null)
        {
            for (int i = 0; i < scorePerSide.Length; i++)
            {
                scorePerSide[i] = 0f;
            }
            usedCells.Clear();
            int      num      = 30;
            CellRect cellRect = spectateRect.ExpandedBy(margin).ClipInsideMap(map);

            for (int j = 0; j < num; j++)
            {
                if (!TryFindSpectatorCellFor(null, spectateRect, map, out var cell, allowedSides, margin, usedCells))
                {
                    break;
                }
                usedCells.Add(cell);
                SpectateRectSide spectateRectSide = SpectateRectSide.None;
                if (cell.z > cellRect.maxZ)
                {
                    spectateRectSide |= SpectateRectSide.Up;
                }
                if (cell.x > cellRect.maxX)
                {
                    spectateRectSide |= SpectateRectSide.Right;
                }
                if (cell.z < cellRect.minZ)
                {
                    spectateRectSide |= SpectateRectSide.Down;
                }
                if (cell.x < cellRect.minX)
                {
                    spectateRectSide |= SpectateRectSide.Left;
                }
                float    num2 = Mathf.Lerp(1f, 0.35f, (float)j / (float)num);
                float    num3 = num2 + (scoreOffset?.Invoke(cell, spectateRectSide, j) ?? 0f);
                Building correctlyRotatedChairAt = GetCorrectlyRotatedChairAt(cell, map, spectateRect);
                foreach (SpectateRectSide allSelectedItem in spectateRectSide.GetAllSelectedItems <SpectateRectSide>())
                {
                    if (allSelectedItem.ValidSingleSide() && allowedSides.HasFlag(allSelectedItem))
                    {
                        scorePerSide[allSelectedItem.AsInt()] += num3;
                        if (correctlyRotatedChairAt != null && correctlyRotatedChairAt.Rotation == allSelectedItem.AsRot4())
                        {
                            scorePerSide[allSelectedItem.AsInt()] += 1.2f * num2;
                        }
                    }
                }
            }
            float num4 = 0f;
            int   num5 = -1;

            for (int k = 0; k < scorePerSide.Length; k++)
            {
                if (scorePerSide[k] != 0f && (num5 <0 || scorePerSide[k]> num4))
                {
                    num5 = k;
                    num4 = scorePerSide[k];
                }
            }
            usedCells.Clear();
            return(num5.ToSpectatorSide());
        }
Beispiel #13
0
 public static SpectateRectSide FindSingleBestSide(CellRect spectateRect, Map map, SpectateRectSide allowedSides = SpectateRectSide.All, int margin = 1)
 {
     return(FindSingleBestSide_NewTemp(spectateRect, map, allowedSides, margin));
 }