Page 1 of 1

Allow spoil_result to spoil into multiple weighted items

Posted: Tue Nov 12, 2024 1:49 pm
by lambdalemon
Allow items to spoil into multiple items using a weighted value. And also only allow the item to spoil into one item at a time.

Code: Select all

data.raw["item"]["iron-plate"].spoil_result = {
	{
		name = "copper-ore",
		weight = 1
	},
	{
		name = "iron-ore",
		weight = 99
	}
}

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Thu Dec 05, 2024 10:17 am
by Puke
+1 to that
Currently, you can have multiple "spoil_result" for an item. Each spoil result can have a probability to happen.
But there is no way I'm aware of to make these results mutually exclusive.

Using the scripting option (spoil_to_trigger) can allow to make this possible, but runs into a wall as soon as the item spoils on a belt (because the item disappears first, then the script triggers, so you cannot replace it where it was on the belt).
Plus, scripting it may have a huge performance impact.

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Thu Dec 05, 2024 11:57 am
by Xorimuth
Puke wrote: Thu Dec 05, 2024 10:17 am Currently, you can have multiple "spoil_result" for an item. Each spoil result can have a probability to happen.
Nope, currently you can only specify a single spoil_result, unless you do more complex shenanigans with spoil_to_trigger_result.

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Thu Dec 05, 2024 3:48 pm
by Puke
That is indeed what I did, I was pretty sure I just tried putting a list of strings, but looking back at the code, I used the insert_item trigger with two items.

Still ! Have the ability to mod multiple results which could be mutually exclusive or not would be nice, in order to be able to spoil in place on a belt simply for instance.

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Thu Dec 05, 2024 9:09 pm
by protocol_1903
+1, this would be interesting for uranium and nuclear mods modeling half-lives. Imagine that each u-235 has a 50% chance to become whatever u235 decays into, and a 50% chance to stay as u235. That would be so cool.

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Thu Dec 05, 2024 9:31 pm
by MacFeejj
This is a nice idea, but technically it'd raise a _lot_ of implementation issues. Currently, one stack of items will always spoil into one stack of items - if a stack spoils while an inserter is moving it, or in a container with limited size, or while being carried in a rocket, it'll spoil into exactly one stack replacing the one already there - if one stack of items could spoil into multiple stacks, that would raise a _lot_ of issues. The only sane way I can see this working is if each stack spoils into the same item, which, while averaging out into the same result, would be quite janky.

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Fri Dec 06, 2024 12:18 am
by protocol_1903
MacFeejj wrote: Thu Dec 05, 2024 9:31 pm This is a nice idea, but technically it'd raise a _lot_ of implementation issues. Currently, one stack of items will always spoil into one stack of items - if a stack spoils while an inserter is moving it, or in a container with limited size, or while being carried in a rocket, it'll spoil into exactly one stack replacing the one already there - if one stack of items could spoil into multiple stacks, that would raise a _lot_ of issues. The only sane way I can see this working is if each stack spoils into the same item, which, while averaging out into the same result, would be quite janky.
It wouldn't really be that janky. When combining items into a stack, the spoilage time is averaged, so it's already "janky" by your definition. Making the whole stack spoil into the same item based on the defined weights would be no less jank, and still makes sense.

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Mon Jul 21, 2025 8:24 pm
by snouz
+ 1, adding a way to spoil into a random result (based on a probability value) would allow for new gameplay possibilities.

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Mon Aug 11, 2025 3:30 pm
by Rseding91
Code wise this would be fairly simple to do. Tooltip wise I have zero idea how it would be shown.

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Mon Aug 11, 2025 9:53 pm
by snouz
Rseding91 wrote: Mon Aug 11, 2025 3:30 pm Code wise this would be fairly simple to do. Tooltip wise I have zero idea how it would be shown.
A simple suggestion, which I think is clean and clear

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Tue Aug 12, 2025 12:18 am
by curiosity
Rseding91 wrote: Mon Aug 11, 2025 3:30 pm Code wise this would be fairly simple to do. Tooltip wise I have zero idea how it would be shown.
I recall raiguard(?) had a WIP implementation of weighted recipe products. See how he's done it?
snouz wrote: Mon Aug 11, 2025 9:53 pm A simple suggestion, which I think is clean and clear
That's not great, because the weight is divorced from the item.

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Tue Aug 12, 2025 2:14 am
by Rseding91
curiosity wrote: Tue Aug 12, 2025 12:18 am I recall raiguard(?) had a WIP implementation of weighted recipe products. See how he's done it?
Well… in fact one of the two kind of blocker issues with that was the tooltip.

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Tue Aug 12, 2025 2:38 am
by Jap2.0
I would expect basically the same as seen for e.g. uranium and scrap. No clue how to denote independent chances vs. exactly one though, considering that as it is now is a bit ambiguous.

Edit: checking now, I'm mixing up a couple things (or they've changed); what I was imagining was a percent on top of the icon, although [icon] 12.3% [name] would work too.

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Tue Aug 12, 2025 12:46 pm
by snouz
Something to consider: if the result is like recipe results, that means you could have several items out of 1 spoiling item? That would mean you could hit a container max and items would need to be able to spill, but I guess that's already taken into account since it can already theoretically spoil into an item with a lower stack size.

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Wed Aug 13, 2025 4:37 am
by protocol_1903
snouz wrote: Tue Aug 12, 2025 12:46 pm Something to consider: if the result is like recipe results, that means you could have several items out of 1 spoiling item? That would mean you could hit a container max and items would need to be able to spill, but I guess that's already taken into account since it can already theoretically spoil into an item with a lower stack size.
The point was to have it weighted such that there would only ever be one outcome. So item A could spoil into item B or item C with a set probability for each totaling 100%, but not both. One of the other suggestions which i like is also having a "spoil to nothing" option where the item just disappears, so you can have item B @ 30%, item C @ 20%, and nothing @ 50%

It is "like recipe results" only in the sense of defining individual "product options" with distinct probabilities

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Wed Aug 13, 2025 1:34 pm
by MrSmoothieHuman
+1, more spoilage ‘types’ is always nice to have and would make some of my ideas way more possible