Suggestion of a way how to implement dependent probabilities
Posted: Mon May 14, 2018 8:55 pm
TL;DR
Here's a suggestion where and how fields have to added in order to allow dependent ingredient and product probabilities in recipes.What?
I suggest expanding the ability of modders to work with volatile values in recipes. Currently, it is possible to have products in a recipe that vary between minimum and maximum values and only appear with a certain probability. This does not work with recipe ingredients nor is it possible to have multiple products that are dependent of one another. As a Lua user I can only guess how the hard-coded data flow works, but I think with the following additional fields, the problem might be solved. (If not, feel free to correct me.)What modders do when adding recipes, is expanding data.raw with a new instance of LuaRecipePrototype. This is where we should store the dependent probabilities in a triple array. A corresponding Lua code could look something like this:
dependent_probability structure
In each section, all probabilities must add up to 100%. Each string value is used to reference the double value behind it and mustn’t be used twice inside the dependent_probability array.As soon as a recipe is executed, a LuaRecipe instance gets created. When doing so, the given double values are checked against math.random() and transferred into boolean values. The cruial point here is that in each section, only one value becomes true, while each section is independent of the others. It will be saved like this (in pseudocode):
dependent_probability in LuaRecipe
Of course, ingredients and products of recipes would have to support this new probability field. Now, the question is why ingredients currently don’t have the probability, amount_min and amount_max fields. Did nobody ask for this or does this create problems for hand-crafting-calculations? Eventually, a volatile ingredient would only mean that the number of items being consumed at the beginning of a crafting process looks differently every time.In the case that this doesn’t represent a problem, I suggest either making the current probability field additionally supporting a string type or adding a separate field for dependent_probability only accepting string values. This string value is used to load the corresponding double value from the recipe prototype for the tooltip and to load the boolean value from the recipe instance to calculate the resulting count of ingredients and products for this recipe execution.
Why ?
With these additions, modders of Factorio would a have lots of new potential to design interesting manufacturing processes. The first big issue I would like to address is the wear of tools during crafting processes. Let’s say, a saw that is used to cut trees shall break with a 5% chance and create debris items that can be recycled. Right now, you could add the same saw with a 95% probability to the output and re-insert it every time it is not consumed or just scale up the recipe by a factor of 20. But both workarounds are far from being a pleasant solution. And after all, after such a recipe execution, you can end up with both a saw and debris items or none of it. Not really an ideal solution.Here’s an example how this problem could be avoided with my suggestion implemented:
Example tool wear
This would mean that the sawing tool breaks with a 5% chance. Always when this happens and only in that case, debris items will be part of the output. But anyways, the big-log-item will be processed into planks. If this shall not happen after a tool break, you could add the negated probability to these items:example tool wear 2
The other point are recipes that split one item up into several possible products. In vanilla Factorio, this can be seen in uranium-processing that converts uranium ore into the desired U-235 which spawns with a 0.007 chance and U-238 with a 0.993 chance. But just like mentioned above, you can end up with both items or none of it, so on the micro level you’re basically creating items from nowhere or sending them to nirvana.With my suggestion implemented, this problem wouldn’t arise anymore (and you could even split an item into three or more products this way). So, the uranium recipe might look like this:
example uranium-processing
Parts of this idea have already been posted here:viewtopic.php?f=6&t=47739&p=281168&hili ... ty#p275350
viewtopic.php?f=6&t=60145&p=361046&hili ... ty#p361046
The content of both wasn’t commented by the devs. Maybe because they weren’t posted in the API suggestions thread? Maybe because I didn’t use the fancy yellow headline template? (Yes, the second thread was created by me – but it contained just a small part of this idea and this is just a too burning issue for me )
For everyone who read trough all of this: excuse the length of this thread, but I didn’t want to leave any ambiguity. I’m looking forward to reading your thoughts about this issue