def _assembleParts(self, isPlayer, appearance): appearance.filter = model_assembler.createVehicleFilter( appearance.typeDescriptor) if appearance.isAlive: appearance.detailedEngineState = model_assembler.assembleDetailedEngineState( appearance.compoundModel, appearance.filter, appearance.typeDescriptor, isPlayer) if not gEffectsDisabled(): model_assembler.assembleVehicleAudition(isPlayer, appearance) model_assembler.subscribeEngineAuditionToEngineState( appearance.engineAudition, appearance.detailedEngineState) createEffects(appearance) if isPlayer: gunRotatorConnector = GunRotatorConnector(appearance) appearance.addComponent(gunRotatorConnector) appearance.frictionAudition = Vehicular.FrictionAudition( TANK_FRICTION_EVENT) appearance.peripheralsController = PeripheralsController() self.__createTrackCrashControl(appearance) appearance.highlighter = Highlighter() isLodTopPriority = isPlayer lodCalcInst = Vehicular.LodCalculator( DataLinks.linkMatrixTranslation(appearance.compoundModel.matrix), True, VEHICLE_PRIORITY_GROUP, isLodTopPriority) appearance.lodCalculator = lodCalcInst lodLink = DataLinks.createFloatLink(lodCalcInst, 'lodDistance') lodStateLink = lodCalcInst.lodStateLink isDamaged = appearance.damageState.isCurrentModelDamaged if not isDamaged: self.__assembleNonDamagedOnly(appearance, isPlayer, lodLink, lodStateLink) model_assembler.setupTurretRotations(appearance) if appearance.fashion is not None: appearance.fashion.movementInfo = appearance.filter.movementInfo appearance.waterSensor = model_assembler.assembleWaterSensor( appearance.typeDescriptor, appearance, lodStateLink) if appearance.engineAudition is not None: appearance.engineAudition.setIsUnderwaterInfo( DataLinks.createBoolLink(appearance.waterSensor, 'isUnderWater')) appearance.engineAudition.setIsInWaterInfo( DataLinks.createBoolLink(appearance.waterSensor, 'isInWater')) if isPlayer and BigWorld.player().isInTutorial: tutorialMatKindsController = TutorialMatKindsController() tutorialMatKindsController.terrainMatKindsLink = lambda: appearance.terrainMatKind appearance.addComponent(tutorialMatKindsController) self.__postSetupFilter(appearance) return
def __init__(self): CallbackDelayer.__init__(self) ComponentSystem.__init__(self) self.turretMatrix = Math.WGAdaptiveMatrixProvider() self.gunMatrix = Math.WGAdaptiveMatrixProvider() self.__vehicle = None self.__filter = None self.__originalFilter = None self.__typeDesc = None self.__fashion = None self.crashedTracksController = None self.__currentDamageState = VehicleDamageState() self.__effectsPlayer = None self.__engineMode = (0, 0) self.__currTerrainMatKind = [-1] * _MATKIND_COUNT self.__terrainEffectMaterialNames = [''] * _MATKIND_COUNT self.__terrainMatKindLodDistance = _LOD_DISTANCE_TERRAIN_MATKIND_UPDATE self.__chassisDecal = VehicleDecal(self) self.__splodge = None self.__vehicleStickers = None self.onModelChanged = Event() self.__leftTrackScroll = 0.0 self.__rightTrackScroll = 0.0 self.__fashions = None self.__compoundModel = None self.__boundEffects = None self.__splineTracks = None self.flyingInfoProvider = Vehicular.FlyingInfoProvider() self.__trackScrollCtl = BigWorld.PyTrackScroll() self.__trackScrollCtl.setFlyingInfo( DataLinks.createBoolLink(self.flyingInfoProvider, 'isLeftSideFlying'), DataLinks.createBoolLink(self.flyingInfoProvider, 'isRightSideFlying')) self.__weaponEnergy = 0.0 self.__activated = False self.__systemStarted = False self.__outfit = None self.__vID = 0 self.__isAlive = True self.__isTurretDetached = False self.__periodicTimerID = None self.__wasDeactivated = False self.__dirtUpdateTime = 0.0 self.__inSpeedTreeCollision = False self.__isObserver = False self.__chassisColisionMatrix = Math.WGAdaptiveMatrixProvider() return
def activate(self): typeDescr = self.typeDescriptor wheelConfig = typeDescr.chassis.generalWheelsAnimatorConfig if self.wheelsAnimator is not None and wheelConfig is not None: self.wheelsAnimator.createCollision(wheelConfig, self.collisions) super(CommonTankAppearance, self).activate() self.wheelsGameObject.activate() for go in self.filterRetrieverGameObjects: go.activate() if not self.isObserver: self._chassisDecal.attach() if not self.isObserver: self._startSystems() self.filter.enableLagDetection(not self.damageState.isCurrentModelDamaged) if self.__periodicTimerID is not None: BigWorld.cancelCallback(self.__periodicTimerID) self.__periodicTimerID = BigWorld.callback(PERIODIC_UPDATE_TIME, self.__onPeriodicTimer) self.setupGunMatrixTargets(self.filter) for lodCalculator in self.allLodCalculators: lodCalculator.setupPosition(DataLinks.linkMatrixTranslation(self.compoundModel.matrix)) for modelAnimator in self.__modelAnimators: modelAnimator.animator.setEnabled(True) modelAnimator.animator.start() if hasattr(self.filter, 'placingCompensationMatrix') and self.swingingAnimator is not None: self.swingingAnimator.placingCompensationMatrix = self.filter.placingCompensationMatrix self.swingingAnimator.worldMatrix = self.compoundModel.matrix if self.isObserver: self.compoundModel.visible = False self._connectCollider() self._attachStickers() return
def __onModelsRefresh(self, modelState, resourceList): if BattleReplay.isFinished(): return elif modelState != self.__currentDamageState.modelState: self.__requestModelsRefresh() return elif self.__vehicle is None: return else: vehicle = self.__vehicle newCompoundModel = resourceList[self.__typeDesc.name] self.deactivate(False) self.__compoundModel = newCompoundModel self.__isTurretDetached = vehicle.isTurretDetached if self.__currentDamageState.isCurrentModelDamaged: fashions = VehiclePartsTuple(None, None, None, None) self.swingingAnimator = None self.gunRecoil = None self.__setFashions(fashions, self.__isTurretDetached) self.__destroySystems() self.__trackFashionSet = False self.__setupModels() self.setVehicle(vehicle) self.activate() self.__reattachComponents(self.__compoundModel) lodLink = DataLinks.createFloatLink(self.lodCalculator, 'lodDistance') if not self.damageState.isCurrentModelDamaged: model_assembler.assembleRecoil(self, lodLink) model_assembler.setupTurretRotations(self) return
def activate(self): if self.collisions is not None and self.isTurretDetached: self.collisions.removeAttachment(TankPartNames.getIdx(TankPartNames.TURRET)) self.collisions.removeAttachment(TankPartNames.getIdx(TankPartNames.GUN)) super(CommonTankAppearance, self).activate() if not self.isObserver: self._chassisDecal.attach() self._createAndAttachStickers() if not self.isObserver: if not self.damageState.isCurrentModelDamaged and not self.__systemStarted: self._startSystems() self.filter.enableLagDetection(not self.damageState.isCurrentModelDamaged) if self.__periodicTimerID is not None: BigWorld.cancelCallback(self.__periodicTimerID) self.__periodicTimerID = BigWorld.callback(PERIODIC_UPDATE_TIME, self.__onPeriodicTimer) self.setupGunMatrixTargets(self.filter) for lodCalculator in self.allLodCalculators: lodCalculator.setupPosition(DataLinks.linkMatrixTranslation(self.compoundModel.matrix)) for modelAnimator in self.__modelAnimators: modelAnimator.animator.start() if hasattr(self.filter, 'placingCompensationMatrix') and self.swingingAnimator is not None: self.swingingAnimator.placingCompensationMatrix = self.filter.placingCompensationMatrix self.swingingAnimator.worldMatrix = self.compoundModel.matrix if self.isObserver: self.compoundModel.visible = False if self.collisions is not None: chassisColisionMatrix, gunNodeName = self._vehicleColliderInfo collisionData = ((TankPartNames.getIdx(TankPartNames.HULL), self.compoundModel.node(TankPartNames.HULL)), (TankPartNames.getIdx(TankPartNames.TURRET), self.compoundModel.node(TankPartNames.TURRET)), (TankPartNames.getIdx(TankPartNames.CHASSIS), chassisColisionMatrix), (TankPartNames.getIdx(TankPartNames.GUN), self.compoundModel.node(gunNodeName))) self.collisions.connect(self.id, ColliderTypes.VEHICLE_COLLIDER, collisionData) return
def assembleVehicleAudition(isPlayer, appearance): PLAYER_UPDATE_PERIOD = 0.1 NPC_UPDATE_PERIOD = 0.25 typeDescriptor = appearance.typeDescriptor engineEventName = typeDescriptor.engine.sounds.getWWPlayerSound(isPlayer) chassisEventName = typeDescriptor.chassis.sounds.getWWPlayerSound(isPlayer) vehicleData = (typeDescriptor.physics['enginePower'] / component_constants.HP_TO_WATTS, typeDescriptor.physics['weight'], typeDescriptor.physics['rotationSpeedLimit']) vehicleAudition = Vehicular.VehicleAudition(appearance.id, isPlayer, vehicleData, engineEventName, chassisEventName) vehicleAudition.setEffectMaterialsInfo( lambda: appearance.terrainEffectMaterialNames) vehicleAudition.setSpeedInfo(lambda: appearance.filter.angularSpeed, lambda: appearance.filter.strafeSpeed) vehicleAudition.setTrackScrollInfo( lambda: appearance.leftTrackScroll, lambda: appearance.rightTrackScroll, lambda: appearance.customEffectManager.getParameter('deltaL'), lambda: appearance.customEffectManager.getParameter('deltaR')) vehicleAudition.setIsFlyingInfo( DataLinks.createBoolLink(appearance.flyingInfoProvider, 'isFlying')) if typeDescriptor.type.siegeModeParams is not None: soundStateChange = typeDescriptor.type.siegeModeParams[ 'soundStateChange'] vehicleAudition.setSiegeSoundEvents( soundStateChange.on if soundStateChange.on is not None else '', soundStateChange.off if soundStateChange.off is not None else '') vehicleAudition.setDetailedEngineState(appearance.detailedEngineState) vehicleAudition.setUpdatePeriod( PLAYER_UPDATE_PERIOD if isPlayer else NPC_UPDATE_PERIOD) appearance.engineAudition = vehicleAudition return
def assembleWaterSensor(vehicleDesc, appearance, lodStateLink): MIN_DEPTH_FOR_HEAVY_SPLASH = 0.5 WATER_SENSOR_LOD_DIST = 150.0 WATER_SENSOR_MAX_PRIORITY = 15 turretOffset = vehicleDesc.chassis.hullPosition + vehicleDesc.hull.turretPositions[ 0] trPoint = vehicleDesc.chassis.topRightCarryingPoint lightVelocityThreshold = vehicleDesc.type.collisionEffectVelocities[ 'waterContact'] heavyVelocityThreshold = vehicleDesc.type.heavyCollisionEffectVelocities[ 'waterContact'] sensorConfig = (turretOffset, trPoint, lightVelocityThreshold, heavyVelocityThreshold, MIN_DEPTH_FOR_HEAVY_SPLASH, BigWorld.player().spaceID) sensor = Vehicular.WaterSensor(sensorConfig) sensor.sensorPlaneLink = appearance.compoundModel.root sensor.speedLink = DataLinks.createFloatLink(appearance.filter, 'averageSpeed') sensor.onWaterSplash = appearance.onWaterSplash sensor.onUnderWaterSwitch = appearance.onUnderWaterSwitch sensor.setLodLink(lodStateLink) sensor.setLodSettings( shared_components.LodSettings(WATER_SENSOR_LOD_DIST, WATER_SENSOR_MAX_PRIORITY)) return sensor
def activate(self): if self.__activated or self.__vehicle is None: return else: if self.__currentDamageState.isCurrentModelDamaged: if self.__customEffectManager is not None: self.__customEffectManager.destroy() self.__customEffectManager = None if self.detailedEngineState is not None: self.detailedEngineState.destroy() self.detailedEngineState = None super(CompoundAppearance, self).activate() isPlayerVehicle = self.__vehicle.isPlayerVehicle isObserver = 'observer' in self.__typeDesc.type.tags player = BigWorld.player() self.__originalFilter = self.__vehicle.filter self.__createFilter() self.__vehicle.filter = self.__filter self.__vehicle.filter.enableNewPhysics(True) self.__vehicle.filter.enableStabilisedMatrix(isPlayerVehicle) self.__filter.isStrafing = self.__vehicle.isStrafing self.__filter.vehicleCollisionCallback = player.handleVehicleCollidedVehicle self.__compoundModel.isHighPriorityReflection = isPlayerVehicle self.__vehicleMatrixProv = self.__compoundModel.matrix if isPlayerVehicle: if player.inputHandler is not None: player.inputHandler.addVehicleToCameraCollider(self.__vehicle) BigWorld.setSpeedTreeCollisionBody(self.__compoundModel.getBoundsForPart(TankPartIndexes.HULL)) self.__linkCompound() self.__chassisShadowForwardDecal.attach(self.__typeDesc, self.__compoundModel) if not isObserver: self.__chassisOcclusionDecal.attach(self.__typeDesc, self.__compoundModel) self.__createStickers() if self.__currentDamageState.isCurrentModelDamaged: self.__attachStickers(items.vehicles.g_cache.commonConfig['miscParams']['damageStickerAlpha'], True) else: self.__startSystems() self.__attachStickers() self.setupGunMatrixTargets() if not isObserver: self.__vehicle.filter.enableLagDetection(True) self.onModelChanged() if self.lodCalculator is not None: self.lodCalculator.setupPosition(DataLinks.linkMatrixTranslation(self.__compoundModel.matrix)) if hasattr(self.filter, 'placingCompensationMatrix') and self.swingingAnimator is not None: self.swingingAnimator.placingCompensationMatrix = self.filter.placingCompensationMatrix self.swingingAnimator.worldMatrix = self.__compoundModel.matrix if self.__periodicTimerID is not None: BigWorld.cancelCallback(self.__periodicTimerID) self.__periodicTimerID = BigWorld.callback(_PERIODIC_TIME, self.__onPeriodicTimer) self.__activated = True if 'observer' in self.__vehicle.typeDescriptor.type.tags: self.__compoundModel.visible = False if self.__currentDamageState.isCurrentModelDamaged: if not self.__wasDeactivated: if not self.__vehicle.isPlayerVehicle: self.setupGunMatrixTargets() else: self.setupGunMatrixTargets(self.__vehicle.filter) return
def __assembleNonDamagedOnly(self, resourceRefs, isPlayer, lodLink, lodStateLink): model_assembler.assembleTerrainMatKindSensor(self, lodStateLink, self.spaceID) model_assembler.assembleRecoil(self, lodLink) model_assembler.assembleMultiGunRecoil(self, lodLink) model_assembler.assembleGunLinkedNodesAnimator(self) model_assembler.assembleCollisionObstaclesCollector(self, lodStateLink, self.typeDescriptor) model_assembler.assembleTessellationCollisionSensor(self, lodStateLink) wheelsScroll = None wheelsSteering = None generalWheelsAnimatorConfig = self.typeDescriptor.chassis.generalWheelsAnimatorConfig if generalWheelsAnimatorConfig is not None: scrollableWheelsCount = generalWheelsAnimatorConfig.getNonTrackWheelsCount() wheelsScroll = [] for _ in xrange(scrollableWheelsCount): retrieverGameObject = ScriptGameObject(self.spaceID) retriever = retrieverGameObject.createComponent(NetworkFilters.FloatFilterRetriever) wheelsScroll.append(DataLinks.createFloatLink(retriever, 'value')) self.filterRetrievers.append(retriever) self.filterRetrieverGameObjects.append(retrieverGameObject) steerableWheelsCount = generalWheelsAnimatorConfig.getSteerableWheelsCount() wheelsSteering = [] for _ in xrange(steerableWheelsCount): retrieverGameObject = ScriptGameObject(self.spaceID) retriever = retrieverGameObject.createComponent(NetworkFilters.FloatFilterRetriever) wheelsSteering.append(DataLinks.createFloatLink(retriever, 'value')) self.filterRetrievers.append(retriever) self.filterRetrieverGameObjects.append(retrieverGameObject) self.wheelsAnimator = model_assembler.createWheelsAnimator(self, ColliderTypes.VEHICLE_COLLIDER, self.typeDescriptor, lambda : self.wheelsState, wheelsScroll, wheelsSteering, self.splineTracks, lodStateLink) if self.customEffectManager is not None: self.customEffectManager.setWheelsData(self) suspensionLodLink = lodStateLink if 'wheeledVehicle' in self.typeDescriptor.type.tags: wheeledLodCalculator = self.wheelsGameObject.createComponent(Vehicular.LodCalculator, DataLinks.linkMatrixTranslation(self.compoundModel.matrix), True, WHEELED_CHASSIS_PRIORITY_GROUP, isPlayer) self.allLodCalculators.append(wheeledLodCalculator) suspensionLodLink = wheeledLodCalculator.lodStateLink model_assembler.assembleSuspensionIfNeed(self, suspensionLodLink) model_assembler.assembleLeveredSuspensionIfNeed(self, suspensionLodLink) self.__assembleSwinging(lodLink) model_assembler.assembleBurnoutProcessor(self) model_assembler.assembleSuspensionSound(self, lodLink, isPlayer) model_assembler.assembleHullAimingController(self) self.trackNodesAnimator = model_assembler.createTrackNodesAnimator(self, self.typeDescriptor, lodStateLink) model_assembler.assembleTracks(resourceRefs, self.typeDescriptor, self, self.splineTracks, False, lodStateLink) model_assembler.assembleVehicleTraces(self, self.filter, lodStateLink) return
def assembleTracks(resourceRefs, vehicleDesc, appearance, splineTracksImpl, instantWarmup, lodLink=None): tracks = Vehicular.VehicleTracks(appearance.compoundModel, TankPartIndexes.CHASSIS, _AREA_LOD_FOR_NONSIMPLE_TRACKS) appearance.tracks = tracks if not __assemblePhysicalTracks(resourceRefs, appearance, tracks, instantWarmup): __assembleSplineTracks(vehicleDesc, appearance, splineTracksImpl, tracks) __assembleSimpleTracks(vehicleDesc, appearance.fashion, appearance.wheelsAnimator, tracks) vehicleFilter = getattr(appearance, 'filter', None) if vehicleFilter is not None: tracks.leftTrack.setupScrollLink(DataLinks.createFloatLink(vehicleFilter, 'leftTrackScroll')) tracks.rightTrack.setupScrollLink(DataLinks.createFloatLink(vehicleFilter, 'rightTrackScroll')) if lodLink is None: lodLink = Vehicular.getDummyLodLink() tracks.setLodLink(lodLink) crashedTracksController = getattr(appearance, 'crashedTracksController', None) if crashedTracksController is not None: crashedTracksController.baseTracksComponent = tracks return
def setupTank(chassisFashion, gunFashion, vehicleDesc, worldMatrix, resources): print resources tank = resources[vehicleDesc.name] tank.matrix = worldMatrix tanks.append(tank) effect = Pixie.create('particles/Tank/exhaust/large_gas_gear.xml') tank.node('HP_gunFire').attach(effect) tank.node('HP_gunFire').attach( BigWorld.Model('helpers/models/position_gizmo.model')) tank.node('HP_Track_Exhaus_1').attach( BigWorld.Model('helpers/models/unit_cube.model')) m = mathUtils.createTranslationMatrix(Vector3(0, 10, 5)) fakeMatrixes.append(m) tank.node('gun').attach(effect.clone(), m) BigWorld.addModel(tank) recoilDescr = vehicleDesc.gun['recoil'] recoil = BigWorld.RecoilAnimator(recoilDescr['backoffTime'], recoilDescr['returnTime'], recoilDescr['amplitude'], recoilDescr['lodDist']) recoil.basisMatrix = tank.node('G').localMatrix recoil = assemblerModule.createGunAnimator(vehicleDesc, tank.node('G').localMatrix) recoil.lodSetting = 10 tank.node('G', recoil) gunFashion.gunLocalMatrix = recoil recoil.lodLink = DataLinks.createFloatLink(chassisFashion, 'lastLod') swingingAnimator = assemblerModule.createSwingingAnimator( vehicleDesc, tank.node('hull').localMatrix, worldMatrix) chassisFashion.setupSwinging(swingingAnimator, 'hull') swingingAnimator.lodLink = DataLinks.createFloatLink( chassisFashion, 'lastLod') tank.setupFashions([chassisFashion, None, None, gunFashion]) fashions.append(swingingAnimator) tank.node('hull', swingingAnimator) animMatrix = Math.MatrixAnimation() keys = [] for x in xrange(100): angle = math.pi * 0.5 * (1 if x & 1 else -1) keys.append((x * 3, mathUtils.createRotationMatrix((angle, 0, 0)))) animMatrix.keyframes = tuple(keys) tank.node('turret', animMatrix) return
def assembleVehicleTraces(appearance, f, lodStateLink=None): vehicleTraces = Vehicular.VehicleTraces() tracesConfig = appearance.typeDescriptor.chassis.traces textures = {} for matKindName, texId in DecalMap.g_instance.getTextureSet(tracesConfig.textureSet).iteritems(): if matKindName != 'bump': for matKind in material_kinds.EFFECT_MATERIAL_IDS_BY_NAMES[matKindName]: textures[matKind] = texId vehicleTraces.setTrackTraces(tracesConfig.bufferPrefs, textures, tracesConfig.centerOffset, tracesConfig.size, appearance.typeDescriptor.chassis.topRightCarryingPoint[1] * 2) vehicleTraces.setCompound(appearance.compoundModel) isLeftFlying = DataLinks.createBoolLink(appearance.flyingInfoProvider, 'isLeftSideFlying') isRightFlying = DataLinks.createBoolLink(appearance.flyingInfoProvider, 'isRightSideFlying') vehicleTraces.setFlyingInfo(isLeftFlying, isRightFlying) vehicleTraces.setLodLink(lodStateLink) vehicleTraces.setLodSettings(shared_components.LodSettings(tracesConfig.lodDist, DEFAULT_MAX_LOD_PRIORITY)) vehicleTraces.setMovementInfo(f.movementInfo) appearance.vehicleTraces = vehicleTraces
def activate(self): if self.__activated or self.__vehicle is None: return else: super(CompoundAppearance, self).activate() isPlayerVehicle = self.__vehicle.isPlayerVehicle isObserver = 'observer' in self.__typeDesc.type.tags player = BigWorld.player() self.__originalFilter = self.__vehicle.filter self.__vehicle.filter = self.__filter self.__vehicle.filter.enableStabilisedMatrix(isPlayerVehicle) self.__filter.isStrafing = self.__vehicle.isStrafing self.__filter.vehicleCollisionCallback = player.handleVehicleCollidedVehicle self.__compoundModel.isHighPriorityReflection = isPlayerVehicle if isPlayerVehicle: if player.inputHandler is not None: player.inputHandler.addVehicleToCameraCollider( self.__vehicle) self.__inSpeedTreeCollision = True BigWorld.setSpeedTreeCollisionBody( self.__compoundModel.getBoundsForPart( TankPartIndexes.HULL)) self.__linkCompound() if not isObserver: self.__chassisDecal.attach() self.__createAndAttachStickers() self.__startSystems() self.setupGunMatrixTargets() if not isObserver: self.__vehicle.filter.enableLagDetection( not self.__currentDamageState.isCurrentModelDamaged) self.onModelChanged() if self.lodCalculator is not None: self.lodCalculator.setupPosition( DataLinks.linkMatrixTranslation( self.__compoundModel.matrix)) if hasattr(self.filter, 'placingCompensationMatrix' ) and self.swingingAnimator is not None: self.swingingAnimator.placingCompensationMatrix = self.filter.placingCompensationMatrix self.swingingAnimator.worldMatrix = self.__compoundModel.matrix if self.__periodicTimerID is not None: BigWorld.cancelCallback(self.__periodicTimerID) self.__periodicTimerID = BigWorld.callback(_PERIODIC_TIME, self.__onPeriodicTimer) if self.fashion is not None: self.fashion.activate() if isObserver: self.__compoundModel.visible = False BigWorld.player().arena.onPeriodChange += self.__arenaPeriodChanged BigWorld.player( ).inputHandler.onCameraChanged += self.__onCameraChanged if self.detailedEngineState is not None: engine_state.checkEngineStart(self.detailedEngineState, BigWorld.player().arena.period) self.__activated = True return
def assembleDrivetrain(appearance, isPlayerVehicle): vehicleFilter = appearance.filter typeDescriptor = appearance.typeDescriptor PLAYER_UPDATE_PERIOD = 0.1 NPC_UPDATE_PERIOD = 0.25 engineState = appearance.createComponent(Vehicular.DetailedEngineState) engineState.vehicleSpeedLink = DataLinks.createFloatLink(vehicleFilter, 'averageSpeed') engineState.rotationSpeedLink = DataLinks.createFloatLink(vehicleFilter, 'averageRotationSpeed') engineState.vehicleMatrixLink = appearance.compoundModel.root speed_limits_0 = typeDescriptor.physics['speedLimits'][0] speed_limits_1 = typeDescriptor.physics['speedLimits'][1] rpm_min = typeDescriptor.engine.rpm_min rpm_max = typeDescriptor.engine.rpm_max rotation_speed_limit = typeDescriptor.physics['rotationSpeedLimit'] max_climb_angle = math.acos(typeDescriptor.physics['minPlaneNormalY']) engineState.setVehicleParams(speed_limits_0, speed_limits_1, rotation_speed_limit, max_climb_angle, rpm_min, rpm_max, isPlayerVehicle) wheeledVehicle = False if typeDescriptor.chassis.generalWheelsAnimatorConfig is not None: wheeledVehicle = typeDescriptor.chassis.generalWheelsAnimatorConfig.isWheeledVehicle() if wheeledVehicle and isPlayerVehicle: gearShiftMap = (((1e-05, rpm_min * 1.2, rpm_max * 0.98), (0.15 * speed_limits_0, rpm_min * 1.7, rpm_max * 0.98), (0.5 * speed_limits_0, rpm_min * 2.2, rpm_max * 0.98), (0.7 * speed_limits_0, rpm_max * 0.7, rpm_max * 0.9)), ((0.01, rpm_min * 1.2, rpm_max * 0.98),)) gearbox = appearance.createComponent(Vehicular.GearBox, speed_limits_0, speed_limits_1, rpm_min, rpm_max, gearShiftMap) gearbox.engineModeLink = DataLinks.createIntLink(engineState, 'mode') gearbox.vehicleSpeedLink = DataLinks.createFloatLink(vehicleFilter, 'averageSpeed') gearbox.flyingLink = DataLinks.createBoolLink(appearance.flyingInfoProvider, 'isFlying') else: gearbox = None if isPlayerVehicle: if gearbox is not None: engineState.physicRPMLink = lambda : gearbox.rpm engineState.physicGearLink = lambda : gearbox.gear elif not IS_EDITOR: p = BigWorld.player() engineState.physicRPMLink = lambda : WoT.unpackAuxVehiclePhysicsData(p.ownVehicleAuxPhysicsData)[5] engineState.physicGearLink = lambda : BigWorld.player().ownVehicleGear else: engineState.physicRPMLink = None engineState.physicGearLink = None engineState.updatePeriod = PLAYER_UPDATE_PERIOD if isPlayerVehicle else NPC_UPDATE_PERIOD return (engineState, gearbox)
def _assembleParts(self, isPlayer, appearance): if appearance.isAlive: appearance.detailedEngineState = self.__assembleEngineState(isPlayer) if not appearance.isPillbox and not gEffectsDisabled(): appearance.engineAudition = self.__assembleEngineAudition(isPlayer, appearance) appearance.detailedEngineState.onEngineStart += appearance.engineAudition.onEngineStart appearance.detailedEngineState.onStateChanged += appearance.engineAudition.onStateChanged _createEffects(appearance) if isPlayer: gunRotatorConnector = GunRotatorConnector(appearance) appearance.addComponent(gunRotatorConnector) self.__createTrackCrashControl(appearance) appearance.highlighter = Highlighter() lodCalcInst = Vehicular.LodCalculator(DataLinks.linkMatrixTranslation(appearance.compoundModel.matrix), True) appearance.lodCalculator = lodCalcInst lodLink = DataLinks.createFloatLink(lodCalcInst, 'lodDistance') if not appearance.damageState.isCurrentModelDamaged: model_assembler.assembleRecoil(appearance, lodLink) _assembleSwinging(appearance, lodLink) model_assembler.setupTurretRotations(appearance)
def setupTank(chassisFashion, gunFashion, vehicleDesc, worldMatrix, resources): print resources tank = resources[vehicleDesc.name] tank.matrix = worldMatrix tanks.append(tank) effect = Pixie.create('particles/Tank/exhaust/large_gas_gear.xml') tank.node('HP_gunFire').attach(effect) tank.node('HP_gunFire').attach(BigWorld.Model('helpers/models/position_gizmo.model')) tank.node('HP_Track_Exhaus_1').attach(BigWorld.Model('helpers/models/unit_cube.model')) m = mathUtils.createTranslationMatrix(Vector3(0, 10, 5)) fakeMatrixes.append(m) tank.node('gun').attach(effect.clone(), m) BigWorld.addModel(tank) recoilDescr = vehicleDesc.gun['recoil'] recoil = BigWorld.RecoilAnimator(recoilDescr['backoffTime'], recoilDescr['returnTime'], recoilDescr['amplitude'], recoilDescr['lodDist']) recoil.basisMatrix = tank.node('G').localMatrix recoil = assemblerModule.createGunAnimator(vehicleDesc, tank.node('G').localMatrix) recoil.lodSetting = 10 tank.node('G', recoil) gunFashion.gunLocalMatrix = recoil recoil.lodLink = DataLinks.createFloatLink(chassisFashion, 'lastLod') swingingAnimator = assemblerModule.createSwingingAnimator(vehicleDesc, tank.node('hull').localMatrix, worldMatrix) chassisFashion.setupSwinging(swingingAnimator, 'hull') swingingAnimator.lodLink = DataLinks.createFloatLink(chassisFashion, 'lastLod') tank.setupFashions([chassisFashion, None, None, gunFashion]) fashions.append(swingingAnimator) tank.node('hull', swingingAnimator) animMatrix = Math.MatrixAnimation() keys = [] for x in xrange(100): angle = math.pi * 0.5 * (1 if x & 1 else -1) keys.append((x * 3, mathUtils.createRotationMatrix((angle, 0, 0)))) animMatrix.keyframes = tuple(keys) tank.node('turret', animMatrix) return
def assembleDetailedEngineState(compoundModel, vehicleFilter, typeDescriptor, isPlayerVehicle): PLAYER_UPDATE_PERIOD = 0.1 NPC_UPDATE_PERIOD = 0.25 engineState = Vehicular.DetailedEngineState() engineState.vehicleSpeedLink = DataLinks.createFloatLink(vehicleFilter, 'averageSpeed') engineState.rotationSpeedLink = DataLinks.createFloatLink(vehicleFilter, 'averageRotationSpeed') engineState.vehicleMatrixLink = compoundModel.root speed_limits_0 = typeDescriptor.physics['speedLimits'][0] speed_limits_1 = typeDescriptor.physics['speedLimits'][1] rpm_min = typeDescriptor.engine.rpm_min rpm_max = typeDescriptor.engine.rpm_max rotation_speed_limit = typeDescriptor.physics['rotationSpeedLimit'] max_climb_angle = math.acos(typeDescriptor.physics['minPlaneNormalY']) engineState.setVehicleParams(speed_limits_0, speed_limits_1, rotation_speed_limit, max_climb_angle, rpm_min, rpm_max, isPlayerVehicle) if isPlayerVehicle: p = BigWorld.player() engineState.physicRPMLink = lambda : WoT.unpackAuxVehiclePhysicsData(p.ownVehicleAuxPhysicsData)[5] engineState.physicGearLink = lambda : BigWorld.player().ownVehicleGear else: engineState.physicRPMLink = None engineState.physicGearLink = None engineState.updatePeriod = PLAYER_UPDATE_PERIOD if isPlayerVehicle else NPC_UPDATE_PERIOD return engineState
def _assembleParts(self, isPlayer, appearance): if appearance.isAlive: appearance.detailedEngineState = self.__assembleEngineState( isPlayer) if not appearance.isPillbox and not gEffectsDisabled(): appearance.engineAudition = self.__assembleEngineAudition( isPlayer, appearance) appearance.detailedEngineState.onEngineStart += appearance.engineAudition.onEngineStart appearance.detailedEngineState.onStateChanged += appearance.engineAudition.onStateChanged _createEffects(appearance) if isPlayer: gunRotatorConnector = GunRotatorConnector(appearance) appearance.addComponent(gunRotatorConnector) self.__createTrackCrashControl(appearance) appearance.highlighter = Highlighter() lodCalcInst = Vehicular.LodCalculator( DataLinks.linkMatrixTranslation(appearance.compoundModel.matrix), True) appearance.lodCalculator = lodCalcInst lodLink = DataLinks.createFloatLink(lodCalcInst, 'lodDistance') if not appearance.damageState.isCurrentModelDamaged: model_assembler.assembleRecoil(appearance, lodLink) _assembleSwinging(appearance, lodLink) model_assembler.setupTurretRotations(appearance)
def __assembleAnimationFlagComponent(appearance, attachment, attachments, modelAnimators): mainAnimator = None for i, modelAnimator in enumerate(modelAnimators): if modelAnimator.attachmentPartNode == attachment.partNodeAlias: mainAnimator = modelAnimators.pop(i) break if mainAnimator is None: return False else: flagParts = tuple((a.partNodeAlias for a in attachments if a.attachmentLogic == 'flagPart')) appearance.flagComponent = appearance.createComponent(Vehicular.FlagComponent, mainAnimator.animator, mainAnimator.node, TankPartNames.TURRET, (attachment.partNodeAlias,) + flagParts) if appearance.filter is not None: appearance.flagComponent.vehicleSpeedLink = DataLinks.createFloatLink(appearance.filter, 'averageSpeed') appearance.flagComponent.allowTransparency(True) return True
def __init__(self, spaceID): ScriptGameObject.__init__(self, spaceID, 'Tank.Root') self._vehicle = None self.__wheelsGameObject = ScriptGameObject(spaceID, 'Tank.Wheels.Root') self.__filter = None self.__typeDesc = None self.crashedTracksController = None self.__currentDamageState = VehicleDamageState() self.__currTerrainMatKind = [-1] * MATKIND_COUNT self.__currTerrainGroundType = [-1] * MATKIND_COUNT self.__terrainEffectMaterialNames = [''] * MATKIND_COUNT self._chassisDecal = VehicleDecal(self) self.__splodge = None self.__boundEffects = None self._splineTracks = None self.flyingInfoProvider = self.createComponent(Vehicular.FlyingInfoProvider) self.__trackScrollCtl = BigWorld.PyTrackScroll() self.__trackScrollCtl.setFlyingInfo(DataLinks.createBoolLink(self.flyingInfoProvider, 'isLeftSideFlying'), DataLinks.createBoolLink(self.flyingInfoProvider, 'isRightSideFlying')) self.__weaponEnergy = 0.0 self.__outfit = None self.__systemStarted = False self.__isAlive = True self._isTurretDetached = False self.__isObserver = False self.__attachments = [] self.__modelAnimators = [] self.turretMatrix = None self.gunMatrix = None self.__allLodCalculators = [] self._commonScroll = 0.0 self._commonSlip = 0.0 self._compoundModel = None self.__fashions = None self.__filterRetrievers = [] self.__filterRetrieverGameObjects = [] self._vehicleStickers = None self._vehicleInfo = {} self.__vID = 0 self.__renderMode = None self.__frameTimestamp = 0 self.__periodicTimerID = None self.undamagedStateChildren = [] return
def assembleTracks(resourceRefs, vehicleDesc, appearance, splineTracksImpl, instantWarmup, lodLink=None): trackPairsCount = 0 tracksCfg = vehicleDesc.chassis.tracks if tracksCfg is not None: trackPairsCount = tracksCfg.pairsCount tracks = Vehicular.VehicleTracks(appearance.worldID, appearance.compoundModel, TankPartIndexes.CHASSIS, _AREA_LOD_FOR_NONSIMPLE_TRACKS, trackPairsCount) appearance.tracks = tracks assemblePhysicalTracks(resourceRefs, trackPairsCount, appearance, tracks, instantWarmup) assembleSplineTracks(vehicleDesc, appearance, splineTracksImpl, tracks) assembleSimpleTracks(appearance, vehicleDesc, appearance.fashion, appearance.wheelsAnimator, tracks) vehicleFilter = getattr(appearance, 'filter', None) if vehicleFilter is not None: tracks.setTrackScrollLink(DataLinks.createFloatLink(vehicleFilter, 'leftTrackScroll'), DataLinks.createFloatLink(vehicleFilter, 'rightTrackScroll')) if appearance.wheelsAnimator.scrollLinksRequired: tracks.sendWheelScrollLinks(appearance.wheelsAnimator) if lodLink is None: lodLink = Vehicular.getDummyLodLink() tracks.setLodLink(lodLink) crashedTracksController = getattr(appearance, 'crashedTracksController', None) if crashedTracksController is not None: crashedTracksController.baseTracksComponent = tracks return
def __linkCompound(self): vehicle = self.__vehicle vehicle.model = None vehicle.model = self.__compoundModel vehicleMatrix = vehicle.matrix self.__compoundModel.matrix = vehicleMatrix if not self.__currentDamageState.isCurrentModelDamaged: self.__swingingAnimator = model_assembler.createSwingingAnimator( self.__typeDesc, self.__compoundModel.node(TankPartNames.HULL).localMatrix, vehicleMatrix) self.__compoundModel.node(TankPartNames.HULL, self.__swingingAnimator) self.__fashions.chassis.setupSwinging(self.__swingingAnimator, 'V') if hasattr(self.__filter, 'placingCompensationMatrix'): self.__swingingAnimator.placingCompensationMatrix = self.__filter.placingCompensationMatrix gunAnimatorNode = self.__compoundModel.node('G') if gunAnimatorNode is not None: localGunMatrix = gunAnimatorNode.localMatrix self.__gunRecoil = model_assembler.createGunAnimator( self.__typeDesc, localGunMatrix) self.__compoundModel.node('G', self.__gunRecoil) self.__fashions.gun.inclinationMatrix = self.gunMatrix self.__fashions.gun.gunLocalMatrix = self.__gunRecoil lodLink = DataLinks.createFloatLink(self.fashions.chassis, 'lastLod') self.__gunRecoil.lodLink = lodLink self.__swingingAnimator.lodLink = lodLink self.__compoundModel.node(TankNodeNames.GUN_INCLINATION, self.gunMatrix) else: self.__compoundModel.node(TankPartNames.GUN, self.gunMatrix) self.__compoundModel.node(TankPartNames.TURRET, self.turretMatrix) if vehicle.isPlayerVehicle: player = BigWorld.player() if player.inputHandler is not None: player.inputHandler.addVehicleToCameraCollider(vehicle) return
def construct(self, isPlayer, resourceRefs): self.__isObserver = 'observer' in self.typeDescriptor.type.tags self._compoundModel = resourceRefs[self.typeDescriptor.name] self.removeComponentByType(GenericComponents.DynamicModelComponent) self.createComponent(GenericComponents.DynamicModelComponent, self._compoundModel) if not self._compoundModel.isValid(): _logger.error('compoundModel is not valid') if self.typeDescriptor.gun.edgeByVisualModel: self._compoundModel.setPartProperties( TankPartIndexes.GUN, PartProperties.HIGHLIGHTABLE | PartProperties.HIGHLIGHTBYVISUAL) self._compoundModel.setPartProperties( TankPartIndexes.CHASSIS, PartProperties.HIGHLIGHTABLE | PartProperties.HIGHLIGHTBYVISUAL) self.__boundEffects = bound_effects.ModelBoundEffects( self.compoundModel) isCurrentModelDamaged = self.damageState.isCurrentModelDamaged fashions = camouflages.prepareFashions(isCurrentModelDamaged) if not isCurrentModelDamaged: model_assembler.setupTracksFashion(self.typeDescriptor, fashions.chassis) self.collisions = self.createComponent( BigWorld.CollisionComponent, resourceRefs['collisionAssembler']) model_assembler.setupCollisions(self.typeDescriptor, self.collisions) self._setFashions(fashions, self.isTurretDetached) self._setupModels() if not isCurrentModelDamaged: modelsSet = self.outfit.modelsSet if IS_EDITOR: modelsSet = self.currentModelsSet self._splineTracks = model_assembler.setupSplineTracks( self.fashion, self.typeDescriptor, self.compoundModel, resourceRefs, modelsSet) self.crashedTracksController = CrashedTrackController( self.typeDescriptor, self.fashion, modelsSet) else: self.__trackScrollCtl = None self._chassisDecal.create() if self.modelsSetParams.state == 'undamaged': self.__modelAnimators = camouflages.getModelAnimators( self.outfit, self.typeDescriptor, self.spaceID, resourceRefs, self.compoundModel) self.__modelAnimators.extend( camouflages.getAttachmentsAnimators(self.__attachments, self.spaceID, resourceRefs, self.compoundModel)) self.transform = self.createComponent( GenericComponents.TransformComponent, Math.Vector3(0, 0, 0)) self.areaTriggerTarget = self.createComponent( Triggers.AreaTriggerTarget) self.__filter = model_assembler.createVehicleFilter( self.typeDescriptor) compoundModel = self.compoundModel if self.isAlive: self.detailedEngineState, self.gearbox = model_assembler.assembleDrivetrain( self, isPlayer) if not gEffectsDisabled(): self.customEffectManager = CustomEffectManager(self) if self.typeDescriptor.hasSiegeMode: self.siegeEffects = SiegeEffectsController(self, isPlayer) model_assembler.assembleVehicleAudition(isPlayer, self) self.detailedEngineState.onEngineStart = self._onEngineStart self.detailedEngineState.onStateChanged = self.engineAudition.onEngineStateChanged if isPlayer: turret = self.typeDescriptor.turret gunRotatorAudition = self.createComponent( Vehicular.GunRotatorAudition, turret.turretRotatorSoundManual, turret.weight / 1000.0, compoundModel.node(TankPartNames.TURRET)) gunRotatorAudition.vehicleMatrixLink = self.compoundModel.root gunRotatorAudition.damaged = lambda: self.turretDamaged() gunRotatorAudition.maxTurretRotationSpeed = lambda: self.maxTurretRotationSpeed( ) self.gunRotatorAudition = gunRotatorAudition self.frictionAudition = self.createComponent( Vehicular.FrictionAudition, TANK_FRICTION_EVENT) isLodTopPriority = isPlayer lodCalcInst = self.createComponent( Vehicular.LodCalculator, DataLinks.linkMatrixTranslation(compoundModel.matrix), True, VEHICLE_PRIORITY_GROUP, isLodTopPriority) self.lodCalculator = lodCalcInst self.allLodCalculators.append(lodCalcInst) lodLink = DataLinks.createFloatLink(lodCalcInst, 'lodDistance') lodStateLink = lodCalcInst.lodStateLink if IS_EDITOR: matrixBinding = None changeCamera = None else: matrixBinding = BigWorld.player( ).consistentMatrices.onVehicleMatrixBindingChanged changeCamera = BigWorld.player().inputHandler.onCameraChanged self.shadowManager = VehicleShadowManager(compoundModel, matrixBinding, changeCamera) if not self.damageState.isCurrentModelDamaged: self.__assembleNonDamagedOnly(resourceRefs, isPlayer, lodLink, lodStateLink) dirtEnabled = BigWorld.WG_dirtEnabled( ) and 'HD' in self.typeDescriptor.type.tags if dirtEnabled and self.fashions is not None: dirtHandlers = [ BigWorld.PyDirtHandler( True, compoundModel.node(TankPartNames.CHASSIS).position.y), BigWorld.PyDirtHandler( False, compoundModel.node(TankPartNames.HULL).position.y), BigWorld.PyDirtHandler( False, compoundModel.node(TankPartNames.TURRET).position.y), BigWorld.PyDirtHandler( False, compoundModel.node(TankPartNames.GUN).position.y) ] modelHeight, _ = self.computeVehicleHeight() self.dirtComponent = self.createComponent( Vehicular.DirtComponent, dirtHandlers, modelHeight) for fashionIdx, _ in enumerate(TankPartNames.ALL): self.fashions[fashionIdx].addMaterialHandler( dirtHandlers[fashionIdx]) self.fashions[fashionIdx].addTrackMaterialHandler( dirtHandlers[fashionIdx]) model_assembler.setupTurretRotations(self) self.waterSensor = model_assembler.assembleWaterSensor( self.typeDescriptor, self, lodStateLink, self.spaceID) if self.engineAudition is not None: self.engineAudition.setIsUnderwaterInfo( DataLinks.createBoolLink(self.waterSensor, 'isUnderWater')) self.engineAudition.setIsInWaterInfo( DataLinks.createBoolLink(self.waterSensor, 'isInWater')) self.__postSetupFilter() compoundModel.setPartBoundingBoxAttachNode( TankPartIndexes.GUN, TankNodeNames.GUN_INCLINATION) camouflages.updateFashions(self) model_assembler.assembleCustomLogicComponents(self, self.typeDescriptor, self.__attachments, self.__modelAnimators) self._createStickers() while self._loadingQueue: prefab, go, vector, callback = self._loadingQueue.pop() CGF.loadGameObjectIntoHierarchy(prefab, go, vector, callback) return
def activate(self): if self.__activated or self.__vehicle is None: return else: if self.collisions is not None and self.__vehicle.isTurretDetached: self.collisions.removeAttachment( TankPartNames.getIdx(TankPartNames.TURRET)) self.collisions.removeAttachment( TankPartNames.getIdx(TankPartNames.GUN)) super(CompoundAppearance, self).activate() isPlayerVehicle = self.__vehicle.isPlayerVehicle self.__isObserver = 'observer' in self.__typeDesc.type.tags player = BigWorld.player() self.__originalFilter = self.__vehicle.filter self.__vehicle.filter = self.__filter self.__vehicle.filter.enableStabilisedMatrix(isPlayerVehicle) self.__filter.isStrafing = self.__vehicle.isStrafing self.__filter.vehicleCollisionCallback = player.handleVehicleCollidedVehicle if isPlayerVehicle and self.collisions is not None: colliderData = (self.collisions.getColliderID(), (TankPartNames.getIdx(TankPartNames.HULL), TankPartNames.getIdx(TankPartNames.TURRET))) BigWorld.appendCameraCollider(colliderData) self.__inSpeedTreeCollision = True BigWorld.setSpeedTreeCollisionBody( self.__compoundModel.getBoundsForPart( TankPartIndexes.HULL)) self.__linkCompound() if not self.__isObserver: self.__chassisDecal.attach() self.__createAndAttachStickers() if self.__currentDamageState.isCurrentModelDamaged: self.__chassisColisionMatrix.target = self.__compoundModel.matrix gunNodeName = 'gun' else: self.__chassisColisionMatrix.target = self.__vehicle.filter.groundPlacingMatrix gunNodeName = TankNodeNames.GUN_INCLINATION if not self.__isObserver: self.__startSystems() self.setupGunMatrixTargets() if not self.__isObserver: self.__vehicle.filter.enableLagDetection( not self.__currentDamageState.isCurrentModelDamaged) self.onModelChanged() if self.lodCalculator is not None: self.lodCalculator.setupPosition( DataLinks.linkMatrixTranslation( self.__compoundModel.matrix)) if hasattr(self.filter, 'placingCompensationMatrix' ) and self.swingingAnimator is not None: self.swingingAnimator.placingCompensationMatrix = self.filter.placingCompensationMatrix self.swingingAnimator.worldMatrix = self.__compoundModel.matrix if not self.__isObserver: if self.__periodicTimerID is not None: BigWorld.cancelCallback(self.__periodicTimerID) self.__periodicTimerID = BigWorld.callback( _PERIODIC_TIME, self.__onPeriodicTimer) self.__dirtUpdateTime = BigWorld.time() if self.fashion is not None: self.fashion.activate() if self.__isObserver: self.__compoundModel.visible = False BigWorld.player().arena.onPeriodChange += self.__arenaPeriodChanged BigWorld.player( ).inputHandler.onCameraChanged += self.__onCameraChanged if self.detailedEngineState is not None: engine_state.checkEngineStart(self.detailedEngineState, BigWorld.player().arena.period) if self.collisions is not None: collisionData = ((TankPartNames.getIdx(TankPartNames.HULL), self.compoundModel.node(TankPartNames.HULL)), (TankPartNames.getIdx(TankPartNames.TURRET), self.compoundModel.node( TankPartNames.TURRET)), (TankPartNames.getIdx(TankPartNames.CHASSIS), self.__chassisColisionMatrix), (TankPartNames.getIdx(TankPartNames.GUN), self.compoundModel.node(gunNodeName))) self.collisions.connect(self.id, ColliderTypes.VEHICLE_COLLIDER, collisionData) self.__activated = True return
def _assembleParts(self, isPlayer, appearance, resourceRefs): appearance.filter = model_assembler.createVehicleFilter( appearance.typeDescriptor) if appearance.isAlive: appearance.detailedEngineState = model_assembler.assembleDetailedEngineState( appearance.compoundModel, appearance.filter, appearance.typeDescriptor, isPlayer) if not gEffectsDisabled(): model_assembler.assembleVehicleAudition(isPlayer, appearance) model_assembler.subscribeEngineAuditionToEngineState( appearance.engineAudition, appearance.detailedEngineState) createEffects(appearance) if isPlayer: gunRotatorConnector = GunRotatorConnector(appearance) appearance.addComponent(gunRotatorConnector) appearance.frictionAudition = Vehicular.FrictionAudition( TANK_FRICTION_EVENT) appearance.peripheralsController = PeripheralsController() self.__createTrackCrashControl(appearance) appearance.highlighter = Highlighter() compoundModel = appearance.compoundModel isLodTopPriority = isPlayer lodCalcInst = Vehicular.LodCalculator( DataLinks.linkMatrixTranslation(appearance.compoundModel.matrix), True, VEHICLE_PRIORITY_GROUP, isLodTopPriority) appearance.lodCalculator = lodCalcInst lodLink = DataLinks.createFloatLink(lodCalcInst, 'lodDistance') lodStateLink = lodCalcInst.lodStateLink matrixBinding = BigWorld.player( ).consistentMatrices.onVehicleMatrixBindingChanged appearance.shadowManager = VehicleShadowManager( compoundModel, matrixBinding) isDamaged = appearance.damageState.isCurrentModelDamaged if not isDamaged: self.__assembleNonDamagedOnly(appearance, isPlayer, lodLink, lodStateLink) dirtEnabled = BigWorld.WG_dirtEnabled( ) and 'HD' in appearance.typeDescriptor.type.tags fashions = appearance.fashions if dirtEnabled and fashions is not None: dirtHandlers = [ BigWorld.PyDirtHandler( True, compoundModel.node(TankPartNames.CHASSIS).position.y), BigWorld.PyDirtHandler( False, compoundModel.node(TankPartNames.HULL).position.y), BigWorld.PyDirtHandler( False, compoundModel.node(TankPartNames.TURRET).position.y), BigWorld.PyDirtHandler( False, compoundModel.node(TankPartNames.GUN).position.y) ] modelHeight, _ = appearance.computeVehicleHeight() appearance.dirtComponent = Vehicular.DirtComponent( dirtHandlers, modelHeight) for fashionIdx, _ in enumerate(TankPartNames.ALL): fashions[fashionIdx].addMaterialHandler( dirtHandlers[fashionIdx]) model_assembler.setupTurretRotations(appearance) if appearance.fashion is not None: appearance.fashion.movementInfo = appearance.filter.movementInfo appearance.waterSensor = model_assembler.assembleWaterSensor( appearance.typeDescriptor, appearance, lodStateLink) if appearance.engineAudition is not None: appearance.engineAudition.setIsUnderwaterInfo( DataLinks.createBoolLink(appearance.waterSensor, 'isUnderWater')) appearance.engineAudition.setIsInWaterInfo( DataLinks.createBoolLink(appearance.waterSensor, 'isInWater')) if isPlayer and BigWorld.player().isInTutorial: tutorialMatKindsController = TutorialMatKindsController() tutorialMatKindsController.terrainMatKindsLink = lambda: appearance.terrainMatKind appearance.addComponent(tutorialMatKindsController) self.__postSetupFilter(appearance) compoundModel.setPartBoundingBoxAttachNode( TankPartIndexes.GUN, TankNodeNames.GUN_INCLINATION) return
def assembleVehicleAudition(isPlayer, appearance): PLAYER_UPDATE_PERIOD = 0.1 NPC_UPDATE_PERIOD = 0.25 typeDescriptor = appearance.typeDescriptor engineEventName = typeDescriptor.engine.sounds.getEvents() chassisEventName = typeDescriptor.chassis.sounds.getEvents() wheeledVehicle = False if typeDescriptor.chassis.generalWheelsAnimatorConfig is not None: wheeledVehicle = typeDescriptor.chassis.generalWheelsAnimatorConfig.isWheeledVehicle() if wheeledVehicle: vehicleData = (typeDescriptor.physics['enginePower'] / component_constants.HP_TO_WATTS, typeDescriptor.physics['weight'], typeDescriptor.physics['rotationSpeedLimit'], engineEventName, chassisEventName, ('wheel_vehicle_wheel_repaired', 'wheel_vehicle_wheel_metal_repaired'), ('wheel_vehicle_wheel_damaged', 'wheel_vehicle_wheel_metal_damaged'), 'RTPC_ext_client_rpm_rel', 'RTPC_ext_client_rpm_abs') else: vehicleData = (typeDescriptor.physics['enginePower'] / component_constants.HP_TO_WATTS, typeDescriptor.physics['weight'], typeDescriptor.physics['rotationSpeedLimit'], engineEventName, chassisEventName, ('repair_treads',), ('brakedown_treads',), '', '') vehicleAudition = appearance.createComponent(Vehicular.VehicleAudition, appearance.id, isPlayer, vehicleData) vehicleAudition.setEffectMaterialsInfo(lambda : appearance.terrainEffectMaterialNames) vehicleAudition.setSpeedInfo(lambda : appearance.filter.angularSpeed, lambda : appearance.filter.strafeSpeed) vehicleAudition.setTracksInfo(lambda : appearance.transmissionScroll, lambda : appearance.transmissionSlip, lambda : appearance.getWheelsSteeringMax(), DataLinks.createBoolLink(appearance.flyingInfoProvider, 'isFlying')) if typeDescriptor.type.siegeModeParams is not None: soundStateChange = typeDescriptor.type.siegeModeParams['soundStateChange'] vehicleAudition.setSiegeSoundEvents(soundStateChange.isEngine, soundStateChange.on if isPlayer else soundStateChange.npcOn, soundStateChange.off if isPlayer else soundStateChange.npcOff) vehicleAudition.setDetailedEngineState(appearance.detailedEngineState) vehicleAudition.setUpdatePeriod(PLAYER_UPDATE_PERIOD if isPlayer else NPC_UPDATE_PERIOD) appearance.engineAudition = vehicleAudition return