AlertSpeaker.Building_AlertSpeaker.CheckIfSupportingWallIsAlive C# (CSharp) Method

CheckIfSupportingWallIsAlive() public static method

Checks if the wall supporting the alert speaker is still alive.
public static CheckIfSupportingWallIsAlive ( IntVec3 alertSpeakerPosition, Rot4 alertSpeakerRotation ) : bool
alertSpeakerPosition IntVec3
alertSpeakerRotation Rot4
return bool
        public static bool CheckIfSupportingWallIsAlive(IntVec3 alertSpeakerPosition, Rot4 alertSpeakerRotation)
        {
            IntVec3 wallPosition = alertSpeakerPosition + new IntVec3(0, 0, -1).RotatedBy(alertSpeakerRotation);
            
            // Built wall.
            if (Find.ThingGrid.ThingAt(wallPosition, ThingDefOf.Wall) != null)
            {
                return true;
            }

            // Natural block.
            Thing potentialWall = Find.ThingGrid.ThingAt(wallPosition, ThingCategory.Building);
            if (potentialWall != null)
            {
                if ((potentialWall as Building).def.building.isNaturalRock)
                {
                    return true;
                }
            }
            // No wall.
            return false;
        }
        

Usage Example

Example #1
0
        /// <summary>
        /// Checks if a new alert speaker can be built at this location.
        /// - must be near a wall,
        /// - must not be too near from another alert speaker.
        /// </summary>
        public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot)
        {
            IntVec3 potentialWallPosition = loc;

            // Check if another alert speaker is not too close.
            List <Thing> alertSpeakerList          = Find.ListerThings.ThingsOfDef(ThingDef.Named("AlertSpeaker"));
            List <Thing> alertSpeakerBlueprintList = Find.ListerThings.ThingsOfDef(ThingDef.Named("AlertSpeaker").blueprintDef);
            List <Thing> alertSpeakerFrameList     = Find.ListerThings.ThingsOfDef(ThingDef.Named("AlertSpeaker").frameDef);

            if (alertSpeakerList != null)
            {
                IEnumerable <Thing> alertSpeakerInTheArea = alertSpeakerList.Where(building => loc.InHorDistOf(building.Position, minDistanceBetweenTwoAlertSpeakers));
                if (alertSpeakerInTheArea.Count() > 0)
                {
                    return(new AcceptanceReport("An other alert speaker is too close."));
                }
            }
            if (alertSpeakerBlueprintList != null)
            {
                IEnumerable <Thing> alertSpeakerBlueprintInTheArea = alertSpeakerBlueprintList.Where(building => loc.InHorDistOf(building.Position, minDistanceBetweenTwoAlertSpeakers));
                if (alertSpeakerBlueprintInTheArea.Count() > 0)
                {
                    return(new AcceptanceReport("An other alert speaker blueprint is too close."));
                }
            }
            if (alertSpeakerFrameList != null)
            {
                IEnumerable <Thing> alertSpeakerFrameInTheArea = alertSpeakerFrameList.Where(building => loc.InHorDistOf(building.Position, minDistanceBetweenTwoAlertSpeakers));
                if (alertSpeakerFrameInTheArea.Count() > 0)
                {
                    return(new AcceptanceReport("An other alert speaker frame is too close."));
                }
            }

            // Check it is built near a wall.
            if (Building_AlertSpeaker.CheckIfSupportingWallIsAlive(loc, rot) == false)
            {
                return(new AcceptanceReport("Alert speaker must be built near a wall."));
            }

            // Display effect zone.
            if (Find.ThingGrid.CellContains(loc, ThingCategory.Building) == false)
            {
                List <IntVec3> cellsInEffectZone = Building_AlertSpeaker.GetEffectZoneCells(loc);
                GenDraw.DrawFieldEdges(cellsInEffectZone);
            }

            return(true);
        }
All Usage Examples Of AlertSpeaker.Building_AlertSpeaker::CheckIfSupportingWallIsAlive