mapSvc.py (20965B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\maps\mapSvc.py 2 import evetypes 3 import eveuniverse.security 4 import fsd.schemas.binaryLoader as fsdBinaryLoader 5 import itertoolsext 6 import telemetry 7 import trinity 8 import uthread 9 import utillib 10 from caching.memoize import Memoize 11 from carbon.common.script.sys import service 12 from carbonui import uiconst 13 from carbonui.control.window import Window 14 from carbonui.util.color import Color 15 from eve.client.script.ui.shared.dockedUI.lobbyWnd import LobbyWnd 16 from eve.client.script.ui.shared.maps.mapcommon import LINESET_EFFECT 17 from eve.client.script.ui.shared.maps.palette import MapPalette 18 from eve.common.script.util.systemExclusions import IsValidDestination 19 from eve.client.script.ui.util import searchUtil 20 from eve.common.lib import appConst as const 21 from eve.common.script.search.const import ResultType 22 from eve.common.script.sys import idCheckers 23 from eve.common.script.sys.idCheckers import IsKnownSpaceSystem, IsKnownSpaceRegion, IsKnownSpaceConstellation 24 from eve.common.script.util import eveFormat 25 26 class MapSvc(service.Service): 27 __guid__ = 'svc.map' 28 __servicename__ = 'map' 29 __displayname__ = 'Map Client Service' 30 __update_on_reload__ = 0 31 __startupdependencies__ = ['settings'] 32 __dependencies__ = ['securitySvc'] 33 __notifyevents__ = ['OnSessionReset'] 34 35 def Run(self, memStream = None): 36 self.state = service.SERVICE_START_PENDING 37 self.LogInfo('Starting Map Client Svc') 38 self.Reset() 39 self.state = service.SERVICE_RUNNING 40 41 def Stop(self, memStream = None): 42 if trinity.device is None: 43 return 44 self.LogInfo('Map svc') 45 self.Reset() 46 47 def Reset(self): 48 self.LogInfo('MapSvc Reset') 49 self.securityInfo = None 50 self.minimizedWindows = [] 51 self.activeMap = '' 52 self.mapconnectionscache = None 53 self.landmarks = None 54 sm.ScatterEvent('OnMapReset') 55 56 def OnSessionReset(self): 57 self.GetJumpBridgesWithMyAccess.clear_memoized() 58 59 def Open(self): 60 viewSvc = sm.GetService('viewState') 61 if not viewSvc.IsViewActive('starmap', 'systemmap'): 62 activeMap = settings.user.ui.Get('activeMap', 'starmap') 63 viewSvc.ActivateView(activeMap) 64 65 def GetActiveMapName(self): 66 return settings.user.ui.Get('activeMap', 'starmap') 67 68 def MinimizeWindows(self): 69 lobby = LobbyWnd.GetIfOpen() 70 if lobby and not lobby.destroyed and lobby.state != uiconst.UI_HIDDEN and not lobby.IsMinimized() and not lobby.IsCollapsed(): 71 lobby.Minimize() 72 self.minimizedWindows.append(LobbyWnd.default_windowID) 73 74 def ResetMinimizedWindows(self): 75 if len(self.minimizedWindows) > 0: 76 windowSvc = sm.GetService('window') 77 for windowID in self.minimizedWindows: 78 wnd = Window.GetIfOpen(windowID=windowID) 79 if wnd and wnd.IsMinimized(): 80 wnd.Maximize() 81 82 self.minimizedWindows = [] 83 84 def Toggle(self, *args): 85 viewSvc = sm.GetService('viewState').ToggleSecondaryView(self.GetActiveMapName()) 86 87 def ToggleMode(self, *args): 88 viewSvc = sm.GetService('viewState') 89 if viewSvc.IsViewActive('starmap'): 90 viewSvc.ActivateView('systemmap') 91 elif viewSvc.IsViewActive('systemmap'): 92 viewSvc.ActivateView('starmap') 93 94 def OpenMapsPalette(self): 95 openMinimized = settings.user.ui.Get('MapWindowMinimized', False) 96 MapPalette.Open(openMinimized=openMinimized) 97 98 def CloseMapsPalette(self): 99 MapPalette.CloseIfOpen() 100 101 def GetSecurityStatus(self, solarSystemID, getColor = False): 102 securityValue = self.GetSystemSecurityValue(solarSystemID) 103 return eveFormat.FmtSystemSecStatus(securityValue, getColor) 104 105 def GetSystemSecurityValue(self, solarSystemID): 106 if self.securityInfo is None: 107 uthread.Lock(self) 108 try: 109 self.securityInfo = {} 110 for systemID, each in cfg.mapSystemCache.iteritems(): 111 self.securityInfo[systemID] = each.pseudoSecurity 112 113 finally: 114 uthread.UnLock(self) 115 116 securityValue = self.securityInfo.get(solarSystemID, 0.0) 117 return securityValue 118 119 def GetSecurityClass(self, solarSystemID): 120 secLevel = self.GetSecurityStatus(solarSystemID) 121 return eveuniverse.security.SecurityClassFromLevel(secLevel) 122 123 @telemetry.ZONE_METHOD 124 def GetSolarsystemItems(self, solarsystemID, requireLocalizedTexts = True, doYields = False): 125 local, structures = uthread.parallel([(cfg.GetLocationsLocalBySystem, (solarsystemID, requireLocalizedTexts, doYields)), (sm.GetService('structureDirectory').GetStructureMapData, (solarsystemID,))], contextSuffix='GetSolarsystemItems') 126 for structure in structures: 127 local.InsertNew(structure) 128 129 return local 130 131 def GetPlanetMoonsInPlayerSystem(self, planetID): 132 if cfg.evelocations.Get(planetID).solarSystemID == session.solarsystemid2: 133 return self._GetMoons(planetID) 134 135 @Memoize 136 def _GetMoons(self, planetID): 137 return [ i for i in self.GetSolarsystemItems(cfg.evelocations.Get(planetID).solarSystemID) if i.groupID == const.groupMoon and i.orbitID == planetID ] 138 139 @Memoize 140 def GetStarGateIDsInSolarSystem(self, solar_system_id): 141 return [ i.itemID for i in self.GetSolarsystemItems(solar_system_id, requireLocalizedTexts=False) if i.groupID == const.groupStargate ] 142 143 def ForEachStarGateIDInSolarSystem(self, solar_system_id, callback): 144 systemInfo = cfg.mapSolarSystemContentCache.get(solar_system_id, None) 145 if not systemInfo: 146 return 147 for gateID in systemInfo.stargates.iterkeys(): 148 callback(gateID) 149 150 def GetMapConnectionCache(self): 151 if self.mapconnectionscache is None: 152 self.mapconnectionscache = settings.user.ui.Get('map_cacheconnectionsfile', {}) 153 return self.mapconnectionscache or {} 154 155 def GetItem(self, itemID, retall = False, categoryID = None): 156 if idCheckers.IsStation(itemID): 157 station = sm.GetService('ui').GetStationStaticInfo(itemID) 158 return utillib.KeyVal(itemID=itemID, locationID=station.solarSystemID, itemName=cfg.evelocations.Get(itemID).name, typeID=station.stationTypeID, groupID=const.groupStation, x=station.x, y=station.y, z=station.z) 159 elif idCheckers.IsSolarSystem(itemID): 160 solarSystem = cfg.mapSystemCache.Get(itemID) 161 return utillib.KeyVal(itemID=itemID, locationID=solarSystem.constellationID, itemName=cfg.evelocations.Get(itemID).name, typeID=const.typeSolarSystem, groupID=const.groupSolarSystem, factionID=getattr(solarSystem, 'factionID', None), neighbours=[ i.solarSystemID for i in solarSystem.neighbours ], x=solarSystem.center.x, y=solarSystem.center.y, z=solarSystem.center.z, security=solarSystem.securityStatus) 162 elif idCheckers.IsConstellation(itemID): 163 constellation = cfg.mapConstellationCache.Get(itemID) 164 return utillib.KeyVal(itemID=itemID, locationID=constellation.regionID, itemName=cfg.evelocations.Get(itemID).name, typeID=const.typeConstellation, neighbours=list(constellation.neighbours), groupID=const.groupConstellation, x=constellation.center.x, y=constellation.center.y, z=constellation.center.z) 165 elif idCheckers.IsRegion(itemID): 166 region = cfg.mapRegionCache.Get(itemID) 167 return utillib.KeyVal(itemID=itemID, locationID=const.locationUniverse, itemName=cfg.evelocations.Get(itemID).name, neighbours=list(region.neighbours), typeID=const.typeRegion, groupID=const.groupRegion, x=region.center.x, y=region.center.y, z=region.center.z) 168 elif idCheckers.IsCelestial(itemID): 169 solarSystemID = cfg.mapCelestialLocationCache[itemID] 170 typeID, pos = self._GetCelestialsTypeIdAndPosition(itemID, solarSystemID) 171 return utillib.KeyVal(itemID=itemID, locationID=solarSystemID, itemName=cfg.evelocations.Get(itemID).name, typeID=typeID, x=pos[0], y=pos[1], z=pos[2]) 172 elif categoryID and categoryID != const.categoryStructure: 173 return 174 elif not cfg.evelocations.GetIfExists(itemID): 175 return 176 else: 177 structureInfo = sm.GetService('structureDirectory').GetStructureInfo(itemID) 178 if structureInfo is None: 179 return 180 locationInfo = cfg.evelocations.Get(itemID) 181 return utillib.KeyVal(itemID=itemID, locationID=locationInfo.solarSystemID, itemName=structureInfo.itemName, typeID=structureInfo.typeID, groupID=evetypes.GetGroupID(structureInfo.typeID), x=locationInfo.x, y=locationInfo.y, z=locationInfo.z) 182 183 def _GetCelestialsTypeIdAndPosition(self, itemID, solarSystemID): 184 if itemID in cfg.mapSolarSystemContentCache.celestials: 185 celestial = cfg.mapSolarSystemContentCache.celestials[itemID] 186 return (celestial.typeID, celestial.position) 187 solarSystem = cfg.mapSolarSystemContentCache[solarSystemID] 188 if itemID == solarSystem.star.id: 189 return (solarSystem.star.typeID, (0.0, 0.0, 0.0)) 190 raise KeyError('Celestial with id %s not found' % itemID) 191 192 @telemetry.ZONE_METHOD 193 def GetParentLocationID(self, locationID): 194 if idCheckers.IsSolarSystem(locationID): 195 solarSystem = cfg.mapSystemCache.Get(locationID) 196 return (const.locationUniverse, 197 solarSystem.regionID, 198 solarSystem.constellationID, 199 locationID, 200 None) 201 if idCheckers.IsConstellation(locationID): 202 constellation = cfg.mapConstellationCache.Get(locationID) 203 return (const.locationUniverse, 204 constellation.regionID, 205 locationID, 206 None, 207 None) 208 if idCheckers.IsRegion(locationID): 209 return (const.locationUniverse, 210 locationID, 211 None, 212 None, 213 None) 214 if idCheckers.IsCelestial(locationID): 215 solarSystemID = cfg.mapCelestialLocationCache[locationID] 216 solarSystem = cfg.mapSystemCache.Get(solarSystemID) 217 return (const.locationUniverse, 218 solarSystem.regionID, 219 solarSystem.constellationID, 220 solarSystemID, 221 locationID) 222 if idCheckers.IsStation(locationID): 223 station = cfg.stations.Get(locationID) 224 ssID = station.solarSystemID 225 solarSystem = cfg.mapSystemCache.Get(ssID) 226 return (const.locationUniverse, 227 solarSystem.regionID, 228 solarSystem.constellationID, 229 ssID, 230 locationID) 231 ssID = cfg.evelocations.Get(locationID).solarSystemID 232 if ssID is None: 233 structureInfo = sm.GetService('structureDirectory').GetStructureInfo(locationID) 234 if structureInfo is not None: 235 ssID = structureInfo.solarSystemID 236 if ssID is not None: 237 mapData = cfg.mapSystemCache.Get(ssID) 238 return (const.locationUniverse, 239 mapData.regionID, 240 mapData.constellationID, 241 ssID, 242 locationID) 243 return (const.locationUniverse, 244 None, 245 None, 246 None, 247 locationID) 248 249 def FindByName(self, searchstr, ignorecommas = 1): 250 searchGroupList = [ResultType.constellation, ResultType.solar_system, ResultType.region] 251 results = searchUtil.GetResultsList(searchstr, searchGroupList) 252 return map(self.GetItem, results) 253 254 def GetLandmarks(self): 255 if self.landmarks is None: 256 self.landmarks = fsdBinaryLoader.LoadFSDDataForCFG('res:/staticdata/landmarks.static') 257 return self.landmarks 258 259 def GetLandmark(self, landmarkID): 260 return self.GetLandmarks()[landmarkID] 261 262 def GetNeighbors(self, itemID): 263 if not (IsKnownSpaceSystem(itemID) or IsKnownSpaceConstellation(itemID) or IsKnownSpaceRegion(itemID)): 264 return [] 265 if not IsValidDestination(itemID): 266 return [] 267 if idCheckers.IsSolarSystem(itemID): 268 solarSystem = cfg.mapSystemCache.Get(itemID) 269 return [ i.solarSystemID for i in solarSystem.neighbours ] 270 if idCheckers.IsConstellation(itemID): 271 constellation = cfg.mapConstellationCache.Get(itemID) 272 return constellation.neighbours 273 if idCheckers.IsRegion(itemID): 274 region = cfg.mapRegionCache.Get(itemID) 275 return region.neighbours 276 return [] 277 278 def GetParent(self, itemID): 279 if idCheckers.IsSolarSystem(itemID): 280 solarSystem = cfg.mapSystemCache.Get(itemID) 281 return solarSystem.constellationID 282 elif idCheckers.IsConstellation(itemID): 283 constellation = cfg.mapConstellationCache.Get(itemID) 284 return constellation.regionID 285 elif idCheckers.IsRegion(itemID): 286 return const.locationUniverse 287 elif idCheckers.IsCelestial(itemID): 288 return cfg.mapCelestialLocationCache[itemID] 289 elif idCheckers.IsStation(itemID): 290 station = cfg.stations.Get(itemID) 291 return station.solarSystemID 292 else: 293 return None 294 295 def GetRegionForSolarSystem(self, solarSystemID): 296 if idCheckers.IsSolarSystem(solarSystemID): 297 solarSystem = cfg.mapSystemCache.Get(solarSystemID) 298 return solarSystem.regionID 299 else: 300 return None 301 302 def GetConstellationForSolarSystem(self, solarSystemID): 303 if idCheckers.IsSolarSystem(solarSystemID): 304 solarSystem = cfg.mapSystemCache.Get(solarSystemID) 305 return solarSystem.constellationID 306 else: 307 return None 308 309 def GetLocationChildren(self, itemID): 310 if idCheckers.IsConstellation(itemID): 311 return cfg.mapConstellationCache.Get(itemID).solarSystemIDs 312 if idCheckers.IsRegion(itemID): 313 return cfg.mapRegionCache.Get(itemID).constellationIDs 314 raise Exception('Unexpected itemID calling GetLocationChildren?' + str(itemID)) 315 316 def ExpandItems(self, itemIDs): 317 ret = [] 318 for i in itemIDs: 319 ret.extend(self.GetSolarSystemIDsIn(i)) 320 321 return ret 322 323 def GetSolarSystemIDsIn(self, i): 324 if idCheckers.IsSolarSystem(i): 325 return [i] 326 if idCheckers.IsConstellation(i): 327 return list(cfg.mapConstellationCache.Get(i).solarSystemIDs) 328 if idCheckers.IsRegion(i): 329 return list(cfg.mapRegionCache.Get(i).solarSystemIDs) 330 331 def GetKnownspaceRegions(self): 332 for regionID in cfg.mapRegionCache.iterkeys(): 333 if not IsValidDestination(regionID): 334 continue 335 if IsKnownSpaceRegion(regionID): 336 yield regionID 337 338 def IterateKnownspaceRegions(self): 339 for regionID, region in cfg.mapRegionCache.iteritems(): 340 if not IsValidDestination(regionID): 341 continue 342 if IsKnownSpaceRegion(regionID): 343 yield (regionID, region) 344 345 def GetSleeperspaceRegions(self): 346 for regionID in cfg.mapRegionCache.iterkeys(): 347 if regionID >= const.mapWormholeRegionMin: 348 yield regionID 349 350 def GetNumberOfStargates(self, itemID): 351 return len(cfg.mapSolarSystemContentCache[itemID].stargates) 352 353 def IterateSolarSystemIDs(self, itemID = None): 354 if itemID is None: 355 for regionID in self.GetKnownspaceRegions(): 356 for s in cfg.mapRegionCache.Get(regionID).solarSystemIDs: 357 yield s 358 359 elif idCheckers.IsSolarSystem(itemID): 360 yield itemID 361 elif idCheckers.IsConstellation(itemID): 362 for systemID in cfg.mapConstellationCache.Get(itemID).solarSystemIDs: 363 yield systemID 364 365 elif idCheckers.IsRegion(itemID): 366 for systemID in cfg.mapRegionCache.Get(itemID).solarSystemIDs: 367 yield systemID 368 369 def IterateKnownSpaceSolarSystems(self): 370 for systemID, system in cfg.mapSystemCache.iteritems(): 371 if not IsValidDestination(systemID): 372 continue 373 if IsKnownSpaceSystem(systemID): 374 yield (systemID, system) 375 376 def GetInfoOnPilotsBySolarSystemIDs(self): 377 sol, sta, statDivisor = sm.ProxySvc('machoNet').GetClusterGameStatisticsForClient('EVE', ({}, {}, 0)) 378 ret = {} 379 for sfoo in sol.iterkeys(): 380 dockedInStationRawCount = sta.get(sfoo, 0) 381 inSystemRawCount = sol.get(sfoo, 0) 382 inSpaceRawCount = inSystemRawCount - dockedInStationRawCount 383 amountDocked = dockedInStationRawCount / float(statDivisor) 384 amountInSpace = inSpaceRawCount / float(statDivisor) 385 amountDockedRounded = round(amountDocked) 386 amountInSpaceRounded = round(amountInSpace) 387 solarSystemID = sfoo + 30000000 388 ret[solarSystemID] = itertoolsext.Bundle(amountDocked=amountDockedRounded, amountInSpace=amountInSpaceRounded) 389 390 return ret 391 392 def GetPlanetInfo(self, planetID, hierarchy = False): 393 p = cfg.mapSolarSystemContentCache.planets[planetID] 394 typeID = p.typeID 395 solarSystemID = p.solarSystemID 396 info = utillib.KeyVal(solarSystemID=solarSystemID, typeID=typeID) 397 if hierarchy: 398 u, regionID, constellationID, s, i = self.GetParentLocationID(solarSystemID) 399 info.regionID = regionID 400 info.constellationID = constellationID 401 return info 402 403 def IteratePlanetInfo(self): 404 for planetID, planetData in cfg.mapSolarSystemContentCache.planets.iteritems(): 405 yield self.PlanetInfo(planetID, planetData.solarSystemID, planetData.typeID) 406 407 @Memoize(5) 408 def GetJumpBridgesWithMyAccess(self): 409 return sm.RemoteSvc('structureDirectory').GetJumpBridgesWithMyAccess() 410 411 def CreateLineSet(self, path = LINESET_EFFECT): 412 lineSet = trinity.EveLineSet() 413 lineSet.effect = trinity.Tr2Effect() 414 lineSet.effect.effectFilePath = path 415 lineSet.renderTransparent = False 416 return lineSet 417 418 def CreateCurvedLineSet(self, effectPath = None): 419 lineSet = trinity.EveCurveLineSet() 420 if effectPath is not None: 421 lineSet.lineEffect.effectFilePath = effectPath 422 texMap = trinity.TriTextureParameter() 423 texMap.name = 'TexMap' 424 texMap.resourcePath = 'res:/dx9/texture/UI/lineSolid.dds' 425 lineSet.lineEffect.resources.append(texMap) 426 overlayTexMap = trinity.TriTextureParameter() 427 overlayTexMap.name = 'OverlayTexMap' 428 overlayTexMap.resourcePath = 'res:/dx9/texture/UI/lineOverlay5.dds' 429 lineSet.lineEffect.resources.append(overlayTexMap) 430 return lineSet 431 432 class PlanetInfo(object): 433 __slots__ = ['planetID', 'solarSystemID', 'typeID'] 434 435 def __init__(self, planetID, solarSystemID, typeID): 436 self.planetID = planetID 437 self.solarSystemID = solarSystemID 438 self.typeID = typeID 439 440 def GetSystemColorString(self, solarSystemID): 441 col = self.GetSystemColor(solarSystemID) 442 return Color.RGBtoHex(col[0], col[1], col[2]) 443 444 @Memoize 445 def GetEdencomFortressSystems(self): 446 return sm.RemoteSvc('map').GetEdencomFortressSystems() 447 448 @Memoize 449 def GetEdencomMinorVictorySystems(self): 450 return sm.RemoteSvc('map').GetEdencomMinorVictorySystems() 451 452 def GetEdencomAvoidanceSystems(self): 453 return self.GetEdencomFortressSystems() + self.GetEdencomMinorVictorySystems() 454 455 @Memoize 456 def GetTriglavianMinorVictorySystems(self): 457 return sm.RemoteSvc('map').GetTriglavianMinorVictorySystems() 458 459 @Memoize(1) 460 def GetAllRoamingWeatherSystems(self): 461 return sm.RemoteSvc('map').GetAllRoamingWeatherSystems() 462 463 def GetSystemColor(self, solarSystemID): 464 sec, col = eveFormat.FmtSystemSecStatus(self.GetSecurityStatus(solarSystemID), 1) 465 return col 466 467 def GetModifiedSystemColor(self, solarSystemID): 468 modifiedSecurityLevel = self.securitySvc.get_modified_security_level(solarSystemID) 469 sec, col = eveFormat.FmtSystemSecStatus(modifiedSecurityLevel, 1) 470 return col 471 472 def GetStation(self, stationID): 473 station = sm.RemoteSvc('stationSvc').GetStation(stationID) 474 if station and idCheckers.IsLocalIdentity(stationID): 475 station.stationName = cfg.evelocations.Get(stationID).name 476 return station 477 478 def GetMapDataForStructure(self, solarSystemID, structureID): 479 structuresInSystem = sm.GetService('structureDirectory').GetStructureMapData(solarSystemID) 480 return itertoolsext.first_or_default(structuresInSystem, lambda x: x.itemID == structureID)