コード例 #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   = RemoteTechUtility.IsEffectiveRoofBreakerPlacement(explosiveProps.explosiveRadius, position, map, false);
            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.TryMakeFilth(cell, map, roof.filthLeaving);
                    }
                }
                if (roof.isThickRoof)
                {
                    anyThickRoofAffected = true;
                    var roofCell = cell;
                    HugsLibController.Instance.TickDelayScheduler.ScheduleCallback(() => {                     // delay collapse for more interesting visual effect
                        CollapseRockOnCell(roofCell, map);
                        SoundDefOf.Roof_Collapse.PlayOneShot(new TargetInfo(roofCell, map));
                    }, CollapseDelay.RandomInRange);
                }
                map.roofGrid.SetRoof(cell, null);
            }
            if (anyThickRoofAffected)
            {
                Resources.Sound.rxMiningCavein.PlayOneShot(new TargetInfo(position, map));
            }
        }
        public override void DrawGhost(ThingDef def, IntVec3 center, Rot4 rot, Color ghostCol, Thing thing = null)
        {
            var ownEffectiveRadius = RemoteTechUtility.TryGetExplosiveRadius(def);
            var map = Find.CurrentMap;

            if (map == null || ownEffectiveRadius <= 0)
            {
                return;
            }
            if (Find.Selector.NumSelected <= 1)
            {
                // highlight nearby thick mountain roof cells
                var fogGrid  = map.fogGrid;
                var roofGrid = map.roofGrid;
                GatherCellsInRadius(center, map, ownEffectiveRadius + AdditionalRoofDisplayRadius,
                                    cell => fogGrid.IsFogged(cell) || (roofGrid.RoofAt(cell)?.isThickRoof ?? false)
                                    );
                OverlayDrawer.DrawFieldEdges(cellBuffer, ThickRoofHighlightColor);

                void DrawMatchingEdgesAroundThing(Thing t)
                {
                    GatherCellsInRadius(t.Position, map, ownEffectiveRadius);
                    OverlayDrawer.DrawSolidField(cellBuffer, OtherEffectiveAreasColor);
                }

                // highlight effective areas of already built charges of same type
                var colonistBuildings = map.listerBuildings.allBuildingsColonist;
                for (var i = 0; i < colonistBuildings.Count; i++)
                {
                    if (colonistBuildings[i]?.def == def)
                    {
                        DrawMatchingEdgesAroundThing(colonistBuildings[i]);
                    }
                }
                // highlight effective areas of blueprints for charges of same type
                var blueprints = map.listerThings.ThingsMatching(ThingRequest.ForGroup(ThingRequestGroup.Blueprint));
                for (var i = 0; i < blueprints.Count; i++)
                {
                    if (blueprints[i]?.def?.entityDefToBuild == def)
                    {
                        DrawMatchingEdgesAroundThing(blueprints[i]);
                    }
                }
            }
            // highlight own effective radius with color-coded effectiveness
            var effectiveRadiusColor = RemoteTechUtility.IsEffectiveRoofBreakerPlacement(ownEffectiveRadius, center, map, true)
                                ? EffectivePlacementColor
                                : IneffectivePlacementColor;

            GatherCellsInRadius(center, map, ownEffectiveRadius);
            OverlayDrawer.DrawFieldEdges(cellBuffer, effectiveRadiusColor);
        }