private void ChangeDroneOwnership(List <MyCubeGrid> gridList, long ownerId, long antennaEntityId)
        {
            foreach (var grid in gridList)
            {
                grid.ChangeGridOwnership(ownerId, MyOwnershipShareModeEnum.None);

                MyRemoteControl firstRemote = null;

                foreach (var block in grid.CubeBlocks)
                {
                    if (block.FatBlock == null)
                    {
                        continue;
                    }

                    var pb = block.FatBlock as MyProgrammableBlock;
                    if (pb != null)
                    {
                        pb.SendRecompile();
                    }

                    var remote = block.FatBlock as MyRemoteControl;
                    if (firstRemote == null)
                    {
                        firstRemote = remote;
                    }
                }

                // If there's no remote control on the grid, we have to register it as is
                RegisterDrone(antennaEntityId, (MyEntity)firstRemote ?? (MyEntity)grid);
            }

            gridList.Clear();
        }
        public bool CanDespawn(MyCubeGrid grid, MyRemoteControl remote)
        {
            if (remote != null && !remote.IsFunctional)
            {
                return(false);
            }

            BoundingSphereD bs = grid.PositionComp.WorldVolume;

            bs.Radius += 4000.0;

            foreach (var player in Sync.Players.GetOnlinePlayers())
            {
                if (bs.Contains(player.GetPosition()) == ContainmentType.Contains)
                {
                    return(false);
                }
            }

            foreach (var gunSet in grid.GridSystems.WeaponSystem.GetGunSets().Values)
            {
                foreach (var gun in gunSet)
                {
                    if (gun.IsShooting)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
예제 #3
0
        private bool SpawnDrone(long antennaEntityId, long ownerId, Vector3D position, MySpawnGroupDefinition spawnGroup)
        {
            Vector3D direction    = MyUtils.GetRandomVector3Normalized();
            Vector3D upVector     = Vector3D.CalculatePerpendicularVector(direction);
            MatrixD  originMatrix = MatrixD.CreateWorld(position, direction, upVector);

            foreach (var shipPrefab in spawnGroup.Prefabs)
            {
                Vector3D shipPosition = Vector3D.Transform((Vector3D)shipPrefab.Position, originMatrix);

                m_tmpGridList.Clear();

                MyPrefabManager.Static.SpawnPrefab(
                    resultList: m_tmpGridList,
                    prefabName: shipPrefab.SubtypeId,
                    position: shipPosition,
                    forward: direction,
                    up: upVector,
                    initialLinearVelocity: default(Vector3),
                    beaconName: null,
                    spawningOptions: Sandbox.ModAPI.SpawningOptions.None,
                    ownerId: ownerId,
                    updateSync: true);

                foreach (var grid in m_tmpGridList)
                {
                    grid.ChangeGridOwnership(ownerId, MyOwnershipShareModeEnum.None);

                    MyRemoteControl firstRemote = null;

                    foreach (var block in grid.CubeBlocks)
                    {
                        if (block.FatBlock == null)
                        {
                            continue;
                        }

                        var pb = block.FatBlock as MyProgrammableBlock;
                        if (pb != null)
                        {
                            pb.SendRecompile();
                        }

                        var remote = block.FatBlock as MyRemoteControl;
                        if (firstRemote == null)
                        {
                            firstRemote = remote;
                        }
                    }

                    // If there's no remote control on the grid, we have to register it as is
                    RegisterDrone(antennaEntityId, (MyEntity)firstRemote ?? (MyEntity)grid);
                }

                m_tmpGridList.Clear();
            }
            return(true);
        }
        public MyDroneStrafeBehaviour(MyRemoteControl remoteControl, MySpaceStrafeData strafeData, bool activate, List <MyUserControllableGun> weapons, List <MyFunctionalBlock> tools, Vector3D firstWaypoint)
        {
            m_remoteControl = remoteControl;
            ReturnPosition  = m_remoteControl.PositionComp.GetPosition();

            LoadStrafeData(strafeData);

            m_weapons = weapons;
            m_tools   = tools;
            MyPlayer player = m_remoteControl.GetNearestPlayer();

            m_target                = player != null ? player.Character as MyEntity : null;
            m_lastTargetUpdate      = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            m_lastWeaponUpdate      = m_lastTargetUpdate;
            m_waypointReachedTimeMs = m_lastTargetUpdate;
            m_firstWaypoint         = firstWaypoint;

            NeedUpdate = activate;
        }
        public MyDroneStrafeBehaviour(MyRemoteControl remoteControl, string presetName, bool activate, List <MyEntity> waypoints, List <DroneTarget> targets, int playerPriority, TargetPrioritization prioritizationStyle, float maxPlayerDistance, bool cycleWaypoints)
        {
            m_remoteControl  = remoteControl;
            m_returnPosition = m_remoteControl.PositionComp.GetPosition();

            MySpaceStrafeData strafeData = MySpaceStrafeDataStatic.LoadPreset(presetName);

            m_currentPreset = presetName;
            LoadStrafeData(strafeData);

            m_lastTargetUpdate      = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            m_lastWeaponUpdate      = m_lastTargetUpdate;
            m_waypointReachedTimeMs = m_lastTargetUpdate;
            m_forcedWaypoints       = waypoints != null ? waypoints : new List <MyEntity>();
            m_targetsList           = targets != null ? targets : new List <DroneTarget>();
            PlayerPriority          = playerPriority;
            m_prioritizationStyle   = prioritizationStyle;
            MaxPlayerDistance       = maxPlayerDistance;
            m_cycleWaypoints        = cycleWaypoints;

            NeedUpdate = activate;
        }
        public void Load(MyObjectBuilder_AutomaticBehaviour objectBuilder, MyRemoteControl remoteControl)
        {
            MyObjectBuilder_DroneStrafeBehaviour builder = objectBuilder as MyObjectBuilder_DroneStrafeBehaviour;

            if (builder != null)
            {
                m_remoteControl = remoteControl;

                MySpaceStrafeData strafeData = MySpaceStrafeDataStatic.LoadPreset(builder.CurrentPreset);
                m_currentPreset = builder.CurrentPreset;
                LoadStrafeData(strafeData);

                m_lastTargetUpdate      = MySandboxGame.TotalGamePlayTimeInMilliseconds;
                m_lastWeaponUpdate      = m_lastTargetUpdate;
                m_waypointReachedTimeMs = m_lastTargetUpdate;

                m_forcedWaypoints   = new List <MyEntity>();
                m_loadWaypointList  = builder.WaypointList;
                m_targetsList       = new List <DroneTarget>();
                m_loadTargetList    = builder.TargetList;
                m_currentTarget     = null;
                m_loadCurrentTarget = builder.CurrentTarget;

                m_returnPosition              = builder.ReturnPosition;
                PlayerPriority                = builder.PlayerPriority;
                m_prioritizationStyle         = builder.PrioritizationStyle;
                MaxPlayerDistance             = builder.MaxPlayerDistance;
                m_cycleWaypoints              = builder.CycleWaypoints;
                m_alternativebehaviorSwitched = builder.AlternativebehaviorSwitched;
                CollisionAvoidance            = builder.CollisionAvoidance;
                m_canSkipWaypoint             = builder.CanSkipWaypoint;

                NeedUpdate     = builder.NeedUpdate;
                IsActive       = builder.IsActive;
                m_loadEntities = true;
            }
        }
예제 #7
0
        private bool SpawnDrone(MyRadioAntenna antenna, long ownerId, Vector3D position, MySpawnGroupDefinition spawnGroup)
        {
            long     antennaEntityId = antenna.EntityId;
            Vector3D antennaPos      = antenna.PositionComp.GetPosition();

            var planet = MyGravityProviderSystem.GetStrongestGravityWell(position);

            Vector3D upVector;

            if (planet != null && planet.IsPositionInGravityWell(position))
            {
                if (!MyGravityProviderSystem.IsPositionInNaturalGravity(antennaPos))
                {
                    MySandboxGame.Log.WriteLine("Couldn't spawn drone; antenna is not in natural gravity but spawn location is.");
                    return(false);
                }
                planet.CorrectSpawnLocation(ref position, spawnGroup.SpawnRadius * 2.0);
                upVector = -planet.GetWorldGravityNormalized(ref position);
            }
            else
            {
                upVector = MyUtils.GetRandomVector3Normalized();
            }

            Vector3D direction    = MyUtils.GetRandomPerpendicularVector(ref upVector);
            MatrixD  originMatrix = MatrixD.CreateWorld(position, direction, upVector);

            foreach (var shipPrefab in spawnGroup.Prefabs)
            {
                Vector3D shipPosition = Vector3D.Transform((Vector3D)shipPrefab.Position, originMatrix);

                m_tmpGridList.Clear();

                MyPrefabManager.Static.SpawnPrefab(
                    resultList: m_tmpGridList,
                    prefabName: shipPrefab.SubtypeId,
                    position: shipPosition,
                    forward: direction,
                    up: upVector,
                    initialLinearVelocity: default(Vector3),
                    beaconName: null,
                    spawningOptions: VRage.Game.ModAPI.SpawningOptions.None,
                    ownerId: ownerId,
                    updateSync: true);

                foreach (var grid in m_tmpGridList)
                {
                    grid.ChangeGridOwnership(ownerId, MyOwnershipShareModeEnum.None);

                    MyRemoteControl firstRemote = null;

                    foreach (var block in grid.CubeBlocks)
                    {
                        if (block.FatBlock == null)
                        {
                            continue;
                        }

                        var pb = block.FatBlock as MyProgrammableBlock;
                        if (pb != null)
                        {
                            pb.SendRecompile();
                        }

                        var remote = block.FatBlock as MyRemoteControl;
                        if (firstRemote == null)
                        {
                            firstRemote = remote;
                        }
                    }

                    // If there's no remote control on the grid, we have to register it as is
                    RegisterDrone(antennaEntityId, (MyEntity)firstRemote ?? (MyEntity)grid);
                }

                m_tmpGridList.Clear();
            }
            return(true);
        }
예제 #8
0
        private bool SpawnDrone(MyRadioAntenna antenna, long ownerId, Vector3D position, MySpawnGroupDefinition spawnGroup, Vector3?spawnUp = null, Vector3?spawnForward = null)
        {
            long     antennaEntityId = antenna.EntityId;
            Vector3D antennaPos      = antenna.PositionComp.GetPosition();

            Vector3D upVector;

            var planet = MyGamePruningStructure.GetClosestPlanet(position);

            if (planet != null)
            {
                if (!MyGravityProviderSystem.IsPositionInNaturalGravity(antennaPos))
                {
                    MySandboxGame.Log.WriteLine("Couldn't spawn drone; antenna is not in natural gravity but spawn location is.");
                    return(false);
                }
                planet.CorrectSpawnLocation(ref position, spawnGroup.SpawnRadius * 2.0);
                upVector = position - planet.PositionComp.GetPosition();
                upVector.Normalize();
            }
            else
            {
                var totalGravityInPoint = MyGravityProviderSystem.CalculateTotalGravityInPoint(position);
                if (totalGravityInPoint != Vector3.Zero)
                {
                    upVector = -totalGravityInPoint;
                    upVector.Normalize();
                }
                else if (spawnUp != null)
                {
                    upVector = spawnUp.Value;
                }
                else
                {
                    upVector = MyUtils.GetRandomVector3Normalized();
                }
            }

            Vector3D direction = MyUtils.GetRandomPerpendicularVector(ref upVector);

            if (spawnForward != null)
            {
                // Align forward to up vector.
                Vector3 forward = spawnForward.Value;
                if (Math.Abs(Vector3.Dot(forward, upVector)) >= 0.98f)
                {
                    forward = Vector3.CalculatePerpendicularVector(upVector);
                }
                else
                {
                    Vector3 right = Vector3.Cross(forward, upVector);
                    right.Normalize();
                    forward = Vector3.Cross(upVector, right);
                    forward.Normalize();
                }

                direction = forward;
            }

            MatrixD originMatrix = MatrixD.CreateWorld(position, direction, upVector);

            foreach (var shipPrefab in spawnGroup.Prefabs)
            {
                Vector3D shipPosition = Vector3D.Transform((Vector3D)shipPrefab.Position, originMatrix);

                m_tmpGridList.Clear();

                MyPrefabManager.Static.SpawnPrefab(
                    resultList: m_tmpGridList,
                    prefabName: shipPrefab.SubtypeId,
                    position: shipPosition,
                    forward: direction,
                    up: upVector,
                    initialLinearVelocity: default(Vector3),
                    beaconName: null,
                    spawningOptions: VRage.Game.ModAPI.SpawningOptions.None,
                    ownerId: ownerId,
                    updateSync: true);

                foreach (var grid in m_tmpGridList)
                {
                    grid.ChangeGridOwnership(ownerId, MyOwnershipShareModeEnum.None);

                    MyRemoteControl firstRemote = null;

                    foreach (var block in grid.CubeBlocks)
                    {
                        if (block.FatBlock == null)
                        {
                            continue;
                        }

                        var pb = block.FatBlock as MyProgrammableBlock;
                        if (pb != null)
                        {
                            pb.SendRecompile();
                        }

                        var remote = block.FatBlock as MyRemoteControl;
                        if (firstRemote == null)
                        {
                            firstRemote = remote;
                        }
                    }

                    // If there's no remote control on the grid, we have to register it as is
                    RegisterDrone(antennaEntityId, (MyEntity)firstRemote ?? (MyEntity)grid);
                }

                m_tmpGridList.Clear();
            }
            return(true);
        }