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

Make item crafting options include recipes from nearby books #37661

Merged
merged 11 commits into from
Feb 9, 2020

Conversation

wapcaplet
Copy link
Contributor

@wapcaplet wapcaplet commented Feb 3, 2020

Summary

SUMMARY: Bugfixes "Make item description consistent with crafting UI for recipe list"

Purpose of change

Resolves #37643

Describe the solution

Instead of showing only memorized recipes at the bottom of the item description panel, show all available recipes (including those from nearby books), so the "You could use it to craft: ..." message is consistent with the recipes found in the main crafting UI for that item.

If no recipes are available (in memorized recipes or nearby books), include this at the bottom of the item description: "You know of nothing you could craft with it."

Describe alternatives you've considered

Considered preserving the original behavior in the item description of only showing learned/memorized recipes, but was persuaded by other players/developers that this was bad and should be changed.

Testing

I tested a variety of ad-hoc use cases, but here's a specific example:

  • Create a new world and blank 0-skill character (survivor scenario)
  • Use the debugging menu to spawn in:
    • "What's a Transistor?"
    • 1 heating element
    • 1 amplifier circuit
  • Read the book or use debug to get Electronics skill to level 2

Then compare:

  • With "What's a Transistor?" nearby:
    • Inspect heating element: You could use it to craft: hotplate and coffeemaker
    • Go to crafting menu and / to search, c:heating element: Matches hotplate and coffemaker
    • Inspect amplifier circuit, and compare recipes with crafting menu: All 7 recipes match
  • Without "What's a Transistor?" nearby:
    • amplifier circuit only has "noise emitter (off)" in both screens
    • heating element has no recipes available in either screen

Additional context

Screenshots below are cut/pasted to show item description and crafting UI for comparison.

With "What's a Transistor?" nearby, the heating element has two recipes available in both the item description and crafting menu:

image

Similarly, the amplifier circuit item description and crafting recipes are matching:

image

With the book too far away, the only recipe I get for the amplifier circuit is the level-0-auto-learned "noise emitter (off)":

image

And for the heating element, without "What's a Transistor?", there are no known recipes:

image

To encourage player to memorize more recipes, and/or make it clearer
that "You could craft" would appear in this place if more recipes were
known.

Resolves CleverRaven#37643

Splits the existing `if` condition into two parts, first to check
if known recipes are empty, and display this message at the bottom of
the item description panel:

    You don't know anything you could craft with it.

Note, unless recipes are listed, this message will be shown for all
items, whether or not recipes exist for the item.
@wapcaplet wapcaplet changed the title Add item description when lacking crafting knowledge WIP Add item description when lacking crafting knowledge Feb 3, 2020
@wapcaplet
Copy link
Contributor Author

I see this change caused a couple failing test cases in tests/iteminfo_test.cpp.

Marking this PR as WIP until I can fix those (I've been looking for an excuse to get into the tests anyway).

@ZhilkinSerg ZhilkinSerg added <Bugfix> This is a fix for a bug (or closes open issue) Crafting / Construction / Recipes Includes: Uncrafting / Disassembling Info / User Interface Game - player communication, menus, etc. Items / Item Actions / Item Qualities Items and how they work and interact [C++] Changes (can be) made in C++. Previously named `Code` labels Feb 3, 2020
Some failed test cases in `tests/iteminfo_test.cpp` made me realize my
previous commit should have kept the `DESCRIPTION_APPLICABLE_RECIPES`
check, since that is a flag indicating whether the section is applicable
to that kind of item, and should be shown at all.

Doing that check first made it clear that the preceding block,
initializing `tid` and `known_recipes`, could move inside the `if` and
avoid being needlessly calculated in some cases.

Due to indentation, this looks like a larger diff than it really is, but
it's all the same logic as before - if no recipes are known, the section
will display "You don't know anything you could craft with it."

Verified that all tests in `make check` are passing now, and confirmed
in-game that messages are shown as expected.
@wapcaplet
Copy link
Contributor Author

wapcaplet commented Feb 4, 2020

A misunderstanding on my part regarding the DESCRIPTION_APPLICABLE_RECIPES flag caused the unit test failure. I have fixed it, and done a little refactoring as well. Full details in the commit message: f45a1e7

I'm satisfied with how this works, but realize it's a far-reaching change, affecting probably a majority of item descriptions, and ultimately adds very little useful information. Now that I've done it, I am not so sure that it should be accepted and merged. It's kind of a waste of text.

So I'm submitting it for consideration and discussion, suggestions of alternatives, criticism, outright ridicule etc.

Pros:

  • Tells player the reason there are no crafts available (lack of knowledge)
  • Suggests itself as a placeholder, a kind of implicit "This is where you would see craftables if you knew any"

Cons:

  • Emphasizes an existing discrepancy in recipe display between item info (which only includes memorized recipes) and crafting menu (which may also include non-memorized recipes from nearby books) - that is the concern described in issue "You could use it to craft" list is empty when it shouldn't #37643
  • Redundant and tedious - many (if not most) items will always show this message, forever

@codemime
Copy link
Contributor

codemime commented Feb 4, 2020

So I'm submitting it for consideration and discussion, suggestions of alternatives, criticism, outright ridicule etc.

Please see the corresponding issue #37643 (comment). In short, I think the description should match the information available through the crafting menu.

In discussion with @codemime, determined that
`player::get_available_recipes` is suitable for use here in place of
`get_learned_recipes`, but my C++fu is weak and I've somehow caused a
game crash that doesn't even include this file in the backtrace.

Committing to ask for help on what I'm doing wrong.
@wapcaplet
Copy link
Contributor Author

@codemime In commit 3228bad I tried to use get_available_recipes as we discussed, passing crafting_inv = g->u.crafting_inventory() but I must have done something horribly wrong because now every time I try to use the main crafting menu (which needs item descriptions) or inspect an item that has one or more possible recipes, the game simply crashes with a segmentation fault. The relevant part of the crash log (before getting into low-level string stuff) is all about item info:

    /usr/include/c++/7/bits/hashtable.h:1439
    Item_factory::find_template(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const
    …/src/item_factory.cpp:1216
    item::item(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, time_point, item::default_charges_tag)
    ??:?
    recipe::create_result() const
    …/src/recipe.cpp:403
    recipe::get_component_filter(recipe_filter_flags) const
    …/src/recipe.cpp:562
    item::final_info(std::vector<iteminfo, std::allocator<iteminfo> >&, iteminfo_query const*, int, bool) const
    ??:?
    item::info[abi:cxx11](std::vector<iteminfo, std::allocator<iteminfo> >&, iteminfo_query const*, int) const

I can post the full log if it'll help, but I'm betting you could look at my code and immediately know what the problem is. It's been something like 20 years since I did any C++ so my syntax may be awkward...

Also, let's just take a moment to appreciate that commit id: 3228bad.

src/item.cpp Outdated Show resolved Hide resolved
Avoid ending up with a null pointer refererence from `of_component`.
Shorten the "no recipes" message slightly to make it fit without
wrapping more often.
@codemime
Copy link
Contributor

codemime commented Feb 7, 2020

Also, let's just take a moment to appreciate that commit id: 3228bad.

Yeah, I suspect that's Linus making fun of our code )). This just gave me an idea. It would be cool to make a generator of commits with funny ids. Some say, SHA-1 was cracked, so there can be something better than the brute-force approach for this.

@wapcaplet wapcaplet changed the title WIP Add item description when lacking crafting knowledge Make item crafting options include recipes from nearby books Feb 7, 2020
@wapcaplet
Copy link
Contributor Author

I've adjusted the PR summary and description to reflect the new nature of this fix, and added screenshots confirming the consistent behavior I am seeing now between the two UIs.

src/item.cpp Outdated Show resolved Hide resolved
@codemime codemime self-assigned this Feb 8, 2020
@wapcaplet wapcaplet changed the title Make item crafting options include recipes from nearby books WIP Make item crafting options include recipes from nearby books Feb 8, 2020
@wapcaplet
Copy link
Contributor Author

Whoops, hold on - that test case isn't working yet. Back in WIP

Test coverage for modified item info behavior
@wapcaplet
Copy link
Contributor Author

The test cases are in much better shape now, but I'm still getting semi-random failures in a couple of them; for examine sometimes the crowbar will show up with a bunch of higher-level recipes (foldable-light frame, wheelchair wheels, pipe bomb, nail rifle etc.) instead of the expected level-0 "makeshift crowbar" only.

Seems like something is bleeding over from other tests; probably I need to clean up / reset the global user g->u - I'm already using empty_skills() and empty_traits() but maybe it takes more than that...

Reduced to essential assertions; all passing now
@wapcaplet wapcaplet changed the title WIP Make item crafting options include recipes from nearby books Make item crafting options include recipes from nearby books Feb 9, 2020
@wapcaplet
Copy link
Contributor Author

All tests are passing now. Assuming this passes build checks, it should be ready to merge.

Caught by Travis CI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Crafting / Construction / Recipes Includes: Uncrafting / Disassembling Info / User Interface Game - player communication, menus, etc. Items / Item Actions / Item Qualities Items and how they work and interact
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"You could use it to craft" list is empty when it shouldn't
3 participants