예제 #1
0
 public PistonEntity(CubeGridEntity parent, MyObjectBuilder_PistonBase definition)
     : base(parent, definition)
 {
     m_velocity = definition.Velocity;
     m_minLimit = definition.MinLimit.GetValueOrDefault(0);
     m_maxLimit = definition.MaxLimit.GetValueOrDefault(0);
 }
예제 #2
0
        public PistonEntity(CubeGridEntity parent, MyObjectBuilder_PistonBase definition, Object backingObject)
            : base(parent, definition, backingObject)
        {
            m_velocity = definition.Velocity;
            m_minLimit = definition.MinLimit.GetValueOrDefault(0);
            m_maxLimit = definition.MaxLimit.GetValueOrDefault(0);

            m_networkManager = new PistonNetworkManager(this, GetPistonNetworkManager( ));
        }
예제 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="partner"></param>
 /// <returns>true iff a new grid was attached</returns>
 private bool isAttached_piston(AttachedGrids partner)
 {
     foreach (IMySlimBlock pistonBase in allPistonBases)
     {
         MyObjectBuilder_PistonBase builder_base = pistonBase.GetObjectBuilder() as MyObjectBuilder_PistonBase;
         long topBlockId = builder_base.TopBlockId;
         foreach (IMySlimBlock pistonTop in partner.allPistonTops)
         {
             if (topBlockId == pistonTop.FatBlock.EntityId)
             {
                 log("matched " + myGrid.DisplayName + " : " + pistonBase.FatBlock.DefinitionDisplayNameText + " to " + partner.myGrid.DisplayName + " : " + pistonTop.FatBlock.DefinitionDisplayNameText, "isAttached_piston()", Logger.severity.TRACE);
                 tryAddAttached(partner);
                 return(true);
             }
         }
     }
     return(false);
 }
        private static IEnumerable <MyObjectBuilder_CubeBlock> MirrorCubes(IMyCubeGrid shipEntity, bool integrate, MirrorDirection xMirror, int xAxis, MirrorDirection yMirror, int yAxis, MirrorDirection zMirror, int zAxis)
        {
            var blocks = new List <MyObjectBuilder_CubeBlock>();

            if (xMirror == MirrorDirection.None && yMirror == MirrorDirection.None && zMirror == MirrorDirection.None)
            {
                return(blocks);
            }

            List <IMySlimBlock> cubeBlocks = new List <IMySlimBlock>();

            shipEntity.GetBlocks(cubeBlocks);
            foreach (var block in cubeBlocks)
            {
                MyObjectBuilder_CubeBlock newBlock = (MyObjectBuilder_CubeBlock)block.GetObjectBuilder().Clone();

                // Need to use the Min from the GetObjectBuilder(), as block.Position is NOT representative.
                Vector3I oldMin = newBlock.Min;

                newBlock.EntityId = 0;

                MyObjectBuilder_MotorBase motorBase = newBlock as MyObjectBuilder_MotorBase;
                if (motorBase != null)
                {
                    motorBase.RotorEntityId = 0;
                }

                MyObjectBuilder_PistonBase pistonBase = newBlock as MyObjectBuilder_PistonBase;
                if (pistonBase != null)
                {
                    pistonBase.TopBlockId = 0;
                }

                MyCubeBlockDefinition definition = MyDefinitionManager.Static.GetCubeBlockDefinition(newBlock);

                MyCubeBlockDefinition mirrorDefinition;
                MirrorCubeOrientation(definition, block.Orientation, xMirror, yMirror, zMirror, out mirrorDefinition, out newBlock.BlockOrientation);

                newBlock.SubtypeName = mirrorDefinition.Id.SubtypeName;


                if (definition.Size.X == 1 && definition.Size.Y == 1 && definition.Size.Z == 1)
                {
                    newBlock.Min = oldMin.Mirror(xMirror, xAxis, yMirror, yAxis, zMirror, zAxis);
                }
                else
                {
                    // resolve size of component, and transform to original orientation.
                    var orientSize = definition.Size.Add(-1).Transform(block.Orientation).Abs();

                    var min      = oldMin.Mirror(xMirror, xAxis, yMirror, yAxis, zMirror, zAxis);
                    var blockMax = new SerializableVector3I(oldMin.X + orientSize.X, oldMin.Y + orientSize.Y, oldMin.Z + orientSize.Z);
                    var max      = ((Vector3I)blockMax).Mirror(xMirror, xAxis, yMirror, yAxis, zMirror, zAxis);

                    if (xMirror != MirrorDirection.None)
                    {
                        newBlock.Min = new SerializableVector3I(max.X, min.Y, min.Z);
                    }
                    if (yMirror != MirrorDirection.None)
                    {
                        newBlock.Min = new SerializableVector3I(min.X, max.Y, min.Z);
                    }
                    if (zMirror != MirrorDirection.None)
                    {
                        newBlock.Min = new SerializableVector3I(min.X, min.Y, max.Z);
                    }
                }

                Vector3I newPosition = ComputePositionInGrid(new MatrixI(newBlock.BlockOrientation), mirrorDefinition, newBlock.Min);

                // Don't place a block if one already exists there in the mirror.
                if (integrate && cubeBlocks.Any(b => b.Position.X == newPosition.X && b.Position.Y == newPosition.Y && b.Position.Z == newPosition.Z))
                {
                    continue;
                }

                //VRage.Utils.MyLog.Default.WriteLineAndConsole($"## CHECK ## new block {newBlock.SubtypeName}");

                blocks.Add(newBlock);

                // Alternate to using AddBlock().
                //Quaternion q;
                //((MyBlockOrientation)newBlock.BlockOrientation).GetQuaternion(out q);
                //((MyCubeGrid)shipEntity).BuildGeneratedBlock(new MyCubeGrid.MyBlockLocation(mirrorDefinition.Id, newBlock.Min, newBlock.Min, newBlock.Min, q, 0, 0) , newBlock.ColorMaskHSV);
            }
            return(blocks);
        }
예제 #5
0
        private static void CheckGridConnection(IMyEntity block)
        {
            IMyCubeBlock cubeBlock = (IMyCubeBlock)block;

            if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_PistonBase))
            {
                MyObjectBuilder_PistonBase pistonBase = (MyObjectBuilder_PistonBase)cubeBlock.GetObjectBuilderCubeBlock();
                IMyEntity connectedEntity             = null;
                if (pistonBase.TopBlockId.HasValue && MyAPIGateway.Entities.TryGetEntityById(pistonBase.TopBlockId.Value, out connectedEntity))
                {
                    IMyEntity parent = connectedEntity.Parent;

                    if (parent is IMyCubeGrid)
                    {
                        if (!m_conveyorConnected.ContainsKey(parent.EntityId))
                        {
                            m_conveyorConnected.Add(parent.EntityId, new long[] { pistonBase.TopBlockId.Value, pistonBase.EntityId });
                        }
                    }
                }
            }
            else if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_ExtendedPistonBase))
            {
                MyObjectBuilder_PistonBase pistonBase = (MyObjectBuilder_PistonBase)cubeBlock.GetObjectBuilderCubeBlock();
                IMyEntity connectedEntity             = null;
                if (pistonBase.TopBlockId.HasValue && MyAPIGateway.Entities.TryGetEntityById(pistonBase.TopBlockId.Value, out connectedEntity))
                {
                    IMyEntity parent = connectedEntity.Parent;

                    if (parent is IMyCubeGrid)
                    {
                        if (!m_conveyorConnected.ContainsKey(parent.EntityId))
                        {
                            m_conveyorConnected.Add(parent.EntityId, new long[] { pistonBase.TopBlockId.Value, pistonBase.EntityId });
                        }
                    }
                }
            }
            else if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_ShipConnector))
            {
                MyObjectBuilder_ShipConnector connector = (MyObjectBuilder_ShipConnector)cubeBlock.GetObjectBuilderCubeBlock();
                IMyEntity connectedEntity = null;
                if (connector.Connected && MyAPIGateway.Entities.TryGetEntityById(connector.ConnectedEntityId, out connectedEntity))
                {
                    if (!m_conveyorConnected.ContainsKey(connectedEntity.Parent.EntityId))
                    {
                        //IMyCubeGrid grid = MyAPIGateway.Entities.GetEntityById(connectedEntity.Parent.EntityId);
                        m_conveyorConnected.Add(connectedEntity.Parent.EntityId, new long[] { connectedEntity.EntityId, connector.EntityId });
                    }
                }
            }
            else if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorAdvancedStator))
            {
                MyObjectBuilder_MotorAdvancedStator stator = (MyObjectBuilder_MotorAdvancedStator)cubeBlock.GetObjectBuilderCubeBlock();
                IMyEntity connectedEntity = null;
                if (stator.RotorEntityId.HasValue && MyAPIGateway.Entities.TryGetEntityById(stator.RotorEntityId.Value, out connectedEntity))
                {
                    IMyEntity parent = connectedEntity.Parent;

                    if (parent is IMyCubeGrid)
                    {
                        if (!m_conveyorConnected.ContainsKey(parent.EntityId))
                        {
                            m_conveyorConnected.Add(parent.EntityId, new long[] { stator.RotorEntityId.Value, stator.EntityId });
                        }
                    }
                }
            }
        }
예제 #6
0
        private static List <IMyCubeGrid> GetConnectedGridList(HashSet <IMyEntity> checkedGrids, List <IMySlimBlock> blocks)
        {
            List <IMyCubeGrid> connectedGrids = new List <IMyCubeGrid>();

            foreach (IMySlimBlock slimBlock in blocks)
            {
                try
                {
                    if (slimBlock.FatBlock != null && slimBlock.FatBlock is IMyCubeBlock)
                    {
                        IMyCubeBlock cubeBlock = (IMyCubeBlock)slimBlock.FatBlock;

                        // Check for Piston
                        if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_PistonBase))
                        {
                            MyObjectBuilder_PistonBase pistonBase = (MyObjectBuilder_PistonBase)cubeBlock.GetObjectBuilderCubeBlock();
                            IMyEntity entity = null;
                            if (MyAPIGateway.Entities.TryGetEntityById(pistonBase.TopBlockId, out entity))
                            {
                                IMyCubeGrid parent = (IMyCubeGrid)entity.Parent;
                                if (!checkedGrids.Contains(parent))
                                {
                                    connectedGrids.Add(parent);
                                }
                            }
                        }
                        else if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_ExtendedPistonBase))
                        {
                            MyObjectBuilder_PistonBase pistonBase = (MyObjectBuilder_PistonBase)cubeBlock.GetObjectBuilderCubeBlock();
                            IMyEntity entity = null;
                            if (MyAPIGateway.Entities.TryGetEntityById(pistonBase.TopBlockId, out entity))
                            {
                                IMyCubeGrid parent = (IMyCubeGrid)entity.Parent;
                                if (!checkedGrids.Contains(parent))
                                {
                                    connectedGrids.Add(parent);
                                }
                            }
                        }
                        // Connector
                        else if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_ShipConnector))
                        {
                            MyObjectBuilder_ShipConnector connector = (MyObjectBuilder_ShipConnector)cubeBlock.GetObjectBuilderCubeBlock();
                            IMyEntity entity = null;
                            if (MyAPIGateway.Entities.TryGetEntityById(connector.ConnectedEntityId, out entity))
                            //IMyEntity entity = MyAPIGateway.Entities.GetEntityById(connector.ConnectedEntityId);
                            //if(entity != null)
                            {
                                IMyCubeGrid parent = (IMyCubeGrid)entity.Parent;
                                if (!checkedGrids.Contains(parent))
                                {
                                    connectedGrids.Add(parent);
                                }
                            }
                        }
                        else if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorAdvancedStator))
                        {
                            MyObjectBuilder_MotorAdvancedStator stator = (MyObjectBuilder_MotorAdvancedStator)cubeBlock.GetObjectBuilderCubeBlock();
                            IMyEntity connectedEntity = null;
                            if (stator.RotorEntityId.HasValue && MyAPIGateway.Entities.TryGetEntityById(stator.RotorEntityId.Value, out connectedEntity))
                            {
                                IMyCubeGrid parent = (IMyCubeGrid)connectedEntity.Parent;
                                if (!checkedGrids.Contains(parent))
                                {
                                    connectedGrids.Add(parent);
                                }
                            }
                        }
                    }
                }
                catch
                {
                    continue;
                }
            }

            return(connectedGrids);
        }