コード例 #1
0
 private static bool CorrectlyRotatedChairAt(IntVec3 x, Map map, CellRect spectateRect)
 {
     return(SpectatorCellFinder.GetCorrectlyRotatedChairAt(x, map, spectateRect) != null);
 }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
            }
        }