public override string GetInspectString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(base.GetInspectString());

            if (ParentHolder != null && !(ParentHolder is Map))
            {
                // If minified, don't show computer and feedstock check Inspector messages
            }
            else
            {
                if (!ReplimatUtility.CanFindComputer(this))
                {
                    stringBuilder.AppendLine("NotConnectedToComputer".Translate());
                }

                if (Empty)
                {
                    stringBuilder.AppendLine("CorpseRecyclerEmpty".Translate());
                }
                else
                {
                    stringBuilder.AppendLine("CorpseRecyclerMassRemaining".Translate(corpseRemainingMass.ToString("0.00"), corpseInitialMass.ToString("0.00")));
                }
            }
            return(stringBuilder.ToString().TrimEndNewlines());
        }
Example #2
0
        public bool HasStockFor(ThingDef def)
        {
            float totalAvailableFeedstock = powerComp.PowerNet.GetTanks().Sum(x => x.storedFeedstock);
            float stockNeeded             = ReplimatUtility.convertMassToFeedstockVolume(def.BaseMass);

            return(totalAvailableFeedstock >= stockNeeded);
        }
        public void TryBatchMakingSurvivalMeals()
        {
            // Determine the maximum number of survival meals that can be replicated, based on available feedstock
            // (Cap this at 30 meals so that players don't accidentally use up all their feedstock on survival meals)
            ThingDef survivalMeal                = ThingDefOf.MealSurvivalPack;
            int      maxSurvivalMeals            = 30;
            float    totalAvailableFeedstock     = powerComp.PowerNet.GetTanks().Sum(x => x.storedFeedstock);
            float    totalAvailableFeedstockMass = ReplimatUtility.convertFeedstockVolumeToMass(totalAvailableFeedstock);
            int      maxPossibleSurvivalMeals    = (int)Math.Floor(totalAvailableFeedstockMass / survivalMeal.BaseMass);
            int      survivalMealCap             = (maxPossibleSurvivalMeals < maxSurvivalMeals) ? maxPossibleSurvivalMeals : maxSurvivalMeals;

            float survivalMealCapVolumeOfFeedstockRequired = ReplimatUtility.convertMassToFeedstockVolume(survivalMealCap * survivalMeal.BaseMass);

            if (!CanDispenseNow)
            {
                Messages.Message("MessageCannotBatchMakeSurvivalMeals".Translate(), MessageTypeDefOf.RejectInput, false);
                return;
            }

            if (!HasEnoughFeedstockInHopperForIncident(survivalMealCapVolumeOfFeedstockRequired))
            {
                return;
            }

            Func <int, string> textGetter;

            textGetter = ((int x) => "SetSurvivalMealBatchSize".Translate(x, survivalMealCap));

            Dialog_Slider window = new Dialog_Slider(textGetter, 1, survivalMealCap, delegate(int x)
            {
                ConfirmAction(x, ReplimatUtility.convertMassToFeedstockVolume(survivalMeal.BaseMass));
            }, 1);

            Find.WindowStack.Add(window);
        }
Example #4
0
        public bool HasEnoughFeedstockInHoppers()
        {
            float totalAvailableFeedstock = powerComp.PowerNet.GetTanks().Sum(x => x.storedFeedstock);
            float stockNeeded             = ReplimatUtility.convertMassToFeedstockVolume(1f);

            return(totalAvailableFeedstock >= stockNeeded);
        }
Example #5
0
        public override string GetInspectString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(base.GetInspectString());

            if (ParentHolder != null && !(ParentHolder is Map))
            {
                // If minified, don't show computer and feedstock check Inspector messages
            }
            else
            {
                if (!ReplimatUtility.CanFindComputer(this, PowerComp.PowerNet))
                {
                    stringBuilder.AppendLine();
                    stringBuilder.Append("NotConnectedToComputer".Translate());
                }
                else if (!HasEnoughFeedstockInHoppers())
                {
                    stringBuilder.AppendLine();
                    stringBuilder.Append("NotEnoughFeedstock".Translate());
                }
                else
                {
                }
            }

            return(stringBuilder.ToString());
        }
Example #6
0
        public Thing TryDispenseFood(Pawn eater, Pawn getter)
        {
            if (getter == null)
            {
                getter = eater;
            }
            if (!CanDispenseNow)
            {
                return(null);
            }

            ThingDef meal = ReplimatUtility.PickMeal(eater, getter);

            if (meal == null)
            {
                return(null);
            }

            if (!HasStockFor(meal))
            {
                //Log.Error("[Replimat] " + "Did not find enough foodstock in tanks while trying to replicate.");
                return(null);
            }

            ReplicatingTicks = GenTicks.SecondsToTicks(2f);
            def.building.soundDispense.PlayOneShot(new TargetInfo(base.Position, base.Map, false));

            Thing dispensedMeal = ThingMaker.MakeThing(meal, null);

            float dispensedMealMass = dispensedMeal.def.BaseMass;

            powerComp.PowerNet.TryConsumeFeedstock(ReplimatUtility.convertMassToFeedstockVolume(dispensedMealMass));

            return(dispensedMeal);
        }
Example #7
0
        public void TryBatchMakingSurvivalMeals()
        {
            // Determine the maximum number of survival meals that can be replicated, based on available feedstock
            ThingDef survivalMeal                = ThingDefOf.MealSurvivalPack;
            float    totalAvailableFeedstock     = powerComp.PowerNet.GetTanks().Sum(x => x.storedFeedstock);
            float    totalAvailableFeedstockMass = ReplimatUtility.ConvertFeedstockVolumeToMass(totalAvailableFeedstock);
            int      maxPossibleSurvivalMeals    = (int)Math.Floor(totalAvailableFeedstockMass / survivalMeal.BaseMass);

            float survivalMealCapVolumeOfFeedstockRequired = ReplimatUtility.ConvertMassToFeedstockVolume(maxPossibleSurvivalMeals * survivalMeal.BaseMass);

            if (!CanDispenseNow)
            {
                Messages.Message("MessageCannotBatchMakeSurvivalMeals".Translate(), MessageTypeDefOf.RejectInput, false);
                return;
            }

            if (!HasEnoughFeedstockInHopperForIncident(survivalMealCapVolumeOfFeedstockRequired))
            {
                return;
            }

            string dialogTitle = "SetSurvivalMealBatchSize".Translate(maxPossibleSurvivalMeals);

            Dialog_BatchMakeSurvivalMeals window = new Dialog_BatchMakeSurvivalMeals(dialogTitle, 1, maxPossibleSurvivalMeals, delegate(int x)
            {
                ConfirmAction(x, ReplimatUtility.ConvertMassToFeedstockVolume(survivalMeal.BaseMass));
            }, 1);

            Find.WindowStack.Add(window);
        }
Example #8
0
        public override bool HasEnoughFeedstockInHoppers()
        {
            float totalAvailableFeedstock = powerComp.PowerNet.GetTanks().Sum(x => x.storedFeedstock);
            // Use a default amount for all meals
            float stockNeeded = ReplimatUtility.convertMassToFeedstockVolume(DispensableDef.BaseMass);

            return(totalAvailableFeedstock >= stockNeeded);
        }
Example #9
0
 public override void SpawnSetup(Map map, bool respawningAfterLoad)
 {
     base.SpawnSetup(map, respawningAfterLoad);
     powerComp = GetComp <CompPowerTrader>();
     stateDependentPowerComp = GetComp <CompStateDependentPowerUse>();
     AllowedAnimalFeedDefs   = def.building.fixedStorageSettings.filter.allowedDefs.ToList();
     volumePerAnimalFeed     = ReplimatUtility.ConvertMassToFeedstockVolume(CurrentAnimalFeedDef.BaseMass);
 }
Example #10
0
            private static bool Prefix(ref Thing foodSource, ref ThingDef __result)
            {
                if (foodSource is Building_ReplimatTerminal && BestFoodSourceOnMap)
                {
                    __result = ReplimatUtility.PickMeal(eater, getter);
                    return(false);
                }

                return(true);
            }
Example #11
0
        public override void Tick()
        {
            base.Tick();

            if (!powerComp.PowerOn || !ReplimatUtility.CanFindComputer(this, PowerComp.PowerNet))
            {
                return;
            }

            if (this.IsHashIntervalTick(60))
            {
                List <Thing> list         = Map.thingGrid.ThingsListAtFast(Position);
                Thing        foodInFeeder = list.FirstOrDefault(x => x.def.IsNutritionGivingIngestible);

                if (foodInFeeder == null)
                {
                    int maxAnimFeed = Mathf.FloorToInt(powerComp.PowerNet.GetTanks().Sum(x => x.storedFeedstock) / volumePerAnimalFeed);
                    maxAnimFeed = Mathf.Min(maxAnimFeed, CurrentAnimalFeedDef.stackLimit);

                    if (maxAnimFeed > 0 && powerComp.PowerNet.TryConsumeFeedstock(volumePerAnimalFeed * maxAnimFeed))
                    {
                        ReplicatingTicks = GenTicks.SecondsToTicks(2f);
                        def.building.soundDispense.PlayOneShot(new TargetInfo(Position, Map, false));

                        Thing t = ThingMaker.MakeThing(CurrentAnimalFeedDef, null);
                        t.stackCount = maxAnimFeed;
                        GenPlace.TryPlaceThing(t, Position, Map, ThingPlaceMode.Direct);
                    }
                }
                else if (foodInFeeder.def == CurrentAnimalFeedDef && foodInFeeder.stackCount < (CurrentAnimalFeedDef.stackLimit * 0.25))
                {
                    int refill      = Mathf.Min(foodInFeeder.def.stackLimit - foodInFeeder.stackCount, foodInFeeder.def.stackLimit);
                    int maxAnimFeed = Mathf.FloorToInt(powerComp.PowerNet.GetTanks().Sum(x => x.storedFeedstock) / volumePerAnimalFeed);
                    maxAnimFeed = Mathf.Min(maxAnimFeed, refill);

                    if (maxAnimFeed > 0 && powerComp.PowerNet.TryConsumeFeedstock(volumePerAnimalFeed * maxAnimFeed))
                    {
                        ReplicatingTicks = GenTicks.SecondsToTicks(2f);
                        def.building.soundDispense.PlayOneShot(new TargetInfo(Position, Map, false));

                        foodInFeeder.stackCount += maxAnimFeed;
                    }
                }
            }

            powerComp.PowerOutput = -powerComp.Props.basePowerConsumption;

            if (ReplicatingTicks > 0)
            {
                ReplicatingTicks--;
                powerComp.PowerOutput = -Math.Max(stateDependentPowerComp.ActiveModePowerConsumption, powerComp.Props.basePowerConsumption);
            }
        }
        public override string GetInspectString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(base.GetInspectString());
            if ((ParentHolder == null || ParentHolder is Map) && !ReplimatUtility.CanFindComputer(this, PowerComp.PowerNet))
            {
                stringBuilder.AppendLine();
                stringBuilder.Append(Translator.Translate("NotConnectedToComputer"));
            }
            return(stringBuilder.ToString());
        }
Example #13
0
        private static bool RepDel(Building_ReplimatTerminal t)
        {
            if (
                !allowDispenserFull ||
                !(getter.RaceProps.ToolUser && getter.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) ||
                t.Faction != getter.Faction && t.Faction != getter.HostFaction ||
                !allowForbidden && t.IsForbidden(getter) ||
                !t.powerComp.PowerOn ||
                !t.InteractionCell.Standable(t.Map) ||
                !FoodUtility.IsFoodSourceOnMapSociallyProper(t, getter, eater, allowSociallyImproper) ||
                getter.IsWildMan() ||
                ReplimatUtility.PickMeal(eater, getter) == null ||
                !t.HasStockFor(ReplimatUtility.PickMeal(eater, getter)) ||
                !getter.Map.reachability.CanReachNonLocal(getter.Position, new TargetInfo(t.InteractionCell, t.Map),
                                                          PathEndMode.OnCell, TraverseParms.For(getter, Danger.Some)))
            {
                return(false);
            }

            return(true);
        }
        public override string GetInspectString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(base.GetInspectString());
            stringBuilder.Append("FeedstockStored".Translate(storedFeedstock.ToString("0.00"), StoredFeedstockMax.ToString("0.00")));

            if (ParentHolder != null && !(ParentHolder is Map))
            {
                // If minified, don't show computer and feedstock check Inspector messages
            }
            else
            {
                if (!ReplimatUtility.CanFindComputer(this, PowerComp.PowerNet))
                {
                    stringBuilder.AppendLine();
                    stringBuilder.Append("NotConnectedToComputer".Translate());
                }
            }
            return(stringBuilder.ToString().TrimEndNewlines());
        }
Example #15
0
        public override bool TryExecuteWorker(IncidentParms parms)
        {
            Map          map  = (Map)parms.target;
            List <Thing> list = map.listerThings.ThingsOfDef(ReplimatDef.ReplimatTerminal);

            if (!list.Any())
            {
                // If there are no Terminals or Animal Feeders, break out of execution early
                return(false);
            }

            Thing building_ReplimatTerminal           = list.RandomElement();
            Building_ReplimatTerminal currentTerminal = building_ReplimatTerminal as Building_ReplimatTerminal;

            ThingDef kibble                   = ThingDef.Named("Kibble");
            int      unitsOfKibble            = 75 * 3;
            float    volumeOfFeedstockToWaste = ReplimatUtility.convertMassToFeedstockVolume(unitsOfKibble * kibble.BaseMass);

            if (currentTerminal.HasEnoughFeedstockInHopperForIncident(volumeOfFeedstockToWaste))
            {
                currentTerminal.powerComp.PowerNet.TryConsumeFeedstock(volumeOfFeedstockToWaste);
                Thing t = ThingMaker.MakeThing(kibble, null);
                t.stackCount = unitsOfKibble;
                GenPlace.TryPlaceThing(t, building_ReplimatTerminal.InteractionCell, map, ThingPlaceMode.Near);

                string letterLabel = "LetterLabelReplimatMalfunctionKibble".Translate();

                string letterText = "LetterTextReplimatMalfunctionKibble".Translate(new object[]
                {
                    currentTerminal.def.label
                });

                Find.LetterStack.ReceiveLetter(letterLabel, letterText, LetterDefOf.NegativeEvent, new TargetInfo(building_ReplimatTerminal.Position, map, false), null);
                return(true);
            }
            return(false);
        }
Example #16
0
        public Thing TryDispenseFood(Pawn eater, Pawn getter)
        {
            if (getter == null)
            {
                getter = eater;
            }
            if (!CanDispenseNow)
            {
                return(null);
            }

            ThingDef meal = ReplimatUtility.PickMeal(eater, getter);

            if (meal == null)
            {
                return(null);
            }

            if (!HasStockFor(meal))
            {
                return(null);
            }

            ReplicatingTicks = GenTicks.SecondsToTicks(2f);
            def.building.soundDispense.PlayOneShot(new TargetInfo(base.Position, base.Map, false));

            Thing dispensedMeal = ThingMaker.MakeThing(meal, null);

            ReplimatUtility.GenerateIngredients(dispensedMeal, eater);

            float dispensedMealMass = dispensedMeal.def.BaseMass;

            powerComp.PowerNet.TryConsumeFeedstock(ReplimatUtility.ConvertMassToFeedstockVolume(dispensedMealMass));

            return(dispensedMeal);
        }
        public override void Tick()
        {
            base.Tick();

            if (!powerComp.PowerOn)
            {
                return;
            }

            powerComp.PowerOutput = -125f;

            if (this.IsHashIntervalTick(60))
            {
                List <Building_ReplimatFeedTank> tanks = GetTanks;
                List <Thing> list = Map.thingGrid.ThingsListAtFast(Position);



                Thing food = list.FirstOrDefault(x => settings.AllowedToAccept(x));

                if (food == null)
                {
                    return;
                }

                float stockvol  = ReplimatUtility.convertMassToFeedstockVolume(food.def.BaseMass);
                float FreeSpace = tanks.Sum(x => x.AmountCanAccept);

                if (FreeSpace >= stockvol)
                {
                    float buffy = stockvol;

                    food.stackCount = food.stackCount - 1;

                    if (food.stackCount == 0)
                    {
                        food.Destroy();
                    }

                    DematerializingTicks = GenTicks.SecondsToTicks(2f);

                    foreach (var tank in tanks.InRandomOrder())
                    {
                        if (buffy > 0f)
                        {
                            float sent = Mathf.Min(buffy, tank.AmountCanAccept);
                            buffy -= sent;
                            tank.AddFeedstock(sent);
                        }
                    }
                }
            }

            if (DematerializingTicks > 0)
            {
                DematerializingTicks--;
                powerComp.PowerOutput = -1000f;

                if (this.wickSustainer == null)
                {
                    this.StartWickSustainer();
                }
                else if (this.wickSustainer.Ended)
                {
                    this.StartWickSustainer();
                }
                else
                {
                    this.wickSustainer.Maintain();
                }



                if (this.IsHashIntervalTick(5))
                {
                    dematerializingCycleInt++;
                    if (dematerializingCycleInt > 2)
                    {
                        dematerializingCycleInt = 0;
                    }
                }
            }
        }
        public override void Tick()
        {
            base.Tick();

            if (this.IsHashIntervalTick(5))
            {
                powerComp.PowerOutput = -powerComp.Props.basePowerConsumption;

                if (Empty)
                {
                    corpseInitialMass = 0;
                    Running           = false;
                }
                else
                {
                    List <Building_ReplimatFeedTank> tanks = GetTanks;

                    float massDecrementStepSize = Mathf.Min(defaultMassDecrementStepSize, corpseRemainingMass);
                    float feedstockVolume       = ReplimatUtility.convertMassToFeedstockVolume(massDecrementStepSize);
                    float freeSpaceInTanks      = tanks.Sum(x => x.AmountCanAccept);

                    if (powerComp.PowerOn && freeSpaceInTanks >= feedstockVolume)
                    {
                        Running = true;

                        powerComp.PowerOutput = -Math.Max(stateDependentPowerComp.ActiveModePowerConsumption, powerComp.Props.basePowerConsumption);

                        float buffer = feedstockVolume;

                        foreach (var tank in tanks.InRandomOrder())
                        {
                            if (buffer > 0f)
                            {
                                float sent = Mathf.Min(buffer, tank.AmountCanAccept);
                                buffer -= sent;
                                tank.AddFeedstock(sent);
                                corpseRemainingMass -= Mathf.Min(defaultMassDecrementStepSize, corpseRemainingMass);
                            }
                        }

                        dematerializingCycleInt++;
                        if (dematerializingCycleInt > 3)
                        {
                            dematerializingCycleInt = 0;
                        }
                    }
                    else
                    {
                        Running = false;
                    }
                }
                Map.mapDrawer.MapMeshDirty(Position, MapMeshFlag.Things | MapMeshFlag.Buildings);
            }

            if (Running)
            {
                if (wickSustainer == null || wickSustainer.Ended)
                {
                    StartWickSustainer();
                }
                else
                {
                    wickSustainer.Maintain();
                }
            }
        }