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
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