コード例 #1
0
ファイル: LaserAntenna.cs プロジェクト: borrel/Autopilot
        public void UpdateAfterSimulation100()
        {
            try
            {
                if (!myLaserAntenna.IsWorking)
                {
                    return;
                }

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

                // stage 5 is the final stage. It is possible for one to be in stage 5, while the other is not
                MyObjectBuilder_LaserAntenna builder = CubeBlock.getSlim().GetObjectBuilder() as MyObjectBuilder_LaserAntenna;
                if (builder.targetEntityId != null)
                {
                    foreach (LaserAntenna lAnt in value_registry)
                    {
                        if (lAnt.CubeBlock.EntityId == builder.targetEntityId)
                        {
                            if (builder.State == 5 && (lAnt.CubeBlock.getSlim().GetObjectBuilder() as MyObjectBuilder_LaserAntenna).State == 5)
                            {
                                //log("Laser " + CubeBlock.gridBlockName() + " connected to " + lAnt.CubeBlock.gridBlockName(), "UpdateAfterSimulation100()", Logger.severity.DEBUG);
                                foreach (LastSeen seen in myLastSeen.Values)
                                {
                                    lAnt.receive(seen);
                                }
                                foreach (Message mes in myMessages)
                                {
                                    lAnt.receive(mes);
                                }
                                break;
                            }
                        }
                    }
                }

                // send to attached receivers
                Receiver.sendToAttached(CubeBlock, myLastSeen);
                Receiver.sendToAttached(CubeBlock, myMessages);

                UpdateEnemyNear();
            }
            catch (Exception e)
            { myLogger.log("Exception: " + e, "UpdateAfterSimulation100()", Logger.severity.ERROR); }
        }
コード例 #2
0
ファイル: ProgrammableBlock.cs プロジェクト: borrel/Autopilot
 /// <summary>
 /// Uses MessageParser to grab messages, then sends them out. Not registered for event because it fires too frequently.
 /// </summary>
 /// Not actually subscribed to an event
 private void myProgBlock_CustomNameChanged()
 {
     try
     {
         List <Message> toSend = MessageParser.getFromName(myProgBlock as IMyTerminalBlock);                // get messages from name
         if (toSend == null || toSend.Count == 0)
         {
             myLogger.debugLog("could not get message from parser", "ProgBlock_CustomNameChanged()", Logger.severity.TRACE);
             return;
         }
         Receiver.sendToAttached(CubeBlock, toSend);
         myLogger.debugLog("finished sending message", "myProgBlock_CustomNameChanged()", Logger.severity.TRACE);
     }
     catch (Exception e)
     {
         myLogger.log("Exception: " + e, "ProgBlock_CustomNameChanged()", Logger.severity.ERROR);
     }
 }
コード例 #3
0
ファイル: Beacon.cs プロジェクト: borrel/Autopilot
        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
        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); }
        }