EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Planet.cpp
Go to the documentation of this file.
1 
11  /*
12  * PLANET__ERROR
13  * PLANET__WARNING
14  * PLANET__MESSAGE
15  * PLANET__DEBUG
16  * PLANET__INFO
17  * PLANET__TRACE
18  * PLANET__DUMP
19  * PLANET__RES_DUMP
20  * PLANET__GC_DUMP
21  * PLANET__PKT_TRACE
22  * PLANET__DB_ERROR
23  * PLANET__DB_WARNING
24  */
25 
26 
27 #include "Client.h"
28 #include "EVEServerConfig.h"
29 #include "planet/Colony.h"
30 #include "planet/Planet.h"
31 #include "planet/PlanetMgr.h"
32 #include "planet/CustomsOffice.h"
33 #include "packets/Planet.h"
34 #include "pos/Structure.h"
35 #include "system/Celestial.h"
36 #include "system/SystemManager.h"
37 
38 
40 {
42 }
43 
44 
46 : StaticSystemEntity(self, services, system),
47 pCO(nullptr)
48 {
50 }
51 
53 {
54  for (auto cur : m_colonies) {
55  cur.second->Shutdown();
56  SafeDelete(cur.second);
57  }
58 }
59 
62  return false;
63 
67  std::vector<uint16> typeIDs;
68  sPlanetDataMgr.GetPlanetData(m_self->typeID(), typeIDs);
69  m_data.type_1 = typeIDs.at(0);
70  m_data.type_2 = typeIDs.at(1);
71  m_data.type_3 = typeIDs.at(2);
72  m_data.type_4 = typeIDs.at(3);
73  m_data.type_5 = typeIDs.at(4);
74 
77  /* quality: (min=1.0, max=154.275) */
78  // these are relative indicators of material quantity. makes no difference to ecu or extraction amount
79  // as system matures, we will begin adjusting these (from extractor data) and saving per planet
80  float sysSec = (1.1 - m_system->GetSystemSecurityRating()); // 0.1 - 2.0
81  int min = round(sysSec *10);
82  m_data.dist_1 = MakeRandomInt(min, 75) * sysSec + MakeRandomFloat(0, 4);
83  m_data.dist_2 = MakeRandomInt(min, 75) * sysSec + MakeRandomFloat(0, 4);
84  m_data.dist_3 = MakeRandomInt(min, 75) * sysSec + MakeRandomFloat(0, 4);
85  m_data.dist_4 = MakeRandomInt(min, 75) * sysSec + MakeRandomFloat(0, 4);
86  m_data.dist_5 = MakeRandomInt(min, 75) * sysSec + MakeRandomFloat(0, 4);
87 
88  //if (sysSec > 1) {
89  for (uint16 i=0; i<3600; ++i) //this cannot use numList
90  m_data.buffer_1 += hexList[MakeRandomInt(0,15)]; // random fill buffer to capacity, 1k8 bytes.
91  for (uint16 i=0; i<3600; ++i)
92  m_data.buffer_2 += hexList[MakeRandomInt(0,15)]; // random fill buffer to capacity, 1k8 bytes.
93  for (uint16 i=0; i<3600; ++i)
94  m_data.buffer_3 += hexList[MakeRandomInt(0,15)]; // random fill buffer to capacity, 1k8 bytes.
95  for (uint16 i=0; i<3600; ++i)
96  m_data.buffer_4 += hexList[MakeRandomInt(0,15)]; // random fill buffer to capacity, 1k8 bytes.
97  for (uint16 i=0; i<3600; ++i)
98  m_data.buffer_5 += hexList[MakeRandomInt(0,15)]; // random fill buffer to capacity, 1k8 bytes.
99  /* } else {
100  for (uint16 i=0; i<1000; ++i) {
101  m_data.buffer_1 += asciiList[MakeRandomInt(0,57)]; // random fill buffer to capacity, 1k8 bytes.
102  m_data.buffer_2 += alphaList[MakeRandomInt(0,26)]; // random fill buffer to capacity, 1k8 bytes.
103  m_data.buffer_3 += numList[MakeRandomInt(0,10)]; // random fill buffer to capacity, 1k8 bytes.
104  m_data.buffer_4 += numList[MakeRandomInt(0,10)]; // random fill buffer to capacity, 1k8 bytes.
105  m_data.buffer_5 += numList[MakeRandomInt(0,10)]; // random fill buffer to capacity, 1k8 bytes.
106  }
107  } */
108 /*
109  for (uint16 i=0; i<800; ++i) {
110  m_data.buffer_1 += std::to_string(0);
111  m_data.buffer_2 += std::to_string(0);
112  m_data.buffer_3 += std::to_string(0);
113  m_data.buffer_4 += std::to_string(0);
114  m_data.buffer_5 += std::to_string(0);
115  }
116 */
122 
123  // should we check for a CO here?
124  // no, it hasnt been loaded at this point
125 
126  return true;
127 }
128 
129 // called from SystemManager::Process() @ 1m
131 {
132  for (auto cur : m_colonies)
133  cur.second->Process();
134 }
135 
136 PyRep* PlanetSE::GetResourceData(Call_ResourceDataDict& dict)
137 {
138  /* from eve/client/script/environment/planet\clientPlanet.py
139  * This method is used to fetch spherical harmonic data for a given
140  * resource type on the current planet.
141  */
142  // will update this to use PI skills (sent in dict) as system grows..not sure how yet.
153  // actual hex from live for "data"
154  //E80E364382F13EBFEC13F03FEB42483F1263B2BF8C94004075360EC19842ACBEC0B7FABF0C5DA73EF4F6E03FC0B21C3EE0D71F3E5206233E8FC6E43E5245E6BFAD29A63F112C81 \
155  BF6038393EFE19C1BF8FA975C2808D093FE0BB5EBF6C9A533FA1DB4FBF04DDAF3D3CE450C0435DB7BCBDDB80BF2EAD783FE028A8C04A733FBF76012BBFEA17FCBFF4F4113E6C7EC9 \
156  3FFB8EDBBE52C084BF04608B3DFA748F3E3715823F5DA7F1BE5FA97B4206CE83BE2597E03FF6AF46BF2F6EA9BE160297BFBD70FB3FC02B75BF66A0AD3FA095213F2ED9033E5B9D50 \
157  BE94BC53BE2C77E9BFDFDDE24066B21F3F5B1A043FC6531D40E2426CBE5012204036F3ACBF4EA60DBFBDDC46BFB469044020D610BFF68E0EBF1145A8BFD3B0063FF43EB7BFAF69DE \
158  3F437B92C14232D1BEA0E45FBFDC639BBE4813C43E476F2D3F3E260F403436BC3EA993B8BFCDE9153F22C3243F0021DCBF9ECB443F619A6EBF824FE03F4118ED3E96AD5C3F9413B5 \
159  3FE8D0CA3D0EE85CBDF3EC6D3E32E5EDBE3DBAA13EB2379BBF18A8233FCFA5E1BE91B0C03FA51AC9BE9F3F593F4B160FC0A817F0BEF1E5AE3F487E6C3F586B943F4921A73FA845FE \
160  BEAE9D103FE725AEBF1B3A9FC14F69733F3B1B04BF18B9AE3FCBF4D0BD447B483F3E1870BFAAA7A1BEEC3C35C076BB1C3F697F493D00C4C7BEE74CFABFA4E6053F972189BCBDC3AE \
161  3F42E984BF85FDBC3E3C9275BF3C07FFBD4C30D0BED828C43E6CF6C3C0C2F5CDBEBD5E3DBFACB29ABFCA75B1BD6A4035BFE537F83E165BD3BD5D3F4FBDACA1F6BF2A97E0BD4C1F44 \
162  3FF054B6BE692C0F3F8EFB933F52BDE4BF5D97D33E4998C8BF22E25BBE581710BF9F093A3E3D8E8F3DBFEF453F9D32443E1B2EAD41B9FB39BFA85A753F73FABFBFE1B155BE01FFBE \
163  BF897341BF715F19BE5739323EC2E50C3FF7A2B23F47499ABF6E4E1E3F93F555BEF51F8E3FBC21C13DC69CE5BFCD1E5DBF997FC23DDB348D3E300E6B3D49D4183FEDE50CBFD2EBAC \
164  BE509C37BE5310D9BF22BFA940BBE2013F9437083FEC5EB33FE79D053E8FB0903F12BB5CBF4D02BC3E26DAC2BF0CD894BDEEB8B7BEAE1F1440564199BEFE322BBFE5F690BE9E1241 \
165  3FDD38A5BFB2AEAC3E3C8681BF19A36F3F3E2C9D3EB039813E46BD47BF200996BE12F0A3BFC1DAFE3E9C5EA4BFAC65223F74A7EBC03047C3BB1CB01ABF15148F3E9B71163E6C545E \
166  3FDB34553F34096E3D6E12A03F3CF08ABFE904303F367E9ABE064D583FEAE2953F3A5DC7BE
167 
168  /*
169  dict.resourceTypeID;
170  dict.advancedPlanetology;
171  dict.oldBand;
172  dict.planetology;
173  dict.remoteSensing;
174  dict.updateTime;
175  */
176  std::map<uint16, std::string>::iterator itr = m_typeBuffers.find(dict.resourceTypeID);
177  if (itr == m_typeBuffers.end())
178  return nullptr;
179  uint16 size = (uint16)pow(dict.newBand, 2) *4;
180  std::string data = itr->second.substr(0, size);
181  // adjust data for system security. not sure how to make it 'less' yet
182  _log(PLANET__DEBUG, "PlanetSE::GetResourceData() for %s (%u) using remoteSense: %u, planetology: %u, advPlanetology: %u - updateTime: %u, proximity: %u, newBand: %u, oldBand: %u, bufferSize: %u", \
183  sPIDataMgr.GetProductName(dict.resourceTypeID), dict.resourceTypeID, dict.remoteSensing, dict.planetology, dict.advancedPlanetology, \
184  dict.updateTime, dict.proximity, dict.newBand, dict.oldBand, size);
185  PyDict* args = new PyDict();
186  args->SetItemString("data", new PyString(data));
187  args->SetItemString("numBands", new PyInt(dict.newBand));
188  args->SetItemString("proximity", new PyInt(dict.proximity));
189  //PyIncRef(args);
190  PyObject* rtn = new PyObject("util.KeyVal", args);
191  if (is_log_enabled(PLANET__RES_DUMP))
192  rtn->Dump(PLANET__RES_DUMP, " ");
193  return rtn;
194 }
195 
197 {
198  PyDict* res = new PyDict();
199  res->SetItem(new PyInt(m_data.type_1), new PyFloat(m_data.dist_1));
200  res->SetItem(new PyInt(m_data.type_2), new PyFloat(m_data.dist_2));
201  res->SetItem(new PyInt(m_data.type_3), new PyFloat(m_data.dist_3));
202  res->SetItem(new PyInt(m_data.type_4), new PyFloat(m_data.dist_4));
203  res->SetItem(new PyInt(m_data.type_5), new PyFloat(m_data.dist_5));
204  if (is_log_enabled(PLANET__RES_DUMP))
205  res->Dump(PLANET__RES_DUMP, " ");
206  return res;
207 }
208 
210  PyDict *args = new PyDict();
211  args->SetItem("planetTypeID", new PyInt(m_self->typeID()));
212  args->SetItem("solarSystemID", new PyInt(m_system->GetID()));
213  args->SetItem("radius", new PyInt(GetRadius()));
214  args->SetItem("planetID", new PyInt(m_self->itemID()));
215  if (pColony->HasColony()) {
216  //pColony->Update();
217  args->SetItem("level", new PyInt(pColony->GetLevel()));
218  args->SetItem("pins", pColony->GetPins());
219  args->SetItem("links", pColony->GetLinks());
220  args->SetItem("routes", pColony->GetRoutes());
221  args->SetItem("currentSimTime", new PyLong(pColony->GetSimTime()));
222  }
223  //PyIncRef(args);
224  PyObject *rtn = new PyObject("util.KeyVal", args);
225  if (is_log_enabled(PLANET__RES_DUMP))
226  rtn->Dump(PLANET__RES_DUMP, " ");
227  return rtn;
228 }
229 
231  // NOTE this gets ALL extractors on this planet
232  // returns typeID, ownerID, latitude?, longitude?
233 
234  DBQueryResult res;
235  // {for ecu in planetID} SELECT `headID`, `typeID`, `ownerID`, `latitude`, `longitude` FROM `piECUHeads`
236  PlanetDB::GetExtractorsForPlanet(planetID, res);
237 
238  PyList* list = new PyList();
239  DBResultRow row;
240  while (res.GetRow(row)) {
241  PyDict* dict(new PyDict());
242  dict->SetItem("pinID", new PyInt(row.GetInt(0)));
243  dict->SetItem("typeID", new PyInt(row.GetInt(1)));
244  dict->SetItem("ownerID", new PyInt(row.GetInt(2)));
245  dict->SetItem("latitude", new PyFloat(row.GetFloat(3)));
246  dict->SetItem("longitude", new PyFloat(row.GetFloat(4)));
247  list->AddItem(new PyObject("util.KeyVal", dict));
248  }
249 
250  if (is_log_enabled(PLANET__RES_DUMP))
251  list->Dump(PLANET__RES_DUMP, " ");
252  return list;
253 }
254 
256 {
257  std::map<uint32, Colony*>::const_iterator itr = m_colonies.find(pClient->GetCharacterID());
258  if (itr != m_colonies.end())
259  return itr->second;
260  Colony* pColony = new Colony(&m_services, pClient, this);
261  m_colonies[pClient->GetCharacterID()] = pColony;
262 
263  return pColony;
264 }
265 
267 {
268  pColony->AbandonColony();
269  m_colonies.erase(pColony->GetOwner());
270 }
271 
273 {
283  //ItemData( uint32 _typeID, uint32 _ownerID, uint32 _locationID, EVEItemFlags _flag, uint32 _quantity, const char *_customInfo = "", bool _contraband = false);
284  FactionData data = FactionData();
285  data.ownerID = corpInterbus;
286  data.factionID = factionInterBus;
287  data.allianceID = 0;
290 
291  if (m_system->GetSystemSecurityRating() > 0.49) {
293  data.ownerID = corpCONCORD;
294  data.factionID = factionCONCORD; //sDataMgr.GetRegionFaction(m_system->GetRegionID());
295  data.allianceID = 0;
296  data.corporationID = corpCONCORD;
297  }
298 
299  /* this puts CO in warp-in bubble
300  // calculate warp-in point
301  GPoint pos = GetPosition();
302  uint32 radius = m_self->radius();
303  srandom(m_self->itemID());
304  int64 rand = random();
305  double j = (((rand / RAND_MAX) -1.0) / 3.0);
306  double s = 20 * pow(0.025 * (10 * log10(radius/1000000) -39), 20) +0.5;
307  s = EvE::max(0.5, EvE::min(s, 10.5));
308  double t = asin((pos.x/fabs(pos.x)) * (pos.z / sqrt(pow(pos.x, 2) + pow(pos.z, 2)))) +j;
309  uint32 d = radius * (s +1) +10000;
310  pos.x += d * sin(t);
311  pos.y += 0.5 * radius * sin(j);
312  pos.z -= d * cos(t);
313  // put CO 50km closer to planet than warpIn point.
314  GVector dir(pos, m_self->position());
315  dir.normalize();
316  pos -= (dir * 50000);
317  */
318  // this puts CO in random 700km orbit around planet
319  GPoint pos(GetPosition());
320  //pos.MakeRandomPointOnSphere(GetRadius() + 700000);
321 
322  //uint32 dist = BUBBLE_RADIUS_METERS + 10000/*m_self->GetAttribute(AttrMoonAnchorDistance).get_int()*/;
323  uint32 radius = GetRadius();
324  float rad = EvE::Trig::Deg2Rad(25);
325 
326  pos.x += radius + 700000 * std::sin(rad);
327  pos.z += radius + 700000 * std::cos(rad);
328  pos.y += MakeRandomInt(-1000, 1000);
329 
330  ItemData idata(typeID, data.ownerID, m_system->GetID(), flagNone, 1, itoa(m_self->itemID()), false);
331  StructureItemRef iRef = sItemFactory.SpawnStructure(idata);
332  iRef->SetPosition(pos);
333  iRef->ChangeSingleton(true, false);
334  iRef->SaveItem();
335  pCO = new CustomsSE(iRef, m_services, m_system, data);
336  pCO->Init();
338 }
Base Python wire object.
Definition: PyRep.h:66
PlanetSE(InventoryItemRef self, PyServiceMgr &services, SystemManager *system)
Definition: Planet.cpp:45
PlanetResourceData m_data
Definition: Planet.h:74
void AddEntity(SystemEntity *pSE, bool addSignal=true)
void AbandonColony(Colony *pColony)
Definition: Planet.cpp:266
#define _log(type, fmt,...)
Definition: logsys.h:124
int64 GetSimTime()
Definition: Colony.h:92
float GetFloat(uint32 index) const
Definition: dbcore.cpp:682
Python string.
Definition: PyRep.h:430
double GetRadius()
Definition: SystemEntity.h:208
int32 GetInt(uint32 index) const
Definition: dbcore.cpp:635
std::string buffer_2
Definition: EVE_Planet.h:111
Python's dictionary.
Definition: PyRep.h:719
double min(double x, double y)
Definition: misc.h:95
int8 GetLevel()
Definition: Colony.h:91
#define sPIDataMgr
Definition: PlanetDataMgr.h:79
double MakeRandomFloat(double low, double high)
Generates random real from interval [low; high].
Definition: misc.cpp:114
virtual void Init()
Python floating point number.
Definition: PyRep.h:292
int32 GetCharacterID() const
Definition: Client.h:113
uint32 GetOwner()
Definition: Colony.cpp:249
PyServiceMgr & m_services
Definition: SystemEntity.h:267
const float GetSystemSecurityRating()
Definition: SystemManager.h:86
uint32 GetID() const
Definition: SystemManager.h:80
GaFloat x
Definition: GaTypes.h:207
PyRep * GetResourceData(Call_ResourceDataDict &dict)
Definition: Planet.cpp:136
void Dump(FILE *into, const char *pfx) const
Dumps object to file.
Definition: PyRep.cpp:84
const GPoint & GetPosition() const
Definition: SystemEntity.h:211
void AddItem(PyRep *i)
Definition: PyRep.h:701
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
PyRep * GetPlanetResourceInfo()
Definition: Planet.cpp:196
signed __int32 int32
Definition: eve-compat.h:49
PyTuple * GetLinks()
Definition: Colony.cpp:1277
Definition: Colony.h:38
bool HasColony()
Definition: Colony.h:89
* args
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
#define is_log_enabled(type)
Definition: logsys.h:78
Definition: gpoint.h:33
InventoryItemRef m_self
Definition: SystemEntity.h:269
virtual bool LoadExtras()
Definition: Planet.cpp:60
PyTuple * GetRoutes()
Definition: Colony.cpp:1293
Python object.
Definition: PyRep.h:826
double Deg2Rad(double deg)
Definition: Trig.h:25
Python integer.
Definition: PyRep.h:231
SystemManager * m_system
Definition: SystemEntity.h:263
static const char hexList[]
Definition: EVE_Consts.h:18
Definition: Client.h:66
virtual void Process()
Definition: Planet.cpp:130
unsigned __int32 uint32
Definition: eve-compat.h:50
virtual ~PlanetSE()
Definition: Planet.cpp:52
uint32 corporationID
void CreateCustomsOffice()
Definition: Planet.cpp:272
void AbandonColony()
Definition: Colony.cpp:341
PyTuple * GetPins()
Definition: Colony.cpp:1206
GaFloat y
Definition: GaTypes.h:207
std::string buffer_3
Definition: EVE_Planet.h:112
Colony * GetColony(Client *pClient)
Definition: Planet.cpp:255
int64 MakeRandomInt(int64 low, int64 high)
Generates random integer from interval [low; high].
Definition: misc.cpp:109
PyRep * GetPlanetInfo(Colony *pColony)
Definition: Planet.cpp:209
std::string buffer_5
Definition: EVE_Planet.h:114
std::map< uint16, std::string > m_typeBuffers
Definition: Planet.h:77
std::string buffer_4
Definition: EVE_Planet.h:113
virtual bool LoadExtras()
#define sItemFactory
Definition: ItemFactory.h:165
std::string buffer_1
Definition: EVE_Planet.h:110
CustomsSE * pCO
Definition: Planet.h:73
static void GetExtractorsForPlanet(uint32 planetID, DBQueryResult &res)
Definition: PlanetDB.cpp:194
PyRep * GetExtractorsForPlanet(int32 planetID)
Definition: Planet.cpp:230
unsigned __int16 uint16
Definition: eve-compat.h:48
void SetItem(PyRep *key, PyRep *value)
SetItem adds or sets a database entry.
Definition: PyRep.cpp:713
uint16 typeID() const
#define sPlanetDataMgr
Definition: PlanetDataMgr.h:41
Python list.
Definition: PyRep.h:639
GaFloat z
Definition: GaTypes.h:207
const char * itoa(int64 num)
Convers num to string.
uint32 itemID() const
Definition: InventoryItem.h:98
Planet()
Definition: Planet.cpp:39
std::map< uint32, Colony * > m_colonies
Definition: Planet.h:84
Python long integer.
Definition: PyRep.h:261