Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite crafting skill checks to use normal roll #63886

Merged
merged 21 commits into from
Mar 9, 2023

Conversation

anothersimulacrum
Copy link
Member

Summary

SUMMARY: Features "Tweak crafting failure formulas and display failure chances"

Purpose of change

See #46153 for maximal detail, this replaces that.
The goals of this are two-fold:

  1. Make calculating failure chance at all reasonable
  2. By making failure chance calculation possible, enable tweaking and testing of the crafting failure formula

There are also longer-term goals such as #44738, and enabling partial skill to play a role.

Describe the solution

From @I-am-Erk 's rewrite of the formula:

  1. NPCs no longer have to be more skilled than you to increase your chance of success. Instead, each NPC able to help that also has all the prerequisites to be able to do the craft on their own gets a skill check just like you. Then we add those skill checks together using the formula:
final skill value = sqrt( your skill value^2 + sum (all contributing NPC skill values^2) )

This root-sum-of-squares is the same system used in summing morale: it creates diminishing returns the more contributors you have, and makes more skilled sources of help substantially outweigh smaller ones. Using this formula, for example, if you and a helper NPC both have an effective skill level of 7 once all effects are applied, your combined skill level is around 10. If you add another NPC of effective skill level 7, you get a total combined skill of 12.

In the end this makes NPC helpers much more useful (previously they just added a small flat bonus, and only if they were more skilled than you).

  1. Changes the role of secondary and primary skills in your check, making secondary skills potentially more important. Previously the weight of primary and secondary skill requirements was flat: 3/4 of your skill check was from your primary skill and 1/4 was from the average of the secondary skills. Now it is a weighted average of: 2*primary skill*required level of primary skill, + sum of secondary skills * required level of secondary skills. That means if a recipe asks for electronics 2 and cooking 1 (what the hell recipe is this??), your overall level in electronics will be twice as important to your final skill value. If that same recipe uses fabrication 2 as its primary skill, then fabrication will weigh in at 2x as important as electronics and 4x as important as cooking.

  2. Moves the method of calculating your effective skill level to a new method to make it easier to determine your and your NPCs' effective skills with all modifiers included.

From my additional changes:

  1. Calculate and display the failure chance for a recipe 9f2ee4d

  2. Adjust the chance for destruction of components to follow a different formula 58f5676, and display that chance (catastrophic failure chance). This is just an easier version of the above formula for now, I just fudged it to get pretty numbers.

  3. Add some tests to:

    1. generate failure chance for every recipe in the game for some given stats related to the recipes
    2. Check if the actual failure rate of a number of recipes matches the calculated value, and that both match a value input, to detect changes to the failure rates.

Testing

See tests.
image
image
image
image
(Ridiculous percentages due to debug set skills command)

Additional context

This has ping-ponged between Erk and I for a while, and the commit history reflects that. Mergers may want to avoid squashing for history reasons.
I do not expect this to be the final formula(s), this just puts the infrastructure in place.
The proficiency info screen is lying about how the failure rates work from proficiencies. I want to fix that (included in https://github.com/CleverRaven/Cataclysm-DDA/pull/46082/commits), but it's a lot of lines, and so I think it's better separate.
Closes #46153

I-am-Erk and others added 21 commits March 7, 2023 16:22
Co-authored-by: actual-nh <74678550+actual-nh@users.noreply.github.com>
Make intelligence neutral at an average of 8.

make final_difficulty tallied the same as skill total
fix a dumb gaffe from me
just some comments as I review.
begone, unused variable.

Co-authored-by: actual-nh <74678550+actual-nh@users.noreply.github.com>
Co-authored-by: anothersimulacrum <anothersimulacrum@gmail.com>
can be worked to use morale later, not important at the moment.
Split the crafting roll function into just providing the parameters for
the normal curve it will be rolling on, and a function doing the actual
roll.
Also, fix some DBZ bugs, and add debug outputs while we're there.

Then, add a function to calculate the chance we'll pass a normal roll
with given center, stddev, and difficulty, and use that to provide the
recipe success chance.
Add this to the crafting GUI.
Fudge the numbers to make catastrophic (item-destroying) failures much
less likely than setback failures.
Also display the chance of a catastrophic failure in the UI.
Add a number of benchmark recipes which need only a 2x4 for
tools/ingredients, and test that their actual failure rates match the
calculated one and pre-provided ones at various levels of skill and
proficiency.

Also add a synthetic test to output the calculated chances for every
recipe in the game.
@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` [JSON] Changes (can be) made in JSON Code: Tests Measurement, self-control, statistics, balancing. Crafting / Construction / Recipes Includes: Uncrafting / Disassembling Info / User Interface Game - player communication, menus, etc. <Bugfix> This is a fix for a bug (or closes open issue) astyled astyled PR, label is assigned by github actions json-styled JSON lint passed, label assigned by github actions labels Mar 7, 2023
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Mar 8, 2023
@I-am-Erk
Copy link
Member

I-am-Erk commented Mar 8, 2023

thank you for this

@dseguin dseguin merged commit 1b1c08e into CleverRaven:master Mar 9, 2023
@anothersimulacrum anothersimulacrum deleted the erks-success-rolls branch March 9, 2023 15:44
@I-am-Erk
Copy link
Member

I-am-Erk commented Mar 9, 2023

we've done it Sim, we've destroyed one of the core parts of the game. Bwahahaha.

float Character::crafting_success_roll( const recipe &making ) const
{
craft_roll_data data = recipe_success_roll_data( making );
float craft_roll = std::max( normal_roll( data.center, data.stddev ), 0.0 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get an assertion failure here

/usr/include/c++/12.2.1/bits/random.h:1995: std::normal_distribution<_RealType>::param_type::param_type(_RealType, _RealType) [with _RealType = double]: Assertion '_M_stddev > _RealType(0)' failed.

Build with -Wp,-D_GLIBCXX_ASSERTIONS and run cata_test proficiency_gain_short_crafts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Code: Tests Measurement, self-control, statistics, balancing. Crafting / Construction / Recipes Includes: Uncrafting / Disassembling Info / User Interface Game - player communication, menus, etc. [JSON] Changes (can be) made in JSON json-styled JSON lint passed, label assigned by github actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants