/// <summary>
        /// Check if there is enough food in the adjacent aquaculture hoppers.
        /// </summary>
        public bool IsEnoughFoodInHopper()
        {
            int availableFoodSum = 0;

            foreach (IntVec3 cell in GenAdj.CellsAdjacentCardinal(this))
            {
                Thing        food = null;
                Thing        aquacultureHopper = null;
                List <Thing> thingList         = cell.GetThingList(this.Map);
                for (int thingIndex = 0; thingIndex < thingList.Count; thingIndex++)
                {
                    Thing currentThing = thingList[thingIndex];
                    if (currentThing.def == Util_FishIndustry.AquacultureHopperDef)
                    {
                        aquacultureHopper = currentThing;
                    }
                    if (IsAcceptableFeedstock(currentThing.def))
                    {
                        food = currentThing;
                    }
                }
                if (aquacultureHopper != null && food != null)
                {
                    availableFoodSum += food.stackCount;
                    if (availableFoodSum >= this.def.building.nutritionCostPerDispense)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 2
0
        private void NetUpdate()
        {
            this.newComps
            .SelectMany(c => GenAdj.CellsAdjacentCardinal(c.parent))
            .Where(c => c.InBounds(this.map))
            .SelectMany(c => Option(this.grid.NetAt(c)))
            .ForEach(this.DeleteNet);

            this.oldComps
            .SelectMany(c => Option(this.grid.NetAt(c.parent.Position)))
            .ForEach(this.DeleteNet);

            this.newComps
            .Select(c => new { Comp = c, Net = Option(this.grid.NetAt(c.parent.Position)) })
            .Where(r => !r.Net.HasValue)
            .ForEach(r => this.RegisterNet(AutomationNetMaker.NewNetStartingFrom((Building)r.Comp.parent, this.map)));

            this.oldComps
            .SelectMany(c => GenAdj.CellsAdjacentCardinal(c.parent))
            .Where(c => c.InBounds(this.map))
            .SelectMany(c => c.GetThingList(this.map)
                        .SelectMany(t => Option(t as Building))
                        .Where(b => b.TryGetComp <CompAutomation>() != null)
                        .FirstOption()
                        )
            .ForEach(b => this.RegisterNet(AutomationNetMaker.NewNetStartingFrom(b, this.map)));

            this.newComps.Clear();
            this.oldComps.Clear();
        }
Esempio n. 3
0
 public static bool FindFeedInAnyCustomHopper(Building_NutrientPasteDispenser __instance, ref Thing __result, ref List <IntVec3> ___cachedAdjCellsCardinal)
 {
     if (___cachedAdjCellsCardinal is null)
     {
         ___cachedAdjCellsCardinal = (from c in GenAdj.CellsAdjacentCardinal(__instance)
                                      where c.InBounds(__instance.Map)
                                      select c).ToList <IntVec3>();
     }
     foreach (IntVec3 c in ___cachedAdjCellsCardinal)
     {
         Thing        thing     = null;
         Thing        thing2    = null;
         List <Thing> thingList = c.GetThingList(__instance.Map);
         foreach (Thing t in thingList)
         {
             if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(t.def))
             {
                 thing = t;
             }
             if (t.def == ThingDefOf.Hopper || t.def.thingClass == typeof(NPDHopper_Storage))
             {
                 thing2 = t;
             }
         }
         if (thing != null && thing2 != null)
         {
             __result = thing;
             return(false);
         }
     }
     __result = null;
     return(true);
 }
Esempio n. 4
0
        public static bool AdjacentReachableHopperCustom(Pawn reacher, Building_NutrientPasteDispenser __instance, ref Building __result,
                                                         List <IntVec3> ___cachedAdjCellsCardinal)
        {
            if (__instance.def.HasModExtension <NutrientPasteCustom>())
            {
                if (___cachedAdjCellsCardinal is null)
                {
                    ___cachedAdjCellsCardinal = (from c in GenAdj.CellsAdjacentCardinal(__instance)
                                                 where c.InBounds(__instance.Map)
                                                 select c).ToList <IntVec3>();
                }
                foreach (IntVec3 c in ___cachedAdjCellsCardinal)
                {
                    Building edifice = c.GetEdifice(__instance.Map);

                    if (!(edifice is null) && (edifice.def == ThingDefOf.Hopper || edifice.def.thingClass == typeof(NPDHopper_Storage)) &&
                        reacher.CanReach(edifice, PathEndMode.Touch, Danger.Deadly, false, TraverseMode.ByPawn))
                    {
                        __result = edifice;
                        return(false);
                    }
                }
            }
            return(true);
        }
        public override AlertReport GetReport()
        {
            List <Map> maps = Find.Maps;

            for (int i = 0; i < maps.Count; i++)
            {
                foreach (Building aquacultureBasin in maps[i].listerBuildings.AllBuildingsColonistOfDef(Util_FishIndustry.AquacultureBasinDef))
                {
                    bool hopperIsFound = false;
                    foreach (IntVec3 adjacentCell in GenAdj.CellsAdjacentCardinal(aquacultureBasin))
                    {
                        Thing edifice = adjacentCell.GetEdifice(maps[i]);
                        if ((edifice != null) &&
                            (edifice.def == ThingDefOf.Hopper))
                        {
                            hopperIsFound = true;
                            break;
                        }
                    }
                    if (hopperIsFound == false)
                    {
                        return(AlertReport.CulpritIs(aquacultureBasin));
                    }
                }
            }
            return(AlertReport.Inactive);
        }
Esempio n. 6
0
        /// <summary>
        /// Check if there is enough food in the adjacent hoppers.
        /// </summary>
        public bool IsEnoughFoodInHoppers()
        {
            float foodSum = 0;

            foreach (IntVec3 cell in GenAdj.CellsAdjacentCardinal(this))
            {
                Thing        food      = null;
                Thing        hopper    = null;
                List <Thing> thingList = cell.GetThingList(this.Map);
                for (int thingIndex = 0; thingIndex < thingList.Count; thingIndex++)
                {
                    Thing currentThing = thingList[thingIndex];
                    if (currentThing.def == ThingDefOf.Hopper)
                    {
                        hopper = currentThing;
                    }
                    if (IsAcceptableFeedstock(currentThing.def))
                    {
                        food = currentThing;
                    }
                }
                if (hopper != null && food != null)
                {
                    foodSum += (float)food.stackCount * food.def.ingestible.nutrition;
                    if (foodSum >= this.def.building.nutritionCostPerDispense)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 7
0
 public static List <Building> ShipBuildingsAttachedTo(Building root)
 {
     closedSet.Clear();
     if (root == null || root.Destroyed)
     {
         return(closedSet);
     }
     openSet.Clear();
     openSet.Add(root);
     while (openSet.Count > 0)
     {
         Building building = openSet[openSet.Count - 1];
         openSet.Remove(building);
         closedSet.Add(building);
         foreach (IntVec3 item in GenAdj.CellsAdjacentCardinal(building))
         {
             Building edifice = item.GetEdifice(building.Map);
             if (edifice != null && edifice.def.building.shipPart && !closedSet.Contains(edifice) && !openSet.Contains(edifice))
             {
                 openSet.Add(edifice);
             }
         }
     }
     return(closedSet);
 }
Esempio n. 8
0
        private void MapUpdateHandler(object sender, MapUpdateWatcher.MapUpdateInfo info)
        {
            var  cell    = info.center;
            bool removed = info.removed;
            bool roof    = sender is RoofGrid;

            if (isFacingSet && roof && cell.IsInterior(this) && !GenAdj.CellsAdjacentCardinal(this).Contains(cell))
            {
                return;
            }
            bool unsureFace = false;

            for (int i = 0; i < scanLines.Count(); i++)
            {
                if (scanLines[i].Affected(cell))
                {
                    IntVec3 motivator = roof ? IntVec3.Zero : cell;
                    var     line      = scanLines[i];
                    bool    before    = line.facingSet;
                    line.FindObstruction(motivator, removed, info.map);
                    unsureFace |= line.facingSet != before;
                    needsUpdate = true;
                }
            }
            if (unsureFace)
            {
                isFacingSet = false;
            }
        }
 public static List <Building> ShipBuildingsAttachedTo(Building root)
 {
     if (root != null && !root.Destroyed)
     {
         ShipUtility.closedSet.Clear();
         ShipUtility.openSet.Clear();
         ShipUtility.openSet.Add(root);
         while (ShipUtility.openSet.Count > 0)
         {
             Building building = ShipUtility.openSet[ShipUtility.openSet.Count - 1];
             ShipUtility.openSet.Remove(building);
             ShipUtility.closedSet.Add(building);
             foreach (IntVec3 item in GenAdj.CellsAdjacentCardinal(building))
             {
                 Building edifice = item.GetEdifice(building.Map);
                 if (edifice != null && edifice.def.building.shipPart && !ShipUtility.closedSet.Contains(edifice) && !ShipUtility.openSet.Contains(edifice))
                 {
                     ShipUtility.openSet.Add(edifice);
                 }
             }
         }
         return(ShipUtility.closedSet);
     }
     return(new List <Building>());
 }
Esempio n. 10
0
 private List <Building_ExhaustPort> GetActiveExhausts()
 {
     return(GenAdj.CellsAdjacentCardinal(this)
            .Select(s => Map.thingGrid.ThingAt <Building_ExhaustPort>(s))
            .Where(thingAt => thingAt != null)
            .Where(s => s.isAvailable)
            .ToList());
 }
Esempio n. 11
0
        public void DeregisterPipe(CompPipe pipe)
        {
            TryDestroyPipeNet(pipe.parent.Position, pipe.PipeType);

            foreach (IntVec3 item in GenAdj.CellsAdjacentCardinal(pipe.parent.Position, pipe.parent.Rotation, pipe.parent.def.size))
            {
                TryCreatePipeNet(item, pipe.PipeType);
            }
        }
Esempio n. 12
0
        private static IEnumerable <CompAir> ContiguousAirBuildings(Building root, NetLayer layer, Map map)
        {
            closedSet.Clear();
            currentSet.Clear();
            openSet.Add(root);

            do
            {
                //Move all opened to closed
                foreach (var current in openSet)
                {
                    closedSet.Add(current);
                }

                var tempSet = currentSet;
                currentSet = openSet;
                openSet    = tempSet;
                openSet.Clear();

                foreach (var things in currentSet.SelectMany(openBuilding =>
                                                             GenAdj.CellsAdjacentCardinal(openBuilding)
                                                             .Select(openCells => openCells.GetThingList(map)))
                         )
                {
                    //All adjacent things
                    foreach (var current in things)
                    {
                        var building = current as Building;
                        var compAir  = building?.TryGetComp <CompAir>();

                        //No adjacent CompAir
                        if (compAir == null)
                        {
                            continue;
                        }
                        //CompAir is not on the same layer
                        if (!compAir.IsLayerOf(layer))
                        {
                            continue;
                        }
                        //Already swept through
                        if (openSet.Contains(building) ||
                            currentSet.Contains(building) ||
                            closedSet.Contains(building))
                        {
                            continue;
                        }

                        openSet.Add(building);
                        break;
                    }
                }
            } while (openSet.Count > 0);

            return(from b in closedSet
                   select b.TryGetComp <CompAir>());
        }
Esempio n. 13
0
        public void RegisterPipe(CompPipe pipe, bool respawningAfterLoad)
        {
            foreach (IntVec3 item in GenAdj.CellsAdjacentCardinal(pipe.parent))
            {
                TryDestroyPipeNet(item, pipe.PipeType);
            }

            TryCreatePipeNet(pipe.parent.Position, pipe.PipeType);
        }
Esempio n. 14
0
 public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null)
 {
     if (!GenAdj.CellsAdjacentCardinal(loc, rot, checkingDef.Size)
         .Any(x => x.Impassable(map) &&
              x.GetThingList(map).Any(y => y.def.holdsRoof && !y.def.IsDoor)))
     {
         return("MustPlaceAgainstWall".Translate());
     }
     return(true);
 }
        // RimWorld.Building_NutrientPasteDispenser
        //static private List<IntVec3> AdjCellsCardinalInBounds(this Building_NutrientPasteDispenser self)
        //{
        //	return (List<IntVec3>)typeof(RimWorld.Building_NutrientPasteDispenser).GetProperty("AdjCellsCardinalInBounds", Helpers.AllBindingFlags).GetValue(self,null);
        //}

        static private List <IntVec3> AdjCellsCardinalInBounds(this Building_NutrientPasteDispenser self)
        {
            if (self.cachedAdjCellsCardinal() == null)
            {
                var value = (from c in GenAdj.CellsAdjacentCardinal(self)
                             where c.InBounds(self.Map)
                             select c).ToList <IntVec3>();

                self.cachedAdjCellsCardinal_set_(value);
            }
            return(self.cachedAdjCellsCardinal());
        }
Esempio n. 16
0
 public override void PostSpawnSetup(bool respawningAfterLoad)
 {
     base.PostSpawnSetup(respawningAfterLoad);
     if (Props.SupportDiagonal)
     {
         possibleOutputs = new List <IntVec3>(GenAdj.CellsAdjacent8Way(parent));
     }
     else
     {
         possibleOutputs = new List <IntVec3>(GenAdj.CellsAdjacentCardinal(parent));
     }
 }
        // Returns a list of touching things by thing comp
        // optionally room bounds
        public static List <Thing> ListSameThingCompTouching(this Thing thing, Type MatchingComp, bool RoomBound = false, List <Thing> cache = null)
        {
            if (cache == null)
            {
                // Create cache on first call
                cache = new List <Thing>();
            }

            if (cache.Contains(thing))
            {
                // Already in list
                return(cache);
            }

            // Add it to the list
            cache.Add(thing);

            List <IntVec3> cells;

            if (RoomBound)
            {
                // Get adjacent cells bound by room
                cells = GenAdj.CellsAdjacentCardinal(thing)
                        .Where(c =>
                               (c.GetRoom() == thing.GetRoom())
                               )
                        .ToList <IntVec3>();
            }
            else
            {
                // Get all adjacent cells
                cells = GenAdj.CellsAdjacentCardinal(thing)
                        .ToList <IntVec3>();
            }

            // Scan cells
            foreach (IntVec3 cell in cells)
            {
                // Add things in cell with matching thing comp
                var things = thing.ListSameThingCompInCell(cell, MatchingComp);
                if ((things != null) &&
                    (things.Count > 0))
                {
                    // Scan things
                    foreach (Thing match in things)
                    {
                        cache = match.ListSameThingCompTouching(MatchingComp, RoomBound, cache);
                    }
                }
            }
            return(cache);
        }
        public static List <CompGas> GetAdjacentGasComps(this CompGas gas, Map map, bool includeSelf = false)
        {
            var cells = GenAdj.CellsAdjacentCardinal(gas.parent).ToList();

            if (includeSelf)
            {
                cells.AddRange(gas.parent.OccupiedRect().Cells);
            }
            return(cells.SelectMany(c => c.GetThingList(map))
                   .Distinct()
                   .TryGetComps <CompGas>()
                   .ToList());
        }
Esempio n. 19
0
        // Get's a group of touching things by linker
        // optionally room bounds
        public static List <Thing> GetGroupOfTouchingByLinker(this Thing parent, bool RoomBound = false, List <Thing> cache = null)
        {
            // First call, cache should be null
            if (cache == null)
            {
                // Create cache
                cache = new List <Thing>();
            }
            // Already in list
            if (cache.Contains(parent))
            {
                return(cache);
            }
            // Add this one too
            cache.Add(parent);

            // Get adjacent cells
            List <IntVec3> adjCells;

            if (RoomBound)
            {
                adjCells = GenAdj.CellsAdjacentCardinal(parent)
                           .Where(c => c.GetRoom() == parent.GetRoom())
                           .ToList <IntVec3>();
            }
            else
            {
                adjCells = GenAdj.CellsAdjacentCardinal(parent)
                           .ToList <IntVec3>();
            }

            // Scan cells
            foreach (IntVec3 adjCell in adjCells)
            {
                // Things in cell which match parent def
                var things = Find.ThingGrid.ThingsAt(adjCell)
                             .Where(thing =>
                                    (thing != null) &&
                                    (thing.def.graphic != null) &&
                                    (thing.def.graphic.data != null) &&
                                    (thing.def.graphic.data.linkFlags == parent.def.graphic.data.linkFlags))
                             .ToList <Thing>();
                // Scan things
                foreach (Thing thing in things)
                {
                    // Add it and scan it
                    cache = thing.GetGroupOfTouchingByLinker(RoomBound, cache);
                }
            }
            return(cache);
        }
Esempio n. 20
0
 private static IEnumerable <CompPower> ContiguousPowerBuildings(Building root)
 {
     PowerNetMaker.closedSet.Clear();
     PowerNetMaker.openSet.Clear();
     PowerNetMaker.currentSet.Clear();
     PowerNetMaker.openSet.Add(root);
     do
     {
         foreach (Building item in PowerNetMaker.openSet)
         {
             PowerNetMaker.closedSet.Add(item);
         }
         HashSet <Building> hashSet = PowerNetMaker.currentSet;
         PowerNetMaker.currentSet = PowerNetMaker.openSet;
         PowerNetMaker.openSet    = hashSet;
         PowerNetMaker.openSet.Clear();
         foreach (Building building in PowerNetMaker.currentSet)
         {
             foreach (IntVec3 c in GenAdj.CellsAdjacentCardinal(building))
             {
                 if (c.InBounds(building.Map))
                 {
                     List <Thing> thingList = c.GetThingList(building.Map);
                     for (int i = 0; i < thingList.Count; i++)
                     {
                         Building building2 = thingList[i] as Building;
                         if (building2 != null)
                         {
                             if (building2.TransmitsPowerNow)
                             {
                                 if (!PowerNetMaker.openSet.Contains(building2) && !PowerNetMaker.currentSet.Contains(building2) && !PowerNetMaker.closedSet.Contains(building2))
                                 {
                                     PowerNetMaker.openSet.Add(building2);
                                     break;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }while (PowerNetMaker.openSet.Count > 0);
     CompPower[] result = (from b in PowerNetMaker.closedSet
                           select b.PowerComp).ToArray <CompPower>();
     PowerNetMaker.closedSet.Clear();
     PowerNetMaker.openSet.Clear();
     PowerNetMaker.currentSet.Clear();
     return(result);
 }
 private void Notify_SupplierSpawned()
 {
     if (Find.ListerBuildings.AllBuildingsColonistOfClass <Building_RepairStation>() != null)
     {
         foreach (var c in GenAdj.CellsAdjacentCardinal(this.parent))
         {
             Building_RepairStation rps = Find.ThingGrid.ThingAt <Building_RepairStation>(c);
             if (rps != null)
             {
                 rps.Notify_SupplierSpawned(this);
                 repairStations.Add(rps);
             }
         }
     }
 }
Esempio n. 22
0
        private void NeighborCheck()
        {
            nextNeighborCheck--;
            if (neighbors != null && nextNeighborCheck > 0)
            {
                return;
            }
            nextNeighborCheck += 100;

            var cells = GenAdj.CellsAdjacentCardinal(this);

            neighbors =
                cells.Select(cell => Find.ThingGrid.ThingAt <Building_PAL_Component>(cell))
                .Where(c => c != null && !c.Destroyed).ToList();
        }
 private void Notify_RepairStationSpawned()
 {
     ListerDroids.RegisterRepairStation(this);
     foreach (var c in GenAdj.CellsAdjacentCardinal(this))
     {
         Building b = Find.ThingGrid.ThingAt <Building>(c);
         if (b != null)
         {
             CompRepairStationSupplier supplier = b.GetComp <CompRepairStationSupplier>();
             if (supplier != null)
             {
                 supplier.Notify_RepairStationSpawned(this);
             }
         }
     }
 }
        public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot)
        {
            ThingDef def = ThingDef.Named("MD2CoalBurner");

            foreach (IntVec3 pos in GenAdj.CellsAdjacentCardinal(loc, Rot4.North, IntVec2.One))
            {
                foreach (Thing thing in Find.ThingGrid.ThingsAt(pos))
                {
                    if (thing.def == def)
                    {
                        return(true);
                    }
                }
            }
            return("Must be placed next to a coal burner");
        }
Esempio n. 25
0
        // Get's a group of touching things by thing comp
        // optionally room bounds
        public static List <Thing> GetGroupOfTouchingByThingComp(this Thing parent, Type RequiredComp, bool RoomBound = false, List <Thing> cache = null)
        {
            // First call, cache should be null
            if (cache == null)
            {
                // Create cache
                cache = new List <Thing>();
            }
            // Already in list
            if (cache.Contains(parent))
            {
                return(cache);
            }
            // Add this one too
            cache.Add(parent);

            // Get adjacent cells
            List <IntVec3> adjCells;

            if (RoomBound)
            {
                adjCells = GenAdj.CellsAdjacentCardinal(parent)
                           .Where(c => c.GetRoom() == parent.GetRoom())
                           .ToList <IntVec3>();
            }
            else
            {
                adjCells = GenAdj.CellsAdjacentCardinal(parent)
                           .ToList <IntVec3>();
            }

            // Scan cells
            foreach (IntVec3 adjCell in adjCells)
            {
                // Things in cell which match parent def
                var things = Find.ThingGrid.ThingsAt(adjCell)
                             .Where(thing => ((thing as ThingWithComps) != null) && (((ThingWithComps)thing).AllComps.Where(tc => tc.GetType() == RequiredComp).ToList().Count > 0))
                             .ToList <Thing>();
                // Scan things
                foreach (ThingWithComps thing in things)
                {
                    // Add it and scan it
                    cache = thing.GetGroupOfTouchingByThingComp(RequiredComp, RoomBound, cache);
                }
            }
            return(cache);
        }
Esempio n. 26
0
        public void Dig()
        {
            if (HasPower && HasFissure)
            {
                //Get the number to spawn
                int num = (int)(Rand.Range(availableList[resourceIndex].spawnRangeMin, availableList[resourceIndex].spawnRangeMax) * SizeMultiplier);
                //Set the spawn position to the interaction cell
                IntVec3 pos = this.InteractionCell;
                //Try to find the def for the conveyor belt loader
                ThingDef loaderDef = DefDatabase <ThingDef> .GetNamed("A2BLoader", false);

                //If the def exists, then search for any that are connected to the extractor
                if (loaderDef != null)
                {
                    //Look at each cell around the extractor
                    foreach (IntVec3 current in GenAdj.CellsAdjacentCardinal(this))
                    {
                        //Search for a loader in that cell
                        Thing thing3 = Find.ThingGrid.ThingAt(current, loaderDef);
                        //If one is found, set the spawn position to the loader position and exit the loop
                        if (thing3 != null)
                        {
                            pos = thing3.Position;
                            break;
                        }
                    }
                }

                //Look for some of the resource at the spawn position
                Thing thing2 = Find.ThingGrid.ThingAt(pos, availableList[resourceIndex].resourceDefName);
                //If some is found, the resource to be spawned will be placed in this stack
                if (thing2 != null)
                {
                    thing2.stackCount += num;
                }
                else
                {
                    //If there is no resource already there, then make a new stack at the position
                    Thing thing = ThingMaker.MakeThing(availableList[resourceIndex].resourceDefName);
                    thing.stackCount = num;
                    //Spawn the resource
                    GenSpawn.Spawn(thing, pos);
                }
            }
        }
Esempio n. 27
0
 private static IEnumerable <CompSteam> ContiguousSteamBuildings(Building root)
 {
     closedSet.Clear();
     currentSet.Clear();
     openSet.Add(root);
     do
     {
         foreach (Building building in openSet)
         {
             closedSet.Add(building);
         }
         HashSet <Building> hashSet = currentSet;
         currentSet = openSet;
         openSet    = hashSet;
         openSet.Clear();
         foreach (Building currentBuilding in currentSet)
         {
             foreach (IntVec3 adjacentCell in GenAdj.CellsAdjacentCardinal(currentBuilding))
             {
                 if (adjacentCell.InBounds(currentBuilding.Map))
                 {
                     List <Thing> thingList = adjacentCell.GetThingList(currentBuilding.Map);
                     foreach (Thing thing in thingList)
                     {
                         if (thing.TryGetComp <CompSteam>() != null)
                         {
                             Building building = (Building)thing;
                             if (FlickUtility.WantsToBeOn(building))
                             {
                                 if (!openSet.Contains(building) && !currentSet.Contains(building) &&
                                     !closedSet.Contains(building))
                                 {
                                     openSet.Add(building);
                                     break;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }while (openSet.Count > 0);
     return(from b in closedSet
            select b.GetComp <CompSteam>());
 }
        // Returns if this thing has another thing touching it with the same thing comp
        public static bool                  IsSameThingCompTouching(this Thing thing, Type MatchingComp)
        {
            // Get adjacent cells
            var cells = GenAdj.CellsAdjacentCardinal(thing).ToList <IntVec3>();

            // Scan cells
            foreach (var cell in cells)
            {
                // Things in cell with matching thing comp
                if (thing.IsSameThingCompInCell(cell, MatchingComp))
                {
                    return(true);
                }
            }

            // Nothing found
            return(false);
        }
        // Returns true if there is another thing touching it with the same linker flag
        public static bool                  IsSameGraphicLinkerTouching(this Thing thing)
        {
            // Get adjacent cells
            var cells = GenAdj.CellsAdjacentCardinal(thing).ToList <IntVec3>();

            // Scan cells
            foreach (var cell in cells)
            {
                // Things in cell with matching graphic linker
                if (thing.IsSameGraphicLinkerInCell(cell))
                {
                    return(true);
                }
            }

            // Nothing found
            return(false);
        }
Esempio n. 30
0
        private bool SurroundedWithWalls(IntVec3 c, Map map)
        {
            int num = 0;

            foreach (var cell in GenAdj.CellsAdjacentCardinal(c, Rot4.South, new IntVec2(1, 1)))
            {
                if (GenGrid.InBounds(cell, map) && (cell.GetFirstBuilding(map) is Mineable ||
                                                    cell.GetTerrain(map) == TerrainDefOf.Gravel))
                {
                    num++;
                    if (num >= 2)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }