EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SBU.cpp
Go to the documentation of this file.
1 
10 /*
11  * POS__ERROR
12  * POS__WARNING
13  * POS__MESSAGE
14  * POS__DUMP
15  * POS__DEBUG
16  * POS__DESTINY
17  * POS__SLIMITEM
18  * POS__TRACE
19  */
20 
21 #include "Client.h"
22 #include "EntityList.h"
23 #include "EVEServerConfig.h"
24 #include "planet/Planet.h"
25 #include "pos/sovStructures/SBU.h"
26 #include "pos/sovStructures/TCU.h"
27 #include "system/Container.h"
28 #include "system/Damage.h"
29 #include "system/SystemBubble.h"
30 #include "system/SystemManager.h"
32 
34  : StructureSE(structure, services, system, fData)
35 {
36 }
37 
39 {
40  _log(SE__TRACE, "SBUSE %s(%u) is being initialised", m_self->name(), m_self->itemID());
42 
43  // check for valid bubble
44  if (m_bubble == nullptr)
45  assert(0);
46  m_bubble->SetSBUSE(this);
47 
48  // set global attribute
50 }
51 
53 {
54  _log(SOV__DEBUG, "Onlining SBU...");
55 
56  // Ensure the SBU is online before we check the ratio
58 
59  // If more than 50 percent of gates have an SBU, the TCU should be vulnerable
60  if ((GetSBUs() / GetGates()) > 0.5)
61  {
62  _log(SOV__DEBUG, "- STATE CHANGE - This system has %u SBUs installed in the total of %u stargates. The TCU is now vulnerable to attack.", (int)GetSBUs(), (int)GetGates());
63  // Make the TCU vulnerable
64  for (auto cur : m_system->GetOperationalStatics())
65  {
66  if (cur.second->IsTCUSE())
67  {
68  cur.second->GetTCUSE()->SetVulnerable();
69  }
70  }
71  // Mark the system as contested
72  MarkContested(m_system->GetID(), true);
73  }
74  else
75  {
76  _log(SOV__DEBUG, "This system has %u SBUs installed in the total of %u stargates. The TCU is invulnerable.", (int)GetSBUs(), (int)GetGates());
77  }
78 }
79 
81 {
82  // Ensure that the SBU is offline before we check ratio
84 
85  if ((GetSBUs() / GetGates()) <= 0.5)
86  {
87  _log(SOV__DEBUG, "- STATE CHANGE - This system has %u SBUs installed in the total of %u stargates. The TCU is no longer vulnerable to attack.", (int)GetSBUs(), (int)GetGates());
88  // Make the TCU invulnerable
89  for (auto cur : m_system->GetOperationalStatics())
90  {
91  if (cur.second->IsTCUSE())
92  {
93  cur.second->GetTCUSE()->SetOnline();
94  }
95  }
96  // Unmark the system as contested
97  MarkContested(m_system->GetID(), false);
98  }
99  else
100  {
101  _log(SOV__DEBUG, "This system has %u SBUs installed in the total of %u stargates. The TCU is vulnerable.", (int)GetSBUs(), (int)GetGates());
102  }
103 }
104 
106 {
108 }
109 
110 void SBUSE::MarkContested(uint32 systemID, bool contested)
111 {
112  //Send ProcessSovStatusChanged Notification
113  PyDict *args = new PyDict;
114  _log(SOV__DEBUG, "SBUSE::MarkContested(): Sending ProcessSovStatusChanged for %u", systemID);
115 
116  //Update datamgr records with new contested state
117  svDataMgr.MarkContested(systemID, contested);
118 
119  //Get the new sov data so we can send it to the client in a notification
120  SovereigntyData sovData = svDataMgr.GetSovereigntyData(systemID);
121 
122  args->SetItemString("corporationID", new PyInt(sovData.corporationID));
123  args->SetItemString("claimTime", new PyLong(sovData.claimTime));
124  args->SetItemString("claimStructureID", new PyInt(sovData.claimStructureID));
125  args->SetItemString("hubID", new PyInt(sovData.hubID));
126  args->SetItemString("allianceID", new PyInt(sovData.allianceID));
127  args->SetItemString("contested", new PyInt(int(contested)));
128  args->SetItemString("solarSystemID", new PyInt(systemID));
129 
130  PyTuple *data = new PyTuple(2);
131  data->SetItem(0, new PyInt(systemID));
132  data->SetItem(1, new PyObject("util.KeyVal", args));
133 
134  std::vector<Client *> list;
135  sEntityList.GetClients(list);
136  for (auto cur : list)
137  {
138  if (cur->GetChar().get() != nullptr)
139  {
140  cur->SendNotification("ProcessSovStatusChanged", "clientID", &data);
141  _log(SOV__DEBUG, "ProcessSovStatusChanged sent to client %u", cur->GetClientID());
142  }
143  }
144 }
145 
146 // Calculate number of gates in the system
148 {
149  return (float)m_system->GetGates().size();
150 }
151 
152 // Calculate number of SBUs in the system
154 {
155  int numberOfSBUs = 0;
156  for (auto cur : m_system->GetOperationalStatics())
157  {
158  if (cur.second->IsSBUSE())
159  {
160  //Only increment the number of SBUs if they are online
161  if (cur.second->GetSBUSE()->GetState() == EVEPOS::StructureState::Online)
162  {
163  numberOfSBUs++;
164  }
165  }
166  }
167  return (float)numberOfSBUs;
168 }
#define _log(type, fmt,...)
Definition: logsys.h:124
std::map< uint32, SystemEntity * > GetGates()
Python's dictionary.
Definition: PyRep.h:719
float GetSBUs()
Definition: SBU.cpp:153
SystemBubble * m_bubble
Definition: SystemEntity.h:262
#define sEntityList
Definition: EntityList.h:208
uint32 GetID() const
Definition: SystemManager.h:80
virtual void SetOffline()
Definition: SBU.cpp:80
virtual void SetOnline()
Definition: Structure.cpp:869
const char * name()
Python tuple.
Definition: PyRep.h:567
void MarkContested(uint32 systemID, bool contested)
Definition: SBU.cpp:110
* args
virtual void SetOnline()
Definition: SBU.cpp:52
InventoryItemRef m_self
Definition: SystemEntity.h:269
Python object.
Definition: PyRep.h:826
SBUSE(StructureItemRef structure, PyServiceMgr &services, SystemManager *system, const FactionData &fData)
Definition: SBU.cpp:33
void SetItem(size_t index, PyRep *object)
Stores Python object.
Definition: PyRep.h:610
Python integer.
Definition: PyRep.h:231
void SetSBUSE(SBUSE *pSBU)
Definition: SystemBubble.h:152
SystemManager * m_system
Definition: SystemEntity.h:263
virtual void Process()
Definition: SBU.cpp:105
void SetAttribute(uint16 attrID, int num, bool notify=true)
virtual void Init()
Definition: SBU.cpp:38
virtual void Process()
Definition: Structure.cpp:458
unsigned __int32 uint32
Definition: eve-compat.h:50
virtual void SetOffline()
Definition: Structure.cpp:888
std::map< uint32, SystemEntity * > GetOperationalStatics()
EvilNumber EvilOne
Definition: EvilNumber.cpp:34
#define svDataMgr
float GetGates()
Definition: SBU.cpp:147
virtual void Init()
Definition: Structure.cpp:275
uint32 itemID() const
Definition: InventoryItem.h:98
void SetItemString(const char *key, PyRep *value)
SetItemString adds or sets a database entry.
Definition: PyRep.h:812
Python long integer.
Definition: PyRep.h:261
Reference-counting-based smart pointer.
Definition: RefPtr.h:133