def getPenalties(self, vehicle):
        crew, emptySlots, otherVehicleSlots = functions.extractCrewDescrs(vehicle, replaceNone=False)
        crewFactors = items_utils.getCrewAffectedFactors(vehicle.descriptor, crew)
        result = {}
        currParams = self.getParamsDict(True)
        for slotId, factors in crewFactors.iteritems():
            for factor, factorValue in factors.iteritems():
                if factor in _FACTOR_TO_SKILL_PENALTY_MAP:
                    oldFactor = copy.copy(self.__factors[factor])
                    self.__factors[factor] = _universalSum(oldFactor, factorValue)
                    params = _FACTOR_TO_SKILL_PENALTY_MAP[factor]
                    for paramName in params:
                        paramPenalties = result.setdefault(paramName, {})
                        if slotId not in emptySlots:
                            newValue = getattr(self, paramName)
                            if newValue is None:
                                continue
                            state = rateParameterState(paramName, currParams[paramName], newValue)
                            if isinstance(currParams[paramName], collections.Iterable):
                                states, deltas = zip(*state)
                                if findFirst(lambda v: v == PARAM_STATE.WORSE, states):
                                    paramPenalties[slotId] = deltas
                            elif state[0] == PARAM_STATE.WORSE:
                                paramPenalties[slotId] = state[1]
                        paramPenalties[slotId] = 0

                    self.__factors[factor] = oldFactor

        roles = vehicle.descriptor.type.crewRoles
        for paramName, penalties in result.items():
            result[paramName] = [ _PenaltyInfo(roles[slotId][0], value, slotId in otherVehicleSlots) for slotId, value in penalties.iteritems() ]

        return {k:v for k, v in result.iteritems() if v}
示例#2
0
    def __getPenalties(self, vehicle):
        crew, emptySlots, otherVehicleSlots = functions.extractCrewDescrs(vehicle, replaceNone=False)
        crewFactors = getCrewAffectedFactors(vehicle.descriptor, crew)
        result = {}
        currParams = self.getParamsDict()
        roles = vehicle.descriptor.type.crewRoles
        for slotId, factors in crewFactors.iteritems():
            for factor, factorValue in factors.iteritems():
                if factor in _UI_TO_SERVER_MAP:
                    oldFactor = copy.copy(self.__factors[factor])
                    self.__factors[factor] = _universalSum(oldFactor, factorValue)
                    params = _UI_TO_SERVER_MAP[factor]
                    for paramName in params:
                        paramPenalties = result.setdefault(paramName, {})
                        if slotId not in emptySlots:
                            newValue = getattr(self, paramName)
                            if newValue is None:
                                continue
                            if isinstance(newValue, collections.Iterable):
                                delta = sum(currParams[paramName]) - sum(newValue)
                            else:
                                delta = currParams[paramName] - newValue
                            if delta > 0 and paramName in BACKWARD_QUALITY_PARAMS or delta < 0 and paramName not in BACKWARD_QUALITY_PARAMS:
                                paramPenalties[slotId] = delta
                        else:
                            paramPenalties[slotId] = 0

                    self.__factors[factor] = oldFactor

        for paramName, penalties in result.items():
            result[paramName] = [ (roles[slotId][0], value, slotId in otherVehicleSlots) for slotId, value in penalties.iteritems() ]

        return result
示例#3
0
    def __getPenalties(self, vehicle):
        crew, emptySlots, otherVehicleSlots = functions.extractCrewDescrs(
            vehicle, replaceNone=False)
        crewFactors = items_utils.getCrewAffectedFactors(
            vehicle.descriptor, crew)
        result = {}
        currParams = self.getParamsDict()
        roles = vehicle.descriptor.type.crewRoles
        for slotId, factors in crewFactors.iteritems():
            for factor, factorValue in factors.iteritems():
                if factor in _UI_TO_SERVER_MAP:
                    oldFactor = copy.copy(self.__factors[factor])
                    self.__factors[factor] = _universalSum(
                        oldFactor, factorValue)
                    params = _UI_TO_SERVER_MAP[factor]
                    for paramName in params:
                        paramPenalties = result.setdefault(paramName, {})
                        if slotId not in emptySlots:
                            newValue = getattr(self, paramName)
                            if newValue is None:
                                continue
                            if isinstance(newValue, collections.Iterable):
                                delta = sum(
                                    currParams[paramName]) - sum(newValue)
                            else:
                                delta = currParams[paramName] - newValue
                            if delta > 0 and paramName in BACKWARD_QUALITY_PARAMS or delta < 0 and paramName not in BACKWARD_QUALITY_PARAMS:
                                paramPenalties[slotId] = delta
                        else:
                            paramPenalties[slotId] = 0

                    self.__factors[factor] = oldFactor

        for paramName, penalties in result.items():
            result[paramName] = [(roles[slotId][0], value, slotId
                                  in otherVehicleSlots)
                                 for slotId, value in penalties.iteritems()]

        return result