示例#1
0
		/// <summary>
		/// For sending newly created Message to all attached antennae.
		/// </summary>
		/// <param name="sender">The block doing the sending.</param>
		/// <param name="toSend">The Message to send.</param>
		public static void SendToAttached(IMyCubeBlock sender, ICollection<Message> toSend)
		{
			Registrar.ForEach((RadioAntenna radioAnt) => {
				if (sender.canSendTo(radioAnt.CubeBlock, true))
					foreach (Message msg in toSend)
						radioAnt.Receive(msg);
			});

			Registrar.ForEach((LaserAntenna laserAnt) => {
				if (sender.canSendTo(laserAnt.CubeBlock, true))
					foreach (Message msg in toSend)
						laserAnt.Receive(msg);
			});
		}
示例#2
0
		/// <summary>
		/// For sending newly created LastSeen to all attached antennae and ShipController.
		/// </summary>
		/// <param name="sender">The block doing the sending.</param>
		/// <param name="toSend">The LastSeen to send.</param>
		public static void SendToAttached(IMyCubeBlock sender, ICollection<LastSeen> toSend)
		{
			Registrar.ForEach((RadioAntenna radioAnt) => {
				if (sender.canSendTo(radioAnt.CubeBlock, true))
					foreach (LastSeen seen in toSend)
						radioAnt.Receive(seen);
			});

			Registrar.ForEach((LaserAntenna laserAnt) => {
				if (sender.canSendTo(laserAnt.CubeBlock, true))
					foreach (LastSeen seen in toSend)
						laserAnt.Receive(seen);
			});

			Registrar.ForEach((ShipController controller) => {
				if (sender.canSendTo(controller.CubeBlock, true))
					foreach (LastSeen seen in toSend)
						controller.Receive(seen);
			});
		}
示例#3
0
        public void UpdateAfterSimulation100()
        {
            //if (!IsInitialized) return;
            if (CubeBlock == null || CubeBlock.Closed || CubeBlock.CubeGrid == null)
            {
                return;
            }
            try
            {
                if (!myBeacon.IsWorking)
                {
                    if (isRadar && powerLevel > 0)
                    {
                        powerLevel += powerDecrease;
                    }
                    return;
                }

                // send beacon self to radio antenna
                LinkedList <RadioAntenna> canSeeMe = new LinkedList <RadioAntenna>();               // friend and foe alike

                float radiusSquared = myBeacon.Radius * myBeacon.Radius;
                foreach (RadioAntenna ant in RadioAntenna.registry)
                {
                    if (CubeBlock.canSendTo(ant.CubeBlock, false, radiusSquared, true))
                    {
                        canSeeMe.AddLast(ant);
                    }
                }

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

                //log("beacon made self known to "+canSeeMe.Count+" antennas", "UpdateAfterSimulation100()", Logger.severity.TRACE);

                if (!isRadar)
                {
                    return;
                }

                // Radar

                float Radius = myBeacon.Radius;

                // cap small radar
                if (isSmallBlock)
                {
                    if (Radius > maxRadiusSmallRadar)
                    {
                        myLogger.debugLog("Reduce radius from " + Radius + " to " + maxRadiusSmallRadar, "UpdateAfterSimulation100()");
                        myBeacon.SetValueFloat("Radius", maxRadiusSmallRadar);
                        Radius = maxRadiusSmallRadar;
                    }
                }

                // adjust power level
                if (powerLevel < 0)
                {
                    powerLevel = 0;
                }
                powerLevel += powerIncrease;
                if (powerLevel > Radius)
                {
                    powerLevel = Radius;
                }
                myLogger.debugLog("Radius = " + Radius + ", power level = " + powerLevel, "UpdateAfterSimulation100()");

                // figure out what radar sees
                LinkedList <LastSeen> radarSees = new LinkedList <LastSeen>();

                HashSet <IMyEntity> allGrids = new HashSet <IMyEntity>();
                MyAPIGateway.Entities.GetEntities_Safe(allGrids, (entity) => { return(entity is IMyCubeGrid); });
                foreach (IMyEntity ent in allGrids)
                //if (ent is IMyCubeGrid || ent is IMyCharacter)
                {
                    // get detection distance
                    float volume = ent.LocalAABB.Volume();
                    float power  = (volume + radarPower_A) / (volume + radarPower_B) / radarPower_C * powerLevel;
                    if (!CubeBlock.canSendTo(ent, false, power))                     // not in range
                    {
                        continue;
                    }

                    //log("radar found a grid: " + (ent as IMyCubeGrid).DisplayName, "UpdateAfterSimulation100()", Logger.severity.TRACE);

                    // report to attached antennas and remotes
                    LastSeen seen = new LastSeen(ent, false, new RadarInfo(volume));
                    radarSees.AddLast(seen);

                    //foreach (RadioAntenna ant in RadioAntenna.registry)
                    //	if (CubeBlock.canSendTo(ant.CubeBlock, true))
                    //		ant.receive(seen);
                    //foreach (RemoteControl rem in RemoteControl.registry.Values)
                    //	if (CubeBlock.canSendTo(rem.CubeBlock, true))
                    //		rem.receive(seen);
                }

                Receiver.sendToAttached(CubeBlock, radarSees);
            }
            catch (Exception e)
            { alwaysLog("Exception: " + e, "UpdateAfterSimulation100()", Logger.severity.ERROR); }
        }
示例#4
0
        /// <summary>
        /// If attached to final destination, send message to it. Otherwise sends Message to all attached friendly antennae.
        /// removes invalids from the list
        /// </summary>
        /// <param name="additional">also sends to this collection, without testing</param>
        public static void sendToAttached(IMyCubeBlock sender, ICollection <Message> toSend)
        {
            LinkedList <Message> removeList = new LinkedList <Message>();

            foreach (Message mes in toSend)
            {
                if (mes.isValid)
                {
                    if (AttachedGrids.isGridAttached(sender.CubeGrid, mes.DestCubeBlock.CubeGrid))
                    {
                        // get receiver for block
                        RemoteControl remote;
                        if (RemoteControl.registry.TryGetValue(mes.DestCubeBlock, out remote))
                        {
                            remote.receive(mes);
                            mes.isValid = false;
                            removeList.AddLast(mes);
                        }
                        else
                        {
                            ProgrammableBlock progBlock;
                            if (ProgrammableBlock.registry.TryGetValue(mes.DestCubeBlock, out progBlock))
                            {
                                progBlock.receive(mes);
                                mes.isValid = false;
                                removeList.AddLast(mes);
                            }
                        }
                    }
                }
                else                 // not valid
                {
                    removeList.AddLast(mes);
                }
            }
            foreach (Message mes in removeList)
            {
                toSend.Remove(mes);
            }

            // to radio antenna
            foreach (RadioAntenna radioAnt in RadioAntenna.registry)
            {
                if (sender.canSendTo(radioAnt.CubeBlock, true))
                {
                    foreach (Message mes in toSend)
                    {
                        radioAnt.receive(mes);
                    }
                }
            }

            // to laser antenna
            foreach (LaserAntenna laserAnt in LaserAntenna.registry)
            {
                if (sender.canSendTo(laserAnt.CubeBlock, true))
                {
                    foreach (Message mes in toSend)
                    {
                        laserAnt.receive(mes);
                    }
                }
            }
        }
示例#5
0
        /// <summary>
        /// Sends LastSeen to attached all attached friendly antennae and to remote controls.
        /// removes invalids from the list
        /// </summary>
        private static void sendToAttached(IMyCubeBlock sender, LinkedList <LastSeen> list = null, Dictionary <long, LastSeen> dictionary = null)
        {
            ICollection <LastSeen> toSend;

            if (list != null)
            {
                toSend = list;
            }
            else
            {
                toSend = dictionary.Values;
            }

            LinkedList <LastSeen> removeList = new LinkedList <LastSeen>();

            foreach (LastSeen seen in toSend)
            {
                if (!seen.isValid)
                {
                    removeList.AddLast(seen);
                }
            }
            foreach (LastSeen seen in removeList)
            {
                if (dictionary != null)
                {
                    dictionary.Remove(seen.Entity.EntityId);
                }
                else
                {
                    toSend.Remove(seen);
                }
            }

            // to radio antenna
            foreach (RadioAntenna radioAnt in RadioAntenna.registry)
            {
                if (sender.canSendTo(radioAnt.CubeBlock, true))
                {
                    foreach (LastSeen seen in toSend)
                    {
                        radioAnt.receive(seen);
                    }
                }
            }

            // to laser antenna
            foreach (LaserAntenna laserAnt in LaserAntenna.registry)
            {
                if (sender.canSendTo(laserAnt.CubeBlock, true))
                {
                    foreach (LastSeen seen in toSend)
                    {
                        laserAnt.receive(seen);
                    }
                }
            }

            // to remote control
            foreach (RemoteControl remote in RemoteControl.registry.Values)
            {
                if (sender.canSendTo(remote.CubeBlock, true))
                {
                    foreach (LastSeen seen in toSend)
                    {
                        remote.receive(seen);
                    }
                }
            }
        }