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); } }
public void AttachRotor(MyMotorRotor rotor) { AttachMsg msg = new AttachMsg(); msg.EntityId = this.Entity.EntityId; msg.AttachableEntityId = rotor.EntityId; Sync.Layer.SendMessageToAll(ref msg); }
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); }
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); }
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); }
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); } } }
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)); } }
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); } } }
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); } } }
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)); } }