private void SetupSpaceshipScreen(MyShipController ship) { m_lightsControlHelper.SetEntity(ship); m_dampingControlHelper.SetEntity(ship); m_landingGearsControlHelper.SetEntity(ship); m_connectorControlHelper.SetEntity(ship); m_reactorsControlHelper.SetEntity(ship); m_showBuildScreenControlHelper.SetEntity(ship); m_showTerminalControlHelper.SetEntity(ship); m_controlMenu = new MyGuiScreenControlMenu(); m_controlMenu.AddItem(m_showTerminalControlHelper); m_controlMenu.AddItem(m_showBuildScreenControlHelper); m_controlMenu.AddItem(m_quickLoadControlHelper); m_controlMenu.AddItem(m_hudToggleControlHelper); m_controlMenu.AddItem(m_lightsControlHelper); m_controlMenu.AddItem(m_dampingControlHelper); m_controlMenu.AddItem(m_landingGearsControlHelper); m_controlMenu.AddItem(m_connectorControlHelper); m_controlMenu.AddItem(m_reactorsControlHelper); m_controlMenu.AddItem(m_cameraModeControlHelper); }
public void AddControllerBlock(MyShipController controllerBlock) { bool result = m_groupControllers.Add(controllerBlock); //Debug.Assert(result, "Controller block was already present in the control group's controller list!"); if (m_groupControllers.Count == 1 && controllerBlock != m_currentShipController) { m_currentShipController = null; } bool newControllerHasPriority = m_currentShipController == null || MyShipController.HasPriorityOver(controllerBlock, m_currentShipController); if (newControllerHasPriority) { m_controlDirty = true; } if (Sync.IsServer) { if (m_currentShipController != null && newControllerHasPriority) { Sync.Players.ReduceAllControl(m_currentShipController); } } }
protected override void ClientWrite(VRage.Library.Collections.BitStream stream) { base.ClientWrite(stream); MyShipController controller = MySession.Static.ControlledEntity as MyShipController; stream.WriteBool(m_grid != null && controller != null); if (m_grid != null && controller != null) { stream.WriteBool(m_grid.IsStatic); if (m_grid.IsStatic == false) { stream.WriteBool(controller != null); if (controller != null) { stream.WriteInt64(controller.EntityId); Vector2 rotation = controller.RotationIndicator; stream.WriteFloat(rotation.X); stream.WriteFloat(rotation.Y); stream.WriteHalf(controller.RollIndicator); Vector3 position = controller.MoveIndicator; stream.WriteHalf(position.X); stream.WriteHalf(position.Y); stream.WriteHalf(position.Z); } } } }
private void UpdateControl() { MyShipController preferredController = null; foreach (var controller in m_groupControllers) { if (preferredController == null) { preferredController = controller; } else { if (MyShipController.HasPriorityOver(controller, preferredController)) { preferredController = controller; } } } m_currentShipController = preferredController; // The server synchronizes control to all clients, but current ship controller is determined by each client separately if (Sync.IsServer && m_currentShipController != null) { var newController = m_currentShipController.ControllerInfo.Controller; foreach (var grid in m_cubeGrids) { Debug.Assert(m_firstControlRecalculation || Sync.Players.GetControllingPlayer(grid) == null); Debug.Assert(m_currentShipController.ControllerInfo.Controller != null, "Trying to extend control from uncontrolled cockpit!"); Sync.Players.TryExtendControl(m_currentShipController, grid); } } }
private static void LoadAsync(long ownerId, long characterId, Action <MyCharacter> loadingDoneHandler) { MyEntity entity; MyEntities.TryGetEntityById(ownerId, out entity); MyShipController owner = entity as MyShipController; if (owner != null) { if (owner.Pilot != null) { loadingDoneHandler(owner.Pilot); MySession.Static.Players.UpdatePlayerControllers(ownerId); } else { MyEntity characterEntity; MyEntities.TryGetEntityById(characterId, out characterEntity); MyCharacter character = characterEntity as MyCharacter; loadingDoneHandler(character); } } else { loadingDoneHandler(null); } }
public static void GooeyProgram(MyShipController block) { AutopilotCommands cmds = AutopilotCommands.GetOrCreate(block); if (cmds != null) { cmds.StartGooeyProgramming(); } }
public float GetGroupPriority(int frameCountWithoutSync, MyClientInfo client) { ProfilerShort.Begin("MyEntityInventoryStateGroup::GetGroupPriority"); InventoryClientData clientData = m_clientInventoryUpdate[client.EndpointId.Value]; List <MyPhysicalInventoryItem> items = Inventory.GetItems(); if (clientData.Dirty == false && clientData.FailedIncompletePackets.Count == 0) { ProfilerShort.End(); return(-1); } if (clientData.FailedIncompletePackets.Count > 0) { ProfilerShort.End(); return(1.0f * frameCountWithoutSync); } MyClientState state = (MyClientState)client.State; if (Inventory.Owner is MyCharacter) { MyCharacter character = Inventory.Owner as MyCharacter; MyPlayer player = MyPlayer.GetPlayerFromCharacter(character); if (player == null && character.IsUsing != null) { MyShipController cockpit = (character.IsUsing as MyShipController); if (cockpit != null && cockpit.ControllerInfo.Controller != null) { player = cockpit.ControllerInfo.Controller.Player; } } if (player != null && player.Id.SteamId == client.EndpointId.Value) { ProfilerShort.End(); return(1.0f * frameCountWithoutSync); } } if (state.ContextEntity is MyCharacter && state.ContextEntity == Inventory.Owner) { ProfilerShort.End(); return(1.0f * frameCountWithoutSync); } if (state.Context == MyClientState.MyContextKind.Inventory || state.Context == MyClientState.MyContextKind.Building || (state.Context == MyClientState.MyContextKind.Production && Inventory.Owner is MyAssembler)) { ProfilerShort.End(); return(GetPriorityStateGroup(client) * frameCountWithoutSync); } ProfilerShort.End(); return(0); }
void grid_OnPhysicsChanged(MyEntity obj) { if (m_grid.GridSystems != null && m_grid.GridSystems.ControlSystem != null) { MyShipController controller = m_grid.GridSystems.ControlSystem.GetShipController(); if (controller != null) { InitControl(controller); } } }
public static void AddController(MyShipController controller) { FieldInfo fieldMainCockpit = typeof(MyShipController).GetField("m_isMainCockpit", BindingFlags.Instance | BindingFlags.NonPublic); if (fieldMainCockpit == null) { throw new NullReferenceException("MyShipController.m_isMainCockpit does not exist or has unexpected binding"); } VRage.Sync.SyncBase valueMainCockpit = (VRage.Sync.SyncBase)fieldMainCockpit.GetValue(controller); valueMainCockpit.ValueChanged += (obj) => MainCockpitChanged(controller); }
private void WritePhysics(BitStream stream, MyEntity controlledEntity) { IMyReplicable controlledReplicable = MyExternalReplicable.FindByObject(controlledEntity); stream.WriteBool(controlledReplicable != null); if (controlledReplicable == null) { return; } IMyStateGroup stateGroup = null; bool useCharacterOnServer = controlledEntity is MyCharacter && MyFakes.ENABLE_CHARACTER_CONTROL_ON_SERVER; bool useGridOnServer = controlledEntity is MyCubeGrid && MyFakes.ENABLE_SHIP_CONTROL_ON_SERVER; MyShipController controller = MySession.Static.ControlledEntity as MyShipController; bool hasWheels = controller != null && controller.HasWheels; long? supportId = null; if (useCharacterOnServer || (useGridOnServer && hasWheels == false)) { MyEntityPositionVerificationStateGroup group = controlledReplicable.FindStateGroup <MyEntityPositionVerificationStateGroup>(); stateGroup = group; supportId = group.GetSupportID(); } else { stateGroup = controlledReplicable.FindStateGroup <MyEntityPhysicsStateGroup>(); } stream.WriteBool(useCharacterOnServer || (useGridOnServer && hasWheels == false)); stream.WriteBool(stateGroup != null); if (stateGroup == null) { return; } stream.WriteBool(supportId.HasValue); if (supportId.HasValue) { stream.WriteInt64(supportId.Value); } bool isResponsible = MyEntityPhysicsStateGroup.ResponsibleForUpdate(controlledEntity, new EndpointId(Sync.MyId)); stream.WriteBool(isResponsible); if (isResponsible) { stateGroup.Serialize(stream, EndpointId, ClientTimeStamp, 0, 1024 * 1024); } }
private static void MainCockpitChanged(MyShipController controller) { MyGroupControlSystem system = controller.CubeGrid.GridSystems.ControlSystem; MethodInfo OnControlReleased = typeof(MyGridSelectionSystem).GetMethod("OnControlReleased", BindingFlags.Instance | BindingFlags.NonPublic); if (OnControlReleased == null) { throw new NullReferenceException("MyGridSelectionSystem.OnControlReleased does not exist or has unexpected binding"); } MethodInfo OnControlAcquired = typeof(MyGridSelectionSystem).GetMethod("OnControlAcquired", BindingFlags.Instance | BindingFlags.NonPublic); if (OnControlAcquired == null) { throw new NullReferenceException("MyGridSelectionSystem.OnControlAcquired does not exist or has unexpected binding"); } bool enabled = controller.IsMainCockpit; foreach (MySlimBlock block in controller.CubeGrid.GetBlocks()) { MyShipController otherController = block.FatBlock as MyShipController; if (otherController != null && otherController.EnableShipControl && otherController != controller && otherController.ControllerInfo.Controller != null) { MyGridSelectionSystem selectSystem = otherController.GridSelectionSystem; if (enabled) { if (system != null) { system.RemoveControllerBlock(otherController); } if (selectSystem != null) { OnControlReleased.Invoke(selectSystem, null); } } else { if (system != null) { system.AddControllerBlock(otherController); } if (selectSystem != null) { OnControlAcquired.Invoke(selectSystem, null); } } } } }
public ControllableThrusters(IMyShipController controller) { _thisIController = controller; _thisController = (MyShipController)controller; _thisController.ControlThrusters = true; controller.GetNaturalGravity(); _thrusters.Add(ThrustDirection.Forward, new ConcurrentCachingList <ControllableThruster>()); _thrusters.Add(ThrustDirection.Back, new ConcurrentCachingList <ControllableThruster>()); _thrusters.Add(ThrustDirection.Up, new ConcurrentCachingList <ControllableThruster>()); _thrusters.Add(ThrustDirection.Down, new ConcurrentCachingList <ControllableThruster>()); _thrusters.Add(ThrustDirection.Left, new ConcurrentCachingList <ControllableThruster>()); _thrusters.Add(ThrustDirection.Right, new ConcurrentCachingList <ControllableThruster>()); }
private void TryGetShipController() { try { foreach (var block2 in CubeGrid.GetFatBlocks()) { if (block2 != null && block2 is MyShipController) { var newController = block2 as MyShipController; m_shipController = newController; break; } } } catch (Exception e) { Debug.HandleException(e); } }
private void Eject(IMyPlayer player) { if (player.Controller.ControlledEntity.Entity.Parent != null) { MyAPIGateway.Utilities.SendMessage(SenderSteamId, "ejecting", player.DisplayName); // To eject the player from controlling a cube, like a turret or cryo. player.Controller.ControlledEntity.Use(); MyShipController shipController = player.Controller.ControlledEntity as MyShipController; // To eject from any cockpit the player's character is inside of. shipController?.Use(); } else { MyAPIGateway.Utilities.SendMessage(SenderSteamId, "player", "{0} is not a pilot", player.DisplayName); } }
public void AddControllerBlock(MyShipController controllerBlock) { bool result = m_groupControllers.Add(controllerBlock); bool found = false; if (m_currentShipController != null && m_currentShipController.CubeGrid != controllerBlock.CubeGrid) { var group = MyCubeGridGroups.Static.Logical.GetGroup(controllerBlock.CubeGrid); if (group != null) { foreach (var node in group.Nodes) { if (node.NodeData == m_currentShipController.CubeGrid) { found = true; break; } } } } if (found == false && m_currentShipController != null && m_currentShipController.CubeGrid != controllerBlock.CubeGrid) { RemoveControllerBlock(m_currentShipController); m_currentShipController = null; } bool newControllerHasPriority = m_currentShipController == null || MyShipController.HasPriorityOver(controllerBlock, m_currentShipController); if (newControllerHasPriority) { m_controlDirty = true; } if (Sync.IsServer) { if (m_currentShipController != null && newControllerHasPriority) { Sync.Players.ReduceAllControl(m_currentShipController); } } }
public void RemoveControllerBlock(MyShipController controllerBlock) { bool result = m_groupControllers.Remove(controllerBlock); Debug.Assert(result, "Controller block was not present in the control group's controller list!"); if (controllerBlock == m_currentShipController) { m_controlDirty = true; } if (Sync.IsServer) { if (controllerBlock == m_currentShipController) { Sync.Players.ReduceAllControl(m_currentShipController); m_currentShipController = null; } } }
protected override void ClientWrite(VRage.Library.Collections.BitStream stream, EndpointId forClient, uint timestamp, int maxBitPosition) { base.ClientWrite(stream, forClient, timestamp, maxBitPosition); stream.Write(Entity.WorldMatrix.Translation); MyShipController controller = MySession.Static.ControlledEntity as MyShipController; stream.WriteBool(m_grid != null && controller != null); if (m_grid != null && controller != null) { stream.WriteBool(m_grid.IsStatic); if (m_grid.IsStatic == false) { stream.WriteBool(controller != null); if (controller != null) { stream.WriteInt64(controller.EntityId); Vector2 rotation = controller.RotationIndicator; stream.WriteFloat(rotation.X); stream.WriteFloat(rotation.Y); stream.WriteHalf(controller.RollIndicator); Vector3 position = controller.MoveIndicator; stream.WriteHalf(position.X); stream.WriteHalf(position.Y); stream.WriteHalf(position.Z); Vector3D gridPosition = m_grid.PositionComp.GetPosition(); MyGridPhysicsStateGroup.WriteSubgrids(m_grid, stream, ref forClient, timestamp, maxBitPosition, m_lowPositionOrientation, ref gridPosition, ref m_currentSentPosition); } } } }
private bool IsGridControlled(MyCubeGrid grid) { MyShipController shipController = grid.GridSystems.ControlSystem.GetShipController(); return((shipController != null) && ReferenceEquals(shipController.CubeGrid, grid)); }
public MySyncShipController(MyShipController shipController) : base(shipController) { this.m_shipController = shipController; }
public void AttachedToShipController(MyShipController newShipController) { ShipController = newShipController; OnShipControllerChanged(); }
public MyGridSelectionSystem(MyShipController shipController) { m_shipController = shipController; }
public MyGroupControlSystem() { m_currentShipController = null; m_controlDirty = false; m_firstControlRecalculation = true; }
/// <summary> /// Apply the calculated force ratios to the controller. /// </summary> public void MoveAndRotate() { CheckGrid(); //Log.DebugLog("moveForceRatio: " + moveForceRatio + ", rotateForceRatio: " + rotateForceRatio + ", move length: " + moveForceRatio.Length(), "MoveAndRotate()"); // if all the force ratio values are 0, Autopilot has to stop the ship, MoveAndRotate will not if (m_moveForceRatio == Vector3.Zero && m_rotateTargetVelocity == Vector3.Zero) { //Log.DebugLog("Stopping the ship, move: " + m_moveForceRatio + ", rotate: " + m_rotateTargetVelocity); // should not toggle dampeners, grid may just have landed MoveAndRotateStop(false); return; } if (m_moveForceRatio != Vector3.Zero && CheckStuck(WriggleAfter)) { ulong upWoMove = Globals.UpdateCount - m_lastAccel; if (m_rotateForceRatio != Vector3.Zero) { // wriggle float wriggle = (upWoMove - WriggleAfter) * 0.0001f; //Log.DebugLog("wriggle: " + wriggle + ", updates w/o moving: " + upWoMove); m_rotateForceRatio.X += (0.5f - (float)Globals.Random.NextDouble()) * wriggle; m_rotateForceRatio.Y += (0.5f - (float)Globals.Random.NextDouble()) * wriggle; m_rotateForceRatio.Z += (0.5f - (float)Globals.Random.NextDouble()) * wriggle; } // increase force m_moveForceRatio *= 1f + (upWoMove - WriggleAfter) * 0.1f; } // clamp values Vector3 moveControl; moveControl.X = MathHelper.Clamp(m_moveForceRatio.X, -1f, 1f); moveControl.Y = MathHelper.Clamp(m_moveForceRatio.Y, -1f, 1f); moveControl.Z = MathHelper.Clamp(m_moveForceRatio.Z, -1f, 1f); Vector3 rotateControl = -m_rotateForceRatio; // control torque is opposite of move indicator Vector3.ClampToSphere(ref rotateControl, 1f); m_stopped = false; MyShipController controller = Block.Controller; MyAPIGateway.Utilities.TryInvokeOnGameThread(() => { //Log.DebugLog("rotate control: " + rotateControl + ", previous: " + m_prevRotateControl + ", delta: " + (rotateControl - m_prevRotateControl), "MoveAndRotate()"); if (Block.Controller.GridGyroSystem != null) { DirectionGrid gridRotate = ((DirectionBlock)rotateControl).ToGrid(Block.CubeBlock); Block.Controller.GridGyroSystem.ControlTorque = gridRotate; } else { Log.DebugLog("No gyro system"); } MyEntityThrustComponent thrustComponent = Block.CubeGrid.Components.Get <MyEntityThrustComponent>(); if (thrustComponent != null) { DirectionGrid gridMove = ((DirectionBlock)moveControl).ToGrid(Block.CubeBlock); thrustComponent.ControlThrust = gridMove; } else { Log.DebugLog("No thrust component"); } }); }