Skip to content

Commit

Permalink
Remove implicit instance flags from wished items (#45558)
Browse files Browse the repository at this point in the history
* Remove implicit instance flags from wished items

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 #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.
  • Loading branch information
wapcaplet authored Nov 23, 2020
1 parent 279c637 commit acb00ed
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/wish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ class wish_item_callback: public uilist_callback
bool spawn_everything;
std::string msg;
std::string flags;
std::string itype_flags;
const std::vector<const itype *> &standard_itype_ids;
wish_item_callback( const std::vector<const itype *> &ids ) :
incontainer( false ), spawn_everything( false ), standard_itype_ids( ids ) {
Expand All @@ -478,10 +479,12 @@ class wish_item_callback: public uilist_callback
return;
}
const itype &selected_itype = *standard_itype_ids[menu->selected];
// Make liquids "contained" by default (toggled with CONTAINER action)
incontainer = selected_itype.phase == phase_id::LIQUID;

// grab default flags for the itype
flags = debug_menu::iterable_to_string( selected_itype.get_flags(), " ",
// Clear instance flags when switching items
flags.clear();
// Grab default flags for the itype (added with the FLAG action)
itype_flags = debug_menu::iterable_to_string( selected_itype.get_flags(), " ",
[]( const flag_id & f ) {
return f.str();
} );
Expand All @@ -496,13 +499,22 @@ class wish_item_callback: public uilist_callback
return true;
}
if( action == "FLAG" ) {
std::string edit_flags;
if( flags.empty() ) {
// If this is the first time using the FLAG action on this item, start with itype flags
edit_flags = itype_flags;
} else {
// Otherwise, edit the existing list of user-defined instance flags
edit_flags = flags;
}
string_input_popup popup;
popup
.title( _( "Flags:" ) )
.description( _( "UPPERCASE, no quotes, separate with spaces" ) )
.max_length( 100 )
.text( flags )
.text( edit_flags )
.query();
// Save instance flags on this item (will be reset when selecting another item)
if( popup.confirmed() ) {
flags = popup.text();
return true;
Expand Down Expand Up @@ -872,4 +884,3 @@ void debug_menu::wishproficiency( player *p )
}
} while( prmenu.ret != UILIST_CANCEL );
}

0 comments on commit acb00ed

Please sign in to comment.