public static bool IsRecievedByPlayer(MyCubeBlock cubeBlock)
        {
            var player = MySession.LocalCharacter;

            if (player == null)
            {
                return(false);
            }

            var playerReciever = player.RadioReceiver;

            foreach (var broadcaster in playerReciever.RelayedBroadcasters)
            {
                if (broadcaster.Parent is MyRadioAntenna)
                {
                    MyRadioAntenna antenna       = broadcaster.Parent as MyRadioAntenna;
                    var            ownerCubeGrid = (broadcaster.Parent as MyCubeBlock).CubeGrid;
                    if (antenna.HasLocalPlayerAccess() && MyCubeGridGroups.Static.Physical.HasSameGroup(ownerCubeGrid, cubeBlock.CubeGrid))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #2
0
        private void OnMessageRecieved(MyRadioAntenna requester, string arg, MyTransmitTarget target)
        {
            if (!ReferenceEquals(requester.CubeGrid, base.CubeGrid))
            {
                MyProgrammableBlock block2;
                switch (MyIDModule.GetRelation(base.OwnerId, requester.OwnerId, MyOwnershipShareModeEnum.Faction, MyRelationsBetweenPlayerAndBlock.Enemies, MyRelationsBetweenFactions.Enemies, MyRelationsBetweenPlayerAndBlock.FactionShare))
                {
                case MyRelationsBetweenPlayerAndBlock.NoOwnership:
                case MyRelationsBetweenPlayerAndBlock.Neutral:
                    if (target.HasFlag(MyTransmitTarget.Neutral))
                    {
                        break;
                    }
                    return;

                case MyRelationsBetweenPlayerAndBlock.Owner:
                    if (target.HasFlag(MyTransmitTarget.Owned))
                    {
                        break;
                    }
                    return;

                case MyRelationsBetweenPlayerAndBlock.FactionShare:
                    if (!this.m_ignoreAlliedBroadcast.Value && target.HasFlag(MyTransmitTarget.Ally))
                    {
                        break;
                    }
                    return;

                case MyRelationsBetweenPlayerAndBlock.Enemies:
                    if (!this.m_ignoreOtherBroadcast.Value && target.HasFlag(MyTransmitTarget.Enemy))
                    {
                        break;
                    }
                    return;

                default:
                    return;
                }
                Sandbox.Game.Entities.MyEntities.TryGetEntityById <MyProgrammableBlock>(this.m_attachedPB.Value, out block2, false);
                if (((this.RadioReceiver != null) && ((block2 != null) && MyCubeGridGroups.Static.Logical.GetGroup(block2.CubeGrid).Nodes.Any <MyGroups <MyCubeGrid, MyGridLogicalGroupData> .Node>(n => (n.NodeData == base.CubeGrid)))) && MyAntennaSystem.Static.GetAllRelayedBroadcasters(this.RadioReceiver, base.OwnerId, false, null).Contains(requester.RadioBroadcaster))
                {
                    block2.Run(arg, UpdateType.Antenna);
                }
            }
        }
        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;
        }