/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary> protected override void OnPostCreate( bool loaded ) { base.OnPostCreate( loaded ); AddTimer(); 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 ); } } } }
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 ); AddTimer(); if( EntitySystemWorld.Instance.WorldSimulationType != WorldSimulationType.Editor ) { 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; } ); //That the body did not fall after loading a map. //After loading a map, the physics simulate 5 seconds, that bodies have fallen asleep. if( loaded && EntitySystemWorld.Instance.SerializationMode == SerializationModes.Map ) { if( chassisBody != null ) chassisBody.Static = true; if( towerBody != null ) towerBody.Static = true; } //replace track materials if( EntitySystemWorld.Instance.WorldSimulationType != WorldSimulationType.Editor ) InitTracksAnimation(); }