Пример #1
0
        public static void FillOrderProcessorFromPawnKindDef(ThingOrderProcessor orderProcessor, PawnKindDef pawnKind)
        {
            ThingDef       pawnThingDef = pawnKind.race;
            RaceProperties raceProps    = pawnThingDef.race;

            //Assemble all required materials for a fully grown adult.
            ThingDef meatDef = raceProps.meatDef;
            float    meatBaseNutrition = meatDef.ingestible.CachedNutrition;
            float    meatAmount = pawnThingDef.GetStatValueAbstract(StatDefOf.MeatAmount);
            int      nutritionAmount, proteinAmount;

            //protein cost = Meat * base Meat nutrition (vanilla is .05) * magic multiplier of 27
            //Minimum protein cost is 25, max is 750. Multiply by mod setting for clone ingredients
            //finally, round up to the nearest number divisible by 5
            proteinAmount = (int)(Math.Ceiling((meatAmount * meatBaseNutrition * 27f).Clamp(25, 750)
                                               * QEESettings.instance.cloneTotalResourcesFloat / 5) * 5);

            nutritionAmount = 4 * proteinAmount;

            {
                ThingOrderRequest orderRequest = new ThingOrderRequest(QEThingDefOf.QE_ProteinMash, proteinAmount);
                orderProcessor.desiredIngredients.Add(orderRequest);
            }

            {
                ThingOrderRequest orderRequest = new ThingOrderRequest(QEThingDefOf.QE_NutrientSolution, nutritionAmount);
                orderProcessor.desiredIngredients.Add(orderRequest);
            }
        }
        public static int TotalStackCountForOrderRequestInContainer(this ThingOrderRequest request, ThingOwner thingOwner)
        {
            if (request == null)
            {
                return(0);
            }
            if (thingOwner.Count <= 0)
            {
                return(0);
            }

            int result = 0;

            if (request.HasThing)
            {
                result += thingOwner.Where(thing => thing == request.thing)?.Select(thing => thing.stackCount)?.Sum() ?? 0;
            }
            if (request.HasThingFilter)
            {
                foreach (ThingDef def in request.thingFilter.AllowedThingDefs)
                {
                    result += thingOwner.TotalStackCountOfDef(def);
                }
            }

            return(result);
        }
        public static void FillOrderProcessorFromPawnKindDef(ThingOrderProcessor orderProcessor, PawnKindDef pawnKind)
        {
            ThingDef pawnThingDef = pawnKind.race;

            RaceProperties raceProps = pawnThingDef.race;

            //Assemble all required materials for a fully grown adult.
            //Meat is worth the full nutritional value.
            ThingDef meatDef           = raceProps.meatDef;
            float    meatBaseNutrition = meatDef.ingestible.CachedNutrition;
            float    meatAmount        = pawnThingDef.GetStatValueAbstract(StatDefOf.MeatAmount) * raceProps.baseBodySize;

            //Leather is worth half of the meat value.
            float leatherAmount = pawnThingDef.GetStatValueAbstract(StatDefOf.LeatherAmount) * raceProps.baseBodySize;

            int proteinAmount   = (int)(meatAmount * meatBaseNutrition * 15f) + (int)(leatherAmount * meatBaseNutrition * 15f);
            int nutritionAmount = (int)(proteinAmount * 4.5f);

            {
                ThingOrderRequest orderRequest = new ThingOrderRequest(QEThingDefOf.QE_ProteinMash, proteinAmount);
                orderProcessor.desiredIngredients.Add(orderRequest);
            }

            {
                ThingOrderRequest orderRequest = new ThingOrderRequest(QEThingDefOf.QE_NutrientSolution, nutritionAmount);
                orderProcessor.desiredIngredients.Add(orderRequest);
            }
        }
 public ThingOrderRequest(ThingOrderRequest other)
 {
     customLabel = other.customLabel;
     thing       = other.thing;
     amount      = other.amount;
     if (other.HasThingFilter)
     {
         ThingFilter filter = new ThingFilter();
         filter.CopyAllowancesFrom(other.thingFilter);
         thingFilter = filter;
     }
     Initialize();
 }
Пример #5
0
        public static void FillOrderProcessorFromVatGrowerRecipe(ThingOrderProcessor orderProcessor, GrowerRecipeDef recipeDef)
        {
            foreach (IngredientCount ingredientCount in recipeDef.ingredients)
            {
                ThingFilter filterCopy = new ThingFilter();
                filterCopy.CopyAllowancesFrom(ingredientCount.filter);

                ThingOrderRequest copy = new ThingOrderRequest(filterCopy);
                copy.amount = (int)(ingredientCount.GetBaseCount() * QEESettings.instance.organTotalResourcesFloat);

                orderProcessor.desiredIngredients.Add(copy);
            }
        }
Пример #6
0
        public void UpdateDesiredRequests()
        {
            desiredRequests.Clear();

            List <Bill> bills = new List <Bill>();

            if (_activeBill != null)
            {
                bills.Add(_activeBill);
            }
            else
            {
                bills = (observedThingHolder as IBillGiver)?.BillStack.Bills;
            }

            for (int i = 0; i < bills.Count; i++)
            {
                Bill_Production theBill = bills[i] as Bill_Production;

                if (theBill?.recipe?.ingredients == null)
                {
                    continue;
                }

                foreach (IngredientCount curIng in theBill.recipe.ingredients)
                {
                    ThingFilter filterCopy = new ThingFilter();
                    filterCopy.CopyAllowancesFrom(curIng.filter);

                    ThingOrderRequest request = new ThingOrderRequest(filterCopy);

                    int storedCount           = request.TotalStackCountForOrderRequestInContainer(ObservedThingOwner);
                    int countNeededFromRecipe = (int)(curIng.CountRequiredOfFor(curIng.FixedIngredient, theBill.recipe) *
                                                      QEESettings.instance.organTotalResourcesFloat);

                    int countNeededForCrafting = countNeededFromRecipe - storedCount;
                    countNeededForCrafting = countNeededForCrafting < 0 ? 0 : countNeededForCrafting;

                    if (countNeededForCrafting > 0)
                    {
                        //QEEMod.TryLog("Adding " + curIng.FixedIngredient.label + " amount: " + countNeededForCrafting);

                        request.amount = countNeededForCrafting;

                        desiredRequests[curIng.FixedIngredient.defName] = request;
                    }
                } //end foreach loop
            }     //end for loop
        }         //end UpdateDesiredRequests
Пример #7
0
        public void UpdateDesiredRequests()
        {
            desiredRequests.Clear();

            List <Bill> bills = new List <Bill>();

            if (_activeBill != null)
            {
                bills.Add(_activeBill);
            }
            else
            {
                bills = (observedThingHolder as IBillGiver)?.BillStack.Bills;
            }

            for (int i = 0; i < bills.Count; i++)
            {
                Bill_Production theBill = bills[i] as Bill_Production;

                if (theBill?.recipe?.ingredients == null)
                {
                    continue;
                }

                foreach (IngredientCount curIng in theBill.recipe.ingredients)
                {
                    ThingFilter filterCopy = new ThingFilter();
                    filterCopy.CopyAllowancesFrom(curIng.filter);

                    ThingOrderRequest request = new ThingOrderRequest(filterCopy);

                    int countNeededForCrafting = IngredientUtility.RemainingCountForIngredient(ObservedThingOwner, theBill.recipe, curIng);

                    if (countNeededForCrafting > 0)
                    {
                        //QEEMod.TryLog("Adding " + curIng.FixedIngredient.label + " amount: " + countNeededForCrafting);

                        request.amount = countNeededForCrafting;

                        desiredRequests[curIng.FixedIngredient.defName] = request;
                    }
                } //end foreach loop
            }     //end for loop
        }         //end UpdateDesiredRequests
Пример #8
0
        /// <summary>
        /// Checks if any Things were lost in the bill processor.
        /// </summary>
        public void ValidateDesiredRequests()
        {
            int elementsRemoved = 0;

            foreach (KeyValuePair <string, ThingOrderRequest> entry in desiredRequests)
            {
                ThingOrderRequest orderRequest = entry.Value;
                if (orderRequest != null)
                {
                    if (orderRequest.HasThing)
                    {
                        if (orderRequest.thing.Destroyed)
                        {
                            //Log.Message("QEE: ABORTING CLONE! " + orderRequest.Label + " was destroyed");
                            elementsRemoved++;
                            desiredRequests.Remove(entry.Key);
                        }
                        else if (!(orderRequest.thing.ParentHolder is Pawn_CarryTracker ||
                                   orderRequest.thing.ParentHolder is Map || orderRequest.thing.ParentHolder is IThingHolder))
                        {
                            //Log.Message("QEE: ABORTING CLONE! " + orderRequest.Label + " did not spawn in valid container");
                            elementsRemoved++;
                            desiredRequests.Remove(entry.Key);
                        }
                    }
                }
                else
                {
                    //Log.Message("QEE: orderRequest is null");
                }
            }

            if (elementsRemoved > 0)
            {
                requestsLost = true;
            }
        }