-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEveMap.cpp
More file actions
342 lines (293 loc) · 9.79 KB
/
EveMap.cpp
File metadata and controls
342 lines (293 loc) · 9.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
// Copyright © 2014 CCP ehf.
#include "stdafx.h"
#include "EveMap.h"
EveMap::EveMap():
m_systemCount( 0 )
{
}
// -------------------------------------------------------------
// Description:
// Create a region in the map. This must be done prior to creating
// children constellations or solar systems.
// Arguments:
// regionID - itemID of the region
// Return Value:
// Success or failure
// -------------------------------------------------------------
Be::Result<PRESULT> EveMap::CreateRegion( unsigned regionID )
{
EveMapNode newNode;
newNode.m_itemID = regionID;
newNode.m_jumpCount = 0;
newNode.m_type = EveMapNode::REGION;
m_nodes.push_back( newNode );
AddLastEveMapNodeIDToLookup(regionID);
return Be::Result<PRESULT>( PRESULT_OK );
}
// -------------------------------------------------------------
// Description:
// Create a constellation in the map. This must be done prior to creating
// children solar systems.
// Arguments:
// constellationID - itemID of the constellation
// regionID - the itemID of the parent region. This must already have been created.
// Return Value:
// Success or failure
// -------------------------------------------------------------
Be::Result<PRESULT> EveMap::CreateConstellation( unsigned constellationID, unsigned int regionID )
{
EveMapNode newNode;
newNode.m_itemID = constellationID;
newNode.m_jumpCount = 0;
newNode.m_type = EveMapNode::CONSTELLATION;
EveMapNodeID parent;
if( !GetNodeID( regionID, parent ) )
{
return Be::Result<PRESULT>( PRESULT_INVALID_ID );
}
newNode.m_parent = parent;
m_nodes.push_back( newNode );
AddLastEveMapNodeIDToLookup(constellationID);
return Be::Result<PRESULT>( PRESULT_OK );
}
// -------------------------------------------------------------
// Description:
// Create a solar system in the map.
// Arguments:
// solarSystemID - itemID of the solar system
// constellationID - the itemID of the parent constellation. This must already have been created.
// Return Value:
// Success or failure
// -------------------------------------------------------------
Be::Result<PRESULT> EveMap::CreateSystem( unsigned solarSystemID, unsigned constellationID, float security )
{
EveMapNode newNode;
newNode.m_itemID = solarSystemID;
newNode.m_jumpCount = 0;
newNode.m_type = EveMapNode::SOLAR_SYSTEM;
newNode.m_jumpsOffset = 0;
newNode.m_trueSecRating = security;
if( !GetConstellationID( constellationID, newNode.m_parent ) )
{
return Be::Result<PRESULT>( PRESULT_INVALID_ID );
}
m_nodes.push_back( newNode );
AddLastEveMapNodeIDToLookup(solarSystemID);
return Be::Result<PRESULT>( PRESULT_OK );
}
// -------------------------------------------------------------
// Description:
// Add a jump from one solar system to another.
// Arguments:
// solarSystemID - EveMapNodeID of the solar system to jump from
// toSystemID - EveMapNodeID of the solar system to jump to
// jumpGateID - the itemID of the jumpgate
// Return Value:
// Success or failure
// -------------------------------------------------------------
Be::Result<PRESULT> EveMap::AddJump( unsigned fromID, unsigned toID, unsigned jumpGateID )
{
EveMapNodeID fromNodeID;
CHECK_RETURN_GET_SYSTEM( GetSolarSystemID(fromID, fromNodeID) );
EveMapNodeID toNodeID;
CHECK_RETURN_GET_SYSTEM( GetSolarSystemID(toID, toNodeID) );
EveMapNode& from = m_nodes[fromNodeID.m_mapNodeOffset];
if( from.m_jumpCount == 0 )
{
// no jumps yet
EveSolarSystemJump newJump;
newJump.m_starGateItemID = jumpGateID;
newJump.m_toSystemID = toNodeID;
m_jumps.push_back( newJump );
from.m_jumpsOffset = m_jumps.size() - 1;
from.m_jumpCount = 1;
return Be::Result<PRESULT>( PRESULT_OK );
}
else
{
// Not so efficient, unless the jumps for a system are all added in one block!
EveSolarSystemJump newJump;
newJump.m_starGateItemID = jumpGateID;
newJump.m_toSystemID = toNodeID;
// insert at the back of the current list of jumps for this system
// Ideally, this is at the end of the jumps list
m_jumps.insert( m_jumps.begin() + from.m_jumpsOffset + from.m_jumpCount, newJump );
from.m_jumpCount += 1;
// Shift any references down
for( std::vector<EveMapNode>::iterator i = m_nodes.begin(); i != m_nodes.end(); i++ )
{
if( i->m_type == EveMapNode::SOLAR_SYSTEM && i->m_jumpsOffset > from.m_jumpsOffset )
{
i->m_jumpsOffset += 1;
}
}
return Be::Result<PRESULT>( PRESULT_OK );
}
}
// -------------------------------------------------------------
// Description:
// Gets an EveMapNodeID for a given itemID, if it exists
// Arguments:
// itemID - the itemID to look for
// outNode - the EveMapNodeID to initialize
// Return Value:
// Success or failure
// -------------------------------------------------------------
bool EveMap::GetNodeID( unsigned itemID, EveMapNodeID& outNode ) const
{
auto i = m_itemIDToNodeID.find(itemID);
if( i != m_itemIDToNodeID.end() )
{
outNode = i->second;
return true;
}
return false;
}
// -------------------------------------------------------------
// Description:
// Gets an EveMapNodeID for a given constellation itemID, if it exists
// Arguments:
// itemID - the itemID to look for
// outNode - the EveMapNodeID to initialize
// Return Value:
// Success or failure
// -------------------------------------------------------------
bool EveMap::GetConstellationID( unsigned constellationID, EveMapNodeID& constellation ) const
{
EveMapNodeID test;
if( GetNodeID( constellationID, test) )
{
if( m_nodes[ test.m_mapNodeOffset ].m_type == EveMapNode::CONSTELLATION )
{
constellation.m_mapNodeOffset = test.m_mapNodeOffset;
return true;
}
}
return false;
}
// -------------------------------------------------------------
// Description:
// Gets an EveMapNodeID for a given constellation itemID, if it exists
// Arguments:
// itemID - the itemID to look for
// outNode - the EveMapNodeID to initialize
// Return Value:
// Success or failure
// -------------------------------------------------------------
bool EveMap::GetSolarSystemID( unsigned solarSystemID, EveMapNodeID& solarSystem ) const
{
EveMapNodeID test;
if( GetNodeID( solarSystemID, test) )
{
if( m_nodes[ test.m_mapNodeOffset ].m_type == EveMapNode::SOLAR_SYSTEM )
{
solarSystem.m_mapNodeOffset = test.m_mapNodeOffset;
return true;
}
}
return false;
}
// -------------------------------------------------------------
// Description:
// Gets the node information for a solar system given an EveMapNodeID
// Arguments:
// solarSystemID - the EveMapNodeID for the system
// Return Value:
// Const pointer to the EveMapNode data
// -------------------------------------------------------------
EveMapNode const * EveMap::GetSolarSystem( EveMapNodeID solarSystemID ) const
{
return &m_nodes[ solarSystemID.m_mapNodeOffset ];
}
// -------------------------------------------------------------
// Description:
// Gets the node information for a constellation given an EveMapNodeID
// Arguments:
// solarSystemID - the EveMapNodeID for the constellation
// Return Value:
// Const pointer to the EveMapNode data
// -------------------------------------------------------------
EveMapNode const * EveMap::GetConstellation( EveMapNodeID solarSystemID ) const
{
return &m_nodes[ solarSystemID.m_mapNodeOffset ];
}
// -------------------------------------------------------------
// Description:
// Gets the node information for a region given an EveMapNodeID
// Arguments:
// solarSystemID - the EveMapNodeID for the region
// Return Value:
// Const pointer to the EveMapNode data
// -------------------------------------------------------------
EveMapNode const * EveMap::GetRegion( EveMapNodeID solarSystemID ) const
{
return &m_nodes[ solarSystemID.m_mapNodeOffset ];
}
// -------------------------------------------------------------
// Description:
// Gets the count of the number of systems initialized to
// inform the creation of a packed closed list in a contiguous
// vector
// See Also:
// EveMapPathfinderCache
// -------------------------------------------------------------
unsigned int EveMap::GetRequiredClosedListSize() const
{
return m_systemCount;
}
// -------------------------------------------------------------
// Description:
// Gets the count of the number of systems initialized to
// inform the creation of a packed closed list in a contiguous
// vector
// See Also:
// EveMapPathfinderCache
// -------------------------------------------------------------
void EveMap::FinalizeMap()
{
m_systemCount = 0;
std::vector<EveMapNode>::iterator i = m_nodes.begin();
for(; i != m_nodes.end(); ++i )
{
if( i->m_type == EveMapNode::SOLAR_SYSTEM )
{
i->m_closedListID.m_offsetInClosedList = m_systemCount;
++m_systemCount;
}
}
}
// -------------------------------------------------------------
// Description:
// Sets a begin and end const_iterator for the jumps for the given
// systemID.
// -------------------------------------------------------------
bool EveMap::GetJumpsForSystem( EveMapNodeID systemID, std::vector<EveSolarSystemJump>::const_iterator& begin, std::vector<EveSolarSystemJump>::const_iterator& end ) const
{
EveMapNode const * const system = GetSolarSystem( systemID );
if( system )
{
begin = m_jumps.begin() + system->m_jumpsOffset;
end = m_jumps.begin() + system->m_jumpsOffset + system->m_jumpCount;
return true;
}
return false;
}
void EveMap::AddLastEveMapNodeIDToLookup( unsigned itemID )
{
EveMapNodeID last;
last.m_mapNodeOffset = m_nodes.size() - 1;
m_itemIDToNodeID.insert( std::make_pair(itemID, last));
}
// Sets the security level for a solar system
void EveMap::SetSolarSystemSecurity(unsigned solarSystemID, float security)
{
EveMapNodeID nodeID;
if (GetNodeID(solarSystemID, nodeID))
{
if (m_nodes[nodeID.m_mapNodeOffset].m_type == EveMapNode::SOLAR_SYSTEM)
{
EveMapNode& node = m_nodes[nodeID.m_mapNodeOffset];
node.m_trueSecRating = security;
}
}
}