[SA] How quality works under the hood?

Place to get help with not working mods / modding interface.
User avatar
Hares
Filter Inserter
Filter Inserter
Posts: 809
Joined: Sat Oct 22, 2022 8:05 pm
Contact:

[SA] How quality works under the hood?

Post by Hares »

Hi there. I've searched both the prototypes data & "quality" mod data to see what bonuses each quality provides and find only specific bonuses, but not the generic ones.
Question 1. Quality bonus
Generic quality bonuses are:
  • Normal: Level 0 / +0%
  • Uncommon: Level 1 / +30% (+30% compared to Q1)
  • Rare: Level 2 / +60% (+30% compared to Q2)
  • Epic: Level 3 / +90% (+30% compared to Q3)
  • Legendary: Level 5 / +150% (+60% compared to Q4)
At first I thought the +30% is hardcoded built-in bonus, but the Q4 -> Q5 jump is strange that way.
I assume that the properties to which these quality bonuses are applied are built-in (like health, crafting time, etc.) but the bonus itself is not.


Edit: PennyJim pointed that levels are 0-5 (with level 4 missing) and not 1-5 as I thought initially. So the +30% constant looks more real, but where the constant itself? Especially given the fact level can only be integer (unsigned integer and thus we can't have negative quality like Unfinished/Broken/Poor)
Question 2. Next level chance
For all Q1-Q4 next level is set to 0.1 (10%), but it's not explained what these numbers mean. Isn't the next quality determined by the quality bonus of a crafting machine, so having quality bonus of 16% determines that 16% of results will be at least one quality better, and at least 16% * 16% = 2.56% will be two quality levels better?
Last edited by Hares on Thu Nov 07, 2024 8:13 pm, edited 3 times in total.
User avatar
PennyJim
Fast Inserter
Fast Inserter
Posts: 107
Joined: Wed Jan 18, 2023 3:49 am
Contact:

Re: [SA] How quality works under the hood?

Post by PennyJim »

The levels are actualy

Normal: 0
Uncommon: 1
Rare: 2
Epic: 3
Legendary: 5
11-07-2024, 10-39-14.png
11-07-2024, 10-39-14.png (148.09 KiB) Viewed 1285 times
11-07-2024, 10-39-22.png
11-07-2024, 10-39-22.png (146.52 KiB) Viewed 1285 times
(Pictures obtained using the prototype explorer with ctrl-shift-e)
User avatar
Hares
Filter Inserter
Filter Inserter
Posts: 809
Joined: Sat Oct 22, 2022 8:05 pm
Contact:

Re: [SA] How quality works under the hood?

Post by Hares »

PennyJim wrote: Thu Nov 07, 2024 5:40 pm The levels are actualy

Normal: 0
Uncommon: 1
Rare: 2
Epic: 3
Legendary: 5
Thanks. Original post updated.
User avatar
Hares
Filter Inserter
Filter Inserter
Posts: 809
Joined: Sat Oct 22, 2022 8:05 pm
Contact:

Re: [SA] How quality works under the hood?

Post by Hares »

Checked the public data sources for all occurrences of the following:
  • quality
  • 0.3
  • 30% (nothing found)
Checked all utility constants & "quality"-containing classes & fields in Prototypes API.
Can't find how level is converted to the bonus. We need someone with the source code access.
User avatar
LCStark
Fast Inserter
Fast Inserter
Posts: 205
Joined: Thu Jan 28, 2021 5:04 pm
Contact:

Re: [SA] How quality works under the hood?

Post by LCStark »

Hares wrote: Thu Nov 07, 2024 5:33 pm
Question 2. Next level chance
For all Q1-Q4 next level is set to 0.1 (10%), but it's not explained what these numbers mean. Isn't the next quality determined by the quality bonus of a crafting machine, so having quality bonus of 16% determines that 16% of results will be at least one quality better, and at least 16% * 16% = 2.56% will be two quality levels better?
So, as far as I understand it: The 10% you see in the "Quality probabilities" section of Tips and tricks is confusing, because both the given quality percent bonus and the chance to skip to the next level are the same.

It shows an assembler with 4 T3 quality modules (each giving +2.5%). The 10% is the chance to get the next quality level from the ingredient base, and each higher level has that chance reduced by a factor of 1/10th. Meaning that if you'd use only one T3 quality module, you'd get 2.5% chance for at least 1 level higher, 0.25% chance for at least 2 levels higher, etc.

I've made a little test. I've set up an Assembling Machine 3 with 4 T3 quality modules and gave it resources to craft 100k electronic circuits. This was the result:

11-07-2024, 23-11-15.png
11-07-2024, 23-11-15.png (49.11 KiB) Viewed 1226 times

I ran a bit shorter test for only one T3 quality module and it looks like the result is what I've expected:

11-07-2024, 23-11-20.png
11-07-2024, 23-11-20.png (46.66 KiB) Viewed 1226 times

For +2.5% quality bonus we got 0.9 * 2.5% uncommons, ~0.09 * 2.5% rares and ~0.009 * 2.5% epics.

So, it looks more or less to be what is happening. For a given total quality bonus of the machine, you'll get that much upgraded items in total. Skipping quality steps doesn't seem to be affected by the +quality% bonus and is always a 10% chance of getting further upgrade after we rolled a quality gain. Regardless of quality bonus, we always get around (0.9 * quality) one level upgrade, (0.09 * quality) two levels upgrade, etc.


This could probably use a more extensive test with multiple repeats and a higher amount of resources used (especially given that at this scale there's a large discrepancy for the legendary level upgrade), but it looks to be in the right ballpark.
User avatar
BraveCaperCat
Filter Inserter
Filter Inserter
Posts: 430
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: [SA] How quality works under the hood?

Post by BraveCaperCat »

LCStark wrote: Thu Nov 07, 2024 10:32 pm
Hares wrote: Thu Nov 07, 2024 5:33 pm
Question 2. Next level chance
For all Q1-Q4 next level is set to 0.1 (10%), but it's not explained what these numbers mean. Isn't the next quality determined by the quality bonus of a crafting machine, so having quality bonus of 16% determines that 16% of results will be at least one quality better, and at least 16% * 16% = 2.56% will be two quality levels better?
So, as far as I understand it: The 10% you see in the "Quality probabilities" section of Tips and tricks is confusing, because both the given quality percent bonus and the chance to skip to the next level are the same.

It shows an assembler with 4 T3 quality modules (each giving +2.5%). The 10% is the chance to get the next quality level from the ingredient base, and each higher level has that chance reduced by a factor of 1/10th. Meaning that if you'd use only one T3 quality module, you'd get 2.5% chance for at least 1 level higher, 0.25% chance for at least 2 levels higher, etc.

I've made a little test. I've set up an Assembling Machine 3 with 4 T3 quality modules and gave it resources to craft 100k electronic circuits. This was the result:


11-07-2024, 23-11-15.png


I ran a bit shorter test for only one T3 quality module and it looks like the result is what I've expected:


11-07-2024, 23-11-20.png


For +2.5% quality bonus we got 0.9 * 2.5% uncommons, ~0.09 * 2.5% rares and ~0.009 * 2.5% epics.

So, it looks more or less to be what is happening. For a given total quality bonus of the machine, you'll get that much upgraded items in total. Skipping quality steps doesn't seem to be affected by the +quality% bonus and is always a 10% chance of getting further upgrade after we rolled a quality gain. Regardless of quality bonus, we always get around (0.9 * quality) one level upgrade, (0.09 * quality) two levels upgrade, etc.


This could probably use a more extensive test with multiple repeats and a higher amount of resources used (especially given that at this scale there's a large discrepancy for the legendary level upgrade), but it looks to be in the right ballpark.
I'll do 1M+ Electronic Circuits tests.
Creator of multiple mods, including Quality Assurance - My most popular one.
Go check them out with the first and second links!
I'll probably be wanting or giving help with modding most of the time I spend here on the forum.
User avatar
Hares
Filter Inserter
Filter Inserter
Posts: 809
Joined: Sat Oct 22, 2022 8:05 pm
Contact:

Re: [SA] How quality works under the hood?

Post by Hares »

LCStark wrote: Thu Nov 07, 2024 10:32 pm
Hares wrote: Thu Nov 07, 2024 5:33 pm
Question 2. Next level chance
For all Q1-Q4 next level is set to 0.1 (10%), but it's not explained what these numbers mean. Isn't the next quality determined by the quality bonus of a crafting machine, so having quality bonus of 16% determines that 16% of results will be at least one quality better, and at least 16% * 16% = 2.56% will be two quality levels better?
So, as far as I understand it: The 10% you see in the "Quality probabilities" section of Tips and tricks is confusing, because both the given quality percent bonus and the chance to skip to the next level are the same.
I am not referring to one in Tips & Tricks, I am speaking of this field (API, definition):
11-08-2024, 01-59-33.png
11-08-2024, 01-59-33.png (22.74 KiB) Viewed 1207 times
User avatar
LCStark
Fast Inserter
Fast Inserter
Posts: 205
Joined: Thu Jan 28, 2021 5:04 pm
Contact:

Re: [SA] How quality works under the hood?

Post by LCStark »

Hares wrote: Thu Nov 07, 2024 11:00 pm I am not referring to one in Tips & Tricks, I am speaking of this field (API, definition):
11-08-2024, 01-59-33.png
Look at the amounts I got in my test. It looks like when you get a quality upgrade from the machine's +quality%, that 0.1 is just a roll chance to further upgrade the quality level. So if you're producing with normal ingredients and you get an upgrade to an uncommon, before that uncommon is returned as a product the game rolls for a chance to upgrade it to a rare one, with 10% (or 0.1) chance of getting the rare and 90% (or 1.0 - 0.1) of remaining uncommon. And if it rolls for the rare, it rolls again with 10% chance to upgrade to epic and 90% of remaining rare. And if you get the epic it rolls again, with 10% chance to upgrade to legendary and 90% chance to remain epic.
User avatar
Hares
Filter Inserter
Filter Inserter
Posts: 809
Joined: Sat Oct 22, 2022 8:05 pm
Contact:

Re: [SA] How quality works under the hood?

Post by Hares »

LCStark wrote: Thu Nov 07, 2024 11:09 pm
Hares wrote: Thu Nov 07, 2024 11:00 pm I am not referring to one in Tips & Tricks, I am speaking of this field (API, definition):
11-08-2024, 01-59-33.png
Look at the amounts I got in my test. It looks like when you get a quality upgrade from the machine's +quality%, that 0.1 is just a roll chance to further upgrade the quality level. So if you're producing with normal ingredients and you get an upgrade to an uncommon, before that uncommon is returned as a product the game rolls for a chance to upgrade it to a rare one, with 10% (or 0.1) chance of getting the rare and 90% (or 1.0 - 0.1) of remaining uncommon. And if it rolls for the rare, it rolls again with 10% chance to upgrade to epic and 90% of remaining rare. And if you get the epic it rolls again, with 10% chance to upgrade to legendary and 90% chance to remain epic.
Thanks. Extremely unobvious behaviour.
Post Reply

Return to “Modding help”