EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BeltMgr.cpp
Go to the documentation of this file.
1 
17 #include "eve-server.h"
18 
19 #include "EVEServerConfig.h"
20 #include "PyServiceMgr.h"
21 #include "StaticDataMgr.h"
22 #include "system/SystemBubble.h"
23 #include "system/SystemManager.h"
26 
27 
29 : m_respawnTimer(0),
30 m_system(mgr),
31 m_services(svc),
32 m_initialized(false)
33 {
34 }
35 
36 void BeltMgr::Init(uint32 regionID)
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 }
56 
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 }
64 
65 //not used
66 void BeltMgr::ClearBelt(uint16 bubbleID)
67 {
68  //ClearAll();
69 }
70 
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 }
81 
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 }
95 
96 bool BeltMgr::IsSpawned(uint16 bubbleID)
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 }
104 
105 bool BeltMgr::IsActive(uint16 bubbleID)
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 }
113 
114 void BeltMgr::SetActive(uint16 bubbleID, bool active/*true*/)
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 }
124 
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 }
138 
139 bool BeltMgr::Load(uint16 bubbleID) {
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 }
186 
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 }
220 
221 void BeltMgr::GetList(uint32 beltID, std::vector< AsteroidSE* >& list)
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 }
227 
228  /*
229 struct CosmicSignature {
230  std::string sigID; // this is unique xxx-nnn id displayed in scanner
231  std::string sigName;
232  uint32 ownerID;
233  uint32 systemID;
234  uint32 sigItemID; // itemID of this entry
235  uint8 dungeonType;
236  uint16 sigTypeID;
237  uint16 sigGroupID;
238  uint16 scanGroupID;
239  uint16 scanAttributeID;
240  GPoint position;
241 };
242 */
243 
244 bool BeltMgr::Create(CosmicSignature& sig, std::unordered_multimap<float, uint16>& roidTypes)
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 }
254 
255 void BeltMgr::SpawnBelt(uint16 bubbleID, std::unordered_multimap<float, uint16>& roidTypes, int type/*0*/, bool anomaly/*false*/)
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 }
361 
362 uint32 BeltMgr::GetAsteroidType(double p, const std::unordered_multimap<float, uint16>& roids) {
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 }
374 
375 void BeltMgr::SpawnAsteroid(uint32 beltID, uint32 typeID, double radius, const GPoint& position, bool ice/*false*/) {
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 }
423 
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 }
445 
446 void BeltMgr::GetIceDist(uint8 quarter, float secStatus, std::unordered_multimap<float, uint16>& roidDist)
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 }
536 
537 /* this gives random single point on sphere with radius of 'r'
538  *
539  double theta = MakeRandomFloat(0.0, (2*M_PI) );
540  double phi = MakeRandomFloat(0.0, (2*M_PI) );
541  x += r * sin(theta) * cos(phi);
542  y += r * sin(theta) * sin(phi);
543  z += r * cos(theta);
544 
545 */
546 /* straight line from center
547  *
548  theta += angleSeperation;
549  double theta = MakeRandomFloat(0.0, (theta) );
550  double phi = MakeRandomFloat(0.0, (2*M_PI) );
551  mposition.x += radius * sin(theta) * cos(phi);
552  mposition.y += radius * sin(theta) * sin(phi);
553  mposition.z += radius * cos(theta);
554  */
555 
556 /* up-an-over arc from center
557  *
558  theta += angleSeperation;
559  double theta = MakeRandomFloat(0.0, (theta) );
560  double phi = MakeRandomFloat(0.0, (2*M_PI) );
561  mposition.x += radius * sin(theta) * cos(phi);
562  mposition.y += radius * sin(theta) * sin(phi);
563  mposition.z += radius * cos(theta);
564 */
565 /* this makes triple helix design -allan 7May15
566  *
567  int8 pcs = 0, rand = MakeRandomInt(-10, 20 );
568  if (customCount > 15 )
569  pcs = customCount + rand;
570  else
571  pcs = 30 + rand;
572 
573  float radius = 15000;
574  const double security = 1.1 - m_db.GetSecurity(sys->GetID());
575  radius += (radius * security) *2;
576 
577  GPoint mposition = NULL_ORIGIN;
578  const GPoint position(who->SysBubble()->GetCenter() );
579  double roidradius = 0, thefloat = 0;
580  uint32 theta = 0, angleSeperation = floor(180 /pcs);
581 
582  for (uint32 i = 0; i < pcs; ++i) {
583  roidradius = 3000;
584 
585  if (makeIceBelt) {
586  thefloat = MakeRandomFloat(1.0, 5.0 );
587  roidradius += thefloat * 1000;
588  roidradius *= 5;
589  } else {
590  thefloat = MakeRandomFloat(1.0, 7.0 );
591  roidradius += thefloat * 1000;
592  }
593  roidradius *= security;
594 
595  theta += angleSeperation;
596  mposition.x = cos(theta) *radius + (roidradius *2) + MakeRandomFloat(-1000, 5000 );
597  mposition.z = sin(theta) *radius + (roidradius *2) + MakeRandomFloat(-3000, 5000 );
598  mposition.y += MakeRandomFloat(-2000, 3000 ) + roidradius;
599 
600  SpawnAsteroid(sys, GetAsteroidType(MakeRandomFloat(), roidDist ), roidradius, position + mposition );
601  sLog.Warning("Command_spawnbelt", "roidradius: %.2f, mpos: %.2f, %.2f, %.2f, angleSeperation: %u, theta: %u",
602  roidradius, mposition.x, mposition.y, mposition.z, angleSeperation, theta );
603  }
604 
605 */
606 /*
607  for (uint32 i = 0; i < pcs; ++i) {
608  roidradius = MakeRandomFloat(1.0, 7.0 ) *1000 *security +secRad;
609  theta = MakeRandomFloat(0.0, M_PI );
610  phi = MakeRandomFloat(0.0, M_PI );
611  mposition.x = radius * sin(theta) * cos(phi);
612  mposition.z = radius * sin(theta) * sin(phi);
613  mposition.y = MakeRandomInt(-security, security) *100;
614 */
615 
616  /*
617  * triple helix
618  uint32 theta = 0, angleSeperation = floor(180 /pcs);
619  theta += angleSeperation;
620  mposition.x = cos(theta) *radius + (roidradius *2) + MakeRandomFloat(-1000, 5000 );
621  mposition.z = sin(theta) *radius + (roidradius *2) + MakeRandomFloat(-3000, 5000 );
622  mposition.y += MakeRandomFloat(-2000, 3000 ) + roidradius;
623 
624  TODO: make neocom note "there is odd vortex here..", then make ships drift! (and update position)
625  */
626  /*
627  * flat circle @ 50k
628  uint32 theta = 0, angleSeperation = floor(180 /pcs);
629  theta += angleSeperation;
630  mposition.x = radius * cos(theta);
631  mposition.z = radius * sin(theta);
632  */
633  /*
634  * ufo style
635  uint32 theta = 0, angleSeperation = floor(180 /pcs);
636  phi += angleSeperation;
637  if (phi > 90)
638  theta = phi - 180;
639  else
640  theta = phi;
641 
642  mposition.x = radius * sin(theta) + (roidradius /3);
643  mposition.z = radius * cos(phi) + (roidradius /3);
644  mposition.y = MakeRandomInt(-secRad, secRad);
645  */
646  /*
647  * diagonal
648  uint32 theta = 0, angleSeperation = floor(180 /pcs);
649  phi += angleSeperation;
650  if (phi > 90)
651  theta = phi - 180;
652  else
653  theta = phi;
654 
655  mposition.x = radius * sin(theta);// + (roidradius /3);
656  mposition.z = radius * cos(phi);// + (roidradius /3);
657  mposition.y = MakeRandomInt(-secRad, secRad);
658  */
659 
660  /* idea...
661  * huge rock in center, with smaller rocks in 'orbit' at various angles
662  */
#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
void AddEntity(SystemEntity *pSE, bool addSignal=true)
bool Load(uint16 bubbleID)
Definition: BeltMgr.cpp:139
#define _log(type, fmt,...)
Definition: logsys.h:124
void Init(uint32 regionID)
Definition: BeltMgr.cpp:36
const double Pi
Definition: Trig.h:20
#define IsCelestialID(itemID)
Definition: EVE_Defines.h:288
SystemBubble * SysBubble()
Definition: SystemEntity.h:195
void SetMgr(BeltMgr *beltMgr, uint32 beltID)
Definition: Asteroid.h:102
double MakeRandomFloat(double low, double high)
Generates random real from interval [low; high].
Definition: misc.cpp:114
void ClearAll()
Definition: BeltMgr.cpp:71
void Save()
Definition: BeltMgr.cpp:187
void GetList(uint32 beltID, std::vector< AsteroidSE * > &list)
Definition: BeltMgr.cpp:221
bool Create(CosmicSignature &sig, std::unordered_multimap< float, uint16 > &roidTypes)
Definition: BeltMgr.cpp:244
void Process()
Definition: BeltMgr.cpp:125
const float GetSystemSecurityRating()
Definition: SystemManager.h:86
uint32 GetID() const
Definition: SystemManager.h:80
ManagerDB m_db
Definition: BeltMgr.h:59
bool IsActive(uint16 bubbleID)
Definition: BeltMgr.cpp:105
signed __int8 int8
Definition: eve-compat.h:45
std::map< uint32, InventoryItemRef > m_belts
Definition: BeltMgr.h:81
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
uint32 m_systemID
Definition: BeltMgr.h:73
std::unordered_multimap< uint32, AsteroidSE * > m_asteroids
Definition: BeltMgr.h:83
Definition: gpoint.h:33
bool IsSpawned(uint16 bubbleID)
Definition: BeltMgr.cpp:96
double GetTimeUSeconds()
Definition: utils_time.cpp:116
SystemManager * m_system
Definition: BeltMgr.h:69
InventoryItemRef GetSelf()
Definition: SystemEntity.h:202
double Deg2Rad(double deg)
Definition: Trig.h:25
BeltMgr(SystemManager *mgr, PyServiceMgr &svc)
Definition: BeltMgr.cpp:28
uint16 GetID()
Definition: SystemBubble.h:91
static const GPoint NULL_ORIGIN(0, 0, 0)
void RemoveEntity(SystemEntity *pSE)
void SetBelt(InventoryItemRef itemRef)
bool m_initialized
Definition: BeltMgr.h:72
float GetSecValue()
uint32 GetID()
Definition: SystemEntity.h:207
bool Check(bool reset=true)
Definition: timer.cpp:62
X * get() const
Definition: RefPtr.h:213
void SpawnBelt(uint16 bubbleID, std::unordered_multimap< float, uint16 > &roidTypes, int type=0, bool anomaly=false)
Definition: BeltMgr.cpp:255
unsigned __int32 uint32
Definition: eve-compat.h:50
static AsteroidItemRef SpawnTemp(ItemData &idata, AsteroidData &adata)
Definition: Asteroid.cpp:54
PyServiceMgr * GetServiceMgr()
Definition: SystemManager.h:88
void RemoveAsteroid(uint32 asteroidID)
Definition: ManagerDB.cpp:539
void ClearBelt(uint16 bubbleID)
Definition: BeltMgr.cpp:66
void RemoveAsteroid(uint32 beltID, AsteroidSE *pASE)
Definition: BeltMgr.cpp:424
void SetActive(uint16 bubbleID, bool active=true)
Definition: BeltMgr.cpp:114
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
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
#define sItemFactory
Definition: ItemFactory.h:165
std::map< uint32, bool > m_spawned
Definition: BeltMgr.h:77
void RegisterBelt(InventoryItemRef itemRef)
Definition: BeltMgr.cpp:57
bool LoadSystemRoids(uint32 systemID, uint32 &beltID, std::vector< AsteroidData > &into)
Definition: ManagerDB.cpp:508
uint16 GetTypeID()
Definition: SystemEntity.h:203
uint32 GetAsteroidType(double p, const std::unordered_multimap< float, uint16 > &roids)
Definition: BeltMgr.cpp:362
#define sBubbleMgr
unsigned __int16 uint16
Definition: eve-compat.h:48
std::string itemName
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
Timer m_respawnTimer
Definition: BeltMgr.h:60
const char * GetSystemSecurityClass()
Definition: SystemManager.h:85
Reference-counting-based smart pointer.
Definition: RefPtr.h:133
void CheckSpawn(uint16 bubbleID)
Definition: BeltMgr.cpp:82
#define sDataMgr
bool IsNaN(double x)
Definition: misc.h:89
void Start(uint32 setTimerTime=0, bool changeResetTimer=true)
Definition: timer.cpp:81