Exemple #1
0
        protected override void Detonate()
        {
            var map      = parentMap;
            var position = parentPosition;

            base.Detonate();
            if (map == null)
            {
                return;
            }
            var explosiveProps = props as CompProperties_Explosive;

            if (explosiveProps == null)
            {
                return;
            }
            var  canAffectThickRoof   = RemoteExplosivesUtility.IsEffectiveRoofBreakerPlacement(explosiveProps.explosiveRadius, position, map);
            bool anyThickRoofAffected = false;

            foreach (var cell in GenRadial.RadialCellsAround(position, explosiveProps.explosiveRadius, true))
            {
                if (!cell.InBounds(map))
                {
                    continue;
                }
                var roof = map.roofGrid.RoofAt(cell);
                if (roof == null || (roof.isThickRoof && !canAffectThickRoof))
                {
                    continue;
                }
                if (roof.filthLeaving != null)
                {
                    for (int j = 0; j < RoofFilthAmount; j++)
                    {
                        FilthMaker.MakeFilth(cell, map, roof.filthLeaving);
                    }
                }
                if (roof.isThickRoof)
                {
                    anyThickRoofAffected = true;
                    map.roofGrid.SetRoof(cell, null);
                    var roofCell = cell;
                    HugsLibController.Instance.CallbackScheduler.ScheduleCallback(() => {                     // delay collapse for more interesting visual effect
                        CollapseRockOnCell(roofCell, map);
                        SoundDefOf.RoofCollapse.PlayOneShot(new TargetInfo(roofCell, map));
                    }, CollapseDelay.RandomInRange);
                }
            }
            if (anyThickRoofAffected)
            {
                Resources.Sound.RemoteMiningCavein.PlayOneShot(new TargetInfo(position, map));
            }
        }
        public override void DrawGhost(ThingDef def, IntVec3 center, Rot4 rot)
        {
            var effectiveRadius = RemoteExplosivesUtility.TryGetExplosiveRadius(def);

            if (effectiveRadius <= 0)
            {
                return;
            }
            var roofGrid = Map.roofGrid;

            effectiveRadiusCells.Clear();
            overheadMountainCells.Clear();
            var effectiveRadiusNumCells   = GenRadial.NumCellsInRadius(effectiveRadius);
            var roofDisplayRadiusNumCells = GenRadial.NumCellsInRadius(effectiveRadius + AdditionalRoofDisplayRadius);

            // collect cells to display
            for (int i = 0; i < roofDisplayRadiusNumCells; i++)
            {
                var cell = center + GenRadial.RadialPattern[i];
                if (!cell.InBounds(Map))
                {
                    continue;
                }
                var roof = roofGrid.RoofAt(cell);
                if (roof != null && roof.isThickRoof)
                {
                    overheadMountainCells.Add(cell);
                }
                var cellInsideEffectiveRadius = i < effectiveRadiusNumCells;
                if (cellInsideEffectiveRadius)
                {
                    effectiveRadiusCells.Add(cell);
                }
            }
            if (overheadMountainCells.Count > 0 && Find.Selector.NumSelected <= 1)               // don't draw overlay when multple charges are selected
            {
                GenDraw.DrawFieldEdges(overheadMountainCells, Color.white);
            }
            var effectiveRadiusColor = RemoteExplosivesUtility.IsEffectiveRoofBreakerPlacement(effectiveRadius, center, Map) ? EffectivePlacementColor : IneffectivePlacementColor;

            GenDraw.DrawFieldEdges(effectiveRadiusCells, effectiveRadiusColor);
        }