Exemplo n.º 1
0
 public virtual void Init(MyObjectBuilder_Character characterBuilder)
 {
     if (characterBuilder != null)
     {
         MyFuelConverterInfo fuelConverter;
         this.CurrentAutoEnableDelay = characterBuilder.AutoenableJetpackDelay;
         if (this.ThrustComp != null)
         {
             base.Character.Components.Remove <MyJetpackThrustComponent>();
         }
         MyObjectBuilder_ThrustDefinition thrustProperties = base.Character.Definition.Jetpack.ThrustProperties;
         this.FuelConverterDefinition = null;
         if (MyFakes.ENABLE_HYDROGEN_FUEL)
         {
             fuelConverter = base.Character.Definition.Jetpack.ThrustProperties.FuelConverter;
         }
         else
         {
             MyFuelConverterInfo info1 = new MyFuelConverterInfo();
             info1.Efficiency = 1f;
             fuelConverter    = info1;
         }
         this.FuelConverterDefinition = fuelConverter;
         MyDefinitionId defId = new MyDefinitionId();
         if (!this.FuelConverterDefinition.FuelId.IsNull())
         {
             defId = thrustProperties.FuelConverter.FuelId;
         }
         MyGasProperties definition = null;
         if (MyFakes.ENABLE_HYDROGEN_FUEL)
         {
             MyDefinitionManager.Static.TryGetDefinition <MyGasProperties>(defId, out definition);
         }
         MyGasProperties properties2 = definition;
         if (definition == null)
         {
             MyGasProperties local1      = definition;
             MyGasProperties properties1 = new MyGasProperties();
             properties1.Id            = MyResourceDistributorComponent.ElectricityId;
             properties1.EnergyDensity = 1f;
             properties2 = properties1;
         }
         this.FuelDefinition              = properties2;
         this.ForceMagnitude              = thrustProperties.ForceMagnitude;
         this.MinPowerConsumption         = thrustProperties.MinPowerConsumption;
         this.MaxPowerConsumption         = thrustProperties.MaxPowerConsumption;
         this.MinPlanetaryInfluence       = thrustProperties.MinPlanetaryInfluence;
         this.MaxPlanetaryInfluence       = thrustProperties.MaxPlanetaryInfluence;
         this.EffectivenessAtMinInfluence = thrustProperties.EffectivenessAtMinInfluence;
         this.EffectivenessAtMaxInfluence = thrustProperties.EffectivenessAtMaxInfluence;
         this.NeedsAtmosphereForInfluence = thrustProperties.NeedsAtmosphereForInfluence;
         this.ConsumptionFactorPerG       = thrustProperties.ConsumptionFactorPerG;
         MyEntityThrustComponent component = new MyJetpackThrustComponent();
         component.Init();
         base.Character.Components.Add <MyEntityThrustComponent>(component);
         this.ThrustComp.DampenersEnabled = characterBuilder.DampenersEnabled;
         foreach (Vector3I vectori in Base6Directions.IntDirections)
         {
             this.ThrustComp.Register(base.Character, vectori, null);
         }
         component.ResourceSink(base.Character).TemporaryConnectedEntity = base.Character;
         base.Character.SuitRechargeDistributor.AddSink(component.ResourceSink(base.Character));
         this.TurnOnJetpack(characterBuilder.JetpackEnabled, true, true);
     }
 }
        public virtual void Init(MyObjectBuilder_Character characterBuilder)
        {
            if (characterBuilder == null)
            {
                return;
            }

            m_inertiaDampenersNotification = new MyHudNotification();
            m_jetpackToggleNotification    = new MyHudNotification();

            CurrentAutoEnableDelay = characterBuilder.AutoenableJetpackDelay;

            if (ThrustComp != null)
            {
                Character.Components.Remove <MyJetpackThrustComponent>();
            }

            var thrustProperties = Character.Definition.Jetpack.ThrustProperties;

            FuelConverterDefinition = null;;
            FuelConverterDefinition = !MyFakes.ENABLE_HYDROGEN_FUEL ? new MyFuelConverterInfo {
                Efficiency = 1.0f
            } : Character.Definition.Jetpack.ThrustProperties.FuelConverter;

            MyDefinitionId fuelId = new MyDefinitionId();

            if (!FuelConverterDefinition.FuelId.IsNull())
            {
                fuelId = thrustProperties.FuelConverter.FuelId;
            }

            MyGasProperties fuelDef = null;

            if (MyFakes.ENABLE_HYDROGEN_FUEL)
            {
                MyDefinitionManager.Static.TryGetDefinition(fuelId, out fuelDef);
            }

            FuelDefinition = fuelDef ?? new MyGasProperties // Use electricity by default
            {
                Id            = MyResourceDistributorComponent.ElectricityId,
                EnergyDensity = 1f,
            };

            ForceMagnitude              = thrustProperties.ForceMagnitude;
            MinPowerConsumption         = thrustProperties.MinPowerConsumption;
            MaxPowerConsumption         = thrustProperties.MaxPowerConsumption;
            MinPlanetaryInfluence       = thrustProperties.MinPlanetaryInfluence;
            MaxPlanetaryInfluence       = thrustProperties.MaxPlanetaryInfluence;
            EffectivenessAtMinInfluence = thrustProperties.EffectivenessAtMinInfluence;
            EffectivenessAtMaxInfluence = thrustProperties.EffectivenessAtMaxInfluence;
            NeedsAtmosphereForInfluence = thrustProperties.NeedsAtmosphereForInfluence;
            ConsumptionFactorPerG       = thrustProperties.ConsumptionFactorPerG;

            MyEntityThrustComponent thrustComp = new MyJetpackThrustComponent();

            thrustComp.Init();
            Character.Components.Add(thrustComp);


            ThrustComp.DampenersEnabled = characterBuilder.DampenersEnabled;

            foreach (Vector3I direction in Base6Directions.IntDirections)
            {
                ThrustComp.Register(Character, direction);                      // Preferably there should be a jetpack entity (equipment) that could hold the thrusts instead of the character
            }
            thrustComp.ResourceSink(Character).TemporaryConnectedEntity = Character;
            Character.SuitRechargeDistributor.AddSink(thrustComp.ResourceSink(Character));
            TurnOnJetpack(characterBuilder.JetpackEnabled, true, true, true);
        }
Exemplo n.º 3
0
        public unsafe void MoveAndRotate(ref Vector3 moveIndicator, ref Vector2 rotationIndicator, float roll, bool canRotate)
        {
            MyCharacterProxy characterProxy = base.Character.Physics.CharacterProxy;

            this.ThrustComp.ControlThrust = Vector3.Zero;
            base.Character.SwitchAnimation(MyCharacterMovementEnum.Flying, true);
            base.Character.SetCurrentMovementState(MyCharacterMovementEnum.Flying);
            MyCharacterMovementFlags movementFlags = base.Character.MovementFlags;
            MyCharacterMovementFlags flags2        = base.Character.MovementFlags;

            this.IsFlying = !(moveIndicator.LengthSquared() == 0f);
            HkCharacterStateType type = (characterProxy != null) ? characterProxy.GetState() : HkCharacterStateType.HK_CHARACTER_ON_GROUND;

            if ((type == HkCharacterStateType.HK_CHARACTER_IN_AIR) || (type == ((HkCharacterStateType)5)))
            {
                base.Character.PlayCharacterAnimation("Jetpack", MyBlendOption.Immediate, MyFrameOption.Loop, 0.2f, 1f, false, null, false);
                base.Character.CanJump = true;
            }
            MatrixD worldMatrix = base.Character.WorldMatrix;

            if (canRotate)
            {
                MatrixD identity = MatrixD.Identity;
                MatrixD xd3      = MatrixD.Identity;
                MatrixD xd4      = MatrixD.Identity;
                if (Math.Abs(rotationIndicator.X) > float.Epsilon)
                {
                    if (base.Character.Definition.VerticalPositionFlyingOnly)
                    {
                        base.Character.SetHeadLocalXAngle(base.Character.HeadLocalXAngle - (rotationIndicator.X * base.Character.RotationSpeed));
                    }
                    else
                    {
                        identity = MatrixD.CreateFromAxisAngle(worldMatrix.Right, (double)((-rotationIndicator.X * base.Character.RotationSpeed) * 0.02f));
                    }
                }
                if (Math.Abs(rotationIndicator.Y) > float.Epsilon)
                {
                    xd3 = MatrixD.CreateFromAxisAngle(worldMatrix.Up, (double)((-rotationIndicator.Y * base.Character.RotationSpeed) * 0.02f));
                }
                if (!base.Character.Definition.VerticalPositionFlyingOnly && (Math.Abs(roll) > float.Epsilon))
                {
                    xd4 = MatrixD.CreateFromAxisAngle(worldMatrix.Forward, (double)(roll * 0.02f));
                }
                float    y      = base.Character.ModelCollision.BoundingBoxSizeHalf.Y;
                MatrixD  xd7    = worldMatrix.GetOrientation() * ((identity * xd3) * xd4);
                MatrixD *xdPtr1 = (MatrixD *)ref xd7;
                xdPtr1.Translation         = (base.Character.Physics.GetWorldMatrix().Translation + (worldMatrix.Up * y)) - (xd7.Up * y);
                base.Character.WorldMatrix = xd7;
                base.Character.ClearShapeContactPoints();
            }
            Vector3 position = moveIndicator;

            if (base.Character.Definition.VerticalPositionFlyingOnly)
            {
                float  num2 = Math.Sign(base.Character.HeadLocalXAngle);
                double x    = Math.Abs(MathHelper.ToRadians(base.Character.HeadLocalXAngle));
                double y    = 1.95;
                double num5 = Math.Pow(x, y) * (x / Math.Pow((double)MathHelper.ToRadians((float)89f), y));
                position = (Vector3)Vector3D.Transform(position, MatrixD.CreateFromAxisAngle(Vector3D.Right, num2 * num5));
            }
            if (!Vector3.IsZero(position))
            {
                position.Normalize();
            }
            MyJetpackThrustComponent thrustComp = this.ThrustComp;

            thrustComp.ControlThrust += position * this.ForceMagnitude;
        }