1 #pragma once
2 #ifndef CATA_SRC_BONUSES_H
3 #define CATA_SRC_BONUSES_H
4 
5 #include <iosfwd>
6 #include <map>
7 #include <vector>
8 
9 #include "damage.h"
10 
11 class Character;
12 class JsonArray;
13 class JsonObject;
14 
15 enum scaling_stat : int {
16     STAT_NULL = 0,
17     STAT_STR,
18     STAT_DEX,
19     STAT_INT,
20     STAT_PER,
21     NUM_STATS
22 };
23 
24 enum class affected_stat : int {
25     NONE = 0,
26     HIT,
27     CRITICAL_HIT_CHANCE,
28     DODGE,
29     BLOCK,
30     BLOCK_EFFECTIVENESS,
31     SPEED,
32     MOVE_COST,
33     DAMAGE,
34     ARMOR,
35     ARMOR_PENETRATION,
36     TARGET_ARMOR_MULTIPLIER,
37     NUM_AFFECTED
38 };
39 
40 // We'll be indexing bonuses with this
41 struct affected_type {
42     public:
43         explicit affected_type( affected_stat s );
44         affected_type( affected_stat s, damage_type t );
45         bool operator<( const affected_type & ) const;
46         bool operator==( const affected_type & ) const;
47 
get_stataffected_type48         affected_stat get_stat() const {
49             return stat;
50         }
51 
get_damage_typeaffected_type52         damage_type get_damage_type() const {
53             return type;
54         }
55 
56     private:
57         affected_stat stat = affected_stat::NONE;
58         damage_type type = damage_type::NONE;
59 };
60 
61 // This is the bonus we are indexing
62 struct effect_scaling {
63     scaling_stat stat;
64     float scale;
65 
66     float get( const Character &u ) const;
67 
68     explicit effect_scaling( const JsonObject &obj );
69 };
70 
71 class bonus_container
72 {
73     public:
74         bonus_container();
75         void load( const JsonObject &jo );
76 
77         float get_flat( const Character &u, affected_stat stat, damage_type dt ) const;
78         float get_flat( const Character &u, affected_stat stat ) const;
79 
80         float get_mult( const Character &u, affected_stat stat, damage_type dt ) const;
81         float get_mult( const Character &u, affected_stat stat ) const;
82 
83         std::string get_description() const;
84 
85     private:
86         void load( const JsonArray &jarr, bool mult );
87 
88         using bonus_map = std::map<affected_type, std::vector<effect_scaling>>;
89         /** All kinds of bonuses by types to damage, hit etc. */
90         bonus_map bonuses_flat;
91         bonus_map bonuses_mult;
92 };
93 
94 #endif // CATA_SRC_BONUSES_H
95