private int GetBlockConnections(NaniteDeconstructionGrid deconstruct, IMySlimBlock currentBlock)
        {
            deconstruct.AddingList.Clear();
            deconstruct.AddingGridList.Clear();

            MyObjectBuilder_CubeBlock block = (MyObjectBuilder_CubeBlock)currentBlock.GetObjectBuilder();
            MyCubeBlockDefinition     blockDefinition;

            MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDefinition);

            // Get real block max
            Vector3I Max = Vector3I.Zero;
            Vector3I Min = block.Min;

            ComputeMax(blockDefinition, block.BlockOrientation, ref Min, out Max);

            AddNeighbours(deconstruct, currentBlock, Min, new Vector3I(Min.X, Max.Y, Max.Z), -Vector3I.UnitX);
            AddNeighbours(deconstruct, currentBlock, Min, new Vector3I(Max.X, Min.Y, Max.Z), -Vector3I.UnitY);
            AddNeighbours(deconstruct, currentBlock, Min, new Vector3I(Max.X, Max.Y, Min.Z), -Vector3I.UnitZ);
            AddNeighbours(deconstruct, currentBlock, new Vector3I(Max.X, Min.Y, Min.Z), Max, Vector3I.UnitX);
            AddNeighbours(deconstruct, currentBlock, new Vector3I(Min.X, Max.Y, Min.Z), Max, Vector3I.UnitY);
            AddNeighbours(deconstruct, currentBlock, new Vector3I(Min.X, Min.Y, Max.Z), Max, Vector3I.UnitZ);

            // Check if currentBlock is a connector of some kind, then follow it
            // AddConnectedGridBlock(deconstruct, currentBlock);

            return(deconstruct.AddingList.Count + deconstruct.AddingGridList.Count);
        }
Ejemplo n.º 2
0
        static void DetachBlock(IMySlimBlock block, IMyAngleGrinder grinder)
        {
            if (!MyAPIGateway.Session.IsServer)
            {
                return;
            }

            MyCubeBlockDefinition blockDef = (MyCubeBlockDefinition)block.BlockDefinition;
            string blockName = blockDef.DisplayNameText;
            string gridName  = $"(Detached {blockName})";

            IMyCubeGrid detachFrom = block.CubeGrid;

            MyObjectBuilder_CubeBlock blockOb = block.GetObjectBuilder();
            MyObjectBuilder_CubeGrid  gridOb  = CreateNewGridOB(block.CubeGrid, blockOb, gridName);

            block.CubeGrid.RemoveBlock(block, true);

            MyCubeGrid createdGrid = MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(gridOb) as MyCubeGrid;

            if (createdGrid == null)
            {
                Log.Error($"Failed to create a new grid! obj={gridOb}; new entId={gridOb.EntityId.ToString()}");
                MyVisualScriptLogicProvider.SendChatMessageColored($"Failed to create detached block grid!", Color.Red, Log.ModName, grinder.OwnerIdentityId, MyFontEnum.Debug);
                return;
            }

            Log.Info($"Detached '{blockName}' from '{detachFrom.CustomName}' ({detachFrom.EntityId.ToString()}); new grid id={createdGrid.EntityId.ToString()}");

            // sending "to server" so that it happens serverside too if server is a player (or singleplayer).
            DetachEffectsPacket packet = new DetachEffectsPacket(createdGrid.GetBlocks().First());

            AdvancedWeldingMod.Instance.Networking.SendToServer(packet);
        }
Ejemplo n.º 3
0
        private void Actual_OnBlockAdded(IMySlimBlock obj)
        {
            SeenHolo sh;

            if (!m_holoEntities.TryGetValue(obj.CubeGrid.EntityId, out sh))
            {
                Log.DebugLog("failed lookup of grid: " + obj.CubeGrid.DisplayName, Logger.severity.ERROR);
                obj.CubeGrid.OnBlockAdded   -= Actual_OnBlockAdded;
                obj.CubeGrid.OnBlockRemoved -= Actual_OnBlockRemoved;
                return;
            }

            IMyCubeGrid holo = (IMyCubeGrid)sh.Holo;
            MyObjectBuilder_CubeBlock objBuilder = obj.GetObjectBuilder();

            objBuilder.EntityId = 0L;
            holo.AddBlock(objBuilder, false);

            IMyCubeBlock cubeBlock = holo.GetCubeBlock(obj.Position).FatBlock;

            if (cubeBlock != null)
            {
                SetupProjection(cubeBlock);
            }
        }
Ejemplo n.º 4
0
        private bool isAttached_connector(AttachedGrids partner)
        {
            foreach (KeyValuePair <IMySlimBlock, wasConnected> pair in allConnectors)
            {
                IMySlimBlock connector = pair.Key;
                MyObjectBuilder_ShipConnector builder_conn = connector.GetObjectBuilder() as MyObjectBuilder_ShipConnector;
                pair.Value.connected = builder_conn.Connected;
                if (!builder_conn.Connected)
                {
                    continue;
                }

                long connectedEntityId = builder_conn.ConnectedEntityId;
                foreach (IMySlimBlock connectPartner in partner.allConnectors.Keys)
                {
                    if (connectedEntityId == connectPartner.FatBlock.EntityId)
                    {
                        log("matched " + myGrid.DisplayName + " : " + connector.FatBlock.DefinitionDisplayNameText + " to " + partner.myGrid.DisplayName + " : " + connectPartner.FatBlock.DefinitionDisplayNameText, "isAttached_connector()", Logger.severity.TRACE);
                        tryAddAttached(partner);
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Check if the given block is a "live" existing block, or a "zombie" reference left after a dead and removed block.
        /// </summary>
        /// <param name="StrictCheck">Performs strict check (checks if block in same place is of same typeid+subtypeid). Generates 2 object builders.</param>
        public static bool IsLive(this IMySlimBlock Block, bool StrictCheck = false)
        {
            if (Block == null)
            {
                return(false);
            }
            if (Block.FatBlock != null && Block.FatBlock.Closed)
            {
                return(false);
            }
            if (Block.IsDestroyed)
            {
                return(false);
            }
            var ThereBlock = Block.CubeGrid.GetCubeBlock(Block.Position);

            if (ThereBlock == null)
            {
                return(false);
            }
            var Builder      = Block.GetObjectBuilder();
            var ThereBuilder = ThereBlock.GetObjectBuilder();

            return(Builder.TypeId == ThereBuilder.TypeId && Builder.SubtypeId == ThereBuilder.SubtypeId);
        }
Ejemplo n.º 6
0
 public static MyObjectBuilder_CubeBlock GetSlimObjectBuilder_Safe(this IMyCubeBlock block)
 {
     using (Lock_MainThread.AcquireSharedUsing())
     {
         IMySlimBlock slim = block.CubeGrid.GetCubeBlock(block.Position);
         return(slim.GetObjectBuilder());
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Returns block's builder id. WARNING: Heavy!
        /// </summary>
        public static long GetBuiltBy(this IMySlimBlock block)
        {
            if (block is IMyCubeBlock)
            {
                return((block as MyCubeBlock).BuiltBy);
            }
            MyObjectBuilder_CubeBlock builder = block.GetObjectBuilder();

            return(builder.BuiltBy);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns block's builder id. WARNING: Heavy!
        /// </summary>
        public static long GetBuiltBy(this IMySlimBlock Block)
        {
            if (Block is IMyCubeBlock)
            {
                return((Block as MyCubeBlock).BuiltBy);
            }
            var builder = Block.GetObjectBuilder();

            return(builder.BuiltBy);
        }
        private int GetBlockConnections(IMySlimBlock currentBlock)
        {
            if (currentBlock.CubeGrid.Closed)
            {
                return(0);
            }

            NaniteDeconstructionGrid deconstruct = new NaniteDeconstructionGrid(currentBlock.CubeGrid);

            deconstruct.AddingList.Clear();
            deconstruct.AddingGridList.Clear();

            MyObjectBuilder_CubeBlock block = (MyObjectBuilder_CubeBlock)currentBlock.GetObjectBuilder();
            MyCubeBlockDefinition     blockDefinition;

            MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDefinition);

            // Get real block max
            Vector3I Max = Vector3I.Zero;
            Vector3I Min = block.Min;

            ComputeMax(blockDefinition, block.BlockOrientation, ref Min, out Max);

            AddNeighbours(deconstruct, currentBlock, Min, new Vector3I(Min.X, Max.Y, Max.Z), -Vector3I.UnitX);
            AddNeighbours(deconstruct, currentBlock, Min, new Vector3I(Max.X, Min.Y, Max.Z), -Vector3I.UnitY);
            AddNeighbours(deconstruct, currentBlock, Min, new Vector3I(Max.X, Max.Y, Min.Z), -Vector3I.UnitZ);
            AddNeighbours(deconstruct, currentBlock, new Vector3I(Max.X, Min.Y, Min.Z), Max, Vector3I.UnitX);
            AddNeighbours(deconstruct, currentBlock, new Vector3I(Min.X, Max.Y, Min.Z), Max, Vector3I.UnitY);
            AddNeighbours(deconstruct, currentBlock, new Vector3I(Min.X, Min.Y, Max.Z), Max, Vector3I.UnitZ);

            int additional = 0;

            if (currentBlock.FatBlock != null && currentBlock.FatBlock.BlockDefinition.SubtypeName.Contains("NaniteBeaconDeconstruct"))
            {
                additional += 10;
            }

            /*
             * if (currentBlock.FatBlock != null &&
             *      (currentBlock.FatBlock is IMyPistonBase ||
             *       currentBlock.FatBlock is IMyPistonTop ||
             *       currentBlock.FatBlock is IMyMotorRotor ||
             *       currentBlock.FatBlock is IMyMotorStator ||
             *       currentBlock.FatBlock is IMyMotorBase ||
             *       currentBlock.FatBlock is Ingame.IMyShipConnector))
             * {
             *  additional += 10;
             * }
             */

            AddConnectedGridBlock(deconstruct, currentBlock);

            return(deconstruct.AddingList.Count + deconstruct.AddingGridList.Count + additional);
        }
Ejemplo n.º 10
0
        private int getComputerCount(IMySlimBlock block)
        {
            var componets = MyDefinitionManager.Static.GetCubeBlockDefinition(block.GetObjectBuilder()).Components;
            int computers = 0;

            for (var i = 0; i < componets.Length; i++)
            {
                if (componets[i].Definition.Id.SubtypeName == "Computer")
                {
                    computers += componets[i].Count;
                }
            }
            return(computers);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Updates the appearance of the block if the integrity has changed. Only used for welding/griding.
        /// </summary>
        private static void UpdateBlockModel(IMySlimBlock realBlock, IMyCubeGrid holoGrid)
        {
            IMySlimBlock holoBlock = holoGrid.GetCubeBlock(realBlock.Position);

            Logger.DebugLog("holoBlock == null", Logger.severity.FATAL, condition: holoBlock == null);

            float realIntegrityRatio = (realBlock.BuildIntegrity - realBlock.CurrentDamage) / realBlock.MaxIntegrity;
            float holoIntegrityRatio = (holoBlock.BuildIntegrity - holoBlock.CurrentDamage) / holoBlock.MaxIntegrity;

            if (realIntegrityRatio == holoIntegrityRatio)
            {
                return;
            }

            float min, max;

            if (realIntegrityRatio > holoIntegrityRatio)
            {
                max = realIntegrityRatio;
                min = holoIntegrityRatio;
            }
            else
            {
                max = holoIntegrityRatio;
                min = realIntegrityRatio;
            }

            if (((MyCubeBlockDefinition)realBlock.BlockDefinition).ModelChangeIsNeeded(min, max))
            {
                holoGrid.RemoveBlock(holoBlock);

                MyObjectBuilder_CubeBlock objBuilder = realBlock.GetObjectBuilder();
                objBuilder.EntityId = 0L;
                holoGrid.AddBlock(objBuilder, false);

                IMyCubeBlock cubeBlock = holoGrid.GetCubeBlock(realBlock.Position).FatBlock;
                if (cubeBlock != null)
                {
                    SetupProjection(cubeBlock);
                }
            }
        }
Ejemplo n.º 12
0
 public static long BuiltBy(this IMySlimBlock Block)
 {
     return(Block.GetObjectBuilder().BuiltBy);
 }
Ejemplo n.º 13
0
        private void GetAllComponents(IMySlimBlock slim)
        {
            using (MainLock.AcquireSharedUsing())
            {
                MyCubeBlockDefinition definition;

                IMyCubeBlock fat = slim.FatBlock;
                if (fat != null)
                    definition = fat.GetCubeBlockDefinition();
                else
                    definition = MyDefinitionManager.Static.GetCubeBlockDefinition(slim.GetObjectBuilder());

                foreach (var component in definition.Components)
                {
                    int currentCount;
                    if (!m_components_missing.TryGetValue(component.Definition.Id.SubtypeName, out currentCount))
                        currentCount = 0;
                    currentCount += component.Count;
                    m_components_missing[component.Definition.Id.SubtypeName] = currentCount;
                    //m_logger.debugLog("missing " + component.Definition.Id.SubtypeName + ": " + component.Count + ", total: " + currentCount, "GetAllComponents()");
                }
            }
        }
Ejemplo n.º 14
0
        public virtual void Close()
        {
            //Logging.Instance.WriteLine(string.Format("Close"));

            int pos = 0;

            try
            {
                if (m_performanceFriendly)
                {
                    if (Sync.IsClient)
                    {
                        NaniteConstructionManager.ParticleManager.RemoveParticle(m_cubeEntityId, m_position);
                    }
                    else
                    {
                        m_constructionBlock.SendRemoveParticleEffect(m_cubeEntityId, m_position);
                    }

                    if (m_isGrinder && m_removed)
                    {
                        TransferRemainingComponents();
                        Logging.Instance.WriteLine(string.Format("GRINDING completed.  Target block: {0} - (EntityID: {1} Elapsed: {2})", m_targetBlock.FatBlock != null ? m_targetBlock.FatBlock.GetType().Name : m_targetBlock.GetType().Name, m_targetBlock.FatBlock != null ? m_targetBlock.FatBlock.EntityId : 0, m_completeTime + m_waitTime));
                    }

                    m_completed = true;
                    return;
                }

                if (m_constructionBlock != null && m_constructionBlock.ConstructionBlock != null)
                {
                    var toolInventory = ((MyEntity)m_tool).GetInventory(0);

                    // Since grinding in creative gives no components.  Insert hack.
                    if (MyAPIGateway.Session.CreativeMode && m_tool is Sandbox.ModAPI.Ingame.IMyShipGrinder)
                    {
                        MyObjectBuilder_CubeBlock block = (MyObjectBuilder_CubeBlock)m_targetBlock.GetObjectBuilder();
                        MyCubeBlockDefinition     blockDefinition;
                        if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDefinition))
                        {
                            foreach (var item in blockDefinition.Components)
                            {
                                var inventoryItem = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(item.DeconstructItem.Id);
                                toolInventory.AddItems(item.Count, inventoryItem);
                            }
                        }
                    }

                    if (toolInventory.GetItemsCount() > 0)
                    {
                        TransferFromTarget((MyCubeBlock)m_tool);
                    }
                }

                m_completed = true;
                if (m_tool != null)
                {
                    m_tool.Enabled = false;
                }

                if (!m_toolEntity.Closed)
                {
                    m_toolEntity.Close();
                }
            }
            catch (Exception ex)
            {
                Logging.Instance.WriteLine(string.Format("Close() {1}: {0}", ex.ToString(), pos));
            }
        }
        private void BuildBlock(IMySlimBlock block, MyCubeBlock constructionBlock)
        {
            MyObjectBuilder_CubeBlock     cubeBlock        = block.GetObjectBuilder();
            MyObjectBuilder_ProjectorBase projectorBuilder = null;// = (MyObjectBuilder_ProjectorBase)constructionBlock.GetObjectBuilderCubeBlock();
            MyCubeGrid  projectorGrid = null;
            MyCubeGrid  blockGrid     = (MyCubeGrid)block.CubeGrid;
            MyCubeBlock projector     = null;

            foreach (var item in NaniteConstructionManager.ProjectorBlocks)
            {
                var projectorTest = item.Value as IMyProjector;
                if (projectorTest == null)
                {
                    continue;
                }

                if (projectorTest.ProjectedGrid == null)
                {
                    continue;
                }

                if (projectorTest.ProjectedGrid == block.CubeGrid)
                {
                    projector        = (MyCubeBlock)projectorTest;
                    projectorGrid    = projector.CubeGrid;
                    projectorBuilder = (MyObjectBuilder_ProjectorBase)projector.GetObjectBuilderCubeBlock();
                    break;
                }
            }

            /*
             * Ingame.IMyGridTerminalSystem system = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid((IMyCubeGrid)m_constructionBlock.ConstructionBlock.CubeGrid);
             * List<Ingame.IMyTerminalBlock> terminalBlocks = new List<Ingame.IMyTerminalBlock>();
             * system.GetBlocks(terminalBlocks);
             * foreach(var item in terminalBlocks)
             * {
             *  if (!(item is IMyFunctionalBlock) || !((IMyFunctionalBlock)item).Enabled)
             *      continue;
             *
             *  if (!(item is Ingame.IMyProjector))
             *      continue;
             *
             *  var cube = (MyCubeBlock)item;
             *  MyObjectBuilder_ProjectorBase testBuilder = (MyObjectBuilder_ProjectorBase)cube.GetObjectBuilderCubeBlock();
             *  if (testBuilder.ProjectedGrid == null)
             *      continue;
             *
             *  if(testBuilder.ProjectedGrid.DisplayName == blockGrid.DisplayName)
             *  {
             *      projector = cube;
             *      projectorGrid = cube.CubeGrid;
             *      projectorBuilder = testBuilder;
             *      break;
             *  }
             * }
             */

            if (projectorBuilder == null)
            {
                Logging.Instance.WriteLine("PROBLEM Can not locate projector that is projecting target!");
                return;
            }

            Quaternion quat        = Quaternion.Identity;
            var        orientation = block.Orientation;

            Matrix local;

            orientation.GetMatrix(out local);
            var gridOrientation = GetGridOrientation(projectorBuilder);

            if (gridOrientation != Matrix.Identity)
            {
                var afterRotation = Matrix.Multiply(local, gridOrientation);
                orientation = new MyBlockOrientation(ref afterRotation);
            }

            Quaternion projQuat = Quaternion.Identity;

            projector.Orientation.GetQuaternion(out projQuat);
            orientation.GetQuaternion(out quat);
            quat = Quaternion.Multiply(projQuat, quat);

            // Get real block max
            MyCubeBlockDefinition blockDefinition = (MyCubeBlockDefinition)block.BlockDefinition;
            Vector3I blockMax = block.Max;
            Vector3I blockMin = cubeBlock.Min;
            Vector3I position = block.Position;

            Vector3I min = projectorGrid.WorldToGridInteger(blockGrid.GridIntegerToWorld(blockMin));
            Vector3I max = projectorGrid.WorldToGridInteger(blockGrid.GridIntegerToWorld(blockMax));
            Vector3I pos = projectorGrid.WorldToGridInteger(blockGrid.GridIntegerToWorld(block.Position));

            Vector3I projectedMin = new Vector3I(Math.Min(min.X, max.X), Math.Min(min.Y, max.Y), Math.Min(min.Z, max.Z));
            Vector3I projectedMax = new Vector3I(Math.Max(min.X, max.X), Math.Max(min.Y, max.Y), Math.Max(min.Z, max.Z));

            MyCubeGrid.MyBlockLocation location = new MyCubeGrid.MyBlockLocation(blockDefinition.Id, projectedMin, projectedMax, pos,
                                                                                 quat, 0, constructionBlock.OwnerId);

            /*
             * MyObjectBuilder_CubeGrid originalGridBuilder = (MyObjectBuilder_CubeGrid)blockGrid.GetObjectBuilder();
             * MyObjectBuilder_CubeBlock objectBuilder = null;
             * //Find original grid builder
             * foreach (var blockBuilder in originalGridBuilder.CubeBlocks)
             * {
             *  if (blockBuilder.GetId() == blockDefinition.Id)
             *  {
             *      if ((Vector3I)blockBuilder.Min == blockMin)
             *      {
             *          objectBuilder = (MyObjectBuilder_CubeBlock)blockBuilder.Clone();
             *          objectBuilder.SetupForProjector();
             *      }
             *  }
             * }
             */

            MyObjectBuilder_CubeBlock objectBuilder = cubeBlock;

            objectBuilder.SetupForProjector();
            var functionalBuilder = objectBuilder as MyObjectBuilder_FunctionalBlock;

            if (functionalBuilder != null && !functionalBuilder.Enabled)
            {
                functionalBuilder.Enabled = true;
            }

            var terminalBuilder = objectBuilder as MyObjectBuilder_TerminalBlock;

            if (terminalBuilder != null)
            {
                terminalBuilder.Owner = constructionBlock.OwnerId;
            }

            var shipConnector = objectBuilder as MyObjectBuilder_ShipConnector;

            if (shipConnector != null)
            {
                shipConnector.Connected              = false;
                shipConnector.ConnectedEntityId      = 0;
                shipConnector.MasterToSlaveGrid      = null;
                shipConnector.MasterToSlaveTransform = null;
            }

            //if (objectBuilder == null)
            //    objectBuilder = cubeBlock;

            location.EntityId      = 0; // MyEntityIdentifier.AllocateId();
            objectBuilder.EntityId = 0;

            objectBuilder.ConstructionInventory = null;
            projector.CubeGrid.BuildBlockRequest(block.GetColorMask().PackHSVToUint(), location, objectBuilder, constructionBlock.EntityId, false, constructionBlock.OwnerId);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Updates the appearance of the block if the integrity has changed. Only used for welding/griding.
        /// </summary>
        private static void UpdateBlockModel(IMySlimBlock realBlock, IMyCubeGrid holoGrid)
        {
            IMySlimBlock holoBlock = holoGrid.GetCubeBlock(realBlock.Position);
            Static.logger.debugLog(holoBlock == null, "holoBlock == null", Logger.severity.FATAL);

            float realIntegrityRatio = (realBlock.BuildIntegrity - realBlock.CurrentDamage) / realBlock.MaxIntegrity;
            float holoIntegrityRatio = (holoBlock.BuildIntegrity - holoBlock.CurrentDamage) / holoBlock.MaxIntegrity;

            if (realIntegrityRatio == holoIntegrityRatio)
                return;

            float min, max;
            if (realIntegrityRatio > holoIntegrityRatio)
            {
                max = realIntegrityRatio;
                min = holoIntegrityRatio;
            }
            else
            {
                max = holoIntegrityRatio;
                min = realIntegrityRatio;
            }

            if (((MyCubeBlockDefinition)realBlock.BlockDefinition).ModelChangeIsNeeded(min, max))
            {
                holoGrid.RemoveBlock(holoBlock);

                MyObjectBuilder_CubeBlock objBuilder = realBlock.GetObjectBuilder();
                objBuilder.EntityId = 0L;
                holoGrid.AddBlock(objBuilder, false);

                IMyCubeBlock cubeBlock = holoGrid.GetCubeBlock(realBlock.Position).FatBlock;
                if (cubeBlock != null)
                    SetupProjection(cubeBlock);
            }
        }
Ejemplo n.º 17
0
        private void Actual_OnBlockAdded(IMySlimBlock obj)
        {
            SeenHolo sh;
            if (!m_holoEntities.TryGetValue(obj.CubeGrid.EntityId, out sh))
            {
                m_logger.debugLog("failed lookup of grid: " + obj.CubeGrid.DisplayName, Logger.severity.ERROR);
                obj.CubeGrid.OnBlockAdded -= Actual_OnBlockAdded;
                obj.CubeGrid.OnBlockRemoved -= Actual_OnBlockRemoved;
                return;
            }

            IMyCubeGrid holo = (IMyCubeGrid)sh.Holo;
            MyObjectBuilder_CubeBlock objBuilder = obj.GetObjectBuilder();
            objBuilder.EntityId = 0L;
            holo.AddBlock(objBuilder, false);

            IMyCubeBlock cubeBlock = holo.GetCubeBlock(obj.Position).FatBlock;
            if (cubeBlock != null)
                SetupProjection(cubeBlock);
        }
        private int getComputerCount(IMySlimBlock block)
        {
            MyCubeBlockDefinition.Component[] components = MyDefinitionManager.Static.GetCubeBlockDefinition(block.GetObjectBuilder()).Components;
            int computers = 0;

            foreach (MyCubeBlockDefinition.Component c in components)
            {
                if (c.Definition.Id.SubtypeName == "Computer")
                {
                    computers += c.Count;
                }
            }
            return(computers);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Creates properties for a thruster and adds it to allMyThrusters. If the thruster is working, calls enableDisableThruster(true).
        /// </summary>
        /// <param name="thruster">The new thruster</param>
        private void newThruster(IMySlimBlock thruster)
        {
            float dampingForce            = 10 * (MyDefinitionManager.Static.GetCubeBlockDefinition(thruster.GetObjectBuilder()) as MyThrustDefinition).ForceMagnitude;
            ThrusterProperties properties = new ThrusterProperties(dampingForce, Base6Directions.GetFlippedDirection(thruster.FatBlock.Orientation.Forward));

            allMyThrusters.Add(thruster.FatBlock, properties);
            thruster.FatBlock.IsWorkingChanged += block_IsWorkingChanged;
            if (thruster.FatBlock.IsWorking)
            {
                enableDisableThruster(properties, true);
            }
            return;
        }
Ejemplo n.º 20
0
 public static MyObjectBuilder_CubeBlock GetObjectBuilder_Safe(this IMySlimBlock block)
 {
     using (Lock_MainThread.AcquireSharedUsing())
         return(block.GetObjectBuilder());
 }
Ejemplo n.º 21
0
        private void Complete()
        {
            if (m_targetBlock.IsDestroyed || m_targetBlock.CubeGrid.GetCubeBlock(m_targetBlock.Position) == null || (m_targetBlock.FatBlock != null && m_targetBlock.FatBlock.Closed))
            {
                return;
            }

            if (m_targetBlock.CubeGrid.Closed)
            {
                return;
            }

            MyCubeGrid grid = (MyCubeGrid)m_targetBlock.CubeGrid;
            MyObjectBuilder_CubeBlock block;

            try
            {
                if (m_targetBlock.FatBlock == null)
                {
                    block = m_targetBlock.GetObjectBuilder();
                }
                else
                {
                    block = m_targetBlock.FatBlock.GetObjectBuilderCubeBlock();
                }
            }
            catch (Exception ex)
            {
                Logging.Instance.WriteLine(string.Format("ERROR getting cubeblock object builder (3): {0} {1} - {2}", m_targetBlock.IsDestroyed, m_targetBlock.FatBlock != null ? m_targetBlock.FatBlock.GetType().Name : m_targetBlock.GetType().Name, ex.ToString()));
            }

            // Target block contains inventory, spawn it
            if (m_targetBlock.FatBlock != null && ((MyEntity)m_targetBlock.FatBlock).HasInventory)
            {
                for (int r = 0; r < ((MyEntity)m_targetBlock.FatBlock).InventoryCount; r++)
                {
                    var inventory = ((MyEntity)m_targetBlock.FatBlock).GetInventoryBase(r);
                    if (inventory == null)
                    {
                        continue;
                    }

                    foreach (var item in inventory.GetItems())
                    {
                        Logging.Instance.WriteLine(string.Format("INVENTORY found.  Target block contains inventory: {0} {1}", item.Amount, item.Content.SubtypeId));
                        if (!m_inventory.ContainsKey(item.Content.SubtypeName))
                        {
                            m_inventory.Add(item.Content.SubtypeName, new MyTuple <MyFixedPoint, MyObjectBuilder_PhysicalObject>(item.Amount, item.Content));
                        }
                        else
                        {
                            m_inventory[item.Content.SubtypeName] = new MyTuple <MyFixedPoint, MyObjectBuilder_PhysicalObject>(m_inventory[item.Content.SubtypeName].Item1 + item.Amount, m_inventory[item.Content.SubtypeName].Item2);
                        }
                    }
                }
            }

            m_targetBlock.GetMissingComponents(m_missingComponents);
            //grid.RemoveBlock()
            //grid.RemoveBlock((Sandbox.Game.Entities.Cube.MySlimBlock)m_targetBlock, true);
            grid.RazeBlock(m_targetBlock.Position);
            m_removed = true;
        }
        private void CreateRemovalOrder(NaniteDeconstructionGrid deconstruct, IMySlimBlock startBlock)
        {
            IMySlimBlock currentBlock = startBlock;

            deconstruct.AddingList.Clear();
            deconstruct.GridsProcessed.Clear();

            while (true)
            {
                if (!deconstruct.GridsProcessed.Contains(currentBlock.CubeGrid))
                {
                    ((MyCubeGrid)currentBlock.CubeGrid).OnGridSplit += OnGridSplit;
                    deconstruct.GridsProcessed.Add(currentBlock.CubeGrid);
                }

                MyObjectBuilder_CubeBlock block = (MyObjectBuilder_CubeBlock)currentBlock.GetObjectBuilder();
                MyCubeBlockDefinition     blockDefinition;
                MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDefinition);

                // Get real block max
                Vector3I Max = Vector3I.Zero;
                Vector3I Min = block.Min;
                ComputeMax(blockDefinition, block.BlockOrientation, ref Min, out Max);

                AddNeighbours(deconstruct, currentBlock, Min, new Vector3I(Min.X, Max.Y, Max.Z), -Vector3I.UnitX);
                AddNeighbours(deconstruct, currentBlock, Min, new Vector3I(Max.X, Min.Y, Max.Z), -Vector3I.UnitY);
                AddNeighbours(deconstruct, currentBlock, Min, new Vector3I(Max.X, Max.Y, Min.Z), -Vector3I.UnitZ);
                AddNeighbours(deconstruct, currentBlock, new Vector3I(Max.X, Min.Y, Min.Z), Max, Vector3I.UnitX);
                AddNeighbours(deconstruct, currentBlock, new Vector3I(Min.X, Max.Y, Min.Z), Max, Vector3I.UnitY);
                AddNeighbours(deconstruct, currentBlock, new Vector3I(Min.X, Min.Y, Max.Z), Max, Vector3I.UnitZ);

                // Check if currentBlock is a connector of some kind, then follow it
                AddConnectedGridBlock(deconstruct, currentBlock);

                // Add to removal list
                if (!deconstruct.RemoveList.Contains(currentBlock))
                {
                    deconstruct.RemoveList.AddStart(currentBlock);
                }

                if (deconstruct.AddingList.Count < 1 && deconstruct.AddingGridList.Count < 1)
                {
                    break;
                }

                if (deconstruct.AddingList.Count < 1 && deconstruct.AddingGridList.Count > 0)
                {
                    currentBlock = deconstruct.AddingGridList[0];
                    deconstruct.AddingGridList.Remove(currentBlock);
                    //deconstruct.TreePosition++;
                    //deconstruct.GridTree.Add(new Node<IMySlimBlock>(currentBlock));
                }
                else
                {
                    currentBlock = deconstruct.AddingList[0];
                    deconstruct.AddingList.Remove(currentBlock);
                }
            }

            // Find user defined priority blocks for deconstruction.
            FindPriorityBlocks(deconstruct, startBlock);

            Logging.Instance.WriteLine(string.Format("Block Count: {0}", deconstruct.RemoveList.Count));
            //Logging.Instance.WriteLine(string.Format("Grid Count: {0}", deconstruct.GridsProcessed.Count));
            //Logging.Instance.WriteLine(string.Format("Tree Size: {0}", deconstruct.GridTree.Sum(x => x.All.Count())));
        }