protected override void CreateTerminalControls()
        {
            if (MyTerminalControlFactory.AreControlsCreated <MyMechanicalConnectionBlockBase>())
            {
                return;
            }
            base.CreateTerminalControls();
            var weldSpeed = new MyTerminalControlSlider <MyMechanicalConnectionBlockBase>("Weld speed", MySpaceTexts.BlockPropertyTitle_WeldSpeed, MySpaceTexts.Blank);

            weldSpeed.SetLimits((block) => 0f, (block) => MyGridPhysics.SmallShipMaxLinearVelocity());
            weldSpeed.DefaultValueGetter = (block) => MyGridPhysics.LargeShipMaxLinearVelocity() - 5f;
            weldSpeed.Getter             = (x) => x.m_weldSpeed;
            weldSpeed.Setter             = (x, v) => x.m_weldSpeed.Value = v;
            weldSpeed.Writer             = (x, res) => res.AppendDecimal((float)Math.Sqrt(x.m_weldSpeedSq), 1).Append("m/s");
            weldSpeed.EnableActions();
            MyTerminalControlFactory.AddControl(weldSpeed);

            var weldForce = new MyTerminalControlCheckbox <MyMechanicalConnectionBlockBase>("Force weld", MySpaceTexts.BlockPropertyTitle_WeldForce, MySpaceTexts.Blank);

            weldForce.Getter = (x) => x.m_forceWeld;
            weldForce.Setter = (x, v) => x.m_forceWeld.Value = v;
            weldForce.EnableAction();
            MyTerminalControlFactory.AddControl(weldForce);

            var addPistonHead = new MyTerminalControlButton <MyMechanicalConnectionBlockBase>("Add Top Part", MySpaceTexts.BlockActionTitle_AddPistonHead, MySpaceTexts.BlockActionTooltip_AddPistonHead, (b) => b.RecreateTop());

            addPistonHead.Enabled = (b) => (b.TopBlock == null);
            addPistonHead.EnableAction(MyTerminalActionIcons.STATION_ON);
            MyTerminalControlFactory.AddControl(addPistonHead);
        }
Ejemplo n.º 2
0
        private static void UpdateGridMaxSpeed(MyCubeGrid grid, bool fromServer = true)
        {
            if (Sync.IsServer == false && grid != null && grid.Physics != null && grid.Physics.RigidBody != null)
            {
                float maxSpeed = 1.04f * (grid.GridSizeEnum == MyCubeSize.Large ? MyGridPhysics.LargeShipMaxLinearVelocity() : MyGridPhysics.SmallShipMaxLinearVelocity());

                maxSpeed *= Sync.RelativeSimulationRatio;

                if (fromServer && grid.Physics.RigidBody.LinearVelocity.LengthSquared() > maxSpeed * maxSpeed)
                {
                    grid.Physics.RigidBody.MaxLinearVelocity = grid.Physics.RigidBody.LinearVelocity.Length();
                }
                else
                {
                    grid.Physics.RigidBody.MaxLinearVelocity = maxSpeed;
                }
            }
        }
        private void UpdateGridMaxSpeed(MyCubeGrid grid, bool fromServer = true)
        {
            if (Sync.IsServer == false && MyPerGameSettings.EnableMultiplayerVelocityCompensation && grid != null && grid.Physics != null && grid.Physics.RigidBody != null)
            {
                float maxSpeed = grid.GridSizeEnum == MyCubeSize.Large ? MyGridPhysics.LargeShipMaxLinearVelocity() : MyGridPhysics.SmallShipMaxLinearVelocity();

                maxSpeed *= Sync.RelativeSimulationRatio;

                if (fromServer && grid.Physics.RigidBody.LinearVelocity.LengthSquared() > maxSpeed * maxSpeed)
                {
                    grid.Physics.RigidBody.MaxLinearVelocity = grid.Physics.RigidBody.LinearVelocity.Length();
                }
                else
                {
                    grid.Physics.RigidBody.MaxLinearVelocity = maxSpeed;
                }
            }
        }
Ejemplo n.º 4
0
        static void CreateTerminalControls()
        {
            if (MyTerminalControlFactory.AreControlsCreated <MyMechanicalConnectionBlockBase>())
            {
                return;
            }

            var weldSpeed = new MyTerminalControlSlider <MyMechanicalConnectionBlockBase>("Weld speed", MySpaceTexts.BlockPropertyTitle_WeldSpeed, MySpaceTexts.Blank);

            weldSpeed.SetLimits((block) => 0f, (block) => MyGridPhysics.SmallShipMaxLinearVelocity());
            weldSpeed.DefaultValueGetter = (block) => MyGridPhysics.LargeShipMaxLinearVelocity() - 5f;
            weldSpeed.Getter             = (x) => (float)Math.Sqrt(x.m_weldSpeedSq);
            weldSpeed.Setter             = (x, v) => x.m_weldSpeedSq.Value = v * v;
            weldSpeed.Writer             = (x, res) => res.AppendDecimal((float)Math.Sqrt(x.m_weldSpeedSq), 1).Append("m/s");
            weldSpeed.EnableActions();
            MyTerminalControlFactory.AddControl(weldSpeed);

            var weldForce = new MyTerminalControlCheckbox <MyMechanicalConnectionBlockBase>("Force weld", MySpaceTexts.BlockPropertyTitle_WeldForce, MySpaceTexts.Blank);

            weldForce.Getter = (x) => x.m_forceWeld;
            weldForce.Setter = (x, v) => x.m_forceWeld.Value = v;
            weldForce.EnableAction();
            MyTerminalControlFactory.AddControl(weldForce);
        }
        protected override void UpdateThrusts(bool networkUpdate = false)
        {
            base.UpdateThrusts(networkUpdate);

            ProfilerShort.Begin("ThrusterBlockComponent.UpdateThrusts");
            if (CubeGrid != null && CubeGrid.Physics != null)
            {
                if (CubeGrid.Physics.Enabled)
                {
                    if (FinalThrust.LengthSquared() > 0.001f)
                    {
                        var thrust = FinalThrust;
                        if (CubeGrid.Physics.IsWelded) //only reliable variant
                        {
                            thrust = Vector3.TransformNormal(thrust, CubeGrid.WorldMatrix);
                            thrust = Vector3.TransformNormal(thrust, Matrix.Invert(CubeGrid.Physics.RigidBody.GetRigidBodyMatrix()));
                        }
                        CubeGrid.Physics.AddForce(MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE, thrust, null, null);

                        if (MyPerGameSettings.EnableMultiplayerVelocityCompensation)
                        {
                            Vector3 velocity = CubeGrid.Physics.LinearVelocity;
                            float   maxSpeed = CubeGrid.GridSizeEnum == MyCubeSize.Large ? MyGridPhysics.LargeShipMaxLinearVelocity() : MyGridPhysics.SmallShipMaxLinearVelocity();

                            maxSpeed *= Sync.RelativeSimulationRatio;
                            if (velocity.LengthSquared() > maxSpeed * maxSpeed)
                            {
                                velocity.Normalize();
                                velocity *= maxSpeed;
                                CubeGrid.Physics.LinearVelocity = velocity;
                            }
                        }
                    }

                    const float stoppingVelocitySq = 0.001f * 0.001f;
                    if (CubeGrid.Physics.LinearVelocity != Vector3.Zero && CubeGrid.Physics.LinearVelocity.LengthSquared() < stoppingVelocitySq && CubeGrid.Physics.RigidBody.IsActive)
                    {
                        CubeGrid.Physics.LinearVelocity = Vector3.Zero;
                        ControlThrustChanged            = true;
                    }
                }
            }
            ProfilerShort.End();
        }
Ejemplo n.º 6
0
        static void CreateTerminalControls()
        {
            if (MyTerminalControlFactory.AreControlsCreated <MyMotorStator>())
            {
                return;
            }

            var reverse = new MyTerminalControlButton <MyMotorStator>("Reverse", MySpaceTexts.BlockActionTitle_Reverse, MySpaceTexts.Blank, (b) => b.TargetVelocityRPM = -b.TargetVelocityRPM);

            reverse.EnableAction(MyTerminalActionIcons.REVERSE);
            MyTerminalControlFactory.AddControl(reverse);

            var detach = new MyTerminalControlButton <MyMotorStator>("Detach", MySpaceTexts.BlockActionTitle_Detach, MySpaceTexts.Blank, (b) => b.m_rotorBlockId.Value = new State()
            {
                OtherEntityId = null, MasterToSlave = null
            });

            detach.Enabled = (b) => b.m_rotorBlockId.Value.OtherEntityId.HasValue && b.m_isWelding == false && b.m_welded == false;
            detach.Visible = (b) => b.m_canBeDetached;
            var actionDetach = detach.EnableAction(MyTerminalActionIcons.NONE);

            actionDetach.Enabled = (b) => b.m_canBeDetached;
            MyTerminalControlFactory.AddControl(detach);

            var attach = new MyTerminalControlButton <MyMotorStator>("Attach", MySpaceTexts.BlockActionTitle_Attach, MySpaceTexts.Blank, (b) => b.m_rotorBlockId.Value = new State()
            {
                OtherEntityId = 0, MasterToSlave = null
            });

            attach.Enabled = (b) => !b.m_rotorBlockId.Value.OtherEntityId.HasValue;
            attach.Visible = (b) => b.m_canBeDetached;
            var actionAttach = attach.EnableAction(MyTerminalActionIcons.NONE);

            actionAttach.Enabled = (b) => b.m_canBeDetached;
            MyTerminalControlFactory.AddControl(attach);

            var torque = new MyTerminalControlSlider <MyMotorStator>("Torque", MySpaceTexts.BlockPropertyTitle_MotorTorque, MySpaceTexts.BlockPropertyDescription_MotorTorque);

            torque.Getter             = (x) => x.Torque;
            torque.Setter             = (x, v) => x.Torque.Value = v;
            torque.DefaultValueGetter = (x) => x.MotorDefinition.MaxForceMagnitude;
            torque.Writer             = (x, result) => MyValueFormatter.AppendTorqueInBestUnit(x.Torque, result);
            torque.EnableActions();
            torque.Denormalizer = (x, v) => x.DenormalizeTorque(v);
            torque.Normalizer   = (x, v) => x.NormalizeTorque(v);
            MyTerminalControlFactory.AddControl(torque);

            var brakingTorque = new MyTerminalControlSlider <MyMotorStator>("BrakingTorque", MySpaceTexts.BlockPropertyTitle_MotorBrakingTorque, MySpaceTexts.BlockPropertyDescription_MotorBrakingTorque);

            brakingTorque.Getter       = (x) => x.BrakingTorque;
            brakingTorque.Setter       = (x, v) => x.BrakingTorque.Value = v;
            brakingTorque.DefaultValue = 0;
            brakingTorque.Writer       = (x, result) => MyValueFormatter.AppendTorqueInBestUnit(x.BrakingTorque, result);
            brakingTorque.EnableActions();
            brakingTorque.Denormalizer = (x, v) => x.DenormalizeTorque(v);
            brakingTorque.Normalizer   = (x, v) => x.NormalizeTorque(v);
            MyTerminalControlFactory.AddControl(brakingTorque);

            var targetVelocity = new MyTerminalControlSlider <MyMotorStator>("Velocity", MySpaceTexts.BlockPropertyTitle_MotorTargetVelocity, MySpaceTexts.BlockPropertyDescription_MotorVelocity);

            targetVelocity.Getter       = (x) => x.TargetVelocityRPM;
            targetVelocity.Setter       = (x, v) => x.TargetVelocityRPM = v;
            targetVelocity.DefaultValue = 0;
            targetVelocity.Writer       = (x, result) => result.Concat(x.TargetVelocityRPM, 2).Append(" rpm");
            targetVelocity.EnableActionsWithReset();
            targetVelocity.Denormalizer = (x, v) => x.DenormalizeRPM(v);
            targetVelocity.Normalizer   = (x, v) => x.NormalizeRPM(v);
            MyTerminalControlFactory.AddControl(targetVelocity);

            var lowerLimit = new MyTerminalControlSlider <MyMotorStator>("LowerLimit", MySpaceTexts.BlockPropertyTitle_MotorMinAngle, MySpaceTexts.BlockPropertyDescription_MotorLowerLimit);

            lowerLimit.Getter       = (x) => x.MinAngle;
            lowerLimit.Setter       = (x, v) => x.MinAngle = v;
            lowerLimit.DefaultValue = -361;
            lowerLimit.SetLimits(-361, 360);
            lowerLimit.Writer = (x, result) => WriteAngle(x.m_minAngle, result);
            lowerLimit.EnableActions();
            MyTerminalControlFactory.AddControl(lowerLimit);

            var upperLimit = new MyTerminalControlSlider <MyMotorStator>("UpperLimit", MySpaceTexts.BlockPropertyTitle_MotorMaxAngle, MySpaceTexts.BlockPropertyDescription_MotorUpperLimit);

            upperLimit.Getter       = (x) => x.MaxAngle;
            upperLimit.Setter       = (x, v) => x.MaxAngle = v;
            upperLimit.DefaultValue = 361;
            upperLimit.SetLimits(-360, 361);
            upperLimit.Writer = (x, result) => WriteAngle(x.m_maxAngle, result);
            upperLimit.EnableActions();
            MyTerminalControlFactory.AddControl(upperLimit);

            var rotorDisplacement = new MyTerminalControlSlider <MyMotorStator>("Displacement", MySpaceTexts.BlockPropertyTitle_MotorRotorDisplacement, MySpaceTexts.BlockPropertyDescription_MotorRotorDisplacement);

            rotorDisplacement.Getter             = (x) => x.DummyDisplacement;
            rotorDisplacement.Setter             = (x, v) => x.DummyDisplacement = v;
            rotorDisplacement.DefaultValueGetter = (x) => 0.0f;
            rotorDisplacement.SetLimits((x) => x.MotorDefinition.RotorDisplacementMin, (x) => x.MotorDefinition.RotorDisplacementMax);
            rotorDisplacement.Writer  = (x, result) => MyValueFormatter.AppendDistanceInBestUnit(x.DummyDisplacement, result);
            rotorDisplacement.Enabled = (b) => b.m_isAttached;
            rotorDisplacement.EnableActions();
            MyTerminalControlFactory.AddControl(rotorDisplacement);

            var weldSpeed = new MyTerminalControlSlider <MyMotorStator>("Weld speed", MySpaceTexts.BlockPropertyTitle_WeldSpeed, MySpaceTexts.Blank);

            weldSpeed.SetLimits((block) => 0f, (block) => MyGridPhysics.SmallShipMaxLinearVelocity());
            weldSpeed.DefaultValueGetter = (block) => MyGridPhysics.LargeShipMaxLinearVelocity() - 5f;
            weldSpeed.Getter             = (x) => (float)Math.Sqrt(x.m_weldSpeedSq);
            weldSpeed.Setter             = (x, v) => x.m_weldSpeedSq.Value = v * v;
            weldSpeed.Writer             = (x, res) => res.AppendDecimal((float)Math.Sqrt(x.m_weldSpeedSq), 1).Append("m/s");
            weldSpeed.EnableActions();
            MyTerminalControlFactory.AddControl(weldSpeed);

            var weldForce = new MyTerminalControlCheckbox <MyMotorStator>("Force weld", MySpaceTexts.BlockPropertyTitle_WeldForce, MySpaceTexts.Blank);

            weldForce.Getter = (x) => x.m_forceWeld;
            weldForce.Setter = (x, v) => x.m_forceWeld.Value = v;
            weldForce.EnableAction();
            MyTerminalControlFactory.AddControl(weldForce);
        }
Ejemplo n.º 7
0
        protected override void UpdateThrusts(bool enableDampeners)
        {
            base.UpdateThrusts(enableDampeners);

            ProfilerShort.Begin("ThrusterBlockComponent.UpdateThrusts");
            if (CubeGrid != null && CubeGrid.Physics != null)
            {
                if (CubeGrid.Physics.Enabled)
                {
                    if (FinalThrust.LengthSquared() > 0.0001f)
                    {
                        var thrust = FinalThrust;
                        if (CubeGrid.Physics.IsWelded) //only reliable variant
                        {
                            thrust = Vector3.TransformNormal(thrust, CubeGrid.WorldMatrix);
                            thrust = Vector3.TransformNormal(thrust, Matrix.Invert(CubeGrid.Physics.RigidBody.GetRigidBodyMatrix()));
                        }

                        CubeGrid.Physics.AddForce(MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE, thrust, null, null);
                        m_index++;

                        Vector3 velocity = CubeGrid.Physics.LinearVelocity;
                        float   maxSpeed = CubeGrid.GridSizeEnum == MyCubeSize.Large ? MyGridPhysics.LargeShipMaxLinearVelocity() : MyGridPhysics.SmallShipMaxLinearVelocity();

                        if (velocity.LengthSquared() > maxSpeed * maxSpeed)
                        {
                            velocity.Normalize();
                            velocity *= maxSpeed;
                            CubeGrid.Physics.LinearVelocity = velocity;
                        }
                    }
                }
            }
            ProfilerShort.End();
        }
Ejemplo n.º 8
0
        static void CreateTerminalControls()
        {
            if (MyTerminalControlFactory.AreControlsCreated <MyPistonBase>())
            {
                return;
            }

            var reverse = new MyTerminalControlButton <MyPistonBase>("Reverse", MySpaceTexts.BlockActionTitle_Reverse, MySpaceTexts.Blank, (x) => x.Velocity.Value = -x.Velocity);

            reverse.EnableAction(MyTerminalActionIcons.REVERSE);
            MyTerminalControlFactory.AddControl(reverse);

            var extendAction = new MyTerminalAction <MyPistonBase>("Extend", MyTexts.Get(MySpaceTexts.BlockActionTitle_Extend), OnExtendApplied, null, MyTerminalActionIcons.REVERSE);

            extendAction.Enabled = (b) => b.IsFunctional == true;
            MyTerminalControlFactory.AddAction(extendAction);

            var retractAction = new MyTerminalAction <MyPistonBase>("Retract", MyTexts.Get(MySpaceTexts.BlockActionTitle_Retract), OnRetractApplied, null, MyTerminalActionIcons.REVERSE);

            retractAction.Enabled = (b) => b.IsFunctional == true;
            MyTerminalControlFactory.AddAction(retractAction);

            var velocity = new MyTerminalControlSlider <MyPistonBase>("Velocity", MySpaceTexts.BlockPropertyTitle_Velocity, MySpaceTexts.Blank);

            velocity.SetLimits((block) => - block.BlockDefinition.MaxVelocity, (block) => block.BlockDefinition.MaxVelocity);
            velocity.DefaultValue = -0.5f;
            velocity.Getter       = (x) => x.Velocity;
            velocity.Setter       = (x, v) => x.Velocity.Value = v;
            velocity.Writer       = (x, res) => res.AppendDecimal(x.Velocity, 1).Append("m/s");
            velocity.EnableActionsWithReset();
            MyTerminalControlFactory.AddControl(velocity);

            var maxDist = new MyTerminalControlSlider <MyPistonBase>("UpperLimit", MySpaceTexts.BlockPropertyTitle_MaximalDistance, MySpaceTexts.Blank);

            maxDist.SetLimits((block) => block.BlockDefinition.Minimum, (block) => block.BlockDefinition.Maximum);
            maxDist.DefaultValueGetter = (block) => block.BlockDefinition.Maximum;
            maxDist.Getter             = (x) => x.MaxLimit;
            maxDist.Setter             = (x, v) => x.MaxLimit.Value = v;
            maxDist.Writer             = (x, res) => res.AppendDecimal(x.MaxLimit, 1).Append("m");
            maxDist.EnableActions();
            MyTerminalControlFactory.AddControl(maxDist);

            var minDist = new MyTerminalControlSlider <MyPistonBase>("LowerLimit", MySpaceTexts.BlockPropertyTitle_MinimalDistance, MySpaceTexts.Blank);

            minDist.SetLimits((block) => block.BlockDefinition.Minimum, (block) => block.BlockDefinition.Maximum);
            minDist.DefaultValueGetter = (block) => block.BlockDefinition.Minimum;
            minDist.Getter             = (x) => x.MinLimit;
            minDist.Setter             = (x, v) => x.MinLimit.Value = v;
            minDist.Writer             = (x, res) => res.AppendDecimal(x.MinLimit, 1).Append("m");
            minDist.EnableActions();
            MyTerminalControlFactory.AddControl(minDist);

            var weldSpeed = new MyTerminalControlSlider <MyPistonBase>("Weld speed", MySpaceTexts.BlockPropertyTitle_WeldSpeed, MySpaceTexts.Blank);

            weldSpeed.SetLimits((block) => 0f, (block) => MyGridPhysics.SmallShipMaxLinearVelocity());
            weldSpeed.DefaultValueGetter = (block) => MyGridPhysics.LargeShipMaxLinearVelocity() - 5f;
            weldSpeed.Getter             = (x) => (float)Math.Sqrt(x.m_weldSpeedSq);
            weldSpeed.Setter             = (x, v) => x.m_weldSpeedSq.Value = v * v;
            weldSpeed.Writer             = (x, res) => res.AppendDecimal((float)Math.Sqrt(x.m_weldSpeedSq), 1).Append("m/s");
            weldSpeed.EnableActions();
            MyTerminalControlFactory.AddControl(weldSpeed);

            var weldForce = new MyTerminalControlCheckbox <MyPistonBase>("Force weld", MySpaceTexts.BlockPropertyTitle_WeldForce, MySpaceTexts.Blank);

            weldForce.Getter = (x) => x.m_forceWeld;
            weldForce.Setter = (x, v) => x.m_forceWeld.Value = v;
            weldForce.EnableAction();
            MyTerminalControlFactory.AddControl(weldForce);

            var addPistonHead = new MyTerminalControlButton <MyPistonBase>("Add Piston Head", MySpaceTexts.BlockActionTitle_AddPistonHead, MySpaceTexts.BlockActionTooltip_AddPistonHead, (b) => b.RecreateTop());

            addPistonHead.Enabled = (b) => (b.m_topBlock == null);
            addPistonHead.EnableAction(MyTerminalActionIcons.STATION_ON);
            MyTerminalControlFactory.AddControl(addPistonHead);
        }