public static void PreviewSelectedGrid(IMyTerminalBlock block)
        {
            m_block = block as IMyProjector;
            IMyProjector a = block as IMyProjector;



            a.SetProjectedGrid(null);

            if (SelectedGrid != null)
            {
                if (SelectedGrid.GridDefinition == null)
                {
                    MyLog.Default.WriteLineAndConsole("Grid needs to be re-sent to market! Ask admins to delete the market.json!");
                    return;
                }

                MyObjectBuilder_CubeGrid CubeGrid = MyAPIGateway.Utilities.SerializeFromBinary <MyObjectBuilder_CubeGrid>(SelectedGrid.GridDefinition);
                if (CubeGrid == null)
                {
                    MyLog.Default.WriteLineAndConsole("No Blueprints In file");

                    //No Blueprints in file!
                    return;
                }


                a.SetProjectedGrid(CubeGrid);
            }
            else
            {
                MyLog.Default.WriteLineAndConsole("Unable to preview grid");
            }
        }
        private static IEnumerable <IMySlimBlock> IterBuildableBlocksMgp(IMyProjector projector)
        {
            var blockStates  = new Dictionary <Vector3I, BlockState>();
            var subgridCount = MgpAgent.GetSubgridCount(projector.EntityId);

            for (var subgridIndex = 0; subgridIndex < subgridCount; subgridIndex++)
            {
                var previewGrid = MgpAgent.GetPreviewGrid(projector.EntityId, subgridIndex);
                if (previewGrid == null)
                {
                    continue;
                }

                if (!MgpAgent.GetBlockStates(blockStates, projector.EntityId, subgridIndex, UnlimitedBoundingBoxI, ConstructionBlockStateMask))
                {
                    continue;
                }

                foreach (var blockPosition in blockStates.Keys)
                {
                    var block = previewGrid.GetCubeBlock(blockPosition);
                    if (block == null)
                    {
                        continue;
                    }

                    yield return(block);
                }

                blockStates.Clear();
            }
        }
Beispiel #3
0
        public void Main(string argument)
        {
            IMyProjector projector = GridTerminalSystem.GetBlockWithName("Projector") as IMyProjector;

            var blocks = projector.RemainingBlocksPerType;

            char[] delimiters = new char[] { ',' };
            char[] remove     = new char[] { '[', ']' };
            Dictionary <string, int> totalComponents = new Dictionary <string, int>();

            foreach (var item in blocks)
            {
                // blockInfo[0] is blueprint, blockInfo[1] is number of required item
                string[] blockInfo = item.ToString().Trim(remove).Split(delimiters, StringSplitOptions.None);

                string blockName = blockInfo[0];
                int    amount    = Convert.ToInt32(blockInfo[1]);

                addComponents(totalComponents, getComponents(blockName), amount);
            }
            string output = "";

            foreach (KeyValuePair <string, int> component in totalComponents)
            {
                output += component.Key.Replace("MyObjectBuilder_BlueprintDefinition/", "") + " " + component.Value.ToString() + "\n";
            }
            Me.CustomData = output;
        }
 public ProjectionController(GridProgramRef gridProgramRef, string projectorName, ProjectorState projectorState)
 {
     if (gridProgramRef.GridTerminalSystem == null)
     {
         throw new ArgumentNullException("Passed GTS reference was null.");
     }
     if (gridProgramRef.Echo == null)
     {
         throw new ArgumentNullException("Passed Echo reference was null.");
     }
     if (gridProgramRef.Utils == null)
     {
         throw new ArgumentNullException("Passed UtilsClass reference was null.");
     }
     if (projectorName == null)
     {
         throw new ArgumentNullException("projectorName was null.");
     }
     if (!gridProgramRef.Utils.BlockWithNameExists(projectorName))
     {
         throw new ArgumentNullException("Projector was not found.");
     }
     Projector          = gridProgramRef.GridTerminalSystem.GetBlockWithName(projectorName) as IMyProjector;
     GridProgram        = gridProgramRef;
     ProjectorName      = projectorName;
     ProjectorState     = projectorState;
     GridTerminalSystem = GridProgram.GridTerminalSystem;
     Safeguard_Check();
 }
        private void CheckBlockProjection(IMySlimBlock item)
        {
            if (item.FatBlock == null)
            {
                return;
            }

            if (!(item.FatBlock is IMyProjector))
            {
                return;
            }

            IMyProjector projector = item.FatBlock as IMyProjector;

            if (!projector.Enabled)
            {
                return;
            }

            if (projector.ProjectedGrid == null)
            {
                return;
            }

            //Logging.Instance.WriteLine(string.Format("Projector: {0} - BuildableBlocksCount: {1}", projector.CustomName, projector.BuildableBlocksCount));
            if (projector.BuildableBlocksCount > 0)
            {
                ProcessProjector(projector);
            }
        }
        public void CycleShips()
        {
            if (CycleEnabled)
            {
                if (CycleTicksCurrent > 0)
                {
                    CycleTicksCurrent -= 10;
                    Echo(CycleTicksCurrent.ToString());
                    Echo(_CycleCurrentIndex.ToString());
                    Echo(_CurrentProjector.DisplayNameText);
                }
                else
                {
                    CycleTicksCurrent = CycleTicks;
                    if (_CurrentProjector != null)
                    {
                        _CurrentProjector.Enabled = false;
                    }
                    _CurrentProjector         = _Projectors[_CycleCurrentIndex];
                    _CurrentProjector.Enabled = true;
                    _CycleCurrentIndex       += 1;
                    if (_CycleCurrentIndex > _Projectors.Count - 1)
                    {
                        _CycleCurrentIndex = 0;
                    }

                    UpdateLCD();
                }
            }
        }
        public GridComponents(IMyProjector p)
        {
            if (p.ProjectedGrid != null)
            {
                Dictionary <MyDefinitionId, int> ids = new Dictionary <MyDefinitionId, int>();
                MyObjectBuilder_Projector        ob  = (MyObjectBuilder_Projector)p.GetObjectBuilderCubeBlock(true);
                foreach (MyObjectBuilder_CubeGrid grid in ob.ProjectedGrids)
                {
                    foreach (MyObjectBuilder_CubeBlock block in grid.CubeBlocks)
                    {
                        int            num;
                        MyDefinitionId id = block.GetId();
                        if (ids.TryGetValue(id, out num))
                        {
                            ids[id] = num + 1;
                        }
                        else
                        {
                            ids[id] = 1;
                        }
                    }
                }

                foreach (KeyValuePair <MyDefinitionId, int> kv in ids)
                {
                    MyCubeBlockDefinition def = MyDefinitionManager.Static.GetCubeBlockDefinition(kv.Key);
                    if (def != null)
                    {
                        IncludeCount(def, kv.Value);
                    }
                }
            }
        }
        bool CollectAllPartsLandpedo(IMyTerminalBlock block)
        {
            if (block == Me)
            {
                return(false);
            }
            if (!Me.IsSameConstructAs(block))
            {
                return(false);
            }
            if (block is IMyProgrammableBlock)
            {
                return(false);
            }
            if (block is IMyShipMergeBlock)
            {
                Base = (IMyShipMergeBlock)block;
            }
            if (block is IMyProjector)
            {
                Projector = (IMyProjector)block;
            }
            if (block is IMyShipConnector)
            {
                Connector = (IMyShipConnector)block;
            }

            PartsOfInterest.Add(block);

            return(false);
        }
        /// <summary>
        /// Is the block a projected block
        /// </summary>
        public static bool IsProjected(this IMySlimBlock target, out IMyProjector projector)
        {
            var cubeGrid = target.CubeGrid as MyCubeGrid;

            projector = cubeGrid != null ? cubeGrid.Projector : null;
            return(projector != null);
        }
        private static void GetItemList(IMyTerminalBlock block, List <MyTerminalControlListBoxItem> items, List <MyTerminalControlListBoxItem> selected)
        {
            IMyProjector me = (IMyProjector)block;

            if (me.ProjectedGrid != null)
            {
                StringBuilder  sb    = new StringBuilder();
                GridComponents comps = block.GameLogic.GetAs <InstantProjector>().GetComponents();
                foreach (KeyValuePair <MyDefinitionId, int> kv in comps)
                {
                    if (IPSession.Instance != null)
                    {
                        sb.Append(IPSession.Instance.GetComponentName(kv.Key));
                    }
                    else
                    {
                        sb.Append(kv.Key.SubtypeName);
                    }
                    sb.Append(": ").Append(kv.Value);
                    MyStringId s = MyStringId.GetOrCompute(sb.ToString());
                    MyTerminalControlListBoxItem item = new MyTerminalControlListBoxItem(s, s, 0);
                    items.Add(item);
                    sb.Clear();
                }
            }
        }
        public static bool TryGetSubgridIndex(IMyProjector projector, IMySlimBlock block, out int subgridIndex)
        {
            var blockGrid = block.CubeGrid;

            if (blockGrid == null || projector.ProjectedGrid == null)
            {
                subgridIndex = 0;
                return(false);
            }

            if (!MgpAgent.Available)
            {
                subgridIndex = 0;
                return(blockGrid == projector.ProjectedGrid);
            }

            var subgridCount = MgpAgent.GetSubgridCount(projector.EntityId);

            for (subgridIndex = 0; subgridIndex < subgridCount; subgridIndex++)
            {
                var previewGrid = MgpAgent.GetPreviewGrid(projector.EntityId, subgridIndex);
                if (previewGrid == blockGrid)
                {
                    return(true);
                }
            }

            subgridIndex = 0;
            return(false);
        }
        Dictionary <string, int> GetBlocksForQueue(IMyProjector projector, bool allBlocks)
        {
            var resultDictionary = new Dictionary <string, int>();
            var projectedGrid    = projector.ProjectedGrid;
            var blockList        = new List <IMySlimBlock>();

            projectedGrid.GetBlocks(blockList);

            foreach (var block in blockList)
            {
                var blockDefininition = block.BlockDefinition as MyCubeBlockDefinition;
                var blockcomponents   = blockDefininition.Components;

                if (allBlocks == false && projector.CanBuild(block, true) == BuildCheckResult.AlreadyBuilt)
                {
                    continue;
                }

                foreach (var component in blockcomponents)
                {
                    if (resultDictionary.ContainsKey(component.Definition.Id.SubtypeName) == true)
                    {
                        resultDictionary[component.Definition.Id.SubtypeName] += component.Count;
                    }
                    else
                    {
                        resultDictionary.Add(component.Definition.Id.SubtypeName, component.Count);
                    }
                }
            }

            return(resultDictionary);
        }
        private bool BuildTarget(BlockTarget target, ShipyardItem item, IMyCubeBlock tool)
        {
            IMyProjector projector = target.Projector;
            IMySlimBlock block     = target.Block;

            if (projector == null || block == null)
            {
                return(false);
            }

            if (projector.CanBuild(block, false) != BuildCheckResult.OK)
            {
                return(false);
            }

            if (MyAPIGateway.Session.CreativeMode)
            {
                projector.Build(block, 0, tool.EntityId, false);
                return(projector.CanBuild(block, true) != BuildCheckResult.OK);
            }

            //try to remove the first component from inventory
            string name = ((MyCubeBlockDefinition)block.BlockDefinition).Components[0].Definition.Id.SubtypeName;

            if (_tmpInventory.PullAny(item.ConnectedCargo, name, 2))
            {
                _tmpInventory.Clear();
                projector.Build(block, 0, tool.EntityId, false);
                return(projector.CanBuild(block, true) != BuildCheckResult.OK);
            }

            return(false);
        }
        void ProcessProjection(IMyAssembler assembler, IMyProjector projector, bool allBlocks)
        {
            var queueDictionary = GetBlocksForQueue(projector, allBlocks);

            if (allBlocks == false)
            {
                var existingParts = GetExistingParts(assembler);

                foreach (var component in existingParts.Keys.Where(component => queueDictionary.ContainsKey(component)))
                {
                    if (existingParts[component] >= queueDictionary[component])
                    {
                        queueDictionary[component] = 0;
                    }
                    else
                    {
                        queueDictionary[component] -= existingParts[component];
                    }
                }
            }

            foreach (var component in queueDictionary.Keys.Where(component => blueprintDictionary.ContainsKey(component)))
            {
                var blueprint  = new MyDefinitionId();
                var definition = $"MyObjectBuilder_BlueprintDefinition/{blueprintDictionary[component]}";

                if (MyDefinitionId.TryParse(definition, out blueprint) && assembler.CanUseBlueprint(blueprint))
                {
                    assembler.AddQueueItem(blueprint, (MyFixedPoint)queueDictionary[component]);
                }
            }
        }
Beispiel #15
0
            public void ProjectorProp(int propId, int propVal)
            {
                if (0 == propId)
                {
                    projector = NextBlockInGrid(Pgm, Me, projector, propVal);
                    return;
                }
                if (null == projector)
                {
                    return;
                }

                switch (propId)
                {
                case 1:
                case 2:
                case 3:
                    projector.ProjectionOffset = UpdDim(projector.ProjectionOffset, propId, propVal, (v, d) => { return(MathHelper.Clamp(v + d, -50, 50)); });
                    projector.UpdateOffsetAndRotation();
                    break;

                case 4:
                case 5:
                case 6:
                    projector.ProjectionRotation = UpdDim(projector.ProjectionRotation, propId - 3, propVal, (v, d) => { return(((v + 4) + d) % 4); });
                    projector.UpdateOffsetAndRotation();
                    break;
                }
            }
        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 #17
0
        private void InitializeVariables()
        {
            setupScreen    = GridTerminalSystem.GetBlockWithName(setupScreenName) as IMyTextPanel;
            mineralsScreen = GridTerminalSystem.GetBlockWithName(mineralsScreenName) as IMyTextPanel;
            gasInfoScreen  = GridTerminalSystem.GetBlockWithName(gasInfoScreenName) as IMyTextPanel;

            componentsScreens = new List <IMyTextPanel>();
            componentsScreens.Add(GridTerminalSystem.GetBlockWithName(componentsScreen1Name) as IMyTextPanel);
            componentsScreens.Add(GridTerminalSystem.GetBlockWithName(componentsScreen2Name) as IMyTextPanel);

            projectorInfoScreens = new List <IMyTextPanel>();
            projectorInfoScreens.Add(GridTerminalSystem.GetBlockWithName(projectionInfoScreenName1) as IMyTextPanel);
            projectorInfoScreens.Add(GridTerminalSystem.GetBlockWithName(projectionInfoScreenName2) as IMyTextPanel);

            componentDic = new Dictionary <string, Component>();
            mineralDic   = new Dictionary <string, Mineral>();

            projector  = GridTerminalSystem.GetBlockWithName(projectorName) as IMyProjector;
            assemblers = new List <IMyAssembler>();

            outTextMinerals       = new System.Text.StringBuilder();
            outTextComponents     = new System.Text.StringBuilder();
            outTextGasInfo        = new System.Text.StringBuilder();
            outTextProjectiorInfo = new System.Text.StringBuilder();

            mineralList   = new List <Mineral>();
            componentList = new List <Component>();
        }
 private static float GetScale(IMyProjector p)
 {
     if (p.BlockDefinition.SubtypeId != "LargeBlockConsole")
     {
         return(1);
     }
     return(p.GetValueFloat("Scale"));
 }
Beispiel #19
0
    public void replicate()
    {
        if (this.battery < 5)
        {
            return; // Solar cells need to recharge.
        }
        IMyProjector   myProjector = this.myProjector;
        IMyShipGrinder grinder     = this.getGrinder();

        if (grinder != null)
        {
            if (myProjector != null)
            {
                if (this.grinderStart != 0 && Communication.getTimestamp() - this.grinderStart > 30)
                {
                    this.grinderStart = 0;
                    grinder.Enabled   = false;
                }

                if (this.replicatingInProgress == true)   // Acceptable loss
                {
                    if (myProjector.RemainingBlocks == myProjector.RemainingArmorBlocks)
                    {
                        // Turn on other drone logic block.
                        this.turnOnDrones();
                        // Cut it free
                        grinder.Enabled   = true; // release the new ship.
                        this.grinderStart = Communication.getTimestamp();
                        this.commHandle.sendMasterFinishedSignal(this.id);
                        this.replicatingInProgress = false;
                        this.status = "finishing-replication";
                        // @TODO: switch to another projector?
                    }
                    else
                    {
                        this.status = "non-armor-blocks-remainig";
                    }
                }
                else
                {
                    this.replicatingInProgress = true;
                    this.status         = "replicating";
                    grinder.Enabled     = false;
                    myProjector.Enabled = true;
                }
            }
            else
            {
                grinder.Enabled = false;
                this.status     = "missing-projector";
            }
        }
        else
        {
            this.status = "unable-to-replicate";
        }
    }
        public Program()
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update100;

            List <IMyProjector> li = new List <IMyProjector>();

            GridTerminalSystem.GetBlocksOfType <IMyProjector>(li, b => b.CubeGrid == Me.CubeGrid);
            this.projector = li[0];
        }
Beispiel #21
0
        public override void Init(VRage.ObjectBuilders.MyObjectBuilder_EntityBase objectBuilder)
        {
            _objectBuilder = objectBuilder;
            projector      = (Entity as IMyProjector);

            if (projector != null && projector.BlockDefinition.ToString().Contains("projector"))
            {
                Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;
            }
        }
Beispiel #22
0
 private void ProcessProjector(IMyProjector projector)
 {
     foreach (IMySlimBlock block in ProjectorIntegration.IterBuildableBlocks(projector))
     {
         if (!PotentialTargetList.Contains(block))
         {
             PotentialTargetList.Add(block);
         }
     }
 }
        private void Exec_Setup()
        {
            _projector = GetBlocksOfTypeWithName <IMyProjector>("_MTB").FirstOrDefault();
            _timer     = GetBlocksOfTypeWithName <IMyTimerBlock>("_MTB").FirstOrDefault();
            _welders   = GetBlocksOfTypeWithName <IMyShipWelder>("_MTB");
            _cutters   = GetBlocksOfTypeWithName <IMyThrust>("_MTB");
            _torpDock  = GetBlocksOfTypeWithName <IMyShipConnector>("_MTB").FirstOrDefault();
            _piston    = GetBlocksOfTypeWithName <IMyPistonBase>("_MTB").FirstOrDefault();

            EchoText(
                "==SETUP== \n" +
                "\n" +
                "Projector: " + ((_projector != null) ? "Ok ✅" : "Not found") + "\n" +
                "Timer: " + ((_timer != null) ? "Ok ✅" : "Not found") + "\n" +
                "Welders: " + ((_welders != null) ? (_welders.Count > 0) ? "Ok ✅" : "Not found" : "Not found") + " (" + _cutters.Count + ")" + "\n" +
                "Torpedo Dock: " + ((_torpDock != null) ? "Ok ✅" : "Not found") + "\n" +
                "Piston: " + ((_piston != null) ? "Ok ✅" : "Not found") + "\n" +
                "Cutters: " + ((_cutters != null) ? (_cutters.Count > 0) ? "Ok ✅" : "Not found" : "Not found") + " (" + _cutters.Count + ")"
                );

            if (_projector == null || _timer == null || _welders == null || _cutters == null || _torpDock == null)
            {
                return;
            }

            if (_cutters.Count == 0)
            {
                return;
            }

            _shipTag = ParseTag(_torpDock.CubeGrid.CustomName);

            _projector.CustomName = _shipTag + "_MTB_" + "Projector";
            _timer.CustomName     = _shipTag + "_MTB_" + "Timer"; //..setup timer actions automatically?
            _torpDock.CustomName  = _shipTag + "_MTB_" + "TorpedoDock";
            _piston.CustomName    = _shipTag + "_MTB_" + "Piston";

            //..name the welders
            for (int i = 0; i < _welders.Count; ++i)
            {
                IMyShipWelder w = _welders[i];
                w.Enabled    = false;
                w.CustomName = _shipTag + "_MTB_" + "Welder_" + (i + 1);
            }

            //..make sure all the cutters are off to begin with
            for (int i = 0; i < _cutters.Count; ++i)
            {
                IMyThrust t = _cutters[i];

                t.ThrustOverridePercentage = 1;
                t.Enabled    = false;
                t.CustomName = _shipTag + "_MTB_" + "Cutter_" + (i + 1);
            }
        }
Beispiel #24
0
        private List <KeyValuePair <string, int> > GetTotalComponents(IMyProjector projector)
        {
            var blocks = projector.RemainingBlocksPerType;

            char[] delimiters = new char[] { ',' };
            char[] remove     = new char[] { '[', ']' };
            Dictionary <string, int> totalComponents = new Dictionary <string, int>();

            foreach (var item in blocks)
            {
                // blockInfo[0] is blueprint, blockInfo[1] is number of required item
                string[] blockInfo = item.ToString().Trim(remove).Split(delimiters, StringSplitOptions.None);

                string blockName = blockInfo[0].Replace(" ", ""); // data in blockDefinitionData is compressed removing spaces
                int    amount    = Convert.ToInt32(blockInfo[1]);

                AddComponents(totalComponents, GetComponents(blockName), amount);
            }

            bool LargeGrid = projector.BlockDefinition.SubtypeId == "LargeProjector";

            string armorType = "MyObjectBuilder_CubeBlock/";

            if (LargeGrid)
            {
                if (lightArmor)
                {
                    armorType += "LargeBlockArmorBlock";
                }
                else
                {
                    armorType += "LargeHeavyBlockArmorBlock";
                }
            }
            else
            if (lightArmor)
            {
                armorType += "SmallBlockArmorBlock";
            }
            else
            {
                armorType += "SmallHeavyBlockArmorBlock";
            }

            int armors = projector.RemainingArmorBlocks;

            AddComponents(totalComponents, GetComponents(armorType), armors);

            var compList = totalComponents.ToList();

            //compList.Sort((x, y) => string.Compare(TranslateDef(x.Key), TranslateDef(y.Key)));
            compList.Sort((x, y) => string.Compare(x.Key, y.Key));

            return(compList);
        }
        public static IMySlimBlock GetPreviewBlock(IMyProjector projector, int subgridIndex, Vector3I blockPosition)
        {
            if (!MgpAgent.Available)
            {
                return(projector.ProjectedGrid.GetCubeBlock(blockPosition));
            }

            var previewGrid = MgpAgent.GetPreviewGrid(projector.EntityId, subgridIndex);

            return(previewGrid?.GetCubeBlock(blockPosition));
        }
Beispiel #26
0
        public Program()
        {
            IMyTerminalBlock block;

            if (string.IsNullOrWhiteSpace(lcdName))
            {
                block = Me;
            }
            else
            {
                block = GridTerminalSystem.GetBlockWithName(lcdName);
                if (block == null)
                {
                    throw new Exception("Unable to find lcd.");
                }
            }

            if (block is IMyTextSurface)
            {
                canvas = (IMyTextSurface)block;
            }
            else if (block is IMyTextSurfaceProvider)
            {
                IMyTextSurfaceProvider temp = (IMyTextSurfaceProvider)block;
                lcdIndex = Math.Max(temp.SurfaceCount - 1, lcdIndex);
                canvas   = temp.GetSurface(lcdIndex);
            }
            else
            {
                throw new Exception("Unable to find lcd.");
            }

            if (string.IsNullOrWhiteSpace(projectorName))
            {
                List <IMyTerminalBlock> temp = new List <IMyTerminalBlock>();
                GridTerminalSystem.GetBlocksOfType <IMyProjector>(temp, (b) => temp.Count <= 1);
                projector = (IMyProjector)temp.FirstOrDefault();
            }
            else
            {
                projector = GridTerminalSystem.GetBlockWithName(projectorName) as IMyProjector;
            }

            if (projector == null)
            {
                throw new Exception("Unable to find projector.");
            }

            spawnProjection    = projector.GetActionWithName("BuildGrid");
            projectedGridComps = projector.GetProperty("RequiredComponents").As <Dictionary <MyItemType, int> >();
            projectedGridTimer = projector.GetProperty("GridTimerProjection").As <int>();
            timer = projector.GetProperty("GridTimerCurrent").As <int>();
            Runtime.UpdateFrequency = UpdateFrequency.Update10;
        }
        // Context: Terminal
        private static Dictionary <MyItemType, int> GetItemListPB(IMyTerminalBlock block)
        {
            IMyProjector me = (IMyProjector)block;

            if (me.ProjectedGrid != null)
            {
                GridComponents comps = block.GameLogic.GetAs <InstantProjector>().GetComponents();
                return(comps.ToDictionary(kv => new MyItemType(kv.Key.TypeId, kv.Key.SubtypeId), kv => kv.Value));
            }
            return(new Dictionary <MyItemType, int>());
        }
 private ProjectedGrid(ulong activator, IMyProjector p, List <MyObjectBuilder_CubeGrid> grids, GridBounds bounds, GridComponents comps, GridOrientation orientation, bool shiftBuildArea, int blockCount)
 {
     Activator           = activator;
     BlockCount          = blockCount;
     this.p              = p;
     this.grids          = grids;
     this.bounds         = bounds;
     this.comps          = comps;
     finalOrientation    = orientation;
     this.shiftBuildArea = shiftBuildArea;
 }
        private static IEnumerable <IMySlimBlock> IterBuildableBlocksVanilla(IMyProjector projector)
        {
            var grid = (MyCubeGrid)projector.ProjectedGrid;

            foreach (IMySlimBlock block in grid.GetBlocks())
            {
                if (projector.CanBuild(block, false) == BuildCheckResult.OK)
                {
                    yield return(block);
                }
            }
        }
Beispiel #30
0
        bool CollectParts(IMyTerminalBlock block)
        {
            if (!block.IsSameConstructAs(Me))
            {
                return(false);
            }
            //if (!block.CustomName.Contains(Me.CustomName.Last())) return false;
            if (block is IMyMotorAdvancedStator && block.CustomName.Contains("Small Hinge"))
            {
                SmallHinge = (IMyMotorAdvancedStator)block;
            }
            if (block is IMyMotorAdvancedStator && block.CustomName.Contains("Large Hinge"))
            {
                LargeHinge = (IMyMotorAdvancedStator)block;
            }
            if (block is IMyMotorAdvancedStator && block.CustomName.Contains("Elevation"))
            {
                Elevation = (IMyMotorAdvancedStator)block;
            }
            if (block is IMyMotorStator && block.CustomName.Contains("Sweeper"))
            {
                Sweeper = (IMyMotorStator)block;
            }

            if (block is IMyProjector && block.CustomName.Contains("Base Projector"))
            {
                BaseProjector = (IMyProjector)block;
            }
            if (block is IMyProjector && block.CustomName.Contains("Top Projector"))
            {
                TopProjector = (IMyProjector)block;
            }

            if (block is IMyShipMergeBlock && block.CustomName.Contains("Top Release"))
            {
                TopMerge = (IMyShipMergeBlock)block;
            }
            if (block is IMyShipMergeBlock && block.CustomName.Contains("Base Release"))
            {
                BaseMerge = (IMyShipMergeBlock)block;
            }

            if (block is IMyShipWelder)
            {
                Welders.Add((IMyShipWelder)block);
            }
            if (block is IMyTextPanel)
            {
                Display = (IMyTextPanel)block;
            }

            return(false);
        }