1 #pragma once
2 #ifndef CATA_SRC_FACTION_H
3 #define CATA_SRC_FACTION_H
4 
5 #include <bitset>
6 #include <iosfwd>
7 #include <map>
8 #include <set>
9 #include <string>
10 #include <tuple>
11 #include <unordered_map>
12 #include <utility>
13 #include <vector>
14 
15 #include "character_id.h"
16 #include "color.h"
17 #include "translations.h"
18 #include "type_id.h"
19 
20 namespace catacurses
21 {
22 class window;
23 }  // namespace catacurses
24 
25 // TODO: Redefine?
26 static constexpr int MAX_FAC_NAME_SIZE = 40;
27 
28 std::string fac_ranking_text( int val );
29 std::string fac_respect_text( int val );
30 std::string fac_wealth_text( int val, int size );
31 std::string fac_combat_ability_text( int val );
32 
33 class JsonIn;
34 class JsonObject;
35 class JsonOut;
36 class faction;
37 
38 using faction_id = string_id<faction>;
39 
40 namespace npc_factions
41 {
42 void finalize();
43 enum relationship : int {
44     kill_on_sight,
45     watch_your_back,
46     share_my_stuff,
47     guard_your_stuff,
48     lets_you_in,
49     defend_your_space,
50     knows_your_voice,
51     // final value is the count
52     rel_types
53 };
54 
55 const std::unordered_map<std::string, relationship> relation_strs = { {
56         { "kill on sight", kill_on_sight },
57         { "watch your back", watch_your_back },
58         { "share my stuff", share_my_stuff },
59         { "guard your stuff", guard_your_stuff },
60         { "lets you in", lets_you_in },
61         { "defends your space", defend_your_space },
62         { "knows your voice", knows_your_voice }
63     }
64 };
65 } // namespace npc_factions
66 
67 class faction_template
68 {
69     protected:
70         faction_template();
71         void load_relations( const JsonObject &jsobj );
72 
73     private:
74         explicit faction_template( const JsonObject &jsobj );
75 
76     public:
77         faction_template( const faction_template & ) = default;
78         static void load( const JsonObject &jsobj );
79         static void check_consistency();
80         static void reset();
81 
82         std::string name;
83         int likes_u;
84         int respects_u;
85         bool known_by_u;
86         faction_id id;
87         translation desc;
88         int size; // How big is our sphere of influence?
89         int power; // General measure of our power
90         int food_supply;  //Total nutritional value held
91         int wealth;  //Total trade currency
92         bool lone_wolf_faction; // is this a faction for just one person?
93         itype_id currency; // id of the faction currency
94         std::map<std::string, std::bitset<npc_factions::rel_types>> relations;
95         mfaction_str_id mon_faction; // mon_faction_id of the monster faction; defaults to human
96         std::set<std::tuple<int, int, snippet_id>> epilogue_data;
97 };
98 
99 class faction : public faction_template
100 {
101     public:
102         faction() = default;
103         explicit faction( const faction_template &templ );
104 
105         void deserialize( JsonIn &jsin );
106         void serialize( JsonOut &json ) const;
107         void faction_display( const catacurses::window &fac_w, int width ) const;
108 
109         std::string describe() const;
110         std::vector<std::string> epilogue() const;
111 
112         std::string food_supply_text();
113         nc_color food_supply_color();
114 
115         bool has_relationship( const faction_id &guy_id, npc_factions::relationship flag ) const;
116         void add_to_membership( const character_id &guy_id, const std::string &guy_name, bool known );
117         void remove_member( const character_id &guy_id );
118         std::vector<int> opinion_of;
119         bool validated = false;
120         std::map<character_id, std::pair<std::string, bool>> members;
121 };
122 
123 class faction_manager
124 {
125     private:
126         std::map<faction_id, faction> factions;
127 
128     public:
129         void deserialize( JsonIn &jsin );
130         void serialize( JsonOut &jsout ) const;
131 
132         void clear();
133         void create_if_needed();
134         void display() const;
135         faction *add_new_faction( const std::string &name_new, const faction_id &id_new,
136                                   const faction_id &template_id );
137         void remove_faction( const faction_id &id );
all()138         const std::map<faction_id, faction> &all() const {
139             return factions;
140         }
141 
142         faction *get( const faction_id &id, bool complain = true );
143 };
144 
145 #endif // CATA_SRC_FACTION_H
146