mapData.py (4758B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\fwwarzone\client\dashboard\mapData.py 2 import cPickle 3 import logging 4 import blue 5 import factionwarfare.occupationState 6 from fwwarzone.client.data.warzoneMapPositionsDataLoader import get_frontlines_map_data 7 log = logging.getLogger(__name__) 8 9 class TestOccupationState: 10 11 def __init__(self, occupierID, adjacencyState): 12 self.adjacencyState = adjacencyState 13 self.occupierID = occupierID 14 15 16 class _WarzoneSystemData: 17 18 def __init__(self, position, systemId, occupationState, neighbours, territoryTexturePath, textureWidth, textureHeight, xOffset, yOffset, isNavigationSystem = False): 19 self.isNavigationSystem = isNavigationSystem 20 self.yOffset = yOffset 21 self.xOffset = xOffset 22 self.textureHeight = textureHeight 23 self.textureWidth = textureWidth 24 self.territoryTexturePath = territoryTexturePath 25 self.neighbours = neighbours 26 self.occupationState = occupationState 27 self.systemId = systemId 28 self.position = position 29 30 31 class _SystemsData: 32 33 def __init__(self, systems, mapWidth, mapHeight): 34 self.systems = systems 35 self.mapWidth = mapWidth 36 self.mapHeight = mapHeight 37 38 39 class WarzoneMapData: 40 41 def __init__(self, fwWarzoneSvc): 42 self.fwWarzoneSvc = fwWarzoneSvc 43 self.occupationStates = None 44 self.starMapCache = None 45 self.warzonePositionCache = None 46 self.RefreshOccupationStates() 47 48 def RefreshOccupationStates(self): 49 self.occupationStates = self.fwWarzoneSvc.GetAllOccupationStates() 50 51 def GetWarzoneSystems(self, warzoneId): 52 mapCache = self._GetStarMapCache() 53 warzonesPosData = self._GetWarzonePositionData() 54 warzone = self.occupationStates[warzoneId] 55 systems = {} 56 warzoneData = warzonesPosData[warzoneId] 57 positionsData = warzoneData.systems 58 mapHeight = warzoneData.mapHeight 59 mapWidth = warzoneData.mapWidth 60 for systemId, posData in positionsData.iteritems(): 61 if not posData.isVisible: 62 continue 63 posData = positionsData[systemId] 64 system = mapCache['solarSystems'][systemId] 65 position = (posData.xpos, posData.ypos) 66 neighbours = system['neighbours'] 67 texturePath = '' 68 textureWidth = 0 69 textureHeight = 0 70 xOffset = 0 71 yOffset = 0 72 isNavigationSystem = False 73 occupationState = None 74 if posData.territorySprite is not None and systemId in warzone: 75 texturePath = posData.territorySprite.territoryIconFile 76 textureWidth = posData.territorySprite.imageWidth 77 textureHeight = posData.territorySprite.imageHeight 78 xOffset = posData.territorySprite.xOffset 79 yOffset = posData.territorySprite.yOffset 80 occupationState = warzone[systemId] 81 else: 82 isNavigationSystem = True 83 systems[systemId] = _WarzoneSystemData(position, systemId, occupationState, neighbours, texturePath, textureWidth, textureHeight, xOffset, yOffset, isNavigationSystem=isNavigationSystem) 84 85 return _SystemsData(systems, mapWidth, mapHeight) 86 87 def _GetWarzonePositionData(self): 88 if self.warzonePositionCache is None: 89 self.warzonePositionCache = get_frontlines_map_data() 90 return self.warzonePositionCache 91 92 def _GetStarMapCache(self): 93 if self.starMapCache is None: 94 res = blue.ResFile() 95 starMapResPath = 'res:/staticdata/starMapCache.pickle' 96 if not res.open('%s' % starMapResPath): 97 log.error('Could not load Starmap Cache data file: %s' % starMapResPath) 98 else: 99 try: 100 pickleData = res.Read() 101 self.starMapCache = cPickle.loads(pickleData) 102 finally: 103 res.Close() 104 105 return self.starMapCache 106 107 def GetSolarsystemWithMostRecentOccupancyChange(self, warzone_id): 108 warzone_occupation_states = self.fwWarzoneSvc.GetAllOccupationStates()[warzone_id] 109 states_that_have_taken_date = [ (solarsystem_id, occupation_state) for solarsystem_id, occupation_state in warzone_occupation_states.iteritems() if occupation_state.dateTaken is not None ] 110 if len(states_that_have_taken_date) == 0: 111 return (None, None) 112 solarsystem_id, occupation_state = sorted(states_that_have_taken_date, reverse=True, key=lambda _solarsystem_id__occupation_state: _solarsystem_id__occupation_state[1].dateTaken)[0] 113 return (solarsystem_id, occupation_state)