diff --git a/data/json/item_category.json b/data/json/item_category.json index 5b5a89b8bdd8c..4354b2c3efe9c 100644 --- a/data/json/item_category.json +++ b/data/json/item_category.json @@ -3,54 +3,63 @@ "id": "guns", "type": "ITEM_CATEGORY", "name": "GUNS", + "zone": "LOOT_GUNS", "sort_rank": -23 }, { "id": "magazines", "type": "ITEM_CATEGORY", "name": "MAGAZINES", + "zone": "LOOT_MAGAZINES", "sort_rank": -22 }, { "id": "ammo", "type": "ITEM_CATEGORY", "name": "AMMO", + "zone": "LOOT_AMMO", "sort_rank": -21 }, { "id": "weapons", "type": "ITEM_CATEGORY", "name": "WEAPONS", + "zone": "LOOT_WEAPONS", "sort_rank": -20 }, { "id": "tools", "type": "ITEM_CATEGORY", "name": "TOOLS", + "zone": "LOOT_TOOLS", "sort_rank": -19 }, { "id": "clothing", "type": "ITEM_CATEGORY", "name": "CLOTHING", + "//": "zone is hardcoded due to filthy clothing", "sort_rank": -18 }, { "id": "food", "type": "ITEM_CATEGORY", "name": "FOOD", + "//": "zone is hardcoded", "sort_rank": -17 }, { "id": "drugs", "type": "ITEM_CATEGORY", "name": "DRUGS", + "zone": "LOOT_DRUGS", "sort_rank": -16 }, { "id": "books", "type": "ITEM_CATEGORY", "name": "BOOKS", + "zone": "LOOT_BOOKS", "sort_rank": -15 }, { @@ -63,66 +72,77 @@ "id": "mods", "type": "ITEM_CATEGORY", "name": "MODS", + "zone": "LOOT_MODS", "sort_rank": -13 }, { "id": "mutagen", "type": "ITEM_CATEGORY", "name": "MUTAGENS", + "zone": "LOOT_MUTAGENS", "sort_rank": -12 }, { "id": "bionics", "type": "ITEM_CATEGORY", "name": "BIONICS", + "zone": "LOOT_BIONICS", "sort_rank": -12 }, { "id": "veh_parts", "type": "ITEM_CATEGORY", "name": "VEHICLE PARTS", + "zone": "LOOT_VEHICLE_PARTS", "sort_rank": -10 }, { "id": "other", "type": "ITEM_CATEGORY", "name": "OTHER", + "zone": "LOOT_OTHER", "sort_rank": -9 }, { "id": "fuel", "type": "ITEM_CATEGORY", "name": "FUEL", + "zone": "LOOT_FUEL", "sort_rank": -8 }, { "id": "seeds", "type": "ITEM_CATEGORY", "name": "SEEDS", + "zone": "LOOT_SEEDS", "sort_rank": -7 }, { "id": "chems", "type": "ITEM_CATEGORY", "name": "CHEMICAL STUFF", + "zone": "LOOT_CHEMICAL", "sort_rank": 5 }, { "id": "spare_parts", "type": "ITEM_CATEGORY", "name": "SPARE PARTS", + "zone": "LOOT_SPARE_PARTS", "sort_rank": 8 }, { "id": "artifacts", "type": "ITEM_CATEGORY", "name": "ARTIFACTS", + "zone": "LOOT_ARTIFACTS", "sort_rank": 10 }, { "id": "armor", "type": "ITEM_CATEGORY", "name": "ARMOR", + "//": "zone is hardcoded due to filthy clothing", "sort_rank": 20 }, { diff --git a/src/clzones.cpp b/src/clzones.cpp index 74e24a32df5a7..2bba218fe1f05 100644 --- a/src/clzones.cpp +++ b/src/clzones.cpp @@ -827,7 +827,8 @@ cata::optional zone_manager::get_nearest( const zone_type_id &type, co zone_type_id zone_manager::get_near_zone_type_for_item( const item &it, const tripoint &where, int range ) const { - auto cat = it.get_category(); + const item_category &cat = it.get_category(); + if( has_near( zone_type_id( "LOOT_CUSTOM" ), where, range ) ) { for( const auto elem : get_near( zone_type_id( "LOOT_CUSTOM" ), where, range, &it ) ) { ( void )elem; @@ -845,6 +846,10 @@ zone_type_id zone_manager::get_near_zone_type_for_item( const item &it, } } + if( cat.zone() ) { + return *cat.zone(); + } + if( cat.get_id() == "food" ) { const bool preserves = it.is_food_container() && it.type->container->preserves; const auto &it_food = it.is_food_container() ? it.contents.front() : it; @@ -865,63 +870,12 @@ zone_type_id zone_manager::get_near_zone_type_for_item( const item &it, return zone_type_id( "LOOT_FOOD" ); } - if( cat.get_id() == "guns" ) { - return zone_type_id( "LOOT_GUNS" ); - } - if( cat.get_id() == "magazines" ) { - return zone_type_id( "LOOT_MAGAZINES" ); - } - if( cat.get_id() == "ammo" ) { - return zone_type_id( "LOOT_AMMO" ); - } - if( cat.get_id() == "weapons" ) { - return zone_type_id( "LOOT_WEAPONS" ); - } - if( cat.get_id() == "tools" ) { - return zone_type_id( "LOOT_TOOLS" ); - } if( cat.get_id() == "clothing" ) { if( it.is_filthy() && has_near( zone_type_id( "LOOT_FCLOTHING" ), where, range ) ) { return zone_type_id( "LOOT_FCLOTHING" ); } return zone_type_id( "LOOT_CLOTHING" ); } - if( cat.get_id() == "drugs" ) { - return zone_type_id( "LOOT_DRUGS" ); - } - if( cat.get_id() == "books" ) { - return zone_type_id( "LOOT_BOOKS" ); - } - if( cat.get_id() == "mods" ) { - return zone_type_id( "LOOT_MODS" ); - } - if( cat.get_id() == "mutagen" ) { - return zone_type_id( "LOOT_MUTAGENS" ); - } - if( cat.get_id() == "bionics" ) { - return zone_type_id( "LOOT_BIONICS" ); - } - if( cat.get_id() == "veh_parts" ) { - return zone_type_id( "LOOT_VEHICLE_PARTS" ); - } - if( cat.get_id() == "other" ) { - return zone_type_id( "LOOT_OTHER" ); - } - if( cat.get_id() == "fuel" ) { - return zone_type_id( "LOOT_FUEL" ); - } - if( cat.get_id() == "seeds" ) { - return zone_type_id( "LOOT_SEEDS" ); - } - if( cat.get_id() == "chems" ) { - return zone_type_id( "LOOT_CHEMICAL" ); - } - if( cat.get_id() == "spare_parts" ) { - return zone_type_id( "LOOT_SPARE_PARTS" ); - } - if( cat.get_id() == "artifacts" ) { - return zone_type_id( "LOOT_ARTIFACTS" ); - } if( cat.get_id() == "armor" ) { if( it.is_filthy() && has_near( zone_type_id( "LOOT_FARMOR" ), where, range ) ) { return zone_type_id( "LOOT_FARMOR" ); diff --git a/src/item_category.cpp b/src/item_category.cpp index 6c43d182e18a1..64feac313b1e0 100644 --- a/src/item_category.cpp +++ b/src/item_category.cpp @@ -29,6 +29,7 @@ void item_category::load( JsonObject &jo, const std::string & ) mandatory( jo, was_loaded, "id", id ); mandatory( jo, was_loaded, "name", name_ ); mandatory( jo, was_loaded, "sort_rank", sort_rank_ ); + optional( jo, was_loaded, "zone", zone_, cata::nullopt ); } bool item_category::operator<( const item_category &rhs ) const @@ -62,6 +63,11 @@ item_category_id item_category::get_id() const return id; } +cata::optional item_category::zone() const +{ + return zone_; +} + int item_category::sort_rank() const { return sort_rank_; diff --git a/src/item_category.h b/src/item_category.h index c1bd27134ef0f..953312c3532b2 100644 --- a/src/item_category.h +++ b/src/item_category.h @@ -4,6 +4,7 @@ #include +#include "optional.h" #include "translations.h" #include "type_id.h" @@ -24,6 +25,8 @@ class item_category /** Used to sort categories when displaying. Lower values are shown first. */ int sort_rank_ = 0; + cata::optional zone_; + public: /** Unique ID of this category, used when loading from JSON. */ item_category_id id; @@ -41,6 +44,7 @@ class item_category std::string name() const; item_category_id get_id() const; + cata::optional zone() const; int sort_rank() const; /**