-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbasic.cpp
135 lines (118 loc) · 2.76 KB
/
basic.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
#include "basic.h"
using namespace std;
Config Basic::config = {};
int Basic::edition = 0;
int Basic::mode[2] = {0, 0};
bool Basic::lever[3] = {0, 0, 0};
int Basic::ench_table_l = INIT_LENGTH;
int Basic::weapon_l = INIT_LENGTH;
int Basic::origin_ench_l = INIT_LENGTH;
int Basic::needed_ench_l = INIT_LENGTH;
int Basic::available_item_l = INIT_LENGTH;
int Basic::flow_list_l = INIT_LENGTH;
EnchTable *Basic::ench_table = new EnchTable[Basic::ench_table_l];
Weapon *Basic::weapon = new Weapon[Basic::weapon_l];
Ench *Basic::origin_ench = new Ench[Basic::origin_ench_l];
Ench *Basic::needed_ench = new Ench[Basic::needed_ench_l];
Item *Basic::available_item = new Item[Basic::available_item_l];
Step *Basic::flow_list = new Step[Basic::flow_list_l];
Item Basic::OriginItem = {};
Item Basic::OutputItem = {};
int Basic::sumCost = 0;
Basic::Basic(QObject *parent)
: QObject{parent}
{
}
Basic::~Basic()
{
}
int Basic::searchTable(QString aim)
{
if(aim.isEmpty())
return -1;
for(int i = 0; i < Basic::ench_table_l; i++)
{
if(Basic::ench_table[i].name == aim)
{
return i;
}
}
return -1;
}
int Basic::searchWeapon(QString aim)
{
if(aim.isEmpty())
return -1;
for(int i = 0; i < Basic::weapon_l; i++)
{
if(Basic::weapon[i].name == aim)
{
return i;
}
}
return -1;
}
int Basic::searchEnch(Ench *src, int len, QString aim)
{
if(aim.isEmpty())
return -1;
for(int i = 0; i < len && src[i].name != ""; i++)
{
if(src[i].name == aim)
{
return i;
}
}
return -1;
}
int Basic::compareEnch(Ench *e1, Ench *e2, int len)
{
int diff = 0;
for(int i = 0; i < len && (e1[i].name != "" || e2[i].name != ""); i++)
{
if(e1[i].name != e2[i].name || e1[i].lvl != e2[i].lvl)
diff++;
}
return diff;
}
QString Basic::IntToRoman(int num)
{
if(num > 10 || num < 1)
return "level." + QString::number(num);
else if(num == 10)
return "X";
else if(num == 9)
return "IX";
else if(num == 4)
return "IV";
QString str = "";
if(num > 4)
{
str += "V";
for(int i = num%5; i > 0; i--)
str += "I";
}
else if(num < 4)
{
for(int i = num; i > 0; i--)
str += "I";
}
return str;
//Roman number needed 'N'!
}
int Basic::compareItem(Item A, Item B)
{
int distance = 0;
if(A.name != B.name)
distance++;
if(A.duration != B.duration)
distance++;
if(A.penalty != B.penalty)
distance++;
for(int i = 0; i < INIT_LENGTH; i++)
{
if(A.ench[i].name != B.ench[i].name || A.ench[i].lvl != B.ench[i].lvl)
distance++;
}
return distance;
}