private void OnCockpitEnter(VRage.Game.ModAPI.Interfaces.IMyControllableEntity arg1, VRage.Game.ModAPI.Interfaces.IMyControllableEntity arg2)
        {
            string strRes = "";

            if (arg2 is Sandbox.Game.Entities.MyCockpit)
            {
                IMyTerminalBlock cockpit    = arg2 as IMyTerminalBlock;
                List <IMyBeacon> allBeacons = new List <IMyBeacon>();
                List <VRage.Game.ModAPI.IMySlimBlock> blocks = new List <VRage.Game.ModAPI.IMySlimBlock>();
                cockpit.CubeGrid.GetBlocks(blocks);

                if (!blocks.Exists(x => x.FatBlock != null && x.FatBlock.GetType().ToString() == "Sandbox.Game.Entities.Cube.MyBeacon"))
                {
                    strRes += "  * Grid does not have a beacon. It will be deleted on next cleanup.\n";
                }
                if (cockpit.CubeGrid.BigOwners.Count == 0)
                {
                    strRes += "  * Grid does not have an owner. It will be deleted on next cleanup.\n";
                }
                if (cockpit.CubeGrid.DisplayName.Contains("Grid"))
                {
                    strRes += "  * Grid does not have a unique name. Cannot have \"Grid\" in the name.\n";
                }
                if (strRes.Length > 0)
                {
                    strRes = "!!!WARNING!!! Please fix the following issues:\n" + strRes;
                }
                MyAPIGateway.Utilities.ShowNotification(strRes, 6000, "Red");
            }
        }
Beispiel #2
0
        public Ship(IMyCubeGrid ent, long id, String fleetName)
        {
            this.fleetname     = fleetName;
            _cubeGrid          = ent;
            GridTerminalSystem = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(_cubeGrid);

            SetOwner(id);
            List <Sandbox.ModAPI.IMyTerminalBlock> remoteControls = new List <Sandbox.ModAPI.IMyTerminalBlock>();

            GridTerminalSystem.GetBlocksOfType <IMyRemoteControl>(remoteControls);
            GridTerminalSystem.GetBlocksOfType <IMyCubeBlock>(AllBlocks);
            ShipControls = remoteControls.FirstOrDefault() != null?remoteControls.First() as Sandbox.Game.Entities.IMyControllableEntity : null;

            _ownerId = id;

            if (ShipControls == null)
            {
                return;
            }

            DetectReactors();
            LocateShipComponets();
            ResetHealthMax();
            SetupRescanDelay();
            FindAntennasAndBeacons();
            ConfigureAntennas();
        }
 void IMyPlayerCollection.ReduceControl(IMyControllableEntity entityWhichKeepsControl, IMyEntity entityWhichLoosesControl)
 {
     var e1 = entityWhichKeepsControl as Sandbox.Game.Entities.IMyControllableEntity;
     var e2 = entityWhichLoosesControl as MyEntity;
     if (e1 != null && e2 != null)
         ReduceControl(e1, e2);
 }
Beispiel #4
0
        //private void SettingsRequest(ulong steamid)
        //{
        //	NetSettings.SetValue(Settings.Static);

        //	Tools.Debug(MyAPIGateway.Utilities.SerializeToXML(Settings.Static));

        //}

        private void Changed(VRage.Game.ModAPI.Interfaces.IMyControllableEntity o, VRage.Game.ModAPI.Interfaces.IMyControllableEntity n)
        {
            foreach (WeaponBase w in GridWeapons)
            {
                w.State.Value &= ~WeaponState.ManualShoot;
            }

            GridWeapons.Clear();
            ControlledGridId = 0;

            ActiveTurret = n?.Entity as IMyLargeTurretBase;

            if (ActiveTurret == null)
            {
                ActiveShipController = n?.Entity as IMyShipController;
                SelectedDefinitionId = Tools.GetSelectedHotbarDefinition(ActiveShipController);
            }

            MyCubeGrid grid = (n?.Entity as MyCubeBlock)?.CubeGrid;

            if (grid != null)
            {
                ControlledGridId = grid.EntityId;
                foreach (MyCubeBlock block in grid.GetFatBlocks())
                {
                    WeaponControlLayer layer = block.GameLogic.GetAs <WeaponControlLayer>();

                    if (layer != null)
                    {
                        GridWeapons.Add(layer.Weapon);
                    }
                }
            }
        }
 void IMyPlayerCollection.TryExtendControl(IMyControllableEntity entityWithControl, IMyEntity entityGettingControl)
 {
     var e1 = entityWithControl as Sandbox.Game.Entities.IMyControllableEntity;
     var e2 = entityGettingControl as MyEntity;
     if (e1 != null && e2 != null)
         TryExtendControl(e1, e2);
 }
Beispiel #6
0
        public DroneNavigation(IMyCubeGrid ship, IMyControllableEntity shipControls,
                               List <IMyEntity> nearbyFloatingObjects)
        {
            //stuff passed from sip
            _shipControls          = shipControls;
            Ship                   = ship;
            GridTerminalSystem     = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(ship);
            _nearbyFloatingObjects = nearbyFloatingObjects;

            var value = (ship.LocalAABB.Max - ship.LocalAABB.Center).Length();

            if (ship.Physics.Mass > 100000)
            {
                FollowRange = 600 + value;
            }
            else
            {
                FollowRange = 400 + value;
            }

            ShipOrientation();
            FindGyros();

            _initialized = true;
        }
 bool IMyPlayerCollection.HasExtendedControl(IMyControllableEntity firstEntity, IMyEntity secondEntity)
 {
     var e1 = firstEntity as Sandbox.Game.Entities.IMyControllableEntity;
     var e2 = secondEntity as MyEntity;
     if (e1 != null && e2 != null)
         return HasExtendedControl(e1, e2);
     return false;
 }
 bool IMyPlayerCollection.TryReduceControl(IMyControllableEntity entityWhichKeepsControl, IMyEntity entityWhichLoosesControl)
 {
     var e1 = entityWhichKeepsControl as Sandbox.Game.Entities.IMyControllableEntity;
     var e2 = entityWhichLoosesControl as MyEntity;
     if (e1 != null && e2 != null)
         return TryReduceControl(e1, e2);
     return false;
 }
Beispiel #9
0
 public static IMyEntity FindLookAtEntity(IMyControllableEntity controlledEntity, bool findShips, bool findCubes, bool findPlayers, bool findAsteroids, bool findPlanets, bool findReplicable, bool ignoreProjection)
 {
     IMyEntity entity;
     double distance;
     Vector3D hitPoint;
     FindLookAtEntity(controlledEntity, true, ignoreProjection, out entity, out distance, out hitPoint, findShips, findCubes, findPlayers, findAsteroids, findPlanets, findReplicable);
     return entity;
 }
Beispiel #10
0
        public static IMyEntity FindLookAtEntity(IMyControllableEntity controlledEntity, bool findShips, bool findCubes, bool findPlayers, bool findAsteroids, bool findPlanets, bool findReplicable, bool ignoreProjection)
        {
            IMyEntity entity;
            double    distance;
            Vector3D  hitPoint;

            FindLookAtEntity(controlledEntity, true, ignoreProjection, out entity, out distance, out hitPoint, findShips, findCubes, findPlayers, findAsteroids, findPlanets, findReplicable);
            return(entity);
        }
        void IMyPlayerCollection.TryExtendControl(IMyControllableEntity entityWithControl, IMyEntity entityGettingControl)
        {
            var e1 = entityWithControl as Sandbox.Game.Entities.IMyControllableEntity;
            var e2 = entityGettingControl as MyEntity;

            if (e1 != null && e2 != null)
            {
                TryExtendControl(e1, e2);
            }
        }
        void IMyPlayerCollection.ReduceControl(IMyControllableEntity entityWhichKeepsControl, IMyEntity entityWhichLoosesControl)
        {
            var e1 = entityWhichKeepsControl as Sandbox.Game.Entities.IMyControllableEntity;
            var e2 = entityWhichLoosesControl as MyEntity;

            if (e1 != null && e2 != null)
            {
                ReduceControl(e1, e2);
            }
        }
        bool IMyPlayerCollection.TryReduceControl(IMyControllableEntity entityWhichKeepsControl, IMyEntity entityWhichLoosesControl)
        {
            var e1 = entityWhichKeepsControl as Sandbox.Game.Entities.IMyControllableEntity;
            var e2 = entityWhichLoosesControl as MyEntity;

            if (e1 != null && e2 != null)
            {
                return(TryReduceControl(e1, e2));
            }
            return(false);
        }
        bool IMyPlayerCollection.HasExtendedControl(IMyControllableEntity firstEntity, IMyEntity secondEntity)
        {
            var e1 = firstEntity as Sandbox.Game.Entities.IMyControllableEntity;
            var e2 = secondEntity as MyEntity;

            if (e1 != null && e2 != null)
            {
                return(HasExtendedControl(e1, e2));
            }
            return(false);
        }
Beispiel #15
0
        public void translate_linear_input(Vector3 input_thrust, VRage.Game.ModAPI.Interfaces.IMyControllableEntity current_controller)
        {
            var controller = current_controller as MyShipController;

            if (controller?.CubeGrid != _grid)
            {
                reset_user_input(reset_gyros_only: false);
                return;
            }

            Matrix cockpit_matrix;

            controller.Orientation.GetMatrix(out cockpit_matrix);
            _manual_thrust        = Vector3.Clamp(Vector3.Transform(input_thrust, cockpit_matrix), -Vector3.One, Vector3.One);
            _under_player_control = true;
        }
Beispiel #16
0
        public ThrusterGyroControls(IMyEntity entity, VRage.Game.ModAPI.Interfaces.IMyControllableEntity cont)
        {
            _remoteControl = cont;
            _grid          = entity as IMyCubeGrid;
            _ship          = entity;

            if (_grid != null)
            {
                _gridTerminalSystem = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(_grid);
            }

            ShipOrientation();
            RefreshGyros();
            RefreshThrusters();
            Util.GetInstance().Log("inside", _logPath);
        }
Beispiel #17
0
        public NavigationControls(IMyEntity entity, VRage.Game.ModAPI.Interfaces.IMyControllableEntity cont)
        {
            _remoteControl = cont;
            _grid          = entity as IMyCubeGrid;
            _ship          = entity;

            if (_grid != null)
            {
                _gridTerminalSystem = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(_grid);
            }

            ShipOrientation();
            RefreshGyros();
            RefreshThrusters();
            Logger.Debug("Navigation Controls Online: " + IsOperational());
        }
Beispiel #18
0
        public void translate_rotation_input(Vector3 input_rotation, VRage.Game.ModAPI.Interfaces.IMyControllableEntity current_controller)
        {
            var controller = current_controller as MyShipController;

            if (controller == null || controller.CubeGrid != _grid)
            {
                reset_user_input(reset_gyros_only: false);
                return;
            }

            Matrix cockpit_matrix;

            controller.Orientation.GetMatrix(out cockpit_matrix);
            _target_rotation.X    = input_rotation.X * (-0.05f);
            _target_rotation.Y    = input_rotation.Y * (-0.05f);
            _target_rotation.Z    = input_rotation.Z * (-0.2f);
            _target_rotation      = Vector3.Transform(_target_rotation, cockpit_matrix);
            _under_player_control = true;
        }
Beispiel #19
0
        private void OnPlayerController(IMyControllableEntity arg1, IMyControllableEntity arg2)
        {
            try
            {
                var            ent1 = arg1 as MyEntity;
                var            ent2 = arg2 as MyEntity;
                HashSet <long> players;

                if (ent1 != null)
                {
                    var cube = ent1 as MyCubeBlock;
                    if (cube != null && PlayerGrids.TryGetValue(cube.CubeGrid, out players) && arg2 != null)
                    {
                        players.Remove(arg2.ControllerInfo.ControllingIdentityId);

                        if (players.Count == 0)
                        {
                            PlayerGridPool.Return(players);
                        }
                    }
                }
                if (ent2 != null)
                {
                    var cube = ent2 as MyCubeBlock;

                    if (cube != null)
                    {
                        if (PlayerGrids.TryGetValue(cube.CubeGrid, out players))
                        {
                            players.Add(arg2.ControllerInfo.ControllingIdentityId);
                        }
                        else
                        {
                            players = PlayerGridPool.Get();
                            players.Add(arg2.ControllerInfo.ControllingIdentityId);
                            PlayerGrids[cube.CubeGrid] = players;
                        }
                    }
                }
            }
            catch (Exception ex) { Log.Line($"Exception in OnPlayerController: {ex}"); }
        }
Beispiel #20
0
 private void Controller_ControlledEntityChanged(VRage.Game.ModAPI.Interfaces.IMyControllableEntity arg1,
                                                 VRage.Game.ModAPI.Interfaces.IMyControllableEntity arg2)
 {
     if (arg2 != null && arg2.Entity is IMyCharacter)
     {
         MyAPIGateway.Utilities.InvokeOnGameThread(() =>
         {
             try
             {
                 if (MyAPIGateway.Session != null && MyAPIGateway.Session.Player != null)
                 {
                     PlayerInit(MyAPIGateway.Session.Player.PlayerID);
                 }
             }
             catch (Exception e)
             {
                 MyLog.Default.WriteLine($"ERROR PlayerInit Entity Change: {e.Message}");
                 MyLog.Default.Flush();
             }
         });
         MyAPIGateway.Session.Player.Controller.ControlledEntityChanged -= Controller_ControlledEntityChanged;
     }
 }
        public override void UpdateBeforeSimulation10()
        {
            base.UpdateBeforeSimulation10();

            MyAPIGateway.Parallel.Start(delegate {
                try
                {
                    if (!logicEnabled || beacon == null || !beacon.IsWorking || client == null)
                    {
                        return;
                    }

                    if (Vector3D.Distance(client.GetPosition(), beacon.GetPosition()) < beacon.Radius)
                    {
                        playerInArea = true;
                        character    = client.Character;
                        controller   = character as VRage.Game.ModAPI.Interfaces.IMyControllableEntity;
                        var drill    = MyAPIGateway.Session?.Player?.Character?.EquippedTool as IMyHandDrill;

                        if (character.EquippedTool is IMyHandDrill && drill != null)
                        {
                            var controlEnt = character as Sandbox.Game.Entities.IMyControllableEntity;
                            controlEnt?.SwitchToWeapon(null);
                        }
                    }

                    else
                    {
                        playerInArea = false;
                    }
                }
                catch (Exception e)
                {
                    MyAPIGateway.Utilities.ShowMessage("DrillBlocker", "An error happened in the mod" + e);
                }
            });
        }
Beispiel #22
0
        private void ControlledEntityChanged(IMyControllableEntity _, IMyControllableEntity entity)
        {
            if (_grid != null)
            {
                _grid.OnBlockAdded   -= OnBlockAdded;
                _grid.OnBlockRemoved -= OnBlockRemoved;
            }

            _grid = (entity?.Entity as IMyCockpit)?.CubeGrid;
            if (_grid == null)
            {
                MyLog.Default.Info("Player #{0} {1} left ship", Session.Player.IdentityId, Session.Player.DisplayName);
                _slimBlocks.Clear();
                _thrusters.Clear();
                _boostInfo.Clear();
                return;
            }

            UpdateThrusters();

            _grid.OnBlockAdded   += OnBlockAdded;
            _grid.OnBlockRemoved += OnBlockRemoved;

            MyLog.Default.Info(
                "Player #{0} {1} entered ship #{2} ({3} thrusters)",
                Session.Player.IdentityId,
                Session.Player.DisplayName,
                _grid.EntityId,
                _thrusters.Count);

            if (!_hintShown)
            {
                MyAPIGateway.Utilities.ShowNotification("Hold <Shift> to activate thrust boosters", 5000, MyFontEnum.UrlHighlight);
                _hintShown = true;
            }
        }
Beispiel #23
0
        public static void FindLookAtEntity(IMyControllableEntity controlledEntity, bool ignoreOccupiedGrid, bool ignoreProjection, out IMyEntity lookEntity, out double lookDistance, out Vector3D hitPoint, bool findShips, bool findCubes, bool findPlayers, bool findAsteroids, bool findPlanets, bool findReplicable)
        {
            const float range = 5000000;
            Matrix      worldMatrix;
            Vector3D    startPosition;
            Vector3D    endPosition;
            IMyCubeGrid occupiedGrid = null;

            if (controlledEntity.Entity.Parent == null)
            {
                worldMatrix   = controlledEntity.GetHeadMatrix(true, true, false); // dead center of player cross hairs, or the direction the player is looking with ALT.
                startPosition = worldMatrix.Translation + worldMatrix.Forward * 0.5f;
                endPosition   = worldMatrix.Translation + worldMatrix.Forward * (range + 0.5f);
            }
            else
            {
                occupiedGrid = controlledEntity.Entity.GetTopMostParent() as IMyCubeGrid;
                worldMatrix  = controlledEntity.Entity.WorldMatrix;
                // TODO: need to adjust for position of cockpit within ship.
                startPosition = worldMatrix.Translation + worldMatrix.Forward * 1.5f;
                endPosition   = worldMatrix.Translation + worldMatrix.Forward * (range + 1.5f);
            }

            var entites = new HashSet <IMyEntity>();

            MyAPIGateway.Entities.GetEntities(entites, e => e != null);

            var list = new Dictionary <IMyEntity, double>();
            var ray  = new RayD(startPosition, worldMatrix.Forward);

            foreach (var entity in entites)
            {
                if (findShips || findCubes)
                {
                    var cubeGrid = entity as IMyCubeGrid;

                    if (cubeGrid != null)
                    {
                        if (ignoreOccupiedGrid && occupiedGrid != null && occupiedGrid.EntityId == cubeGrid.EntityId)
                        {
                            continue;
                        }

                        // Will ignore Projected grids, new grid/cube placement, and grids in middle of copy/paste.
                        if (ignoreProjection && cubeGrid.Physics == null)
                        {
                            continue;
                        }

                        // check if the ray comes anywhere near the Grid before continuing.
                        if (ray.Intersects(entity.WorldAABB).HasValue)
                        {
                            var hit = cubeGrid.RayCastBlocks(startPosition, endPosition);
                            if (hit.HasValue)
                            {
                                var distance = (startPosition - cubeGrid.GridIntegerToWorld(hit.Value)).Length();
                                var block    = cubeGrid.GetCubeBlock(hit.Value);

                                if (block.FatBlock != null && findCubes)
                                {
                                    list.Add(block.FatBlock, distance);
                                }
                                else if (findShips)
                                {
                                    list.Add(entity, distance);
                                }
                            }
                        }
                    }
                }

                if (findPlayers)
                {
                    var controller = entity as IMyControllableEntity;
                    if (controlledEntity.Entity.EntityId != entity.EntityId && controller != null && ray.Intersects(entity.WorldAABB).HasValue)
                    {
                        var distance = (startPosition - entity.GetPosition()).Length();
                        list.Add(entity, distance);
                    }
                }

                if (findReplicable)
                {
                    var replicable = entity as Sandbox.Game.Entities.MyInventoryBagEntity;
                    if (replicable != null && ray.Intersects(entity.WorldAABB).HasValue)
                    {
                        var distance = (startPosition - entity.GetPosition()).Length();
                        list.Add(entity, distance);
                    }
                }

                if (findAsteroids)
                {
                    var voxelMap = entity as IMyVoxelMap;
                    if (voxelMap != null)
                    {
                        var aabb = new BoundingBoxD(voxelMap.PositionLeftBottomCorner, voxelMap.PositionLeftBottomCorner + voxelMap.Storage.Size);
                        var hit  = ray.Intersects(aabb);
                        if (hit.HasValue)
                        {
                            var center   = voxelMap.PositionLeftBottomCorner + (voxelMap.Storage.Size / 2);
                            var distance = (startPosition - center).Length();  // use distance to center of asteroid.
                            list.Add(entity, distance);
                        }
                    }
                }

                if (findPlanets)
                {
                    // Looks to be working against Git and public release.
                    var planet = entity as Sandbox.Game.Entities.MyPlanet;
                    if (planet != null)
                    {
                        var aabb = new BoundingBoxD(planet.PositionLeftBottomCorner, planet.PositionLeftBottomCorner + planet.Size);
                        var hit  = ray.Intersects(aabb);
                        if (hit.HasValue)
                        {
                            var center   = planet.WorldMatrix.Translation;
                            var distance = (startPosition - center).Length(); // use distance to center of planet.
                            list.Add(entity, distance);
                        }
                    }
                }
            }

            if (list.Count == 0)
            {
                lookEntity   = null;
                lookDistance = 0;
                hitPoint     = Vector3D.Zero;
                return;
            }

            // find the closest Entity.
            var item = list.OrderBy(f => f.Value).First();

            lookEntity   = item.Key;
            lookDistance = item.Value;
            hitPoint     = startPosition + (Vector3D.Normalize(ray.Direction) * lookDistance);
        }
Beispiel #24
0
        public static void FindLookAtEntity(IMyControllableEntity controlledEntity, bool ignoreOccupiedGrid, bool ignoreProjection, out IMyEntity lookEntity, out double lookDistance, out Vector3D hitPoint, bool findShips, bool findCubes, bool findPlayers, bool findAsteroids, bool findPlanets, bool findReplicable)
        {
            const float range = 5000000;
            Matrix worldMatrix;
            Vector3D startPosition;
            Vector3D endPosition;
            IMyCubeGrid occupiedGrid = null;

            if (controlledEntity.Entity.Parent == null)
            {
                worldMatrix = controlledEntity.GetHeadMatrix(true, true, false); // dead center of player cross hairs, or the direction the player is looking with ALT.
                startPosition = worldMatrix.Translation + worldMatrix.Forward * 0.5f;
                endPosition = worldMatrix.Translation + worldMatrix.Forward * (range + 0.5f);
            }
            else
            {
                occupiedGrid = controlledEntity.Entity.GetTopMostParent() as IMyCubeGrid;
                worldMatrix = controlledEntity.Entity.WorldMatrix;
                // TODO: need to adjust for position of cockpit within ship.
                startPosition = worldMatrix.Translation + worldMatrix.Forward * 1.5f;
                endPosition = worldMatrix.Translation + worldMatrix.Forward * (range + 1.5f);
            }

            var entites = new HashSet<IMyEntity>();
            MyAPIGateway.Entities.GetEntities(entites, e => e != null);

            var list = new Dictionary<IMyEntity, double>();
            var ray = new RayD(startPosition, worldMatrix.Forward);

            foreach (var entity in entites)
            {
                if (findShips || findCubes)
                {
                    var cubeGrid = entity as IMyCubeGrid;

                    if (cubeGrid != null)
                    {
                        if (ignoreOccupiedGrid && occupiedGrid != null && occupiedGrid.EntityId == cubeGrid.EntityId)
                            continue;

                        // Will ignore Projected grids, new grid/cube placement, and grids in middle of copy/paste.
                        if (ignoreProjection && cubeGrid.Physics == null)
                            continue;

                        // check if the ray comes anywhere near the Grid before continuing.
                        if (ray.Intersects(entity.WorldAABB).HasValue)
                        {
                            var hit = cubeGrid.RayCastBlocks(startPosition, endPosition);
                            if (hit.HasValue)
                            {
                                var distance = (startPosition - cubeGrid.GridIntegerToWorld(hit.Value)).Length();
                                var block = cubeGrid.GetCubeBlock(hit.Value);

                                if (block.FatBlock != null && findCubes)
                                    list.Add(block.FatBlock, distance);
                                else if (findShips)
                                    list.Add(entity, distance);
                            }
                        }
                    }
                }

                if (findPlayers)
                {
                    var controller = entity as IMyControllableEntity;
                    if (controlledEntity.Entity.EntityId != entity.EntityId && controller != null && ray.Intersects(entity.WorldAABB).HasValue)
                    {
                        var distance = (startPosition - entity.GetPosition()).Length();
                        list.Add(entity, distance);
                    }
                }

                if (findReplicable)
                {
                    var replicable = entity as Sandbox.Game.Entities.MyInventoryBagEntity;
                    if (replicable != null && ray.Intersects(entity.WorldAABB).HasValue)
                    {
                        var distance = (startPosition - entity.GetPosition()).Length();
                        list.Add(entity, distance);
                    }
                }

                if (findAsteroids)
                {
                    var voxelMap = entity as IMyVoxelMap;
                    if (voxelMap != null)
                    {
                        var aabb = new BoundingBoxD(voxelMap.PositionLeftBottomCorner, voxelMap.PositionLeftBottomCorner + voxelMap.Storage.Size);
                        var hit = ray.Intersects(aabb);
                        if (hit.HasValue)
                        {
                            var center = voxelMap.PositionLeftBottomCorner + (voxelMap.Storage.Size / 2);
                            var distance = (startPosition - center).Length();  // use distance to center of asteroid.
                            list.Add(entity, distance);
                        }
                    }
                }

                if (findPlanets)
                {
                    // Looks to be working against Git and public release.
                    var planet = entity as Sandbox.Game.Entities.MyPlanet;
                    if (planet != null)
                    {
                        var aabb = new BoundingBoxD(planet.PositionLeftBottomCorner, planet.PositionLeftBottomCorner + planet.Size);
                        var hit = ray.Intersects(aabb);
                        if (hit.HasValue)
                        {
                            var center = planet.WorldMatrix.Translation;
                            var distance = (startPosition - center).Length(); // use distance to center of planet.
                            list.Add(entity, distance);
                        }
                    }
                }
            }

            if (list.Count == 0)
            {
                lookEntity = null;
                lookDistance = 0;
                hitPoint = Vector3D.Zero;
                return;
            }

            // find the closest Entity.
            var item = list.OrderBy(f => f.Value).First();
            lookEntity = item.Key;
            lookDistance = item.Value;
            hitPoint = startPosition + (Vector3D.Normalize(ray.Direction) * lookDistance);
        }
Beispiel #25
0
        public bool is_under_control_of(VRage.Game.ModAPI.Interfaces.IMyControllableEntity current_controller)
        {
            var controller = current_controller as MyShipController;

            return(controller != null && controller.CubeGrid == _grid);
        }
Beispiel #26
0
 private void PlayerChangedController(VRage.Game.ModAPI.Interfaces.IMyControllableEntity arg1, VRage.Game.ModAPI.Interfaces.IMyControllableEntity arg2)
 {
     MyVisualScriptLogicProvider.ClearAllToolbarSlots(player.IdentityId);
     MyAPIGateway.Session.Player.Controller.ControlledEntityChanged -= PlayerChangedController;
     successAction(player);
 }
        public override void UpdateBeforeSimulation()
        {
            if (_hookedConfigurableSpeed)
            {
                if (ConfigurableSpeedComponentLogic.Instance != null)
                {
                    ConfigurableSpeedComponentLogic.Instance.OnEnvironmentComponentChange +=
                        (sender, component) => UpdateRelativeSpeeds(component);
                    _hookedConfigurableSpeed = true;
                }
            }

            lock (ActiveGrids)
            {
                lock (DisabledGrids)
                {
                    lock (PassiveGrids)
                    {
                        // continue to request server settings till received
                        if (!cfg.IsInitialized && waitInterval == 20)
                        {
                            Network.SendCommand("update");
                        }

                        // update active / passive grids every 3 seconds
                        if (waitInterval == 0)
                        {
                            for (int i = 0; i < PassiveGrids.Count; i++)
                            {
                                IMyCubeGrid grid = PassiveGrids[i];
                                if (IsMoving(grid))
                                {
                                    if (!ActiveGrids.Contains(grid))
                                    {
                                        ActiveGrids.Add(grid);
                                    }

                                    PassiveGrids.Remove(grid);
                                    i--;
                                }
                            }

                            for (int i = 0; i < ActiveGrids.Count; i++)
                            {
                                IMyCubeGrid grid = ActiveGrids[i];
                                if (!IsMoving(grid))
                                {
                                    if (!PassiveGrids.Contains(grid))
                                    {
                                        PassiveGrids.Add(grid);
                                    }

                                    ActiveGrids.Remove(grid);
                                    i--;
                                }
                            }

                            waitInterval = 180;                             // reset
                        }

                        MyAPIGateway.Parallel.For(0, ActiveGrids.Count, UpdateGrid);

                        if (!MyAPIGateway.Utilities.IsDedicated)
                        {
                            if (showHud)
                            {
                                IMyControllableEntity controlledEntity = MyAPIGateway.Session.LocalHumanPlayer.Controller.ControlledEntity;
                                if (controlledEntity != null && controlledEntity is IMyCubeBlock && (controlledEntity as IMyCubeBlock).CubeGrid.Physics != null)
                                {
                                    IMyCubeGrid grid        = (controlledEntity as IMyCubeBlock).CubeGrid;
                                    float       mass        = grid.Physics.Mass;
                                    float       speed       = grid.Physics.Speed;
                                    float       cruiseSpeed = GetCruiseSpeed(mass, grid.GridSizeEnum == MyCubeSize.Large);

                                    MyAPIGateway.Utilities.ShowNotification($"Mass: {mass}  Cruise: {cruiseSpeed.ToString("n3")} Boost: {((speed - cruiseSpeed >= 0) ? (speed - cruiseSpeed).ToString("n3") : "0.000")}", 1);
                                }
                            }

                            if (debug && IsAllowedSpecialOperations(MyAPIGateway.Session.LocalHumanPlayer.SteamUserId))
                            {
                                MyAPIGateway.Utilities.ShowNotification($"Grids - Active: {ActiveGrids.Count}  Passive: {PassiveGrids.Count}  Disabled: {DisabledGrids.Count}", 1);
                            }
                        }
                    }
                }
            }

            waitInterval--;
        }
Beispiel #28
0
 private void BootUp(IMyCubeGrid grid, IMyControllableEntity control)
 {
     FindDisplays();
     GetMiningDrillActions();
 }
Beispiel #29
0
            private void UpdateBlacklist()
            {
                CurrentBlacklistMode = SeBlacklistModes.None;

                for (int n = 0; n < bindClients.Count; n++)
                {
                    if ((bindClients[n].RequestBlacklistMode & SeBlacklistModes.AllKeys) == SeBlacklistModes.AllKeys)
                    {
                        CurrentBlacklistMode |= SeBlacklistModes.AllKeys;
                    }

                    if ((bindClients[n].RequestBlacklistMode & SeBlacklistModes.Mouse) > 0)
                    {
                        CurrentBlacklistMode |= SeBlacklistModes.Mouse;
                    }

                    if ((bindClients[n].RequestBlacklistMode & SeBlacklistModes.CameraRot) > 0)
                    {
                        CurrentBlacklistMode |= SeBlacklistModes.CameraRot;
                    }
                }

                // Block/allow camera rotation due to user input
                if ((CurrentBlacklistMode & SeBlacklistModes.CameraRot) > 0)
                {
                    IMyControllableEntity conEnt = MyAPIGateway.Session.ControlledObject;

                    if (conEnt != null)
                    {
                        conEnt.MoveAndRotate(conEnt.LastMotionIndicator, Vector2.Zero, 0f);
                    }
                }

                // Set control blacklist according to flag configuration
                if ((CurrentBlacklistMode & SeBlacklistModes.AllKeys) == SeBlacklistModes.AllKeys)
                {
                    if (!areControlsBlacklisted)
                    {
                        areControlsBlacklisted      = true;
                        areMouseControlsBlacklisted = true;
                        SetBlacklist(seControlIDs, true); // Enable full blacklist
                    }
                }
                else
                {
                    if (areControlsBlacklisted)
                    {
                        SetBlacklist(seControlIDs, false); // Disable full blacklist
                        areControlsBlacklisted      = false;
                        areMouseControlsBlacklisted = false;
                    }

                    if ((CurrentBlacklistMode & SeBlacklistModes.Mouse) > 0)
                    {
                        if (!areMouseControlsBlacklisted)
                        {
                            areMouseControlsBlacklisted = true;
                            SetBlacklist(seMouseControlIDs, true); // Enable mouse button blacklist
                        }
                    }
                    else if (areMouseControlsBlacklisted)
                    {
                        SetBlacklist(seMouseControlIDs, false); // Disable mouse button blacklist
                        areMouseControlsBlacklisted = false;
                    }
                }
            }
        public override void Simulate()
        {
            // update active / passive grids every 3 seconds
            if (waitInterval == 0)
            {
                for (int i = 0; i < PassiveGrids.Count; i++)
                {
                    MyCubeGrid grid = PassiveGrids[i];

                    if (!HasActivationBlock(grid))
                    {
                        continue;
                    }

                    if (IsMoving(grid))
                    {
                        if (!ActiveGrids.Contains(grid))
                        {
                            ActiveGrids.Add(grid);
                        }

                        PassiveGrids.Remove(grid);
                        i--;
                    }
                }

                for (int i = 0; i < ActiveGrids.Count; i++)
                {
                    MyCubeGrid grid = ActiveGrids[i];
                    if (!IsMoving(grid) || !HasActivationBlock(grid))
                    {
                        if (!PassiveGrids.Contains(grid))
                        {
                            PassiveGrids.Add(grid);
                        }

                        ActiveGrids.Remove(grid);
                        i--;
                    }
                }

                foreach (long key in AccelForces.Keys)
                {
                    try
                    {
                        Vector3 value;
                        AccelForces.TryGetValue(key, out value);

                        if (value == Vector3.Zero)
                        {
                            AccelForces.TryRemove(key, out value);
                        }
                    }
                    catch { }
                }

                waitInterval = 180;                 // reset
            }

            for (int i = 0; i < ActiveGrids.Count; i++)
            {
                UpdateGrid(i);
            }

            if (!MyAPIGateway.Utilities.IsDedicated)
            {
                if (showHud)
                {
                    IMyControllableEntity controlledEntity = MyAPIGateway.Session.LocalHumanPlayer.Controller.ControlledEntity;
                    if (controlledEntity != null && controlledEntity is IMyCubeBlock && (controlledEntity as IMyCubeBlock).CubeGrid.Physics != null)
                    {
                        IMyCubeGrid grid = (controlledEntity as IMyCubeBlock).CubeGrid;

                        float mass        = grid.Physics.Mass;
                        float speed       = grid.Physics.Speed;
                        float cruiseSpeed = GetCruiseSpeed(mass, grid.GridSizeEnum == MyCubeSize.Large);

                        float boost      = GetBoost(grid)[3];
                        float resistance = (grid.GridSizeEnum == MyCubeSize.Large) ? cfg.Value.LargeGrid_ResistanceMultiplier : cfg.Value.SmallGrid_ResistanceMultiplyer;

                        MyAPIGateway.Utilities.ShowNotification($"Mass: {mass.ToString("n0")}   Cruise: {cruiseSpeed.ToString("n2")}   Max Boost: {(boost).ToString("n2")}", 1);
                    }
                }

                if (Settings.Debug && IsAllowedSpecialOperations(MyAPIGateway.Session.LocalHumanPlayer.SteamUserId))
                {
                    MyAPIGateway.Utilities.ShowNotification($"Grids - Active: {ActiveGrids.Count}  Passive: {PassiveGrids.Count}  Disabled: {DisabledGrids.Count}", 1);
                }
            }

            waitInterval--;
        }