eradicator wrote: Sun Apr 25, 2021 9:18 pm
Pi-C wrote: Sun Apr 25, 2021 6:22 pm
When using named keys, either amount or (amount_min and amount_max) must be set. But what happens if all are used?
You mean something like this? I think the general rule of thumb is that it always uses the most specific entry, but written clarification would clearly not hurt. Best in a form that tells the user not to attempt such mixtures in the first place.
Code: Select all
{'apple', 1, name='pear', amount=42, amount_min=7, amount_max=3}
Your case has already been covered at the top of the page:
An item product definition for a Prototype/Recipe. Its loading is triggered by the type of a Types/ProductPrototype being "item". It can be specified as a table with named or numbered keys, but not a mix of both.
I was particularly interested in the amount part. The description of amount_max already has:
"If set to a number that is less than amount_min, the game will use amount_min internally. "
But how about a simple case like
Code: Select all
{name='pear', amount=42, amount_min=3, amount_max=7}
I'd assume that "amount=42" would win in this case, but there's room for doubt -- it could also be the range amount_min…amount_max.
Coming to think of it, recipe.results is an array, so if different mods modify the same recipe, it could end up like this:
Code: Select all
{
{'apple', 1},
{name='apple', amount=2},
{name='pear', amount=42, catalyst_amount=28},
{name='pear', amount=24, probability=0.5},
{name='pear', amount=11, probability=0.3},
}
How would that be combined?
Code: Select all
-- Entries of corresponding results are merged, values with the same name are added
{
{name='apple', amount=3},
{name='pear', amount=77, catalyst_amount=28, probability=0.8},
}
-- Entries of corresponding results are merged, values with the same name are averaged (rounded down)
{
{name='apple', amount=1},
{name='pear', amount=77, catalyst_amount=28, probability=0.8},
{name='pear', amount=42, catalyst_amount=math.floor(28 / 3), probability=math.floor( ( (0.8*10) / 3) / 10},
}
-- Entries of corresponding results are merged, values with the same name are averaged (rounded up)
{
{name='apple', amount=2},
{name='pear', amount=42, catalyst_amount=math.ceil(28 / 3), probability=math.ceil( ( (0.8*10) / 3) / 10},
}
-- Entries of corresponding results are merged, optional values from later entries will overwrite those from earlier ones
{
{name='apple', amount=3},
{name='pear', amount=77, catalyst_amount=28, probability=0.3},
}
-- Entries of corresponding results are merged unless they differ in regard to optional values
{
{name='apple', amount=3},
-- Result in game: 14 … (14+24+11)
{name='pear', amount=42, catalyst_amount=28},
{name='pear', amount=24, probability=0.5},
{name='pear', amount=11, probability=0.3},
}