def readConfig(): section = ResMgr.openSection(_CONFIG_FILE) if section is None: _xml.raiseWrongXml(None, _CONFIG_FILE, 'can not open or read') xmlCtx = (None, _CONFIG_FILE) c = {} c['baseStunDuration'] = _xml.readNonNegativeFloat(xmlCtx, section, 'baseStunDuration') c['guaranteedStunDuration'] = _xml.readFraction(xmlCtx, section, 'guaranteedStunDuration') c['damageDurationCoeff'] = _xml.readFraction(xmlCtx, section, 'damageDurationCoeff') c['guaranteedStunEffect'] = _xml.readFraction(xmlCtx, section, 'guaranteedStunEffect') c['damageEffectCoeff'] = _xml.readFraction(xmlCtx, section, 'damageEffectCoeff') c['minStunDuration'] = _xml.readNonNegativeFloat(xmlCtx, section, 'minStunDuration') c['shellEffectFactor'] = _xml.readFraction(xmlCtx, section, 'shellEffectFactor') c['stunFactorEnginePower'] = _xml.readFraction(xmlCtx, section, 'stunFactorEnginePower') c['stunFactorVehicleRotationSpeed'] = _xml.readFraction(xmlCtx, section, 'stunFactorVehicleRotationSpeed') c['stunFactorTurretTraverse'] = _xml.readFraction(xmlCtx, section, 'stunFactorTurretTraverse') c['stunFactorViewDistance'] = _xml.readFraction(xmlCtx, section, 'stunFactorViewDistance') c['stunFactorMaxSpeed'] = _xml.readFraction(xmlCtx, section, 'stunFactorMaxSpeed') c['stunFactorReloadTime'] = _xml.readPositiveFloat(xmlCtx, section, 'stunFactorReloadTime', 1.0) _validateValue1inf('stunFactorReloadTime', c['stunFactorReloadTime']) c['stunFactorAimingTime'] = _xml.readPositiveFloat(xmlCtx, section, 'stunFactorAimingTime', 1.0) _validateValue1inf('stunFactorAimingTime', c['stunFactorAimingTime']) c['stunFactorVehicleMovementShotDispersion'] = _xml.readPositiveFloat(xmlCtx, section, 'stunFactorVehicleMovementShotDispersion', 1.0) _validateValue1inf('stunFactorVehicleMovementShotDispersion', c['stunFactorVehicleMovementShotDispersion']) c['stunFactorVehicleRotationShotDispersion'] = _xml.readPositiveFloat(xmlCtx, section, 'stunFactorVehicleRotationShotDispersion', 1.0) _validateValue1inf('stunFactorVehicleRotationShotDispersion', c['stunFactorVehicleRotationShotDispersion']) c['stunFactorTurretRotationShotDispersion'] = _xml.readPositiveFloat(xmlCtx, section, 'stunFactorTurretRotationShotDispersion', 1.0) _validateValue1inf('stunFactorTurretRotationShotDispersion', c['stunFactorTurretRotationShotDispersion']) c['stunFactorMinShotDispersion'] = _xml.readPositiveFloat(xmlCtx, section, 'stunFactorMinShotDispersion', 1.0) _validateValue1inf('stunFactorMinShotDispersion', c['stunFactorMinShotDispersion']) return c
def _readStun(xmlCtx, scriptSection): stunResistanceEffect = _xml.readFraction( xmlCtx, scriptSection, 'stunResistanceEffect' ) if scriptSection.has_key('stunResistanceEffect') else 0.0 stunResistanceDuration = _xml.readFraction( xmlCtx, scriptSection, 'stunResistanceDuration' ) if scriptSection.has_key('stunResistanceDuration') else 0.0 return (stunResistanceEffect, stunResistanceDuration)
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
def _readLoaderDesperado(xmlCtx, section, subsectionName): res, xmlCtx, section = _readSkillBasics(xmlCtx, section, subsectionName) res['vehicleHealthFraction'] = _xml.readFraction(xmlCtx, section, 'vehicleHealthFraction') res['gunReloadTimeFactor'] = _xml.readPositiveFloat( xmlCtx, section, 'gunReloadTimeFactor') return res
def readShot(xmlCtx, section, nationID, projectileSpeedFactor, cache): """Reads section 'gun/shots/<shell_name>'. :param xmlCtx: tuple(root ctx or None, path to section). :param section: instance of DataSection. :param nationID: integer containing ID of nation. :param projectileSpeedFactor: float containing factor that is applied to projectile speeds and gravities at reading from configs. :param cache: instance of vehicles.Cache to get desired shell by name. :return: instance of GunShot. """ shellName = section.name shellID = cache.shellIDs(nationID).get(shellName) if shellID is None: _xml.raiseWrongXml(xmlCtx, '', 'unknown shell type name') shellDescr = cache.shells(nationID)[shellID] return gun_components.GunShot( shellDescr, 0.0 if not section.has_key('defaultPortion') else _xml.readFraction( xmlCtx, section, 'defaultPortion'), _xml.readVector2(xmlCtx, section, 'piercingPower'), _xml.readPositiveFloat(xmlCtx, section, 'speed') * projectileSpeedFactor, _xml.readNonNegativeFloat(xmlCtx, section, 'gravity') * projectileSpeedFactor**2, _xml.readPositiveFloat(xmlCtx, section, 'maxDistance'), section.readFloat('maxHeight', 1000000.0))
def readShot(xmlCtx, section, nationID, projectileSpeedFactor, cache): shellName = section.name shellID = cache.shellIDs(nationID).get(shellName) if shellID is None: _xml.raiseWrongXml(xmlCtx, '', 'unknown shell type name') shellDescr = cache.shells(nationID)[shellID] return gun_components.GunShot( shellDescr, ZERO_FLOAT if not section.has_key('defaultPortion') else _xml.readFraction(xmlCtx, section, 'defaultPortion'), _xml.readVector2(xmlCtx, section, 'piercingPower'), _xml.readPositiveFloat(xmlCtx, section, 'speed') * projectileSpeedFactor, _xml.readNonNegativeFloat(xmlCtx, section, 'gravity') * projectileSpeedFactor**2, _xml.readPositiveFloat(xmlCtx, section, 'maxDistance'), _xml.readFloat(xmlCtx, section, 'maxHeight', 1000000.0))
def _readMaterials(parentXmlCtx, section): materials = {} if IS_BASEAPP or IS_BOT: return materials else: for matName, (xmlCtx, matSection) in _xml.getItemsWithContext( parentXmlCtx, section): matKind = material_kinds.IDS_BY_NAMES.get(matName) if matKind is None: _xml.raiseWrongXml(xmlCtx, matName, 'material kind name is unknown') if matKind in materials: _xml.raiseWrongXml(xmlCtx, matName, 'duplicate material kind') effectMaterialName = _xml.readString(xmlCtx, matSection, 'effectMaterial') effectMaterialIdx = EFFECT_MATERIAL_INDEXES_BY_NAMES.get( effectMaterialName) if effectMaterialIdx is None: _xml.raiseWrongXml( xmlCtx, matName, 'Unknown effect material %s' % effectMaterialName) materials[matKind] = DestructibleMaterialInfo( kind=matKind, armor=_xml.readInt(xmlCtx, matSection, 'armor'), extra=None, vehicleDamageFactor=_xml.readFraction(xmlCtx, matSection, 'vehicleDamageFactor'), useHitAngle=_xml.readBool(xmlCtx, matSection, 'useHitAngle'), mayRicochet=_xml.readBool(xmlCtx, matSection, 'mayRicochet'), collideOnceOnly=True, checkCaliberForRichet=_xml.readBool(xmlCtx, matSection, 'checkCaliberForRichet'), checkCaliberForHitAngleNorm=_xml.readBool( xmlCtx, matSection, 'checkCaliberForHitAngleNorm'), effectMaterialIdx=effectMaterialIdx) return materials
def _readConfig(self, xmlCtx, section): self.repairAll = section.readBool('repairAll', False) self.bonusValue = _xml.readFraction(xmlCtx, section, 'bonusValue')
def _readSkillFraction(paramName, xmlCtx, section, subsectionName): res, xmlCtx, section = _readSkillBasics(xmlCtx, section, subsectionName) res[paramName] = _xml.readFraction(xmlCtx, section, paramName) return res
def _readGunnerSniperSkill(xmlCtx, section, subsectionName): skill, xmlCtx, section = _readSkillBasics(xmlCtx, section, subsectionName) return skills_components.GunnerSniperSkill(skill, _xml.readFraction(xmlCtx, section, 'deviceChanceToHitBoost'))
def _readCommanderUniversalistSkill(xmlCtx, section, subsectionName): skill, xmlCtx, section = _readSkillBasics(xmlCtx, section, subsectionName) return skills_components.CommanderUniversalistSkill(skill, _xml.readFraction(xmlCtx, section, 'efficiency'))
def _readLoaderDesperadoSkill(xmlCtx, section, subsectionName): skill, xmlCtx, section = _readSkillBasics(xmlCtx, section, subsectionName) return skills_components.LoaderDesperadoSkill(skill, _xml.readFraction(xmlCtx, section, 'vehicleHealthFraction'), _xml.readPositiveFloat(xmlCtx, section, 'gunReloadTimeFactor'))
def _readLoaderIntuitionSkill(xmlCtx, section, subsectionName): skill, xmlCtx, section = _readSkillBasics(xmlCtx, section, subsectionName) return skills_components.LoaderIntuitionSkill(skill, _xml.readFraction(xmlCtx, section, 'chance'))
def _readLoaderIntuitionSkill(xmlCtx, section, subsectionName): skill, xmlCtx, section = _readSkillBasics(xmlCtx, section, subsectionName) return skills_components.LoaderIntuitionSkill( skill, _xml.readFraction(xmlCtx, section, 'quickShellChangerFactorPerPercent'))
def _readLoaderDesperado(xmlCtx, section, subsectionName): res, xmlCtx, section = _readSkillBasics(xmlCtx, section, subsectionName) res['vehicleHealthFraction'] = _xml.readFraction(xmlCtx, section, 'vehicleHealthFraction') res['gunReloadTimeFactor'] = _xml.readPositiveFloat(xmlCtx, section, 'gunReloadTimeFactor') return res