Ejemplo n.º 1
0
        public override void PostSplitOff(Thing piece)
        {
            CompUniversalFermenter comp = ((ThingWithComps)piece).GetComp <CompUniversalFermenter>();

            comp.ruinedPercent = ruinedPercent;
            //ruinedPercent = ruinedPercent;
        }
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            CompUniversalFermenter comp = t.TryGetComp <CompUniversalFermenter>();

            if (comp == null || comp.Fermented || comp.SpaceLeftForIngredient <= 0)
            {
                return(false);
            }
            float ambientTemperature = comp.parent.AmbientTemperature;

            if (ambientTemperature < comp.Product.temperatureSafe.min + 2f || ambientTemperature > comp.Product.temperatureSafe.max - 2f)
            {
                JobFailReason.Is(TemperatureTrans);
                return(false);
            }
            if (t.IsForbidden(pawn) || !pawn.CanReserveAndReach(t, PathEndMode.Touch, pawn.NormalMaxDanger(), 1, -1, null, forced))
            {
                return(false);
            }
            if (pawn.Map.designationManager.DesignationOn(t, DesignationDefOf.Deconstruct) != null)
            {
                return(false);
            }
            if (FindIngredient(pawn, t) == null)
            {
                JobFailReason.Is(NoIngredientTrans);
                return(false);
            }
            return(!t.IsBurning());
        }
Ejemplo n.º 3
0
        public override bool AllowStackWith(Thing other)
        {
            CompUniversalFermenter comp = ((ThingWithComps)other).GetComp <CompUniversalFermenter>();

            return(Ruined == comp.Ruined);
            //return Ruined == Ruined;
        }
Ejemplo n.º 4
0
        public override void PreAbsorbStack(Thing otherStack, int count)
        {
            float t = (float)count / (float)(parent.stackCount + count);
            CompUniversalFermenter comp = ((ThingWithComps)otherStack).GetComp <CompUniversalFermenter>();

            ruinedPercent = Mathf.Lerp(ruinedPercent, comp.ruinedPercent, t);
            //ruinedPercent = Mathf.Lerp(ruinedPercent, ruinedPercent, t);
        }
        public override float GetPriority(Pawn pawn, TargetInfo t)
        {
            CompUniversalFermenter comp = t.Thing.TryGetComp <CompUniversalFermenter>();

            if (comp != null)
            {
                return(1 / comp.SpaceLeftForIngredient);
            }
            return(0f);
        }
Ejemplo n.º 6
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            CompUniversalFermenter comp = Fermenter.TryGetComp <CompUniversalFermenter>();

            // Verify fermenter and ingredient validity
            this.FailOn(() => comp.SpaceLeftForIngredient <= 0);
            this.FailOnDespawnedNullOrForbidden(FermenterInd);
            this.FailOnBurningImmobile(FermenterInd);
            this.FailOnDestroyedNullOrForbidden(IngredientInd);

            // Reserve resources
            // Creating the toil before yielding allows for CheckForGetOpportunityDuplicate
            Toil ingrToil = Toils_Reserve.Reserve(IngredientInd);

            yield return(ingrToil);

            // Reserve fermenter
            yield return(Toils_Reserve.Reserve(FermenterInd));

            // Go to the ingredient
            yield return(Toils_Goto.GotoThing(IngredientInd, PathEndMode.ClosestTouch)
                         .FailOnSomeonePhysicallyInteracting(IngredientInd)
                         .FailOnDestroyedNullOrForbidden(IngredientInd));

            // Haul the ingredients
            yield return(Toils_Haul.StartCarryThing(IngredientInd, false, true).FailOnDestroyedNullOrForbidden(IngredientInd));

            yield return(Toils_Haul.CheckForGetOpportunityDuplicate(ingrToil, IngredientInd, TargetIndex.None, true));

            // Carry ingredients to the fermenter
            yield return(Toils_Haul.CarryHauledThingToCell(FermenterInd));

            // Add delay for adding ingredients to the fermenter
            yield return(Toils_General.Wait(Duration).FailOnDestroyedNullOrForbidden(FermenterInd).WithProgressBarToilDelay(FermenterInd));

            // Use ingredients
            // The UniversalFermenter automatically destroys held ingredients
            Toil add = new Toil();

            add.initAction = () =>
            {
                if (!comp.AddIngredient(Ingredient))
                {
                    // The ingredient is not allowed, end the job
                    EndJobWith(JobCondition.Incompletable);
                    Log.Message("JobCondition.Incompletable");
                }
            };
            add.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(add);

            // End the current job
            yield break;
        }
Ejemplo n.º 7
0
 internal static void ChangeQuality(QualityCategory qualityToTarget, QualityCategory quality)
 {
     foreach (Thing thing in Find.Selector.SelectedObjects.OfType <Thing>())
     {
         CompUniversalFermenter comp = thing.TryGetComp <CompUniversalFermenter>();
         if (comp != null && comp.CurrentProcess.usesQuality && comp.TargetQuality == qualityToTarget)
         {
             comp.TargetQuality = quality;
         }
     }
 }
Ejemplo n.º 8
0
 internal static void ChangeProcess(UF_Process processToTarget, UF_Process process)
 {
     foreach (Thing thing in Find.Selector.SelectedObjects.OfType <Thing>())
     {
         CompUniversalFermenter comp = thing.TryGetComp <CompUniversalFermenter>();
         if (comp != null && comp.CurrentProcess == processToTarget)
         {
             comp.CurrentProcess = process;
         }
     }
 }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            CompUniversalFermenter comp = Fermenter.TryGetComp <CompUniversalFermenter>();

            // Verify fermenter and ingredient validity
            this.FailOnDespawnedNullOrForbidden(FermenterInd);
            this.FailOnBurningImmobile(FermenterInd);
            base.AddEndCondition(delegate
            {
                if (comp.SpaceLeftForIngredient > 0)
                {
                    return(JobCondition.Ongoing);
                }
                return(JobCondition.Succeeded);
            });
            yield return(Toils_General.DoAtomic(delegate
            {
                job.count = comp.SpaceLeftForIngredient;
            }));

            // Creating the toil before yielding allows for CheckForGetOpportunityDuplicate
            Toil reserveIngredient = Toils_Reserve.Reserve(IngredientInd);

            yield return(reserveIngredient);

            yield return(Toils_Goto.GotoThing(IngredientInd, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(IngredientInd).FailOnSomeonePhysicallyInteracting(IngredientInd));

            yield return(Toils_Haul.StartCarryThing(IngredientInd, false, true, false).FailOnDestroyedNullOrForbidden(IngredientInd));

            yield return(Toils_Haul.CheckForGetOpportunityDuplicate(reserveIngredient, IngredientInd, TargetIndex.None, true));

            // Carry ingredients to the fermenter
            yield return(Toils_Goto.GotoThing(FermenterInd, PathEndMode.Touch));

            // Add delay for adding ingredients to the fermenter
            yield return(Toils_General.Wait(Duration, FermenterInd).FailOnDestroyedNullOrForbidden(IngredientInd).FailOnDestroyedNullOrForbidden(FermenterInd)
                         .FailOnCannotTouch(FermenterInd, PathEndMode.Touch).WithProgressBarToilDelay(FermenterInd, false, -0.5f));

            // Use ingredients
            // The UniversalFermenter automatically destroys held ingredients
            yield return(new Toil
            {
                initAction = delegate()
                {
                    comp.AddIngredient(Ingredient);
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });
        }
Ejemplo n.º 10
0
 internal static void LogSpeedFactors()
 {
     foreach (Thing thing in Find.Selector.SelectedObjects.OfType <Thing>())
     {
         CompUniversalFermenter comp = thing.TryGetComp <CompUniversalFermenter>();
         if (comp != null)
         {
             Log.Message(comp.parent.ToString() + ": " +
                         "sun: " + comp.CurrentSunFactor.ToStringPercent() +
                         "| rain: " + comp.CurrentRainFactor.ToStringPercent() +
                         "| snow: " + comp.CurrentSnowFactor.ToStringPercent() +
                         "| wind: " + comp.CurrentWindFactor.ToStringPercent() +
                         "| roofed: " + comp.RoofCoverage.ToStringPercent());
         }
     }
     gooseAngle = Rand.Range(0, 360);
     SoundStarter.PlayOneShotOnCamera(UF_DefOf.UF_Honk);
 }
Ejemplo n.º 11
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            CompUniversalFermenter comp = Fermenter.TryGetComp <CompUniversalFermenter>();

            // Verify fermenter validity
            this.FailOn(() => !comp.Finished);
            this.FailOnDestroyedNullOrForbidden(FermenterInd);

            // Reserve fermenter
            yield return(Toils_Reserve.Reserve(FermenterInd));

            // Go to the fermenter
            yield return(Toils_Goto.GotoThing(FermenterInd, PathEndMode.ClosestTouch));

            // Add delay for collecting product from fermenter, if it is ready
            yield return(Toils_General.Wait(Duration).FailOnDestroyedNullOrForbidden(FermenterInd).WithProgressBarToilDelay(FermenterInd));

            // Collect product
            Toil collect = new Toil();

            collect.initAction = () =>
            {
                Thing product = comp.TakeOutProduct();
                GenPlace.TryPlaceThing(product, pawn.Position, Map, ThingPlaceMode.Near);
                StoragePriority storagePriority = StoreUtility.CurrentStoragePriorityOf(product);
                IntVec3         c;

                // Try to find a suitable storage spot for the product
                if (StoreUtility.TryFindBestBetterStoreCellFor(product, pawn, Map, storagePriority, pawn.Faction, out c))
                {
                    this.job.SetTarget(TargetIndex.B, product);
                    this.job.count = product.stackCount;
                    this.job.SetTarget(TargetIndex.C, c);
                }
                // If there is no spot to store the product, end this job
                else
                {
                    EndJobWith(JobCondition.Incompletable);
                }
            };
            collect.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(collect);

            // Reserve the product
            yield return(Toils_Reserve.Reserve(ProductToHaulInd));

            // Reserve the storage cell
            yield return(Toils_Reserve.Reserve(StorageCellInd));

            // Go to the product
            yield return(Toils_Goto.GotoThing(ProductToHaulInd, PathEndMode.ClosestTouch));

            // Pick up the product
            yield return(Toils_Haul.StartCarryThing(ProductToHaulInd));

            // Carry the product to the storage cell, then place it down
            Toil carry = Toils_Haul.CarryHauledThingToCell(StorageCellInd);

            yield return(carry);

            yield return(Toils_Haul.PlaceHauledThingInCell(StorageCellInd, carry, true));

            // End the current job
            yield break;
        }
Ejemplo n.º 12
0
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            CompUniversalFermenter comp = t.TryGetComp <CompUniversalFermenter>();

            return(comp != null && comp.Fermented && !t.IsBurning() && !t.IsForbidden(pawn) && pawn.CanReserveAndReach(t, PathEndMode.Touch, pawn.NormalMaxDanger(), 1, -1, null, forced));
        }
Ejemplo n.º 13
0
 public void ReplaceVanillaBarrels()
 {
     if (Current.ProgramState != ProgramState.Playing)
     {
         return;
     }
     foreach (Map map in Find.Maps)
     {
         foreach (Thing thing in map.listerThings.ThingsOfDef(ThingDefOf.FermentingBarrel).ToList())
         {
             bool     inUse     = false;
             float    progress  = 0;
             int      fillCount = 0;
             IntVec3  position  = thing.Position;
             ThingDef stuff;
             if (thing.Stuff != null)
             {
                 stuff = thing.Stuff;
             }
             else
             {
                 stuff = ThingDefOf.WoodLog;
             }
             if (thing is Building_FermentingBarrel oldBarrel)
             {
                 inUse = oldBarrel.SpaceLeftForWort < 25;
                 if (inUse)
                 {
                     progress  = oldBarrel.Progress;
                     fillCount = 25 - oldBarrel.SpaceLeftForWort;
                 }
             }
             Thing newBarrel = ThingMaker.MakeThing(UF_DefOf.UniversalFermenter, stuff);
             GenSpawn.Spawn(newBarrel, position, map);
             if (inUse)
             {
                 CompUniversalFermenter compUF = newBarrel.TryGetComp <CompUniversalFermenter>();
                 compUF.CurrentProcess = compUF.Props.processes.First(p => p.thingDef == ThingDefOf.Beer);
                 Thing wort = ThingMaker.MakeThing(ThingDefOf.Wort, null);
                 wort.stackCount = fillCount;
                 compUF.AddIngredient(wort);
                 compUF.ProgressTicks = (int)(360000 * progress);
             }
         }
         foreach (Thing thing in map.listerThings.ThingsOfDef(ThingDefOf.MinifiedThing).Where(t => t.GetInnerIfMinified().def == ThingDefOf.FermentingBarrel))
         {
             MinifiedThing minifiedThing = thing as MinifiedThing;
             ThingDef      stuff;
             if (minifiedThing.InnerThing.Stuff != null)
             {
                 stuff = minifiedThing.InnerThing.Stuff;
             }
             else
             {
                 stuff = ThingDefOf.WoodLog;
             }
             minifiedThing.InnerThing = null;
             Thing newBarrel = ThingMaker.MakeThing(UF_DefOf.UniversalFermenter, stuff);
             minifiedThing.InnerThing = newBarrel;
             cachedGraphic.SetValue(minifiedThing, null);
         }
     }
 }