EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Tower.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 
22 #include "Client.h"
23 #include "EntityList.h"
24 #include "EVEServerConfig.h"
25 #include "planet/Moon.h"
26 #include "pos/Tower.h"
27 #include "system/Container.h"
28 #include "system/Damage.h"
29 #include "system/SystemBubble.h"
30 #include "system/SystemManager.h"
31 
106 : StructureSE(structure, services, system, fData),
107 m_pShieldSE(nullptr)
108 {
109  m_hasShield = false;
110  m_structs.clear();
111 
112  // create AI object for tower here....not written yet.
113  //m_ai = new POS_AI(this);
114 
117 
119  if ((m_tsize < 1) or (m_tsize > 3))
120  m_tsize = 1; // do something constructive here cause size is wrong
122 
123 
125 
134 }
135 
137 {
139 
140  if (!m_db.GetTowerData(m_tdata, m_data)) {
141  _log(SE__TRACE, "TowerSE %s(%u) has no saved data. Initializing default set.", m_self->name(), m_self->itemID());
142  // invalid data....init to 0 as this will only hit for currently-launching items (or errors)
143  InitData();
144  }
145 
146  // if password is already set and tower online, then we can online (create) the forcefield
149  and (!m_tdata.password.empty())
152 
153  // if tower anchored, tell moon this is its tower
155  m_moonSE->SetTower(this);
156 
157  // set tower in bubble
158  if (m_bubble == nullptr)
159  assert(0);
160  m_bubble->SetTowerSE(this);
161 
171  // take resources, move items, process reactions or whatever needs to be done (follow PI proc code)
172 
173 }
174 
176  // init base data first
178  m_tdata.harmonic = m_harmonic; // set during base SE creation
182 }
183 
186  m_moonSE->SetTower(nullptr);
188  m_self->ChangeSingleton(false);
189  m_self->SaveItem();
190 }
191 
193 {
194  /* called by EntityList::Process on every loop */
195 
196  // starbase charter checks for empire space
197 
198  // tower-specific tests here
199 
200  /* Enable base call to Process Anchoring, Targeting and Movement */
202 }
203 
204 /*
205  * 473 prototypingBonus 250000 NULL
206  * 556 anchoringDelay 1800000 NULL
207  * 650 maxStructureDistance 50000 NULL
208  * 676 unanchoringDelay NULL 3600000
209  * 677 onliningDelay 1800000 NULL
210  * 680 shieldRadius 30000 NULL
211  * 711 moonAnchorDistance 100000 NULL
212  * 1214 posStructureControlDistanceMax NULL 15000
213  */
214 
216 {
217  //StructureSE::SetOnline();
218 
226 
228  and (!m_tdata.password.empty()))
230 
231  SendSlimUpdate();
232  m_destiny->SendSpecialEffect(m_self->itemID(),m_self->itemID(),m_self->typeID(),0,0,"effects.StructureOnline",0,1,1,-1,0);
233 
235 
248 }
249 
251 {
252  if (m_hasShield) {
253  m_pShieldSE->Delete();
255  m_hasShield = false;
256  }
257 
259 }
260 
261 
263 {
264  // structure online, but not operating
265  // take resources or whatever needs to be done
266  /*
267  * 1031 controlTowerSize 3 NULL
268  *
269  * POS fuel usage per hour
270  * Fuel blocks s:10 m:20 l:40
271  */
272 
273  // if fuel has run out, start reinforced mode.
274 
275 
276  // reset timers
278 
279 }
280 
282 {
283  // structure operating
284  // take resources or whatever needs to be done
285 
286  //1031 controlTowerSize 3
287 
288  // if fuel has run out, start reinforced mode.
289 
290  // reset timers
292 
293 }
294 
296 {
297  // see how many stront is in tower and set timer accordingly
298  // Strontium Clathrates s:100 m:200 l:400
299 
300 }
301 
303 {
304  // dunno what to do here yet.
305 
306 }
307 
309 {
310  if (m_tdata.password.empty()) {
313  if (m_pShieldSE == nullptr)
314  return;
315 
317 
318  // this is for UPDATING forcefield ONLY...do not send on creation.
319  std::vector<PyTuple*> updates;
320  // 'massive' enables client-side bounce
321  SetBallMassive sbm;
322  sbm.entityID = m_pShieldSE->GetSelf()->itemID();
323  sbm.is_massive = false; // disable client-side bump checks
324  updates.push_back(sbm.Encode());
325  // harmonic for ForceField
326  SetBallHarmonic sbh;
327  sbh.itemID = m_pShieldSE->GetSelf()->itemID();
328  sbh.corpID = m_corpID;
329  sbh.allianceID = m_allyID;
330  sbh.mass = -1; // always -1
331  sbh.harmonic = m_harmonic;
332  updates.push_back(sbh.Encode());
333  m_destiny->SendDestinyUpdate(updates); //consumed
334  } else {
337 
340  }
341 
343 }
344 
345 void TowerSE::SetDeployFlags(int8 anchor/*0*/, int8 unanchor/*0*/, int8 online/*0*/, int8 offline/*0*/)
346 {
347  m_tdata.anchor = anchor;
348  m_tdata.unanchor = unanchor;
349  m_tdata.online = online;
350  m_tdata.offline = offline;
351 
353 }
354 
356 {
357  PyList* header = new PyList(4);
358  header->SetItemString(0, "anchor");
359  header->SetItemString(1, "unanchor");
360  header->SetItemString(2, "online");
361  header->SetItemString(3, "offline");
362  PyList* line = new PyList(4); // these are structure permissions for this tower
363  line->SetItem(0, new PyInt(m_tdata.anchor));
364  line->SetItem(1, new PyInt(m_tdata.unanchor));
365  line->SetItem(2, new PyInt(m_tdata.online));
366  line->SetItem(3, new PyInt(m_tdata.offline));
367 
368  PyDict* dict = new PyDict();
369  dict->SetItemString("header", header);
370  dict->SetItemString("line", line);
371 
372  return new PyObject("util.Row", dict);
373 }
374 
375 void TowerSE::SetUseFlags(uint32 itemID, int8 view, int8 take, int8 use/*0*/)
376 {
377  std::map<uint32, StructureSE*>::iterator itr = m_structs.find(itemID);
378  if (itr != m_structs.end()) {
379  itr->second->SetUsageFlags(view, take, use);
380  itr->second->UpdateUsageFlags();
381  }
382 }
383 
385 {
386  /*
387  [PyObject Name: eve.common.script.sys.rowset.Rowset]
388  [PyDict 3 kvp]
389  Key:[PyString "header"]
390  ==Value:[PyList 4 items]
391  [PyString "structureID"]
392  [PyString "viewput"]
393  [PyString "viewputtake"]
394  [PyString "use"]
395  Key:[PyString "RowClass"]
396  ==Value:[PyToken carbon.common.script.sys.row.Row]
397  Key:[PyString "lines"]
398  ==Value:[PyList 1 items]
399  [PyList 4 items]
400  [PyIntegerVar 1010759458081]
401  [PyInt 3]
402  [PyInt 0]
403  [PyInt 0]
404  */
405 
406  PyList* header = new PyList(4);
407  header->SetItemString(0, "structureID");
408  header->SetItemString(1, "viewput");
409  header->SetItemString(2, "viewputtake");
410  header->SetItemString(3, "use");
411  PyList* lines = new PyList();
412  for (auto cur : m_structs) {
413  PyList* line = new PyList(4);
414  line->SetItem(0, new PyInt(cur.first));
415  line->SetItem(1, new PyInt(cur.second->CanView()));
416  line->SetItem(2, new PyInt(cur.second->CanTake()));
417  line->SetItem(3, new PyInt(cur.second->CanUse()));
418  lines->AddItem(line);
419  }
420 
421  PyDict* dict = new PyDict();
422  dict->SetItemString("header", header);
423  dict->SetItemString("RowClass", new PyToken("util.Row"));
424  dict->SetItemString("lines", lines);
425 
426  return new PyObject("util.Rowset", dict);
427 }
428 
430 {
431  /*
432  info = self.posMgr.GetMoonProcessInfoForTower(self.slimItem.itemID)
433  itemID, active, reaction, connections, demands, supplies in info:
434 
435  if reaction and rec.groupID == const.groupMobileReactor and not demands and not supplies:
436  demands = [ (row.typeID, row.quantity) for row in cfg.invtypereactions[reaction[1]] if row.input == 1 ]
437  supplies = [ (row.typeID, row.quantity) for row in cfg.invtypereactions[reaction[1]] if row.input == 0 ]
438  demand = {}
439  demands = demands or []
440  for tID, quant in demands:
441  demand[tID] = quant
442 
443  supply = {}
444  supplies = supplies or []
445  for tID, quant in supplies:
446  supply[tID] = quant
447 
448  for sourceID, tID in connections:
449  self.sr.structureConnections[tID, sourceID] = itemID
450 
451  [PyList 2 items]
452  [PyTuple 6 items]
453  [PyIntegerVar 1002332982210]
454  [PyBool False]
455  [PyNone]
456  [PyList 0 items]
457  [PyList 0 items]
458  [PyList 0 items]
459  [PyTuple 6 items]
460  [PyIntegerVar 1002331680835]
461  [PyBool False]
462  [PyNone]
463  [PyList 0 items]
464  [PyList 0 items]
465  [PyList 0 items]
466  */
467 
468  PyList* list = new PyList();
469  for (auto cur : m_structs) {
470  switch (cur.second->GetSelf()->groupID()) {
474  PyTuple* tuple = new PyTuple(6);
475  tuple->SetItem(0, new PyInt(cur.first));
476  tuple->SetItem(1, new PyBool(false));
477  tuple->SetItem(2, PyStatic.NewNone());
478  tuple->SetItem(3, new PyList());
479  tuple->SetItem(4, new PyList());
480  tuple->SetItem(5, new PyList());
481  list->AddItem(tuple);
482  }
483  }
484  }
485 
486  if (is_log_enabled(POS__RSP_DUMP))
487  list->Dump(POS__RSP_DUMP, " ");
488  return list;
489 }
490 
492 {
493  if (m_hasShield)
494  return;
495  // create and add force field to tower
497  InventoryItemRef ifRef = sItemFactory.SpawnItem(idata);
498  if (ifRef.get() == nullptr)
499  return; // we'll get over it
500  ifRef->SetPosition(GetPosition());
501  ifRef->SetAttribute(AttrRadius, m_self->GetAttribute(AttrShieldRadius));
502  FactionData data = FactionData();
503  data.allianceID = m_allyID;
504  data.corporationID = m_corpID;
505  data.factionID = m_warID;
506  data.ownerID = m_ownerID;
507  FieldSE* iSE = new FieldSE(ifRef, m_services, m_system, data);
508  // set shield harmonic to tower harmonic
509  iSE->SetHarmonic(m_harmonic);
510  m_system->AddEntity(iSE);
511  m_pShieldSE = iSE;
512  m_hasShield = true;
513 }
514 
516 {
517  _log(SE__SLIMITEM, "MakeSlimItem for TowerSE %u", m_self->itemID());
518  _log(POS__SLIMITEM, "MakeSlimItem for TowerSE %u", m_self->itemID());
519 
520  PyDict *slim = new PyDict();
521  slim->SetItemString("name", new PyString(m_self->itemName()));
522  slim->SetItemString("itemID", new PyLong(m_self->itemID()));
523  slim->SetItemString("typeID", new PyInt(m_self->typeID()));
524  slim->SetItemString("ownerID", new PyInt(m_ownerID));
525  slim->SetItemString("corpID", IsCorp(m_corpID) ? new PyInt(m_corpID) : PyStatic.NewNone());
526  slim->SetItemString("allianceID", IsAlliance(m_allyID) ? new PyInt(m_allyID) : PyStatic.NewNone());
527  slim->SetItemString("warFactionID", IsFaction(m_warID) ? new PyInt(m_warID) : PyStatic.NewNone());
528  slim->SetItemString("posTimestamp", new PyLong(m_data.timestamp));
529  slim->SetItemString("posState", new PyInt(m_data.state));
530  slim->SetItemString("incapacitated", new PyInt((m_data.state == EVEPOS::StructureState::Incapacitated) ? 1 : 0));
531  slim->SetItemString("posDelayTime", new PyInt(m_delayTime));
532 
533  if (is_log_enabled(POS__SLIMITEM)) {
534  _log( POS__SLIMITEM, "TowerSE::MakeSlimItem() - %s(%u)", GetName(), GetID());
535  slim->Dump(POS__SLIMITEM, " ");
536  }
537  return slim;
538 }
539 /*
540  [PyString "OnSlimItemChange"]
541  [PyTuple 2 items]
542  [PyIntegerVar 1006120578679]
543  [PyObjectData Name: foo.SlimItem]
544  [PyDict 11 kvp]
545  [PyString "itemID"]
546  [PyIntegerVar 1006120578679]
547  [PyString "typeID"]
548  [PyInt 20060] <<-- Amarr Control Tower Small
549  [PyString "name"]
550  [PyString "Pix0r monto la torre de al lado"]
551  [PyString "incapacitated"]
552  [PyFloat 0]
553  [PyString "posTimestamp"]
554  [PyIntegerVar 129773067243437304]
555  [PyString "posState"]
556  [PyInt 4]
557  [PyString "warFactionID"]
558  [PyNone]
559  [PyString "allianceID"]
560  [PyInt 99001691]
561  [PyString "corpID"]
562  [PyInt 717154310]
563  [PyString "ownerID"]
564  [PyInt 717154310]
565  [PyString "nameID"]
566  [PyNone]
567  */
568 
569 /*
570  * def IsShipInRangeOfStructureControlTower(self, shipID, structureID):
571  * """
572  * Returns True if structureID is associated with a control tower (or is itself a tower), and shipID is in range of that tower.
573  * 'In range of the tower' means within of the force-field radius.
574  * This function should mirror the behaviour of the equivalent server-side function in park.py
575  * """
576  * structureSlim = self.slimItems.get(structureID)
577  * if structureSlim is None:
578  * return False
579  * controlTowerID = None
580  * if structureSlim.groupID == const.groupControlTower:
581  * controlTowerID = structureID
582  * elif structureSlim.controlTowerID is not None:
583  * controlTowerID = structureSlim.controlTowerID
584  * if controlTowerID is None:
585  * return False
586  * towerSlim = self.slimItems.get(controlTowerID)
587  * if towerSlim is None:
588  * return False
589  * towerShieldRadius = self.broker.godma.GetStateManager().GetType(towerSlim.typeID).shieldRadius
590  * return self.GetCenterDist(controlTowerID, shipID) < towerShieldRadius
591  */
Base Python wire object.
Definition: PyRep.h:66
void AddEntity(SystemEntity *pSE, bool addSignal=true)
float m_cpu
Definition: Tower.h:131
int32 standingOwnerID
Definition: EVE_POS.h:53
void SetTimer(uint32 time)
Definition: Structure.h:178
virtual void InitData()
Definition: Tower.cpp:175
#define _log(type, fmt,...)
Definition: logsys.h:124
Python string.
Definition: PyRep.h:430
int32 harmonic
Definition: EVE_POS.h:52
DestinyManager * m_destiny
Definition: SystemEntity.h:265
Python's dictionary.
Definition: PyRep.h:719
virtual void Scoop()
Definition: Tower.cpp:184
virtual void Online()
Definition: Tower.cpp:262
uint32 m_ownerID
Definition: SystemEntity.h:283
bool SetFlag(EVEItemFlags flag, bool notify=false)
void UpdateBaseData(EVEPOS::StructureData &data)
Definition: PosMgrDB.cpp:132
uint32 m_delayTime
Definition: Structure.h:217
void ReinforceTower()
Definition: Tower.cpp:295
virtual void Operating()
Definition: Tower.cpp:281
void SetItemString(size_t index, const char *str)
Stores Python string.
Definition: PyRep.h:699
uint16 m_soi
Definition: Tower.h:133
void UpdateDeployFlags(int32 itemID, EVEPOS::TowerData &data)
Definition: PosMgrDB.cpp:456
SystemBubble * m_bubble
Definition: SystemEntity.h:262
void SendDestinyUpdate(std::vector< PyTuple * > &updates, bool self_only=false) const
virtual void SetOnline()
Definition: Tower.cpp:215
PyServiceMgr & m_services
Definition: SystemEntity.h:267
virtual void Process()
Definition: Tower.cpp:192
uint32 GetID() const
Definition: SystemManager.h:80
int8 m_procState
Definition: Structure.h:214
PyRep * GetDeployFlags()
Definition: Tower.cpp:355
void CreateForceField()
Definition: Tower.cpp:491
const char * name()
Python tuple.
Definition: PyRep.h:567
virtual void Init()
Definition: Tower.cpp:136
int32 m_harmonic
Definition: SystemEntity.h:276
void Dump(FILE *into, const char *pfx) const
Dumps object to file.
Definition: PyRep.cpp:84
signed __int8 int8
Definition: eve-compat.h:45
const GPoint & GetPosition() const
Definition: SystemEntity.h:211
void UpdatePassword()
Definition: Tower.cpp:308
void AddItem(PyRep *i)
Definition: PyRep.h:701
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
virtual void Delete()
Python boolean.
Definition: PyRep.h:323
#define is_log_enabled(type)
Definition: logsys.h:78
std::map< uint32, StructureSE * > m_structs
Definition: Tower.h:135
void SendSpecialEffect(uint32 entityID, uint32 moduleID, uint32 moduleTypeID, uint32 targetID, uint32 chargeTypeID, std::string guid, bool isOffensive, bool start, bool isActive, int32 duration, uint32 repeat, int32 graphicInfo=0) const
std::string password
Definition: EVE_POS.h:56
InventoryItemRef m_self
Definition: SystemEntity.h:269
InventoryItemRef GetSelf()
Definition: SystemEntity.h:202
Python object.
Definition: PyRep.h:826
uint32 m_corpID
Definition: SystemEntity.h:281
int64 get_int()
Definition: EvilNumber.cpp:166
void SetItem(size_t index, PyRep *object)
Stores Python object.
Definition: PyRep.h:610
Python integer.
Definition: PyRep.h:231
void SetItem(size_t index, PyRep *object)
Stores Python object.
Definition: PyRep.h:682
bool GetTowerData(EVEPOS::TowerData &tData, EVEPOS::StructureData &sData)
Definition: PosMgrDB.cpp:140
SystemManager * m_system
Definition: SystemEntity.h:263
uint32 GetID()
Definition: SystemEntity.h:207
#define PyStatic
Definition: PyRep.h:1209
void SaveTowerData(EVEPOS::TowerData &tData, EVEPOS::StructureData &sData)
Definition: PosMgrDB.cpp:178
TowerSE(StructureItemRef structure, PyServiceMgr &services, SystemManager *system, const FactionData &fData)
Definition: Tower.cpp:105
virtual void InitData()
Definition: Structure.cpp:240
const char * GetName() const
Definition: SystemEntity.h:210
EVEPOS::StructureData m_data
Definition: Structure.h:212
virtual void Online()
Definition: Structure.cpp:918
bool ChangeSingleton(bool singleton, bool notify=false)
virtual void Process()
Definition: Structure.cpp:458
unsigned __int32 uint32
Definition: eve-compat.h:50
virtual void Reinforced()
Definition: Tower.cpp:302
uint32 corporationID
virtual void Scoop()
Definition: Structure.cpp:449
#define IsCorp(itemID)
Definition: EVE_Defines.h:234
virtual void SetOffline()
Definition: Structure.cpp:888
Python token (eg. class name).
Definition: PyRep.h:522
double GetFileTimeNow()
Definition: utils_time.cpp:84
virtual PyDict * MakeSlimItem()
Definition: Tower.cpp:515
EVEPOS::TowerData m_tdata
Definition: Tower.h:118
const std::string & itemName() const
void SetTowerSE(TowerSE *pTower)
Definition: SystemBubble.h:143
void SendSlimUpdate()
Definition: Structure.cpp:966
EvilNumber GetAttribute(const uint16 attrID) const
typeID Spawn an NPC with the specified type text Search for items matching the specified query() type()() itemID() copy() materialLevel()() itemID(attributeID)-Retrieves attribute value." ) COMMAND( setattr
#define IsFaction(itemID)
Definition: EVE_Defines.h:250
MoonSE * m_moonSE
Definition: Structure.h:203
virtual void Operating()
Definition: Structure.cpp:945
void SetTower(StructureSE *pSE)
Definition: Moon.h:47
bool m_hasShield
Definition: Tower.h:126
void SetDeployFlags(int8 anchor=0, int8 unanchor=0, int8 online=0, int8 offline=0)
Definition: Tower.cpp:345
void SetUseFlags(uint32 itemID, int8 view=0, int8 take=0, int8 use=0)
Definition: Tower.cpp:375
PyRep * GetUsageFlagList()
Definition: Tower.cpp:384
void UpdateHarmonicAndPassword(int32 itemID, EVEPOS::TowerData &data)
Definition: PosMgrDB.cpp:430
float m_pg
Definition: Tower.h:130
#define sItemFactory
Definition: ItemFactory.h:165
#define IsAlliance(itemID)
Definition: EVE_Defines.h:244
SystemEntity * m_pShieldSE
Definition: Tower.h:120
PosMgrDB m_db
Definition: Structure.h:201
virtual void SetOffline()
Definition: Tower.cpp:250
void SetHarmonic(int8 set)
Definition: SystemEntity.h:224
uint16 typeID() const
int8 m_tsize
Definition: Tower.h:128
Python list.
Definition: PyRep.h:639
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
PyRep * GetProcessInfo()
Definition: Tower.cpp:429
Python long integer.
Definition: PyRep.h:261
Reference-counting-based smart pointer.
Definition: RefPtr.h:133