# uncompyle6 version 2.11.3
# Python bytecode 2.7 (62211)
# Decompiled from: Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)]
# Embedded file name: scripts/common/dossiers2/custom/cache.py
import nations
from items import vehicles

def getCache():
    global _g_cache
    return _g_cache


def buildCache():
    vehiclesByLevel = {}
    vehiclesByTag = {'beast': set(),'sinai': set(),'patton': set()}
    vehiclesInTreeByNation = {}
    vehiclesInTree = set()
    nationsWithVehiclesInTree = []
    unlocksSources = vehicles.getUnlocksSources()
    for nationIdx in xrange(len(nations.NAMES)):
        nationList = vehicles.g_list.getList(nationIdx)
        vehiclesInNationTree = set()
        for vehDescr in nationList.itervalues():
            vehiclesByLevel.setdefault(vehDescr.level, set()).add(vehDescr.compactDescr)
            for tag in ('beast', 'sinai', 'patton'):
                if tag in vehDescr.tags:
                    vehiclesByTag[tag].add(vehDescr.compactDescr)

            if len(unlocksSources.get(vehDescr.compactDescr, set())) > 0 or len(vehicles.g_cache.vehicle(nationIdx, vehDescr.id).unlocksDescrs) > 0:
                vehiclesInNationTree.add(vehDescr.compactDescr)

        vehiclesInTree.update(vehiclesInNationTree)
        vehiclesInTreeByNation[nationIdx] = vehiclesInNationTree
        if bool(vehiclesInNationTree):
            nationsWithVehiclesInTree.append(nationIdx)

    vehicles8p = vehiclesByLevel[8] | vehiclesByLevel[9] | vehiclesByLevel[10]
    _g_cache.update({'vehiclesByLevel': vehiclesByLevel,
       'vehicles8+': vehicles8p,
       'vehiclesByTag': vehiclesByTag,
       'mausTypeCompDescr': vehicles.makeVehicleTypeCompDescrByName('germany:G42_Maus'),
       'vehiclesInTreesByNation': vehiclesInTreeByNation,
       'vehiclesInTrees': vehiclesInTree,
       'nationsWithVehiclesInTree': nationsWithVehiclesInTree
       })


_g_cache = {}
[((19, 21, 19, 49), 'items.vehicles.getUnlocksSources', 'vehicles.getUnlocksSources', ({}, {}), '()', False, 'from items import vehicles\n'), ((21, 21, 21, 55), 'items.vehicles.g_list.getList', 'vehicles.g_list.getList', ({(21, 45, 21, 54): 'nationIdx'}, {}), '(nationIdx)', False, 'from items import vehicles\n'), ((41, 28, 41, 87), 'items.vehicles.makeVehicleTypeCompDescrByName', 'vehicles.makeVehicleTypeCompDescrByName', ({(41, 68, 41, 86): '"""germany:G42_Maus"""'}, {}), "('germany:G42_Maus')", False, 'from items import vehicles\n'), ((29, 80, 29, 128), 'items.vehicles.g_cache.vehicle', 'vehicles.g_cache.vehicle', ({(29, 105, 29, 114): 'nationIdx', (29, 116, 29, 127): 'vehDescr.id'}, {}), '(nationIdx, vehDescr.id)', False, 'from items import vehicles\n')]