Exemplo n.º 1
0
        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 || m_currentShipController is MyRemoteControl, "Trying to extend control from uncontrolled cockpit!");

                    Sync.Players.TryExtendControl(m_currentShipController, grid);
                }
            }
        }
		public ShipControllerBlock(IMyCubeBlock block)
		{
			m_logger = new Logger(GetType().Name, block);
			Controller = block as MyShipController;
			CubeBlock = block;
			Terminal = block as IMyTerminalBlock;
			Pseudo = new PseudoBlock(block);
		}
Exemplo n.º 3
0
        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;
                }
            }
        }
 public MySyncShipController(MyShipController shipController) :
     base(shipController)
 {
     this.m_shipController = shipController;
 }
Exemplo n.º 5
0
 public MyGroupControlSystem()
 {
     m_currentShipController = null;
     m_controlDirty = false;
     m_firstControlRecalculation = true;
 }
Exemplo n.º 6
0
        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);
                }
            }
        }
Exemplo n.º 7
0
        // Returns true when the first controller has priority
        public static bool HasPriorityOver(MyShipController first, MyShipController second)
        {
            Debug.Assert(first.CubeGrid != null, "Ship controller cube grid was null");
            Debug.Assert(second.CubeGrid != null, "Ship controller cube grid was null");

            if (first.Priority < second.Priority) return true;
            if (first.Priority > second.Priority) return false;

            if (first.CubeGrid.Physics == null && second.CubeGrid.Physics == null)
            {
                return first.CubeGrid.BlocksCount > second.CubeGrid.BlocksCount;
            }
            else if (first.CubeGrid.Physics != null && second.CubeGrid.Physics != null)
            {
                return first.CubeGrid.Physics.Mass > second.CubeGrid.Physics.Mass;
            }
            else
            {
                return first.CubeGrid.Physics == null;
            }
        }
        private void SetupSpaceshipScreen(MyShipController ship)
        {
            m_lightsControlHelper.SetEntity(ship);
            m_dampingControlHelper.SetEntity(ship);
            m_landingGearsControlHelper.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_reactorsControlHelper);

            m_controlMenu.AddItem(m_cameraModeControlHelper);
        }
 public MyGridSelectionSystem(MyShipController shipController)
 {
     m_shipController = shipController;
 }
        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!");

            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);
                }
            }
        }
Exemplo n.º 11
0
 public void AttachedToShipController(MyShipController newShipController)
 {
     ShipController = newShipController;
     OnShipControllerChanged();
 }