Skip to content

Commit

Permalink
jsonizes zones into item_category (#35176)
Browse files Browse the repository at this point in the history
* add zones to item categories

* move zones from hardcode to JSON
  • Loading branch information
KorGgenT authored and ZhilkinSerg committed Nov 3, 2019
1 parent b79b927 commit 33fcb6e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 52 deletions.
20 changes: 20 additions & 0 deletions data/json/item_category.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
{
Expand All @@ -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
},
{
Expand Down
58 changes: 6 additions & 52 deletions src/clzones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,8 @@ cata::optional<tripoint> 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;
Expand All @@ -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;
Expand All @@ -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" );
Expand Down
6 changes: 6 additions & 0 deletions src/item_category.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,6 +63,11 @@ item_category_id item_category::get_id() const
return id;
}

cata::optional<zone_type_id> item_category::zone() const
{
return zone_;
}

int item_category::sort_rank() const
{
return sort_rank_;
Expand Down
4 changes: 4 additions & 0 deletions src/item_category.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <string>

#include "optional.h"
#include "translations.h"
#include "type_id.h"

Expand All @@ -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_type_id> zone_;

public:
/** Unique ID of this category, used when loading from JSON. */
item_category_id id;
Expand All @@ -41,6 +44,7 @@ class item_category

std::string name() const;
item_category_id get_id() const;
cata::optional<zone_type_id> zone() const;
int sort_rank() const;

/**
Expand Down

0 comments on commit 33fcb6e

Please sign in to comment.