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

Remove implicit instance flags from wished items #45558

Merged
merged 2 commits into from
Nov 23, 2020

Conversation

wapcaplet
Copy link
Contributor

@wapcaplet wapcaplet commented Nov 21, 2020

Summary

SUMMARY: Interface "Remove implicit instance flags from wished items"

Purpose of change

When using the debug "spawn item" menu to wish for an item, the item instance was being assigned all of the flags from the item type, such as EATEN_COLD or NO_REPAIR:

Cataclysm-DDA/src/wish.cpp

Lines 483 to 484 in f3a1933

// grab default flags for the itype
flags = debug_menu::iterable_to_string( selected_itype.get_flags(), " ",

This made debug-spawned items behave differently from their game-world-spawned counterparts, which normally do not have these flags stored in the item instance (item_tags).

This behavior was added in PR #44675 to support an enhancement to the "Add flags to spawned items" action (F), including the ability to add/edit multiple instance flags to an item before spawning it.

Describe the solution

This PR changes the wish_item_callback behavior so item type flags are not implicitly added to every spawned item's instance flags. Instead, debug-spawned items have no instance flags unless the user explicitly adds them with "Add flags to spawned items" action (F).

The first time using F on an item, you'll see the default list of item type flags, which you can edit or append. The spawned item will have all of the designated flags added to its item_tags (instance flags).

If you add flags to an item, then switch to another item in the menu before spawning it, the flags will be reset. This is consistent with the "contained" (f) behavior, and prevents instance flags from carrying over to another unrelated item that may not support them.

Describe alternatives you've considered

Nothing comes to mind

Testing

  • Toggle "Debug Mode" on using a custom keybinding, to see instance flags (tags) in the item description.
  • Use the debug "Spawn an item" menu, and see that "tags:" is empty by default for every item (no implicit instance flags)
  • Press F to add flags to an item instance - see item type flags by default
    • Press escape to cancel - item flags not changed ("tags:" still empty)
    • Press enter without editing - item instance gets all of the flags from the type by default, shown in "tags:" description
    • Edit flags and press enter - item gets all valid tags from the space-separated list, and "tags:" description shows them
  • Press enter to spawn one or more instance of the item
  • Check item description - see all the assigned flags
  • Spawn HOT, COLD, or FROZEN water or other liquids - spawned liquid has correct phase indicated
  • Spawn clean water, water, mead or other liquids without adding any flags - see no explicit instance flags assigned

Additional context

Found this issue while investigating #45471. This is not a fix for that issue, but will make it easier to test reliably.

When wishing for water, press F to edit or append flags to the item, just like before:

image

Here, the water type has EATEN_COLD and NO_REPAIR - which is where the "This item is not repairable" and "This tastes better while cold" information comes from. Pressing F here is allowing us to add those flags to the water instance, or edit/append to customize the water item that will be spawned.

Thus, adding HOT:

image

yields a bottle of hot water:

image

When using the debug "spawn item" menu to wish for an item, the item
instance was being assigned *all* of the flags from the item type, such
as `EATEN_COLD` or `NO_REPAIR`. This made debug-spawned items behave
differently from their game-world-spawned counterparts, which normally
do not have these flags stored in the item instance (`item_tags`).
This behavior was added in PR CleverRaven#44675 to support an enhancement to the
"Add flags to spawned items" action (`F`), including the ability to
add/edit multiple instance flags to an item before spawning it.

This commit changes the behavior so item type flags are not implicitly
added to every spawned item's instance flags. Instead, debug-spawned
items have no instance flags unless the user explicitly adds them with
"Add flags to spawned items" action (`F`).

The first time using `F` on an item, you'll see the default list of item
type flags, which you can edit or append. The spawned item will have all
of the designated flags added to its `item_tags` (instance flags).

If you add flags to an item, then switch to another item in the menu
before spawning it, the flags will be reset. This is consistent with the
"contained" (`f`) behavior, and prevents instance flags from carrying
over to another unrelated item that may not support them.
@anothersimulacrum anothersimulacrum added <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` labels Nov 21, 2020
@Pupsi-Mupsi
Copy link
Contributor

Would you mind adding SOFTWARE to be "contained" by default while you're at it?

@wapcaplet
Copy link
Contributor Author

wapcaplet commented Nov 21, 2020

Would you mind adding SOFTWARE to be "contained" by default while you're at it?

I don't see anything in the item type data that would identify something as "software", though I see the softwares do have the NO_DROP flag (meaning they "must be contained by another item"). I will check for this flag, and default those item types to be "contained" as well as liquids.

Edit This is more difficult than expected. Software items cannot presently be spawned on a USB drive at all, because the in_its_container function can only put items in CONTAINER pockets. This may be better addressed in a separate PR.

@ZhilkinSerg ZhilkinSerg self-assigned this Nov 23, 2020
src/wish.cpp Outdated Show resolved Hide resolved
@ZhilkinSerg ZhilkinSerg merged commit acb00ed into CleverRaven:master Nov 23, 2020
@ZhilkinSerg ZhilkinSerg removed their assignment Nov 24, 2020
@wapcaplet wapcaplet deleted the w-spawn-flagless branch March 1, 2021 23:07
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`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants