EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GenericModule.cpp
Go to the documentation of this file.
1 
9 /*
10 MODULE__ERROR
11 MODULE__WARNING
12 MODULE__MESSAGE
13 MODULE__INFO
14 MODULE__DEBUG
15 MODULE__TRACE
16 */
17 #include "Client.h"
20 
21 
23 : m_repeat(0),
24 m_modRef(mRef),
25 m_shipRef(sRef),
26 m_chargeRef(InventoryItemRef(nullptr)),
27 m_ModuleState(Module::State::Unfitted),
28 m_ChargeState(Module::State::Unloaded),
29 m_linked(false),
30 m_linkMaster(false),
31 m_isWarpSafe(false),
32 m_overLoaded(false),
33 m_chargeLoaded(false),
34 m_hiPower(false),
35 m_medPower(false),
36 m_loPower(false),
37 m_rigSlot(false),
38 m_subSystem(false),
39 m_turret(false),
40 m_launcher(false)
41 {
42  if (mRef->type().HasEffect(EVEEffectID::loPower)) {
43  m_loPower = true;
44  } else if (mRef->type().HasEffect(EVEEffectID::medPower)) {
45  m_medPower = true;
46  } else if (mRef->type().HasEffect(EVEEffectID::hiPower)) {
47  m_hiPower = true;
49  m_turret = true;
50  } else if (mRef->type().HasEffect(EVEEffectID::launcherFitted)) {
51  m_launcher = true;
52  }
53  } else if (mRef->type().HasEffect(EVEEffectID::rigSlot)) {
54  m_rigSlot = true;
55  } else if (mRef->type().HasEffect(EVEEffectID::subSystem)) {
56  m_subSystem = true;
57  }
58 
59  _log(MODULE__DEBUG, "Created GenericModule %p for item %s (%u).", this, mRef->name(), mRef->itemID());
60 }
61 
63 {
64 
65 }
66 
67 // this function must NOT throw
68 // throwing an error negates further processing
70 {
71  if (m_shipRef->GetPilot()->IsDocked() and (!m_shipRef->IsUndocking())) {
74  return;
75  }
76 
78  _log(MODULE__ERROR, "GenericModule::Online() called for unfitted module %u(%s).",itemID(), m_modRef->name());
79  return;
80  }
82  _log(MODULE__MESSAGE, "GenericModule::Online() called for non-offline module %u(%s). State is %s", \
84  return; // already online
85  }
86 
88  m_shipRef->GetPilot()->SendNotifyMsg("Your %s is too damaged to be put online.", m_modRef->name());
89  return;
90  /*{'messageKey': 'ModuleTooDamagedToBeOnlined', 'dataID': 17878773, 'suppressable': False, 'bodyID': 257752, 'messageType': 'notify', 'urlAudio': '', 'urlIcon': '', 'titleID': None, 'messageID': 2303}
91  * u'ModuleTooDamagedToBeOnlinedBody'}(u'The module is too damaged to be onlined'
92  */
93  }
94  // check PG and CPU usage to see if we have enough to online this module
96  if (cpuNeed > m_shipRef->GetAttribute(AttrCpuOutput)) {
97  _log(MODULE__TRACE, "GenericModule::Online() %u(%s) - not enough CPU. (%.1f/%.1f)", \
98  itemID(), m_modRef->name(), cpuNeed.get_float(), m_shipRef->GetAttribute(AttrCpuOutput).get_float());
99  if (!m_shipRef->GetPilot()->IsLogin()) {
100  m_modRef->SetOnline(false, isRig());
101  float require(GetAttribute(AttrCpu).get_float());
103  float remaining(total - m_shipRef->GetAttribute(AttrCpuLoad).get_float());
104  std::string str = "To bring " + m_modRef->itemName() + " online requires %.2f cpu units, ";
105  str += "but only %.2f of the %.2f units that your computer produces are still available.";
106  m_shipRef->GetPilot()->SendNotifyMsg(str.c_str(), require, remaining, total);
107  }
108  return;
109  }
111  if (pgNeed > m_shipRef->GetAttribute(AttrPowerOutput)) {
112  _log(MODULE__TRACE, "GenericModule::Online() %u(%s) - not enough PG. (%.1f/%.1f)", \
113  itemID(), m_modRef->name(), pgNeed.get_float(), m_shipRef->GetAttribute(AttrPowerOutput).get_float());
114  if (!m_shipRef->GetPilot()->IsLogin()) {
115  m_modRef->SetOnline(false, isRig());
116  float require(GetAttribute(AttrPower).get_float());
118  float remaining(total - m_shipRef->GetAttribute(AttrPowerLoad).get_float());
119  std::string str = "To bring " + m_modRef->itemName() + " online requires %.2f power units, ";
120  str += "but only %.2f of the %.2f units that your power core produces are still available.";
121  m_shipRef->GetPilot()->SendNotifyMsg(str.c_str(), require, remaining, total);
122  }
123  return;
124  }
125 
126  m_modRef->SetOnline(true, isRig());
128  _log(MODULE__MESSAGE, "GenericModule::Online() - %u(%s) cpu: %.2f, pg: %.2f, loaded: %s", \
129  itemID(), m_modRef->name(), cpuNeed.get_float(), pgNeed.get_float(), m_ChargeState == Module::State::Loaded?"true":"false");
130 
134  if (!m_chargeLoaded) {
135  _log(MODULE__ERROR, "GenericModule::Online() - module %u(%s) has ChargeState(CHG_LOADED) but m_chargeLoaded = false.", \
136  itemID(), m_modRef->name());
137  } else if (m_chargeRef.get() == nullptr) {
138  _log(MODULE__ERROR, "GenericModule::Online() - module %u(%s) has ChargeState(CHG_LOADED) but m_chargeRef = NULL.", \
139  itemID(), m_modRef->name());
140  } else {
141  _log(MODULE__MESSAGE, "GenericModule::Online() - module %u(%s) loading charge fx for %s.", itemID(), m_modRef->name(), m_chargeRef->name());
142  for (auto it : m_chargeRef->type().m_stateFxMap) {
143  fxData data = fxData();
145  data.srcRef = m_chargeRef;
146  sFxProc.ParseExpression(m_modRef.get(), sFxDataMgr.GetExpression(it.second.preExpression), data, this);
147  }
148  }
149  }
150 
151  // update available ship resources.
155 }
156 
158 {
159  if (m_shipRef->GetPilot()->IsDocked()) {
162  return;
163  }
164 
165  //if (m_shipRef->GetPilot()->GetShipSE()->IsDead()) // SE->IsDead() for all SEs
166  if (m_shipRef->IsPopped()) // only for player ships
167  return;
168 
169  switch(m_ModuleState) {
171  m_modRef->SetOnline(false, isRig());
172  _log(MODULE__WARNING, "GenericModule::Offline() called for unfitted module %u(%s).",itemID(), m_modRef->name());
173  return;
174  }
175  case Module::State::Offline: {
176  m_modRef->SetOnline(false, isRig());
177  _log(MODULE__WARNING, "GenericModule::Offline() called for offline module %u(%s).",itemID(), m_modRef->name());
178  return;
179  }
180  // these two should only be called for activeModules...
182  _log(MODULE__MESSAGE, "GenericModule::Offline() called for deactivating module %u(%s).",itemID(), m_modRef->name());
183  if (IsActiveModule())
185  }
187  _log(MODULE__MESSAGE, "GenericModule::Offline() called for active module %u(%s).",itemID(), m_modRef->name());
188  if (IsActiveModule())
190  }
191  }
192 
194 
195  /* code for offlining module before MOD_OFFLINE state is set. */
200 
201  _log(MODULE__MESSAGE, "GenericModule::Offline() - %u(%s) cpu: %.2f, pg: %.2f",itemID(), m_modRef->name(), cpuNeed.get_float(), pgNeed.get_float());
202 
204  if (m_chargeRef.get() == nullptr) {
205  _log(MODULE__ERROR, "GenericModule::Offline() - module %u(%s) has ChargeState(CHG_LOADED) but m_chargeRef = NULL.", \
206  itemID(), m_modRef->name());
207  } else {
208  for (auto it : m_chargeRef->type().m_stateFxMap) {
209  fxData data = fxData();
211  data.srcRef = m_chargeRef;
212  sFxProc.ParseExpression(m_modRef.get(), sFxDataMgr.GetExpression(it.second.postExpression), data, this);
213  }
214  }
215  }
216 
219  sFxProc.ApplyEffects(m_modRef.get(), m_shipRef->GetPilot()->GetChar().get(), m_shipRef.get(), true);
220 
222  m_modRef->SetOnline(false, isRig());
223 }
224 
226 {
228  sFxProc.ApplyEffects(m_modRef.get(), m_shipRef->GetPilot()->GetChar().get(), m_shipRef.get(), true);
229  //m_modRef->ClearModifiers();
230 }
231 
233 {
235  sFxProc.ApplyEffects(m_modRef.get(), m_shipRef->GetPilot()->GetChar().get(), m_shipRef.get(), true);
236  //m_modRef->ClearModifiers();
237 }
238 
239 void GenericModule::ProcessEffects(int8 state, bool active/*false*/)
240 {
241  // get module/charge pre/post effects in state x
242  std::map<uint16, Effect> effectMap;
243  m_modRef->type().GetEffectMap(state, effectMap);
244  _log(EFFECTS__TRACE, "GenericModule::ProcessEffects() called for %s. effects: %u, state: %s, online: %s", \
245  m_modRef->name(), effectMap.size(), sFxProc.GetStateName(state), (active ? "true" : "false"));
246  for (auto it : effectMap) {
247  if (it.first == 16) // skip the online effect. this is done internally elsewhere
248  continue;
249  fxData data = fxData();
251  data.srcRef = m_modRef;
252  /* module and charge effects will be added/removed from it's item
253  * active/overload/gang/other effects will be applied and removed when called.
254  */
255  if (active) {
256  sFxProc.ParseExpression(m_modRef.get(), sFxDataMgr.GetExpression(it.second.preExpression), data, this);
257  } else {
258  sFxProc.ParseExpression(m_modRef.get(), sFxDataMgr.GetExpression(it.second.postExpression), data, this);
259  }
260  }
261 }
262 
263 // not used
265 {
266  if (GetAttribute(AttrDamage) > 0) {
267  EvilNumber newAmount = GetAttribute(AttrDamage) - amount;
268  if (newAmount < EvilZero)
269  newAmount = EvilZero;
270  SetAttribute(AttrDamage, newAmount);
271  }
272  _log(MODULE__DAMAGE, "GenericModule::Repair() - %s repaired %u damage. new damage %u", m_modRef->name(), amount, GetAttribute(AttrDamage).get_int());
273 }
274 
276 {
277  using namespace Module;
278  switch(state) {
279  case State::Unloaded: return "Unloaded";
280  case State::Loaded: return "Loaded";
281  case State::Loading: return "Loading";
282  case State::Reloading: return "Reloading";
283  case State::Unfitted: return "Unfitted";
284  case State::Offline: return "Offline";
285  case State::Online: return "Online";
286  case State::Activated: return "Activated";
287  case State::Deactivating: return "Deactivating";
288  default: return "Invalid";
289  }
290 }
291 
293  {
294  if (m_hiPower) {
295  return Module::Bank::High;
296  } else if (m_medPower) {
297  return Module::Bank::Mid;
298  } else if (m_loPower) {
299  return Module::Bank::Low;
300  } else if (m_rigSlot) {
301  return Module::Bank::Rig;
302  } else if (m_subSystem) {
304  } else {
306  }
307  }
308 }
bool IsLogin()
Definition: Client.h:235
void GetEffectMap(const int8 state, std::map< uint16, Effect > &effectMap) const
Definition: ItemType.cpp:217
#define _log(type, fmt,...)
Definition: logsys.h:124
void ProcessEffects(int8 state, bool active=false)
virtual void DeOverload()
void SetOnline(bool online=false, bool isRig=false)
Definition: ModuleItem.cpp:57
bool HasEffect(uint16 effectID) const
Definition: ItemType.cpp:208
this is a class that kinda mimics how python polymorph's numbers.
Definition: EvilNumber.h:59
const char * name()
InventoryItemRef srcRef
Definition: EffectsData.h:78
void SendNotifyMsg(const char *fmt,...)
Definition: Client.cpp:2776
CharacterRef GetChar() const
Definition: Client.h:164
void SetAttribute(uint32 attrID, EvilNumber val, bool update=true)
Definition: GenericModule.h:51
uint32 itemID()
Definition: GenericModule.h:97
std::unordered_multimap< int8, Effect > m_stateFxMap
Definition: ItemType.h:154
signed __int8 int8
Definition: eve-compat.h:45
ModuleItemRef m_modRef
EvilNumber EvilZero
Definition: EvilNumber.cpp:32
virtual ~GenericModule()
const ItemType & type() const
ShipItemRef m_shipRef
int64 get_int()
Definition: EvilNumber.cpp:166
bool IsDocked()
Definition: Client.h:229
InventoryItemRef m_chargeRef
#define sFxDataMgr
virtual void Overload()
void SetAttribute(uint16 attrID, int num, bool notify=true)
X * get() const
Definition: RefPtr.h:213
virtual void AbortCycle()
const char * GetModuleStateName(int8 state)
int8 GetModulePowerLevel()
uint8 action
Definition: EffectsData.h:73
bool IsPopped()
Definition: Ship.h:89
#define sFxProc
bool IsUndocking()
Definition: Ship.h:149
const std::string & itemName() const
virtual Client * GetPilot()
Definition: Ship.h:72
GenericModule(ModuleItemRef mRef, ShipItemRef sRef)
EvilNumber GetAttribute(const uint16 attrID) const
EvilNumber EvilOne
Definition: EvilNumber.cpp:34
float get_float()
Definition: EvilNumber.cpp:184
virtual ActiveModule * GetActiveModule()
Definition: GenericModule.h:60
entityID heal the character with the entityID note giving you detailed ship status information gives a list of all dynamic entities and players and their destinyState in this bubble shows some current destiny variables save all kick all and halt server immediate command list all items in current location s gives list of cargo contents and volumes in all holds list current session values show current ship DNA show current objects in their destiny state
EvilNumber GetAttribute(uint32 attrID)
Definition: GenericModule.h:53
virtual bool IsActiveModule() const
Definition: GenericModule.h:72
uint32 itemID() const
Definition: InventoryItem.h:98