EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BeltMgr Class Reference

#include "BeltMgr.h"

Collaboration diagram for BeltMgr:

Public Member Functions

 ~BeltMgr ()
 

Protected Attributes

ManagerDB m_db
 
Timer m_respawnTimer
 

Private Attributes

SystemManagerm_system
 
PyServiceMgrm_services
 
bool m_initialized
 
uint32 m_systemID
 
uint32 m_regionID
 
std::map< uint32, bool > m_spawned
 
std::map< uint32, bool > m_active
 
std::map< uint32,
InventoryItemRef
m_belts
 
std::unordered_multimap
< uint32, AsteroidSE * > 
m_asteroids
 

BeltMgr.cpp

Asteroid Belt Spawn management system for EVEmu

: Allan

Date
: 15 April 2016
 BeltMgr (SystemManager *mgr, PyServiceMgr &svc)
 
void Init (uint32 regionID)
 
void Save ()
 
void Process ()
 
void ClearAll ()
 
void ClearBelt (uint16 bubbleID)
 
void SetActive (uint16 bubbleID, bool active=true)
 
void RegisterBelt (InventoryItemRef itemRef)
 
bool Create (CosmicSignature &sig, std::unordered_multimap< float, uint16 > &roidTypes)
 
bool Load (uint16 bubbleID)
 
bool IsActive (uint16 bubbleID)
 
bool IsSpawned (uint16 bubbleID)
 
void CheckSpawn (uint16 bubbleID)
 
void GetList (uint32 beltID, std::vector< AsteroidSE * > &list)
 
void RemoveAsteroid (uint32 beltID, AsteroidSE *pASE)
 
void SpawnBelt (uint16 bubbleID, std::unordered_multimap< float, uint16 > &roidTypes, int type=0, bool anomaly=false)
 
void SpawnAsteroid (uint32 beltID, uint32 typeID, double radius, const GPoint &position, bool ice=false)
 
void GetIceDist (uint8 quarter, float secStatus, std::unordered_multimap< float, uint16 > &roidDist)
 
uint32 GetAsteroidType (double p, const std::unordered_multimap< float, uint16 > &roids)
 

Detailed Description

Definition at line 34 of file BeltMgr.h.

Constructor & Destructor Documentation

BeltMgr::BeltMgr ( SystemManager mgr,
PyServiceMgr svc 
)
Note
roid save/load uses InventoryItem::Load(), which saves/reads from entity table, which we DONT want for roids. for now, save and load are disabled, roids are temp items, and use generic InventoryItem class. this will have to be revisited and corrected to properly implement persistent roids/belts

Definition at line 28 of file BeltMgr.cpp.

29 : m_respawnTimer(0),
30 m_system(mgr),
31 m_services(svc),
32 m_initialized(false)
33 {
34 }
PyServiceMgr & m_services
Definition: BeltMgr.h:70
SystemManager * m_system
Definition: BeltMgr.h:69
bool m_initialized
Definition: BeltMgr.h:72
Timer m_respawnTimer
Definition: BeltMgr.h:60
BeltMgr::~BeltMgr ( )
inline

Definition at line 38 of file BeltMgr.h.

38 { /* do nothing here */ }

Member Function Documentation

void BeltMgr::CheckSpawn ( uint16  bubbleID)

Definition at line 82 of file BeltMgr.cpp.

References IsSpawned(), Load(), and SpawnBelt().

Referenced by SystemBubble::Add().

83 {
84  if (IsSpawned(bubbleID))
85  return;
86  /* if there are already roids created for this belt, they will be loaded in Load()
87  * if Load() has roids for this belt, this belt will have true already set, and checked in SpawnBelt()
88  */
89  if (!Load(bubbleID)) {
90  std::unordered_multimap<float, uint16> roidTypes;
91  roidTypes.clear();
92  SpawnBelt(bubbleID, roidTypes);
93  }
94 }
bool Load(uint16 bubbleID)
Definition: BeltMgr.cpp:139
bool IsSpawned(uint16 bubbleID)
Definition: BeltMgr.cpp:96
void SpawnBelt(uint16 bubbleID, std::unordered_multimap< float, uint16 > &roidTypes, int type=0, bool anomaly=false)
Definition: BeltMgr.cpp:255

Here is the call graph for this function:

Here is the caller graph for this function:

void BeltMgr::ClearAll ( )

Definition at line 71 of file BeltMgr.cpp.

References m_asteroids, m_belts, m_system, SystemManager::RemoveEntity(), SafeDelete(), and Save().

Referenced by SystemManager::UnloadSystem().

71  {
72  Save();
73  for (auto cur : m_asteroids) {
74  m_system->RemoveEntity(cur.second);
75  //cur.second->Delete();
76  SafeDelete(cur.second);
77  }
78  m_asteroids.clear();
79  m_belts.clear();
80 }
void Save()
Definition: BeltMgr.cpp:187
std::map< uint32, InventoryItemRef > m_belts
Definition: BeltMgr.h:81
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
std::unordered_multimap< uint32, AsteroidSE * > m_asteroids
Definition: BeltMgr.h:83
SystemManager * m_system
Definition: BeltMgr.h:69
void RemoveEntity(SystemEntity *pSE)

Here is the call graph for this function:

Here is the caller graph for this function:

void BeltMgr::ClearBelt ( uint16  bubbleID)

Definition at line 66 of file BeltMgr.cpp.

67 {
68  //ClearAll();
69 }
bool BeltMgr::Create ( CosmicSignature sig,
std::unordered_multimap< float, uint16 > &  roidTypes 
)

Definition at line 244 of file BeltMgr.cpp.

References SystemBubble::GetID(), SystemManager::GetSE(), SystemEntity::GetSelf(), m_system, SystemBubble::SetBelt(), CosmicSignature::sigItemID, SpawnBelt(), and SystemEntity::SysBubble().

Referenced by DungeonMgr::Create().

245 {
246  // register this as a belt.
247  SystemEntity* pSE = m_system->GetSE(sig.sigItemID);
248  if (pSE == nullptr)
249  return false;
250  pSE->SysBubble()->SetBelt(pSE->GetSelf());
251  SpawnBelt(pSE->SysBubble()->GetID(), roidTypes, 0, true);
252  return true;
253 }
SystemEntity * GetSE(uint32 entityID) const
SystemBubble * SysBubble()
Definition: SystemEntity.h:195
SystemManager * m_system
Definition: BeltMgr.h:69
InventoryItemRef GetSelf()
Definition: SystemEntity.h:202
uint16 GetID()
Definition: SystemBubble.h:91
void SetBelt(InventoryItemRef itemRef)
void SpawnBelt(uint16 bubbleID, std::unordered_multimap< float, uint16 > &roidTypes, int type=0, bool anomaly=false)
Definition: BeltMgr.cpp:255

Here is the call graph for this function:

Here is the caller graph for this function:

uint32 BeltMgr::GetAsteroidType ( double  p,
const std::unordered_multimap< float, uint16 > &  roids 
)
protected

Definition at line 362 of file BeltMgr.cpp.

References _log.

Referenced by SpawnBelt().

362  {
363  std::unordered_multimap<float, uint16>::const_iterator cur = roids.begin();
364  float chance = 0.0;
365  for(; cur != roids.end(); ++cur ) {
366  chance += cur->first;
367  _log(COSMIC_MGR__DEBUG, "BeltMgr::GetAsteroidType - checking %u with chance %.3f(%.3f)", cur->second, chance, p);
368  if (chance > p )
369  return cur->second;
370  }
371 
372  return 0;
373 }
#define _log(type, fmt,...)
Definition: logsys.h:124

Here is the caller graph for this function:

void BeltMgr::GetIceDist ( uint8  quarter,
float  secStatus,
std::unordered_multimap< float, uint16 > &  roidDist 
)
protected

Definition at line 446 of file BeltMgr.cpp.

Referenced by SpawnBelt().

447 {
448  // get map region for ice distro
449  switch (quarter) {
450  case 1: { // caldari
451  if (secStatus < 0.0) {
452  roidDist.insert(std::pair<float,uint32>(0.2, 16265)); // White Glaze - caldari
453  roidDist.insert(std::pair<float,uint32>(0.16, 16266)); // Glare Crust - all < 0.4
454  roidDist.insert(std::pair<float,uint32>(0.16, 16267)); // Dark Glitter - all but gallente < 0.1
455  roidDist.insert(std::pair<float,uint32>(0.16, 17976)); // Pristine White Glaze - caldari < 0.0
456  roidDist.insert(std::pair<float,uint32>(0.16, 16268)); // Gelidus - all < 0.0
457  roidDist.insert(std::pair<float,uint32>(0.16, 16269)); // Krystallos - all < 0.0
458  } else if (secStatus < 0.1) {
459  roidDist.insert(std::pair<float,uint32>(0.70, 16265)); // White Glaze - caldari
460  roidDist.insert(std::pair<float,uint32>(0.20, 16266)); // Glare Crust - all < 0.4
461  roidDist.insert(std::pair<float,uint32>(0.10, 16267)); // Dark Glitter - all but gallente < 0.1
462  } else if (secStatus < 0.4) {
463  roidDist.insert(std::pair<float,uint32>(0.75, 16265)); // White Glaze - caldari
464  roidDist.insert(std::pair<float,uint32>(0.25, 16266)); // Glare Crust - all < 0.4
465  } else {
466  roidDist.insert(std::pair<float,uint32>(1.0, 16265)); // White Glaze - caldari
467  }
468  } break;
469  case 2: { // minmatar
470  if (secStatus < 0.0) {
471  roidDist.insert(std::pair<float,uint32>(0.2, 16263)); // Glacial Mass - minmatar
472  roidDist.insert(std::pair<float,uint32>(0.16, 16266)); // Glare Crust - all < 0.4
473  roidDist.insert(std::pair<float,uint32>(0.16, 16267)); // Dark Glitter - all but gallente < 0.1
474  roidDist.insert(std::pair<float,uint32>(0.16, 17977)); // Smooth Glacial Mass - minmatar < 0.0
475  roidDist.insert(std::pair<float,uint32>(0.16, 16268)); // Gelidus - all < 0.0
476  roidDist.insert(std::pair<float,uint32>(0.16, 16269)); // Krystallos - all < 0.0
477  } else if (secStatus < 0.1) {
478  roidDist.insert(std::pair<float,uint32>(0.70, 16263)); // Glacial Mass - minmatar
479  roidDist.insert(std::pair<float,uint32>(0.20, 16266)); // Glare Crust - all < 0.4
480  roidDist.insert(std::pair<float,uint32>(0.10, 16267)); // Dark Glitter - all but gallente < 0.1
481  } else if (secStatus < 0.4) {
482  roidDist.insert(std::pair<float,uint32>(0.75, 16263)); // Glacial Mass - minmatar
483  roidDist.insert(std::pair<float,uint32>(0.25, 16266)); // Glare Crust - all < 0.4
484  } else {
485  roidDist.insert(std::pair<float,uint32>(1.0, 16263)); // Glacial Mass - minmatar
486  }
487  } break;
488  case 3: { //amarr
489  if (secStatus < 0.0) {
490  roidDist.insert(std::pair<float,uint32>(0.2, 16262)); // Clear Icicle - amarr
491  roidDist.insert(std::pair<float,uint32>(0.16, 16266)); // Glare Crust - all < 0.4
492  roidDist.insert(std::pair<float,uint32>(0.16, 16267)); // Dark Glitter - all but gallente < 0.1
493  roidDist.insert(std::pair<float,uint32>(0.16, 17978)); // Enriched Clear Icicle - amarr < 0.0
494  roidDist.insert(std::pair<float,uint32>(0.16, 16268)); // Gelidus - all < 0.0
495  roidDist.insert(std::pair<float,uint32>(0.16, 16269)); // Krystallos - all < 0.0
496  } else if (secStatus < 0.1) {
497  roidDist.insert(std::pair<float,uint32>(0.70, 16262)); // Clear Icicle - amarr
498  roidDist.insert(std::pair<float,uint32>(0.20, 16266)); // Glare Crust - all < 0.4
499  roidDist.insert(std::pair<float,uint32>(0.10, 16267)); // Dark Glitter - all but gallente < 0.1
500  } else if (secStatus < 0.4) {
501  roidDist.insert(std::pair<float,uint32>(0.75, 16262)); // Clear Icicle - amarr
502  roidDist.insert(std::pair<float,uint32>(0.25, 16266)); // Glare Crust - all < 0.4
503  } else {
504  roidDist.insert(std::pair<float,uint32>(1.0, 16262)); // Clear Icicle - amarr
505  }
506  } break;
507  case 4: { //gallente
508  if (secStatus < 0.0) {
509  roidDist.insert(std::pair<float,uint32>(0.3, 16264)); // Blue Ice - gallente
510  roidDist.insert(std::pair<float,uint32>(0.17, 16266)); // Glare Crust - all < 0.4
511  roidDist.insert(std::pair<float,uint32>(0.17, 17975)); // Thick Blue Ice - gallente < 0.0
512  roidDist.insert(std::pair<float,uint32>(0.17, 16268)); // Gelidus - all < 0.0
513  roidDist.insert(std::pair<float,uint32>(0.17, 16269)); // Krystallos - all < 0.0
514  } else if (secStatus < 0.4) {
515  roidDist.insert(std::pair<float,uint32>(0.75, 16264)); // Blue Ice - gallente
516  roidDist.insert(std::pair<float,uint32>(0.25, 16266)); // Glare Crust - all < 0.4
517  } else {
518  roidDist.insert(std::pair<float,uint32>(1.0, 16264)); // Blue Ice - gallente
519  }
520  } break;
521  case 5: { // none? no region quarter?
522  if (secStatus < 0.0) {
523  roidDist.insert(std::pair<float,uint32>(0.4, 16266)); // Glare Crust - all < 0.4
524  roidDist.insert(std::pair<float,uint32>(0.2, 16267)); // Dark Glitter - all but gallente < 0.1
525  roidDist.insert(std::pair<float,uint32>(0.2, 16268)); // Gelidus - all < 0.0
526  roidDist.insert(std::pair<float,uint32>(0.2, 16269)); // Krystallos - all < 0.0
527  } else if (secStatus < 0.1) {
528  roidDist.insert(std::pair<float,uint32>(0.75, 16266)); // Glare Crust - all < 0.4
529  roidDist.insert(std::pair<float,uint32>(0.25, 16267)); // Dark Glitter - all but gallente < 0.1
530  } else if (secStatus < 0.4) {
531  roidDist.insert(std::pair<float,uint32>(1.0, 16266)); // Glare Crust - all < 0.4
532  }
533  } break;
534  }
535 }

Here is the caller graph for this function:

void BeltMgr::GetList ( uint32  beltID,
std::vector< AsteroidSE * > &  list 
)

Definition at line 221 of file BeltMgr.cpp.

References m_asteroids.

Referenced by Command_beltlist(), and ActiveModule::DeactivateCycle().

222 {
223  auto range = m_asteroids.equal_range(beltID);
224  for (auto itr = range.first; itr != range.second; ++itr)
225  list.push_back(itr->second);
226 }
std::unordered_multimap< uint32, AsteroidSE * > m_asteroids
Definition: BeltMgr.h:83

Here is the caller graph for this function:

void BeltMgr::Init ( uint32  regionID)

Definition at line 36 of file BeltMgr.cpp.

References _log, SystemManager::GetID(), SystemManager::GetName(), m_active, m_belts, m_initialized, m_regionID, m_respawnTimer, m_spawned, m_system, m_systemID, sConfig, and Timer::Start().

Referenced by SystemManager::LoadCosmicMgrs().

37 {
38  if (!sConfig.cosmic.BeltEnabled) {
39  _log(COSMIC_MGR__MESSAGE, "BeltMgr System Disabled. Not Initializing Belt Manager for %s(%u)", m_system->GetName(), m_system->GetID());
40  return;
41  }
42 
43  m_belts.clear();
44  m_active.clear();
45  m_spawned.clear();
46 
47  assert(m_system != nullptr);
48 
49  m_regionID = regionID;
51  m_respawnTimer.Start(sConfig.cosmic.BeltRespawn *60 *60 *1000); // hours->ms
52 
53  m_initialized = true;
54  _log(COSMIC_MGR__MESSAGE, "BeltMgr Initialized for %s(%u)", m_system->GetName(), m_systemID);
55 }
#define sConfig
A macro for easier access to the singleton.
std::map< uint32, bool > m_active
Definition: BeltMgr.h:79
#define _log(type, fmt,...)
Definition: logsys.h:124
uint32 GetID() const
Definition: SystemManager.h:80
std::map< uint32, InventoryItemRef > m_belts
Definition: BeltMgr.h:81
uint32 m_systemID
Definition: BeltMgr.h:73
SystemManager * m_system
Definition: BeltMgr.h:69
bool m_initialized
Definition: BeltMgr.h:72
const char * GetName() const
Definition: SystemManager.h:84
std::map< uint32, bool > m_spawned
Definition: BeltMgr.h:77
uint32 m_regionID
Definition: BeltMgr.h:74
Timer m_respawnTimer
Definition: BeltMgr.h:60
void Start(uint32 setTimerTime=0, bool changeResetTimer=true)
Definition: timer.cpp:81

Here is the call graph for this function:

Here is the caller graph for this function:

bool BeltMgr::IsActive ( uint16  bubbleID)

Definition at line 105 of file BeltMgr.cpp.

References m_active, and sBubbleMgr.

Referenced by AsteroidSE::Process().

106 {
107  uint32 beltID = sBubbleMgr.GetBeltID(bubbleID);
108  std::map<uint32, bool>::iterator itr = m_active.find(beltID);
109  if (itr != m_active.end())
110  return itr->second;
111  return false;
112 }
std::map< uint32, bool > m_active
Definition: BeltMgr.h:79
unsigned __int32 uint32
Definition: eve-compat.h:50
#define sBubbleMgr

Here is the caller graph for this function:

bool BeltMgr::IsSpawned ( uint16  bubbleID)

Definition at line 96 of file BeltMgr.cpp.

References m_spawned, and sBubbleMgr.

Referenced by CheckSpawn(), and SpawnBelt().

97 {
98  uint32 beltID = sBubbleMgr.GetBeltID(bubbleID);
99  std::map<uint32, bool>::iterator itr = m_spawned.find(beltID);
100  if (itr != m_spawned.end())
101  return itr->second;
102  return false;
103 }
unsigned __int32 uint32
Definition: eve-compat.h:50
std::map< uint32, bool > m_spawned
Definition: BeltMgr.h:77
#define sBubbleMgr

Here is the caller graph for this function:

bool BeltMgr::Load ( uint16  bubbleID)

Definition at line 139 of file BeltMgr.cpp.

References _log, SystemManager::AddEntity(), AttrMass, AttrQuantity, AttrRadius, AttrVolume, RefPtr< X >::get(), SystemManager::GetName(), SystemManager::GetServiceMgr(), ManagerDB::LoadSystemRoids(), m_active, m_asteroids, m_db, m_spawned, m_system, m_systemID, sBubbleMgr, AsteroidSE::SetMgr(), and sItemFactory.

Referenced by CheckSpawn().

139  {
140  std::vector<AsteroidData> entities;
141  entities.clear();
142  uint32 beltID = sBubbleMgr.GetBeltID(bubbleID);
143  if (beltID == 0)
144  return false;
145  if (!m_db.LoadSystemRoids(m_systemID, beltID, entities))
146  return false;
147 
148  for (auto entity : entities) {
149  AsteroidItemRef itemRef = sItemFactory.GetAsteroid(entity.itemID);
150  if (itemRef.get() == nullptr) {
151  _log(COSMIC_MGR__WARNING, "BeltMgr::Load() - Unable to spawn item #%u:'%s' of type %u.", entity.itemID, entity.itemName.c_str(), entity.typeID);
152  continue;
153  }
154  // set attribs using loaded values from asteroid table.
155  itemRef->SetAttribute(AttrRadius, itemRef->type().radius() * entity.radius); // Radius
156  itemRef->SetAttribute(AttrQuantity, entity.quantity); // Quantity
157  itemRef->SetAttribute(AttrVolume, itemRef->type().volume()); // Volume
158  itemRef->SetAttribute(AttrMass, itemRef->type().mass() * entity.quantity); // Mass
159 
160  AsteroidSE* pASE = new AsteroidSE(itemRef, *(m_system->GetServiceMgr()), m_system );
161  if (pASE == nullptr) {
162  _log(COSMIC_MGR__WARNING, "BeltMgr::Load() - Unable to spawn itemID %u - %s (type %u).", entity.itemID, entity.itemName.c_str(), entity.typeID);
163  continue;
164  }
165  _log(COSMIC_MGR__TRACE, "BeltMgr::Load() - Loaded asteroid %u, type %u for %s(%u)", entity.itemID, entity.typeID, m_system->GetName(), m_systemID );
166  m_system->AddEntity(pASE);
167  m_asteroids.emplace(std::pair<uint32, AsteroidSE*>(beltID, pASE));
168  pASE->SetMgr(this, beltID);
169  }
170  std::map<uint32, bool>::iterator itr = m_spawned.find(beltID);
171  if (itr == m_spawned.end()) {
172  m_spawned.insert(std::pair<uint32, bool>(beltID, true));
173  } else {
174  itr->second = true;
175  }
176 
177  itr = m_active.find(beltID);
178  if (itr == m_active.end()) {
179  m_active.insert(std::pair<uint32, bool>(beltID, true));
180  } else {
181  itr->second = true;
182  }
183 
184  return true;
185 }
std::map< uint32, bool > m_active
Definition: BeltMgr.h:79
void AddEntity(SystemEntity *pSE, bool addSignal=true)
#define _log(type, fmt,...)
Definition: logsys.h:124
void SetMgr(BeltMgr *beltMgr, uint32 beltID)
Definition: Asteroid.h:102
ManagerDB m_db
Definition: BeltMgr.h:59
uint32 m_systemID
Definition: BeltMgr.h:73
std::unordered_multimap< uint32, AsteroidSE * > m_asteroids
Definition: BeltMgr.h:83
SystemManager * m_system
Definition: BeltMgr.h:69
X * get() const
Definition: RefPtr.h:213
unsigned __int32 uint32
Definition: eve-compat.h:50
PyServiceMgr * GetServiceMgr()
Definition: SystemManager.h:88
const char * GetName() const
Definition: SystemManager.h:84
#define sItemFactory
Definition: ItemFactory.h:165
std::map< uint32, bool > m_spawned
Definition: BeltMgr.h:77
bool LoadSystemRoids(uint32 systemID, uint32 &beltID, std::vector< AsteroidData > &into)
Definition: ManagerDB.cpp:508
#define sBubbleMgr
Reference-counting-based smart pointer.
Definition: RefPtr.h:133

Here is the call graph for this function:

Here is the caller graph for this function:

void BeltMgr::Process ( )

Definition at line 125 of file BeltMgr.cpp.

References Timer::Check(), m_initialized, m_respawnTimer, m_spawned, and SpawnBelt().

Referenced by SystemManager::ProcessTic().

125  {
126  if (!m_initialized)
127  return;
128 
129  if (m_respawnTimer.Check()) {
130  for (auto cur : m_spawned)
131  if (!cur.second) {
132  std::unordered_multimap<float, uint16> roidTypes;
133  roidTypes.clear();
134  SpawnBelt(cur.first, roidTypes);
135  }
136  }
137 }
bool m_initialized
Definition: BeltMgr.h:72
bool Check(bool reset=true)
Definition: timer.cpp:62
void SpawnBelt(uint16 bubbleID, std::unordered_multimap< float, uint16 > &roidTypes, int type=0, bool anomaly=false)
Definition: BeltMgr.cpp:255
std::map< uint32, bool > m_spawned
Definition: BeltMgr.h:77
Timer m_respawnTimer
Definition: BeltMgr.h:60

Here is the call graph for this function:

Here is the caller graph for this function:

void BeltMgr::RegisterBelt ( InventoryItemRef  itemRef)

Definition at line 57 of file BeltMgr.cpp.

References m_active, m_belts, and m_spawned.

Referenced by SystemBubble::SetBelt().

58 {
59  uint32 beltID = itemRef->itemID();
60  m_belts.insert(std::pair<uint32, InventoryItemRef>(beltID, itemRef));
61  m_active.insert(std::pair<uint32, bool>(beltID, false));
62  m_spawned.insert(std::pair<uint32, bool>(beltID, false));
63 }
std::map< uint32, bool > m_active
Definition: BeltMgr.h:79
std::map< uint32, InventoryItemRef > m_belts
Definition: BeltMgr.h:81
unsigned __int32 uint32
Definition: eve-compat.h:50
std::map< uint32, bool > m_spawned
Definition: BeltMgr.h:77
uint32 itemID() const
Definition: InventoryItem.h:98

Here is the caller graph for this function:

void BeltMgr::RemoveAsteroid ( uint32  beltID,
AsteroidSE pASE 
)

Definition at line 424 of file BeltMgr.cpp.

References SystemEntity::GetID(), m_asteroids, m_db, and ManagerDB::RemoveAsteroid().

Referenced by AsteroidSE::Delete().

425 {
426  m_db.RemoveAsteroid(pASE->GetID());
427  // this doesnt work right. not sure why yet.
428  auto range = m_asteroids.equal_range(beltID);
429  for (auto itr = range.first; itr != range.second; ++itr) {
430  if (itr->second == pASE) {
431  m_asteroids.erase(itr);
432  return;
433  }
434  }
435 /*
436  if (m_asteroids.count(beltID)) {
437  std::map<uint32, bool>::iterator itr = m_spawned.find(beltID);
438  if (itr != m_spawned.end())
439  itr->second = false;
440  else
441  m_spawned.insert(std::pair<uint32, bool>(beltID, false));
442  }
443 */
444 }
ManagerDB m_db
Definition: BeltMgr.h:59
std::unordered_multimap< uint32, AsteroidSE * > m_asteroids
Definition: BeltMgr.h:83
uint32 GetID()
Definition: SystemEntity.h:207
void RemoveAsteroid(uint32 asteroidID)
Definition: ManagerDB.cpp:539

Here is the call graph for this function:

Here is the caller graph for this function:

void BeltMgr::Save ( )

Definition at line 187 of file BeltMgr.cpp.

References _log, AsteroidData::beltID, SystemManager::GetName(), GetTimeUSeconds(), IsTempItem, AsteroidData::itemID, AsteroidData::itemName, m_asteroids, m_db, m_system, m_systemID, AsteroidData::position, AsteroidData::quantity, AsteroidData::radius, ManagerDB::SaveSystemRoids(), AsteroidData::systemID, and AsteroidData::typeID.

Referenced by ClearAll().

187  {
188  if (m_asteroids.empty()) {
189  _log(COSMIC_MGR__TRACE, "BeltMgr::Save - m_asteroids is empty for %s(%u). nothing to save.", m_system->GetName(), m_systemID);
190  return;
191  }
192 
193  double start = GetTimeUSeconds();
194  std::vector<AsteroidData> roids;
195  roids.clear();
196  uint16 save(0), skip(0);
197  for (auto cur : m_asteroids) {
198  // we are not saving anomaly belts (yet. small belts in anomalies will become their own grav sites (wip))
199  if (IsTempItem(cur.first)) {
200  ++skip;
201  continue;
202  }
203  AsteroidData entry = AsteroidData();
204  entry.itemID = cur.second->GetID();
205  entry.itemName = cur.second->GetName();
206  entry.typeID = cur.second->GetSelf()->typeID();
207  entry.systemID = m_systemID;
208  entry.beltID = cur.first;
209  entry.radius = cur.second->GetRadius();
210  entry.quantity = ((25000 * log(entry.radius)) - 112404.8); // quantity in m^3
211  entry.position = cur.second->GetPosition();
212  roids.push_back(entry);
213  ++save;
214  }
215 
217  _log(COSMIC_MGR__TRACE, "BeltMgr::Save - Saving %u Asteroids for %s(%u) took %.3fus. Skipped %u temp anomaly asteroids.", \
218  save, m_system->GetName(), m_systemID, (GetTimeUSeconds() - start), skip);
219 }
#define _log(type, fmt,...)
Definition: logsys.h:124
ManagerDB m_db
Definition: BeltMgr.h:59
uint32 m_systemID
Definition: BeltMgr.h:73
std::unordered_multimap< uint32, AsteroidSE * > m_asteroids
Definition: BeltMgr.h:83
double GetTimeUSeconds()
Definition: utils_time.cpp:116
SystemManager * m_system
Definition: BeltMgr.h:69
void SaveSystemRoids(uint32 systemID, std::vector< AsteroidData > &roids)
Definition: ManagerDB.cpp:566
#define IsTempItem(itemID)
Definition: EVE_Defines.h:333
const char * GetName() const
Definition: SystemManager.h:84
unsigned __int16 uint16
Definition: eve-compat.h:48
std::string itemName

Here is the call graph for this function:

Here is the caller graph for this function:

void BeltMgr::SetActive ( uint16  bubbleID,
bool  active = true 
)

Definition at line 114 of file BeltMgr.cpp.

References m_active, and sBubbleMgr.

Referenced by MiningLaser::CanActivate().

115 {
116  uint32 beltID = sBubbleMgr.GetBeltID(bubbleID);
117  std::map<uint32, bool>::iterator itr = m_active.find(beltID);
118  if (itr != m_active.end()) {
119  itr->second = active;
120  } else {
121  m_active.insert(std::pair<uint32, bool>(beltID, active));
122  }
123 }
std::map< uint32, bool > m_active
Definition: BeltMgr.h:79
unsigned __int32 uint32
Definition: eve-compat.h:50
#define sBubbleMgr

Here is the caller graph for this function:

void BeltMgr::SpawnAsteroid ( uint32  beltID,
uint32  typeID,
double  radius,
const GPoint position,
bool  ice = false 
)
protected

Definition at line 375 of file BeltMgr.cpp.

References _log, SystemManager::AddEntity(), AsteroidData::beltID, flagNone, RefPtr< X >::get(), SystemManager::GetServiceMgr(), IsNaN(), IsTempItem, m_asteroids, m_system, m_systemID, ownerSystem, AsteroidData::position, AsteroidData::quantity, AsteroidData::radius, sConfig, AsteroidSE::SetMgr(), sItemFactory, AsteroidItem::SpawnTemp(), AsteroidData::systemID, and AsteroidData::typeID.

Referenced by SpawnBelt().

375  {
376  if (typeID == 0) {
377  _log(COSMIC_MGR__WARNING, "BeltMgr::SpawnAsteroid - typeID is 0");
378  return;
379  }
380  if (IsNaN(radius)) {
381  _log(COSMIC_MGR__WARNING, "BeltMgr::SpawnAsteroid - radius is NaN");
382  return;
383  }
384  if (radius <= 0) {
385  _log(COSMIC_MGR__WARNING, "BeltMgr::SpawnAsteroid - radius < 0");
386  return;
387  }
388 
389  double quantity = 0;
390  if (ice) {
391  quantity = radius * 2;
392  } else {
393  radius *= sConfig.cosmic.roidRadiusMultiplier;
394  //Amount of Ore = (25000*ln(Radius))-112404.8 V = 25000Ln(r) - 112407
395  quantity = ((25000 * log(radius)) - 112404.8);
396  }
397 
398  AsteroidData adata = AsteroidData();
399  adata.beltID = beltID;
400  adata.systemID = m_systemID;
401  adata.typeID = typeID;
402  adata.quantity = quantity;
403  adata.radius = radius;
404  adata.position = position;
405  ItemData idata(typeID, ownerSystem, m_systemID, flagNone, "", position);
406  InventoryItemRef iRef(nullptr);
407  if (IsTempItem(beltID)) {
408  iRef = AsteroidItem::SpawnTemp(idata, adata); // create temp item for anomaly belt
409  } else {
410  iRef = sItemFactory.SpawnAsteroid(idata, adata);
411  }
412  if (iRef.get() == nullptr)
413  return;
414 
415  AsteroidSE* pASE = new AsteroidSE( iRef, *(m_system->GetServiceMgr()), m_system );
416  if (pASE == nullptr)
417  return;
418 
419  m_asteroids.emplace(std::pair<uint32, AsteroidSE*>(beltID, pASE));
420  pASE->SetMgr(this, beltID);
421  m_system->AddEntity(pASE, false); // we're not adding roids to signal list
422 }
#define sConfig
A macro for easier access to the singleton.
void AddEntity(SystemEntity *pSE, bool addSignal=true)
#define _log(type, fmt,...)
Definition: logsys.h:124
void SetMgr(BeltMgr *beltMgr, uint32 beltID)
Definition: Asteroid.h:102
uint32 m_systemID
Definition: BeltMgr.h:73
std::unordered_multimap< uint32, AsteroidSE * > m_asteroids
Definition: BeltMgr.h:83
SystemManager * m_system
Definition: BeltMgr.h:69
static AsteroidItemRef SpawnTemp(ItemData &idata, AsteroidData &adata)
Definition: Asteroid.cpp:54
PyServiceMgr * GetServiceMgr()
Definition: SystemManager.h:88
#define IsTempItem(itemID)
Definition: EVE_Defines.h:333
#define sItemFactory
Definition: ItemFactory.h:165
bool IsNaN(double x)
Definition: misc.h:89

Here is the call graph for this function:

Here is the caller graph for this function:

void BeltMgr::SpawnBelt ( uint16  bubbleID,
std::unordered_multimap< float, uint16 > &  roidTypes,
int  type = 0,
bool  anomaly = false 
)
protected

Definition at line 255 of file BeltMgr.cpp.

References _log, EvE::Trig::Deg2Rad(), GetAsteroidType(), SystemBubble::GetCenter(), GetIceDist(), SystemManager::GetName(), SystemManager::GetSE(), SystemManager::GetSecValue(), SystemManager::GetSystemSecurityClass(), SystemManager::GetSystemSecurityRating(), SystemEntity::GetTypeID(), IsCelestialID, IsSpawned(), m_active, m_regionID, m_spawned, m_system, m_systemID, MakeRandomFloat(), MakeRandomInt(), NULL_ORIGIN(), EvE::Trig::Pi, sBubbleMgr, sConfig, sDataMgr, SpawnAsteroid(), and SystemEntity::SysBubble().

Referenced by CheckSpawn(), Create(), and Process().

256 {
257  if (IsSpawned(bubbleID))
258  return;
259 
260  uint32 beltID = sBubbleMgr.GetBeltID(bubbleID);
261  if ((!IsCelestialID(beltID)) and (!anomaly))
262  return;
263 
264  SystemEntity* pSE = m_system->GetSE(beltID);
265  if (pSE == nullptr)
266  return;
267 
268  bool ice = (pSE->GetTypeID() == 17774);
269 
270  float secRating = m_system->GetSystemSecurityRating();
271  float secValue = m_system->GetSecValue();
272  std::unordered_multimap<float, uint16> roidDist;
273  if (ice) {
274  // caldari=1, minmatar=2, amarr=3, gallente=4, none=5
275  GetIceDist(sDataMgr.GetRegionQuarter(m_regionID), secRating, roidDist);
276  } else if (anomaly) {
277  roidDist = roidTypes;
278  } else {
279  sDataMgr.GetRoidDist(m_system->GetSystemSecurityClass(), roidDist);
280  }
281 
282  int8 pcs = 5;
283  double radius = 8000;
284  radius *= sConfig.cosmic.roidRadiusMultiplier;
285  double roidradius = 0, theta = 0, randRadius = 0, elevation = 0;
286  if (anomaly) {
287  pcs += roidDist.size();
288  radius += (radius * secValue);
289  radius += (pcs * 1000 / 4);
290  elevation = (radius / 4);
291  } else if (ice) { //880 total systems with ice. 293 in hisec
292  // ice needs to be 30k to 75k, with radius of 40k to 100k
293  radius *= 3; //24k base
294  if (secRating > 0.7) {
295  pcs = 1;
296  } else if (secRating > 0.4) {
297  pcs = 2;
298  } else if (secRating > 0.0) {
299  pcs = 3;
300  } else if (secRating > -0.4) {
301  pcs = 4;
302  } else {
303  pcs = 6;
304  }
305  } else {
306  pcs += MakeRandomInt(5, 30);
307  radius += (radius * secValue);
308  radius += (pcs * 1000 / 4);
309  elevation = (radius / 4);
310  }
311 
312  double degreeSeparation = (180 / pcs);
313  ++pcs;
314  GPoint center(pSE->SysBubble()->GetCenter());
315  GPoint mposition(NULL_ORIGIN);
316  for (uint8 i = 1; i < pcs; ++i) {
317  if (ice) {
318  if (secRating > -0.2) {
319  roidradius = MakeRandomInt(20, 40) * 1000; // (40k,70k) 72-102k radius
320  } else {
321  roidradius = MakeRandomInt(40, 70) * 1000; // (40k,80k) 82-112k radius
322  }
323  radius += roidradius;
324  elevation = (radius + (roidradius / 2) / 2);
325  } else {
326  roidradius = MakeRandomInt(3000, 8000) * secValue;
327  }
328  if (anomaly) {
329  // random for anomaly...use the "special" placements at end of this file....eventually.
330  theta = MakeRandomFloat(0, (EvE::Trig::Pi*2));
331  mposition.x = (radius + roidradius / 5) * cos(theta);
332  mposition.z = (radius + roidradius / 5) * sin(theta);
333  } else if (type == 0) {
334  randRadius = MakeRandomFloat(-radius / 4, radius / 2);
335  // half-circle type
336  theta = EvE::Trig::Deg2Rad(degreeSeparation * i);
337  mposition.x = (randRadius + roidradius + radius) * cos(theta);
338  mposition.z = (randRadius + roidradius + radius) * sin(theta);
339  }
340  mposition.y = MakeRandomFloat(-elevation, elevation);
341  SpawnAsteroid(beltID, GetAsteroidType(MakeRandomFloat(), roidDist), roidradius, (center + mposition), ice);
342  }
343 
344  std::map<uint32, bool>::iterator itr = m_spawned.find(beltID);
345  if (itr == m_spawned.end()) {
346  m_spawned.insert(std::pair<uint32, bool>(beltID, true));
347  } else {
348  itr->second = true;
349  }
350 
351  itr = m_active.find(beltID);
352  if (itr == m_active.end()) {
353  m_active.insert(std::pair<uint32, bool>(beltID, false));
354  } else {
355  itr->second = false;
356  }
357 
358  _log(COSMIC_MGR__TRACE, "BeltMgr::SpawnBelt - Belt spawned with %u roids of %s in %s %u for %s(%u)", \
359  pcs, (ice?"ice":"ore"), (anomaly?"anomalyID":"beltID"), beltID, m_system->GetName(), m_systemID );
360 }
#define sConfig
A macro for easier access to the singleton.
unsigned __int8 uint8
Definition: eve-compat.h:46
std::map< uint32, bool > m_active
Definition: BeltMgr.h:79
SystemEntity * GetSE(uint32 entityID) const
#define _log(type, fmt,...)
Definition: logsys.h:124
const double Pi
Definition: Trig.h:20
#define IsCelestialID(itemID)
Definition: EVE_Defines.h:288
SystemBubble * SysBubble()
Definition: SystemEntity.h:195
double MakeRandomFloat(double low, double high)
Generates random real from interval [low; high].
Definition: misc.cpp:114
const float GetSystemSecurityRating()
Definition: SystemManager.h:86
signed __int8 int8
Definition: eve-compat.h:45
uint32 m_systemID
Definition: BeltMgr.h:73
Definition: gpoint.h:33
bool IsSpawned(uint16 bubbleID)
Definition: BeltMgr.cpp:96
SystemManager * m_system
Definition: BeltMgr.h:69
double Deg2Rad(double deg)
Definition: Trig.h:25
static const GPoint NULL_ORIGIN(0, 0, 0)
float GetSecValue()
unsigned __int32 uint32
Definition: eve-compat.h:50
const char * GetName() const
Definition: SystemManager.h:84
int64 MakeRandomInt(int64 low, int64 high)
Generates random integer from interval [low; high].
Definition: misc.cpp:109
void SpawnAsteroid(uint32 beltID, uint32 typeID, double radius, const GPoint &position, bool ice=false)
Definition: BeltMgr.cpp:375
std::map< uint32, bool > m_spawned
Definition: BeltMgr.h:77
uint16 GetTypeID()
Definition: SystemEntity.h:203
uint32 GetAsteroidType(double p, const std::unordered_multimap< float, uint16 > &roids)
Definition: BeltMgr.cpp:362
#define sBubbleMgr
GPoint GetCenter()
Definition: SystemBubble.h:93
uint32 m_regionID
Definition: BeltMgr.h:74
void GetIceDist(uint8 quarter, float secStatus, std::unordered_multimap< float, uint16 > &roidDist)
Definition: BeltMgr.cpp:446
const char * GetSystemSecurityClass()
Definition: SystemManager.h:85
#define sDataMgr

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

std::map<uint32, bool> BeltMgr::m_active
private

Definition at line 79 of file BeltMgr.h.

Referenced by Init(), IsActive(), Load(), RegisterBelt(), SetActive(), and SpawnBelt().

std::unordered_multimap<uint32, AsteroidSE*> BeltMgr::m_asteroids
private

Definition at line 83 of file BeltMgr.h.

Referenced by ClearAll(), GetList(), Load(), RemoveAsteroid(), Save(), and SpawnAsteroid().

std::map<uint32, InventoryItemRef> BeltMgr::m_belts
private

Definition at line 81 of file BeltMgr.h.

Referenced by ClearAll(), Init(), and RegisterBelt().

ManagerDB BeltMgr::m_db
protected

Definition at line 59 of file BeltMgr.h.

Referenced by Load(), RemoveAsteroid(), and Save().

bool BeltMgr::m_initialized
private

Definition at line 72 of file BeltMgr.h.

Referenced by Init(), and Process().

uint32 BeltMgr::m_regionID
private

Definition at line 74 of file BeltMgr.h.

Referenced by Init(), and SpawnBelt().

Timer BeltMgr::m_respawnTimer
protected

Definition at line 60 of file BeltMgr.h.

Referenced by Init(), and Process().

PyServiceMgr& BeltMgr::m_services
private

Definition at line 70 of file BeltMgr.h.

std::map<uint32, bool> BeltMgr::m_spawned
private

Definition at line 77 of file BeltMgr.h.

Referenced by Init(), IsSpawned(), Load(), Process(), RegisterBelt(), and SpawnBelt().

SystemManager* BeltMgr::m_system
private

Definition at line 69 of file BeltMgr.h.

Referenced by ClearAll(), Create(), Init(), Load(), Save(), SpawnAsteroid(), and SpawnBelt().

uint32 BeltMgr::m_systemID
private

Definition at line 73 of file BeltMgr.h.

Referenced by Init(), Load(), Save(), SpawnAsteroid(), and SpawnBelt().


The documentation for this class was generated from the following files: