コード例 #1
0
    def __init__(self, vehicleDescr, crewCompactDescrs, mainSkillQualifiersApplier, activityFlags = None, isFire = False, stunFactors = None):
        if activityFlags is None:
            activityFlags = [True] * len(crewCompactDescrs)
        self._vehicleDescr = vehicleDescr
        self._crewCompactDescrs = crewCompactDescrs
        self._activityFlags = activityFlags
        self._isFire = isFire
        self._stunFactors = stunFactors
        self._mainSkillQualifiersApplier = mainSkillQualifiersApplier
        skills, femaleCount = self._validateAndComputeCrew()
        self._skills = skills
        if _DO_DEBUG_LOG:
            items = skills.iteritems()
            for skillName, skillData in sorted(items, cmp=lambda x, y: cmp(x[0], y[0])):
                LOG_DEBUG("TankmanIdxs/levels with skill '%s': %s" % (skillName, str(skillData)))

        self._commanderIdx = skills['commander'][0][0]
        self.__factorsDirty = True
        self._levelIncreaseByVehicle = 0.0
        skillData = skills.get('brotherhood')
        if skillData is None or len(skillData) != len(crewCompactDescrs) or 0 < femaleCount < len(skillData):
            self._levelIncreaseByBrotherhood = 0.0
        else:
            self._levelIncreaseByBrotherhood = tankmen.getSkillsConfig()['brotherhood']['crewLevelIncrease']
        self._camouflageFactor = 1.0
        return
コード例 #2
0
    def __init__(self,
                 vehicleDescr,
                 crewCompactDescrs,
                 activityFlags=None,
                 isFire=False):
        if activityFlags is None:
            activityFlags = [True] * len(crewCompactDescrs)
        self._vehicleDescr = vehicleDescr
        self._crewCompactDescrs = crewCompactDescrs
        self._activityFlags = activityFlags
        self._isFire = isFire
        self._skills = skills = self._validateAndComputeCrew()
        if _DO_DEBUG_LOG:
            items = skills.iteritems()
            for skillName, skillData in sorted(
                    items, cmp=lambda x, y: cmp(x[0], y[0])):
                LOG_DEBUG("TankmanIdxs/levels with skill '%s': %s" %
                          (skillName, str(skillData)))

        self._commanderIdx = skills['commander'][0][0]
        self.__factorsDirty = True
        self._levelIncreaseByVehicle = 0.0
        self._crewRolesFactor = 1.0
        skillData = skills.get('brotherhood')
        if skillData is None or len(skillData) != len(crewCompactDescrs):
            self._levelIncreaseByBrotherhood = 0.0
        else:
            self._levelIncreaseByBrotherhood = tankmen.getSkillsConfig(
            ).getSkill('brotherhood').crewLevelIncrease
        self._camouflageFactor = 1.0
        self._boostedSkills = {}
        return
コード例 #3
0
    def _processSkills(self, skillEfficiencies, commonLevelIncrease,
                       nonCommanderLevelIncrease):
        skills = self._skills
        isFire = self._isFire
        getSkill = tankmen.getSkillsConfig().getSkill
        skillToBoost = set(self._boostedSkills.iterkeys())
        callSkillProcessor = self.callSkillProcessor
        for skillName, efficiency, baseAvgLevel in skillEfficiencies:
            factor = 0.57 + 0.43 * efficiency
            skillToBoost.discard(skillName)
            callSkillProcessor(skillName, factor, baseAvgLevel)

        ROLES_AND_COMMON_SKILLS = tankmen.ROLES_AND_COMMON_SKILLS
        for skillName, skillData in skills.iteritems():
            if skillName in ROLES_AND_COMMON_SKILLS:
                continue
            bestTankman = self._findBestTankmanForSkill(
                skillData,
                nonCommanderLevelIncrease=nonCommanderLevelIncrease,
                commanderLevelIncrease=commonLevelIncrease)
            if bestTankman is None:
                continue
            skillToBoost.discard(skillName)
            idxInCrew, level, levelIncrease, isActive = bestTankman
            callSkillProcessor(skillName, idxInCrew, level, levelIncrease,
                               isActive, isFire, getSkill(skillName))

        for skillName in skillToBoost:
            callSkillProcessor(skillName, None, 0, 0, True, False,
                               getSkill(skillName))

        return
コード例 #4
0
    def _calculateSkillEfficiencies(self, commonLevelIncrease,
                                    nonCommanderLevelIncrease):
        skills = self._skills
        activityFlags = self._activityFlags
        isFire = self._isFire
        commanderIdx = self._commanderIdx
        MAX_SKILL_LEVEL = tankmen.MAX_SKILL_LEVEL
        skillsConfig = tankmen.getSkillsConfig()
        skillEfficiencies = []
        universalistAddition = 0
        numInactive = activityFlags.count(False)
        if numInactive and activityFlags[commanderIdx]:
            level = skills.get('commander_universalist')
            if level is not None:
                level = level[0][1]
                universalistAddition = (level +
                                        commonLevelIncrease) / numInactive
                universalistAddition *= skillsConfig.getSkill(
                    'commander_universalist').efficiency
        computeSummSkillLevel = self._computeSummSkillLevel
        llen = len
        for skillName in tankmen.ROLES:
            if isFire:
                efficiency = 0.0
                baseAvgLevel = 0.0
            else:
                skillData = skills[skillName]
                baseSummLevel, summLevel, numInactive = computeSummSkillLevel(
                    skillData,
                    nonCommanderLevelIncrease=nonCommanderLevelIncrease,
                    commanderLevelIncrease=commonLevelIncrease)
                summLevel += numInactive * universalistAddition
                skillDataLen = llen(skillData)
                avgLevel = summLevel / skillDataLen
                efficiency = avgLevel / MAX_SKILL_LEVEL
                baseAvgLevel = baseSummLevel / skillDataLen
            skillEfficiencies.append((skillName, efficiency, baseAvgLevel))

        crewCompactDescrsLen = llen(self._crewCompactDescrs)
        crewCompactDescrsLenMaxSkillLev = crewCompactDescrsLen * MAX_SKILL_LEVEL
        for skillName in ('repair', 'fireFighting', 'camouflage'):
            skillData = skills.get(skillName)
            if skillData is None or isFire and skillName != 'fireFighting':
                efficiency = 0.0
                baseAvgLevel = 0.0
            else:
                baseSummLevel, summLevel, numInactive = computeSummSkillLevel(
                    skillData,
                    nonCommanderLevelIncrease=nonCommanderLevelIncrease,
                    commanderLevelIncrease=commonLevelIncrease)
                efficiency = summLevel / crewCompactDescrsLenMaxSkillLev
                baseAvgLevel = baseSummLevel / crewCompactDescrsLen
            skillEfficiencies.append((skillName, efficiency, baseAvgLevel))

        return skillEfficiencies
コード例 #5
0
    def _buildFactors(self):
        self._factors = {}
        self._shotDispFactor = 1.0
        self._terrainResistanceFactors = [1.0, 1.0, 1.0]
        skills = self._skills
        activityFlags = self._activityFlags
        isFire = self._isFire
        crewCompactDescrs = self._crewCompactDescrs
        commanderIdx = self._commanderIdx
        MAX_SKILL_LEVEL = tankmen.MAX_SKILL_LEVEL
        skillsConfig = tankmen.getSkillsConfig()
        commonLevelIncrease = self._levelIncreaseByBrotherhood + self._levelIncreaseByVehicle
        if _DO_DEBUG_LOG:
            LOG_DEBUG(
                'Crew level increase by vehicle={}, by brotherhood={}'.format(
                    self._levelIncreaseByVehicle,
                    self._levelIncreaseByBrotherhood))
        nonCommanderLevelIncrease = self._calcLeverIncreaseForNonCommander(
            commonLevelIncrease)
        skillEfficiencies = []
        universalistAddition = 0
        numInactive = activityFlags.count(False)
        if numInactive and activityFlags[commanderIdx]:
            level = skills.get('commander_universalist')
            if level is not None:
                level = level[0][1]
                universalistAddition = (level +
                                        commonLevelIncrease) / numInactive
                universalistAddition *= skillsConfig['commander_universalist'][
                    'efficiency']
        applier = self._mainSkillQualifiersApplier
        for skillName in tankmen.ROLES:
            if isFire:
                efficiency = 0.0
            else:
                skillData = skills[skillName]
                summLevel, numInactive = self._computeSummSkillLevel(
                    skillData,
                    nonCommanderLevelIncrease=nonCommanderLevelIncrease,
                    commanderLevelIncrease=commonLevelIncrease)
                summLevel += numInactive * universalistAddition
                avgLevel = summLevel / len(skillData)
                avgUpdatedLevel = applier[CREW_ROLE.ALL](avgLevel)
                avgUpdatedLevel = applier[skillName](avgUpdatedLevel)
                efficiency = avgUpdatedLevel / MAX_SKILL_LEVEL
            skillEfficiencies.append((skillName, efficiency))

        for skillName in ('repair', 'fireFighting', 'camouflage'):
            skillData = skills.get(skillName)
            if skillData is None or isFire and skillName != 'fireFighting':
                efficiency = 0.0
            else:
                summLevel, numInactive = self._computeSummSkillLevel(
                    skillData,
                    nonCommanderLevelIncrease=nonCommanderLevelIncrease,
                    commanderLevelIncrease=commonLevelIncrease)
                efficiency = summLevel / (len(crewCompactDescrs) *
                                          MAX_SKILL_LEVEL)
            skillEfficiencies.append((skillName, efficiency))

        skillProcessors = self._skillProcessors
        for skillName, efficiency in skillEfficiencies:
            factor = 0.57 + 0.43 * efficiency
            if _DO_DEBUG_LOG:
                LOG_DEBUG("Efficiency/factor of skill '%s': (%s, %s)" %
                          (skillName, efficiency, factor))
            skillProcessors[skillName](self, factor)

        markers = {}
        ROLES_AND_COMMON_SKILLS = tankmen.ROLES_AND_COMMON_SKILLS
        for skillName, skillData in skills.iteritems():
            if skillName in ROLES_AND_COMMON_SKILLS:
                continue
            try:
                for idxInCrew, level in skillData:
                    processor = skillProcessors[skillName]
                    if processor is not None:
                        levelIncrease = commonLevelIncrease if idxInCrew == commanderIdx else nonCommanderLevelIncrease
                        processor(self, idxInCrew, level, levelIncrease,
                                  activityFlags[idxInCrew], isFire,
                                  skillsConfig[skillName], markers)

            except:
                LOG_ERROR(
                    'Failed to compute skill (arenaUniqueID, vehicleID, skillName, skillData):',
                    self.__getUniqueArenaID(),
                    self.__getVehicleID(),
                    skillName,
                    skillData,
                    stack=True)
                LOG_CURRENT_EXCEPTION()

        self._factorsDirty = False
        return
コード例 #6
0
    def _buildFactors(self):
        self._factors = {}
        self._shotDispFactor = 1.0
        self._terrainResistanceFactors = [1.0, 1.0, 1.0]
        skills = self._skills
        activityFlags = self._activityFlags
        isFire = self._isFire
        crewCompactDescrs = self._crewCompactDescrs
        commanderIdx = self._commanderIdx
        MAX_SKILL_LEVEL = tankmen.MAX_SKILL_LEVEL
        skillsConfig = tankmen.getSkillsConfig()
        commonLevelIncrease = self._levelIncreaseByBrotherhood + self._levelIncreaseByVehicle
        if _DO_DEBUG_LOG:
            LOG_DEBUG('Crew level increase by vehicle={}, by brotherhood={}'.format(self._levelIncreaseByVehicle, self._levelIncreaseByBrotherhood))
        nonCommanderLevelIncrease = self._calcLeverIncreaseForNonCommander(commonLevelIncrease)
        skillEfficiencies = []
        universalistAddition = 0
        numInactive = activityFlags.count(False)
        if numInactive and activityFlags[commanderIdx]:
            level = skills.get('commander_universalist')
            if level is not None:
                level = level[0][1]
                universalistAddition = (level + commonLevelIncrease) / numInactive
                universalistAddition *= skillsConfig['commander_universalist']['efficiency']
        applier = self._mainSkillQualifiersApplier
        for skillName in tankmen.ROLES:
            if isFire:
                efficiency = 0.0
            else:
                skillData = skills[skillName]
                summLevel, numInactive = self._computeSummSkillLevel(skillData, nonCommanderLevelIncrease=nonCommanderLevelIncrease, commanderLevelIncrease=commonLevelIncrease)
                summLevel += numInactive * universalistAddition
                avgLevel = summLevel / len(skillData)
                avgUpdatedLevel = applier[CREW_ROLE.ALL](avgLevel)
                avgUpdatedLevel = applier[skillName](avgUpdatedLevel)
                efficiency = avgUpdatedLevel / MAX_SKILL_LEVEL
            skillEfficiencies.append((skillName, efficiency))

        for skillName in ('repair', 'fireFighting', 'camouflage'):
            skillData = skills.get(skillName)
            if skillData is None or isFire and skillName != 'fireFighting':
                efficiency = 0.0
            else:
                summLevel, numInactive = self._computeSummSkillLevel(skillData, nonCommanderLevelIncrease=nonCommanderLevelIncrease, commanderLevelIncrease=commonLevelIncrease)
                efficiency = summLevel / (len(crewCompactDescrs) * MAX_SKILL_LEVEL)
            skillEfficiencies.append((skillName, efficiency))

        skillProcessors = self._skillProcessors
        for skillName, efficiency in skillEfficiencies:
            factor = 0.57 + 0.43 * efficiency
            if _DO_DEBUG_LOG:
                LOG_DEBUG("Efficiency/factor of skill '%s': (%s, %s)" % (skillName, efficiency, factor))
            skillProcessors[skillName](self, factor)

        markers = {}
        ROLES_AND_COMMON_SKILLS = tankmen.ROLES_AND_COMMON_SKILLS
        for skillName, skillData in skills.iteritems():
            if skillName in ROLES_AND_COMMON_SKILLS:
                continue
            try:
                for idxInCrew, level in skillData:
                    processor = skillProcessors[skillName]
                    if processor is not None:
                        levelIncrease = commonLevelIncrease if idxInCrew == commanderIdx else nonCommanderLevelIncrease
                        processor(self, idxInCrew, level, levelIncrease, activityFlags[idxInCrew], isFire, skillsConfig[skillName], markers)

            except:
                LOG_ERROR('Failed to compute skill (arenaUniqueID, vehicleID, skillName, skillData):', self.__getUniqueArenaID(), self.__getVehicleID(), skillName, skillData, stack=True)
                LOG_CURRENT_EXCEPTION()

        self._factorsDirty = False
        return
コード例 #7
0
    def _buildFactors(self):
        self._factors = {}
        self._shotDispFactor = 1.0
        self._terrainResistanceFactors = [1.0, 1.0, 1.0]
        skills = self._skills
        activityFlags = self._activityFlags
        isFire = self._isFire
        crewCompactDescrs = self._crewCompactDescrs
        commanderIdx = self._commanderIdx
        MAX_SKILL_LEVEL = tankmen.MAX_SKILL_LEVEL
        skillsConfig = tankmen.getSkillsConfig()
        commanderLevelIncrease = self._levelIncreaseByBrotherhood + self._levelIncreaseByVehicle
        if not activityFlags[commanderIdx]:
            self._levelIncreaseByCommander = 0.0
        else:
            self._levelIncreaseByCommander = (skills['commander'][0][1] + commanderLevelIncrease) / tankmen.COMMANDER_ADDITION_RATIO
        nonCommanderLevelIncrease = commanderLevelIncrease + self._levelIncreaseByCommander
        if _DO_DEBUG_LOG:
            LOG_DEBUG('Crew level increase (by vehicle (dynamic), by commander, by brotherhood):' + str((self._levelIncreaseByVehicle, self._levelIncreaseByCommander, self._levelIncreaseByBrotherhood)))
        skillEfficiencies = []
        universalistAddition = 0
        numInactive = activityFlags.count(False)
        if numInactive and activityFlags[commanderIdx]:
            level = skills.get('commander_universalist')
            if level is not None:
                level = level[0][1]
                universalistAddition = (level + commanderLevelIncrease) / numInactive
                universalistAddition *= skillsConfig['commander_universalist']['efficiency']
        for skillName in tankmen.ROLES:
            if isFire:
                efficiency = 0.0
            else:
                skillData = skills[skillName]
                summLevel, numInactive = self._computeSummSkillLevel(skillData, nonCommanderLevelIncrease, commanderLevelIncrease)
                summLevel += numInactive * universalistAddition
                efficiency = summLevel / (len(skillData) * MAX_SKILL_LEVEL)
            skillEfficiencies.append((skillName, efficiency))

        for skillName in ('repair', 'fireFighting', 'camouflage'):
            skillData = skills.get(skillName)
            if skillData is None or isFire and skillName != 'fireFighting':
                efficiency = 0.0
            else:
                summLevel, numInactive = self._computeSummSkillLevel(skillData, nonCommanderLevelIncrease, commanderLevelIncrease)
                efficiency = summLevel / (len(crewCompactDescrs) * MAX_SKILL_LEVEL)
            skillEfficiencies.append((skillName, efficiency))

        skillProcessors = self._skillProcessors
        for skillName, efficiency in skillEfficiencies:
            factor = 0.57 + 0.43 * efficiency
            if _DO_DEBUG_LOG:
                LOG_DEBUG("Efficiency/factor of skill '%s': (%s, %s)" % (skillName, efficiency, factor))
            skillProcessors[skillName](self, factor)

        markers = {}
        ROLES_AND_COMMON_SKILLS = tankmen.ROLES_AND_COMMON_SKILLS
        for skillName, skillData in skills.iteritems():
            if skillName in ROLES_AND_COMMON_SKILLS:
                continue
            try:
                for idxInCrew, level in skillData:
                    processor = skillProcessors[skillName]
                    if processor is not None:
                        levelIncrease = commanderLevelIncrease if idxInCrew == commanderIdx else nonCommanderLevelIncrease
                        processor(self, idxInCrew, level, levelIncrease, activityFlags[idxInCrew], isFire, skillsConfig[skillName], markers)

            except:
                LOG_CURRENT_EXCEPTION()

        self._factorsDirty = False
        return