EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
EffectsDataMgr.cpp
Go to the documentation of this file.
1 
12 #include "effects/EffectsDataMgr.h"
14 
15 
17 {
18  m_loaded = false;
19 
20  m_fxMap.clear();
21  m_opMap.clear();
22  m_expMap.clear();
23  m_effectMap.clear();
24  m_typeFxMap.clear();
25 }
26 
28 {
29 
30 }
31 
33 {
34  Populate();
35  sLog.Blue(" FxDataMgr", "Effects Data Manager Initialized.");
36  return 1;
37 }
38 
40 {
41  if (m_loaded)
42  return;
43 
44  double begin = GetTimeMSeconds();
45  double start = GetTimeMSeconds();
46  DBResultRow row;
47  DBQueryResult* res = new DBQueryResult();
48 
49  GetDgmTypeEffects(*res);
50  while (res->GetRow(row)) {
51  //SELECT typeID, effectID, isDefault
52  TypeEffects mTfx = TypeEffects();
53  mTfx.effectID = row.GetInt(1);
54  mTfx.isDefault = row.GetBool(2);
55  m_typeFxMap.insert(std::pair<uint16, TypeEffects>(row.GetInt(0), mTfx));
56  }
57  sLog.Cyan(" FxDataMgr", "%u Type Effects loaded in %.3fms.", m_typeFxMap.size(), (GetTimeMSeconds() - start));
58 
59  //res->Reset();
60  start = GetTimeMSeconds();
61  GetOperands(*res);
62  while (res->GetRow(row)) {
63  //SELECT operandID, operandKey, format, arg1categoryID, arg2categoryID, resultCategoryID
64  Operand mOpr = Operand();
65  mOpr.arg1categoryID = row.GetInt(3);
66  mOpr.arg2categoryID = row.GetInt(4);
67  mOpr.format = row.GetText(2);
68  mOpr.operandKey = row.GetText(1);
69  mOpr.resultCategoryID = row.GetInt(5);
70  m_opMap.insert(std::pair<uint16, Operand>(row.GetInt(0), mOpr));
71  }
72  // insert a zero-value data set
73  Operand mOpr = Operand();
74  mOpr.format = "None";
75  mOpr.operandKey = "NULL";
76  m_opMap[0] = mOpr;
77  sLog.Cyan(" FxDataMgr", "%u Operands loaded in %.3fms.", m_opMap.size(), (GetTimeMSeconds() - start));
78 
79  //res->Reset();
80  start = GetTimeMSeconds();
81  GetExpressions(*res);
82  while (res->GetRow(row)) {
83  //SELECT expressionID, operandID, arg1, arg2, expressionValue, description, expressionName, expressionTypeID, expressionGroupID, expressionAttributeID
84  Expression mExp = Expression();
85  mExp.id = row.GetInt(0);
86  mExp.arg1 = (row.IsNull(2) ? 0 : row.GetInt(2));
87  mExp.arg2 = (row.IsNull(3) ? 0 : row.GetInt(3));
88  mExp.expressionAttributeID = (row.IsNull(9) ? 0 : row.GetInt(9));
89  mExp.description = row.GetText(5);
90  mExp.expressionGroupID = (row.IsNull(8) ? 0 : row.GetInt(8));
91  mExp.expressionName = row.GetText(6);
92  mExp.operandID = row.GetInt(1);
93  mExp.expressionTypeID = (row.IsNull(7) ? 0 : row.GetInt(7));
94  mExp.expressionValue = row.GetText(4);
95  m_expMap.insert(std::pair<uint16, Expression>(row.GetInt(0), mExp));
96  }
97  // insert a zero-value data set
98  Expression mExp = Expression();
99  mExp.description = "NULL";
100  mExp.expressionName = "NULL";
101  m_expMap[0] = mExp;
102  sLog.Cyan(" FxDataMgr", "%u Expressions loaded in %.3fms.", m_expMap.size(), (GetTimeMSeconds() - start));
103 
104  //res->Reset();
105  start = GetTimeMSeconds();
106  GetDgmEffects(*res);
107  while (res->GetRow(row)) {
108  //SELECT effectID, effectName, effectState, preExpression, postExpression, isOffensive, isAssistance, disallowAutoRepeat, isWarpSafe \
109  // npcUsageChanceAttributeID, npcActivationChanceAttributeID, fittingUsageChanceAttributeID,\
110  // durationAttributeID, trackingSpeedAttributeID, dischargeAttributeID, rangeAttributeID, falloffAttributeID, rangeChance, electronicChance, propulsionChance, guid
111  Effect mEffect = Effect();
112  mEffect.effectID = row.GetInt(0);
113  mEffect.effectName = row.GetText(1);
114  mEffect.effectState = row.GetInt(2);
115  mEffect.preExpression = row.GetInt(3);
116  mEffect.postExpression = row.GetInt(4);
117  mEffect.isOffensive = row.GetInt(5) ? true : false;
118  mEffect.isAssistance = row.GetInt(6) ? true : false;
119  mEffect.disallowAutoRepeat = row.GetInt(7) ? true : false;
120  mEffect.isWarpSafe = row.GetInt(8) ? true : false;
121  mEffect.npcUsageChanceAttributeID = row.GetInt(9);
122  mEffect.npcActivationChanceAttributeID = row.GetInt(10);
123  mEffect.fittingUsageChanceAttributeID = row.GetInt(11);
124  mEffect.durationAttributeID = (row.IsNull(12) ? 0 : row.GetInt(12));
125  mEffect.trackingSpeedAttributeID = (row.IsNull(13) ? 0 : row.GetInt(13));
126  mEffect.dischargeAttributeID = (row.IsNull(14) ? 0 : row.GetInt(14));
127  mEffect.rangeAttributeID = (row.IsNull(15) ? 0 : row.GetInt(15));
128  mEffect.falloffAttributeID = (row.IsNull(16) ? 0 : row.GetInt(16));
129  mEffect.rangeChance = row.GetFloat(17);
130  mEffect.electronicChance = row.GetFloat(18);
131  mEffect.propulsionChance = row.GetFloat(19);
132  mEffect.guid = row.GetText(20);
133  m_effectMap.insert(std::pair<uint16, Effect>(row.GetInt(0), mEffect));
134  m_effectName.insert(std::pair<std::string, uint16>(mEffect.effectName, row.GetInt(0)));
135  }
136  // insert a zero-value data set
137  Effect mEffect = Effect();
138  mEffect.effectName = "NULL";
139  m_effectMap[0] = mEffect;
140  sLog.Cyan(" FxDataMgr", "%u Effect Types loaded in %.3fms.", m_effectMap.size(), (GetTimeMSeconds() - start));
141 
142  //cleanup
143  SafeDelete(res);
144 
145  m_loaded = true;
146  sLog.Cyan(" FxDataMgr", "Effects Data loaded in %.3fms.", (GetTimeMSeconds() - begin));
147 }
148 
150 {
151  effectMapType::const_iterator itr = m_effectMap.find(eID);
152  if (itr != m_effectMap.end())
153  return itr->second;
154  return m_effectMap.at(0);
155 }
156 
157 void FxDataMgr::GetTypeEffect(uint16 typeID, std::vector< TypeEffects >& typeEffMap)
158 {
159  auto itr = m_typeFxMap.equal_range(typeID);
160  for (auto it = itr.first; it != itr.second; ++it)
161  typeEffMap.push_back(it->second);
162 }
163 
165 {
166  std::map<uint16, Expression>::const_iterator itr = m_expMap.find(eID);
167  if (itr != m_expMap.end())
168  return itr->second;
169  return m_expMap.at(0);
170 }
171 
173 {
174  std::map<uint16, Operand>::const_iterator itr = m_opMap.find(oID);
175  if (itr != m_opMap.end())
176  return itr->second;
177  return m_opMap.at(0);
178 
179 }
180 
182 {
183  effectMapType::const_iterator itr = m_effectMap.find(eID);
184  if (itr != m_effectMap.end())
185  return itr->second.isWarpSafe;
186  return false; // default to false if effectID not found
187 }
188 
190 {
191  effectMapType::const_iterator itr = m_effectMap.find(eID);
192  if (itr != m_effectMap.end())
193  return itr->second.isOffensive;
194  return false; // default to false if effectID not found
195 }
196 
198 {
199  effectMapType::const_iterator itr = m_effectMap.find(eID);
200  if (itr != m_effectMap.end())
201  return itr->second.isAssistance;
202  return false; // default to false if effectID not found
203 }
204 
205 uint16 FxDataMgr::GetEffectID(std::string effectName)
206 {
207  std::map<std::string, uint16>::const_iterator itr = m_effectName.find(effectName);
208  if (itr != m_effectName.end())
209  return itr->second;
210  return 0;
211 }
212 
214 {
215  effectMapType::const_iterator itr = m_effectMap.find(eID);
216  if (itr != m_effectMap.end())
217  return itr->second.guid;
218  return ""; // default to 'nothing' if effectID not found
219 }
220 
222 {
223  effectMapType::const_iterator itr = m_effectMap.find(eID);
224  if (itr != m_effectMap.end())
225  return itr->second.effectName;
226  return ""; // default to 'nothing' if effectID not found
227 }
228 
229 
231 {
232  if( !sDatabase.RunQuery(res,
233  " SELECT"
234  " operandID,"
235  " operandKey,"
236  " format,"
237  " arg1categoryID,"
238  " arg2categoryID,"
239  " resultCategoryID"
240  " FROM dgmOperands"))
241  {
242  codelog(DATABASE__ERROR, "Error in GetOperands: %s", res.error.c_str());
243  }
244 }
245 
247 {
248  if( !sDatabase.RunQuery(res,
249  " SELECT"
250  " effectID,"
251  " effectName,"
252  " effectCategory,"
253  " preExpression,"
254  " postExpression,"
255  " isOffensive,"
256  " isAssistance,"
257  " disallowAutoRepeat,"
258  " isWarpSafe,"
259  " npcUsageChanceAttributeID,"
260  " npcActivationChanceAttributeID,"
261  " fittingUsageChanceAttributeID,"
262  " durationAttributeID,"
263  " trackingSpeedAttributeID,"
264  " dischargeAttributeID,"
265  " rangeAttributeID,"
266  " falloffAttributeID,"
267  " rangeChance," // dunno what this is ...bool?
268  " electronicChance," // dunno what this is...bool?
269  " propulsionChance," // not used (all 0)...bool?
270  " guid"
271  " FROM dgmEffects"))
272  {
273  codelog(DATABASE__ERROR, "Error in GetDgmEffects: %s", res.error.c_str());
274  }
275 }
276 
278 {
279  if( !sDatabase.RunQuery(res,
280  " SELECT"
281  " expressionID,"
282  " operandID,"
283  " arg1,"
284  " arg2,"
285  " expressionValue,"
286  " description,"
287  " expressionName,"
288  " expressionTypeID,"
289  " expressionGroupID,"
290  " expressionAttributeID"
291  " FROM dgmExpressions"))
292  {
293  codelog(DATABASE__ERROR, "Error in GetExpressions: %s", res.error.c_str());
294  }
295 }
296 
298 {
299  if( !sDatabase.RunQuery(res,
300  " SELECT"
301  " typeID,"
302  " effectID,"
303  " isDefault"
304  " FROM dgmTypeEffects "
305  " WHERE effectID != 132")) // 132 maps skill level onto skill data. this screws up my skill level code
306  {
307  codelog(DATABASE__ERROR, "Error in GetDgmTypeEffects: %s", res.error.c_str());
308  }
309 }
uint16 preExpression
Definition: EffectsData.h:26
#define sDatabase
Definition: dbcore.h:199
bool isDefault
Definition: EffectsData.h:65
uint16 effectID
Definition: EffectsData.h:66
Operand GetOperand(uint16 oID)
const char * GetText(uint32 index) const
Definition: dbcore.h:104
std::map< std::string, uint16 > m_effectName
bool isWarpSafe(uint16 eID)
float GetFloat(uint32 index) const
Definition: dbcore.cpp:682
int32 GetInt(uint32 index) const
Definition: dbcore.cpp:635
std::string GetEffectName(uint16 eID)
uint16 GetEffectID(std::string effectName)
uint16 fittingUsageChanceAttributeID
Definition: EffectsData.h:30
uint16 durationAttributeID
Definition: EffectsData.h:31
std::string format
Definition: EffectsData.h:61
int Initialize()
uint16 id
Definition: EffectsData.h:45
int8 operandID
Definition: EffectsData.h:44
std::map< uint16, Expression > m_expMap
uint16 postExpression
Definition: EffectsData.h:27
float propulsionChance
Definition: EffectsData.h:38
std::string effectName
Definition: EffectsData.h:39
uint16 falloffAttributeID
Definition: EffectsData.h:35
uint16 expressionTypeID
Definition: EffectsData.h:48
float rangeChance
Definition: EffectsData.h:36
bool isOffensive
Definition: EffectsData.h:20
uint16 arg1categoryID
Definition: EffectsData.h:58
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
std::string operandKey
Definition: EffectsData.h:60
std::string expressionName
Definition: EffectsData.h:53
effectMapType m_effectMap
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
bool GetBool(uint32 index) const
Definition: dbcore.cpp:647
uint8 effectState
Definition: EffectsData.h:25
Expression GetExpression(uint16 eID)
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
std::string GetEffectGuid(uint16 eID)
uint16 arg2categoryID
Definition: EffectsData.h:59
const char * c_str() const
Definition: dbcore.h:48
double GetTimeMSeconds()
Definition: utils_time.cpp:104
bool isWarpSafe
Definition: EffectsData.h:23
#define codelog(type, fmt,...)
Definition: logsys.h:128
uint16 arg2
Definition: EffectsData.h:47
void GetDgmEffects(DBQueryResult &res)
uint16 dischargeAttributeID
Definition: EffectsData.h:33
void GetTypeEffect(uint16 typeID, std::vector< TypeEffects > &typeEffMap)
bool IsNull(uint32 index) const
Definition: dbcore.h:102
float electronicChance
Definition: EffectsData.h:37
uint16 npcUsageChanceAttributeID
Definition: EffectsData.h:28
uint16 arg1
Definition: EffectsData.h:46
bool isAssistance
Definition: EffectsData.h:21
uint16 expressionAttributeID
Definition: EffectsData.h:50
bool disallowAutoRepeat
Definition: EffectsData.h:22
uint16 expressionGroupID
Definition: EffectsData.h:49
std::map< uint16, Operand > m_opMap
uint16 effectID
Definition: EffectsData.h:24
Effect GetEffect(uint16 eID)
void GetExpressions(DBQueryResult &res)
DBerror error
Definition: dbcore.h:69
std::unordered_multimap< uint16, TypeEffects > m_typeFxMap
std::string expressionValue
Definition: EffectsData.h:51
uint8 resultCategoryID
Definition: EffectsData.h:57
bool isAssistance(uint16 eID)
uint16 trackingSpeedAttributeID
Definition: EffectsData.h:32
effectMapType m_fxMap
void GetDgmTypeEffects(DBQueryResult &res)
bool isOffensive(uint16 eID)
std::string guid
Definition: EffectsData.h:40
uint16 npcActivationChanceAttributeID
Definition: EffectsData.h:29
std::string description
Definition: EffectsData.h:52
unsigned __int16 uint16
Definition: eve-compat.h:48
void GetOperands(DBQueryResult &res)
void Populate()
uint16 rangeAttributeID
Definition: EffectsData.h:34