Skip to content

Commit

Permalink
JSONize inheritance of flags via crafting (#34825)
Browse files Browse the repository at this point in the history
* JSONize inheritance of flags via crafting

* Remove hardcoded inheritance for in-progress craft
I considered replacing it with a block that used the new JSONized
inheritance, but realized it doesn't seem to actually do anything,
so I got rid of it instead.

* Add JSONized inheritance to in-progress crafts
On second thought, given that I'm unsure, better to leave in code that
doesn't do anything than remove code that does do something.

* Add documentation to JSON_FLAGS.md
  • Loading branch information
Davi-DeGanne authored and ZhilkinSerg committed Oct 20, 2019
1 parent 3f83c82 commit e5f61fe
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 12 deletions.
20 changes: 20 additions & 0 deletions data/json/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
"type": "json_flag",
"context": [ "ARMOR", "TOOL_ARMOR" ],
"//": "Zombie-dropped clothing giving various penalties if Filthy mod is active. Also CBMs harvested from zombies.",
"craft_inherit": true,
"info": "This item is <bad>filthy</bad>."
},
{
Expand Down Expand Up @@ -693,5 +694,24 @@
{
"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",
"context": [ "COMESTIBLE" ],
"craft_inherit": true,
"//": "Contains hallucinogenic compounds from foraged foods."
},
{
"id": "HIDDEN_POISON",
"type": "json_flag",
"context": [ "COMESTIBLE" ],
"craft_inherit": true,
"//": "Contains poisonous compounds from foraged foods."
}
]
6 changes: 6 additions & 0 deletions doc/JSON_FLAGS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# JSON Flags

* [Notes](#notes)
* [Inheritance](#inheritance)
* [TODO](#todo)
* [Ammo](#ammo)
+ [Ammo type](#ammo-type)
Expand Down Expand Up @@ -74,6 +75,11 @@
- Offensive and defensive flags can be used on any item type that can be wielded.


## Inheritance

When an item is crafted, it can inherit flags from the components that were used to craft it. This requires that the flag to be inherited has the `"craft_inherit": true` entry. If you don't want a particular item to inherit flags when crafted, you can add the flag `NO_CRAFT_INHERIT` to that item.


## TODO

- Descriptions for `Special attacks` under `Monsters` could stand to be more descriptive of exactly what the attack does.
Expand Down
15 changes: 12 additions & 3 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "calendar.h"
#include "craft_command.h"
#include "debug.h"
#include "flag.h"
#include "game.h"
#include "game_inventory.h"
#include "handle_liquid.h"
Expand Down Expand Up @@ -1113,11 +1114,19 @@ void player::complete_craft( item &craft, const tripoint &loc )
if( component.has_flag( "FIT" ) ) {
newit.item_tags.insert( "FIT" );
}
if( component.has_flag( "HIDDEN_HALLU" ) ) {
newit.item_tags.insert( "HIDDEN_HALLU" );
if( !newit.has_flag( "NO_CRAFT_INHERIT" ) ) {
for( const std::string &f : component.item_tags ) {
if( json_flag::get( f ).craft_inherit() ) {
newit.set_flag( f );
}
}
for( const std::string &f : component.type->item_tags ) {
if( json_flag::get( f ).craft_inherit() ) {
newit.set_flag( f );
}
}
}
if( component.has_flag( "HIDDEN_POISON" ) ) {
newit.item_tags.insert( "HIDDEN_POISON" );
newit.poison = component.poison;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/flag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void json_flag::load( JsonObject &jo )
jo.read( "info", f.info_ );
jo.read( "conflicts", f.conflicts_ );
jo.read( "inherit", f.inherit_ );
jo.read( "craft_inherit", f.craft_inherit_ );
}

void json_flag::check_consistency()
Expand Down
6 changes: 6 additions & 0 deletions src/flag.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class json_flag
return inherit_;
}

/** Is flag inherited by crafted items from any component items? */
bool craft_inherit() const {
return craft_inherit_;
}

/** Is this a valid (non-null) flag */
operator bool() const {
return !id_.empty();
Expand All @@ -40,6 +45,7 @@ class json_flag
std::string info_;
std::set<std::string> conflicts_;
bool inherit_ = true;
bool craft_inherit_ = false;

json_flag( const std::string &id = std::string() ) : id_( id ) {}

Expand Down
18 changes: 9 additions & 9 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,18 +306,18 @@ item::item( const recipe *rec, int qty, std::list<item> items, std::vector<item_
}
}

for( const item &it : components ) {
if( it.has_flag( "HIDDEN_POISON" ) ) {
set_flag( "HIDDEN_POISON" );
}
if( it.has_flag( "HIDDEN_HALLU" ) ) {
set_flag( "HIDDEN_HALLU" );
for( item &component : components ) {
for( const std::string &f : component.item_tags ) {
if( json_flag::get( f ).craft_inherit() ) {
set_flag( f );
}
}
if( it.is_filthy() ) {
set_flag( "FILTHY" );
for( const std::string &f : component.type->item_tags ) {
if( json_flag::get( f ).craft_inherit() ) {
set_flag( f );
}
}
}

}

item item::make_corpse( const mtype_id &mt, time_point turn, const std::string &name )
Expand Down

0 comments on commit e5f61fe

Please sign in to comment.