コード例 #1
0
        public Program()
        {
            soundBlock  = (IMySoundBlock)GridTerminalSystem.GetBlockWithName(nameSoundBlock);
            lightBlocks = new List <IMyInteriorLight>
            {
                (IMyInteriorLight)GridTerminalSystem.GetBlockWithName(nameLightBlocks[0]),
                (IMyInteriorLight)GridTerminalSystem.GetBlockWithName(nameLightBlocks[1])
            };
            lcdPanel = (IMyTextPanel)GridTerminalSystem.GetBlockWithName(nameLCDPanel);

            bigBadAlertLight         = new AlertLight(lightBlocks[0], Color.Yellow, true);
            biggerBadderAlertLight   = new AlertLight(lightBlocks[1]);
            bigBadAlertSound         = new AlertSound(soundBlock);
            bigBadAlertMessage       = new AlertText(lcdPanel, warningMessage, 2f, Color.Blue, Color.Yellow);
            biggerBadderAlertMessage = new AlertText(lcdPanel, warningMessage2, 3f, Color.Cyan, Color.Red);
            bigBadAlert = new Alert(new List <AlertObject> {
                bigBadAlertLight, bigBadAlertMessage, bigBadAlertSound
            });
            biggerBadderAlert = new Alert(new List <AlertObject> {
                biggerBadderAlertLight, bigBadAlertLight, biggerBadderAlertMessage, bigBadAlertSound
            });

            alertSystemManager = new AlertSystemManager <int>(new Dictionary <int, Alert> {
                { 0, bigBadAlert }, { 1, biggerBadderAlert }
            });
        }
コード例 #2
0
 public void setSound(IMySoundBlock speaker, bool value)
 {
     speaker.SelectedSound = "Alert 1";
     speaker.LoopPeriod    = soundLength;
     if (value)
     {
         if (alarmStarted == null)
         {
             ITerminalAction action;
             action = speaker.GetActionWithName("OnOff_On");
             action.Apply(speaker);
             alarmStarted = DateTime.Now;
             speaker.Play();
         }
         else
         {
             TimeSpan delta = DateTime.Now.Subtract(alarmStarted.Value);   // If the warning time has elapsed, start the welders
             if (delta.TotalSeconds > (soundLength - .9))
             {
                 ITerminalAction action;
                 action = speaker.GetActionWithName("OnOff_On");
                 action.Apply(speaker);
                 alarmStarted = DateTime.Now;
                 speaker.Play();
             }
         }
     }
     else
     {
         alarmStarted = null;
         speaker.Stop();
     }
 }
コード例 #3
0
 public void setSound(IMySoundBlock speaker, bool value)
 {
     speakerGroup.GetBlocksOfType <IMySoundBlock>(speakerList);
     speaker.SelectedSound = soundName;
     speaker.LoopPeriod    = loopTime;
     if (value)
     {
         if (endLoop == null)
         {
             ITerminalAction action;
             action = speaker.GetActionWithName("OnOff_On");
             action.Apply(speaker);
             endLoop = DateTime.Now.AddSeconds(loopTime);
             speaker.Play();
         }
         else
         {
             if (endLoop <= DateTime.Now)
             {
                 ITerminalAction action;
                 action = speaker.GetActionWithName("OnOff_On");
                 action.Apply(speaker);
                 endLoop = DateTime.Now;
                 speaker.Play();
             }
         }
     }
     else
     {
         endLoop = null;
         speaker.Stop();
     }
 }
コード例 #4
0
 // TODO: Workaround for sounds being distorted when calling IMySoundBlock.Play() on a block which is already playing.
 // https://support.keenswh.com/spaceengineers/general/topic/improvements-to-imysoundblock-interface
 public static void PlaySound(this IMySoundBlock soundBlock, String sound)
 {
     if (soundBlock.SelectedSound != sound)
     {
         soundBlock.SelectedSound = sound;
         soundBlock.Play();
     }
 }
コード例 #5
0
ファイル: Rakete.cs プロジェクト: S13B3N/space-engineers
        //Initialiser
        #region Setup Stages
        Program()
        {
            //Sets Runtime
            Runtime.UpdateFrequency = Global_Timestep == 0.16? UpdateFrequency.Update10 : UpdateFrequency.Update1;

            //Setup String
            string SetupString = "Rdavs Guided Missile Script Hints Tips & Setup \n================================================== \n \n \nSystem Setup \n=================== \n \nTo Set Up The Ship: \n------------------------ \n- Put this Code Into a P-block \n- Install a sound block (optional) \n- Install a turret called #A# (seeker turret) \n- Recompile if prompted to 'reset' \n- To fire from the toolbar 'run' this Pb with \n  the argument 'Fire' \n \n\nTo Set Up A Missile: \n--------------------------- \n- Every Missile Requires: \n    ~ 1 gyro\n    ~ Forward thrusters \n    ~ 1 Merge Block \n    ~ 1 battery/power source \n    ~ Warheads (optional) \n    ~ Side thrusters (if in gravity)\n \n- Call everything on missile #A# \n- Weld/paste missile onto launching ship \n- Same missile design can be pasted multiple times \n- Missile(s) are now ready to fire!\n\n \n\nSystem Usage \n=================== \n \nMove to engagement distance (800m), a distinctive  \ntarget lock bleeping will sound from the sound block. \n(if sound block installed) \n \n'Run' The programmable block with the argument  \n'Fire' this will launch the next available missile.  \nthis action can be bound to the toolbar of any cockpit. \n \nA ship can have up to 100 missiles active at any one  \npoint, missile setup for every missile is identical  \nand thus missiles can be printed, copy pasted, etc. \n\n- NOTE:\n- For ALL missiles the weight of the missile\n  (can be found in the 'info' tab in kg)\n  should be written as a number into the \n  custom data of the missiles gyro.\n  This is not compulsory but is necessary for\n  accurate guidance.\n\n\nTroubleshooting: \n============================\n\nif you find that your missiles are:\n\n - Sinking and hit the ground in gravity\n - Miss the target / have sub par guidance\n - Not tracking an enemy\n - Not firing at all\n\nHere are some of the most common faults:\n\n- Check the terminal of the PB, this might show\n  some useful error readouts\n\n- Boost the acceleration of the missile! \n  (especially if unable to hit targets)\n\n- Ensure the turret (called #A#) is turned on \n  and set to attack enemy targets, what this turret\n  targets is what the script will track\n\n- The weight of the missile should be input\n  into the gyros custom data,\n\n- Lateral (side) thrusters are not compulsory but\n  are very useful at helping the guidance\n  especially in natural gravity\n\n \n \nHints & Tips \n=================== \n \n  \nPerformance Tips:  \n------------------------ \n \n- Use light and fast missiles for best small ship  \n  tracking capability, the key to a good hit rate is \n  good missile design!\n \n- For 'best' target tracking ensure your missile has  \n  at least 3x the acceleration of the ship you are  \n  intending to take out. \n \n- Lateral (sideways) thrusters can be used for better  \n  gravity correction and handling. \n \n \nUsage Tips: \n---------------------- \n \n- ID'ing the target can be done with common sense, (ie looking \n  at what the seeker turret is currently looking at) \n \n- you can fire a missile without lock to 'laser guide it'  \n  (ie it follows where you are pointing your ship) \n  towards an enemy, once close tracking will engage \n \n- The missile will (by default) not engage guidance until further  \n  than the ships radius away from where it launched. This should  \n  make it practical for launch tubes/ not damaging the launching ship.  \n\n- If a customn launch distance is required this can be changed by changing\n  the 'launch distance' value in the code shortly after the introduction\n\n- An extra seeker turret can be put on the missile itself (must be called #A#)\n  this missile will then use that turret to guide itself.\n\n- The missile tracking is good but as with anything depends on the pilots\n  ability to use them well, read up on real-world missile usage to help \n  boost your hit rate.\n\n\n\n  \n";

            Me.CustomData = SetupString;

            //Sets ShipSize
            ThisShipSize = (Me.CubeGrid.WorldVolume.Radius);
            ThisShipSize = LaunchDist == 0 ? ThisShipSize : LaunchDist;

            //Collects First Turret
            List <IMyTerminalBlock> TempCollection = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocksOfType <IMyLargeTurretBase>(TempCollection, a => a.CustomName.Contains(MissileTag) && a.DetailedInfo != "NoUse");
            if (TempCollection.Count > 0)
            {
                Turret = TempCollection[0] as IMyLargeTurretBase;
            }

            //Collects Sound/Alarm
            List <IMyTerminalBlock> TempCollection2 = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocksOfType <IMySoundBlock>(TempCollection2, a => a.DetailedInfo != "NoUse");
            if (TempCollection2.Count > 0)
            {
                Alarm = TempCollection2[0] as IMySoundBlock;
                Alarm.SelectedSound = "SoundBlockAlert2";
                Alarm.LoopPeriod    = 99999;
                Alarm.Play();
                Alarm.Enabled = false;
            }

            //Collects RC Unit
            List <IMyTerminalBlock> TempCollection3 = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocksOfType <IMyShipController>(TempCollection3, a => a.DetailedInfo != "NoUse");
            if (TempCollection3.Count > 0)
            {
                RC = TempCollection3[0] as IMyShipController;
            }

            //Collects TOW CameraBlock
            List <IMyTerminalBlock> TempCollection4 = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocksOfType <IMyCameraBlock>(TempCollection3, a => a.DetailedInfo == "#A#");
            if (TempCollection3.Count > 0)
            {
                TOWCamera = TempCollection3[0] as IMyCameraBlock; TOWCamera.EnableRaycast = true;
            }
        }
コード例 #6
0
        public new void Main(string arguments)
        {
            enemies.Clear();
            lostContact.Clear();

            sinceLastAlarm += Runtime.TimeSinceLastRun;

            DetectedEntityData entityData;

            foreach (string serialized in arguments.Split(entitySeparator))
            {
                if (DetectedEntityData.TryDeserialize(serialized, out entityData))
                {
                    if (entityData.relations == Relation_Enemy)
                    {
                        enemies.Add(TerminalActionParameter.Get(entityData.entityId));

                        // sound alarm if enemy is near
                        if (sinceLastAlarm >= alarmInterval &&
                            (entityData.volume > 100 || entityData.volume == 0f) &&
                            entityData.secondsSinceDetected < 60 &&
                            Vector3D.DistanceSquared(Me.GetPosition(), entityData.predictedPosition) < 10000 * 10000)
                        {
                            sinceLastAlarm = new TimeSpan();

                            IMySoundBlock alarm = GridTerminalSystem.GetBlockWithName("Proximity Alarm")
                                                  as IMySoundBlock;
                            if (alarm == null)
                            {
                                Terminate("Proximity Alarm is not a sound block");
                                return;
                            }
                            else
                            {
                                alarm.ApplyAction("PlaySound");
                            }
                        }
                    }
                    else if (entityData.relations == Relation_Owner && entityData.secondsSinceDetected > 10)
                    {
                        lostContact.Add(TerminalActionParameter.Get(entityData.entityId));
                    }
                }
                else
                {
                    Terminate("Deserialize failed: " + serialized);
                    return;
                }
            }

            DisplayEntitiesOnPanel("Wide LCD panel for Enemy", enemies);
            DisplayEntitiesOnPanel("Wide LCD panel for Lost Contact", lostContact);
        }
コード例 #7
0
            public override void InitWithDrone(Drone drone)
            {
                Drone = drone;
                Drone.ListenToChannel(DockingRequestChannel);
                Drone.NetworkService.RegisterBroadcastCallback(DockingRequestChannel, "docking_request_pending");
                Drone.Program.IGC.UnicastListener.SetMessageCallback("unicast");

                List <IMySoundBlock> soundBlocks = new List <IMySoundBlock>();

                Drone.Grid().GetBlocksOfType <IMySoundBlock>(soundBlocks, rc => rc.CustomName == "Drone Klaxon" && rc.IsSameConstructAs(Drone.Program.Me));
                DroneKlaxon            = soundBlocks.First();
                DroneKlaxon.LoopPeriod = 2f;
            }
コード例 #8
0
        bool FuncTest(IMySoundBlock block)
        {
            //Sound Block
            //Interface name: IMySoundBlock
            //Parent: IMyFunctionalBlock
            //Fields:
            float Volume          = block.Volume;
            float Range           = block.Range;
            bool  IsSoundSelected = block.IsSoundSelected;
            float LoopPeriod      = block.LoopPeriod;

            return(true);
        }
コード例 #9
0
        private void SaveAndApply(IBlockConfiguration block, IMySoundBlock soundBlock, Action <IMySoundBlock> action)
        {
            if (!block.HasStyle)
            {
                block.SetStyle(nameof(IMySoundBlock.Enabled), soundBlock.Enabled);
                block.SetStyle(nameof(IMySoundBlock.SelectedSound), soundBlock.SelectedSound);
                block.SetStyle(nameof(IMySoundBlock.Volume), soundBlock.Volume);
                block.SetStyle(nameof(IMySoundBlock.Range), soundBlock.Range);
                block.SetStyle(nameof(IMySoundBlock.LoopPeriod), soundBlock.LoopPeriod);
            }

            action(soundBlock);
        }
コード例 #10
0
        public void setUp()
        {
            control    = GridTerminalSystem.GetBlockWithName("Targetting Ray/Remote") as IMyShipController;
            XROT       = GridTerminalSystem.GetBlockWithName("Targetting Ray/Yaw Rotor") as IMyMotorStator;
            YROT       = GridTerminalSystem.GetBlockWithName("Targetting Ray/Pitch Rotor") as IMyMotorStator;
            camera     = GridTerminalSystem.GetBlockWithName("Targetting Ray/Camera") as IMyCameraBlock;
            soundBlock = GridTerminalSystem.GetBlockWithName("Targetting Ray/Sound Block") as IMySoundBlock;
            if (camera != null && camera.EnableRaycast == false)
            {
                camera.EnableRaycast = true;
            }

            misCMDListener = IGC.RegisterBroadcastListener(misCMDTag);
            misCMDListener.SetMessageCallback();
        }
コード例 #11
0
        private int timeSinceSpoken = -2;         // -2 means player hasn't gone into antenna range even,
        //-1 means player hasn't visited Miki Scrap yet. Otherwise it's normally counting up to AudioMaxTime

        //				MyAPIGateway.Utilities.ShowNotification(""+timeSinceSpoken, 1000, MyFontEnum.Debug);

        internal MikiScrap(IMyCubeGrid mikiScrapGrid, IMyRemoteControl remoteControl, MyInventory scrapIn, MyInventory output,
                           IMyDoor furnaceDoor, IMySoundBlock speaker, List <IMyTextPanel> furnaceLcds,
                           List <IMyReflectorLight> furnaceSpotlights,
                           MyInventory furnaceOutput, QueuedAudioSystem audioSystem)
        {
            this.mikiScrapGrid     = mikiScrapGrid;
            this.remoteControl     = remoteControl;
            this.scrapIn           = scrapIn;
            this.output            = output;
            this.furnaceDoor       = furnaceDoor;
            this.speaker           = speaker;
            this.furnaceLcds       = furnaceLcds;
            this.furnaceSpotlights = furnaceSpotlights;
            this.furnaceOutput     = furnaceOutput;
            this.audioSystem       = audioSystem;
        }
コード例 #12
0
        private void Restore(IBlockConfiguration block, IMySoundBlock soundBlock)
        {
            soundBlock.Enabled = block.GetBooleanStyle(nameof(IMySoundBlock.Enabled), true);
            // TODO: Currently assuming that sound blocks are off by default.
            // https://support.keenswh.com/spaceengineers/general/topic/improvements-to-imysoundblock-interface
            var selectedSound = block.GetStringStyle(nameof(IMySoundBlock.SelectedSound));

            if (selectedSound != soundBlock.SelectedSound)
            {
                soundBlock.Stop();
                soundBlock.SelectedSound = selectedSound;
            }
            soundBlock.Volume     = block.GetSingleStyle(nameof(IMySoundBlock.Volume), 1);
            soundBlock.Range      = block.GetSingleStyle(nameof(IMySoundBlock.Range), 1);
            soundBlock.LoopPeriod = block.GetSingleStyle(nameof(IMySoundBlock.LoopPeriod));
        }
コード例 #13
0
        Program()
        {
            gts = GridTerminalSystem;

            cockpit  = gts.GetBlockWithName(COCKPIT) as IMyCockpit;
            sound    = gts.GetBlockGroupWithName(SOUND) as IMySoundBlock;
            radar    = new Radar(RADAR);
            arta     = new Artillery(ARTA, cockpit, 1200, 900);
            Torpedos = new List <Torpedo>();
            InitializeTorpedos();
            WolfPackDelays = new List <int>();
            lcd            = gts.GetBlockWithName(LCD) as IMyTextPanel;
            if (lcd == null)
            {
                lcd = cockpit.GetSurface(0) as IMyTextPanel;
            }
        }
コード例 #14
0
        public Program()
        {
            List <IMyGasTank> listH2Tanks = new List <IMyGasTank>();

            foreach (string nameH2Tank in nameHydrogenTanks)
            {
                listH2Tanks.Add((IMyGasTank)GridTerminalSystem.GetBlockWithName(nameH2Tank));
            }
            IMyInteriorLight warningLight      = (IMyInteriorLight)GridTerminalSystem.GetBlockWithName(nameWarningLight);
            IMyTextPanel     warningPanel      = (IMyTextPanel)GridTerminalSystem.GetBlockWithName(nameLCDPanel);
            IMySoundBlock    warningSoundBlock = (IMySoundBlock)GridTerminalSystem.GetBlockWithName(nameSoundBlock);

            lowH2WarningSystem = new LowHydrogenWarningSystem(listH2Tanks, warningLight, warningPanel, warningSoundBlock)
            {
                warningLevel = warningLevel
            };

            Runtime.UpdateFrequency = UpdateFrequency.Update100;
        }
コード例 #15
0
 public void setUp()
 {
     if (shipId.Length > 0)
     {
         shipId = shipId + " ";
     }
     control    = GridTerminalSystem.GetBlockWithName(shipId + "Targetting Ray/Remote") as IMyRemoteControl;
     XROT       = GridTerminalSystem.GetBlockWithName(shipId + "Targetting Ray/Yaw Rotor") as IMyMotorStator;
     YROT       = GridTerminalSystem.GetBlockWithName(shipId + "Targetting Ray/Pitch Rotor") as IMyMotorStator;
     YROTA      = GridTerminalSystem.GetBlockWithName(shipId + "Targetting Ray/Anti Pitch Rotor") as IMyMotorStator;
     camera     = GridTerminalSystem.GetBlockWithName(shipId + "Targetting Ray/Camera") as IMyCameraBlock;
     soundBlock = GridTerminalSystem.GetBlockWithName(shipId + "Targetting Ray/Sound Block") as IMySoundBlock;
     if (camera != null && camera.EnableRaycast == false)
     {
         camera.EnableRaycast = true;
     }
     if (control != null)
     {
         control.ControlThrusters = false;
     }
 }
コード例 #16
0
        //Main Method
        #region Main Method
        void Main(string argument)
        {
            //General Layout Diagnostics
            OP_BAR();
            QuickEcho(MISSILES.Count, "Active (Fired) Missiles:");
            QuickEcho(Runtime.LastRunTimeMs, "Runtime:");
            Echo("Version:  " + VERSION);
            Echo("\nInfo:\n---------------");
            Echo(Lstrundata);

            #region Block Error Readouts

            //Core Block Checks
            if (RC == null || RC.CubeGrid.GetCubeBlock(RC.Position) == null)
            {
                Echo(" ~ No Ship Control Found,\nInstall Forward Facing Cockpit/RC/Flightseat And Press Recompile"); RC = null; return;
            }
            if (Turret == null || Turret.CubeGrid.GetCubeBlock(Turret.Position) == null)
            {
                Echo(" ~ Searching For A new Seeker\n (Guidance Turret)\n Name Of Turret Needs to be: '#A#'\nInstall Block And Press Recompile"); Turret = null; return;
            }
            if (Alarm == null || Alarm.CubeGrid.GetCubeBlock(Alarm.Position) == null)
            {
                Echo(" ~ No Sound Block For Lock Tone Found,\nInstall Block And Press Recompile\n (script will work fine without) "); Alarm = null;
            }

            #endregion

            //Sounds 60 hz growl lock Alarm
            if (Turret != null && Alarm != null)
            {
                if (!Turret.GetTargetedEntity().IsEmpty() && !Alarm.Enabled)
                {
                    Alarm.Enabled = true;
                }
                else if (Turret.GetTargetedEntity().IsEmpty() && Alarm.Enabled)
                {
                    Alarm.Enabled = false;
                }
            }

            //Begins Launch Scheduler
            //-----------------------------------------
            if (argument == "Fire" && LaunchStateMachine == null)
            {
                LaunchStateMachine = MissileLaunchHandler().GetEnumerator();
            }

            //Runs Guidance Block (foreach missile)
            //---------------------------------------
            for (int i = 0; i < MISSILES.Count; i++)
            {
                var ThisMissile = MISSILES[i];

                //Runs Standard System Guidance
                if (ThisMissile.IS_CLEAR == true)
                {
                    STD_GUIDANCE(ThisMissile);
                }

                //Fires Straight (NO OVERRIDES)
                else if (ThisMissile.IS_CLEAR == false)
                {
                    if ((ThisMissile.GYRO.GetPosition() - Me.GetPosition()).Length() > ThisShipSize)
                    {
                        ThisMissile.IS_CLEAR = true;
                    }
                }

                //Disposes If Out Of Range Or Destroyed (misses a beat on one missile)
                bool Isgyroout     = ThisMissile.GYRO.CubeGrid.GetCubeBlock(ThisMissile.GYRO.Position) == null;
                bool Isthrusterout = ThisMissile.THRUSTERS[0].CubeGrid.GetCubeBlock(ThisMissile.THRUSTERS[0].Position) == null;
                bool Isouttarange  = (ThisMissile.GYRO.GetPosition() - Me.GetPosition()).LengthSquared() > 9000 * 9000;
                if (Isgyroout || Isthrusterout || Isouttarange)
                {
                    MISSILES.Remove(ThisMissile);
                }
            }

            //Launcher Statemachine Disposed If Complete
            //---------------------------------------------------
            if (LaunchStateMachine != null)
            {
                if (!LaunchStateMachine.MoveNext() || !LaunchStateMachine.Current)
                {
                    LaunchStateMachine.Dispose();
                    LaunchStateMachine = null;
                }
            }
        }
コード例 #17
0
        //Main Functions

        public void SwitchRedAlert()
        {
            List <IMyLightingBlock> rotatLights  = GetRotatingLights();
            List <IMyLightingBlock> alarmLights  = GetAlarmLights();
            List <IMyLightingBlock> switchLights = GetSwtchLights();
            List <IMyLightingBlock> otherLights  = GetOtherLights();
            List <IMyLightingBlock> sredLights   = GetSredLights();
            IMySoundBlock           alarmBlock   = GridTerminalSystem.GetBlockWithName(SOUND_BLOCK) as IMySoundBlock;

            onAlert = !onAlert;

            if (onAlert)     // turn the <s> F*****g Furries </s> on
            {
                ChangeLightsColor(otherLights, new Color(60, 0, 0));
                ChangeLightsColor(switchLights, new Color(0, 0, 255));
                ChangeLightsColor(alarmLights, new Color(0, 0, 255));
                ChangeLightsColor(sredLights, new Color(60, 0, 0));
                ChangeLightsStatus(rotatLights, true);
                ChangeLightsStatus(alarmLights, true);
                if (alarmBlock != null)
                {
                    alarmBlock.Play();
                }
                foreach (IMyLightingBlock l in otherLights)
                {
                    l.BlinkLength          = 50f;
                    l.BlinkIntervalSeconds = 2;
                }
                foreach (IMyLightingBlock l in switchLights)
                {
                    l.BlinkLength          = 50f;
                    l.BlinkIntervalSeconds = 2;
                }
                SetWeapons(true);
                CloseAllDoors();
                Output("\nRED ALERT");
                if (EnergyControl != null)
                {
                    EnergyControl.TryRun("COMBAT");
                }
            }
            else     // turn the <s> F*****g Furries </s> off
            {
                ChangeLightsColor(otherLights, new Color(255, 255, 255));
                ChangeLightsColor(switchLights, new Color(255, 255, 255));
                ChangeLightsColor(sredLights, new Color(255, 255, 255));
                ChangeLightsStatus(rotatLights, false);
                ChangeLightsStatus(alarmLights, false);
                if (alarmBlock != null)
                {
                    alarmBlock.Stop();
                }
                foreach (IMyLightingBlock l in otherLights)
                {
                    l.BlinkIntervalSeconds = 0;
                    l.BlinkOffset          = 50f;
                }
                foreach (IMyLightingBlock l in switchLights)
                {
                    l.BlinkIntervalSeconds = 0;
                }
                Output("\nIN ORDER");
                if (EnergyControl != null)
                {
                    EnergyControl.TryRun("NORMAL");
                }
            }
        }
コード例 #18
0
        public void Main(string argument, UpdateType updateSource)
        {
            soundBlock = (IMySoundBlock)GridTerminalSystem.GetBlockWithName(AlarmBlockName);
            Runtime.UpdateFrequency = UpdateFrequency.Update100;


            IMyTextPanel MessagePanel = (IMyTextPanel)GridTerminalSystem.GetBlockWithName(messagePanelName);



            // If setupcomplete is false, run Setup method.
            if (!setupcomplete)
            {
                Echo("Running setup.");
                Setup();
                SaveData();
            }
            else
            {
                // To create a listener, we use IGC to access the relevant method.
                // We pass the same tag argument we used for our message.
                IGC.RegisterBroadcastListener(broadcastChannel);


                // Create a list for broadcast listeners.
                List <IMyBroadcastListener> listeners = new List <IMyBroadcastListener>();

                // The method argument below is the list we wish IGC to populate with all Listeners we've made.
                // Our Listener will be at index 0, since it's the only one we've made so far.
                IGC.GetBroadcastListeners(listeners);

                foreach (var item in listeners)
                {
                    Echo("Somone listen");
                }
                if (listeners[0].HasPendingMessage)
                {
                    // Let's create a variable for our new message.
                    // Remember, messages have the type MyIGCMessage.
                    MyIGCMessage message = new MyIGCMessage();

                    // Time to get our message from our Listener (at index 0 of our Listener list).
                    // We do this with the following method:
                    message = listeners[0].AcceptMessage();


                    // A message is a struct of 3 variables. To read the actual data,
                    // we access the Data field, convert it to type string (unboxing),
                    // and store it in the variable messagetext.
                    string messagetext = message.Data.ToString();

                    // We can also access the tag that the message was sent with.
                    string messagetag = message.Tag;

                    //Here we store the "address" to the Programmable Block (our friend's) that sent the message.
                    long sender = message.Source;

                    //Do something with the information!
                    Echo("Message received with tag" + messagetag + "\n\r");
                    Echo("from address " + sender.ToString() + ": \n\r");
                    Echo(messagetext);

                    MessagePanel.WriteText("Error");

                    if (knownIp.Contains(sender.ToString()))
                    {
                        Echo("Here222");
                        Gates("y");
                        MessagePanel.WriteText(messagetext);
                    }
                    else if (messagetext.Contains(acceptCode))
                    {
                        MessagePanel.WriteText("Err33or");
                        soundBlock.Play();

                        MessagePanel.WriteText("accepted part 2");


                        Echo("Accepted");

                        Gates("y");


                        if (knownIp.Contains(sender.ToString()))
                        {
                            MessagePanel.WriteText("accepted part 3");
                        }
                        else
                        {
                            knownIp.Add(sender.ToString());
                            MessagePanel.WriteText(messagetext);
                        }

                        TextMessage = "";
                        for (int i = 0; i < knownIp.Count; i++)
                        {
                            TextMessage += $"{knownIp[i]}\n";
                        }

                        userIpPanel.WriteText(TextMessage);
                    }
                    else
                    {
                        Echo("Im here");
                        MessagePanel.WriteText("Acces denied" + "\n" + TextMessage);
                        Gates("n");
                    }
                }
            }
        }
コード例 #19
0
            public LowHydrogenWarningSystem(List <IMyGasTank> h2TankBlocks, IMyInteriorLight warningLightBlock, IMyTextPanel warningLCDBlock, IMySoundBlock warningSoundBlock)
            {
                gasTanksManager = new GasTanksManager(h2TankBlocks);

                AlertLight warningLight = new AlertLight(warningLightBlock);
                AlertLight warningLCD   = new AlertText(warningLCDBlock, "Low H2!");
                AlertLight warningSound = new AlertSound(warningSoundBlock);

                listAlertObjects = new List <AlertLight> {
                    warningLight, warningLCD, warningSound
                };
            }
コード例 #20
0
 public AlertSound(IMySoundBlock soundBlock)
 {
     this.soundBlock = soundBlock;
 }
コード例 #21
0
        public void Main(string argument, UpdateType updateSource)
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update10;
            IMyTextPanel display = GridTerminalSystem.GetBlockWithName("LCD Panel [Status]") as IMyTextPanel;

            IMyBlockGroup hangarLights = GridTerminalSystem.GetBlockGroupWithName("Hangar Lights");

            IMyBlockGroup hangarDoors = GridTerminalSystem.GetBlockGroupWithName("Hangar Doors");

            List <IMyTerminalBlock> doors = new List <IMyTerminalBlock>();

            hangarDoors.GetBlocksOfType <IMyAirtightHangarDoor>(doors);

            bool missing = false;

            if (hangarDoors == null) //Returns if doors not found
            {
                Echo("Doors not found");
                missing = true;
            }

            List <IMyTerminalBlock> lights = new List <IMyTerminalBlock>();

            hangarLights.GetBlocksOfType <IMyInteriorLight>(lights);

            if (hangarLights == null) //Returns if lights not found
            {
                Echo("Lights not found");
                missing = true;
            }

            IMyTimerBlock timer = GridTerminalSystem.GetBlockWithName("[Hangar] Timer Block") as IMyTimerBlock;

            if (timer == null) //Returns if timer not found
            {
                Echo("Timer not found");
                missing = true;
            }

            IMyAirVent vent = GridTerminalSystem.GetBlockWithName("[Hangar] Air Vent") as IMyAirVent;

            if (vent == null) //Returns if vent not found
            {
                Echo("Vent not found");
                missing = true;
            }

            IMySoundBlock speaker = GridTerminalSystem.GetBlockWithName("[Hangar] Sound Block") as IMySoundBlock;

            if (speaker == null) //Returns if speaker not found
            {
                Echo("Speaker not found");
                missing = true;
            }

            if (missing == true)
            {
                return;
            }

            UnifyLights(lights);               //Turns all lights on

            speaker.SelectedSound = "Alert 1"; //Set speaker sound

            if (!timer.IsCountingDown)         //Program will skip over if the timer is counting down
            {
                if (timer.TriggerDelay == 10)  //Program will disable timer if the timer is set to 10 (end of hanagar door stage).
                {
                    NormalLights(lights);
                    display.FontSize = 4.4F;
                    Echo("All is well");
                    display.WritePublicTitle("All is well");
                    timer.Enabled      = true;
                    timer.TriggerDelay = 15;
                    speaker.LoopPeriod = 10;
                    speaker.Stop();
                    Runtime.UpdateFrequency = UpdateFrequency.None;
                }
                else //Program will start hangar toggle process else wise
                {
                    if (vent.CanPressurize && !vent.Depressurize) //If the vent needs to depressurize, start depressurize sequence
                    {
                        vent.Depressurize  = true;
                        timer.Enabled      = true;
                        timer.TriggerDelay = 15;
                        timer.StartCountdown();
                        speaker.LoopPeriod = 25;
                        speaker.Play();
                        WarningLights(lights);
                        return;
                    }
                    WarningLights(lights);
                    ToggleDoors(doors);
                    display.FontSize = 3;
                    Echo("!!!CAUTION!!!");
                    display.WritePublicTitle("!!!CAUTION!!!");
                    timer.TriggerDelay = 10;
                    timer.StartCountdown();
                    vent.Depressurize = false;
                    if (speaker.LoopPeriod != 25)
                    {
                        speaker.LoopPeriod = 10;
                        speaker.Play();
                    }
                }
            }
        }
コード例 #22
0
        public HangarController(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action <string> echo, TimeSpan elapsedTime)
        {
            GridTerminalSystem = grid;
            Echo        = echo;
            ElapsedTime = elapsedTime;
            Me          = me;

            hangarDoors   = new List <IMyDoor> [groups.Count];
            interiorDoors = new List <IMyDoor> [groups.Count];
            exteriorDoors = new List <IMyDoor> [groups.Count];
            soundBlocks   = new List <IMySoundBlock> [groups.Count];
            warningLights = new List <IMyInteriorLight> [groups.Count];
            airVents      = new List <IMyAirVent> [groups.Count];

            hangarOpen = new Boolean[groups.Count];

            // Get list of groups on this station/ship
            List <IMyBlockGroup> BlockGroups = new List <IMyBlockGroup>();

            GridTerminalSystem.GetBlockGroups(BlockGroups);

            // Search all groups that exist for the groups with name as specified in groups list
            for (int i = 0; i < BlockGroups.Count; i++)
            {
                int pos = groups.IndexOf(BlockGroups[i].Name);
                // If name is one of our candidates...
                if (pos != -1)
                {
                    List <IMyTerminalBlock> blocks = BlockGroups[i].Blocks;

                    // Define list of blocks for each group
                    List <IMyDoor>          hangarDoorList   = new List <IMyDoor>();
                    List <IMyDoor>          interiorDoorList = new List <IMyDoor>();
                    List <IMyDoor>          exteriorDoorList = new List <IMyDoor>();
                    List <IMySoundBlock>    soundBlockList   = new List <IMySoundBlock>();
                    List <IMyInteriorLight> warningLightList = new List <IMyInteriorLight>();
                    List <IMyAirVent>       airVentList      = new List <IMyAirVent>();

                    // Go through all blocks and add to appropriate list
                    // Also initialize to a sane known state e.g. closed, on...
                    for (int j = 0; j < blocks.Count; j++)
                    {
                        IMyTerminalBlock block     = blocks[j];
                        String           blockType = block.DefinitionDisplayNameText;
                        String           blockName = block.CustomName;
                        block.ApplyAction("OnOff_On");

                        if (blockType.Equals("Airtight Hangar Door"))
                        {
                            IMyDoor item = block as IMyDoor;
                            item.ApplyAction("Open_Off");
                            hangarDoorList.Add(item);
                        }
                        else if ((blockType.Equals("Sliding Door") || blockType.Equals("Door")) && blockName.Contains("Interior"))
                        {
                            IMyDoor item = block as IMyDoor;
                            item.ApplyAction("Open_Off");
                            interiorDoorList.Add(item);
                        }
                        else if ((blockType.Equals("Sliding Door") || blockType.Equals("Door")) && blockName.Contains("Exterior"))
                        {
                            IMyDoor item = block as IMyDoor;
                            item.ApplyAction("Open_Off");
                            exteriorDoorList.Add(item);
                        }
                        else if (blockType.Equals("Sound Block"))
                        {
                            IMySoundBlock item = block as IMySoundBlock;
                            item.ApplyAction("StopSound");
                            item.SetValueFloat("LoopableSlider", 10);
                            soundBlockList.Add(item);
                        }
                        else if (blockType.Equals("Interior Light"))
                        {
                            IMyInteriorLight item = block as IMyInteriorLight;
                            item.ApplyAction("OnOff_Off");
                            item.SetValueFloat("Blink Interval", 1);
                            item.SetValueFloat("Blink Lenght", 50);
                            item.SetValueFloat("Blink Offset", 0);
                            item.SetValue <Color>("Color", Color.Red);
                            warningLightList.Add(item);
                        }
                        else if (blockType.Contains("Air Vent"))
                        {
                            IMyAirVent item = block as IMyAirVent;
                            item.ApplyAction("Depressurize_Off");
                            airVentList.Add(item);
                        }
                    }

                    // Some cleanup
                    hangarDoorList.TrimExcess();
                    interiorDoorList.TrimExcess();
                    exteriorDoorList.TrimExcess();
                    soundBlockList.TrimExcess();
                    warningLightList.TrimExcess();
                    airVentList.TrimExcess();

                    if (hangarDoorList.Count == 0)
                    {
                        Echo("Warning: no hangar doors detected for " + BlockGroups[i].Name);
                    }
                    else if (interiorDoorList.Count == 0)
                    {
                        Echo("Warning: no interior doors detected for " + BlockGroups[i].Name);
                    }
                    else if (soundBlockList.Count == 0)
                    {
                        Echo("Warning: no sound blocks detected for " + BlockGroups[i].Name);
                    }
                    else if (warningLightList.Count == 0)
                    {
                        Echo("Warning: no warning lights detected for " + BlockGroups[i].Name);
                    }
                    else if (airVentList.Count == 0)
                    {
                        Echo("Warning: no air vents detected for " + BlockGroups[i].Name);
                    }

                    // Now that we have populated lists add them to the correct position in the group list

                    hangarDoors[pos]   = hangarDoorList;
                    interiorDoors[pos] = interiorDoorList;
                    exteriorDoors[pos] = exteriorDoorList;
                    soundBlocks[pos]   = soundBlockList;
                    warningLights[pos] = warningLightList;
                    airVents[pos]      = airVentList;
                    hangarOpen[pos]    = false;

                    // Exterior doors have been requested to close so we set a check to lock them when they are in fact closed
                    requests.Add(new requestTicket(pos, "lockExteriorDoors"));
                }
            }
        }