public static void CreateSmallTop(IMyPistonBase block)
        {
            if (block.IsAttached || block.CurrentPosition < 0.3)
            {
                return;
            }

            MatrixD m;

            if (!GetTopMatrix(block, MyCubeSize.Small, out m))
            {
                return;
            }

            List <IMyCubeGrid> temp = new List <IMyCubeGrid>(2);
            string             name;

            if (MyAPIGateway.Session.CreativeMode)
            {
                name = "SmallPistonTop";
            }
            else
            {
                name = "SmallPistonTop2";
            }
            MyAPIGateway.PrefabManager.SpawnPrefab(temp, name, m.Translation, m.Forward, m.Up, ownerId: block.OwnerId, callback: () => OnSmallTopCreated(block, temp));
        }
Beispiel #2
0
        private bool ExtendPiston()
        {
            DrawText("Extend pistons...");

            bool bAllPistonsExtended = true;

            for (int nIndex = 0; nIndex < m_listPiston.Count; nIndex++)
            {
                IMyPistonBase piston = m_listPiston[nIndex];

                float distance = Math.Abs(piston.HighestPosition - piston.CurrentPosition);

                if (distance > 0.003)
                {
                    bAllPistonsExtended = false;

                    piston.Velocity = m_pistonExtendVelocity;

                    break;
                }
                else
                {
                    piston.Velocity = 0.0f;
                }
            }

            return(bAllPistonsExtended);
        }
    public void Init()
    {
        top_connector    = (IMyShipConnector)GridTerminalSystem.GetBlockWithName(TOP_CONNECTOR_NAME);
        middle_connector = (IMyShipConnector)GridTerminalSystem.GetBlockWithName(MIDDLE_CONNECTOR_NAME);
        bottom_connector = (IMyShipConnector)GridTerminalSystem.GetBlockWithName(BOTTOM_CONNECTOR_NAME);

        connectors = new Dictionary <string, IMyShipConnector> {
            { TOP_CONNECTOR_NAME, top_connector },
            { MIDDLE_CONNECTOR_NAME, middle_connector },
            { BOTTOM_CONNECTOR_NAME, bottom_connector }
        };

        top_piston    = (IMyPistonBase)GridTerminalSystem.GetBlockWithName(TOP_PISTON);
        bottom_piston = (IMyPistonBase)GridTerminalSystem.GetBlockWithName(BOTTOM_PISTON);

        programmable_block = (IMyProgrammableBlock)GridTerminalSystem.GetBlockWithName(PROGRAMMABLE_BLOCK_NAME);

        top_piston.MaxLimit    = PISTON_MAX_DISTANCE;
        top_piston.MinLimit    = PISTON_MIN_DISTANCE;
        bottom_piston.MaxLimit = PISTON_MAX_DISTANCE;
        bottom_piston.MinLimit = PISTON_MIN_DISTANCE;

        SetupDisplay();
        GetStatus();
        PrintStatus();
    }
            private bool RunPhaseExtendingPistons()
            {
                if (listPiston == null || listPiston.Count <= 0)
                {
                    return(true);
                }
                // Extends piston one by one
                IMyPistonBase currentPistonExtending = listPiston.Find(p => p.Status == PistonStatus.Extending);

                if (currentPistonExtending != null)
                {
                    // piston mining already extending
                    // do nothing
                    return(false);
                }

                foreach (IMyPistonBase p in listPiston)
                {
                    if (p.Status != PistonStatus.Extended)
                    {
                        // Extend one of the pistons not already extended
                        p.SetValue("Velocity", Params.PistonVitesseDescente);
                        return(false);
                    }
                }

                // Tous les pistons sont étendues
                return(true);
            }
        public Program()
        {
            Load();

            // Grinder Arm Blocks
            _grindArmRotor            = GetBlockOrThrow <IMyMotorStator>("Grinder Rotor");
            _grindArmHinge            = GetBlockOrThrow <IMyMotorStator>("Grinder Hinge");
            _grindArmPistonVert       = GetBlockOrThrow <IMyPistonBase>("Grinder Piston Vert");
            _grindArmPistonHoriz      = GetBlockOrThrow <IMyPistonBase>("Grinder Piston Horiz");
            _grindArmPistonPark       = GetBlockOrThrow <IMyPistonBase>("Grinder Park Piston");
            _grindArmLandingGearGroup = GetGroupOrThrow("Grinder Landing Gear");

            // Drill Blocks
            _drillPistonGroup       = GetGroupOrThrow("Drill Pistons");
            _drillGroup             = GetGroupOrThrow("Drills");
            _drillWelderGroup       = GetGroupOrThrow("Welders");
            _drillMergeBlock        = GetBlockOrThrow <IMyShipMergeBlock>("Drill Merge Block");
            _drillConnector         = GetBlockOrThrow <IMyShipConnector>("Drill Connector");
            _drillSupportMergeBlock = GetBlockOrThrow <IMyShipMergeBlock>("Support Merge Block");
            _drillProjector         = GetBlockOrThrow <IMyProjector>("Drill Projector");

            // LCD setup
            _lcd = GetBlockOrThrow <IMyTextPanel>("Drill Rig LCD");
            if (_lcd != null)
            {
                Echo("Found LCD");
                _lcd.ContentType = ContentType.TEXT_AND_IMAGE;
                _lcd.FontSize    = 0.5f;
                _lcd.FontColor   = new Color(200, 200, 200); // less bright white is also less blurry
                _lcd.Alignment   = TextAlignment.LEFT;
                _lcd.WriteText("Drill Rig Debug Logs");      // Clear all text
            }
        }
Beispiel #6
0
        public float getActualPistonExtend(List <IMyTerminalBlock> pistonList, bool extender)
        {
            float actualPistonExtend = 0f;

            if (!extender)
            {
                for (int i = 0; i < pistonList.Count; i++)
                {
                    IMyPistonBase pistonList_X = GridTerminalSystem.GetBlockWithName(pistonList[i].CustomName) as IMyPistonBase;
                    if (pistonList_X.CustomName.Contains(pistonNameTag) && !pistonList_X.CustomName.Contains("Extender"))
                    {
                        actualPistonExtend += pistonList_X.CurrentPosition;
                    }
                }
            }
            else
            {
                for (int i = 0; i < pistonList.Count; i++)
                {
                    IMyPistonBase pistonList_X = GridTerminalSystem.GetBlockWithName(pistonList[i].CustomName) as IMyPistonBase;
                    if (pistonList_X.CustomName.Contains(pistonNameTag) && pistonList_X.CustomName.Contains("Extender"))
                    {
                        actualPistonExtend += pistonList_X.CurrentPosition;
                    }
                }
            }
            return(actualPistonExtend);
        }
Beispiel #7
0
        public void workIsFinished(List <IMyTerminalBlock> drillList, List <IMyTerminalBlock> pistonList, List <IMyTerminalBlock> rotorList)
        {
            if (getActualPistonExtend(pistonList, false) == 0 && isExtended && finishedMining)
            {
                for (int i = 0; i < drillList.Count; i++)
                {
                    IMyShipDrill drillList_X = GridTerminalSystem.GetBlockWithName(drillList[i].CustomName) as IMyShipDrill;
                    if (drillList_X.CustomName.Contains(drillNameTag))
                    {
                        drillList_X.Enabled = false;
                    }
                }

                for (int i = 0; i < pistonList.Count; i++)
                {
                    IMyPistonBase pistonList_X = GridTerminalSystem.GetBlockWithName(pistonList[i].CustomName) as IMyPistonBase;
                    if (pistonList_X.CustomName.Contains(pistonNameTag) && !pistonList_X.CustomName.Contains("Extender"))
                    {
                        pistonList_X.Enabled = false;
                    }
                }

                for (int i = 0; i < rotorList.Count; i++)
                {
                    IMyMotorAdvancedStator rotorList_X = GridTerminalSystem.GetBlockWithName(rotorList[i].CustomName) as IMyMotorAdvancedStator;
                    if (rotorList_X.CustomName.Contains(rotorNameTag))
                    {
                        rotorList_X.Enabled = false;
                    }
                }
                Echo("Work is finished");
                workFinished = true;
            }
        }
Beispiel #8
0
 public void startMininingStage2(List <IMyTerminalBlock> drillList, List <IMyTerminalBlock> pistonList, List <IMyTerminalBlock> rotorList)
 {
     if (!workFinished && isMiningDown && finishedMining)
     {
         if (getActualPistonExtend(pistonList, false) == 0f)
         {
             for (int i = 0; i < pistonList.Count; i++)
             {
                 IMyPistonBase pistonList_X = GridTerminalSystem.GetBlockWithName(pistonList[i].CustomName) as IMyPistonBase;
                 if (pistonList_X.CustomName.Contains(pistonNameTag) && pistonList_X.CustomName.Contains("Extender"))
                 {
                     pistonList_X.SetValue("Velocity", 1f);
                     pistonList_X.Enabled = true;
                 }
             }
         }
         if (getActualPistonExtend(pistonList, true) == getMaxPistonExtend(pistonList, true))
         {
             isMiningDown   = false;
             finishedMining = false;
             startMining(drillList, pistonList, rotorList);
             isExtended = true;
         }
     }
 }
Beispiel #9
0
        private bool findPistons()
        {
            List <IMyPistonBase> allPistons = new List <IMyPistonBase>();
            bool ret = false;

            this.GridTerminalSystem.GetBlocksOfType <IMyPistonBase>(allPistons);

            if (allPistons == null || allPistons.Count == 0)
            {
                return(false);
            }

            foreach (IMyPistonBase piston in allPistons)
            {
                if (piston.CustomName.Contains("Flattener"))
                {
                    pistons.Add(piston);
                    Echo("Found piston " + piston.CustomName);

                    ret = true;
                    if (flattenerPistonPrime == null && piston.CustomName.Contains("Flattener Piston Prime"))
                    {
                        flattenerPistonPrime = piston;
                    }
                }
            }

            return(ret);
        }
        private static IMyPistonTop FindTop(IMyPistonBase block)
        {
            if (block.CubeGrid == null)
            {
                return(null);
            }

            MatrixD topMatrix;

            if (!GetTopMatrix(block, block.CubeGrid.GridSizeEnum, out topMatrix))
            {
                return(null);
            }

            Vector3D        pos  = topMatrix.Translation;
            BoundingSphereD area = new BoundingSphereD(pos, 1);

            foreach (IMyEntity e in MyAPIGateway.Entities.GetTopMostEntitiesInSphere(ref area))
            {
                IMyCubeGrid g = e as IMyCubeGrid;
                if (g != null)
                {
                    foreach (IMySlimBlock slim in g.GetBlocksInsideSphere(ref area))
                    {
                        IMyPistonTop top = slim.FatBlock as IMyPistonTop;
                        if (top != null && (top.Base == null || top.Base.Top == null) && TrySetDir(top, block, out top))
                        {
                            return(top);
                        }
                    }
                }
            }
            return(null);
        }
            public PistonController(Program parent, IMyPistonBase piston)
            {
                parent_ = parent;
                piston_ = piston;

                setup();
            }
Beispiel #12
0
        public Program()
        {
            rotor = (IMyMotorBase)GridTerminalSystem.GetBlockWithName("Advanced Rotor");

            pistons = GridTerminalSystem.GetBlockGroupWithName("Crane Pisonts");
            pistons.GetBlocksOfType <IMyPistonBase>(cranePistons);
            horizontal1 = (IMyPistonBase)GridTerminalSystem.GetBlockWithName("Piston Crane Horizontal 1");
            horizontal2 = (IMyPistonBase)GridTerminalSystem.GetBlockWithName("Piston Crane Horizontal 2");
            horizontal3 = (IMyPistonBase)GridTerminalSystem.GetBlockWithName("Piston Crane Horizontal 3");

            vertical1 = (IMyPistonBase)GridTerminalSystem.GetBlockWithName("Piston Crane Vertical 1");
            vertical2 = (IMyPistonBase)GridTerminalSystem.GetBlockWithName("Piston Crane Vertical 2");
            vertical3 = (IMyPistonBase)GridTerminalSystem.GetBlockWithName("Piston Crane Vertical 3");

            Echo("Status");
            Echo("-------------------------------------------");
            Echo("Rotor: " + (rotor == null ? "Not Available" : "Ok"));
            Echo("Crane Pistons: " + (pistons == null ? "Not Available" : "Ok") + " / " + (cranePistons == null ? "Not Available" : "Ok"));
            Echo(" - Horizontal 1: " + (horizontal1 == null ? "Not Available" : "Ok"));
            Echo(" - Horizontal 2: " + (horizontal2 == null ? "Not Available" : "Ok"));
            Echo(" - Horizontal 3: " + (horizontal3 == null ? "Not Available" : "Ok"));
            Echo(" - Vertical 1: " + (vertical1 == null ? "Not Available" : "Ok"));
            Echo(" - Vertical 2: " + (vertical2 == null ? "Not Available" : "Ok"));
            Echo(" - Vertical 3: " + (vertical3 == null ? "Not Available" : "Ok"));
        }
Beispiel #13
0
        bool CollectBlocks(IMyTerminalBlock block)
        {
            IMyShipDrill drill = block as IMyShipDrill;

            if (drill != null && drill.CustomName.Contains(config["Ship Tag"]))
            {
                drills.Add(drill);
                return(false);
            }

            IMyMotorStator rotor = block as IMyMotorStator;

            if (rotor != null)
            {
                string name = rotor.CustomName;
                if (!name.Contains(config["Ship Tag"]) || !name.Contains(config["Drill Tag"]))
                {
                    return(false);
                }
                else if (rotor.CustomName.Contains("Deploy Rotor 1"))
                {
                    deployRotor1 = rotor;
                }
                else if (rotor.CustomName.Contains("Deploy Rotor 2"))
                {
                    deployRotor2 = rotor;
                }
                else if (rotor.CustomName.Contains("Door Rotor L"))
                {
                    doorRotorL = rotor;
                }
                else if (rotor.CustomName.Contains("Door Rotor R"))
                {
                    doorRotorR = rotor;
                }
                else
                {
                    drillRotor = rotor;
                }
                return(false);
            }

            IMyPistonBase piston = block as IMyPistonBase;

            if (piston != null && piston.CustomName.Contains(config["Ship Tag"] + config["Drill Tag"]))
            {
                pistons.Add(piston);
                return(false);
            }

            /*
             * IMyProgrammableBlock prog = block as IMyProgrammableBlock;
             * if (prog != null && prog.CustomName.Contains(config["Ship Tag"] + config["Drill Tag"]))
             * {
             *      drillProg = prog;
             *      return false;
             * }
             */
            return(false);
        }
Beispiel #14
0
        private void PistonControl(string switchName, string displayNum, string pistonName, string action)
        {
            IMyButtonPanel panel   = (IMyButtonPanel)GridTerminalSystem.GetBlockWithName(switchName);
            IMyTextSurface surface = ((IMyTextSurfaceProvider)panel).GetSurface(Int32.Parse(displayNum));
            IMyPistonBase  piston  = (IMyPistonBase)GridTerminalSystem.GetBlockWithName(pistonName);

            if (action == "On/Off")
            {
                bool pistonEnabled = piston.Enabled;
                if (pistonEnabled)
                {
                    surface.BackgroundColor = Color.Red;
                }
                else
                {
                    surface.BackgroundColor = Color.Green;
                }
                piston.Enabled = !pistonEnabled;
            }
            if (action == "Reverse")
            {
                piston.Reverse();
                if (piston.Velocity < 0)
                {
                    surface.BackgroundColor = Color.Red;
                }
                else
                {
                    surface.BackgroundColor = Color.Green;
                }
            }
        }
            private bool RunPhaseExtendingPistonMiningDirection()
            {
                SetLightRunning();
                if (listPistonMDir == null || listPistonMDir.Count <= 0)
                {
                    return(true);
                }
                SetDrillsOnOff(true);
                // looking for extending piston
                IMyPistonBase currentPistonExtending = listPistonMDir.Find(p => p.Status == PistonStatus.Extending);

                if (currentPistonExtending != null)
                {
                    // piston mining already extending
                    // do nothing
                    return(false);
                }

                foreach (IMyPistonBase p in listPistonMDir)
                {
                    if (p.Status != PistonStatus.Extended)
                    {
                        // Extend one of the pistons not already extended
                        p.SetValue("Velocity", Params.SlowPistonVelocity);
                        return(false);
                    }
                }

                return(true);
            }
 public static void Detach(IMyPistonBase block)
 {
     if (block.IsAttached)
     {
         block.Detach();
     }
 }
Beispiel #17
0
        public List <IMyPistonBase> GetNextPistonInHierarchy(List <IMyPistonBase> tree, List <IMyPistonBase> allPistons)
        {
            IEnumerable <IMyPistonBase> nextPistons    = allPistons.Where(p => p.TopGrid.EntityId == tree[0].CubeGrid.EntityId);
            IEnumerable <IMyPistonBase> siblingPistons = allPistons.Where(p => p.CubeGrid.EntityId == tree[0].CubeGrid.EntityId && p.EntityId != tree[0].EntityId);

            Echo($"Finding Next Piston");

            if (nextPistons.Count() == 0)
            {
                Echo("No More pistons found");
                return(tree);
            }
            // this one has a landing gear piston on it
            else if (siblingPistons.Count() == 1)
            {
                IEnumerable <IMyPistonBase> pistons = nextPistons.Concat(siblingPistons);
                IMyPistonBase  landingGearPiston    = landingGearGridIds.Contains(pistons.ElementAt(0).TopGrid.EntityId) ? pistons.ElementAt(0) : pistons.ElementAt(1);
                IMyPistonBase  drillPiston          = landingGearPiston == pistons.ElementAt(0) ? pistons.ElementAt(1) : pistons.ElementAt(0);
                IMyLandingGear landingGear          = ALL_LANDING_GEAR.Find(l => l.CubeGrid.EntityId == landingGearPiston.TopGrid.EntityId);
                tree.Insert(0, drillPiston);
                LANDING_GEAR_PISTONS_BY_DRILL_PISTON.Add(drillPiston, landingGearPiston);
                PISTONS_BY_LANDING_GEAR.Add(landingGear, landingGearPiston);
                return(GetNextPistonInHierarchy(tree, allPistons));
            }
            else
            {
                tree.Insert(0, nextPistons.ElementAt(0));
                return(GetNextPistonInHierarchy(tree, allPistons));
            }
        }
        private static MyCubeBlockDefinition GetTopDef(IMyPistonBase block, MyCubeSize size)
        {
            MyPistonBaseDefinition     myDef    = (MyPistonBaseDefinition)((MyCubeBlock)block).BlockDefinition;
            MyCubeBlockDefinitionGroup defGroup = MyDefinitionManager.Static.TryGetDefinitionGroup(myDef.TopPart);

            return(defGroup[size]);
        }
Beispiel #19
0
 public void AddPiston(IMyPistonBase piston)
 {
     if (m_pistons.Contains(piston) == false)
     {
         m_pistons.Add(piston);
     }
 }
 private static void FinalizeAttach(IMyPistonBase block)
 {
     if (!block.IsAttached)
     {
         block.Detach();
     }
 }
 public void AddPart(IMyTerminalBlock part)
 {
     if (part is IMyShipConnector)
     {
         connector = (IMyShipConnector)part;
     }
     if (part is IMyPistonBase)
     {
         extender = (IMyPistonBase)part;
     }
     if (part is IMyMotorAdvancedStator)
     {
         rotor = (IMyMotorAdvancedStator)part;
     }
     if (part is IMyAirtightHangarDoor)
     {
         gates.Add((IMyAirtightHangarDoor)part);
     }
     if (part is IMyTextPanel)
     {
         display = (IMyTextPanel)part;
     }
     if (part is IMyInteriorLight)
     {
         IMyInteriorLight light = (IMyInteriorLight)part;
         lights.Add(light);
         light.Intensity = 2f;
         light.Radius    = 12f;
     }
 }
Beispiel #22
0
        //------------------------------------------------------------------------
        // Blocks
        //------------------------------------------------------------------------

        private bool RetractPiston()
        {
            DrawText("Retracting pistons...");

            bool bAllPistonsRetracted = true;

            for (int nIndex = 0; nIndex < m_listPiston.Count; nIndex++)
            {
                IMyPistonBase piston = m_listPiston[nIndex];

                float distance = Math.Abs(piston.LowestPosition - piston.CurrentPosition);

                if (distance > 0.003)
                {
                    bAllPistonsRetracted = false;

                    piston.Velocity = m_pistonRetractVelocity;
                }
                else
                {
                    piston.Velocity = 0.0f;
                }
            }

            return(bAllPistonsRetracted);
        }
Beispiel #23
0
            public PistonAndLandingGearExtendAndLock(IMyPistonBase piston, IMyLandingGear landingGear, IMyPistonBase supportPiston = null)
            {
                this.piston        = piston;
                this.supportPiston = supportPiston;
                this.landingGear   = landingGear;

                this.StartMovement();
            }
Beispiel #24
0
            private IMyGridTerminalSystem gts; //needed only because keen messed up in IMyShipMergeBlock.IsConnected()

            public PistonAndMergeBlockExtendAndMerge(IMyPistonBase piston, IMyShipMergeBlock mergeBlock, IMyGridTerminalSystem gts)
            {
                this.piston     = piston;
                this.mergeBlock = mergeBlock;
                this.gts        = gts;

                this.StartMovement();
            }
Beispiel #25
0
            public PistonMoveFull(IMyPistonBase piston, bool extend, IMyPistonBase supportPiston = null)
            {
                this.piston        = piston;
                this.supportPiston = supportPiston;
                this.extend        = extend;

                this.StartMovement();
            }
Beispiel #26
0
        public List <IMyPistonBase> GetPistonTree(IMyPistonBase basePiston, List <IMyPistonBase> allPistons)
        {
            List <IMyPistonBase> tree = new List <IMyPistonBase>();

            tree.Add(basePiston);
            GetNextPistonInHierarchy(tree, allPistons);
            return(tree);
        }
Beispiel #27
0
        public Program()
        {
            drill  = GridTerminalSystem.GetBlockWithName(drill_name) as IMyShipDrill;
            piston = GridTerminalSystem.GetBlockWithName(piston_name) as IMyPistonBase;

            broadcast_listener = IGC.RegisterBroadcastListener(broadcast_tag);
            broadcast_listener.SetMessageCallback(broadcast_tag);
        }
Beispiel #28
0
 private void initiateExtendingState()
 {
     activePiston          = getFirstUnmaxedPiston();
     activePiston.Enabled  = true;
     activePiston.Velocity = 0.1f;
     startingExtension     = getPistonExtension();
     state = FlatteningState.Extending;
 }
Beispiel #29
0
 public Piston(IMyPistonBase piston, bool isNegative)
 {
     piston.Enabled  = true;
     piston.Velocity = 0;
     piston.MinLimit = 0;
     piston.MaxLimit = 10 - (OFFSET * 2);
     this.piston     = piston;
     this.isNegative = isNegative;
 }
Beispiel #30
0
        private void StopPiston()
        {
            for (int nIndex = 0; nIndex < m_listPiston.Count; nIndex++)
            {
                IMyPistonBase piston = m_listPiston[nIndex];

                piston.Velocity = 0.0f;
            }
        }