コード例 #1
0
ファイル: GenSight.cs プロジェクト: wensincai/RW-Decompile
        public static bool LineOfSight(IntVec3 start, IntVec3 end, Map map, bool skipFirstCell = false, Func <IntVec3, bool> validator = null, int halfXOffset = 0, int halfZOffset = 0)
        {
            if (!start.InBounds(map) || !end.InBounds(map))
            {
                return(false);
            }
            bool flag;

            if (start.x == end.x)
            {
                flag = (start.z < end.z);
            }
            else
            {
                flag = (start.x < end.x);
            }
            int num  = Mathf.Abs(end.x - start.x);
            int num2 = Mathf.Abs(end.z - start.z);
            int num3 = start.x;
            int num4 = start.z;
            int i    = 1 + num + num2;
            int num5 = (end.x <= start.x) ? -1 : 1;
            int num6 = (end.z <= start.z) ? -1 : 1;

            num  *= 4;
            num2 *= 4;
            num  += halfXOffset * 2;
            num2 += halfZOffset * 2;
            int     num7   = num / 2 - num2 / 2;
            IntVec3 intVec = default(IntVec3);

            while (i > 1)
            {
                intVec.x = num3;
                intVec.z = num4;
                if (!skipFirstCell || !(intVec == start))
                {
                    if (!intVec.CanBeSeenOverFast(map))
                    {
                        return(false);
                    }
                    if (validator != null && !validator(intVec))
                    {
                        return(false);
                    }
                }
                if (num7 > 0 || (num7 == 0 && flag))
                {
                    num3 += num5;
                    num7 -= num2;
                }
                else
                {
                    num4 += num6;
                    num7 += num;
                }
                i--;
            }
            return(true);
        }
コード例 #2
0
ファイル: GenSight.cs プロジェクト: KraigXu/GameProject
        public static bool LineOfSight(IntVec3 start, IntVec3 end, Map map, CellRect startRect, CellRect endRect, Func <IntVec3, bool> validator = null)
        {
            if (!start.InBounds(map) || !end.InBounds(map))
            {
                return(false);
            }
            bool flag = (start.x != end.x) ? (start.x < end.x) : (start.z < end.z);
            int  num  = Mathf.Abs(end.x - start.x);
            int  num2 = Mathf.Abs(end.z - start.z);
            int  num3 = start.x;
            int  num4 = start.z;
            int  num5 = 1 + num + num2;
            int  num6 = (end.x > start.x) ? 1 : (-1);
            int  num7 = (end.z > start.z) ? 1 : (-1);
            int  num8 = num - num2;

            num  *= 2;
            num2 *= 2;
            IntVec3 intVec = default(IntVec3);

            while (num5 > 1)
            {
                intVec.x = num3;
                intVec.z = num4;
                if (endRect.Contains(intVec))
                {
                    return(true);
                }
                if (!startRect.Contains(intVec))
                {
                    if (!intVec.CanBeSeenOverFast(map))
                    {
                        return(false);
                    }
                    if (validator != null && !validator(intVec))
                    {
                        return(false);
                    }
                }
                if (num8 > 0 || (num8 == 0 && flag))
                {
                    num3 += num6;
                    num8 -= num2;
                }
                else
                {
                    num4 += num7;
                    num8 += num;
                }
                num5--;
            }
            return(true);
        }
コード例 #3
0
ファイル: ExitMapGrid.cs プロジェクト: wensincai/RW-Decompile
        private bool IsGoodExitCell(IntVec3 cell)
        {
            if (!cell.CanBeSeenOver(this.map))
            {
                return(false);
            }
            int num = GenRadial.NumCellsInRadius(2f);

            for (int i = 0; i < num; i++)
            {
                IntVec3 intVec = cell + GenRadial.RadialPattern[i];
                if (intVec.InBounds(this.map) && intVec.OnEdge(this.map) && intVec.CanBeSeenOverFast(this.map) && GenSight.LineOfSight(cell, intVec, this.map, false, null, 0, 0))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #4
0
ファイル: GenExplosion.cs プロジェクト: KraigXu/GameProject
        private static void CalculateNeededLOSToCells(IntVec3 position, Map map, float direction, out IntVec3?needLOSToCell1, out IntVec3?needLOSToCell2)
        {
            needLOSToCell1 = null;
            needLOSToCell2 = null;
            if (position.CanBeSeenOverFast(map))
            {
                return;
            }
            direction = GenMath.PositiveMod(direction, 360f);
            IntVec3 intVec = position;

            intVec.z++;
            IntVec3 intVec2 = position;

            intVec2.z--;
            IntVec3 intVec3 = position;

            intVec3.x--;
            IntVec3 intVec4 = position;

            intVec4.x++;
            if (direction < 90f)
            {
                if (intVec3.InBounds(map) && intVec3.CanBeSeenOverFast(map))
                {
                    needLOSToCell1 = intVec3;
                }
                if (intVec.InBounds(map) && intVec.CanBeSeenOverFast(map))
                {
                    needLOSToCell2 = intVec;
                }
            }
            else if (direction < 180f)
            {
                if (intVec.InBounds(map) && intVec.CanBeSeenOverFast(map))
                {
                    needLOSToCell1 = intVec;
                }
                if (intVec4.InBounds(map) && intVec4.CanBeSeenOverFast(map))
                {
                    needLOSToCell2 = intVec4;
                }
            }
            else if (direction < 270f)
            {
                if (intVec4.InBounds(map) && intVec4.CanBeSeenOverFast(map))
                {
                    needLOSToCell1 = intVec4;
                }
                if (intVec2.InBounds(map) && intVec2.CanBeSeenOverFast(map))
                {
                    needLOSToCell2 = intVec2;
                }
            }
            else
            {
                if (intVec2.InBounds(map) && intVec2.CanBeSeenOverFast(map))
                {
                    needLOSToCell1 = intVec2;
                }
                if (intVec3.InBounds(map) && intVec3.CanBeSeenOverFast(map))
                {
                    needLOSToCell2 = intVec3;
                }
            }
        }
コード例 #5
0
        public static bool LineOfSight(IntVec3 start, IntVec3 end, Map map, CellRect startRect, CellRect endRect, Func <IntVec3, bool> validator = null)
        {
            bool result;

            if (!start.InBounds(map) || !end.InBounds(map))
            {
                result = false;
            }
            else
            {
                bool flag;
                if (start.x == end.x)
                {
                    flag = (start.z < end.z);
                }
                else
                {
                    flag = (start.x < end.x);
                }
                int num  = Mathf.Abs(end.x - start.x);
                int num2 = Mathf.Abs(end.z - start.z);
                int num3 = start.x;
                int num4 = start.z;
                int i    = 1 + num + num2;
                int num5 = (end.x <= start.x) ? -1 : 1;
                int num6 = (end.z <= start.z) ? -1 : 1;
                int num7 = num - num2;
                num  *= 2;
                num2 *= 2;
                IntVec3 intVec = default(IntVec3);
                while (i > 1)
                {
                    intVec.x = num3;
                    intVec.z = num4;
                    if (endRect.Contains(intVec))
                    {
                        return(true);
                    }
                    if (!startRect.Contains(intVec))
                    {
                        if (!intVec.CanBeSeenOverFast(map))
                        {
                            return(false);
                        }
                        if (validator != null && !validator(intVec))
                        {
                            return(false);
                        }
                    }
                    if (num7 > 0 || (num7 == 0 && flag))
                    {
                        num3 += num5;
                        num7 -= num2;
                    }
                    else
                    {
                        num4 += num6;
                        num7 += num;
                    }
                    i--;
                }
                result = true;
            }
            return(result);
        }