Skip to content

Commit

Permalink
Ported items flags optimization from DDA (cataclysmbnteam#3354)
Browse files Browse the repository at this point in the history
* Ported items flags optimization from DDA

Co-authored-by: Aivean <[email protected]>

* Fixed tests

* Tidy flags list

* Removed remaining traces of MUSHY

* Ported flags housekeeping

Co-authored-by: Aivean <[email protected]>

* fix "item description flags" test on Windows

---------

Co-authored-by: Aivean <[email protected]>
  • Loading branch information
Vollch and Aivean authored Oct 5, 2023
1 parent 6bdb3f2 commit fc9f59f
Show file tree
Hide file tree
Showing 117 changed files with 2,001 additions and 1,222 deletions.
48 changes: 36 additions & 12 deletions data/json/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -884,12 +884,6 @@
"context": [ "ARMOR", "TOOL_ARMOR" ],
"info": "This clothing has a wool lining sewn into it to <good>increase</good> its overall <info>warmth</info>."
},
{
"id": "USES_GRID_POWER",
"type": "json_flag",
"context": [ "TOOL" ],
"info": "This item is uses power from an <info>electric grid</info>."
},
{
"id": "USES_GRID_POWER",
"type": "json_flag",
Expand Down Expand Up @@ -1072,6 +1066,21 @@
"context": [ ],
"type": "json_flag"
},
{
"id": "EFFECT_CLAIRVOYANCE",
"context": [ ],
"type": "json_flag"
},
{
"id": "EFFECT_CLAIRVOYANCE_PLUS",
"context": [ ],
"type": "json_flag"
},
{
"id": "EFFECT_SUPER_CLAIRVOYANCE",
"context": [ ],
"type": "json_flag"
},
{
"id": "EFFECT_ACID_IMMUNE",
"context": [ ],
Expand Down Expand Up @@ -1334,7 +1343,12 @@
"context": [ ]
},
{
"id": "ETHEREAL_ITEM",
"id": "EXPLOSION_SMASHED",
"type": "json_flag",
"context": [ ]
},
{
"id": "EXPLOSION_PROPELLED",
"type": "json_flag",
"context": [ ]
},
Expand Down Expand Up @@ -1463,6 +1477,11 @@
"type": "json_flag",
"context": [ ]
},
{
"id": "IN_CBM",
"type": "json_flag",
"context": [ ]
},
{
"id": "IR_EFFECT",
"type": "json_flag",
Expand All @@ -1473,6 +1492,11 @@
"type": "json_flag",
"context": [ ]
},
{
"id": "IS_EXPLOSION_PROPELLED",
"type": "json_flag",
"context": [ ]
},
{
"id": "IS_PET_ARMOR",
"type": "json_flag",
Expand Down Expand Up @@ -1719,6 +1743,11 @@
"type": "json_flag",
"context": [ ]
},
{
"id": "REACH",
"type": "json_flag",
"context": [ ]
},
{
"id": "REACH_ATTACK",
"type": "json_flag",
Expand Down Expand Up @@ -2041,11 +2070,6 @@
"type": "json_flag",
"context": [ ]
},
{
"id": "STR_DRAW",
"type": "json_flag",
"context": [ ]
},
{
"id": "UNBREAKABLE_MELEE",
"type": "json_flag",
Expand Down
3 changes: 0 additions & 3 deletions doc/src/content/docs/en/mod/json/reference/json_flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,6 @@ to find which flags work elsewhere.
flags: BIRD, CATTLE.
- `FERTILIZER` Works as fertilizer for farming, of if this consumed with the PLANTBLECH function
penalties will be reversed for plants.
- `FREEZERBURN` First thaw is MUSHY, second is rotten
- `FUNGAL_VECTOR` Will give a fungal infection when consumed.
- `HIDDEN_HALLU` ... Food causes hallucinations, visible only with a certain survival skill level.
- `HIDDEN_POISON` ... Food displays as poisonous with a certain survival skill level. Note that this
Expand Down Expand Up @@ -1479,8 +1478,6 @@ Those flags are added by the game code to specific items (that specific welder,
- `HIDDEN_ITEM` This item cannot be seen in AIM.
- `HOT` Item is hot (see EATEN_HOT).
- `LITCIG` Marks a lit smoking item (cigarette, joint etc.).
- `MUSHY` FREEZERBURN item was frozen and is now mushy and tasteless and will go bad after freezing
again.
- `NO_PARASITES` Invalidates parasites count set in food->type->comestible->parasites
- `QUARTERED` Corpse was quartered into parts. Affects butcher results, weight, volume.
- `REVIVE_SPECIAL` ... Corpses revives when the player is nearby.
Expand Down
3 changes: 1 addition & 2 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "creature.h"
#include "cursesdef.h"
#include "debug.h"
#include "flag.h"
#include "game.h"
#include "iexamine.h"
#include "input.h"
Expand Down Expand Up @@ -44,10 +45,8 @@ static const quality_id qual_BUTCHER( "BUTCHER" );
static const quality_id qual_CUT_FINE( "CUT_FINE" );

static const std::string flag_CONSOLE( "CONSOLE" );
static const std::string flag_FLOTATION( "FLOTATION" );
static const std::string flag_GOES_DOWN( "GOES_DOWN" );
static const std::string flag_GOES_UP( "GOES_UP" );
static const std::string flag_REACH_ATTACK( "REACH_ATTACK" );
static const std::string flag_SEALED( "SEALED" );
static const std::string flag_SWIMMABLE( "SWIMMABLE" );

Expand Down
4 changes: 1 addition & 3 deletions src/active_tile_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "coordinate_conversions.h"
#include "debug.h"
#include "distribution_grid.h"
#include "flag.h"
#include "item.h"
#include "itype.h"
#include "json.h"
Expand All @@ -20,9 +21,6 @@

static const itype_id itype_battery( "battery" );

static const std::string flag_RECHARGE( "RECHARGE" );
static const std::string flag_USE_UPS( "USE_UPS" );

namespace active_tiles
{

Expand Down
5 changes: 2 additions & 3 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "enums.h"
#include "event.h"
#include "event_bus.h"
#include "flag.h"
#include "game.h"
#include "gates.h"
#include "iexamine.h"
Expand Down Expand Up @@ -62,8 +63,6 @@ static const mtype_id mon_zombie_rot( "mon_zombie_rot" );
static const mtype_id mon_skeleton( "mon_skeleton" );
static const mtype_id mon_zombie_crawler( "mon_zombie_crawler" );

static const std::string flag_RELOAD_AND_SHOOT( "RELOAD_AND_SHOOT" );

static const std::string has_thievery_witness( "has_thievery_witness" );

aim_activity_actor::aim_activity_actor()
Expand Down Expand Up @@ -441,7 +440,7 @@ void dig_activity_actor::finish( player_activity &act, Character &who )
g->m.place_items( item_group_id( "jewelry_front" ), 20, location, location, false, calendar::turn );
for( item * const &it : dropped ) {
if( it->is_armor() ) {
it->item_tags.insert( "FILTHY" );
it->set_flag( flag_FILTHY );
it->set_damage( rng( 1, it->max_damage() - 1 ) );
}
}
Expand Down
45 changes: 14 additions & 31 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "fault.h"
#include "field_type.h"
#include "fstream_utils.h"
#include "flag.h"
#include "flat_set.h"
#include "game.h"
#include "game_constants.h"
Expand Down Expand Up @@ -260,31 +261,13 @@ static const trait_id trait_NOPAIN( "NOPAIN" );
static const trait_id trait_SPIRITUAL( "SPIRITUAL" );
static const trait_id trait_STOCKY_TROGLO( "STOCKY_TROGLO" );

// not to confuse with item flags (json_flag)
static const std::string flag_AUTODOC( "AUTODOC" );
static const std::string flag_AUTODOC_COUCH( "AUTODOC_COUCH" );
static const std::string flag_BUTCHER_EQ( "BUTCHER_EQ" );
static const std::string flag_FIELD_DRESS( "FIELD_DRESS" );
static const std::string flag_FIELD_DRESS_FAILED( "FIELD_DRESS_FAILED" );
static const std::string flag_FISH_GOOD( "FISH_GOOD" );
static const std::string flag_FISH_POOR( "FISH_POOR" );
static const std::string flag_FORAGE_HALLU( "FORAGE_HALLU" );
static const std::string flag_FORAGE_POISON( "FORAGE_POISON" );
static const std::string flag_GIBBED( "GIBBED" );
static const std::string flag_HIDDEN_HALLU( "HIDDEN_HALLU" );
static const std::string flag_HIDDEN_ITEM( "HIDDEN_ITEM" );
static const std::string flag_HIDDEN_POISON( "HIDDEN_POISON" );
static const std::string flag_MESSY( "MESSY" );
static const std::string flag_PLANTABLE( "PLANTABLE" );
static const std::string flag_PULPED( "PULPED" );
static const std::string flag_QUARTERED( "QUARTERED" );
static const std::string flag_RELOAD_ONE( "RELOAD_ONE" );
static const std::string flag_REQUIRES_TINDER( "REQUIRES_TINDER" );
static const std::string flag_SAFECRACK( "SAFECRACK" );
static const std::string flag_SKINNED( "SKINNED" );
static const std::string flag_SPEEDLOADER( "SPEEDLOADER" );
static const std::string flag_SUPPORTS_ROOF( "SUPPORTS_ROOF" );
static const std::string flag_TREE( "TREE" );
static const std::string flag_USE_UPS( "USE_UPS" );

using namespace activity_handlers;

Expand Down Expand Up @@ -488,7 +471,7 @@ static void extract_or_wreck_cbms( const std::list<item> &cbms, int roll,
// This complicates things
if( it.is_bionic() ) {
if( check_butcher_cbm( roll ) || it.typeId() == itype_burnt_out_bionic ) {
if( it.has_flag( "BIONIC_FAULTY" ) ) {
if( it.has_flag( flag_BIONIC_FAULTY ) ) {
it.convert( itype_burnt_out_bionic );
// We don't need the non-sterile fault on a piece of burnt-out bionic
if( it.has_fault( fault_bionic_nonsterile ) ) {
Expand Down Expand Up @@ -621,7 +604,7 @@ butchery_setup consider_butchery( const item &corpse_item, player &u, butcher_ty
}
if( !b_rack_present ) {
b_rack_present = inv.has_item_with( []( const item & it ) {
return it.has_flag( "BUTCHER_RACK" );
return it.has_flag( flag_BUTCHER_RACK );
} );
}
// workshop butchery (full) prequisites
Expand All @@ -645,7 +628,7 @@ butchery_setup consider_butchery( const item &corpse_item, player &u, butcher_ty
butcherable_rating::no_tree_rope_rack );
}
if( !( here.has_nearby_table( u.pos(), PICKUP_RANGE ) || inv.has_item_with( []( const item & it ) {
return it.has_flag( "FLAT_SURFACE" );
return it.has_flag( flag_FLAT_SURFACE );
} ) ) ) {
not_this_one(
_( "To perform a full butchery on a corpse this big, you need a table nearby or something else with a flat surface. A leather tarp spread out on the ground could suffice." ),
Expand Down Expand Up @@ -1075,7 +1058,7 @@ static void butchery_drops_harvest( item *corpse_item, const mtype &mt, player &
if( obj.goes_bad() ) {
obj.set_rot( corpse_item->get_rot() );
}
for( const std::string &flg : entry.flags ) {
for( const flag_id &flg : entry.flags ) {
obj.set_flag( flg );
}
for( const fault_id &flt : entry.faults ) {
Expand All @@ -1092,7 +1075,7 @@ static void butchery_drops_harvest( item *corpse_item, const mtype &mt, player &
if( obj.goes_bad() ) {
obj.set_rot( corpse_item->get_rot() );
}
for( const std::string &flg : entry.flags ) {
for( const flag_id &flg : entry.flags ) {
obj.set_flag( flg );
}
for( const fault_id &flt : entry.faults ) {
Expand All @@ -1108,7 +1091,7 @@ static void butchery_drops_harvest( item *corpse_item, const mtype &mt, player &
if( obj.goes_bad() ) {
obj.set_rot( corpse_item->get_rot() );
}
for( const std::string &flg : entry.flags ) {
for( const flag_id &flg : entry.flags ) {
obj.set_flag( flg );
}
for( const fault_id &flt : entry.faults ) {
Expand Down Expand Up @@ -1336,7 +1319,7 @@ void activity_handlers::butcher_finish( player_activity *act, player *p )
_( "You did something wrong and hacked the corpse badly. Maybe it's still recoverable." ) );
break;
}
corpse_item.set_flag( "FIELD_DRESS_FAILED" );
corpse_item.set_flag( flag_FIELD_DRESS_FAILED );

here.add_splatter( type_gib, p->pos(), rng( corpse->size + 2, ( corpse->size + 1 ) * 2 ) );
here.add_splatter( type_blood, p->pos(), rng( corpse->size + 2, ( corpse->size + 1 ) * 2 ) );
Expand Down Expand Up @@ -2125,7 +2108,7 @@ void activity_handlers::reload_finish( player_activity *act, player *p )
std::string msg = _( "You reload the %s." );

if( ammo_is_filthy ) {
reloadable.set_flag( "FILTHY" );
reloadable.set_flag( flag_FILTHY );
}

if( reloadable.get_var( "dirt", 0 ) > 7800 ) {
Expand Down Expand Up @@ -2710,7 +2693,7 @@ item get_fake_tool( hack_type_t hack_type, const player_activity &activity )

for( const itype &item_type : item_type_list ) {
if( item_type.get_id() == static_cast<itype_id>( activity.str_values[1] ) ) {
if( !item_type.has_flag( "USES_GRID_POWER" ) ) {
if( !item_type.has_flag( flag_USES_GRID_POWER ) ) {
debugmsg( "Non grid powered furniture for long repairs is not supported yet." );
return fake_item;
}
Expand All @@ -2725,7 +2708,7 @@ item get_fake_tool( hack_type_t hack_type, const player_activity &activity )
}
}

fake_item.set_flag( "PSEUDO" );
fake_item.set_flag( flag_PSEUDO );
return fake_item;
}

Expand Down Expand Up @@ -3131,7 +3114,7 @@ void activity_handlers::toolmod_add_finish( player_activity *act, player *p )
item &mod = *act->targets[1];
p->add_msg_if_player( m_good, _( "You successfully attached the %1$s to your %2$s." ),
mod.tname(), tool.tname() );
mod.set_flag( "IRREMOVABLE" );
mod.set_flag( flag_IRREMOVABLE );
tool.put_in( mod );
act->targets[1].remove_item();
}
Expand Down Expand Up @@ -4877,7 +4860,7 @@ void activity_handlers::spellcasting_finish( player_activity *act, player *p )
}
if( !act->targets.empty() && act->targets.front() ) {
item &it = *act->targets.front();
if( !it.has_flag( "USE_PLAYER_ENERGY" ) ) {
if( !it.has_flag( flag_USE_PLAYER_ENERGY ) ) {
p->consume_charges( it, it.type->charges_to_use() );
}
}
Expand Down
17 changes: 7 additions & 10 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "field.h"
#include "field_type.h"
#include "fire.h"
#include "flag.h"
#include "flat_set.h"
#include "game.h"
#include "game_constants.h"
Expand Down Expand Up @@ -138,16 +139,12 @@ static const quality_id qual_SAW_W( "SAW_W" );
static const quality_id qual_WELD( "WELD" );

static const std::string flag_BUTCHER_EQ( "BUTCHER_EQ" );
static const std::string flag_DIG_TOOL( "DIG_TOOL" );
static const std::string flag_FISHABLE( "FISHABLE" );
static const std::string flag_FISH_GOOD( "FISH_GOOD" );
static const std::string flag_FISH_POOR( "FISH_POOR" );
static const std::string flag_GROWTH_HARVEST( "GROWTH_HARVEST" );
static const std::string flag_PLANT( "PLANT" );
static const std::string flag_PLANTABLE( "PLANTABLE" );
static const std::string flag_PLOWABLE( "PLOWABLE" );
static const std::string flag_TREE( "TREE" );
static const std::string flag_UNSAFE_CONSUME( "UNSAFE_CONSUME" );

void cancel_aim_processing();
//Generic activity: maximum search distance for zones, constructions, etc.
Expand Down Expand Up @@ -776,12 +773,12 @@ void wash_activity_actor::finish( player_activity &act, Character &who )
if( i.count > it.count() ) {
debugmsg( "Invalid item count to wash: tried %d, max %d", i.count, it.count() );
}
it.item_tags.erase( "FILTHY" );
it.item_tags.erase( flag_FILTHY );
} else {
item it2 = it;
it.charges -= i.count;
it2.charges = i.count;
it2.item_tags.erase( "FILTHY" );
it2.item_tags.erase( flag_FILTHY );
std::list<item> tmp;
tmp.push_back( it2 );
put_into_vehicle_or_drop( who, item_drop_reason::deliberate, tmp );
Expand Down Expand Up @@ -1264,11 +1261,11 @@ static bool are_requirements_nearby( const std::vector<tripoint> &loot_spots,
if( weldpart ) {
item welder( itype_welder, calendar::start_of_cataclysm );
welder.charges = veh.fuel_left( itype_battery, true );
welder.set_flag( "PSEUDO" );
welder.set_flag( flag_PSEUDO );
temp_inv.add_item( welder );
item soldering_iron( itype_soldering_iron, calendar::start_of_cataclysm );
soldering_iron.charges = veh.fuel_left( itype_battery, true );
soldering_iron.set_flag( "PSEUDO" );
soldering_iron.set_flag( flag_PSEUDO );
temp_inv.add_item( soldering_iron );
}
}
Expand Down Expand Up @@ -1472,7 +1469,7 @@ static activity_reason_info can_do_activity_there( const activity_id &act, playe
for( const tripoint &pt : here.points_in_radius( src_loc, 2 ) ) {
const inventory &inv = p.crafting_inventory();
if( here.has_flag_furn( flag_BUTCHER_EQ, pt ) || inv.has_item_with( []( const item & it ) {
return it.has_flag( "BUTCHER_RACK" );
return it.has_flag( flag_BUTCHER_RACK );
} ) ) {
b_rack_present = true;
}
Expand All @@ -1482,7 +1479,7 @@ static activity_reason_info can_do_activity_there( const activity_id &act, playe
const inventory &inv = p.crafting_inventory();
if( !b_rack_present || !( here.has_nearby_table( src_loc, PICKUP_RANGE ) ||
inv.has_item_with( []( const item & it ) {
return it.has_flag( "FLAT_SURFACE" );
return it.has_flag( flag_FLAT_SURFACE );
} ) ) ) {
return activity_reason_info::fail( do_activity_reason::NO_ZONE );
}
Expand Down
Loading

0 comments on commit fc9f59f

Please sign in to comment.