Exemplo n.º 1
0
        } //end FindClosestIngForBill

        public static Thing FindClosestIngToBillGiver(Bill theBill, IngredientCount curIng)
        {
            IBillGiver   billGiver            = theBill.billStack.billGiver;
            IThingHolder holder               = billGiver as IThingHolder;
            Thing        building             = billGiver as Thing;
            ThingOwner   vatStoredIngredients = holder?.GetDirectlyHeldThings();

            if (billGiver == null || building == null || billGiver == null || vatStoredIngredients == null)
            {
                return(null);
            }

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

            //only check the map for Things if the vat still needs some of this ingredient
            if (countNeededForCrafting > 0)
            {
                //find the closest accessible Thing of that ThingDef on the map
                ThingRequest tRequest = ThingRequest.ForDef(curIng.FixedIngredient);

                IEnumerable <Thing> searchSet = billGiver.Map.listerThings.ThingsMatching(tRequest);
                Thing result = GenClosest.ClosestThing_Global(building.Position, searchSet,
                                                              validator :
                                                              delegate(Thing testThing)
                {
                    if (testThing.def.defName != curIng.FixedIngredient.defName)
                    {
                        return(false);
                    }

                    if (testThing.IsForbidden(building.Faction))
                    {
                        return(false);
                    }

                    return(true);
                });

                //return the Thing, if we found one
                if (result != null)
                {
                    //QEEMod.TryLog("Ingredient found: " + curIng.FixedIngredient.label + " | stackCount: " + result.stackCount + " | recipe: "
                    //    + countNeededFromRecipe);
                    return(result);
                }
            }

            return(null);
        } //end function FindClosestIngToBillGiver
Exemplo n.º 2
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