/// <summary>
        /// Checks if the terminal is null, gone from world, or broken off from grid.
        /// </summary>
        /// <param name="block">The block<see cref="T"/>.</param>
        /// <returns>The <see cref="bool"/>.</returns>
        bool IsCorrupt(IMyTerminalBlock block)
        {
            bool isCorrupt = block == null || block.WorldMatrix == MatrixD.Identity ||
                             !(GridTerminalSystem.GetBlockWithId(block.EntityId) == block);

            return(isCorrupt);
        }
Ejemplo n.º 2
0
 IMyCockpit GetCockPit()
 {
     if (cachedCockpit == null || GridTerminalSystem.GetBlockWithId(cachedCockpit.EntityId) == null)
     {
         GridTerminalSystem.GetBlocksOfType(cockpitList, x => x.IsSameConstructAs(Me));
         cachedCockpit = cockpitList.FirstOrDefault(x => cockpitName == null || x.CustomName == cockpitName);
     }
     return(cachedCockpit);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Runs a programmable block by its entity ID.
        /// </summary>
        /// <param name="entityId"></param>
        /// <param name="argument"></param>
        /// <param name="updateType"></param>
        public void Trigger(long entityId, string argument = null, UpdateType updateType = UpdateType.Trigger)
        {
            var pb = GridTerminalSystem.GetBlockWithId(entityId) as MockProgrammableBlock;

            if (pb == null)
            {
                throw new InvalidOperationException($"Cannot find a mocked programmable block with the ID {entityId}");
            }
            EnsureInit();
            RunProgrammableBlock(pb, argument, updateType);
        }
Ejemplo n.º 4
0
 void ConnectDisplay(long id, int subId)
 {
     try
     {
         var block = GridTerminalSystem.GetBlockWithId(id);
         if (block is IMyTextPanel)
         {
             displays.Add((IMyTextPanel)block);
         }
         else
         {
             surfaceProviders.Add(block);
             surfaceIndices.Add(subId);
         }
     }
     catch (Exception e)
     {
         setupBuilder.AppendLine(e.ToString());
     }
 }
Ejemplo n.º 5
0
        public Program()
        {
            string[] splitStorage;
            if (string.IsNullOrEmpty(Storage))
            {
                splitStorage = new[] { "", "90", "90" };
            }
            else
            {
                splitStorage = Storage.Split(';');
            }

            var cockpitId = splitStorage[0];

            _targetXAngle = float.Parse(splitStorage[1]);
            _targetYAngle = float.Parse(splitStorage[2]);

            IMyCockpit cockpit = null;

            if (!string.IsNullOrEmpty(cockpitId))
            {
                long id;
                long.TryParse(cockpitId, out id);
                cockpit = GridTerminalSystem.GetBlockWithId(id) as IMyCockpit;
                if (!cockpit.IsMainCockpit)
                {
                    cockpit = null;
                }
            }
            if (cockpit == null)
            {
                cockpit = GridTerminalSystem.GetMainCockpit();
            }
            _mainCockpit = cockpit;

            _hinges = GridTerminalSystem.GetBlockGroupWithName("ArmHinges").GetBlocksOfType <IMyMotorStator>();

            _rotors = GridTerminalSystem.GetBlockGroupWithName("ArmRotors").GetBlocksOfType <IMyMotorStator>();

            Runtime.UpdateFrequency = UpdateFrequency.Update1;
        }
        public void progressPanels()
        {
            while (Runtime.CurrentInstructionCount < LOAD_LIMIT && PanelQueue.Count > 0)
            {
                panelProgressCount++;
                long         panelId = PanelQueue.Dequeue().EntityId;
                IMyTextPanel Panel   = GridTerminalSystem.GetBlockWithId(panelId) as IMyTextPanel;

                IMyTerminalBlock Cargo = getCargo(Panel);
                if (Panel != null && Panel is IMyTextPanel && Cargo != null && Panel.IsFunctional && Panel.IsWorking)
                {
                    int    fillLevel0 = 0;
                    int    fillLevel1 = 0;
                    string fillBar    = getFillLevelBarForBlock(Cargo, out fillLevel0, out fillLevel1);
                    switch (Cargo.InventoryCount)
                    {
                    case 1:
                        Panel.CustomData = getText("lcdStatSingleInventory", Cargo.CustomName, DateTime.Now, fillLevel0);
                        Panel.WritePublicTitle(getText("lcdTitleStatSingle", fillLevel0, Cargo.CustomName));
                        break;

                    case 2:
                        Panel.CustomData = getText("lcdStatDoubleInventory", Cargo.CustomName, DateTime.Now, fillLevel0, fillLevel1);
                        Panel.WritePublicTitle(getText("lcdTitleStatDouble", fillLevel0, fillLevel1, Cargo.CustomName));
                        break;
                    }
                    Panel.WritePublicText(fillBar);
                    Panel.SetValueFloat("FontSize", fontSizeFuelBar);
                    Panel.SetValue <long>("Font", fontIdMonospaced);
                    Panel.ShowPublicTextOnScreen();
                }
                else
                {
                    Panel.WritePublicTitle("");
                    Panel.WritePublicText(getText("warnNoInventory"));
                    Panel.SetValueFloat("FontSize", fontSizeText);
                    Panel.SetValue <long>("Font", fontIdRed);
                    Panel.ShowPublicTextOnScreen();
                }
            }
        }
        public IMyTerminalBlock getCargo(IMyTextPanel Panel)
        {
            if (PanelToCargoMap.ContainsKey(Panel))
            {
                IMyTerminalBlock buffer = GridTerminalSystem.GetBlockWithId(PanelToCargoMap[Panel].EntityId);
                if (buffer != null && buffer is IMyButtonPanel)
                {
                    return(buffer as IMyButtonPanel);
                }
                else
                {
                    PanelToCargoMap.Remove(Panel);
                }
            }
            IMyTerminalBlock Cargo = getBlockBehind(Panel);

            if (Cargo != null && Cargo.HasInventory)
            {
                PanelToCargoMap.Add(Panel, Cargo);
                return(Cargo);
            }

            return(null);
        }
Ejemplo n.º 8
0
        public IMyButtonPanel getButtonPanel(IMyTextPanel Panel)
        {
            if (Cache.ContainsKey(Panel))
            {
                IMyTerminalBlock buffer = GridTerminalSystem.GetBlockWithId(Cache[Panel].EntityId);
                if (buffer != null && buffer is IMyButtonPanel)
                {
                    return(buffer as IMyButtonPanel);
                }
                else
                {
                    Cache.Remove(Panel);
                }
            }
            IMyButtonPanel ButtonPanel = findButtonPanelFromLCD(Panel);

            if (ButtonPanel != null && ButtonPanel is IMyButtonPanel)
            {
                Cache.Add(Panel, ButtonPanel);
                return(ButtonPanel);
            }

            return(null);
        }
Ejemplo n.º 9
0
        IEnumerable <int> DoorCloserLooper()
        {
            int thisIteration = ++numIteration;             // In case multiple calls to this `DoorCloserLooper` occurs, then only the "last one" should survive.

            var newDoors      = new List <IMyDoor>();
            var obsoleteDoors = new List <long>();
            var closingDoors  = new List <long>();

            while (thisIteration == numIteration)
            {
                GridTerminalSystem.GetBlocksOfType(newDoors, x => SameGrid(x, Me) & !NameContains(x, DoorsAutoClose_IgnoreBlocks));

                long nowTick     = DateTime.Now.Ticks;
                long closeAtTick = nowTick + TimeSpan.TicksPerSecond * DoorsAutoClose_SecondsToKeepOpen;

                foreach (var d in newDoors)
                {
                    if (d is IMyAirtightHangarDoor || !d.IsWorking)
                    {
                        continue;
                    }

                    switch (d.Status)
                    {
                    case DoorStatus.Open:
                    case DoorStatus.Opening:
                        if (!openDoors.ContainsKey(d.EntityId))
                        {
                            openDoors.Add(d.EntityId, closeAtTick);
                        }
                        break;
                    }
                }
                newDoors.Clear();

                var doorsToClose = new List <IMyTerminalBlock>();
                foreach (var d in openDoors)
                {
                    if (d.Value < nowTick)
                    {
                        var door = GridTerminalSystem.GetBlockWithId(d.Key);
                        if (null != door)
                        {
                            closingDoors.Add(d.Key);
                            doorsToClose.Add(door);
                        }
                        else
                        {
                            obsoleteDoors.Add(d.Key);
                        }
                    }
                }

                foreach (var k in obsoleteDoors)
                {
                    openDoors.Remove(k);
                }
                obsoleteDoors.Clear();

                foreach (var k in closingDoors)
                {
                    openDoors[k] = DateTime.MaxValue.Ticks;
                }
                closingDoors.Clear();

                if (0 < doorsToClose.Count)
                {
                    yieldMgr.Add(CloseDoors(doorsToClose));
                }

                yield return(1000);
            }
        }
Ejemplo n.º 10
0
 void SendData(long targetId, string data)
 {
     ((IMyProgrammableBlock)GridTerminalSystem.GetBlockWithId(targetId)).CustomData = data;
 }