Пример #1
0
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))
Пример #2
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))
Пример #3
0
def initVehiclePhysicsFromParams(physics, params, xmlPath):
    class _SimpleObject(object):
        pass

    typeDesc = _SimpleObject()
    typeDesc.physics = {}
    typeDesc.physics['weight'] = params['weight']
    typeDesc.physics['enginePower'] = params['enginePower']
    typeDesc.physics['speedLimits'] = params['speedLimits']
    typeDesc.physics['rotationIsAroundCenter'] = params[
        'rotationIsAroundCenter']
    typeDesc.physics['rotationSpeedLimit'] = params['rotationSpeedLimit']
    typeDesc.physics['terrainResistance'] = params['terrainResistance']
    typeDesc.physics['trackCenterOffset'] = params['trackCenterOffset']
    typeDesc.hull = vehicle_items.Hull()
    typeDesc.hull.hitTester = _SimpleObject()
    typeDesc.hull.hitTester.bbox = (params['hullHitTesterMin'],
                                    params['hullHitTesterMax'], None)
    typeDesc.hull.turretPositions = (params['turretPosition'], )
    typeDesc.turret = vehicle_items.createTurret(0, 0, 'Turret')
    typeDesc.turret.hitTester = _SimpleObject()
    typeDesc.turret.hitTester.bbox = (params['turretHitTesterMin'],
                                      params['turretHitTesterMax'], None)
    typeDesc.turret.gunPosition = params['gunPosition']
    typeDesc.type = _SimpleObject()
    typeDesc.type.name = ''
    section = ResMgr.openSection(xmlPath)
    try:
        xphysics = vehicles._readXPhysics((None, xmlPath), section, 'physics')
        typeDesc.type.xphysics = xphysics
    except:
        xphysics = False
        typeDesc.type.xphysics = {}

    if xphysics:
        chassisName = xphysics['detailed']['chassis'].keys()[0]
        engineName = xphysics['detailed']['engines'].keys()[0]
    else:
        chassisName = 'Chassis'
        engineName = 'Engine'
    typeDesc.chassis = vehicle_items.createChassis(0, 0, chassisName)
    typeDesc.chassis.hullPosition = params['hullPosition']
    typeDesc.chassis.hitTester = _SimpleObject()
    typeDesc.chassis.hitTester.bbox = (params['chassisHitTesterMin'],
                                       params['chassisHitTesterMax'], None)
    typeDesc.engine = vehicle_items.createEngine(0, 0, engineName)
    typeDesc.shot = gun_components.GunShot(None, 1.0, (10.0, 10.0), 100.0, 9.8,
                                           500.0, 1000000.0)
    typeDesc.gun = vehicle_items.createGun(0, 0, 'Gun')
    typeDesc.gun.staticTurretYaw = None
    typeDesc.hasSiegeMode = False
    typeDesc.type.isRotationStill = False
    typeDesc.type.useHullZ = False
    typeDesc.type.hullAimingParams = {
        'pitch': {
            'isAvailable': False,
            'wheelCorrectionCenterZ': 0.0,
            'wheelsCorrectionSpeed': 0.2,
            'wheelsCorrectionAngles': {
                'pitchMax': 1.0,
                'pitchMin': 1.0
            }
        },
        'yaw': {
            'isAvailable': False
        }
    }
    initVehiclePhysicsEditor(physics, typeDesc)
    physics.visibilityMask = 4294967295L
    return