forked from simulationcraft/simc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrait_data.cpp
209 lines (171 loc) · 5.11 KB
/
trait_data.cpp
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
// ==========================================================================
// Dedmonwakeen's DPS-DPM Simulator.
// Send questions to [email protected]
// ==========================================================================
#include <array>
#include "config.hpp"
#include "util/util.hpp"
#include "trait_data.hpp"
#include "generated/trait_data.inc"
#if SC_USE_PTR == 1
#include "generated/trait_data_ptr.inc"
#endif
util::span<const trait_data_t> trait_data_t::data( bool ptr )
{
return SC_DBC_GET_DATA( __trait_data_data, __ptr_trait_data_data, ptr );
}
util::span<const trait_data_t> trait_data_t::data( talent_tree tree, bool ptr )
{
auto _data = data( ptr );
auto _tree_index = static_cast<unsigned>( tree );
auto _tree_range = range::equal_range( _data, _tree_index, {}, &trait_data_t::tree_index );
return { _tree_range.first, _tree_range.second };
}
util::span<const trait_data_t> trait_data_t::data( unsigned class_id, talent_tree tree, bool ptr )
{
auto _tree_span = data( tree, ptr );
auto _class_range = range::equal_range( _tree_span, class_id, {}, &trait_data_t::id_class );
return { _class_range.first, _class_range.second };
}
const trait_data_t* trait_data_t::find( unsigned trait_node_entry_id, bool ptr )
{
auto _data = data( ptr );
auto _it = range::find( _data, trait_node_entry_id, &trait_data_t::id_trait_node_entry );
if ( _it != _data.end() )
{
return _it;
}
return &( nil() );
}
const trait_data_t* trait_data_t::find(
talent_tree tree,
util::string_view name,
unsigned class_id,
specialization_e spec,
bool ptr )
{
auto _data = data( class_id, tree, ptr );
auto _it = range::find_if( _data, [name, spec]( const trait_data_t& entry ) {
if ( util::str_compare_ci( name, entry.name ) )
{
if ( entry.id_spec[ 0 ] == 0 )
{
return true;
}
auto _spec_it = range::find( entry.id_spec, static_cast<unsigned>( spec ) );
if ( _spec_it != entry.id_spec.end() )
{
return true;
}
}
return false;
} );
if ( _it != _data.end() )
{
return _it;
}
return &( nil() );
}
const trait_data_t* trait_data_t::find_tokenized(
talent_tree tree,
util::string_view name,
unsigned class_id,
specialization_e spec,
bool ptr )
{
auto _data = data( class_id, tree, ptr );
auto _it = range::find_if( _data, [name, spec]( const trait_data_t& entry ) {
std::string tokenized_name = entry.name;
util::tokenize( tokenized_name );
if ( util::str_compare_ci( name, tokenized_name ) )
{
if ( entry.id_spec[ 0 ] == 0 )
{
return true;
}
auto _spec_it = range::find( entry.id_spec, static_cast<unsigned>( spec ) );
if ( _spec_it != entry.id_spec.end() )
{
return true;
}
}
return false;
} );
if ( _it != _data.end() )
{
return _it;
}
return &( nil() );
}
std::vector<const trait_data_t*> trait_data_t::find_by_spell(
talent_tree tree,
unsigned spell_id,
unsigned class_id,
specialization_e spec,
bool ptr )
{
const auto _data = data( ptr );
const auto _index = SC_DBC_GET_DATA( __trait_spell_id_index, __ptr_trait_spell_id_index, ptr );
auto span = range::equal_range( _index, spell_id, {},
[ _data ]( uint16_t index ) { return _data[ index ].id_spell; } );
if ( span.first == _index.end() )
{
return {};
}
std::vector<const trait_data_t*> generic_entries, spec_entries;
for ( auto i = span.first; i < span.second; ++i )
{
const auto& entry = _data[ *i ];
if ( tree != talent_tree::INVALID &&
entry.tree_index != static_cast<unsigned>( tree ) )
{
continue;
}
if ( class_id != 0 && entry.id_class != class_id )
{
continue;
}
// If no spec filter, store everything as "generic entry"
if ( entry.id_spec[ 0U ] == 0U || spec == SPEC_NONE )
{
generic_entries.push_back( &( entry ) );
}
if ( spec != SPEC_NONE )
{
auto it = range::find( entry.id_spec, static_cast<unsigned>( spec ) );
if ( it != entry.id_spec.end() )
{
spec_entries.push_back( &( entry ) );
}
}
}
if ( spec != SPEC_NONE && !spec_entries.empty() )
{
return spec_entries;
}
else
{
return generic_entries;
}
}
const trait_data_t* trait_data_t::find_by_trait_definition( unsigned trait_definition_id, bool ptr )
{
auto _data = data( ptr );
auto _it = range::find( _data, trait_definition_id, &trait_data_t::id_trait_definition );
if ( _it != _data.end() )
{
return _it;
}
return &( nil() );
}
util::span<const trait_definition_effect_entry_t> trait_definition_effect_entry_t::data( bool ptr )
{
return SC_DBC_GET_DATA( __trait_definition_effect_data, __ptr_trait_definition_effect_data, ptr );
}
util::span<const trait_definition_effect_entry_t> trait_definition_effect_entry_t::find( unsigned id, bool ptr )
{
auto _data = data( ptr );
auto it = range::equal_range( _data, id, {},
&trait_definition_effect_entry_t::id_trait_definition );
return { it.first, it.second };
}