Skip to content

Commit

Permalink
New JSON recipe property for overriding inheritance of specified flags (
Browse files Browse the repository at this point in the history
#35825)

* Add JSON field to delete flags in recipes
My initial incarnation of flag inheritance included an item flag that
completely disabled flag inheritance when that item was crafted.
In retrospect, that was a poor solution. It is too heavy-handed in
practice. For instance, it doesn't allow recipes to inherit one flag as
normal, while removing another. This solution should be more practical.

* Remove obsolete NO_CRAFT_INHERIT flag
The new "delete_flags" property of recipes does everything it used to do
and more.
Also replaced all uses of NO_CRAFT_INHERIT with delete_flags property.

* Change flags_to_delete from vector to set
As suggested by BevapDin.
  • Loading branch information
Davi-DeGanne authored and ZhilkinSerg committed Dec 4, 2019
1 parent 1d0a485 commit 9f74eae
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 19 deletions.
5 changes: 0 additions & 5 deletions data/json/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -701,11 +701,6 @@
"id": "ELECTRIC_IMMUNE",
"type": "json_flag"
},
{
"id": "NO_CRAFT_INHERIT",
"type": "json_flag",
"//": "Crafted items with this flag won't inherit flags with craft_inherit from their components."
},
{
"id": "HIDDEN_HALLU",
"type": "json_flag",
Expand Down
5 changes: 2 additions & 3 deletions data/json/items/comestibles/carnivore.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
"calories": 25,
"fun": 0,
"healthy": 0,
"flags": [ "NUTRIENT_OVERRIDE", "NO_CRAFT_INHERIT" ]
"flags": [ "NUTRIENT_OVERRIDE" ]
},
{
"id": "offal",
Expand Down Expand Up @@ -355,8 +355,7 @@
"quench": -5,
"fun": 4,
"calories": 348,
"vitamins": [ [ "vitA", 0 ], [ "vitC", 0 ], [ "calcium", 2 ], [ "iron", 26 ], [ "vitB", 35 ] ],
"flags": "NO_CRAFT_INHERIT"
"vitamins": [ [ "vitA", 0 ], [ "vitC", 0 ], [ "calcium", 2 ], [ "iron", 26 ], [ "vitB", 35 ] ]
},
{
"id": "salted_fish",
Expand Down
2 changes: 1 addition & 1 deletion data/json/items/comestibles/meat_dishes.json
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@
"material": "flesh",
"primary_material": "cured_meat",
"volume": "125 ml",
"flags": [ "EDIBLE_FROZEN", "NO_CRAFT_INHERIT" ]
"flags": [ "EDIBLE_FROZEN" ]
},
{
"type": "COMESTIBLE",
Expand Down
2 changes: 1 addition & 1 deletion data/json/items/comestibles/other.json
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@
"name_plural": "Kentucky coffee grounds",
"container": "bag_plastic",
"description": "Coffee grounds created through washing, cleaning, and roasting the pods from a Kentucky coffeetree. They can be used to create coffee.",
"flags": [ "EDIBLE_FROZEN", "NUTRIENT_OVERRIDE", "NO_CRAFT_INHERIT" ],
"flags": [ "EDIBLE_FROZEN", "NUTRIENT_OVERRIDE" ],
"charges": 5,
"stack_size": 20
},
Expand Down
1 change: 1 addition & 0 deletions data/json/recipes/food/dry.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"result": "dry_meat",
"category": "CC_FOOD",
"subcategory": "CSC_FOOD_DRY",
"delete_flags": [ "BAD_TASTE" ],
"skill_used": "cooking",
"difficulty": 2,
"time": "18 m",
Expand Down
3 changes: 3 additions & 0 deletions data/json/recipes/recipe_food.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"type": "recipe",
"result": "mutant_meat_scrap_cooked",
"copy-from": "mutant_meat_cooked",
"delete_flags": [ "BAD_TASTE" ],
"time": "45 s",
"qualities": [ { "id": "COOK", "level": 1 } ],
"tools": [ [ [ "surface_heat", 1, "LIST" ] ] ],
Expand Down Expand Up @@ -1694,6 +1695,7 @@
"result": "coffee_raw_kentucky",
"category": "CC_FOOD",
"subcategory": "CSC_FOOD_OTHER",
"delete_flags": [ "HIDDEN_POISON" ],
"skill_used": "cooking",
"difficulty": 1,
"time": "2 h",
Expand Down Expand Up @@ -2129,6 +2131,7 @@
"result": "jerky",
"category": "CC_FOOD",
"subcategory": "CSC_FOOD_MEAT",
"delete_flags": [ "BAD_TASTE" ],
"skill_used": "cooking",
"difficulty": 3,
"time": "1 h",
Expand Down
1 change: 1 addition & 0 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ Mods can modify this via `add:traits` and `remove:traits`.
"category": "CC_WEAPON", // Category of crafting recipe. CC_NONCRAFT used for disassembly recipes
"id_suffix": "", // Optional (default: empty string). Some suffix to make the ident of the recipe unique. The ident of the recipe is "<id-of-result><id_suffix>".
"override": false, // Optional (default: false). If false and the ident of the recipe is already used by another recipe, loading of recipes fails. If true and a recipe with the ident is already defined, the existing recipe is replaced by the new recipe.
"delete_flags": [ "CANNIBALISM" ], // Optional (default: empty list). Flags specified here will be removed from the resultant item upon crafting. This will override flag inheritance, but *will not* delete flags that are part of the item type itself.
"skill_used": "fabrication", // Skill trained and used for success checks
"skills_required": [["survival", 1], ["throw", 2]], // Skills required to unlock recipe
"book_learn": [ // (optional) Array of books that this recipe can be learned from. Each entry contains the id of the book and the skill level at which it can be learned.
Expand Down
20 changes: 11 additions & 9 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,16 +1051,14 @@ void item::inherit_flags( const item &parent )
if( parent.has_flag( "FIT" ) ) {
item_tags.insert( "FIT" );
}
if( !has_flag( "NO_CRAFT_INHERIT" ) ) {
for( const std::string &f : parent.item_tags ) {
if( json_flag::get( f ).craft_inherit() ) {
set_flag( f );
}
for( const std::string &f : parent.item_tags ) {
if( json_flag::get( f ).craft_inherit() ) {
set_flag( f );
}
for( const std::string &f : parent.type->item_tags ) {
if( json_flag::get( f ).craft_inherit() ) {
set_flag( f );
}
}
for( const std::string &f : parent.type->item_tags ) {
if( json_flag::get( f ).craft_inherit() ) {
set_flag( f );
}
}
if( parent.has_flag( "HIDDEN_POISON" ) ) {
Expand Down Expand Up @@ -1136,6 +1134,10 @@ void player::complete_craft( item &craft, const tripoint &loc )
}
food_contained.inherit_flags( used );

for( const std::string &flag : making.flags_to_delete ) {
food_contained.unset_flag( flag );
}

// Don't store components for things made by charges,
// Don't store components for things that can't be uncrafted.
if( recipe_dictionary::get_uncraft( making.result() ) && !food_contained.count_by_charges() &&
Expand Down
4 changes: 4 additions & 0 deletions src/recipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ void recipe::load( JsonObject &jo, const std::string &src )
}
}

if( jo.has_member( "delete_flags" ) ) {
flags_to_delete = jo.get_tags( "delete_flags" );
}

// recipes not specifying any external requirements inherit from their parent recipe (if any)
if( jo.has_string( "using" ) ) {
reqs_external = { { requirement_id( jo.get_string( "using" ) ), 1 } };
Expand Down
1 change: 1 addition & 0 deletions src/recipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class recipe
std::map<skill_id, int> autolearn_requirements; // Skill levels required to autolearn
std::map<skill_id, int> learn_by_disassembly; // Skill levels required to learn by disassembly
std::map<itype_id, int> booksets; // Books containing this recipe, and the skill level required
std::set<std::string> flags_to_delete; // Flags to delete from the resultant item.

// Create a string list to describe the skill requirements for this recipe
// Format: skill_name(level/amount), skill_name(level/amount)
Expand Down

0 comments on commit 9f74eae

Please sign in to comment.