public void                         ResetAndReprogramHoppers()
 {
     //Log.Message( string.Format( "{0}.ResetAndReprogramHoppers()", this.ThingID ) );
     resourceFilter = null;
     CompHopperUser.ResetResourceSettings();
     CompHopperUser.FindAndProgramHoppers();
 }
        public Thing                        TryProduceThingDef(ThingDef thingDef)
        {
            //Log.Message( string.Format( "{0}.TryProduceThingDef( {1} )", this.ThingID, thingDef == null ? "null" : thingDef.defName ) );
            var recipe = FindRecipeForProduct(thingDef);

            if (recipe == null)
            {
                return((Thing)null);
            }
            var chosen = new List <ThingAmount>();

            if (!CompHopperUser.RemoveResourcesFromHoppers(recipe, chosen))
            {
                return(null);
            }
            var thing = ThingMaker.MakeThing(thingDef);

            thing.stackCount = recipe.products[0].count;
            var ingredients = thing.TryGetComp <CompIngredients>();

            if (ingredients != null)
            {
                foreach (var ingredient in chosen)
                {
                    ingredients.RegisterIngredient(ingredient.thing.def);
                }
            }
            return(thing);
        }
        public Thing                        TryProduceThingDef(ThingDef thingDef)
        {
            //Log.Message( string.Format( "{0}.TryProduceThingDef( {1} )", this.ThingID, thingDef == null ? "null" : thingDef.defName ) );
            var recipe = FindRecipeForProduct(thingDef);

            if (recipe == null)
            {
                return((Thing)null);
            }
            List <ThingAmount> chosen = new List <ThingAmount>();

            if (!CompHopperUser.RemoveResourcesFromHoppers(recipe, chosen))
            {
                return(null);
            }
            var thing = ThingMaker.MakeThing(thingDef);

            thing.stackCount = recipe.products[0].count;
            if (
                (thingDef.thingClass == typeof(Meal)) ||
                (thingDef.thingClass.IsSubclassOf(typeof(Meal)))
                )
            {
                var meal = (Meal)thing;
                foreach (var ingredient in chosen)
                {
                    meal.RegisterIngredient(ingredient.thing.def);
                }
            }
            return(thing);
        }
예제 #4
0
        /// <summary>
        /// Draws a target highlight on all connectable Hoppers around target
        /// </summary>
        /// <param name="def"></param>
        /// <param name="center"></param>
        /// <param name="rot"></param>
        public override void                DrawGhost(ThingDef def, IntVec3 center, Rot4 rot)
        {
            List <CompHopper> hoppers = CompHopperUser.FindHoppers(center, rot, def.Size);

            foreach (var hopper in hoppers)
            {
                GenDraw.DrawFieldEdges(hopper.parent.OccupiedRect().Cells.ToList());
                GenDraw.DrawTargetHighlight(hopper.parent);
            }
        }
예제 #5
0
 public override void                PostDeSpawn()
 {
     //Log.Message( string.Format( "{0}.CompHopper.PostDeSpawn()", this.parent.ThingID ) );
     base.PostDeSpawn();
     DeprogramHopper();
     if (hopperUser != null)
     {
         hopperUser.NotifyHopperDetached();
         hopperUser = null;
     }
 }
        public bool                         HasEnoughResourcesInHoppersFor(ThingDef thingDef)
        {
            //Log.Message( string.Format( "{0}.HasEnoughResourcesInHoppersFor( {1} )", this.ThingID, thingDef == null ? "null" : thingDef.defName ) );
            var recipe = FindRecipeForProduct(thingDef);

            if (recipe == null)
            {
                return(false);
            }
            return(CompHopperUser.EnoughResourcesInHoppers(recipe));
        }
예제 #7
0
 public override void                PostSpawnSetup()
 {
     //Log.Message( string.Format( "{0}.CompHopper.PostSpawnSetup()", this.parent.ThingID ) );
     base.PostSpawnSetup();
     hopperUser = FindHopperUser();
     if (
         (!WasProgrammed) &&
         (hopperUser != null)
         )
     {
         hopperUser.NotifyHopperAttached();
     }
 }
        public ThingDef                     BestProduct(Func <ThingDef, bool> where, Func <ThingDef, ThingDef, int> sort)
        {
            //Log.Message( string.Format( "{0}.BestProduct()", this.ThingID ) );

            var thingDefs = AllProducts().Where(where.Invoke).ToList();

            thingDefs.Sort(sort.Invoke);

            foreach (var thingDef in thingDefs)
            {
                var recipe = FindRecipeForProduct(thingDef);
                if (CompHopperUser.EnoughResourcesInHoppers(recipe))
                {
                    return(thingDef);
                }
            }
            return((ThingDef)null);
        }
        public Building                     AdjacentReachableHopper(Pawn reacher)
        {
            //Log.Message( string.Format( "{0}.AdjacentReachableHopper( {1} )", this.ThingID, reacher == null ? "null" : reacher.NameStringShort ) );
            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);
                    }
                }
            }
            return((Building)null);
        }
예제 #10
0
 public override void            SpawnSetup()
 {
     base.SpawnSetup();
     compHopperUser = this.TryGetComp <CompHopperUser>();
 }