コード例 #1
0
def readDeviceHealthParams(xmlCtx, section, subsectionName = '', withHysteresis = True):
    """Reads health parameter for each device.
    :param xmlCtx: tuple(root ctx or None, path to section).
    :param section: instance of DataSection.
    :param subsectionName: string containing name of desired section or empty string
        if desired section is already exist.
    :param withHysteresis: if value equals True than read section 'hysteresisHealth',
        otherwise - do nothing.
    :return: instance of DeviceHealth.
    """
    if subsectionName:
        section = _xml.getSubsection(xmlCtx, section, subsectionName)
        xmlCtx = (xmlCtx, subsectionName)
    component = shared_components.DeviceHealth(_xml.readInt(xmlCtx, section, 'maxHealth', 1), _xml.readNonNegativeFloat(xmlCtx, section, 'repairCost'), _xml.readInt(xmlCtx, section, 'maxRegenHealth', 0))
    if component.maxRegenHealth > component.maxHealth:
        _xml.raiseWrongSection(xmlCtx, 'maxRegenHealth')
    if not IS_CLIENT and not IS_BOT:
        component.healthRegenPerSec = _xml.readNonNegativeFloat(xmlCtx, section, 'healthRegenPerSec')
        component.healthBurnPerSec = _xml.readNonNegativeFloat(xmlCtx, section, 'healthBurnPerSec')
        if section.has_key('chanceToHit'):
            component.chanceToHit = _xml.readFraction(xmlCtx, section, 'chanceToHit')
        else:
            component.chanceToHit = None
        if withHysteresis:
            hysteresisHealth = _xml.readInt(xmlCtx, section, 'hysteresisHealth', 0)
            if hysteresisHealth > component.maxRegenHealth:
                _xml.raiseWrongSection(xmlCtx, 'hysteresisHealth')
            component.hysteresisHealth = hysteresisHealth
    return component
コード例 #2
0
def _readProjectionDecalSlot(ctx, subsection, slotType):
    descr = shared_components.ProjectionDecalSlotDescription(
        slotType=slotType,
        slotId=_xml.readInt(ctx, subsection, 'slotId'),
        position=_xml.readVector3OrNone(ctx, subsection, 'position'),
        rotation=_xml.readVector3OrNone(ctx, subsection, 'rotation'),
        scale=_xml.readVector3OrNone(ctx, subsection, 'scale'),
        scaleFactors=_xml.readVector3(
            ctx, subsection, 'scaleFactors',
            c11n_constants.DEFAULT_DECAL_SCALE_FACTORS),
        doubleSided=_xml.readBool(ctx, subsection, 'doubleSided', False),
        hiddenForUser=_xml.readBool(ctx, subsection, 'hiddenForUser', False),
        canBeMirroredVertically=_xml.readBool(ctx, subsection,
                                              'verticalMirror', False),
        showOn=_xml.readIntOrNone(ctx, subsection, 'showOn'),
        tags=readOrderedTagsOrEmpty(ctx, subsection,
                                    _customizationSlotTagsValidator),
        clipAngle=_xml.readFloat(ctx, subsection, 'clipAngle',
                                 c11n_constants.DEFAULT_DECAL_CLIP_ANGLE),
        anchorShift=_xml.readFloat(ctx, subsection, 'anchorShift',
                                   c11n_constants.DEFAULT_DECAL_ANCHOR_SHIFT))
    _verifySlotId(ctx, slotType, descr.slotId)
    _verifyMatchingSlotSettings(ctx, descr)
    if descr.showOn is not None:
        availableShowOnRegions = c11n_constants.ApplyArea.HULL | c11n_constants.ApplyArea.TURRET | c11n_constants.ApplyArea.GUN
        if descr.showOn | availableShowOnRegions != availableShowOnRegions:
            _xml.raiseWrongSection(ctx, 'showOn')
    if subsection.has_key('compatibleModels'):
        descr.compatibleModels = _xml.readTupleOfStrings(
            ctx, subsection, 'compatibleModels')
    if subsection.has_key('itemId'):
        descr.itemId = _xml.readInt(ctx, subsection, 'itemId')
    if subsection.has_key('options'):
        descr.options = _xml.readNonNegativeInt(ctx, subsection, 'options')
    return descr
コード例 #3
0
    def __readSharedMetrics(self, shared, xmlCtx, section):
        precessed = _xml.getChildren(xmlCtx, section, 'grids')
        for name, gridSection in precessed:
            gridName = gridSection.asString
            xPath = '{0:>s}/{1:>s}/{2:>s}'.format(TREE_SHARED_REL_FILE_PATH,
                                                  name, gridName)
            gridCtx = (None, xPath)
            subSec = _xml.getSubsection(xmlCtx, gridSection, 'root')
            xmlCtx = (None, '{0:>s}/root'.format(xPath))
            rootPos = {
                'start': _xml.readVector2(xmlCtx, subSec, 'start').tuple(),
                'step': _xml.readInt(xmlCtx, subSec, 'step')
            }
            subSec = _xml.getSubsection(gridCtx, gridSection, 'vertical')
            xmlCtx = (None, '{0:>s}/vertical'.format(xPath))
            vertical = (_xml.readInt(xmlCtx, subSec, 'start'),
                        _xml.readInt(xmlCtx, subSec, 'step'))
            subSec = _xml.getSubsection(gridCtx, gridSection, 'horizontal')
            xmlCtx = (None, '{0:>s}/horizontal'.format(xPath))
            horizontal = (_xml.readInt(xmlCtx, subSec, 'start'),
                          _xml.readInt(xmlCtx, subSec, 'step'))
            shared['grids'][gridName] = {
                'root': rootPos,
                'vertical': vertical,
                'horizontal': horizontal
            }

        precessed = _xml.getChildren(xmlCtx, section, 'lines')
        lines = shared['lines']
        for name, sub in precessed:
            xPath = '{0:>s}/{1:>s}'.format(TREE_SHARED_REL_FILE_PATH, name)
            xmlCtx = (None, xPath)
            pinsSec = _xml.getChildren(xmlCtx, sub, 'inPin')
            inPins = dict(
                ((pName, pSec.asVector2.tuple()) for pName, pSec in pinsSec))
            pinsSec = _xml.getChildren(xmlCtx, sub, 'outPin')
            outPins = dict(
                ((pName, pSec.asVector2.tuple()) for pName, pSec in pinsSec))
            pinsSec = _xml.getChildren(xmlCtx, sub, 'viaPin')
            viaPins = defaultdict(dict)
            for outPin, setSec in pinsSec:
                for inPin, pSec in setSec.items():
                    viaPins[outPin][inPin] = map(
                        lambda section: section[1].asVector2.tuple(),
                        pSec.items())

            defSec = sub['default']
            default = {}
            if defSec is not None:
                xmlCtx = (None, '{0:>s}/default'.format(xPath))
                default = {
                    'outPin': _xml.readString(xmlCtx, defSec, 'outPin'),
                    'inPin': _xml.readString(xmlCtx, defSec, 'inPin')
                }
            lines[name] = {
                'inPins': inPins,
                'outPins': outPins,
                'viaPins': viaPins,
                'default': default
            }
コード例 #4
0
ファイル: artefacts.py プロジェクト: webiumsk/WOT0.9.10
 def _readConfig(self, xmlCtx, section):
     self.delay = _xml.readPositiveFloat(xmlCtx, section, 'delay')
     self.modelName = _xml.readString(xmlCtx, section, 'modelName')
     self.soundEvent = _xml.readString(xmlCtx, section, 'soundEvent')
     self.speed = _xml.readInt(xmlCtx, section, 'speed')
     self.heights = _xml.readTupleOfPositiveInts(xmlCtx, section, 'heights', 2)
     self.areaLength = _xml.readPositiveFloat(xmlCtx, section, 'areaLength')
     self.areaWidth = _xml.readPositiveFloat(xmlCtx, section, 'areaWidth')
     self.antepositions = _xml.readTupleOfFloats(xmlCtx, section, 'antepositions')
     self.lateropositions = _xml.readTupleOfFloats(xmlCtx, section, 'lateropositions')
     self.bombingMask = tuple((bool(v) for v in _xml.readTupleOfInts(xmlCtx, section, 'bombingMask')))
     if not len(self.antepositions) == len(self.lateropositions) == len(self.bombingMask):
         _xml.raiseWrongSection(xmlCtx, 'bombers number mismatch')
     self.waveFraction = _xml.readPositiveFloat(xmlCtx, section, 'waveFraction')
     self.bombsNumber = _xml.readNonNegativeInt(xmlCtx, section, 'bombsNumber')
     self.shellCompactDescr = _xml.readInt(xmlCtx, section, 'shellCompactDescr')
     self.tracerKind = _xml.readInt(xmlCtx, section, 'tracerKind')
     self.piercingPower = _xml.readTupleOfPositiveInts(xmlCtx, section, 'piercingPower', 2)
     self.gravity = _xml.readPositiveFloat(xmlCtx, section, 'gravity')
     self.areaVisual = _xml.readStringOrNone(xmlCtx, section, 'areaVisual')
     self.areaColor = _xml.readIntOrNone(xmlCtx, section, 'areaColor')
     self.areaMarker = _xml.readStringOrNone(xmlCtx, section, 'areaMarker')
     self.reusable = _xml.readBool(xmlCtx, section, 'reusable')
     self.cooldownTime = _xml.readNonNegativeFloat(xmlCtx, section, 'cooldownTime') if self.reusable else 0.0
     self.deployTime = _xml.readNonNegativeFloat(xmlCtx, section, 'deployTime')
コード例 #5
0
ファイル: artefacts.py プロジェクト: kusaku/wot_scripts
 def _readConfig(self, xmlCtx, section):
     self.delay = _xml.readPositiveFloat(xmlCtx, section, 'delay')
     self.modelName = _xml.readString(xmlCtx, section, 'modelName')
     if IS_CLIENT:
         self.soundEvent = _xml.readString(xmlCtx, section, 'wwsoundEvent')
     self.speed = _xml.readInt(xmlCtx, section, 'speed')
     self.heights = _xml.readTupleOfPositiveInts(xmlCtx, section, 'heights', 2)
     self.areaLength = _xml.readPositiveFloat(xmlCtx, section, 'areaLength')
     self.areaWidth = _xml.readPositiveFloat(xmlCtx, section, 'areaWidth')
     self.antepositions = _xml.readTupleOfFloats(xmlCtx, section, 'antepositions')
     self.lateropositions = _xml.readTupleOfFloats(xmlCtx, section, 'lateropositions')
     self.bombingMask = tuple((bool(v) for v in _xml.readTupleOfInts(xmlCtx, section, 'bombingMask')))
     if not len(self.antepositions) == len(self.lateropositions) == len(self.bombingMask):
         _xml.raiseWrongSection(xmlCtx, 'bombers number mismatch')
     self.waveFraction = _xml.readPositiveFloat(xmlCtx, section, 'waveFraction')
     self.bombsNumber = _xml.readNonNegativeInt(xmlCtx, section, 'bombsNumber')
     self.shellCompactDescr = _xml.readInt(xmlCtx, section, 'shellCompactDescr')
     self.tracerKind = _xml.readInt(xmlCtx, section, 'tracerKind')
     self.piercingPower = _xml.readTupleOfPositiveInts(xmlCtx, section, 'piercingPower', 2)
     self.gravity = _xml.readPositiveFloat(xmlCtx, section, 'gravity')
     self.areaVisual = _xml.readStringOrNone(xmlCtx, section, 'areaVisual')
     self.areaColor = _xml.readIntOrNone(xmlCtx, section, 'areaColor')
     self.areaMarker = _xml.readStringOrNone(xmlCtx, section, 'areaMarker')
     self.reusable = _xml.readBool(xmlCtx, section, 'reusable')
     self.cooldownTime = _xml.readNonNegativeFloat(xmlCtx, section, 'cooldownTime') if self.reusable else 0.0
     self.deployTime = _xml.readNonNegativeFloat(xmlCtx, section, 'deployTime')
コード例 #6
0
def readDeviceHealthParams(xmlCtx,
                           section,
                           subsectionName='',
                           withHysteresis=True):
    if subsectionName:
        section = _xml.getSubsection(xmlCtx, section, subsectionName)
        xmlCtx = (xmlCtx, subsectionName)
    component = shared_components.DeviceHealth(
        _xml.readInt(xmlCtx, section, 'maxHealth', 1),
        _xml.readNonNegativeFloat(xmlCtx, section, 'repairCost'),
        _xml.readInt(xmlCtx, section, 'maxRegenHealth', 0))
    if component.maxRegenHealth > component.maxHealth:
        _xml.raiseWrongSection(xmlCtx, 'maxRegenHealth')
    if not IS_CLIENT and not IS_BOT:
        component.healthRegenPerSec = _xml.readNonNegativeFloat(
            xmlCtx, section, 'healthRegenPerSec')
        component.healthBurnPerSec = _xml.readNonNegativeFloat(
            xmlCtx, section, 'healthBurnPerSec')
        if section.has_key('chanceToHit'):
            component.chanceToHit = _xml.readFraction(xmlCtx, section,
                                                      'chanceToHit')
        else:
            component.chanceToHit = None
        if withHysteresis:
            hysteresisHealth = _xml.readInt(xmlCtx, section,
                                            'hysteresisHealth', 0)
            if hysteresisHealth > component.maxRegenHealth:
                _xml.raiseWrongSection(xmlCtx, 'hysteresisHealth')
            component.hysteresisHealth = hysteresisHealth
    return component
コード例 #7
0
def _readPerkItem(xmlCtx, section, storage):
    perkID = _xml.readInt(xmlCtx, section, 'id', 1)
    name = _xml.readStringOrEmpty(xmlCtx, section, 'name')
    description = _xml.readNonEmptyString(xmlCtx, section, 'description')
    icon = _xml.readNonEmptyString(xmlCtx, section, 'icon')
    branchID = _xml.readInt(xmlCtx, section, 'branchID', 0)
    ultimative = section.readBool('ultimative', False)
    maxCount = _xml.readInt(xmlCtx, section, 'maxCount', 1)
    situational = _xml.readBool(xmlCtx, section, 'situational', False)
    perkItem = Perk(perkID, name, description, icon, branchID, ultimative, maxCount, situational)
    storage[perkID] = perkItem
コード例 #8
0
def readGroundNodesAndGroups(xmlCtx, section, cache):
    if section['groundNodes'] is None:
        return (component_constants.EMPTY_TUPLE,
                component_constants.EMPTY_TUPLE, False, None)
    else:
        groundGroups = []
        groundNodes = []
        for sname, subsection in _xml.getChildren(xmlCtx, section,
                                                  'groundNodes'):
            if sname == 'group':
                ctx = (xmlCtx, 'groundNodes/group')
                group = chassis_components.GroundNodeGroup(
                    isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                    minOffset=_xml.readFloat(ctx, subsection, 'minOffset'),
                    maxOffset=_xml.readFloat(ctx, subsection, 'maxOffset'),
                    nodesTemplate=intern(
                        _xml.readNonEmptyString(ctx, subsection, 'template')),
                    affectedWheelsTemplate=_xml.readStringOrNone(
                        ctx, subsection, 'affectedWheelsTemplate'),
                    nodesCount=_xml.readInt(ctx, subsection, 'count', 1),
                    startIndex=subsection.readInt('startIndex', 0),
                    collisionSamplesCount=subsection.readInt(
                        'collisionSamplesCount', 1),
                    hasLiftMode=_xml.readBool(ctx, subsection, 'hasLiftMode',
                                              False))
                groundGroups.append(group)
            if sname == 'node':
                ctx = (xmlCtx, 'groundNodes/node')
                groundNode = chassis_components.GroundNode(
                    nodeName=intern(
                        _xml.readNonEmptyString(ctx, subsection, 'name')),
                    affectedWheelName=_xml.readStringOrEmpty(
                        ctx, subsection, 'affectedWheelName'),
                    isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                    minOffset=_xml.readFloat(ctx, subsection, 'minOffset'),
                    maxOffset=_xml.readFloat(ctx, subsection, 'maxOffset'),
                    collisionSamplesCount=_xml.readInt(
                        ctx, subsection, 'collisionSamplesCount', 1),
                    hasLiftMode=_xml.readBool(ctx, subsection, 'hasLiftMode',
                                              False))
                groundNodes.append(groundNode)

        activePostmortem = _xml.readBool(xmlCtx, section,
                                         'groundNodes/activePostmortem', False)
        lodSettingsSection = section['groundNodes/lodSettings']
        if lodSettingsSection is not None:
            lodSettings = shared_readers.readLodSettings(
                xmlCtx, section['groundNodes'], cache)
        else:
            lodSettings = None
        return (tuple(groundGroups), tuple(groundNodes), activePostmortem,
                lodSettings)
コード例 #9
0
def _readSkinItem(pricesCache, cache, xmlCtx, section, storage):
    skinID = _xml.readInt(xmlCtx, section, 'id', 1)
    if skinID in storage:
        _xml.raiseWrongXml(xmlCtx, 'id', "duplicate id '%s'" % skinID)
    priceGroup = section.readString('priceGroup')
    tags = _readGroupTags((xmlCtx, 'tags'), section, 'tags')
    firstNameID = _xml.readStringOrEmpty(xmlCtx, section, 'firstName')
    lastNameID = _xml.readNonEmptyString(xmlCtx, section, 'lastName')
    description = _xml.readNonEmptyString(xmlCtx, section, 'description')
    iconID = _xml.readNonEmptyString(xmlCtx, section, 'icon')
    rarity = _xml.readInt(xmlCtx, section, 'rarity', 1)
    maxCount = _xml.readInt(xmlCtx, section, 'maxCount')
    soundSetID = section.readString('soundSet', crew_skins_constants.NO_CREW_SKIN_SOUND_SET)
    historical = _xml.readBool(xmlCtx, section, 'historical', False)
    realmsStr = section.readString('realms', '')
    realms = realmsStr.split()
    unexpectedRealms = set(realms) - REGIONAL_REALMS
    if unexpectedRealms:
        _xml.raiseWrongXml(xmlCtx, 'realms', "unknown realms '%s'" % unexpectedRealms)
    crewSkinItem = cc.CrewSkin(skinID, priceGroup, firstNameID, lastNameID, iconID, description, rarity, maxCount, tags, historical, soundSetID, realms)
    if section.has_key('filters'):
        filterSection = _xml.getSubsection(xmlCtx, section, 'filters')
        if filterSection.has_key('role'):
            roleName = filterSection.readString('role')
            if roleName not in skills_constants.ROLES:
                _xml.raiseWrongXml(xmlCtx, 'role', "unknown tankmanRole '%s'" % roleName)
            crewSkinItem.roleID = roleName if roleName else None
        if filterSection.has_key('nation'):
            nation = filterSection.readString('nation', '')
            if nation and nation not in nations.NAMES:
                _xml.raiseWrongXml(xmlCtx, 'nation', "unknown nation '%s'" % nation)
            crewSkinItem.nation = nation if nation else None
        if filterSection.has_key('sex'):
            sex = filterSection.readString('sex', '')
            if sex not in crew_skins_constants.TANKMAN_SEX.AVAILABLE:
                _xml.raiseWrongXml(xmlCtx, 'sex', "unknown tankman sex '%s'" % sex)
            crewSkinItem.sex = sex
    storage[skinID] = crewSkinItem
    groupsDict = cache.priceGroups
    itemToGroup = cache.itemToPriceGroup
    if crewSkinItem.priceGroup:
        if crewSkinItem.priceGroup not in cache.priceGroupNames:
            _xml.raiseWrongXml(xmlCtx, 'priceGroup', 'unknown price group %s for item %s' % (crewSkinItem.priceGroup, crewSkinItem.id))
        priceGroupId = cache.priceGroupNames[crewSkinItem.priceGroup]
        crewSkinItem.priceGroupTags = groupsDict[priceGroupId].tags
        itemToGroup[crewSkinItem.compactDescr] = groupsDict[priceGroupId].compactDescr
        itemNotInShop = section.readBool('notInShop', False)
        _copyPriceForItem(pricesCache, groupsDict[priceGroupId].compactDescr, crewSkinItem.compactDescr, itemNotInShop)
    else:
        _xml.raiseWrongXml(xmlCtx, 'priceGroup', 'no price for item %s' % crewSkinItem.id)
    return
コード例 #10
0
def _readCustomizationSlotIdRanges():
    filePath = _CUSTOMIZATION_CONSTANTS_PATH
    section = ResMgr.openSection(filePath)
    if section is None:
        _xml.raiseWrongXml(None, filePath, 'can not open or read')
    xmlCtx = (None, filePath)
    slots = _xml.getSubsection(xmlCtx, section, 'slot_id_ranges')
    for partName, part in _xml.getChildren(xmlCtx, section, 'slot_id_ranges'):
        partIds = __customizationSlotIdRanges[partName]
        for itemName, item in _xml.getChildren(xmlCtx, slots, partName):
            range_min = _xml.readInt(xmlCtx, item, 'range_min')
            range_max = _xml.readInt(xmlCtx, item, 'range_max')
            partIds[itemName] = (range_min, range_max)

    return
コード例 #11
0
def __readProgress(xmlCtx, section):
    progress = cc.ProgressForCustomization()
    itemId = ix.readInt(xmlCtx, section, 'id')
    if section.has_key('autobound'):
        progress.autobound = True
    for sectionName, subSection in section.items():
        if sectionName == 'level':
            level = ix.readPositiveInt(xmlCtx, subSection, '')
            progress.levels[level] = __readProgressLevel((xmlCtx, 'level'),
                                                         subSection)
        if sectionName == 'autoGrantCount':
            progress.autoGrantCount = ix.readPositiveInt(
                xmlCtx, subSection, '')

    if len(progress.levels) < 2:
        ix.raiseWrongXml(
            xmlCtx, 'tags',
            'wrong progression. Minimum count progression = 2. Current count progression %i'
            % len(progress.levels))
    for i in range(1, len(progress.levels) + 1):
        if i not in progress.levels:
            ix.raiseWrongXml(xmlCtx, 'tags',
                             'wrong progression. Skipped level %i' % i)

    return (itemId, progress)
コード例 #12
0
 def _readFromXml(self, target, xmlCtx, section, cache=None):
     if section.has_key('id'):
         target.id = ix.readInt(xmlCtx, section, 'id', 1)
     if section.has_key('tags'):
         target.tags = iv._readTags(xmlCtx, section, 'tags',
                                    'customizationItem')
         if target.itemType == CustomizationType.PROJECTION_DECAL:
             formTags = [
                 tag for tag in target.tags
                 if tag in ProjectionDecalFormTags.ALL
             ]
             if len(formTags) > 1:
                 ix.raiseWrongXml(
                     xmlCtx, 'tags',
                     'wrong formfactor for prjection decal ID%i' %
                     target.id)
     if section.has_key('vehicleFilter'):
         target.filter = self.readVehicleFilterFromXml(
             (xmlCtx, 'vehicleFilter'), section['vehicleFilter'])
     target.season = readFlagEnum(xmlCtx, section, 'season', SeasonType,
                                  target.season)
     target.customizationDisplayType = section.readInt(
         'historical', target.customizationDisplayType)
     if section.has_key('priceGroup'):
         target.priceGroup = section.readString('priceGroup')
     if section.has_key('requiredToken'):
         target.requiredToken = section.readString('requiredToken')
     if section.has_key('maxNumber'):
         target.maxNumber = ix.readPositiveInt(xmlCtx, section, 'maxNumber')
         if target.maxNumber <= 0:
             ix.raiseWrongXml(xmlCtx, 'maxNumber',
                              'should not be less then 1')
     if IS_CLIENT or IS_EDITOR or IS_WEB:
         self._readClientOnlyFromXml(target, xmlCtx, section, cache)
コード例 #13
0
def _readFonts(cache, xmlCtx, section, sectionName):
    if IS_EDITOR:
        itemType = CUSTOMIZATION_CLASSES[cc.Font]
        sourceFiles = set()
    for tag, iSection in section.items():
        if tag != sectionName:
            continue
        font = cc.Font()
        font.id = ix.readInt(xmlCtx, iSection, 'id', 1)
        iCtx = (xmlCtx, 'id %s' % font.id)
        if font.id in cache.fonts:
            ix.raiseWrongXml(iCtx, 'id', 'duplicate price group id')
        font.texture = ix.readString(xmlCtx, iSection, 'texture')
        font.alphabet = ix.readString(xmlCtx, iSection, 'alphabet')
        if iSection.has_key('mask'):
            font.mask = ix.readString(xmlCtx, iSection, 'mask')
        cache.fonts[font.id] = font
        if IS_EDITOR:
            refs = iSection.references
            if len(refs) == 1:
                font.editorData.sourceXml = refs[0]
                sourceFiles.add(refs[0])

    if IS_EDITOR:
        cache.editorData.sourceFiles[itemType] = list(sourceFiles)
コード例 #14
0
def readWheelsAndGroups(xmlCtx, section):
    wheelGroups = []
    wheels = []
    defSyncAngle = section.readFloat('wheels/leadingWheelSyncAngle', 60)
    for sname, subsection in _xml.getChildren(xmlCtx, section, 'wheels'):
        if sname == 'group':
            ctx = (xmlCtx, 'wheels/group')
            group = chassis_components.WheelGroup(
                isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                template=intern(
                    _xml.readNonEmptyString(ctx, subsection, 'template')),
                count=_xml.readInt(ctx, subsection, 'count', 1),
                startIndex=subsection.readInt('startIndex', 0),
                radius=_xml.readPositiveFloat(ctx, subsection, 'radius'))
            wheelGroups.append(group)
        if sname == 'wheel':
            ctx = (xmlCtx, 'wheels/wheel')
            w = chassis_components.Wheel(
                isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                radius=_xml.readPositiveFloat(ctx, subsection, 'radius'),
                nodeName=intern(
                    _xml.readNonEmptyString(ctx, subsection, 'name')),
                isLeading=subsection.readBool('isLeading', False),
                leadingSyncAngle=subsection.readFloat('syncAngle',
                                                      defSyncAngle))
            wheels.append(w)

    return (tuple(wheelGroups), tuple(wheels))
コード例 #15
0
 def __readItemFilterNodeFromXml(itemType, xmlCtx, section):
     fn = cc.ItemsFilter.FilterNode()
     if section.has_key('id'):
         fn.ids = ix.readTupleOfPositiveInts(xmlCtx, section, 'id')
     if section.has_key('itemGroupName'):
         fn.itemGroupNames = ix.readTupleOfStrings(xmlCtx,
                                                   section,
                                                   'itemGroupName',
                                                   separator=';')
     if section.has_key('tags'):
         fn.tags = iv._readTags(xmlCtx, section, 'tags',
                                'customizationItem')
     if section.has_key('type'):
         if itemType is not CustomizationType.DECAL:
             ix.raiseWrongXml(xmlCtx, 'type',
                              'type can be used only with decals')
         types = set(
             (getattr(DecalType, typeName)
              for typeName in ix.readTupleOfStrings(xmlCtx, section, 'type')
              ))
         if not types.issubset(DecalType.ALL):
             ix.raiseWrongXml(xmlCtx, 'type', 'unsupported type is used')
         fn.types = types
     if section.has_key('historical'):
         fn.customizationDisplayType = ix.readInt(
             xmlCtx, section, 'historical',
             CustomizationDisplayType.NON_HISTORICAL)
     return fn
コード例 #16
0
def _readPriceGroups(cache, xmlCtx, section, sectionName):
    if IS_EDITOR and section is None:
        return
    else:
        for tag, iSection in section.items():
            if tag != sectionName:
                continue
            priceGroup = cc.PriceGroup()
            priceGroup.id = ix.readInt(xmlCtx, iSection, 'id', 1)
            iCtx = (xmlCtx, 'id %s' % priceGroup.id)
            if priceGroup.id in cache.priceGroups:
                ix.raiseWrongXml(iCtx, 'id', 'duplicate price group id')
            priceGroup.name = intern(ix.readString(iCtx, iSection, 'name'))
            if priceGroup.name in cache.priceGroupNames:
                ix.raiseWrongXml(
                    iCtx, 'id',
                    'duplicate price group name "%s"' % priceGroup.name)
            priceGroup.notInShop = iSection.readBool('notInShop', False)
            iv._readPriceForItem(iCtx, iSection, priceGroup.compactDescr)
            if iSection.has_key('tags'):
                tags = iSection.readString('tags').split()
                priceGroup.tags = frozenset(map(intern, tags))
                for tag in priceGroup.tags:
                    cache.priceGroupTags.setdefault(tag, []).append(priceGroup)

            cache.priceGroupNames[priceGroup.name] = priceGroup.id
            cache.priceGroups[priceGroup.id] = priceGroup

        return
コード例 #17
0
ファイル: hitLog.py プロジェクト: NikolayXHD/xvmconfig
 def onEnterWorld(self, vehicle):
     self.macros.setChooseRating()
     self.player = BigWorld.player()
     self.playerVehicleID = self.player.playerVehicleID
     self.ammo = self.guiSessionProvider.shared.ammo
     shots = vehicle.typeDescriptor.gun.shots
     nation = nations.NAMES[vehicle.typeDescriptor.type.id[0]]
     xmlPath = '%s%s%s%s' % (ITEM_DEFS_PATH, 'vehicles/', nation,
                             '/components/shells.xml')
     xmlCtx_s = (((None, '{}/{}'.format(xmlPath, n)), s)
                 for n, s in ResMgr.openSection(xmlPath).items()
                 if (n != 'icons') and (n != 'xmlns:xmlref'))
     goldShells = [
         _xml.readInt(xmlCtx, s, 'id', 0, 65535) for xmlCtx, s in xmlCtx_s
         if s.readBool('improved', False)
     ]
     for shot in shots:
         shell = shot.shell
         intCD = shell.compactDescr
         self.shells[intCD] = {}
         self.shells[intCD]['shellKind'] = shell.kind.lower()
         self.shells[intCD]['shellDamage'] = shell.damage[0]
         self.shells[intCD]['costShell'] = 'gold-shell' if shell.id[
             1] in goldShells else 'silver-shell'
     ResMgr.purge(xmlPath, True)
     arena = avatar_getter.getArena()
     self.battletypeKey = BATTLE_TYPE.get(arena.guiType,
                                          ARENA_GUI_TYPE.UNKNOWN)
コード例 #18
0
def readGroundNodesAndGroups(xmlCtx, section):
    """Reads section 'groundNodes' for each chassis if it has.
    :param xmlCtx: tuple(root ctx or None, path to section).
    :param section: instance of DataSection.
    :return: tuple(sequence of groups, sequence of nodes).
    """
    if section['groundNodes'] is None:
        return (component_constants.EMPTY_TUPLE,
                component_constants.EMPTY_TUPLE)
    else:
        groundGroups = []
        groundNodes = []
        for sname, subsection in _xml.getChildren(xmlCtx, section,
                                                  'groundNodes'):
            if sname == 'group':
                ctx = (xmlCtx, 'groundNodes/group')
                group = chassis_components.GroundNodeGroup(
                    isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                    minOffset=_xml.readFloat(ctx, subsection, 'minOffset'),
                    maxOffset=_xml.readFloat(ctx, subsection, 'maxOffset'),
                    template=_xml.readNonEmptyString(ctx, subsection,
                                                     'template'),
                    count=_xml.readInt(ctx, subsection, 'count', 1),
                    startIndex=subsection.readInt('startIndex', 0))
                groundGroups.append(group)
            elif sname == 'node':
                ctx = (xmlCtx, 'groundNodes/node')
                groundNode = chassis_components.GroundNode(
                    name=_xml.readNonEmptyString(ctx, subsection, 'name'),
                    isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                    minOffset=_xml.readFloat(ctx, subsection, 'minOffset'),
                    maxOffset=_xml.readFloat(ctx, subsection, 'maxOffset'))
                groundNodes.append(groundNode)

        return (tuple(groundGroups), tuple(groundNodes))
コード例 #19
0
ファイル: damageLog.py プロジェクト: KOlap5/OSW_Essentials
 def typeShell(self, effectsIndex):
     if (self.data['attackerID'] == 0) or (self.data['attackReasonID']
                                           not in [0, 100]):
         self.data['costShell'] = 'do_not_know'
         self.data['shellKind'] = 'not_shell'
         return
     player = BigWorld.player()
     attacker = player.arena.vehicles.get(self.data['attackerID'])
     self.data['costShell'] = 'do_not_know'
     for shell in attacker['vehicleType'].gun['shots']:
         if effectsIndex == shell['shell']['effectsIndex']:
             self.data['shellKind'] = str(shell['shell']['kind']).lower()
             xmlPath = ITEM_DEFS_PATH + 'vehicles/' + nations.NAMES[
                 shell['shell']['id'][0]] + '/components/shells.xml'
             for name, subsection in ResMgr.openSection(xmlPath).items():
                 if name != 'icons':
                     xmlCtx = (None, xmlPath + '/' + name)
                     if _xml.readInt(xmlCtx, subsection, 'id', 0,
                                     65535) == shell['shell']['id'][1]:
                         price = _xml.readPrice(xmlCtx, subsection, 'price')
                         self.data['costShell'] = 'gold-shell' if price[
                             1] else 'silver-shell'
                         break
             ResMgr.purge(xmlPath, True)
             break
コード例 #20
0
 def __readBasicConfig(self, xmlCtx, section):
     self.itemTypeName = 'equipment'
     self.name = section.name
     self.id = (nations.NONE_INDEX,
                _xml.readInt(xmlCtx, section, 'id', 0, 65535))
     self.compactDescr = vehicles.makeIntCompactDescrByID(
         'equipment', *self.id)
     if not section.has_key('tags'):
         self.tags = frozenset()
     else:
         self.tags = _readTags(xmlCtx, section, 'tags', 'equipment')
     if IS_CLIENT or IS_WEB:
         self.userString = i18n.makeString(section.readString('userString'))
         self.description = i18n.makeString(
             section.readString('description'))
         self.icon = _xml.readIcon(xmlCtx, section, 'icon')
     if IS_CELLAPP or not section.has_key('vehicleFilter'):
         self.__vehicleFilter = None
     else:
         self.__vehicleFilter = _VehicleFilter((xmlCtx, 'vehicleFilter'),
                                               section['vehicleFilter'])
     if not section.has_key('incompatibleTags'):
         self.__equipmentFilter = None
     else:
         self.__equipmentFilter = _EquipmentFilter(
             (xmlCtx, 'incompatibleTags'), section['incompatibleTags'])
     return
コード例 #21
0
def _readBookItem(pricesCache, cache, xmlCtx, section, storage):
    bookID = _xml.readInt(xmlCtx, section, 'id', 1)
    priceGroup = section.readString('priceGroup')
    tags = _readGroupTags((xmlCtx, 'tags'), section, 'tags')
    nameID = _xml.readStringOrEmpty(xmlCtx, section, 'name')
    descriptionID = _xml.readStringOrEmpty(xmlCtx, section, 'description')
    iconID = _xml.readNonEmptyString(xmlCtx, section, 'icon')
    type = _xml.readNonEmptyString(xmlCtx, section, 'type')
    if type not in crew_books_constants.CREW_BOOK_RARITY.ALL_TYPES:
        _xml.raiseWrongXml(xmlCtx, 'type', "unknown crew book rarity type '%s'" % type)
    crewBookItem = cb.CrewBook(bookID, priceGroup, nameID, descriptionID, iconID, type, tags)
    if section.has_key('filters'):
        filterSection = _xml.getSubsection(xmlCtx, section, 'filters')
        if filterSection.has_key('nation'):
            nation = filterSection.readString('nation', '')
            if nation and nation not in nations.NAMES:
                _xml.raiseWrongXml(xmlCtx, 'nation', "unknown nation '%s'" % nation)
            crewBookItem.nation = nation if nation else None
    if not crewBookItem.nation and type not in crew_books_constants.CREW_BOOK_RARITY.NO_NATION_TYPES:
        _xml.raiseWrongXml(xmlCtx, 'nation', "crew book with rarity type '%s' should have nation" % type)
    storage[bookID] = crewBookItem
    groupsDict = cache.priceGroups
    itemToGroup = cache.itemToPriceGroup
    if crewBookItem.priceGroup:
        if crewBookItem.priceGroup not in cache.priceGroupNames:
            _xml.raiseWrongXml(xmlCtx, 'priceGroup', 'unknown price group %s for item %s' % (crewBookItem.priceGroup, crewBookItem.id))
        priceGroupId = cache.priceGroupNames[crewBookItem.priceGroup]
        crewBookItem.priceGroupTags = groupsDict[priceGroupId].tags
        itemToGroup[crewBookItem.compactDescr] = groupsDict[priceGroupId].compactDescr
        itemNotInShop = section.readBool('notInShop', False)
        _copyPriceForItem(pricesCache, groupsDict[priceGroupId].compactDescr, crewBookItem.compactDescr, itemNotInShop)
    else:
        _xml.raiseWrongXml(xmlCtx, 'priceGroup', 'no price for item %s' % crewBookItem.id)
    return
コード例 #22
0
 def typeShell(self, effectsIndex):
     self.data['costShell'] = 'unknown'
     self.data['shellKind'] = 'not_shell'
     if (self.data['attackerID'] == 0) or (self.data['attackReasonID'] != 0):
         return
     player = BigWorld.player()
     attacker = player.arena.vehicles.get(self.data['attackerID'])
     if (attacker is None) or not attacker['vehicleType']:
         self.data['shellKind'] = None
         self.data['caliber'] = None
         self.data['costShell'] = None
         return
     for shell in attacker['vehicleType'].gun['shots']:
         if effectsIndex == shell['shell']['effectsIndex']:
             self.data['shellKind'] = str(shell['shell']['kind']).lower()
             self.data['caliber'] = shell['shell']['caliber']
             xmlPath = ITEM_DEFS_PATH + 'vehicles/' + nations.NAMES[shell['shell']['id'][0]] + '/components/shells.xml'
             for name, subsection in ResMgr.openSection(xmlPath).items():
                 if name != 'icons':
                     xmlCtx = (None, xmlPath + '/' + name)
                     if _xml.readInt(xmlCtx, subsection, 'id', 0, 65535) == shell['shell']['id'][1]:
                         price = _xml.readPrice(xmlCtx, subsection, 'price')
                         self.data['costShell'] = 'gold-shell' if price[1] else 'silver-shell'
                         break
             ResMgr.purge(xmlPath, True)
             break
コード例 #23
0
ファイル: artefacts.py プロジェクト: mahmoudimus/WOT-0.9.20.0
 def _readBasicConfig(self, xmlCtx, section):
     self.name = section.name
     self.id = (nations.NONE_INDEX,
                _xml.readInt(xmlCtx, section, 'id', 0, 65535))
     self.compactDescr = vehicles.makeIntCompactDescrByID(
         self.itemTypeName, *self.id)
     if not section.has_key('tags'):
         self.tags = frozenset()
     else:
         self.tags = _readTags(xmlCtx, section, 'tags', self.itemTypeName)
     if IS_CLIENT or IS_WEB:
         self.i18n = shared_components.I18nComponent(
             section.readString('userString'),
             section.readString('description'))
         self.icon = _xml.readIcon(xmlCtx, section, 'icon')
     if IS_CELLAPP or not section.has_key('vehicleFilter'):
         self.__vehicleFilter = None
     else:
         self.__vehicleFilter = _VehicleFilter((xmlCtx, 'vehicleFilter'),
                                               section['vehicleFilter'])
     if not section.has_key('incompatibleTags'):
         self.__artefactFilter = None
     else:
         self.__artefactFilter = _ArtefactFilter(
             (xmlCtx, 'incompatibleTags'), section['incompatibleTags'],
             self.itemTypeName)
     self.removable = section.readBool('removable', False)
     return
コード例 #24
0
def _readShotDamageTriggerSection(xmlCtx, section, _, triggerID):
    return _readDispatchableTriggerSection(xmlCtx,
                                           section,
                                           triggerID,
                                           triggers.ShotDamageTrigger,
                                           maxCount=_xml.readInt(
                                               xmlCtx, section, 'max-count'))
コード例 #25
0
def readWheelsAndGroups(xmlCtx, section):
    """Reads sections 'wheels/group' and 'wheels/wheel' for each chassis.
    :param xmlCtx: tuple(root ctx or None, path to section).
    :param section: instance of DataSection.
    :return: tuple(sequence of groups, sequence of wheels).
    """
    wheelGroups = []
    wheels = []
    defSyncAngle = section.readFloat('wheels/leadingWheelSyncAngle', 60)
    for sname, subsection in _xml.getChildren(xmlCtx, section, 'wheels'):
        if sname == 'group':
            ctx = (xmlCtx, 'wheels/group')
            group = chassis_components.WheelGroup(
                isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                template=_xml.readNonEmptyString(ctx, subsection, 'template'),
                count=_xml.readInt(ctx, subsection, 'count', 1),
                startIndex=subsection.readInt('startIndex', 0),
                radius=_xml.readPositiveFloat(ctx, subsection, 'radius'))
            wheelGroups.append(group)
        elif sname == 'wheel':
            ctx = (xmlCtx, 'wheels/wheel')
            w = chassis_components.Wheel(
                isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                radius=_xml.readPositiveFloat(ctx, subsection, 'radius'),
                nodeName=_xml.readNonEmptyString(ctx, subsection, 'name'),
                isLeading=subsection.readBool('isLeading', False),
                leadingSyncAngle=subsection.readFloat('syncAngle',
                                                      defSyncAngle))
            wheels.append(w)

    return (tuple(wheelGroups), tuple(wheels))
コード例 #26
0
    def readFromXML(self, xmlCtx, section, *args):
        super(ProgressionTree, self).readFromXML(xmlCtx, section, *args)
        xmlCtx = (xmlCtx, section.name)
        if not section.has_key('steps'):
            _xml.raiseWrongXml(xmlCtx, None, 'Steps not found')
        features, modifications, pairModifications = args
        _ACTION_RESOLVERS = {
            'modification':
            lambda x: (ACTION_TYPES.MODIFICATION, modifications.get(x)),
            'pair_modification':
            lambda x:
            (ACTION_TYPES.PAIR_MODIFICATION, pairModifications.get(x)),
            'feature':
            lambda x: (ACTION_TYPES.FEATURE, features.get(x))
        }
        steps = {}
        for name, data in section['steps'].items():
            if name != 'step':
                _xml.raiseWrongXml(xmlCtx, name, 'Unexpected subsection')
            step = TreeStep()
            step.readFromXML(xmlCtx, data, _ACTION_RESOLVERS)
            steps[step.id] = step

        for stepID, step in steps.iteritems():
            for unlockID in step.unlocks:
                steps[unlockID].addRequiredUnlock(stepID)

        self.steps = steps
        self.rootStep = _xml.readInt(xmlCtx, section, 'rootStep')
        if self.rootStep not in self.steps or steps[
                self.rootStep].requiredUnlocks:
            _xml.raiseWrongXml(xmlCtx, None,
                               'Invalid root step id {}'.format(self.rootStep))
        self._validateLevels(xmlCtx)
        return
コード例 #27
0
def readGroundNodesAndGroups(xmlCtx, section):
    if section['groundNodes'] is None:
        return (component_constants.EMPTY_TUPLE,
                component_constants.EMPTY_TUPLE)
    else:
        groundGroups = []
        groundNodes = []
        for sname, subsection in _xml.getChildren(xmlCtx, section,
                                                  'groundNodes'):
            if sname == 'group':
                ctx = (xmlCtx, 'groundNodes/group')
                group = chassis_components.GroundNodeGroup(
                    isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                    minOffset=_xml.readFloat(ctx, subsection, 'minOffset'),
                    maxOffset=_xml.readFloat(ctx, subsection, 'maxOffset'),
                    template=intern(
                        _xml.readNonEmptyString(ctx, subsection, 'template')),
                    count=_xml.readInt(ctx, subsection, 'count', 1),
                    startIndex=subsection.readInt('startIndex', 0))
                groundGroups.append(group)
            if sname == 'node':
                ctx = (xmlCtx, 'groundNodes/node')
                groundNode = chassis_components.GroundNode(
                    name=intern(
                        _xml.readNonEmptyString(ctx, subsection, 'name')),
                    isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                    minOffset=_xml.readFloat(ctx, subsection, 'minOffset'),
                    maxOffset=_xml.readFloat(ctx, subsection, 'maxOffset'))
                groundNodes.append(groundNode)

        return (tuple(groundGroups), tuple(groundNodes))
コード例 #28
0
ファイル: techtree_dp.py プロジェクト: webiumsk/WOT-0.9.15.1
    def __readSharedMetrics(self, shared, xmlCtx, section):
        precessed = _xml.getChildren(xmlCtx, section, 'grids')
        for name, gridSection in precessed:
            gridName = gridSection.asString
            xPath = '{0:>s}/{1:>s}/{2:>s}'.format(TREE_SHARED_REL_FILE_PATH, name, gridName)
            gridCtx = (None, xPath)
            subSec = _xml.getSubsection(xmlCtx, gridSection, 'root')
            xmlCtx = (None, '{0:>s}/root'.format(xPath))
            rootPos = {'start': _xml.readVector2(xmlCtx, subSec, 'start').tuple(),
             'step': _xml.readInt(xmlCtx, subSec, 'step')}
            subSec = _xml.getSubsection(gridCtx, gridSection, 'vertical')
            xmlCtx = (None, '{0:>s}/vertical'.format(xPath))
            vertical = (_xml.readInt(xmlCtx, subSec, 'start'), _xml.readInt(xmlCtx, subSec, 'step'))
            subSec = _xml.getSubsection(gridCtx, gridSection, 'horizontal')
            xmlCtx = (None, '{0:>s}/horizontal'.format(xPath))
            horizontal = (_xml.readInt(xmlCtx, subSec, 'start'), _xml.readInt(xmlCtx, subSec, 'step'))
            shared['grids'][gridName] = {'root': rootPos,
             'vertical': vertical,
             'horizontal': horizontal}

        precessed = _xml.getChildren(xmlCtx, section, 'lines')
        lines = shared['lines']
        for name, sub in precessed:
            xPath = '{0:>s}/{1:>s}'.format(TREE_SHARED_REL_FILE_PATH, name)
            xmlCtx = (None, xPath)
            pinsSec = _xml.getChildren(xmlCtx, sub, 'inPin')
            inPins = dict(((pName, pSec.asVector2.tuple()) for pName, pSec in pinsSec))
            pinsSec = _xml.getChildren(xmlCtx, sub, 'outPin')
            outPins = dict(((pName, pSec.asVector2.tuple()) for pName, pSec in pinsSec))
            pinsSec = _xml.getChildren(xmlCtx, sub, 'viaPin')
            viaPins = defaultdict(dict)
            for outPin, setSec in pinsSec:
                for inPin, pSec in setSec.items():
                    viaPins[outPin][inPin] = map(lambda section: section[1].asVector2.tuple(), pSec.items())

            defSec = sub['default']
            default = {}
            if defSec is not None:
                xmlCtx = (None, '{0:>s}/default'.format(xPath))
                default = {'outPin': _xml.readString(xmlCtx, defSec, 'outPin'),
                 'inPin': _xml.readString(xmlCtx, defSec, 'inPin')}
            lines[name] = {'inPins': inPins,
             'outPins': outPins,
             'viaPins': viaPins,
             'default': default}

        return
コード例 #29
0
def readWheelsAndGroups(xmlCtx, section):
    wheelGroups = []
    wheels = []
    wheelId = 0
    defSyncAngle = section.readFloat('wheels/leadingWheelSyncAngle', 60)
    for sname, subsection in _xml.getChildren(xmlCtx, section, 'wheels'):
        if sname == 'group':
            ctx = (xmlCtx, 'wheels/group')
            group = chassis_components.WheelGroup(
                isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                template=intern(
                    _xml.readNonEmptyString(ctx, subsection, 'template')),
                count=_xml.readInt(ctx, subsection, 'count', 1),
                startIndex=subsection.readInt('startIndex', 0),
                radius=_xml.readPositiveFloat(ctx, subsection, 'radius'))
            wheelGroups.append(group)
        if sname == 'wheel':
            from items.vehicles import _readHitTester, _readArmor
            ctx = (xmlCtx, 'wheels/wheel[{}]'.format(wheelId))
            radiusKey = 'radius' if subsection.has_key(
                'radius') else 'geometry/radius'
            index = _xml.readIntOrNone(ctx, subsection, 'index')
            actualIndex = wheelId if index is None else index
            w = chassis_components.Wheel(
                index=index,
                isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                radius=_xml.readPositiveFloat(ctx, subsection, radiusKey),
                nodeName=intern(
                    _xml.readNonEmptyString(ctx, subsection, 'name')),
                isLeading=subsection.readBool('isLeading', False),
                leadingSyncAngle=subsection.readFloat('syncAngle',
                                                      defSyncAngle),
                hitTester=_readHitTester(ctx,
                                         subsection,
                                         'hitTester',
                                         optional=True),
                materials=_readArmor(ctx,
                                     subsection,
                                     'armor',
                                     optional=True,
                                     index=actualIndex),
                position=subsection.readVector3('wheelPos', (0, 0, 0)))
            if IS_EDITOR:
                w.editorData.defSyncAngle = defSyncAngle
            wheels.append(w)
            wheelId += 1

    wheelIndices = [wheel.index for wheel in wheels]
    if sorted(wheelIndices) == range(len(wheels)):
        sortedWheels = [None] * len(wheels)
        for wheel in wheels:
            sortedWheels[wheel.index] = wheel

        wheels = sortedWheels
    elif wheelIndices == [None] * len(wheels):
        pass
    else:
        LOG_ERROR('Invalid wheel index detected', xmlCtx, wheels)
    return (tuple(wheelGroups), tuple(wheels))
コード例 #30
0
 def shell(self):                
     xmlPath = ''
     for nation in nations.NAMES:
         xmlPath = '%s%s%s%s' % (ITEM_DEFS_PATH, 'vehicles/', nation, '/components/shells.xml')
         xmlCtx_s = (((None, '{}/{}'.format(xmlPath, n)), s) for n, s in ResMgr.openSection(xmlPath).items() if (n != 'icons') and (n != 'xmlns:xmlref'))
         id_xmlCtx_s = ((_xml.readInt(xmlCtx, s, 'id', 0, 65535), xmlCtx, s) for xmlCtx, s in xmlCtx_s)
         self.shells[nation] = [i for i, xmlCtx, s in id_xmlCtx_s if s.readBool('improved', False)]
     ResMgr.purge(xmlPath, True)
コード例 #31
0
 def shell(self):
     xmlPath = ''
     for nation in nations.NAMES:
         xmlPath = '%s%s%s%s' % (ITEM_DEFS_PATH, 'vehicles/', nation, '/components/shells.xml')
         xmlCtx_s = (((None, '{}/{}'.format(xmlPath, n)), s) for n, s in ResMgr.openSection(xmlPath).items() if (n != 'icons') and (n != 'xmlns:xmlref'))
         id_xmlCtx_s = ((_xml.readInt(xmlCtx, s, 'id', 0, 65535), xmlCtx, s) for xmlCtx, s in xmlCtx_s)
         self.shells[nation] = [i for i, xmlCtx, s in id_xmlCtx_s if s.readBool('improved', False)]
     ResMgr.purge(xmlPath, True)
コード例 #32
0
def _readInventoryItemTriggerSection(xmlCtx, section, _, triggerID):
    itemTypeID = _xml.readInt(xmlCtx, section, 'item-type-id')
    return sub_parsers._readValidateVarTriggerSection(
        xmlCtx,
        section,
        triggerID,
        triggers.InventoryItemTrigger,
        itemTypeID=itemTypeID)
コード例 #33
0
def _readMiscSlot(ctx, subsection, slotType):
    descr = shared_components.MiscSlot(
        type=slotType,
        slotId=_xml.readInt(ctx, subsection, 'slotId'),
        position=_xml.readVector3OrNone(ctx, subsection, 'position'),
        rotation=_xml.readVector3OrNone(ctx, subsection, 'rotation'),
        attachNode=_xml.readStringOrNone(ctx, subsection, 'attachNode'))
    _verifySlotId(ctx, slotType, descr.slotId)
    return descr
コード例 #34
0
def _readProjectionDecalSlot(ctx, subsection, slotType):
    descr = shared_components.ProjectionDecalSlotDescription(
        slotType=slotType,
        slotId=_xml.readInt(ctx, subsection, 'slotId'),
        anchorPosition=_xml.readVector3OrNone(ctx, subsection,
                                              'anchorPosition'),
        anchorDirection=_xml.readVector3OrNone(ctx, subsection,
                                               'anchorDirection'),
        position=_xml.readVector3OrNone(ctx, subsection, 'position'),
        rotation=_xml.readVector3OrNone(ctx, subsection, 'rotation'),
        scale=_xml.readVector3OrNone(ctx, subsection, 'scale'),
        scaleFactors=_xml.readVector3(
            ctx, subsection, 'scaleFactors',
            c11n_constants.DEFAULT_DECAL_SCALE_FACTORS),
        doubleSided=_xml.readBool(ctx, subsection, 'doubleSided', False),
        canBeMirroredVertically=_xml.readBool(ctx, subsection,
                                              'verticalMirror', False),
        showOn=_xml.readIntOrNone(ctx, subsection, 'showOn'),
        tags=readOrderedTagsOrEmpty(ctx, subsection,
                                    _customizationSlotTagsValidator),
        clipAngle=_xml.readFloat(ctx, subsection, 'clipAngle',
                                 c11n_constants.DEFAULT_DECAL_CLIP_ANGLE))
    _verifySlotId(ctx, slotType, descr.slotId)
    if descr.showOn is not None:
        availableShowOnRegions = c11n_constants.ApplyArea.HULL | c11n_constants.ApplyArea.TURRET | c11n_constants.ApplyArea.GUN
        if descr.showOn | availableShowOnRegions != availableShowOnRegions:
            _xml.raiseWrongSection(ctx, 'showOn')
    if subsection.has_key('attachedPart'):
        attachedPartsData = _xml.readString(ctx, subsection, 'attachedPart')
        descr.attachedParts = defaultdict(set)
        for partData in attachedPartsData.split():
            pType, pName = partData.split(':')
            if pType != 'hull':
                descr.attachedParts[pType].add(pName)

    if subsection.has_key('compatibleModels'):
        descr.compatibleModels = _xml.readTupleOfStrings(
            ctx, subsection, 'compatibleModels')
    if subsection.has_key('itemId'):
        descr.itemId = _xml.readInt(ctx, subsection, 'itemId')
    if subsection.has_key('options'):
        descr.options = _xml.readNonNegativeInt(ctx, subsection, 'options')
    return descr
コード例 #35
0
ファイル: lobby.py プロジェクト: 19colt87/WOTDecompiled
def _readTankmanLevelTriggerSection(xmlCtx, section, _, triggerID):
    role = _xml.readString(xmlCtx, section, 'role')
    roleLevel = _xml.readInt(xmlCtx, section, 'role-level')
    inVehicleFlagID = _xml.readString(xmlCtx, section, 'in-vehicle')
    specVehicleFlagID = section.readString('spec-vehicle')
    if not len(specVehicleFlagID):
        specVehicleFlagID = None
    setVarID = section.readString('set-var')
    if not len(setVarID):
        setVarID = None
    return triggers.TankmanLevelTrigger(triggerID, role, roleLevel, setVarID, inVehicleFlagID, specVehicleFlagID)
コード例 #36
0
ファイル: artefacts.py プロジェクト: webiumsk/WOT0.9.10
 def _readConfig(self, xmlCtx, section):
     self.delay = _xml.readPositiveFloat(xmlCtx, section, 'delay')
     self.duration = _xml.readPositiveFloat(xmlCtx, section, 'duration')
     self.shotsNumber = _xml.readNonNegativeInt(xmlCtx, section, 'shotsNumber')
     self.areaRadius = _xml.readPositiveFloat(xmlCtx, section, 'areaRadius')
     self.shellCompactDescr = _xml.readInt(xmlCtx, section, 'shellCompactDescr')
     self.piercingPower = _xml.readTupleOfPositiveInts(xmlCtx, section, 'piercingPower', 2)
     self.areaVisual = _xml.readStringOrNone(xmlCtx, section, 'areaVisual')
     self.areaColor = _xml.readIntOrNone(xmlCtx, section, 'areaColor')
     self.areaMarker = _xml.readStringOrNone(xmlCtx, section, 'areaMarker')
     self.areaLength = self.areaWidth = self.areaRadius * 2
     self.reusable = _xml.readBool(xmlCtx, section, 'reusable')
     self.cooldownTime = _xml.readNonNegativeFloat(xmlCtx, section, 'cooldownTime') if self.reusable else 0.0
     self.deployTime = _xml.readNonNegativeFloat(xmlCtx, section, 'deployTime')
コード例 #37
0
ファイル: artefacts.py プロジェクト: wotmods/WOTDecompiled
 def __readBasicConfig(self, xmlCtx, section):
     self.itemTypeName = 'optionalDevice'
     self.name = section.name
     self.id = (nations.NONE_INDEX, _xml.readInt(xmlCtx, section, 'id', 0, 65535))
     self.compactDescr = vehicles.makeIntCompactDescrByID('optionalDevice', *self.id)
     if IS_CLIENT or IS_WEB:
         self.userString = i18n.makeString(section.readString('userString'))
         self.description = i18n.makeString(section.readString('description'))
         self.icon = _xml.readIcon(xmlCtx, section, 'icon')
     if IS_CELLAPP or not section.has_key('vehicleFilter'):
         self.__filter = None
     else:
         self.__filter = _VehicleFilter((xmlCtx, 'vehicleFilter'), section['vehicleFilter'])
     self.removable = section.readBool('removable', False)
コード例 #38
0
ファイル: vehicle.py プロジェクト: Bouilloire/WoTConfig
            def getShellPrice(nationID, shellID):
                import ResMgr, nations
                from items import _xml, vehicles
                from constants import ITEM_DEFS_PATH

                price = {}
                xmlPath = ITEM_DEFS_PATH + 'vehicles/' + nations.NAMES[nationID] + '/components/shells.xml'
                for name, subsection in ResMgr.openSection(xmlPath).items():
                    if name != 'icons':
                        xmlCtx = (None, xmlPath + '/' + name)
                        if _xml.readInt(xmlCtx, subsection, 'id', 0, 65535) == shellID:
                            price = _xml.readPrice(xmlCtx, subsection, 'price')
                            break
                ResMgr.purge(xmlPath, True)

                return price
コード例 #39
0
ファイル: hitLog.py プロジェクト: atterdag/atterdag-wot-mods
 def onEnterWorld(self, vehicle):
     self.player = BigWorld.player()
     self.playerVehicleID = self.player.playerVehicleID
     self.ammo = self.guiSessionProvider.shared.ammo
     shots = vehicle.typeDescriptor.gun.shots
     nation = nations.NAMES[vehicle.typeDescriptor.type.id[0]]
     xmlPath = '%s%s%s%s' % (ITEM_DEFS_PATH, 'vehicles/', nation, '/components/shells.xml')
     xmlCtx_s = (((None, '{}/{}'.format(xmlPath, n)), s) for n, s in ResMgr.openSection(xmlPath).items() if (n != 'icons') and (n != 'xmlns:xmlref'))
     goldShells = [_xml.readInt(xmlCtx, s, 'id', 0, 65535) for xmlCtx, s in xmlCtx_s if s.readBool('improved', False)]
     for shot in shots:
         shell = shot.shell
         intCD = shell.compactDescr
         self.shells[intCD] = {}
         self.shells[intCD]['shellKind'] = shell.kind.lower()
         self.shells[intCD]['shellDamage'] = shell.damage[0]
         self.shells[intCD]['costShell'] = 'gold-shell' if shell.id[1] in goldShells else 'silver-shell'
     ResMgr.purge(xmlPath, True)
コード例 #40
0
ファイル: potapov_quests.py プロジェクト: Infernux/Projects
 def __readSeasons(self):
     xmlPath = _POTAPOV_QUEST_XML_PATH + '/seasons.xml'
     section = ResMgr.openSection(xmlPath)
     if section is None:
         _xml.raiseWrongXml(None, xmlPath, 'can not open or read')
     self.__seasonsInfo = idToSeason = {}
     ids = {}
     for (sname, ssection,) in section.items():
         ctx = (None, xmlPath)
         if sname in ids:
             _xml.raiseWrongXml(ctx, '', 'season name is not unique')
         seasonID = _xml.readInt(ctx, ssection, 'id', 0, 15)
         if seasonID in idToSeason:
             _xml.raiseWrongXml(ctx, 'id', 'is not unique')
         basicInfo = {'name': sname}
         if IS_CLIENT or IS_WEB:
             basicInfo['userString'] = i18n.makeString(ssection.readString('userString'))
             basicInfo['description'] = i18n.makeString(ssection.readString('description'))
         ids[sname] = seasonID
         idToSeason[seasonID] = basicInfo
コード例 #41
0
ファイル: artefacts.py プロジェクト: wotmods/WOTDecompiled
 def __readBasicConfig(self, xmlCtx, section):
     self.itemTypeName = 'equipment'
     self.name = section.name
     self.id = (nations.NONE_INDEX, _xml.readInt(xmlCtx, section, 'id', 0, 65535))
     self.compactDescr = vehicles.makeIntCompactDescrByID('equipment', *self.id)
     if not section.has_key('tags'):
         self.tags = frozenset()
     else:
         self.tags = _readTags(xmlCtx, section, 'tags', 'equipment')
     if IS_CLIENT or IS_WEB:
         self.userString = i18n.makeString(section.readString('userString'))
         self.description = i18n.makeString(section.readString('description'))
         self.icon = _xml.readIcon(xmlCtx, section, 'icon')
     if IS_CELLAPP or not section.has_key('vehicleFilter'):
         self.__vehicleFilter = None
     else:
         self.__vehicleFilter = _VehicleFilter((xmlCtx, 'vehicleFilter'), section['vehicleFilter'])
     if not section.has_key('incompatibleTags'):
         self.__equipmentFilter = None
     else:
         self.__equipmentFilter = _EquipmentFilter((xmlCtx, 'incompatibleTags'), section['incompatibleTags'])
コード例 #42
0
    def __readTiles(self):
        xmlPath = _POTAPOV_QUEST_XML_PATH + '/tiles.xml'
        section = ResMgr.openSection(xmlPath)
        if section is None:
            _xml.raiseWrongXml(None, xmlPath, 'can not open or read')
        self.__tilesInfo = idToTile = {}
        ids = {}
        for tname, tsection in section.items():
            if tname == 'quests':
                continue
            ctx = (None, xmlPath)
            if tname in ids:
                _xml.raiseWrongXml(ctx, '', 'tile name is not unique')
            seasonID = _xml.readInt(ctx, tsection, 'seasonID')
            g_seasonCache.getSeasonInfo(seasonID)
            tileID = _xml.readInt(ctx, tsection, 'id', 0, 15)
            if tileID in idToTile:
                _xml.raiseWrongXml(ctx, 'id', 'is not unique')
            chainsCount = _xml.readInt(ctx, tsection, 'chainsCount', 1, 15)
            chainsCountToUnlockNext = _xml.readInt(ctx, tsection, 'chainsCountToUnlockNext', 0, 15)
            nextTileID = _xml.readInt(ctx, tsection, 'nextTileID', 0, 15)
            achievements = {}
            basicInfo = {'name': tname,
             'chainsCount': chainsCount,
             'nextTileID': nextTileID,
             'chainsCountToUnlockNext': chainsCountToUnlockNext,
             'questsInChain': _xml.readInt(ctx, tsection, 'questsInChain', 1, 100),
             'price': _xml.readPrice(ctx, tsection, 'price'),
             'achievements': achievements,
             'seasonID': seasonID,
             'tokens': set(_xml.readString(ctx, tsection, 'tokens').split())}
            if tsection.has_key('achievements'):
                for aname, asection in tsection['achievements'].items():
                    _, aid = aname.split('_')
                    achievements[int(aid)] = asection.asString

                if len(achievements) < basicInfo['chainsCount']:
                    _xml.raiseWrongXml(ctx, 'achievements', 'wrong achievement number')
            if IS_CLIENT or IS_WEB:
                basicInfo['userString'] = i18n.makeString(tsection.readString('userString'))
                basicInfo['description'] = i18n.makeString(tsection.readString('description'))
                basicInfo['iconID'] = i18n.makeString(tsection.readString('iconID'))
            ids[tname] = tileID
            idToTile[tileID] = basicInfo

        return
コード例 #43
0
ファイル: lobby.py プロジェクト: 19colt87/WOTDecompiled
def _readInventoryItemTriggerSection(xmlCtx, section, _, triggerID):
    itemTypeID = _xml.readInt(xmlCtx, section, 'item-type-id')
    return sub_parsers._readValidateVarTriggerSection(xmlCtx, section, triggerID, triggers.InventoryItemTrigger, itemTypeID=itemTypeID)
コード例 #44
0
ファイル: artefacts.py プロジェクト: webiumsk/WOT0.9.10
 def _readConfig(self, xmlCtx, section):
     self.crewLevelIncrease = _xml.readInt(xmlCtx, section, 'crewLevelIncrease', 1)
コード例 #45
0
ファイル: artefacts.py プロジェクト: webiumsk/WOT0.9.10
 def _readConfig(self, xmlCtx, section):
     self.enginePowerFactor = _xml.readPositiveFloat(xmlCtx, section, 'enginePowerFactor')
     self.durationSeconds = _xml.readInt(xmlCtx, section, 'durationSeconds', 1)
コード例 #46
0
ファイル: tankmen.py プロジェクト: webiumsk/WOT-0.9.14-CT
def _readSkillInt(paramName, minVal, xmlCtx, section, subsectionName):
    res, xmlCtx, section = _readSkillBasics(xmlCtx, section, subsectionName)
    res[paramName] = _xml.readInt(xmlCtx, section, paramName, minVal)
    return res
コード例 #47
0
ファイル: damageLog.py プロジェクト: peterbartha/ImmunoMod
 def isStunningShell(n, s):
     if n != 'icons':
         xmlCtx = (None, xmlPath + '/' + n)
         stunDuration = _xml.readStringOrNone(xmlCtx, s, 'stunDuration')
         return _xml.readInt(xmlCtx, s, 'id', 0, 65535) if stunDuration else None
コード例 #48
0
ファイル: damageLog.py プロジェクト: peterbartha/ImmunoMod
 def isGoldShell(n, s):
     if n != 'icons':
         xmlCtx = (None, xmlPath + '/' + n)
         price = 'gold' in _xml.readPrice(xmlCtx, s, 'price')
         return _xml.readInt(xmlCtx, s, 'id', 0, 65535) if price else None
コード例 #49
0
    def __readQuestList(self):
        xmlPath = _POTAPOV_QUEST_XML_PATH + '/list.xml'
        section = ResMgr.openSection(xmlPath)
        if section is None:
            _xml.raiseWrongXml(None, xmlPath, 'can not open or read')
        self.__potapovQuestIDToQuestType = idToQuest = {}
        self.__questUniqueIDToPotapovQuestID = questUniqueNameToPotapovQuestID = {}
        self.__tileIDchainIDToPotapovQuestID = tileIDchainIDToPotapovQuestID = {}
        self.__tileIDchainIDToFinalPotapovQuestID = tileIDchainIDToFinalPotapovQuestID = {}
        self.__tileIDchainIDToInitialPotapovQuestID = tileIDchainIDToInitialPotapovQuestID = {}
        ids = {}
        curTime = int(time.time())
        xmlSource = quest_xml_source.Source()
        for qname, qsection in section.items():
            splitted = qname.split('_')
            ctx = (None, xmlPath)
            if qname in ids:
                _xml.raiseWrongXml(ctx, '', 'potapov quest name is not unique')
            potapovQuestID = _xml.readInt(ctx, qsection, 'id', 0, 1023)
            if potapovQuestID in idToQuest:
                _xml.raiseWrongXml(ctx, 'id', 'is not unique')
            questBranchName, tileID, chainID, internalID = splitted
            tileInfo = g_tileCache.getTileInfo(int(tileID))
            if 1 <= chainID <= tileInfo['chainsCount']:
                _xml.raiseWrongXml(ctx, '', 'quest chainID must be between 1 and %s' % tileInfo['chainsCount'])
            if 1 <= internalID <= tileInfo['questsInChain']:
                _xml.raiseWrongXml(ctx, '', 'quest internalID must be between 1 and %s' % tileInfo['chainsCount'])
            minLevel = _xml.readInt(ctx, qsection, 'minLevel', 1, 10)
            maxLevel = _xml.readInt(ctx, qsection, 'maxLevel', minLevel, 10)
            basicInfo = {'name': qname,
             'id': potapovQuestID,
             'branch': PQ_BRANCH.NAME_TO_TYPE[questBranchName],
             'tileID': int(tileID),
             'chainID': int(chainID),
             'internalID': int(internalID),
             'minLevel': minLevel,
             'maxLevel': maxLevel,
             'requiredUnlocks': frozenset(map(int, _xml.readString(ctx, qsection, 'requiredUnlocks').split()))}
            rewardByDemand = qsection.readInt('rewardByDemand', 0)
            if rewardByDemand != 0 and rewardByDemand not in PQ_REWARD_BY_DEMAND.keys():
                raise Exception('Unexpected value for rewardByDemand')
            basicInfo['rewardByDemand'] = rewardByDemand
            tags = _readTags(ctx, qsection, 'tags')
            basicInfo['tags'] = tags
            if questBranchName == 'regular':
                if 0 == len(tags & VEHICLE_CLASS_TAGS):
                    _xml.raiseWrongXml(ctx, 'tags', 'quest vehicle class is not specified')
            if questBranchName == 'fallout':
                if 0 == len(tags & _FALLOUT_BATTLE_TAGS):
                    _xml.raiseWrongXml(ctx, 'tags', 'quest fallout type is not specified')
            if IS_CLIENT or IS_WEB:
                basicInfo['userString'] = i18n.makeString(qsection.readString('userString'))
                basicInfo['description'] = i18n.makeString(qsection.readString('description'))
                basicInfo['advice'] = i18n.makeString(qsection.readString('advice'))
                basicInfo['condition_main'] = i18n.makeString(qsection.readString('condition_main'))
                basicInfo['condition_add'] = i18n.makeString(qsection.readString('condition_add'))
            questPath = ''.join([_POTAPOV_QUEST_XML_PATH,
             '/',
             questBranchName,
             '/tile_',
             tileID,
             '/chain_',
             chainID,
             '/',
             qname,
             '.xml'])
            questCtx = (None, questPath)
            nodes = xmlSource.readFromInternalFile(questPath, curTime)
            nodes = nodes.get(EVENT_TYPE.POTAPOV_QUEST, None)
            if nodes is None:
                _xml.raiseWrongXml(questCtx, 'potapovQuest', 'Potapov quests are not specified.')
            if len(nodes) != 2:
                _xml.raiseWrongXml(questCtx, 'potapovQuest', 'Main and additional quest should be presented.')
            qinfo = nodes[0].info
            if not qinfo['id'].endswith('main'):
                _xml.raiseWrongXml(questCtx, 'potapovQuest', 'Main quest must be first.')
            if qinfo['id'] in questUniqueNameToPotapovQuestID:
                _xml.raiseWrongXml(questCtx, 'potapovQuest', 'Duplicate name detected.')
            questUniqueNameToPotapovQuestID[qinfo['id']] = potapovQuestID
            basicInfo['mainQuestID'] = qinfo['id']
            if IS_CLIENT or IS_WEB:
                basicInfo['mainQuestInfo'] = qinfo['questClientData']
            qinfo = nodes[1].info
            if not qinfo['id'].endswith('add'):
                _xml.raiseWrongXml(questCtx, 'potapovQuest', 'Add quest must be second.')
            if qinfo['id'] in questUniqueNameToPotapovQuestID:
                _xml.raiseWrongXml(questCtx, 'potapovQuest', 'Duplicate name detected.')
            questUniqueNameToPotapovQuestID[qinfo['id']] = potapovQuestID
            basicInfo['addQuestID'] = qinfo['id']
            if IS_CLIENT or IS_WEB:
                basicInfo['addQuestInfo'] = qinfo['questClientData']
            idToQuest[potapovQuestID] = PQType(basicInfo)
            ids[qname] = potapovQuestID
            key = (int(tileID), int(chainID))
            tileIDchainIDToPotapovQuestID.setdefault(key, set()).add(potapovQuestID)
            if 'final' in tags:
                tileIDchainIDToFinalPotapovQuestID[key] = potapovQuestID
            if 'initial' in tags:
                tileIDchainIDToInitialPotapovQuestID[key] = potapovQuestID

        ResMgr.purge(xmlPath, True)
        return
コード例 #50
0
ファイル: battle.py プロジェクト: webiumsk/WOT0.9.10
def _readShotDamageTriggerSection(xmlCtx, section, _, triggerID):
    return _readDispatchableTriggerSection(xmlCtx, section, triggerID, triggers.ShotDamageTrigger, maxCount=_xml.readInt(xmlCtx, section, 'max-count'))
コード例 #51
0
ファイル: techtree_dp.py プロジェクト: webiumsk/WOT-0.9.15.1
    def __readNation(self, shared, nation, clearCache = False):
        xmlPath = NATION_TREE_REL_FILE_PATH % nation
        if clearCache:
            ResMgr.purge(xmlPath)
        section = ResMgr.openSection(xmlPath)
        if section is None:
            LOG_ERROR('can not open or read nation tree: ', nation, xmlPath)
            return {}
        else:
            xmlCtx = (None, xmlPath)
            settingsName = _xml.readString(xmlCtx, section, 'settings')
            if settingsName not in shared['settings']:
                LOG_ERROR('not found settings (<settings> tag): ', settingsName, xmlPath)
                return {}
            precessed = _xml.getSubsection(xmlCtx, section, 'grid')
            gridName = precessed.asString
            if gridName not in shared['grids']:
                LOG_ERROR('not found grid (<grid> tag): ', gridName, xmlPath)
                return {}
            xPath = '{0:>s}/grid'.format(xmlPath)
            xmlCtx = (None, xPath)
            grid = shared['grids'][gridName]
            settings = shared['settings'][settingsName]
            rows = _xml.readInt(xmlCtx, precessed, 'rows')
            columns = _xml.readInt(xmlCtx, precessed, 'columns')
            self.__displaySettings[nations.INDICES[nation]] = settings
            nationIndex = self.__availableNations.index(nation)
            hasRoot = settings['hasRoot']
            if hasRoot:
                coords = self.__makeGridCoordsWithRoot(grid, nationIndex, rows, columns)
            else:
                coords = self.__makeGridCoordsWoRoot(grid, rows, columns)
            getIDsByName = vehicles.g_list.getIDsByName
            makeIntCDByID = vehicles.makeIntCompactDescrByID
            getVehicle = vehicles.g_cache.vehicle
            precessed = _xml.getChildren(xmlCtx, section, 'nodes')
            displayInfo = {}
            for name, nodeSection in precessed:
                xPath = '{0:>s}/nodes/{1:>s}'.format(xmlPath, name)
                xmlCtx = (None, xPath)
                uName = '{0:>s}:{1:>s}'.format(nation, name)
                try:
                    nationID, vTypeID = getIDsByName(uName)
                except Exception:
                    raise _ConfigError(xmlCtx, 'Unknown vehicle type name {0:>s}'.format(uName))

                nodeCD = makeIntCDByID(_VEHICLE_TYPE_NAME, nationID, vTypeID)
                vType = getVehicle(nationID, vTypeID)
                nextLevel = filter(lambda data: getTypeOfCompactDescr(data[1][1]) == _VEHICLE, enumerate(vType.unlocksDescrs))
                for unlockDescr in vType.unlocksDescrs:
                    self.__unlockPrices[unlockDescr[1]][vType.compactDescr] = unlockDescr[0]

                for idx, data in nextLevel:
                    xpCost = data[0]
                    nextCD = data[1]
                    required = data[2:]
                    self.__nextLevels[nodeCD][nextCD] = (idx, xpCost, set(required))
                    self.__topLevels[nextCD].add(nodeCD)
                    for itemCD in required:
                        self.__topItems[itemCD].add(nodeCD)

                row = _xml.readInt(xmlCtx, nodeSection, 'row')
                column = _xml.readInt(xmlCtx, nodeSection, 'column')
                if hasRoot and row > 1 and column is 1:
                    raise _ConfigError(xmlCtx, 'In first column must be one node - root node, {0:>s} '.format(uName))
                elif row > rows or column > columns:
                    raise _ConfigError(xmlCtx, 'Invalid row or column index: {0:>s}, {1:d}, {2:d}'.format(uName, row, column))
                lines = self.__readNodeLines(nodeCD, nation, xmlCtx, nodeSection, shared)
                displayInfo[nodeCD] = {'row': row,
                 'column': column,
                 'position': coords[column - 1][row - 1],
                 'lines': lines}

            return displayInfo
コード例 #52
0
ファイル: techtree_dp.py プロジェクト: krzcho/WOTDecompiled
    def __readShared(self, clearCache = False):
        if clearCache:
            ResMgr.purge(TREE_SHARED_REL_FILE_PATH)
        shared = {'settings': {},
         'grids': {},
         'default': {},
         'lines': {}}
        section = ResMgr.openSection(TREE_SHARED_REL_FILE_PATH)
        if section is None:
            _xml.raiseWrongXml(None, TREE_SHARED_REL_FILE_PATH, 'can not open or read')
        xmlCtx = (None, TREE_SHARED_REL_FILE_PATH)
        precessed = _xml.getChildren(xmlCtx, section, 'settings-set')
        for name, settingsSec in precessed:
            settingsName = settingsSec.asString
            xPath = '{0:>s}/{1:>s}/{2:>s}'.format(TREE_SHARED_REL_FILE_PATH, name, settingsName)
            xmlCtx = (None, xPath)
            settings = {}
            for _, settingSec in settingsSec.items():
                name = _xml.readString(xmlCtx, settingSec, 'name')
                if name not in DISPLAY_SETTINGS:
                    LOG_ERROR('Setting is invalid', name)
                    continue
                reader = DISPLAY_SETTINGS[name]
                value = getattr(_xml, reader)(xmlCtx, settingSec, 'value')
                settings[name] = value

            for name in DISPLAY_SETTINGS.iterkeys():
                if name not in settings:
                    raise _ConfigError(xmlCtx, 'Setting not found')

            shared['settings'][settingsName] = settings

        precessed = _xml.getChildren(xmlCtx, section, 'grids')
        for name, gridSection in precessed:
            gridName = gridSection.asString
            xPath = '{0:>s}/{1:>s}/{2:>s}'.format(TREE_SHARED_REL_FILE_PATH, name, gridName)
            gridCtx = (None, xPath)
            subSec = _xml.getSubsection(xmlCtx, gridSection, 'root')
            xmlCtx = (None, '{0:>s}/root'.format(xPath))
            rootPos = {'start': _xml.readVector2(xmlCtx, subSec, 'start').tuple(),
             'step': _xml.readInt(xmlCtx, subSec, 'step')}
            subSec = _xml.getSubsection(gridCtx, gridSection, 'vertical')
            xmlCtx = (None, '{0:>s}/vertical'.format(xPath))
            vertical = (_xml.readInt(xmlCtx, subSec, 'start'), _xml.readInt(xmlCtx, subSec, 'step'))
            subSec = _xml.getSubsection(gridCtx, gridSection, 'horizontal')
            xmlCtx = (None, '{0:>s}/horizontal'.format(xPath))
            horizontal = (_xml.readInt(xmlCtx, subSec, 'start'), _xml.readInt(xmlCtx, subSec, 'step'))
            shared['grids'][gridName] = {'root': rootPos,
             'vertical': vertical,
             'horizontal': horizontal}

        if self.__availableNations is None:
            self.__availableNations = self.__readAvailableNations((None, TREE_SHARED_REL_FILE_PATH), section)
        precessed = _xml.getChildren(xmlCtx, section, 'lines')
        lines = shared['lines']
        for name, sub in precessed:
            xPath = '{0:>s}/{1:>s}'.format(TREE_SHARED_REL_FILE_PATH, name)
            xmlCtx = (None, xPath)
            pinsSec = _xml.getChildren(xmlCtx, sub, 'inPin')
            inPins = dict(((pName, pSec.asVector2.tuple()) for pName, pSec in pinsSec))
            pinsSec = _xml.getChildren(xmlCtx, sub, 'outPin')
            outPins = dict(((pName, pSec.asVector2.tuple()) for pName, pSec in pinsSec))
            pinsSec = _xml.getChildren(xmlCtx, sub, 'viaPin')
            viaPins = defaultdict(_makeDict)
            for outPin, setSec in pinsSec:
                for inPin, pSec in setSec.items():
                    viaPins[outPin][inPin] = map(lambda section: section[1].asVector2.tuple(), pSec.items())

            defSec = sub['default']
            default = {}
            if defSec is not None:
                xmlCtx = (None, '{0:>s}/default'.format(xPath))
                default = {'outPin': _xml.readString(xmlCtx, defSec, 'outPin'),
                 'inPin': _xml.readString(xmlCtx, defSec, 'inPin')}
            lines[name] = {'inPins': inPins,
             'outPins': outPins,
             'viaPins': viaPins,
             'default': default}

        defSec = _xml.getSubsection(xmlCtx, section, 'default-line')
        xPath = '{0:>s}/default-line'.format(TREE_SHARED_REL_FILE_PATH)
        xmlCtx = (None, xPath)
        name = _xml.readString(xmlCtx, defSec, 'line')
        outPin = _xml.readString(xmlCtx, defSec, 'outPin')
        inPin = _xml.readString(xmlCtx, defSec, 'inPin')
        self.__getLineInfo(xmlCtx, name, 0, outPin, inPin, lines)
        shared['default'] = {'line': name,
         'inPin': inPin,
         'outPin': outPin}
        return shared