예제 #1
0
        public AntennaEntity(CubeGridEntity parent, MyObjectBuilder_RadioAntenna definition, Object backingObject)
            : base(parent, definition, backingObject)
        {
            Object internalRadioManager = InternalGetRadioManager();

            m_radioManager = new RadioManager(internalRadioManager);
        }
예제 #2
0
        public override MyObjectBuilder_CubeBlock GetObjectBuilderCubeBlock(bool copy = false)
        {
            MyObjectBuilder_RadioAntenna objectBuilder = (MyObjectBuilder_RadioAntenna)base.GetObjectBuilderCubeBlock(copy);

            objectBuilder.BroadcastRadius    = m_radioBroadcaster.BroadcastRadius;
            objectBuilder.ShowShipName       = this.ShowShipName;
            objectBuilder.EnableBroadcasting = m_radioBroadcaster.WantsToBeEnabled;
            return(objectBuilder);
        }
예제 #3
0
        public override MyObjectBuilder_CubeBlock GetObjectBuilderCubeBlock(bool copy = false)
        {
            MyObjectBuilder_RadioAntenna objectBuilderCubeBlock = (MyObjectBuilder_RadioAntenna)base.GetObjectBuilderCubeBlock(copy);

            objectBuilderCubeBlock.BroadcastRadius    = this.RadioBroadcaster.BroadcastRadius;
            objectBuilderCubeBlock.ShowShipName       = this.ShowShipName;
            objectBuilderCubeBlock.EnableBroadcasting = this.RadioBroadcaster.WantsToBeEnabled;
            objectBuilderCubeBlock.HudText            = this.HudText.ToString();
            objectBuilderCubeBlock.AttachedPB         = this.m_attachedPB.Value;
            objectBuilderCubeBlock.IgnoreAllied       = this.m_ignoreAlliedBroadcast.Value;
            objectBuilderCubeBlock.IgnoreOther        = this.m_ignoreOtherBroadcast.Value;
            return(objectBuilderCubeBlock);
        }
예제 #4
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

            m_radioBroadcaster = new MyRadioBroadcaster(this);
            MyObjectBuilder_RadioAntenna antennaBuilder = (MyObjectBuilder_RadioAntenna)objectBuilder;

            if (antennaBuilder.BroadcastRadius != 0)
            {
                m_radioBroadcaster.BroadcastRadius = antennaBuilder.BroadcastRadius;
            }
            else
            {
                m_radioBroadcaster.BroadcastRadius = CubeGrid.GridSizeEnum == MyCubeSize.Large ? 10000 : 500;
            }
            RadioBroadcaster.WantsToBeEnabled = antennaBuilder.EnableBroadcasting;

            m_showShipName  = antennaBuilder.ShowShipName;
            m_radioReceiver = new MyRadioReceiver(this);

            m_radioBroadcaster.OnBroadcastRadiusChanged += OnBroadcastRadiusChanged;

            var antennaDefinition = BlockDefinition as MyRadioAntennaDefinition;

            Debug.Assert(antennaDefinition != null);

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                antennaDefinition.ResourceSinkGroup,
                MyEnergyConstants.MAX_REQUIRED_POWER_ANTENNA,
                UpdatePowerInput);
            sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
            ResourceSink = sinkComp;
            ResourceSink.Update();

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            if (Sync.IsServer)
            {
                this.IsWorkingChanged  += UpdatePirateAntenna;
                this.CustomNameChanged += UpdatePirateAntenna;
                this.OwnershipChanged  += UpdatePirateAntenna;
                UpdatePirateAntenna(this);
            }

            ShowOnHUD = false;

            NeedsUpdate = MyEntityUpdateEnum.EACH_10TH_FRAME;
        }
예제 #5
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            RadioBroadcaster = new MyRadioBroadcaster();
            RadioReceiver    = new MyRadioReceiver();

            var antennaDefinition = BlockDefinition as MyRadioAntennaDefinition;

            Debug.Assert(antennaDefinition != null);

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                antennaDefinition.ResourceSinkGroup,
                MyEnergyConstants.MAX_REQUIRED_POWER_ANTENNA,
                UpdatePowerInput);
            sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);

            MyObjectBuilder_RadioAntenna antennaBuilder = (MyObjectBuilder_RadioAntenna)objectBuilder;

            if (antennaBuilder.BroadcastRadius != 0)
            {
                RadioBroadcaster.BroadcastRadius = antennaBuilder.BroadcastRadius;
            }
            else
            {
                RadioBroadcaster.BroadcastRadius = CubeGrid.GridSizeEnum == MyCubeSize.Large ? 10000 : 500;
            }
            ResourceSink.Update();
            RadioBroadcaster.WantsToBeEnabled = antennaBuilder.EnableBroadcasting;

            m_showShipName.Value = antennaBuilder.ShowShipName;

            //if (Sync.IsServer)
            //{
            //    this.IsWorkingChanged += UpdatePirateAntenna;
            //    this.CustomNameChanged += UpdatePirateAntenna;
            //    this.OwnershipChanged += UpdatePirateAntenna;
            //    UpdatePirateAntenna(this);
            //}

            ShowOnHUD = false;

            m_gizmoColor = MySandboxGame.IsDirectX11 ? new Vector4(0.2f, 0.2f, 0.0f, 0.5f) : new Vector4(0.1f, 0.1f, 0.0f, 0.1f);

            NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME | MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
        }
예제 #6
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            this.RadioBroadcaster = new MyRadioBroadcaster(100f);
            this.RadioReceiver    = new MyRadioReceiver();
            MyRadioAntennaDefinition blockDefinition = base.BlockDefinition as MyRadioAntennaDefinition;
            MyResourceSinkComponent  component       = new MyResourceSinkComponent(1);

            component.Init(blockDefinition.ResourceSinkGroup, 0.002f, new Func <float>(this.UpdatePowerInput));
            component.IsPoweredChanged += new Action(this.Receiver_IsPoweredChanged);
            base.ResourceSink           = component;
            base.Init(objectBuilder, cubeGrid);
            MyObjectBuilder_RadioAntenna antenna = (MyObjectBuilder_RadioAntenna)objectBuilder;

            this.RadioBroadcaster.BroadcastRadius = (antenna.BroadcastRadius <= 0f) ? (blockDefinition.MaxBroadcastRadius / 10f) : antenna.BroadcastRadius;
            this.HudText.Clear();
            if (antenna.HudText != null)
            {
                this.HudText.Append(antenna.HudText);
            }
            this.RadioBroadcaster.BroadcastRadius = MathHelper.Clamp(this.RadioBroadcaster.BroadcastRadius, 1f, blockDefinition.MaxBroadcastRadius);
            base.ResourceSink.Update();
            this.RadioBroadcaster.WantsToBeEnabled = antenna.EnableBroadcasting;
            this.m_showShipName.SetLocalValue(antenna.ShowShipName);
            if (Sync.IsServer)
            {
                this.m_attachedPB.Value         = antenna.AttachedPB;
                this.m_attachedPB.ValueChanged += delegate(SyncBase x) {
                    m_messageRequest -= new Action <MyRadioAntenna, string, MyTransmitTarget>(this.OnMessageRecieved);
                    if (this.m_attachedPB.Value != 0)
                    {
                        m_messageRequest += new Action <MyRadioAntenna, string, MyTransmitTarget>(this.OnMessageRecieved);
                    }
                };
            }
            this.m_ignoreOtherBroadcast.SetLocalValue(antenna.IgnoreOther);
            this.m_ignoreAlliedBroadcast.SetLocalValue(antenna.IgnoreAllied);
            base.ShowOnHUD                        = false;
            this.m_gizmoColor                     = new VRageMath.Vector4(0.2f, 0.2f, 0f, 0.5f);
            base.NeedsUpdate                     |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME | MyEntityUpdateEnum.EACH_10TH_FRAME;
            this.m_radius.ValueChanged           += obj => this.ChangeRadius();
            this.EnableBroadcasting.ValueChanged += obj => this.ChangeEnableBroadcast();
            this.m_showShipName.ValueChanged     += obj => this.OnShowShipNameChanged();
        }
예제 #7
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

            m_radioBroadcaster = new MyRadioBroadcaster(this);
            MyObjectBuilder_RadioAntenna antennaBuilder = (MyObjectBuilder_RadioAntenna)objectBuilder;

            if (antennaBuilder.BroadcastRadius != 0)
            {
                m_radioBroadcaster.BroadcastRadius = antennaBuilder.BroadcastRadius;
            }
            else
            {
                m_radioBroadcaster.BroadcastRadius = CubeGrid.GridSizeEnum == MyCubeSize.Large ? 10000 : 500;
            }
            RadioBroadcaster.WantsToBeEnabled = antennaBuilder.EnableBroadcasting;

            m_showShipName  = antennaBuilder.ShowShipName;
            m_radioReceiver = new MyRadioReceiver(this);

            m_radioBroadcaster.OnBroadcastRadiusChanged += OnBroadcastRadiusChanged;

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Utility,
                false,
                MyEnergyConstants.MAX_REQUIRED_POWER_ANTENNA,
                UpdatePowerInput);
            PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;
            PowerReceiver.Update();

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            ShowOnHUD = false;

            NeedsUpdate = MyEntityUpdateEnum.EACH_10TH_FRAME;
        }
예제 #8
0
 public AntennaEntity(CubeGridEntity parent, MyObjectBuilder_RadioAntenna definition)
     : base(parent, definition)
 {
 }
예제 #9
0
        public void UpdateAfterSimulation100()
        {
            try
            {
                if (!myRadioAntenna.IsWorking)
                {
                    return;
                }

                //Showoff.doShowoff(CubeBlock, myLastSeen.Values.GetEnumerator(), myLastSeen.Count);

                float radiusSquared;
                MyObjectBuilder_RadioAntenna antBuilder = CubeBlock.GetObjectBuilderCubeBlock() as MyObjectBuilder_RadioAntenna;
                if (!antBuilder.EnableBroadcasting)
                {
                    radiusSquared = 0;
                }
                else
                {
                    radiusSquared = myRadioAntenna.Radius * myRadioAntenna.Radius;
                }

                // send antenna self to radio antennae
                LinkedList <RadioAntenna> canSeeMe = new LinkedList <RadioAntenna>();               // friend and foe alike
                foreach (RadioAntenna ant in RadioAntenna.registry)
                {
                    if (CubeBlock.canSendTo(ant.CubeBlock, false, radiusSquared, true))
                    {
                        canSeeMe.AddLast(ant);
                    }
                }

                LastSeen self = new LastSeen(CubeBlock.CubeGrid);
                foreach (RadioAntenna ant in canSeeMe)
                {
                    ant.receive(self);
                }

                // relay information to friendlies
                foreach (RadioAntenna ant in value_registry)
                {
                    if (CubeBlock.canSendTo(ant.CubeBlock, true, radiusSquared, true))
                    {
                        foreach (LastSeen seen in myLastSeen.Values)
                        {
                            ant.receive(seen);
                        }
                        foreach (Message mes in myMessages)
                        {
                            ant.receive(mes);
                        }
                    }
                }

                Receiver.sendToAttached(CubeBlock, myLastSeen);
                Receiver.sendToAttached(CubeBlock, myMessages);

                UpdateEnemyNear();
            }
            catch (Exception e)
            { myLogger.log("Exception: " + e, "UpdateAfterSimulation100()", Logger.severity.ERROR); }
        }