Exemple #1
0
        public override unsafe void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.SyncFlag = true;
            MyResourceSinkComponent component = new MyResourceSinkComponent(1);

            component.Init(this.MotorDefinition.ResourceSinkGroup, this.MotorDefinition.RequiredPowerInput, new Func <float>(this.ComputeRequiredPowerInput));
            component.IsPoweredChanged += new Action(this.Receiver_IsPoweredChanged);
            base.ResourceSink           = component;
            base.Init(objectBuilder, cubeGrid);
            base.SlimBlock.ComponentStack.IsFunctionalChanged += new Action(this.ComponentStack_IsFunctionalChanged);
            base.ResourceSink.Update();
            this.m_dummyDisplacement.SetLocalValue(0f);
            this.m_dummyDisplacement.ValueChanged += new Action <SyncBase>(this.m_dummyDisplacement_ValueChanged);
            this.LoadDummyPosition();
            MyObjectBuilder_MotorBase base2 = objectBuilder as MyObjectBuilder_MotorBase;

            if ((Sync.IsServer && (base2.RotorEntityId != null)) && (base2.RotorEntityId.Value != 0))
            {
                MyMechanicalConnectionBlockBase.State *statePtr1;
                MyMechanicalConnectionBlockBase.State  state = new MyMechanicalConnectionBlockBase.State {
                    TopBlockId = base2.RotorEntityId
                };
                statePtr1->Welded            = (base2.WeldedEntityId != null) || base2.ForceWeld;
                statePtr1                    = (MyMechanicalConnectionBlockBase.State *) ref state;
                base.m_connectionState.Value = state;
            }
            base.AddDebugRenderComponent(new MyDebugRenderComponentMotorBase(this));
            base.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;
        }
Exemple #2
0
 private bool isAttached_motor(AttachedGrids partner)
 {
     foreach (IMySlimBlock motorBase in allMotorBases)
     {
         MyObjectBuilder_MotorBase builder_base = motorBase.GetObjectBuilder() as MyObjectBuilder_MotorBase;
         long rotorEntityId = builder_base.RotorEntityId;
         foreach (IMySlimBlock motorRotor in partner.allMotorRotors)
         {
             if (rotorEntityId == motorRotor.FatBlock.EntityId)
             {
                 log("matched " + myGrid.DisplayName + " : " + motorBase.FatBlock.DefinitionDisplayNameText + " to " + partner.myGrid.DisplayName + " : " + motorRotor.FatBlock.DefinitionDisplayNameText, "isAttached_motor()", 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);
        }