Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Adventure Mode Cooking  (Read 2760 times)

Nathail

  • Bay Watcher
  • Dabbling Modder
    • View Profile
Adventure Mode Cooking
« on: December 01, 2016, 12:53:27 pm »

I'm trying to make it so you can cook the default food items in adventure mode. The reactions currently look like this:

Code: [Select]
reaction_adv_cooking

[OBJECT:REACTION]

[REACTION:PREPARE EASY MEAL]
[NAME:prepare easy meal]
[ADVENTURE_MODE_ENABLED]
[REAGENT:primary ingredient:1:NONE:NONE:NONE:NONE]
[REACTION_CLASS:COOKABLE][UNROTTEN]
[REAGENT:secondary ingredient:1:NONE:NONE:NONE:NONE]
[REACTION_CLASS:COOKABLE][UNROTTEN]
[PRODUCT:100:1:FOOD:ITEM_FOOD_BISCUITS:GET_MATERIAL_FROM_REAGENT:primary ingredient:NONE]
[PRODUCT_TOKEN:biscuits]
[SKILL:COOK]
[CATEGORY:ADV_COOKING]
[CATEGORY_NAME:Cooking]
[CATEGORY_DESCRIPTION:Prepare meals from edible meat and plants.]

[REACTION:PREPARE FINE MEAL]
[NAME:prepare fine meal]
[ADVENTURE_MODE_ENABLED]
[REAGENT:primary ingredient:1:NONE:NONE:NONE:NONE]
[REACTION_CLASS:COOKABLE][UNROTTEN]
[REAGENT:secondary ingredient:1:NONE:NONE:NONE:NONE]
[REACTION_CLASS:COOKABLE][UNROTTEN]
[REAGENT:tertiary ingredient:1:NONE:NONE:NONE:NONE]
[REACTION_CLASS:COOKABLE][UNROTTEN]
[PRODUCT:100:1:FOOD:ITEM_FOOD_STEW:GET_MATERIAL_FROM_REAGENT:primary ingredient:NONE]
[PRODUCT_TOKEN:stew]
[SKILL:COOK]
[CATEGORY:ADV_COOKING]

[REACTION:PREPARE LAVISH MEAL]
[NAME:prepare lavish meal]
[ADVENTURE_MODE_ENABLED]
[REAGENT:primary ingredient:1:NONE:NONE:NONE:NONE]
[REACTION_CLASS:COOKABLE][UNROTTEN]
[REAGENT:secondary ingredient:1:NONE:NONE:NONE:NONE]
[REACTION_CLASS:COOKABLE][UNROTTEN]
[REAGENT:tertiary ingredient:1:NONE:NONE:NONE:NONE]
[REACTION_CLASS:COOKABLE][UNROTTEN]
[REAGENT:quaternary ingredient:1:NONE:NONE:NONE:NONE]
[REACTION_CLASS:COOKABLE][UNROTTEN]
[PRODUCT:100:1:FOOD:ITEM_FOOD_ROAST:GET_MATERIAL_FROM_REAGENT:primary ingredient:NONE]
[PRODUCT_TOKEN:roast]
[SKILL:COOK]
[CATEGORY:ADV_COOKING]

I've gone and attached [REACTION_CLASS:COOKABLE] to every material with the [EDIBLE_COOKED] token, for example:

Code: [Select]
[MATERIAL_TEMPLATE:MUSCLE_TEMPLATE]
[STATE_COLOR:ALL_SOLID:MAUVE]
[STATE_NAME:ALL_SOLID:muscle]
[STATE_ADJ:ALL_SOLID:muscle]
[STATE_COLOR:LIQUID:MAUVE]
[STATE_NAME:LIQUID:n/a]
[STATE_ADJ:LIQUID:n/a]
[STATE_COLOR:GAS:MAUVE]
[STATE_NAME:GAS:n/a]
[STATE_ADJ:GAS:n/a]
[DISPLAY_COLOR:4:0:0]
[MATERIAL_VALUE:1]
[SPEC_HEAT:4181]
[IGNITE_POINT:10508]
[MELTING_POINT:NONE]
[BOILING_POINT:NONE]
[HEATDAM_POINT:10250]
[COLDDAM_POINT:9900]
[MAT_FIXED_TEMP:NONE]
[SOLID_DENSITY:1060]
[LIQUID_DENSITY:NONE]
[MOLAR_MASS:NONE]
[IMPACT_YIELD:10000]
[IMPACT_FRACTURE:10000]
[IMPACT_STRAIN_AT_YIELD:50000]
[COMPRESSIVE_YIELD:10000]
[COMPRESSIVE_FRACTURE:10000]
[COMPRESSIVE_STRAIN_AT_YIELD:50000]
[TENSILE_YIELD:10000]
[TENSILE_FRACTURE:10000]
[TENSILE_STRAIN_AT_YIELD:50000]
[TORSION_YIELD:10000]
[TORSION_FRACTURE:10000]
[TORSION_STRAIN_AT_YIELD:50000]
[SHEAR_YIELD:20000] used human skin
[SHEAR_FRACTURE:20000]
[SHEAR_STRAIN_AT_YIELD:50000]
[BENDING_YIELD:10000]
[BENDING_FRACTURE:10000]
[BENDING_STRAIN_AT_YIELD:50000]
[MAX_EDGE:0]
[ABSORPTION:100]
[IMPLIES_ANIMAL_KILL]
[ROTS]
[GENERATES_MIASMA]
[MEAT]
[BUTCHER_SPECIAL:MEAT:NONE]
[MEAT_NAME:NONE:meat:meat]
This lets the game know that the item can be eaten in various ways.
[EDIBLE_VERMIN]
[EDIBLE_COOKED] [REACTION_CLASS:COOKABLE]


and

Code: [Select]
[MATERIAL_TEMPLATE:HEART_TEMPLATE]
[STATE_COLOR:ALL_SOLID:MAUVE]
[STATE_NAME:ALL_SOLID:heart tissue]
[STATE_ADJ:ALL_SOLID:heart tissue]
[STATE_COLOR:LIQUID:MAUVE]
[STATE_NAME:LIQUID:n/a]
[STATE_ADJ:LIQUID:n/a]
[STATE_COLOR:GAS:MAUVE]
[STATE_NAME:GAS:n/a]
[STATE_ADJ:GAS:n/a]
[DISPLAY_COLOR:4:0:0]
[MATERIAL_VALUE:1]
[SPEC_HEAT:4181]
[IGNITE_POINT:10508]
[MELTING_POINT:NONE]
[BOILING_POINT:NONE]
[HEATDAM_POINT:10250]
[COLDDAM_POINT:9900]
[MAT_FIXED_TEMP:NONE]
[SOLID_DENSITY:500]
[LIQUID_DENSITY:NONE]
[MOLAR_MASS:NONE]
[IMPACT_YIELD:10000]
[IMPACT_FRACTURE:10000]
[IMPACT_STRAIN_AT_YIELD:50000]
[COMPRESSIVE_YIELD:10000]
[COMPRESSIVE_FRACTURE:10000]
[COMPRESSIVE_STRAIN_AT_YIELD:50000]
[TENSILE_YIELD:10000]
[TENSILE_FRACTURE:10000]
[TENSILE_STRAIN_AT_YIELD:50000]
[TORSION_YIELD:10000]
[TORSION_FRACTURE:10000]
[TORSION_STRAIN_AT_YIELD:50000]
[SHEAR_YIELD:20000] copied human skin (no data)
[SHEAR_FRACTURE:20000]
[SHEAR_STRAIN_AT_YIELD:50000]
[BENDING_YIELD:10000]
[BENDING_FRACTURE:10000]
[BENDING_STRAIN_AT_YIELD:50000]
[MAX_EDGE:0]
[ABSORPTION:100]
[IMPLIES_ANIMAL_KILL]
[ROTS]
[GENERATES_MIASMA]
[MEAT]
[BUTCHER_SPECIAL:MEAT:NONE]
[MEAT_NAME:prepared:heart:heart]
[EDIBLE_VERMIN]
[EDIBLE_COOKED] [REACTION_CLASS:COOKABLE]

Everything starts out well, the game recognizes cookable materials (it wants to use an entire stack at a time, but I'm not worried about that), but when I select the final reagent the game crashes. Can you not make actual food items in adventure mode or have I made a mistake?
Logged

kiwiphoenix

  • Bay Watcher
    • View Profile
Re: Adventure Mode Cooking
« Reply #1 on: December 01, 2016, 05:14:38 pm »

No mistake, I'm afraid - to the contrary, I applaud your use of REACTION_CLASSes.

The issue here is that prepared meals can't me made via reaction at all - only by the hardcoded reactions at the Kitchen.

Sorry, your idea and execution are pretty solid, it's just not possible.



The closest thing you could do is use a dummy plant/animal to produce a veggie/meat/fish/cheese that is named like a meal.

Cheese is a good choice for this, since there aren't a lot in Vanilla, and they're fairly inert in terms of game mechanics - they won't be used to feed carnivores/herbivores, etc.
Logged

Nathail

  • Bay Watcher
  • Dabbling Modder
    • View Profile
Re: Adventure Mode Cooking
« Reply #2 on: December 01, 2016, 06:31:50 pm »

Well, that explains why Adventurecraft uses hardtack for cooking. Oh well, such is Dwarf Fortress. Thanks!
Logged

milo christiansen

  • Bay Watcher
  • Something generic here
    • View Profile
Re: Adventure Mode Cooking
« Reply #3 on: December 02, 2016, 01:03:58 pm »

Before you give up: Look at my Underhive Settlement reboot, I make prepared meals in reactions there just fine. All you need is a healthy daub of DFHack code and everything "Just Works (tm)".

Here is the heart of the code in question:
Code: [Select]
function makeMeal(id, parts)
local types = {}
local ids = {}
for i, part in ipairs(parts) do
ids[part[1]] = i
types[i] = part[2]
end

return function(reaction, reaction_product, unit, input_items, input_reagents, output_items, call_native)
call_native.value = false

local item = df['item_foodst']:new()

item.id = df.global.item_next_id
df.global.world.items.all:insert('#',item)
df.global.item_next_id = df.global.item_next_id + 1

-- These always seem to be -1.
item.entity = -1
item.recipe_id = -1

item:setSubtype(dfhack.items.findSubtype(id))

local mats, stk = {}, 0

for x = 0, #input_items - 1, 1 do
local i = ids[input_reagents[x].code]
if i ~= nil then
mats[i] = dfhack.matinfo.decode(input_items[x])
cooked = items.GetMRP("COOKED_MAT", mats[i])
if cooked ~= nil then
mats[i] = cooked
end
stk = stk + input_items[x].stack_size
input_items[x].stack_size = 1
end
end

for i, typ in ipairs(types) do
if typ == "FISH" then
-- This is super weird, but it seems that fish items have their material numbers reversed?
-- Without this you end up with meals made from odd materials. For example sludge prawns report
-- they are material 19:27 and the "rival" creature is 27:19. If you cook sludge prawns you end
-- up with meals made from that rival creature.
-- Maybe "FISH" type items are supposed to use a creature/caste pair instead of a material? Either
-- one seems to work just fine...
item.ingredients:insert('#', {
new = true,
anon_1 = 0,
item_type = df.item_type[typ],
unk_4 = -1,
mat_type = mats[i].index,
mat_index = mats[i].type,
maker = -1,
unk_10 = 0, -- No quality
unk_14 = 0,
unk_18 = -1,
})
else
item.ingredients:insert('#', {
new = true,
anon_1 = 0,
item_type = df.item_type[typ],
unk_4 = -1,
mat_type = mats[i].type,
mat_index = mats[i].index,
maker = -1,
unk_10 = 0, -- No quality
unk_14 = 0,
unk_18 = -1,
})
end
end

item:assignQuality(unit, reaction.skill)
item:setMaker(unit.id)
item.stack_size = stk
item:categorize(true)
levelUp(unit, reaction.skill, 30)
output_items:insert('#', item)
end
end

It's complicated by the fact that this works hand in hand with some special "glue" code generated by Rubble, but you should be able to divine the basic principles either from this or by looking at the whole system.

The only possible sticking point is if reaction hooks work in adventure mode or not (I think they do).
Logged
Rubble 8 - The most powerful modding suite in existence!
After all, coke is for furnaces, not for snorting.
You're not true dwarven royalty unless you own the complete 'Signature Collection' baby-bone bedroom set from NOKEAS