Пример #1
0
        public bool HasEnoughFeedstockInHoppers()
        {
            float totalAvailableFeedstock = powerComp.PowerNet.GetTanks().Sum(x => x.storedFeedstock);
            float stockNeeded             = ReplimatUtility.ConvertMassToFeedstockVolume(1f);

            return(totalAvailableFeedstock >= stockNeeded);
        }
Пример #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);
        }
Пример #3
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);
        }
Пример #4
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);
 }
Пример #5
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);
        }
Пример #6
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.powerComp.PowerOn && 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);
        }
Пример #7
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);
        }
Пример #8
0
        public override void Tick()
        {
            base.Tick();

            if (!powerComp.PowerOn)
            {
                return;
            }

            powerComp.PowerOutput = -powerComp.Props.basePowerConsumption;

            List <Building_ReplimatFeedTank> tanks = GetTanks;

            if (this.IsHashIntervalTick(5))
            {
                if (Empty)
                {
                    corpseInitialMass = 0;
                    Running           = false;
                }
                else
                {
                    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();
                }
            }
        }
Пример #9
0
        public override void Tick()
        {
            base.Tick();

            if (!powerComp.PowerOn)
            {
                return;
            }

            powerComp.PowerOutput = -powerComp.Props.basePowerConsumption;

            if (this.IsHashIntervalTick(15))
            {
                List <Thing> list = Map.thingGrid.ThingsListAtFast(Position);
                Thing        food = list.FirstOrDefault(x => settings.AllowedToAccept(x));

                if (food != null)
                {
                    List <Building_ReplimatFeedTank> tanks = GetTanks;

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

                    if (this.IsHashIntervalTick(60) && FreeSpace >= stockvol)
                    {
                        DematerializingTicks = GenTicks.SecondsToTicks(2f);
                    }

                    if (this.IsHashIntervalTick(5) && FreeSpace >= stockvol)
                    {
                        float buffy = stockvol;

                        food.stackCount--;

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

                        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 = -Math.Max(stateDependentPowerComp.ActiveModePowerConsumption, powerComp.Props.basePowerConsumption);

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

                if (this.IsHashIntervalTick(5))
                {
                    dematerializingCycleInt++;
                    if (dematerializingCycleInt > 2)
                    {
                        dematerializingCycleInt = 0;
                    }
                }
            }
        }