forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelic.h
256 lines (203 loc) · 7.86 KB
/
relic.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#pragma once
#ifndef CATA_SRC_RELIC_H
#define CATA_SRC_RELIC_H
#include <climits>
#include <cmath>
#include <iosfwd>
#include <utility>
#include <vector>
#include "calendar.h"
#include "item.h"
#include "magic.h"
#include "magic_enchantment.h"
#include "translations.h"
#include "type_id.h"
#include "weighted_list.h"
class Character;
class Creature;
class JsonObject;
class JsonOut;
class relic;
class relic_procgen_data;
struct relic_charge_info;
struct relic_charge_template;
struct tripoint;
using relic_procgen_id = string_id<relic_procgen_data>;
class relic_procgen_data
{
public:
/*
* various procgen values for passive enchantment values
* this is a template for the ability to write a little bit
* less code and easier maintainability for additional values
*/
template<typename T = int>
struct enchantment_value_passive {
enchant_vals::mod type;
// THIS CANNOT BE 0
int power_per_increment = 1;
// whatever increment is used for the point values
// THIS CANNOT BE 0
T increment = 1;
T min_value = 0;
T max_value = 0;
int calc_power( T level ) const {
return std::round( level * static_cast<float>( power_per_increment ) /
static_cast<float>( increment ) );
}
bool was_loaded = false;
void load( const JsonObject &jo );
void deserialize( const JsonObject &jo );
};
struct enchantment_active {
spell_id activated_spell;
// power cost of spell at level 0
int base_power = 0;
// power cost increment per spell level increment
int power_per_increment = 1;
// number of spell levels that give the power per increment at
int increment = 1;
// min level of the spell allowed
int min_level = 0;
// max level of the spell allowed
int max_level = 0;
int calc_power( int level ) const {
return base_power + std::round( level *
static_cast<float>( power_per_increment ) / static_cast<float>( increment ) );
}
bool was_loaded = false;
void load( const JsonObject &jo );
void deserialize( const JsonObject &jobj );
};
struct generation_rules {
// the desired power level for the generated artifact
int power_level = 0;
// the most negative (total) attributes a generated artifact can have
int max_negative_power = 0;
// the maximum number of attributes a generated artifact can have
int max_attributes = INT_MAX;
bool was_loaded = false;
void load( const JsonObject &jo );
void deserialize( const JsonObject &jo );
};
enum type {
passive_enchantment_add,
passive_enchantment_mult,
hit_you,
hit_me,
active_enchantment,
last
};
private:
weighted_int_list<relic_charge_template> charge_values;
weighted_int_list<enchantment_value_passive<int>> passive_add_procgen_values;
weighted_int_list<enchantment_value_passive<float>> passive_mult_procgen_values;
weighted_int_list<enchantment_active> passive_hit_you;
weighted_int_list<enchantment_active> passive_hit_me;
weighted_int_list<enchantment_active> active_procgen_values;
weighted_int_list<type> type_weights;
weighted_int_list<itype_id> item_weights;
public:
relic_procgen_id id;
int power_level( const enchantment &ench ) const;
// power level of the active spell
int power_level( const fake_spell &sp ) const;
item create_item( const relic_procgen_data::generation_rules &rules ) const;
relic generate( const generation_rules &rules, const itype_id &it_id ) const;
bool was_loaded = false;
static void load_relic_procgen_data( const JsonObject &jo, const std::string &src );
void load( const JsonObject &jo, const std::string & = "" );
void deserialize( const JsonObject &jobj );
};
enum class relic_recharge_has : int {
WIELD,
WORN,
HELD,
NUM
};
enum class relic_recharge_type : int {
NONE,
PERIODIC,
SOLAR_SUNNY,
NUM
};
struct relic_charge_template {
std::pair<int, int> max_charges;
std::pair<int, int> init_charges;
std::pair<int, int> charges_per_use;
std::pair<time_duration, time_duration> time;
relic_recharge_type type = relic_recharge_type::NUM;
relic_recharge_has has = relic_recharge_has::NUM;
int power_level = 0;
void deserialize( const JsonObject &jo );
void load( const JsonObject &jo );
relic_charge_info generate() const;
};
struct relic_charge_info {
bool regenerate_ammo = false;
int charges = 0;
int charges_per_use = 0;
int max_charges = 0;
relic_recharge_type type = relic_recharge_type::NUM;
relic_recharge_has has = relic_recharge_has::NUM;
time_duration activation_accumulator = 0_seconds;
time_duration activation_time = 0_seconds;
relic_charge_info() = default;
// Because multiple different charge types can overlap, cache the power
// level from the charge type we were generated from here to avoid confusion
int power = 0; // NOLINT(cata-serialize)
// accumulates time for charge, and increases charge if it has enough accumulated.
// assumes exactly one second has passed.
void accumulate_charge( item &parent );
void deserialize( const JsonObject &jo );
void load( const JsonObject &jo );
void serialize( JsonOut &jsout ) const;
};
class relic
{
private:
std::vector<fake_spell> active_effects;
std::vector<enchantment> passive_effects;
// the item's name will be replaced with this if the string is not empty
translation item_name_override; // NOLINT(cata-serialize)
relic_charge_info charge;
// activating an artifact overrides all spell casting costs
int moves = 0;
public:
std::string name() const;
// returns number of charges that should be consumed
int activate( Creature &caster, const tripoint &target );
int charges() const;
int charges_per_use() const;
int max_charges() const;
bool has_activation() const;
// has a recharge type (which needs to be actively processed)
bool has_recharge() const;
void try_recharge( item &parent, Character *carrier, const tripoint &pos );
bool can_recharge( item &parent, Character *carrier );
void load( const JsonObject &jo );
void serialize( JsonOut &jsout ) const;
void deserialize( const JsonObject &jobj );
void add_passive_effect( const enchantment &ench );
void add_active_effect( const fake_spell &sp );
std::vector<enchantment> get_enchantments() const;
int modify_value( enchant_vals::mod value_type, int value ) const;
void overwrite_charge( const relic_charge_info &info );
// what is the power level of this artifact, given a specific ruleset
int power_level( const relic_procgen_id &ruleset ) const;
friend bool operator==( const relic &source_relic, const relic &target_relic );
};
template <typename E> struct enum_traits;
template<>
struct enum_traits<relic_procgen_data::type> {
static constexpr relic_procgen_data::type last = relic_procgen_data::type::last;
};
template<>
struct enum_traits<relic_recharge_type> {
static constexpr relic_recharge_type last = relic_recharge_type::NUM;
};
template<>
struct enum_traits<relic_recharge_has> {
static constexpr relic_recharge_has last = relic_recharge_has::NUM;
};
#endif // CATA_SRC_RELIC_H