Example #1
0
        /// <summary>
        /// Get the farthest position from the turret in direction of spotlightTarget.
        /// </summary>
        public IntVec3 GetFarthestPositionInSight(IntVec3 spotlightTarget)
        {
            IntVec3 farthestPosition = this.Position;

            Mathf.Clamp(spotlightTarget.x, 0, this.Map.Size.x);
            Mathf.Clamp(spotlightTarget.z, 0, this.Map.Size.z);

            IEnumerable <IntVec3> lineOfSightPoints = GenSight.PointsOnLineOfSight(this.Position, spotlightTarget);

            foreach (IntVec3 point in lineOfSightPoints)
            {
                if (point.CanBeSeenOverFast(this.Map) == false)
                {
                    // Return last non-blocked position.
                    return(farthestPosition);
                }
                farthestPosition = point; // Store last valid point in sight.
            }
            if (spotlightTarget.CanBeSeenOverFast(this.Map))
            {
                // Nothing is blocking.
                return(spotlightTarget);
            }
            else
            {
                // Target position is blocked. Return last non-blocked position.
                return(farthestPosition);
            }
        }
Example #2
0
        //Exact copy (1.1)
        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 = new IntVec3?(intVec3);
                }
                if (intVec.InBounds(map) && intVec.CanBeSeenOverFast(map))
                {
                    needLOSToCell2 = new IntVec3?(intVec);
                    return;
                }
            }
            else if (direction < 180f)
            {
                if (intVec.InBounds(map) && intVec.CanBeSeenOverFast(map))
                {
                    needLOSToCell1 = new IntVec3?(intVec);
                }
                if (intVec4.InBounds(map) && intVec4.CanBeSeenOverFast(map))
                {
                    needLOSToCell2 = new IntVec3?(intVec4);
                    return;
                }
            }
            else if (direction < 270f)
            {
                if (intVec4.InBounds(map) && intVec4.CanBeSeenOverFast(map))
                {
                    needLOSToCell1 = new IntVec3?(intVec4);
                }
                if (intVec2.InBounds(map) && intVec2.CanBeSeenOverFast(map))
                {
                    needLOSToCell2 = new IntVec3?(intVec2);
                    return;
                }
            }
            else
            {
                if (intVec2.InBounds(map) && intVec2.CanBeSeenOverFast(map))
                {
                    needLOSToCell1 = new IntVec3?(intVec2);
                }
                if (intVec3.InBounds(map) && intVec3.CanBeSeenOverFast(map))
                {
                    needLOSToCell2 = new IntVec3?(intVec3);
                }
            }
        }
Example #3
0
            private bool IsClear(IntVec3 c, bool inside)
            {
                bool result = Affected(c) && c.CanBeSeenOverFast(map) && (inside || !map.roofGrid.Roofed(c) || c.IsTransparentRoof(map));

                return(result);
            }