public override void Tick() { // If the pod is inflight, slight ending delay here to stop smoke motes covering the crash if (ticksToImpact > 8) { // Throw some smoke and fire glow trails MoteThrower.ThrowSmoke(DrawPos, 3f); MoteThrower.ThrowFireGlow(DrawPos.ToIntVec3(), 1.5f); } this.ticksToImpact--; if (ticksToImpact <= 0) { PodImpact(); } if (!soundPlayed && ticksToImpact < 100) { soundPlayed = true; SoundDefOf.DropPodFall.PlayOneShot(Position); } }
private void PodImpact() { // max side length of drawSize or actual size determine result crater radius var impactRadius = Mathf.Max(Mathf.Max(def.Size.x, def.Size.z), Mathf.Max(Graphic.drawSize.x, Graphic.drawSize.y)) * 1.5f; for (int i = 0; i < 6; i++) { Vector3 loc = Position.ToVector3Shifted() + Gen.RandomHorizontalVector(1f); MoteThrower.ThrowDustPuff(loc, 1.2f); } // Create a crashed drop pod DropPodCrashed dropPod = (DropPodCrashed)ThingMaker.MakeThing(ThingDef.Named("DropPodCrashed"), null); dropPod.info = contents; dropPod.SetFactionDirect(factionDirect); // Spawn the crater var crater = (Crater)ThingMaker.MakeThing(ThingDef.Named("Crater")); // adjust result crater size to the impact zone radius crater.impactRadius = impactRadius; // spawn the crater, rotated to the random angle, to provide visible variety GenSpawn.Spawn(crater, Position, Rot4.North); // Spawn the crashed drop pod GenSpawn.Spawn(dropPod, Position, Rotation); // For all cells around the crater centre point based on half its diameter (radius) foreach (IntVec3 current in GenRadial.RadialCellsAround(crater.Position, impactRadius, true)) { // List all things found in these cells List <Thing> list = Find.ThingGrid.ThingsListAt(current); // Reverse iterate through the things so we can destroy without breaking the pointer for (int i = list.Count - 1; i >= 0; i--) { // If its a plant, filth, or an item if (list[i].def.category == ThingCategory.Plant || list[i].def.category == ThingCategory.Filth || list[i].def.category == ThingCategory.Item) { // Destroy it list[i].Destroy(); } } } RoofDef roof = Position.GetRoof(); if (roof != null) { if (!roof.soundPunchThrough.NullOrUndefined()) { roof.soundPunchThrough.PlayOneShot(Position); } if (roof.filthLeaving != null) { for (int j = 0; j < 3; j++) { FilthMaker.MakeFilth(Position, roof.filthLeaving, 1); } } } // Do a bit of camera shake for added effect CameraShaker.DoShake(0.020f); // Fire an explosion with motes GenExplosion.DoExplosion(Position, 0.5f, DamageDefOf.Bomb, this, null, null, null, null, 0f, false, null, 0f); CellRect cellRect = CellRect.CenteredOn(Position, 2); cellRect.ClipInsideMap(); for (int i = 0; i < 5; i++) { IntVec3 randomCell = cellRect.RandomCell; MoteThrower.ThrowFireGlow(DrawPos.ToIntVec3(), 1.5f); } this.Destroy(DestroyMode.Vanish); }