Does mafia support recursion?

dj_d

Member
I'm trying to figure out a reasonably elegant way of saying "Do I have the ingredients to make X? If not, do I have the ingredients to make the ingredients? If not..."

and turtles all the way down.

(bonus if anyone knows how to figure out if you have the skills AND the ingredients!)
 

jasonharper

Developer
creatable_amount() will tell you if you can make something with the ingredients on hand, including the possibility of making the ingredients themselves. It's only turtles all the way down when Armorcraftiness is involved!

get_ingredients() will return an empty map if you don't have the skill needed to create the item.

Yes, you can use recursion in ASH, but you need to take care to avoid infinite recursion. There are loops you must avoid; flat dough and wads of dough are creatable from each other, and of course there are the two forms of clover.
 

dj_d

Member
Woohoo!

How does creatable_amount handle the absence of bartender & chef? Assuming it doesn't care if the helper is there, can I find out if the helper is actually required for the recipe somehow?
 

jasonharper

Developer
The logic here is rather complicated, but it looks like it's doing the right thing. Cooking, for example, is permitted if you either have a chef, have the ingredients for a chef, or have allowed buying things from the mall. If you don't have "require box servants" checked, cooking will additionally be permitted if you either have an oven, or enough meat to buy an oven.
 

zarqon

Well-known member
Word of caution: beware get_ingredients(). It would appear to give you a map of all the items you need to make an item, but last I checked this is not the case: all item amounts in the returned map are 1, regardless of the actual amount needed to create the item.
 

Veracity

Developer
Staff member
Can you give an example of this bug, please?

> ash get_ingredients( $item[staff of the black kettle] );

Returned: aggregate int [item]
Staff of the Teapot Tempest => 1
around the world => 1
asbestos ore => 1
jug-o-magicalness => 1
magical mystery juice => 6
olive lo mein => 1

> ash get_ingredients( $item[star crossbow] );

Returned: aggregate int [item]
line => 6
star => 5
star chart => 1
 

zarqon

Well-known member
"Last I checked" was several weeks ago, in the middle of Crimbo craziness, and I did mention it in an obscure area of the forum. Rechecking now shows the problem still exists, but I'm glad to see it is not for all items. A few cases I've encountered:

> ash get_ingredients( $item[asshat] );

Returned: aggregate int [item]
bum cheek => 1

> ash get_ingredients( $item[pair of twitching claws] );

Returned: aggregate int [item]
twitching claw => 1
 

jasonharper

Developer
Checking in a fix now... EDIT: r6714. The Universe is now safe from the paradox of having a pair of twitching claws that is created from one twitching claw!
 
Top