Jump to content

How does crockpot determine output


Recommended Posts

Not sure if this is the right place to ask but i did try to look around and google this so hoping someone can help out here :D

If someone could point me to the actual code that would be great too.

I'm trying to make a cooking system similar to how cooking in don't starve works for a school project. My question is how does the crockpot cooking function work? I'm looking for an elegant way to determine output based on 5 ingredients placed in a cooker. I've looked around and could only find recipe mods and not cooker mods.

Currently I'm thinking of sorting an input array of 5 ingredients based on their generic type such as MEAT and then going down a switch statement to determine what will come out. I know this isn't how it's implemented because of the "food values" such as "meat value" and "fish/seafood value" + there some bacon and eggs recipes have a 50% chance to turn into monster lasagna, and a switch statement would just output the first thing that fits.

Also how would i implement fillers and exclusive fillers such as no meat in dragonpie?

Edited by Sujio
Link to comment
Share on other sites

Each recipe has a weight/priority stat, the recipes with the highest weight with the correct ingredients will be prepared. In the case of a tie, it will randomly choose one of the recipes from the tie.

For more information check the preparedfoods.lua

The ingredients allowed in a recipe are stated in that file as well.

Link to comment
Share on other sites

Thanks for the reply IronHunter,

I've already taken a look at the preparedfoods.lua but maybe I'm not familiar with Lua or scripting in general so I'm not sure what is going on in the file.

Spoiler

local foods=
{
    butterflymuffin =
    {
        test = function(cooker, names, tags) return names.butterflywings and not tags.meat and tags.veggie end,
        priority = 1,
        weight = 1,
        foodtype = "VEGGIE",
        health = TUNING.HEALING_MED,
        hunger = TUNING.CALORIES_LARGE,
        perishtime = TUNING.PERISH_SLOW,
        sanity = TUNING.SANITY_TINY,
        cooktime = 2,
    },

    //other recipes

}
for k,v in pairs(foods) do
    v.name = k
    v.weight = v.weight or 1
    v.priority = v.priority or 0
end


return foods
 

Is it the test = function(cooker,names,tag) line or the for loop at the end that determines which recipe is being used?

Link to comment
Share on other sites

I should of clarified that there are two preparedfoods.lua files, one in the main script folders and one in the prefabs folder.

The one in the script folder is imported into the prefab one and acts like a database.

The prefab one does all the actual work for making them into a crockpot dish, and making your own equivalent file is what most modders do to add custom crockpot foods.

In the modmain you'll have to use

	local foods = require("shipwreckedfood")--for example I have a clone of preparedfoods called shipwreckedfood.lua
	for k,recipe in pairs (foods) do
		AddCookerRecipe("cookpot", recipe)
		--AddCookerRecipe("portablecookpot", recipe)
	end

 

Link to comment
Share on other sites

Hello @Sujio!

IronHunter has been describing the cooking recipes (the data). The actual cooking logic is located in scripts/cooking.lua

Basically, every ingredient has "tags" with a certain value each (how much of that kind of ingredient it is). For example, morsels are 0.5 "meat", full meat is 1 "meat", monster meat is 1 "meat" and 1 "monster".

When the crockpot finishes cooking, it checks all recipes to see if they are possible. The possible recipes are sorted by priority. Should there be several top priority recipes, it chooses randomly (weighted, using weights given by the individual recipes).

Feel free to ping me if you need more information.

Link to comment
Share on other sites

Ahh okay that makes sense but i'm still wondering how the crockpot determines which recipe to output based on 4 ingredients, not adding extra recipes.

So looking at the prefab preparedfoods.lua:

Spoiler


local foods = require("preparedfoods")
for k,v in pairs(foods) do
    table.insert(prefs, MakePreparedFood(v))
end
 

does it store all the recipes in the main scripts in a table, and test recipes until one fits? 

5 minutes ago, Mobbstar said:

Hello @Sujio!

IronHunter has been describing the cooking recipes (the data). The actual cooking logic is located in scripts/cooking.lua

Basically, every ingredient has "tags" with a certain value each (how much of that kind of ingredient it is). For example, morsels are 0.5 "meat", full meat is 1 "meat", monster meat is 1 "meat" and 1 "monster".

When the crockpot finishes cooking, it checks all recipes to see if they are possible. The possible recipes are sorted by priority. Should there be several top priority recipes, it chooses randomly (weighted, using weights given by the individual recipes).

Feel free to ping me if you need more information.

Ah yes thank you, this is what i am looking for!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...