//Removed minimum collision distance
        private bool CheckForCollisionBetween()
        {
            var lastPosIV3 = LastPos.ToIntVec3();
            var newPosIV3  = ExactPosition.ToIntVec3();

            List <Thing> list = base.Map.listerThings.ThingsInGroup(ThingRequestGroup.ProjectileInterceptor);

            for (int i = 0; i < list.Count; i++)
            {
                if (CheckIntercept(list[i], list[i].TryGetComp <CompProjectileInterceptor>()))
                {
                    this.Destroy(DestroyMode.Vanish);
                    return(true);
                }
            }

            #region Sanity checks
            if (ticksToImpact == 0 || def.projectile.flyOverhead)
            {
                return(false);
            }

            if (!lastPosIV3.InBounds(Map) || !newPosIV3.InBounds(Map))
            {
                return(false);
            }

            if (Controller.settings.DebugDrawInterceptChecks)
            {
                Map.debugDrawer.FlashLine(lastPosIV3, newPosIV3);
            }
            #endregion

            // Iterate through all cells between the last and the new position
            // INCLUDING[!!!] THE LAST AND NEW POSITIONS!
            var cells = GenSight.PointsOnLineOfSight(lastPosIV3, newPosIV3).Union(new[] { lastPosIV3, newPosIV3 }).Distinct().OrderBy(x => (x.ToVector3Shifted() - LastPos).MagnitudeHorizontalSquared());

            //Order cells by distance from the last position
            foreach (var cell in cells)
            {
                if (CheckCellForCollision(cell))
                {
                    return(true);
                }

                if (Controller.settings.DebugDrawInterceptChecks)
                {
                    Map.debugDrawer.FlashCell(cell, 1, "o");
                }
            }

            return(false);
        }
Beispiel #2
0
        public override void Tick()
        {
            base.Tick();
            if (landed)
            {
                return;
            }
            LastPos = ExactPosition;
            ticksToImpact--;
            if (!ExactPosition.InBounds(Map))
            {
                Position = LastPos.ToIntVec3();
                Destroy();
                return;
            }
            if (CheckForCollisionBetween())
            {
                return;
            }
            Position = ExactPosition.ToIntVec3();
            if (ticksToImpact == 60 && Find.TickManager.CurTimeSpeed == TimeSpeed.Normal &&
                def.projectile.soundImpactAnticipate != null)
            {
                def.projectile.soundImpactAnticipate.PlayOneShot(this);
            }
            //TODO : It appears that the final steps in the arc (past ticksToImpact == 0) don't CheckForCollisionBetween.
            if (ticksToImpact <= 0)
            {
                ImpactSomething();
                return;
            }
            if (ambientSustainer != null)
            {
                ambientSustainer.Maintain();
            }

            if (def.HasModExtension <TrailerProjectileExtension>())
            {
                var trailer = def.GetModExtension <TrailerProjectileExtension>();
                if (trailer != null)
                {
                    if (ticksToImpact % trailer.trailerMoteInterval == 0)
                    {
                        for (int i = 0; i < trailer.motesThrown; i++)
                        {
                            TrailThrower.ThrowSmoke(DrawPos, trailer.trailMoteSize, Map, trailer.trailMoteDef);
                        }
                    }
                }
            }
        }
 public override void Tick()
 {
     base.Tick();
     if (landed)
     {
         return;
     }
     LastPos = ExactPosition;
     ticksToImpact--;
     if (!ExactPosition.InBounds(base.Map))
     {
         Position = LastPos.ToIntVec3();
         Destroy(DestroyMode.Vanish);
         return;
     }
     if (ticksToImpact >= 0 &&
         !def.projectile.flyOverhead &&
         CheckForCollisionBetween())
     {
         return;
     }
     Position = ExactPosition.ToIntVec3();
     if (ticksToImpact == 60 && Find.TickManager.CurTimeSpeed == TimeSpeed.Normal &&
         def.projectile.soundImpactAnticipate != null)
     {
         def.projectile.soundImpactAnticipate.PlayOneShot(this);
     }
     //TODO : It appears that the final steps in the arc (past ticksToImpact == 0) don't CheckForCollisionBetween.
     if (ticksToImpact <= 0)
     {
         ImpactSomething();
         return;
     }
     if (ambientSustainer != null)
     {
         ambientSustainer.Maintain();
     }
 }
        //Removed minimum collision distance
        private bool CheckForCollisionBetween()
        {
            var lastPosIV3 = LastPos.ToIntVec3();
            var newPosIV3  = ExactPosition.ToIntVec3();

            #region Sanity checks
            if (!lastPosIV3.InBounds(base.Map) || !newPosIV3.InBounds(base.Map))
            {
                return(false);
            }

            if (DebugViewSettings.drawInterceptChecks)
            {
                Map.debugDrawer.FlashLine(lastPosIV3, newPosIV3);
            }
            #endregion

            // Iterate through all cells between the last and the new position
            // INCLUDING[!!!] THE LAST AND NEW POSITIONS!
            var cells = GenSight.PointsOnLineOfSight(lastPosIV3, newPosIV3).Union(new [] { lastPosIV3, newPosIV3 }).Distinct().OrderBy(x => (x.ToVector3Shifted() - LastPos).MagnitudeHorizontalSquared());

            //Order cells by distance from the last position
            foreach (IntVec3 cell in cells)
            {
                if (CheckCellForCollision(cell))
                {
                    return(true);
                }

                if (DebugViewSettings.drawInterceptChecks)
                {
                    Map.debugDrawer.FlashCell(cell, 1, "o");
                }
            }

            return(false);
        }