Beispiel #1
0
        internal static Thing           _FindFeedInAnyHopper(this Building_NutrientPasteDispenser obj)
        {
            // Check for generic hoppers
            var CompHopperUser = obj.TryGetComp <CompHopperUser>();

            if (CompHopperUser != null)
            {
                var hoppers = CompHopperUser.FindHoppers();
                if (!hoppers.NullOrEmpty())
                {
                    foreach (var hopper in hoppers)
                    {
                        var resources = hopper.GetAllResources(CompHopperUser.Resources);
                        if (!resources.NullOrEmpty())
                        {
                            foreach (var resource in resources)
                            {
                                // This check shouldn't be needed, but we'll do it as a fail-safe
                                if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(resource.def))
                                {
                                    return(resource);
                                }
                            }
                        }
                    }
                }
            }
            // Check for vanilla hoppers
            var adjCells = _AdjCellsCardinalInBounds(obj);

            for (int cellIndex = 0; cellIndex < adjCells.Count; ++cellIndex)
            {
                IntVec3      c         = adjCells[cellIndex];
                Thing        resource  = (Thing)null;
                Thing        hopper    = (Thing)null;
                List <Thing> thingList = c.GetThingList();
                for (int thingIndex = 0; thingIndex < thingList.Count; ++thingIndex)
                {
                    Thing thisThing = thingList[thingIndex];
                    if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(thisThing.def))
                    {
                        resource = thisThing;
                    }
                    if (thisThing.def == ThingDefOf.Hopper)
                    {
                        hopper = thisThing;
                    }
                }
                if (
                    (resource != null) &&
                    (hopper != null)
                    )
                {
                    return(resource);
                }
            }
            return((Thing)null);
        }
Beispiel #2
0
        internal static bool            _HasEnoughFeedstockInHoppers(this Building_NutrientPasteDispenser obj)
        {
            int costPerDispense = obj.def.building.foodCostPerDispense;

            /* Research Project cut from A13
             * if( ResearchProjectDef.Named( "NutrientResynthesis" ).IsFinished )
             * {
             *  costPerDispense--;
             * }
             */
            // Check for generic hoppers
            var CompHopperUser = obj.TryGetComp <CompHopperUser>();

            if (CompHopperUser != null)
            {
                if (CompHopperUser.EnoughResourcesInHoppers(costPerDispense))
                {
                    return(true);
                }
            }
            // Check for vanilla hoppers
            var adjCells      = _AdjCellsCardinalInBounds(obj);
            int resourceCount = 0;

            for (int cellIndex = 0; cellIndex < adjCells.Count; ++cellIndex)
            {
                IntVec3      c         = adjCells[cellIndex];
                Thing        resource  = (Thing)null;
                Thing        hopper    = (Thing)null;
                List <Thing> thingList = GridsUtility.GetThingList(c);
                for (int thingIndex = 0; thingIndex < thingList.Count; ++thingIndex)
                {
                    Thing thisThing = thingList[thingIndex];
                    if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(thisThing.def))
                    {
                        resource = thisThing;
                    }
                    if (thisThing.def == ThingDefOf.Hopper)
                    {
                        hopper = thisThing;
                    }
                }
                if (
                    (resource != null) &&
                    (hopper != null)
                    )
                {
                    resourceCount += resource.stackCount;
                }
                if (resourceCount >= costPerDispense)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #3
0
        internal static Building        _AdjacentReachableHopper(this Building_NutrientPasteDispenser obj, Pawn reacher)
        {
            // Check for generic hoppers
            var CompHopperUser = obj.TryGetComp <CompHopperUser>();

            if (CompHopperUser != null)
            {
                var hoppers = CompHopperUser.FindHoppers();
                if (!hoppers.NullOrEmpty())
                {
                    foreach (var hopper in hoppers)
                    {
                        if (
                            reacher.CanReach(
                                ( TargetInfo )(( Thing )hopper.parent),
                                PathEndMode.Touch,
                                reacher.NormalMaxDanger(),
                                false)
                            )
                        {
                            return((Building)hopper.parent);
                        }
                    }
                }
            }
            // Check for vanilla hoppers
            var adjCells = _AdjCellsCardinalInBounds(obj);

            for (int index = 0; index < adjCells.Count; ++index)
            {
                Building edifice = adjCells[index].GetEdifice();
                if (
                    (edifice != null) &&
                    (edifice.def == ThingDefOf.Hopper) &&
                    (reacher.CanReach(
                         ( TargetInfo )(( Thing )edifice),
                         PathEndMode.Touch,
                         reacher.NormalMaxDanger(),
                         false))
                    )
                {
                    return(edifice);
                }
            }
            return((Building)null);
        }