forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
item_category.h
88 lines (74 loc) · 2.74 KB
/
item_category.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#pragma once
#ifndef CATA_SRC_ITEM_CATEGORY_H
#define CATA_SRC_ITEM_CATEGORY_H
#include <iosfwd>
#include <new>
#include <vector>
#include "flat_set.h"
#include "optional.h"
#include "translations.h"
#include "type_id.h"
class JsonObject;
class item;
// this is a helper struct with rules for picking a zone
struct zone_priority_data {
bool was_loaded = false;
zone_type_id id;
bool filthy = false;
cata::flat_set<flag_id> flags;
void deserialize( const JsonObject &jo );
void load( const JsonObject &jo );
};
/**
* Contains metadata for one category of items
*
* Every item belongs to a category (e.g. weapons, armor, food, etc). This class
* contains the info about one such category. Actual categories are normally added
* by class @ref Item_factory from definitions in the JSON data files.
*/
class item_category
{
private:
/** Name of category for displaying to the user */
translation name_;
/** Used to sort categories when displaying. Lower values are shown first. */
int sort_rank_ = 0;
cata::optional<zone_type_id> zone_;
std::vector<zone_priority_data> zone_priority_;
public:
/** Unique ID of this category, used when loading from JSON. */
item_category_id id;
std::vector<std::pair<item_category_id, mod_id>> src;
item_category() = default;
/**
* @param id @ref id_
* @param name @ref name_
* @param sort_rank @ref sort_rank_
*/
item_category( const item_category_id &id, const translation &name, int sort_rank )
: name_( name ), sort_rank_( sort_rank ), id( id ) {}
item_category( const std::string &id, const translation &name, int sort_rank )
: name_( name ), sort_rank_( sort_rank ), id( item_category_id( id ) ) {}
std::string name() const;
item_category_id get_id() const;
cata::optional<zone_type_id> priority_zone( const item &it ) const;
cata::optional<zone_type_id> zone() const;
int sort_rank() const;
/**
* Comparison operators
*
* Used for sorting. Will result in sorting by @ref sort_rank, then by @ref name, then by @ref id.
*/
/*@{*/
bool operator<( const item_category &rhs ) const;
bool operator==( const item_category &rhs ) const;
bool operator!=( const item_category &rhs ) const;
/*@}*/
// generic_factory stuff
bool was_loaded = false;
static const std::vector<item_category> &get_all();
static void load_item_cat( const JsonObject &jo, const std::string &src );
static void reset();
void load( const JsonObject &jo, const std::string & );
};
#endif // CATA_SRC_ITEM_CATEGORY_H