-
Notifications
You must be signed in to change notification settings - Fork 7
/
LoadedData.cpp
336 lines (295 loc) · 8.78 KB
/
LoadedData.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
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#include "stdafx.h"
#include "Skill.h"
#include "Common.h"
#include "LoadedData.h"
#include "CharmDatabase.h"
using namespace System;
Skill^ LoadedData::FindSkill( const unsigned skill )
{
Assert( int( skill ) < Skill::static_skills.Count, L"Skill index out of range" );
return Skill::static_skills[ skill ];
}
SkillTag^ SkillTag::FindTag( String^ tag )
{
for each( SkillTag^ st in tags )
{
if( st->name == tag )
return st;
}
return nullptr;
}
void DumpFamilies( String^ filename )
{
Map_t< int, List_t< Armor^ >^ > fammap;
for each( List_t< Armor^ >^ l in Armor::static_armors )
{
for each( Armor^ a in l )
{
if( !fammap.ContainsKey( a->family ) )
fammap.Add( a->family, gcnew List_t< Armor^ >() );
fammap[ a->family ]->Add( a );
}
}
IO::StreamWriter fout( filename );
Map_t< int, List_t< Armor^ >^ >::Enumerator e = fammap.GetEnumerator();
int last_family = -1;
while( e.MoveNext() )
{
if( e.Current.Key != last_family )
{
last_family = e.Current.Key;
fout.WriteLine( L"\nFamily " + last_family );
}
for each( Armor^ a in e.Current.Value )
{
fout.WriteLine( a->name );
}
}
}
void DumpSkills( String^ filename )
{
IO::StreamWriter fout( filename );
for each( Ability^ ab in Ability::static_abilities )
{
fout.WriteLine( ab->jap_name );
}
fout.WriteLine();
for each( Skill^ sk in Skill::static_skills )
{
fout.WriteLine( sk->name );
}
}
void LoadedData::LoadDataFiles()
{
Armor::static_armors = gcnew array< List_t< Armor^ >^ >( int( Armor::ArmorType::NumArmorTypes ) );
Armor::charm_up_armors_b = gcnew array< Armor^ >( int( Armor::ArmorType::NumArmorTypes ) );
Armor::charm_up_armors_g = gcnew array< Armor^ >( int( Armor::ArmorType::NumArmorTypes ) );
for( int i = 0; i < Armor::static_armors->Length; ++i )
Armor::static_armors[ i ] = gcnew List_t< Armor^ >;
Material::LoadMaterials( L"Data/components.txt" );
SkillTag::Load( L"Data/tags.txt" );
Skill::Load( L"Data/skills.txt" );
Skill::LoadCompound( L"Data/compound_skills.txt" );
//DumpSkills( L"Data/Languages/Japanese/skills.txt" );
Skill::LoadSaveData( L"Data/savedata_format.txt");
Armor::Load( L"Data/head.txt", Armor::ArmorType::HEAD );
Armor::Load( L"Data/body.txt", Armor::ArmorType::BODY );
Armor::Load( L"Data/arms.txt", Armor::ArmorType::ARMS );
Armor::Load( L"Data/waist.txt", Armor::ArmorType::WAIST );
Armor::Load( L"Data/legs.txt", Armor::ArmorType::LEGS );
Decoration::Load( L"Data/decorations.txt" );
//DumpFamilies( L"Data/families.txt" );
}
void AddToList( List_t< Decoration^ >^ list, Decoration^ item, List_t< Ability^ >^ rel_abilities, List_t< Decoration^ >^ inf_decs, const bool adv, const bool want_taunt )
{
if( adv && item->force_disable )
return;
const bool may_remove_self = !adv || !item->force_enable;
for( int i = 0; i < list->Count; ++i )
{
if( item->IsBetterThan( list[ i ], rel_abilities ) )
{
const bool may_remove = !adv || !list[ i ]->force_enable;
if( may_remove && !list[ i ]->IsBetterThan( item, rel_abilities ) )
list->Remove( list[ i-- ] );
}
else if( may_remove_self && list[ i ]->IsBetterThan( item, rel_abilities ) )
return;
}
list->Add( item );
inf_decs->Add( item );
}
void AddToList( List_t< Armor^ >^ list, Armor^ armor, List_t< Ability^ >^ rel_abilities, List_t< Armor^ >^ inf_armor, const bool adv, const bool want_taunt )
{
if( adv && ( armor->force_disable || armor->charm_up ) )
return;
const bool may_remove_self = !adv || !armor->force_enable;
for( int i = 0; i < list->Count; ++i )
{
if( armor->IsBetterThan( list[ i ], rel_abilities, want_taunt) )
{
const bool may_remove = !adv || !list[ i ]->force_enable;
if( may_remove && ( !armor->danger || armor->danger == list[ i ]->danger ) && !list[ i ]->IsBetterThan( armor, rel_abilities, want_taunt ) )
{
list->Remove( list[ i-- ] );
}
}
else if( may_remove_self && ( !list[ i ]->danger || list[ i ]->danger == armor->danger ) && list[ i ]->IsBetterThan( armor, rel_abilities, want_taunt ) )
{
if( inf_armor )
{
inf_armor->Add( armor );
}
return;
}
}
list->Add( armor );
if( inf_armor )
inf_armor->Add( armor );
}
void GetRelevantArmors( Query^ query, List_t< Armor^ >^ rel_armor, List_t< Armor^ >^ list, List_t< Armor^ >^ inf_armor, List_t< Ability^ >^ danger_skills, unsigned % max_slots )
{
bool need_slot_only = true;
for each( Armor^ armor in list )
{
if( armor->MatchesQuery( query, danger_skills, max_slots ) )
{
if( armor->num_slots > max_slots )
{
max_slots = armor->num_slots;
need_slot_only = armor->no_skills;
}
else if( armor->num_slots == max_slots && !armor->no_skills )
need_slot_only = false;
AddToList( rel_armor, armor, %query->rel_abilities, inf_armor, false, query->want_taunt );
}
}
for( int i = 0; i < inf_armor->Count; ++i )
{
Armor^ a = inf_armor[ i ];
if( a->no_skills )
{
if( a->num_slots < max_slots ||
a->num_slots == max_slots && !need_slot_only )
inf_armor->RemoveAt( i-- );
}
}
}
void GetRelevantDecorations( Query^ query )
{
for each( Skill^ skill in query->skills )
{
if( !Decoration::static_decoration_ability_map.ContainsKey( skill->ability ) ||
skill->is_taunt )
continue;
for each( Decoration^ decoration in Decoration::static_decoration_ability_map[ skill->ability ] )
{
if( decoration->MatchesQuery( query ) )
{
AddToList( %query->rel_decorations, decoration, %query->rel_abilities, %query->inf_decorations, false, query->want_taunt );
}
}
}
if( query->want_taunt )
{
for each( Decoration^ decoration in Decoration::static_decorations )
{
if( decoration->slots_required == 1 &&
decoration->abilities.Count == 2 &&
decoration->abilities[1]->ability == SpecificAbility::sense &&
decoration->abilities[1]->amount < 0 )
{
if( decoration->hr > query->hr && decoration->elder_star > query->elder_star ||
decoration->is_event && !query->allow_event )
continue;
query->taunt_decorations.Add( decoration );
}
}
}
//for each( Decoration^ decoration in query->rel_decorations )
// decoration->dangerous = decoration->abilities.Count == 2 && Utility::Contains( %query->rel_abilities, decoration->abilities[ 1 ]->ability );
}
int NeededPoints( List_t< Skill^ >^ skills, Ability^ ability )
{
for each( Skill^ skill in skills )
{
if( skill->ability == ability )
return skill->points_required;
}
return 0;
}
void LoadedData::GetRelevantData( Query^ query )
{
for each( Ability^ ab in Ability::static_abilities )
{
ab->relevant = false;
}
for each( Skill^ skill in query->skills )
{
skill->autodisabled = false;
}
List_t< Ability^ > danger_skills;
//get relevant abilities
for each( Skill^ skill in query->skills )
{
if( !skill->is_taunt )
{
query->rel_abilities.Add( skill->ability );
skill->ability->relevant = true;
}
if( Skill::compound_skill_map.ContainsKey( skill ) )
{
for each( Skill^ s in Skill::compound_skill_map[ skill ] )
{
s->autodisabled = true;
}
}
}
query->rel_abilities.TrimExcess();
//get relevant decorations
Decoration::RecheckEfficientDecorations( query );
GetRelevantDecorations( query );
query->rel_decorations.TrimExcess();
//get danger skills
/*if( query->danger )
for each( Decoration^ decoration in query->rel_decorations )
{
Ability^ bad_ability = nullptr;
bool points20 = false;
for each( AbilityPair^ apair in decoration->abilities )
{
if( apair->amount < 0 )
{
if( !Utility::Contains( %danger_skills, apair->ability ) )
bad_ability = apair->ability;
}
else if( NeededPoints( %query->skills, apair->ability ) == 20 )
points20 = true;
}
if( points20 && bad_ability )
danger_skills.Add( bad_ability );
}*/
//get relevant armors
for( int i = 0; i < int( Armor::ArmorType::NumArmorTypes ); ++i )
{
unsigned max_slots = 0;
GetRelevantArmors( query, query->rel_armor[ i ], Armor::static_armors[ i ], query->inf_armor[ i ], %danger_skills, max_slots );
query->rel_armor[ i ]->TrimExcess();
}
query->rel_armor.TrimExcess();
}
void SkillTag::Load( System::String^ filename )
{
tags.Clear();
tags.Add( gcnew SkillTag( L"All" ) );
tags.Add( gcnew SkillTag( L"Misc" ) );
tags.Add( gcnew SkillTag( L"Related" ) );
IO::StreamReader fin( filename );
while( !fin.EndOfStream )
{
String^ tag = fin.ReadLine();
if( tag != L"" )
tags.Add( gcnew SkillTag( tag ) );
}
}
void SkillTag::LoadLanguage( String^ filename )
{
IO::StreamReader fin( filename );
for( int i = 0; i < tags.Count; )
{
String^ line = fin.ReadLine();
if( !line )
{
Windows::Forms::MessageBox::Show( L"Unexpected end of file: not enough lines of text", filename );
break;
}
if( line == L"" || line[ 0 ] == L'#' )
continue;
tags[ i ]->name = line;
i++;
}
}
SkillTag::SkillTag( System::String^ s )
: name( s ), disable_g( s == "Blademaster" ), disable_b( s == "Bow/Gunner" )
{
}