Example #1
0
        public bool WillInterceptDropPod(DropPodIncoming dropPodToCheck)
        {
            //Active and Online
            if (!ShieldDefenceSkyActive || !ShieldOnline)
            {
                return(false);
            }

            //Check IFF
            if (ShieldDefenceIFFActive)
            {
                bool _Hostile = dropPodToCheck.Contents.innerContainer.Any(x => x.Faction == null || x.Faction.AllyOrNeutralTo(Faction.OfPlayer));

                if (!_Hostile)
                {
                    return(true);
                }
            }

            //Check Distance
            float _Distance = Vector3.Distance(dropPodToCheck.Position.ToVector3(), parent.Position.ToVector3());
            float _Radius   = ShieldRadius_Current;

            if (_Distance > _Radius)
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Apply scenario part post map generation.
        /// </summary>
        /// <param name="map">Supplied map.</param>
        public override void PostMapGenerate(Map map)
        {
            //Iterate through starting pawns.
            foreach (Pawn pawn in map.mapPawns.PawnsInFaction(Faction.OfPlayer))
            {
                ApplyToPawn(pawn, map);
            }

            //Iterate through incoming drop pods.
            foreach (Thing pod in map.listerThings.ThingsInGroup(ThingRequestGroup.ActiveDropPod))
            {
                DropPodIncoming dropPod = pod as DropPodIncoming;
                if (dropPod != null)
                {
                    foreach (Thing thing in dropPod.Contents.innerContainer.AsEnumerable())
                    {
                        Pawn pawn = thing as Pawn;
                        if (pawn != null)
                        {
                            ApplyToPawn(pawn, map);
                        }
                    }
                }
            }
        }
        public static Boolean ImpactPrefix(ref DropPodIncoming __instance)
        {
            //Log.Message("Impact");


            //This looks to include the Player Faction as Bring Friendly to Itself.
            bool _Hostile = __instance.Contents.innerContainer.Any(x => x.Faction.HostileTo(Faction.OfPlayer));

            if (__instance.Map.GetComponent <ShieldManagerMapComp>().WillDropPodBeIntercepted(__instance, _Hostile))
            {
                {
                    for (int i = 0; i < 6; i++)
                    {
                        Vector3 loc = __instance.Position.ToVector3Shifted() + Gen.RandomHorizontalVector(1f);
                        MoteMaker.ThrowDustPuff(loc, __instance.Map, 1.2f);
                    }
                    MoteMaker.ThrowLightningGlow(__instance.Position.ToVector3Shifted(), __instance.Map, 2f);

                    GenExplosion.DoExplosion(__instance.Position, __instance.Map, 2, DamageDefOf.Burn, __instance);
                    __instance.Destroy();

                    //Retuen False so the origional method is not executed.
                    return(false);
                }
            }
            return(true);
        }
Example #4
0
 /// <summary>
 /// Notify the SAM site that a target has been destroyed or missed.
 /// </summary>
 public void NotifyTargetIsDestroyedOrMissed(DropPodIncoming dropPod)
 {
     if (this.acquiredTargets.Contains(dropPod))
     {
         this.acquiredTargets.Remove(dropPod);
     }
 }
Example #5
0
        public void destoryAir(Thing t)
        {
            if (t is DropPodIncoming)
            {
                List <Thing>    leftthing = new List <Thing>();
                DropPodIncoming dp        = t as DropPodIncoming;
                for (int i = dp.Contents.innerContainer.Count - 1; i >= 0; i--)
                {
                    Thing thing = dp.Contents.innerContainer[i];
                    if (thing is Pawn)
                    {
                        Pawn p = thing as Pawn;
                        p.Kill(null, null);
                        //Corpse cp = ((Corpse)ThingMaker.MakeThing(p.RaceProps.corpseDef,null));
                        //cp.InnerPawn = p;
                        //cp.GetComp<CompRottable>().RotImmediately();

                        //leftthing.Add(cp);
                        leftthing.Add(p);
                    }
                    else
                    {
                        leftthing.Add(thing);
                    }
                }



                Random rr = new Random();
                foreach (Thing tt in leftthing)
                {
                    if (!(tt is Pawn))
                    {
                        int v = rr.Next(100);
                        // Log.Warning(v+"/"+Settings.droppodCargoDropPercentage+"%");
                        if (v >= Settings.droppodCargoDropPercentage)
                        {
                            continue;
                        }
                    }


                    GenPlace.TryPlaceThing(tt, t.Position, this.Map, ThingPlaceMode.Near);


                    SoundStarter.PlayOneShot(SoundDefOf.DropPod_Open, new TargetInfo(tt));
                }
                for (int i = 0; i < 3; i++)
                {
                    Thing sl = ThingMaker.MakeThing(ThingDefOf.ChunkSlagSteel);
                    GenPlace.TryPlaceThing(sl, t.Position, this.Map, ThingPlaceMode.Near);
                }
            }

            t.Destroy();
        }
Example #6
0
 public void InitializeMissileData(Building_SamSite launcher, DropPodIncoming dropPod, Vector3 missileOrigin, Vector3 predictedImpactPosition, int predictedTicksToImpact, bool targetWillBeHit = true)
 {
     this.launcher = launcher;
     this.target   = dropPod;
     this.origin   = missileOrigin;
     this.predictedImpactPosition = predictedImpactPosition;
     this.predictedTicksToImpact  = predictedTicksToImpact;
     this.ticksToImpact           = predictedTicksToImpact;
     this.missileRotation         = (this.predictedImpactPosition - this.origin).AngleFlat();
     this.targetWillBeHit         = targetWillBeHit;
 }
Example #7
0
        private void LookForIncomingDropPod()
        {
            if (Find.TickManager.TicksGame < GenTicks.TickLongInterval)
            {
                // To prevent shooting down initial 3 drop pods.
                return;
            }

            if (this.missilesTicksUntilNextLaunch > 0)
            {
                // Ensure a minimum delay between each missile launch.
                this.missilesTicksUntilNextLaunch--;
                return;
            }
            if (this.missilesLoadedNumber == 0)
            {
                return;
            }

            List <Thing> incomingDropPodsList = Find.ListerThings.ThingsOfDef(ThingDefOf.DropPodIncoming);

            foreach (Thing element in incomingDropPodsList)
            {
                DropPodIncoming dropPod = element as DropPodIncoming;
                int             dropPodTicksToLanding = (int)(typeof(DropPodIncoming).GetField("ticksToImpact", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(dropPod));
                if (dropPodTicksToLanding < 80)
                {
                    continue;
                }
                if (dropPod.contents.containedThings.NullOrEmpty())
                {
                    continue;
                }
                foreach (Thing thing in dropPod.contents.containedThings)
                {
                    if (thing is Pawn)
                    {
                        Pawn pawn = thing as Pawn;
                        if ((pawn.Faction != null) &&
                            pawn.Faction.HostileTo(this.Faction))
                        {
                            if (this.acquiredTargets.Contains(dropPod) == false)
                            {
                                this.acquiredTargets.Add(dropPod);
                                LaunchMissile(dropPod);
                                this.missilesTicksUntilNextLaunch = missilesDelayBetweenLaunches;
                                return;
                            }
                        }
                    }
                }
            }
        }
Example #8
0
        private bool IsAirTarget(Thing t)
        {
            if (t is Projectile)
            {
                Projectile p         = t as Projectile;
                bool       airbullet = p.def.projectile.flyOverhead;

                if (airbullet)
                {
                    // Log.Warning(BulletStore.theBullet.Count+" now");
                    foreach (ProjectileEnd pe in BulletStore.theBullet)
                    {
                        if (pe.shell == p)
                        {
                            // Log.Message("equal!");
                            if (pe.launcher != null)
                            {
                                //   Log.Message("not null");
                                if (pe.launcher.Faction != this.Faction && pe.launcher.Faction.HostileTo(this.Faction))
                                {
                                    //  Log.Message("equal faction!");
                                    // BulletStore.theBullet.Remove(pe);
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }
            else
            if (t is DropPodIncoming)
            {
                DropPodIncoming dp = t as DropPodIncoming;
                for (int i = dp.Contents.innerContainer.Count - 1; i >= 0; i--)
                {
                    Thing thing = dp.Contents.innerContainer[i];
                    if (thing is Pawn)
                    {
                        Pawn p = thing as Pawn;
                        if (p.Faction != this.Faction && p.Faction.HostileTo(this.Faction))
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }



            return(false);
        }
        public bool WillDropPodBeIntercepted(DropPodIncoming dropPodToTest)
        {
            IEnumerable <Building_Shield> _ShieldBuildings = map.listerBuildings.AllBuildingsColonistOfClass <Building_Shield>();

            if (_ShieldBuildings.Any(x => x.WillInterceptDropPod(dropPodToTest)))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        //---added--- inspired by Frontier Security's method (distributed under an open-source non-profit license)
        public static bool CheckPodHostility(DropPodIncoming dropPod)  //this is me. Didn't want to zap trader deliveries or allies
        {
            var innerContainer = dropPod.Contents.innerContainer;

            for (int i = 0; i < innerContainer.Count; i++)
            {
                if (innerContainer[i] is Pawn pawn)
                {
                    if (GenHostility.IsActiveThreatToPlayer(pawn) || pawn.RaceProps.IsMechanoid)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #11
0
        // prefix
        // - wants instance, result and count
        // - wants to change count
        // - returns a boolean that controls if original is executed (true) or not (false)
        public static Boolean DropPodIncomingImpactPrefix(ref DropPodIncoming __instance)
        {
            Log.Message("Dp incoming called.");

            if (__instance.Map.GetComponent <ShieldManagerMapComp>().WillDropPodBeIntercepted(__instance)) // if the droppod is being intercepted, prevent it from spawning the contents.
            {
                __instance.innerContainer.ClearAndDestroyContents(DestroyMode.Vanish);
                SkyfallerShrapnelUtility.MakeShrapnel(__instance.Position, __instance.Map, __instance.shrapnelDirection, __instance.def.skyfaller.shrapnelDistanceFactor, 3, 0, true);
                Find.CameraDriver.shaker.DoShake(__instance.def.skyfaller.cameraShake);
                SoundStarter.PlayOneShot(DamageDefOf.Bomb.soundExplosion, SoundInfo.InMap(new TargetInfo(__instance.Position, __instance.Map)));
                __instance.Destroy(DestroyMode.Vanish);

                return(false);
            }

            //Retuen False so the origional method is not executed, overriting the false result.
            return(true);
        }
Example #12
0
        private void LaunchMissile(DropPodIncoming dropPod)
        {
            const int ticksToImpactOffsetAverage = 40;

            bool    targetWillBeHit            = true;
            float   landingDistanceCoefficient = 0f;
            Vector3 missPositionOffset;

            // Determine if drop pod will be hit.
            if (Rand.Value < 0.8f)
            {
                targetWillBeHit    = true;
                missPositionOffset = new Vector3(0, 0, 0);
            }
            else
            {
                targetWillBeHit    = false;
                missPositionOffset = new Vector3(5, 0, 5).RotatedBy(Rand.Range(0, 360));
            }

            // Compute predicted target impact position and time.
            int dropPodTicksToLanding  = (int)(typeof(DropPodIncoming).GetField("ticksToImpact", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(dropPod));
            int ticksToImpactOffset    = ticksToImpactOffsetAverage + Rand.RangeInclusive(-10, 10);
            int predictedTicksToImpact = dropPodTicksToLanding - ticksToImpactOffset;

            landingDistanceCoefficient = (float)(ticksToImpactOffset * ticksToImpactOffset) * 0.01f;
            Vector3        predictedImpactPosition = dropPod.Position.ToVector3ShiftedWithAltitude(AltitudeLayer.FlyingItem) + new Vector3(-landingDistanceCoefficient * 0.4f, 0, +landingDistanceCoefficient * 0.6f) + missPositionOffset;
            Projectile_Sam sam = ThingMaker.MakeThing(ThingDef.Named("Sam")) as Projectile_Sam;

            sam.InitializeMissileData(this, dropPod, this.Position.ToVector3Shifted(), predictedImpactPosition, predictedTicksToImpact, targetWillBeHit);
            GenSpawn.Spawn(sam, this.Position);
            this.missilesLoadedNumber--;

            // Update turret rotation.
            this.patrolTicksToNextRotation = patrolRotationIntervalMin;
            this.turretRotation            = (predictedImpactPosition - this.DrawPos).AngleFlat();
            StopRotationSound();

            // Throw smoke and play missile launch sound.
            MoteMaker.ThrowSmoke(this.DrawPos, 2f);
            SoundInfo infos = SoundInfo.InWorld(this);

            OG_Util.MissileLaunchSoundDef.PlayOneShot(infos);
        }
Example #13
0
 private static bool HandlePod(DropPodIncoming pod)
 {
     try
     {
         if (pod.Map.GetComponent <ShieldManager>().Block(PositionUtility.ToVector3WithY(pod.Position, 0), Mod.Settings.DropPodDamage))
         {
             // OfType<Pawn>() causes weirdness here
             foreach (var pawn in pod.Contents.innerContainer.Where(p => p is Pawn).Select(p => (Pawn)p))
             {
                 KillPawn(pawn, pod.Position, pod.Map);
             }
             pod.Destroy();
             Messages.Message("fd.shields.incident.droppod.blocked.body".Translate(), new GlobalTargetInfo(pod.Position, pod.Map), MessageTypeDefOf.NeutralEvent);
             return(false);
         }
     }
     catch (InvalidOperationException) {}
     return(true);
 }
Example #14
0
        public List <Pawn> isPlayerInside(Thing t)
        {
            List <Pawn> result = new List <Pawn>();

            if (t is DropPodIncoming)
            {
                DropPodIncoming dp = t as DropPodIncoming;
                for (int i = dp.Contents.innerContainer.Count - 1; i >= 0; i--)
                {
                    Thing thing = dp.Contents.innerContainer[i];
                    if (thing is Pawn)
                    {
                        Pawn p = thing as Pawn;
                        if (p.Faction != this.Faction && p.Faction.HostileTo(this.Faction) && p.Faction == Faction.OfPlayer)
                        {
                            result.Add(p);
                        }
                    }
                }
            }
            return(result);
        }
        public bool WillInterceptDropPod(DropPodIncoming dropPodToCheck)
        {
            //Check if can and wants to intercept
            if (!this.IntercepDropPod_Active())
            {
                return(false);
            }

            //Check if online
            if (this.CurrentStatus == EnumShieldStatus.Offline || this.CurrentStatus == EnumShieldStatus.Initilising)
            {
                return(false);
            }


            //Check IFF
            if (this.IdentifyFriendFoe_Active())
            {
                bool _Hostile = dropPodToCheck.Contents.innerContainer.Any(x => x.Faction.HostileTo(Faction.OfPlayer));

                if (!_Hostile)
                {
                    return(false);
                }
            }

            //Check Distance
            float _Distance = Vector3.Distance(dropPodToCheck.Position.ToVector3(), this.parent.Position.ToVector3());
            float _Radius   = this.FieldRadius_Active();

            if (_Distance > _Radius)
            {
                return(false);
            }

            //All Tests passed so intercept the pod
            return(true);
        }
Example #16
0
 public bool WillInterceptDropPod(DropPodIncoming dropPodToCheck)
 {
     return(this.GetComp <Comp_ShieldGenerator>().WillInterceptDropPod(dropPodToCheck));
 }