コード例 #1
0
 public void ResetDriver(IMyMotorAdvancedStator driver)
 {
     driver.SetValue <float>("Displacement", restDisplacement);
 }
コード例 #2
0
        public void SetupMiner()
        {
            basePistons    = new List <IMyPistonBase>();
            forwardPistons = new List <IMyPistonBase>();
            downPistons    = new List <IMyPistonBase>();
            drills         = new List <IMyShipDrill>();
            cameras        = new List <IMyCameraBlock>();
            textPanels     = new List <IMyTextPanel>();

            IMyBlockGroup minerGroup = GridTerminalSystem.GetBlockGroupWithName(minerGroupName);

            if (minerGroup == null)
            {
                this.currentState = "stopped";
                Echo("Could not find group with name: " + minerGroupName);
                return;
            }

            minerGroup.GetBlocksOfType <IMyTextPanel>(textPanels);

            List <IMyMotorAdvancedStator> rotors = new List <IMyMotorAdvancedStator>();

            minerGroup.GetBlocksOfType <IMyMotorAdvancedStator>(rotors);
            if (rotors.Count == 0)
            {
                Echo("Could not find an advanced rotor!");
                this.currentState = "stopped";
                return;
            }
            rotor = rotors[0];

            List <IMyPistonBase> pistons = new List <IMyPistonBase>();

            minerGroup.GetBlocksOfType <IMyPistonBase>(pistons);

            Echo("Detected " + pistons.Count + " pistons");

            var UP       = Me.WorldMatrix.Up;
            var FORWARD  = Me.WorldMatrix.Forward;
            var DOWN     = Me.WorldMatrix.Down;
            var BACKWARD = Me.WorldMatrix.Backward;

            UP.Normalize();
            FORWARD.Normalize();
            DOWN.Normalize();
            BACKWARD.Normalize();

            foreach (IMyPistonBase piston in pistons)
            {
                piston.Velocity = 0.0f;
                Vector3D pbf = piston.Top.GetPosition() - piston.GetPosition();
                pbf.Normalize();
                double distanceup       = pbf.Dot(UP);
                double distancedown     = pbf.Dot(DOWN);
                double distanceforward  = pbf.Dot(FORWARD);
                double distancebackward = pbf.Dot(BACKWARD);

                double maxDir = Math.Max(Math.Max(Math.Max(distanceup, distancedown), distanceforward), distancebackward);

                if (distanceup == maxDir)
                {
                    basePistons.Add(piston);
                }
                else if (distanceforward == maxDir)
                {
                    piston.MaxLimit = piston.CurrentPosition;
                    forwardPistons.Add(piston);
                }
                else if (distancedown == maxDir)
                {
                    downPistons.Add(piston);
                }
            }

            minerGroup.GetBlocksOfType <IMyShipDrill>(drills);
            if (doRaycasting)
            {
                minerGroup.GetBlocksOfType <IMyCameraBlock>(cameras);
                foreach (IMyCameraBlock camera in cameras)
                {
                    camera.EnableRaycast = true;
                }
                Echo("Enabled raycasting");
            }



            // Set limits on the pistons
            float minLimitPerVertPiston = minVerticalAltitude / (basePistons.Count + downPistons.Count);

            foreach (var piston in basePistons)
            {
                piston.MinLimit = piston.LowestPosition;
                piston.MaxLimit = piston.HighestPosition - minLimitPerVertPiston;
                piston.SetValue <float>("MaxImpulseAxis", pistonMaxImpulseAxis);
                piston.SetValue <float>("MaxImpulseNonAxis", pistonMaxImpulseNonAxis);
                piston.SetValue <bool>("ShareInertiaTensor", true);
            }
            foreach (var piston in downPistons)
            {
                piston.MinLimit = minLimitPerVertPiston;
                piston.MaxLimit = piston.HighestPosition;
                piston.SetValue <float>("MaxImpulseAxis", pistonMaxImpulseAxis);
                piston.SetValue <float>("MaxImpulseNonAxis", pistonMaxImpulseNonAxis);
                piston.SetValue <bool>("ShareInertiaTensor", true);
            }

            foreach (var piston in forwardPistons)
            {
                piston.MinLimit = piston.LowestPosition;
                piston.MaxLimit = piston.HighestPosition;
                piston.SetValue <float>("MaxImpulseAxis", pistonMaxImpulseAxis);
                piston.SetValue <float>("MaxImpulseNonAxis", pistonMaxImpulseNonAxis);
                piston.SetValue <bool>("ShareInertiaTensor", true);
            }

            rotor.SetValue <bool>("ShareInertiaTensor", false);

            this.currentState = "ready";
        }
コード例 #3
0
 public void ExecuteDriver(IMyMotorAdvancedStator driver, float RotorDisplacement)
 {
     driver.SetValue <float>("Displacement", restDisplacement + RotorDisplacement);
 }