void TickCurrentGear() { //currently gears used only for sounds if( currentGear == null ) return; if( motorOn ) { float speed = Math.Max( leftTrack.speed, rightTrack.speed ); TankType.Gear newGear = null; if( speed < currentGear.SpeedRange.Minimum || speed > currentGear.SpeedRange.Maximum ) { //find new gear newGear = Type.Gears.Find( delegate( TankType.Gear gear ) { return speed >= gear.SpeedRange.Minimum && speed <= gear.SpeedRange.Maximum; } ); } if( newGear != null && currentGear != newGear ) { //change gear TankType.Gear oldGear = currentGear; OnGearChange( oldGear, newGear ); currentGear = newGear; } } else { if( currentGear.Number != 0 ) { currentGear = Type.Gears.Find( delegate( TankType.Gear gear ) { return gear.Number == 0; } ); } } }
/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary> protected override void OnPostCreate( bool loaded ) { base.OnPostCreate( loaded ); SubscribeToTickEvent(); if( EngineApp.Instance.ApplicationType != EngineApp.ApplicationTypes.ResourceEditor ) { if( PhysicsModel == null ) { Log.Error( "Tank: Physics model not exists." ); return; } chassisBody = PhysicsModel.GetBody( "chassis" ); if( chassisBody == null ) { Log.Error( "Tank: \"chassis\" body not exists." ); return; } towerBody = PhysicsModel.GetBody( "tower" ); //chassisBody.Collision += chassisBody_Collision; foreach( MapObjectAttachedObject attachedObject in AttachedObjects ) { if( attachedObject.Alias == "leftTrack" ) leftTrack.trackHelpers.Add( (MapObjectAttachedHelper)attachedObject ); if( attachedObject.Alias == "rightTrack" ) rightTrack.trackHelpers.Add( (MapObjectAttachedHelper)attachedObject ); } if( leftTrack.trackHelpers.Count != 0 ) tracksPositionYOffset = Math.Abs( leftTrack.trackHelpers[ 0 ].PositionOffset.Y ); } //mainGun foreach( MapObjectAttachedObject attachedObject in AttachedObjects ) { MapObjectAttachedMapObject attachedMapObject = attachedObject as MapObjectAttachedMapObject; if( attachedMapObject == null ) continue; mainGun = attachedMapObject.MapObject as Gun; if( mainGun != null ) { mainGunAttachedObject = attachedMapObject; mainGunOffsetPosition = attachedMapObject.PositionOffset; break; } } //towerBodyLocalPosition if( towerBody != null ) towerBodyLocalPosition = PhysicsModel.ModelDeclaration.GetBody( towerBody.Name ).Position; //initialize currentGear currentGear = Type.Gears.Find( delegate( TankType.Gear gear ) { return gear.Number == 0; } ); if( EngineApp.Instance.ApplicationType != EngineApp.ApplicationTypes.ResourceEditor ) { InitTracksTextureAnimation(); InitWheelsSkeletonAnimation(); } //disable contacts between chassisBody and towerBody if( chassisBody != null && towerBody != null ) { foreach( Shape shape1 in chassisBody.Shapes ) { foreach( Shape shape2 in towerBody.Shapes ) { PhysicsWorld.Instance.SetShapePairFlags( shape1, shape2, ShapePairFlags.DisableContacts ); } } } }