EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MapData.cpp
Go to the documentation of this file.
1 
11 #include "../StaticDataMgr.h"
12 #include "agents/Agent.h"
13 #include "map/MapData.h"
14 #include "map/MapDB.h"
15 #include "station/StationDataMgr.h"
16 
17 #include "../../eve-common/EVE_Map.h"
18 
19 
21 : m_stationExtraInfo(nullptr),
22 m_pseudoSecurities(nullptr)
23 {
24  m_regionJumps.clear();
25  m_constJumps.clear();
26  m_systemJumps.clear();
27 }
28 
30 {
31 }
32 
34 {
37 }
38 
40 {
41  Populate();
42  sLog.Blue(" MapData", "Map Data Manager Initialized.");
43  return 1;
44 }
45 
47 {
48  m_regionJumps.clear();
49  m_constJumps.clear();
50  m_systemJumps.clear();
51 }
52 
54 {
55  // print out list of bad jumps
56  // m_badJumps
57 }
58 
60 {
62 
63  double start = GetTimeMSeconds();
64 
65  m_stationExtraInfo = new PyTuple(3);
69  sLog.Cyan(" MapData", "StationExtraInfo loaded in %.3fms.",(GetTimeMSeconds() - start));
70 
71  start = GetTimeMSeconds();
72  DBQueryResult* res = new DBQueryResult();
74  DBResultRow row;
75  while (res->GetRow(row)) {
76  //SELECT ctype, fromsol, tosol FROM mapConnections
77  if (row.GetInt(0) == Map::Jumptype::Region) {
78  m_regionJumps.emplace(row.GetInt(1), row.GetInt(2));
79  } else if (row.GetInt(0) == Map::Jumptype::Constellation) {
80  m_constJumps.emplace(row.GetInt(1), row.GetInt(2));
81  } else {
82  m_systemJumps.emplace(row.GetInt(1), row.GetInt(2));
83  }
84  }
85 
86  sLog.Cyan(" MapData", "%u Region jumps, %u Constellation jumps and %u System jumps loaded in %.3fms.", //
87  m_regionJumps.size(), m_constJumps.size(), m_systemJumps.size(), (GetTimeMSeconds() - start));
88 
89  // cleanup
90  SafeDelete(res);
91 }
92 
93 
94 
95 void MapData::GetMissionDestination(Agent* pAgent, uint8 misionType, MissionOffer& offer)
96 {
97  using namespace Mission::Type;
98  using namespace Agents::Range;
99 
100  uint8 destRange = offer.range;
101  bool station = true, ship = false; // will have to tweak this later for particular mission events
102 
103  // determine distance based on preset range from db or in some cases, mission type and agent level
104  switch(misionType) {
105  case Tutorial: {
106  // always same system?
107  destRange = SameSystem;
108  } break;
109  case Data:
110  case Trade:
111  case Courier:
112  case Research: {
113  //destRange += m_data.level *2;
114  } break;
115  case Arc:
116  case Anomic:
117  case Burner:
118  case Cosmos: {
119  station = false;
120  destRange += pAgent->GetLevel();
121  } break;
122  case Mining:
123  case Encounter:
124  case Storyline: {
125  station = false;
126  //destRange = offer.range;
127  } break;
128  }
129 
130  switch(destRange) {
131  case 0:
132  case SameSystem: //1
135  case SameConstellation: { //6
136  uint32 systemID = pAgent->GetSystemID();
137  if (station)
138  if (sDataMgr.GetStationCount(systemID) < 2)
139  ++destRange;
140 
141  if ((destRange > 1) or (IsEven(MakeRandomInt(0, 100)))) {
142  // neighboring system
143  bool run = true;
144  uint8 count = 0;
145  std::vector<uint32> sysList;
146  auto itr = m_systemJumps.equal_range(systemID);
147  for (auto it = itr.first; it != itr.second; ++it)
148  sysList.push_back(it->second);
150  if (sysList.empty()) {
151  StationData data = StationData();
152  stDataMgr.GetStationData(pAgent->GetStationID(), data);
153  offer.destinationOwnerID = data.corporationID;
154  offer.destinationSystemID = data.systemID;
155  offer.destinationTypeID = data.typeID;
156  return;
157  }
158 
159  while (run) {
160  run = false;
161  systemID = sysList.at(MakeRandomInt(0, (sysList.size() -1)));
162  if (station and (sDataMgr.GetStationCount(systemID) < 1)) {
163  run = true;
164  ++count;
165  }
166  if (run and (count > sysList.size())) {
167  // problem....no station found within one jump
168  offer.destinationID = 0;
169  _log(AGENT__ERROR, "Agent::GetMissionDestination() - no station found within 1 jump." );
170  return;
171  }
172  }
173  }
174  if (station) {
175  std::vector<uint32> list;
176  sDataMgr.GetStationList(systemID, list);
177  if (list.size() < 2) {
178  offer.destinationID = list.at(0);
179  } else {
180  bool run = true;
181  while (run) {
182  offer.destinationID = list.at(MakeRandomInt(0, (list.size() -1)));
183  if (offer.destinationID != pAgent->GetStationID())
184  run = false;
185  }
186  }
187  } else if (ship) {
188  ; // code here for agent in ship
189  }
190  } break;
191 
192  //may have to create data objects based on constellation to do ranges in neighboring constellation
193  // could use data from mapSolarSystemJumps - fromRegionID, fromConstellationID, fromSolarSystemID, toSolarSystemID, toConstellationID, toRegionID
194 
196  case SameOrNeighboringSystem: //3
197  case NeighboringSystem: { //5
198  uint32 systemID = pAgent->GetSystemID();
199  if (IsEven(MakeRandomInt(0, 100))) {
200  // same constellation
201  } else {
202  // neighboring constellation
203  systemID = 0;
204  }
205  if (ship) {
206  ; // code here for agent in ship
207  }
208  } break;
211  if (station)
212  sDataMgr.GetStationConstellation(pAgent->GetStationID());
213  } break;
215  case NeighboringConstellation: { //10
216  if (station)
217  sDataMgr.GetStationRegion(pAgent->GetStationID());
218  } break;
219  // not sure how to do these two yet....
220  case NearestEnemyCombatZone: { //11
221  } break;
222  case NearestCareerHub: { //12
223  } break;
224  }
225 
226  if (sDataMgr.IsStation(offer.destinationID)) {
227  StationData data = StationData();
228  stDataMgr.GetStationData(offer.destinationID, data);
229  offer.destinationOwnerID = data.corporationID;
230  offer.destinationSystemID = data.systemID;
231  offer.destinationTypeID = data.typeID;
232  } else if (ship) {
233  offer.destinationSystemID = offer.destinationID;
234  offer.destinationTypeID = sDataMgr.GetStaticType(offer.destinationID);
235  offer.dungeonLocationID = offer.destinationID;
236  offer.dungeonSolarSystemID = offer.destinationID;
237  } else {
238  offer.destinationSystemID = offer.destinationID;
239  offer.destinationTypeID = sDataMgr.GetStaticType(offer.destinationID);
240  offer.dungeonLocationID = offer.destinationID;
241  offer.dungeonSolarSystemID = offer.destinationID;
242  }
243 }
MapData()
Definition: MapData.cpp:20
unsigned __int8 uint8
Definition: eve-compat.h:46
std::multimap< uint32, uint32 > m_constJumps
Definition: MapData.h:48
uint32 corporationID
#define _log(type, fmt,...)
Definition: logsys.h:124
#define stDataMgr
int32 GetInt(uint32 index) const
Definition: dbcore.cpp:635
PyTuple * m_stationExtraInfo
Definition: MapData.h:44
uint32 GetSystemID()
Definition: Agent.h:39
static void GetSystemJumps(DBQueryResult &res)
Definition: MapDB.cpp:194
uint16 destinationTypeID
Definition: EVE_Missions.h:40
static PyObject * GetStationOpServices()
Definition: MapDB.cpp:60
std::multimap< uint32, uint32 > m_regionJumps
Definition: MapData.h:47
~MapData()
Definition: MapData.cpp:29
int Initialize()
Definition: MapData.cpp:39
uint32 GetStationID()
Definition: Agent.h:40
Python tuple.
Definition: PyRep.h:567
void Close()
Definition: MapData.cpp:33
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
uint32 destinationSystemID
Definition: EVE_Missions.h:53
uint32 dungeonLocationID
Definition: EVE_Missions.h:54
bool IsEven(int64 number)
Definition: misc.h:88
static PyObject * GetPseudoSecurities()
Definition: MapDB.cpp:31
double GetTimeMSeconds()
Definition: utils_time.cpp:104
Definition: Agent.h:21
void GetMissionDestination(Agent *pAgent, uint8 misionType, MissionOffer &offer)
Definition: MapData.cpp:95
static PyObject * GetStationExtraInfo()
Definition: MapDB.cpp:42
void GetInfo()
Definition: MapData.cpp:53
PyObject * m_pseudoSecurities
Definition: MapData.h:45
itemID[count] Create count or of the specified() x() entityID Translocate to the specified entity Immediately stops ship
unsigned __int32 uint32
Definition: eve-compat.h:50
uint32 destinationOwnerID
Definition: EVE_Missions.h:52
int64 MakeRandomInt(int64 low, int64 high)
Generates random integer from interval [low; high].
Definition: misc.cpp:109
std::multimap< uint32, uint32 > m_systemJumps
Definition: MapData.h:49
uint32 dungeonSolarSystemID
Definition: EVE_Missions.h:55
#define PySafeDecRef(op)
Definition: PyRep.h:61
storage_type items
Definition: PyRep.h:628
uint8 GetLevel()
Definition: Agent.h:34
uint32 destinationID
Definition: EVE_Missions.h:51
void Populate()
Definition: MapData.cpp:59
static PyObject * GetStationServiceInfo()
Definition: MapDB.cpp:72
void Clear()
Definition: MapData.cpp:46
#define sDataMgr