示例#1
0
        private static void OnAttach(MySyncPistonBase sync, ref AttachMsg msg, MyNetworkClient sender)
        {
            MyPistonBase pistonBase  = (MyPistonBase)sync.Entity;
            MyEntity     rotorEntity = null;

            if (!MyEntities.TryGetEntityById(msg.TopEntityId, out rotorEntity))
            {
                pistonBase.RetryAttach(msg.TopEntityId);
                Debug.Assert(false, "Could not find top entity to attach to base");
                return;
            }
            MyPistonTop top = (MyPistonTop)rotorEntity;

            Debug.Assert(pistonBase.CubeGrid != top.CubeGrid, "Trying to attach top to base on the same grid");

            if (top.CubeGrid.InScene == false)
            {
                pistonBase.RetryAttach(msg.TopEntityId);
            }
            else
            {
                pistonBase.Attach(top, false);
            }

            if (Sync.IsServer)
            {
                Sync.Layer.SendMessageToAllButOne(ref msg, sender.SteamUserId);
            }
        }
示例#2
0
        public void AttachRotor(MyMotorRotor rotor)
        {
            AttachMsg msg = new AttachMsg();
            msg.EntityId = this.Entity.EntityId;
            msg.AttachableEntityId = rotor.EntityId;

            Sync.Layer.SendMessageToAll(ref msg);
        }
        public void AttachRotor(MyMotorRotor rotor)
        {
            AttachMsg msg = new AttachMsg();

            msg.EntityId           = this.Entity.EntityId;
            msg.AttachableEntityId = rotor.EntityId;

            Sync.Layer.SendMessageToAll(ref msg);
        }
示例#4
0
            public virtual void SendAttachRequest(bool enable)
            {
                var msg = new AttachMsg();

                msg.EntityId = ((MyEntity)m_landingGear).EntityId;
                msg.Enable   = enable;

                Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request);
            }
示例#5
0
            public virtual void InvokeAttachRequest(bool enable)
            {
                Debug.Assert(Sync.IsServer);
                var msg = new AttachMsg();

                msg.EntityId = ((MyEntity)m_landingGear).EntityId;
                msg.Enable   = enable;

                AttachRequest(ref msg, Sync.Clients.LocalClient);
            }
示例#6
0
            private static void AttachFailure(ref AttachMsg msg, MyNetworkClient sender)
            {
                MyEntity entity;

                MyEntities.TryGetEntityById(msg.EntityId, out entity);
                if (entity is MyLandingGear)
                {
                    (entity as MyLandingGear).AttachFailed();
                }
            }
        private static void OnAttach(MySyncMotorBase block, ref AttachMsg msg, MyNetworkClient sender)
        {
            MyMotorBase stator = (MyMotorBase)block.Entity;
            MyEntity rotorEntity = null;
            if (!MyEntities.TryGetEntityById(msg.AttachableEntityId, out rotorEntity))
            {
                Debug.Assert(false, "Could not find rotor entity to attach to stator");
                return;
            }
            MyMotorRotor rotor = (MyMotorRotor)rotorEntity;

            Debug.Assert(stator.CubeGrid != rotor.CubeGrid, "Trying to attach rotor to stator on the same grid");

            stator.Attach(rotor);
        }
        private static void OnAttach(MySyncPistonBase sync, ref AttachMsg msg, MyNetworkClient sender)
        {
            MyPistonBase pistonBase  = (MyPistonBase)sync.Entity;
            MyEntity     rotorEntity = null;

            if (!MyEntities.TryGetEntityById(msg.TopEntityId, out rotorEntity))
            {
                Debug.Assert(false, "Could not find top entity to attach to base");
                return;
            }
            MyPistonTop top = (MyPistonTop)rotorEntity;

            Debug.Assert(pistonBase.CubeGrid != top.CubeGrid, "Trying to attach top to base on the same grid");

            pistonBase.Attach(top);
        }
        private static void OnAttach(MySyncMotorBase block, ref AttachMsg msg, MyNetworkClient sender)
        {
            MyMotorBase stator      = (MyMotorBase)block.Entity;
            MyEntity    rotorEntity = null;

            if (!MyEntities.TryGetEntityById(msg.AttachableEntityId, out rotorEntity))
            {
                Debug.Assert(false, "Could not find rotor entity to attach to stator");
                return;
            }
            MyMotorRotor rotor = (MyMotorRotor)rotorEntity;

            Debug.Assert(stator.CubeGrid != rotor.CubeGrid, "Trying to attach rotor to stator on the same grid");

            stator.Attach(rotor);
        }
示例#10
0
            static void AttachRequest(ref AttachMsg msg, MyNetworkClient sender)
            {
                MyEntity entity;

                MyEntities.TryGetEntityById(msg.EntityId, out entity);
                if (entity is MyLandingGear)
                {
                    var landingGear = entity as MyLandingGear;
                    if (!landingGear.IsFunctional)
                    {
                        return;
                    }
                    if (msg.Enable)
                    {
                        Vector3D pivot;
                        var      otherBody = landingGear.FindBody(out pivot);
                        if (otherBody != null)
                        {
                            var otherEntity = ((MyPhysicsBody)otherBody.UserObject).Entity;

                            var gearClusterMatrix  = landingGear.CubeGrid.Physics.RigidBody.GetRigidBodyMatrix();
                            var otherClusterMatrix = otherBody.GetRigidBodyMatrix();

                            // Calculate world (cluser) matrix of pivot
                            Matrix pivotCluster = gearClusterMatrix;
                            pivotCluster.Translation = landingGear.CubeGrid.Physics.WorldToCluster(pivot);

                            // Convert cluser-space to local space
                            msg.GearPivotPosition = (pivotCluster * Matrix.Invert(gearClusterMatrix)).Translation;
                            msg.OtherPivot.Matrix = pivotCluster * Matrix.Invert(otherClusterMatrix);
                            msg.OtherEntity       = otherEntity.EntityId;
                            AttachSuccess(ref msg, Sync.Clients.LocalClient);
                            Sync.Layer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success);
                        }
                        else
                        {
                            AttachFailure(ref msg, Sync.Clients.LocalClient);
                            Sync.Layer.SendMessageToAll(ref msg, MyTransportMessageEnum.Failure);
                        }
                    }
                    else
                    {
                        AttachSuccess(ref msg, Sync.Clients.LocalClient);
                        Sync.Layer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success);
                    }
                }
            }
示例#11
0
        internal void AttachTop(MyPistonTop topBlock)
        {
            var msg = new AttachMsg();

            Debug.Assert(Entity != null, "null entity when attaching piston top !");
            Debug.Assert(topBlock != null, "null topBlock when attaching piston top !");

            if (Entity != null && topBlock != null)
            {
                msg.EntityId    = Entity.EntityId;
                msg.TopEntityId = topBlock.EntityId;

                Sync.Layer.SendMessageToAll(ref msg);
            }
            else
            {
                MySandboxGame.Log.WriteLine(string.Format("Failed to attach piston top ! Entity value :  {0} top block value : {1}", Entity, topBlock));
            }
        }
示例#12
0
            static void AttachSuccess(ref AttachMsg msg, MyNetworkClient sender)
            {
                MyEntity entity;

                MyEntities.TryGetEntityById(msg.EntityId, out entity);
                if (entity is MyLandingGear)
                {
                    var landingGear = (MyLandingGear)entity;
                    if (msg.Enable)
                    {
                        MyEntity otherEntity;
                        if (MyEntities.TryGetEntityById(msg.OtherEntity, out otherEntity))
                        {
                            landingGear.Attach(otherEntity.Physics.RigidBody, msg.GearPivotPosition, msg.OtherPivot.Matrix);
                        }
                    }
                    else
                    {
                        landingGear.ResetLockConstraint(locked: false);
                    }
                }
            }
示例#13
0
        private static void OnAttach(MySyncPistonBase sync, ref AttachMsg msg, MyNetworkClient sender)
        {
            MyPistonBase pistonBase = (MyPistonBase)sync.Entity;
            MyEntity rotorEntity = null;
            if (!MyEntities.TryGetEntityById(msg.TopEntityId, out rotorEntity))
            {
                pistonBase.RetryAttach(msg.TopEntityId);
                Debug.Assert(false, "Could not find top entity to attach to base");
                return;
            }
            MyPistonTop top = (MyPistonTop)rotorEntity;

            Debug.Assert(pistonBase.CubeGrid != top.CubeGrid, "Trying to attach top to base on the same grid");

            if (top.CubeGrid.InScene == false)
            {
                pistonBase.RetryAttach(msg.TopEntityId);
            }
            else
            {
                pistonBase.Attach(top, false);
            }

            if (Sync.IsServer)
            {
                Sync.Layer.SendMessageToAllButOne(ref msg, sender.SteamUserId);
            }
        }
示例#14
0
 static void AttachSuccess(ref AttachMsg msg, MyNetworkClient sender)
 {
     MyEntity entity;
     MyEntities.TryGetEntityById(msg.EntityId, out entity);
     if (entity is MyLandingGear)
     {
         var landingGear = (MyLandingGear)entity;
         if (msg.Enable)
         {
             MyEntity otherEntity;
             if (MyEntities.TryGetEntityById(msg.OtherEntity, out otherEntity))
             {
                 landingGear.Attach(otherEntity.Physics.RigidBody, msg.GearPivotPosition, msg.OtherPivot.Matrix);
             }
         }
         else
         {
             landingGear.ResetLockConstraint(locked: false);
         }
     }
 }
示例#15
0
            static void AttachRequest(ref AttachMsg msg, MyNetworkClient sender)
            {
                MyEntity entity;
                MyEntities.TryGetEntityById(msg.EntityId, out entity);
                if (entity is MyLandingGear)
                {
                    var landingGear = entity as MyLandingGear;
                    if (!landingGear.IsFunctional)
                        return;
                    if (msg.Enable)
                    {
                        Vector3D pivot;
                        var otherBody = landingGear.FindBody(out pivot);
                        if (otherBody != null)
                        {
                            var otherEntity = ((MyPhysicsBody)otherBody.UserObject).Entity;

                            var gearClusterMatrix = landingGear.CubeGrid.Physics.RigidBody.GetRigidBodyMatrix();
                            var otherClusterMatrix = otherBody.GetRigidBodyMatrix();

                            // Calculate world (cluser) matrix of pivot
                            Matrix pivotCluster = gearClusterMatrix;
                            pivotCluster.Translation = landingGear.CubeGrid.Physics.WorldToCluster(pivot);

                            // Convert cluser-space to local space
                            msg.GearPivotPosition = (pivotCluster * Matrix.Invert(gearClusterMatrix)).Translation;
                            msg.OtherPivot.Matrix = pivotCluster * Matrix.Invert(otherClusterMatrix);
                            msg.OtherEntity = otherEntity.EntityId;
                            AttachSuccess(ref msg, Sync.Clients.LocalClient);
                            Sync.Layer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success);
                        }
                        else
                        {
                            AttachFailure(ref msg, Sync.Clients.LocalClient);
                            Sync.Layer.SendMessageToAll(ref msg, MyTransportMessageEnum.Failure);
                        }
                    }
                    else
                    {
                        AttachSuccess(ref msg, Sync.Clients.LocalClient);
                        Sync.Layer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success);
                    }
                }
            }
示例#16
0
            public virtual void InvokeAttachRequest(bool enable)
            {
                Debug.Assert(Sync.IsServer);
                var msg = new AttachMsg();
                msg.EntityId = ((MyEntity)m_landingGear).EntityId;
                msg.Enable = enable;

                AttachRequest(ref msg, Sync.Clients.LocalClient);
            }
示例#17
0
            public virtual void SendAttachRequest(bool enable)
            {
                var msg = new AttachMsg();
                msg.EntityId = ((MyEntity)m_landingGear).EntityId;
                msg.Enable = enable;

                Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request);
            }
示例#18
0
 private static void AttachFailure(ref AttachMsg msg, MyNetworkClient sender)
 {
     MyEntity entity;
     MyEntities.TryGetEntityById(msg.EntityId, out entity);
     if (entity is MyLandingGear)
     {
         (entity as MyLandingGear).AttachFailed();
     }
 }
示例#19
0
        private static void OnAttach(MySyncPistonBase sync, ref AttachMsg msg, MyNetworkClient sender)
        {
            MyPistonBase pistonBase = (MyPistonBase)sync.Entity;
            MyEntity rotorEntity = null;
            if (!MyEntities.TryGetEntityById(msg.TopEntityId, out rotorEntity))
            {
                Debug.Assert(false, "Could not find top entity to attach to base");
                return;
            }
            MyPistonTop top = (MyPistonTop)rotorEntity;

            Debug.Assert(pistonBase.CubeGrid != top.CubeGrid, "Trying to attach top to base on the same grid");

            pistonBase.Attach(top);
        }
示例#20
0
        internal void AttachTop(MyPistonTop topBlock)
        {
            var msg = new AttachMsg();
            Debug.Assert(Entity != null, "null entity when attaching piston top !");
            Debug.Assert(topBlock != null, "null topBlock when attaching piston top !");

            if (Entity != null && topBlock != null)
            {
                msg.EntityId = Entity.EntityId;
                msg.TopEntityId = topBlock.EntityId;

                Sync.Layer.SendMessageToAll(ref msg);
            }
            else
            {
                MySandboxGame.Log.WriteLine(string.Format("Failed to attach piston top ! Entity value :  {0} top block value : {1}",Entity,topBlock));
            }
        }