// Assume this is triggered when sensor detects player
        public void playerDetected()
        {
            //Echo("Player detected!");

            for (int i = 0; i < doors.Count; i++)
            {
                IMyDoor door           = doors[i];
                Boolean anyoneNearDoor = false;
                for (int j = 0; j < sensors.Count; j++)
                {
                    VRage.ModAPI.IMyEntity player = sensors[j].LastDetectedEntity;
                    if (player == null)
                    {
                        continue;
                    }
                    //Echo("Checking player at " + player.GetPosition().ToString() + " against door " + door.CustomName);

                    if ((player.GetPosition() - door.GetPosition()).Length() <= triggerDist)
                    {
                        anyoneNearDoor = true;
                        break;
                    }
                }
                if (anyoneNearDoor)
                {
                    door.ApplyAction("Open_On");
                }
                else
                {
                    door.ApplyAction("Open_Off");
                }
            }
        }
Exemple #2
0
 void closeDoors(List <IMyTerminalBlock> DoorList)
 {
     for (int i = 0; i < DoorList.Count; i++)
     {
         IMyDoor d = DoorList[i] as IMyDoor;
         if (d == null)
         {
             continue;
         }
         if (d.Status == DoorStatus.Open || d.Status == DoorStatus.Opening)
         {
             d.ApplyAction("Open");
         }
     }
 }
        public AutoDoorProgram(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action <string> echo, TimeSpan elapsedTime)
        {
            GridTerminalSystem = grid;
            Echo        = echo;
            ElapsedTime = elapsedTime;
            Me          = me;

            doors   = new List <IMyDoor>();
            sensors = new List <IMySensorBlock>();

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

            grid.SearchBlocksOfName(PREFIX, blocks);

            // Add some error handling for blocks not found

            for (int i = 0; i < blocks.Count; i++)
            {
                IMyTerminalBlock block     = blocks[i];
                String           blockType = block.DefinitionDisplayNameText;
                String           blockName = block.CustomName;

                //Echo("Processing block " + blockName);

                if (blockType.Equals("Sensor"))
                {
                    IMySensorBlock sensor = block as IMySensorBlock;
                    sensor.ApplyAction("OnOff_On");

                    List <ITerminalProperty> properties = new List <ITerminalProperty>();
                    sensor.GetProperties(properties);

                    sensor.SetValueFloat("Back", SensorBack);
                    sensor.SetValueFloat("Bottom", SensorBottom);
                    sensor.SetValueFloat("Top", SensorTop);
                    sensor.SetValueFloat("Left", SensorLeft);
                    sensor.SetValueFloat("Right", SensorRight);
                    sensor.SetValueFloat("Front", SensorFront);
                    sensor.SetValueBool("Detect Asteroids", false);
                    sensor.SetValueBool("Detect Enemy", false);
                    sensor.SetValueBool("Detect Floating Objects", false);
                    sensor.SetValueBool("Detect Friendly", true);
                    sensor.SetValueBool("Detect Large Ships", false);
                    sensor.SetValueBool("Detect Neutral", false);
                    sensor.SetValueBool("Detect Owner", true);
                    sensor.SetValueBool("Detect Players", true);
                    sensor.SetValueBool("Detect Small Ships", false);
                    sensor.SetValueBool("Detect Stations", false);
                    sensor.SetValueBool("Audible Proximity Alert", false);
                    sensors.Add(sensor);
                }
                else if (blockType.Equals("Sliding Door") || blockType.Equals("Door"))
                {
                    IMyDoor door = block as IMyDoor;
                    door.ApplyAction("Open_Off");
                    doors.Add(door);
                }
                else if (blockType.Equals("Rotor") || blockType.Equals("Advanced Rotor"))
                {
                    rotor = block as IMyMotorStator;
                    rotor.ApplyAction("OnOff_On");
                    rotor.SetValueFloat("Torque", 3.36E+07f);
                    rotor.SetValueFloat("BrakingTorque", 3.36E+07f);
                    rotor.SetValueFloat("Velocity", rotorSpeed);
                    rotor.SetValueFloat("UpperLimit", float.PositiveInfinity);
                    rotor.SetValueFloat("LowerLimit", float.NegativeInfinity);

                    // Add config here
                }
            }
        }
Exemple #4
0
 public void On() => block_.ApplyAction("OnOff_On");
Exemple #5
0
 protected void OpenDoor(IMyDoor door)
 {
     door.ApplyAction("Open_On");
 }
Exemple #6
0
 private void CloseDoor(IMyDoor door)
 {
     door.ApplyAction("Open_Off");
 }
Exemple #7
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"));
                }
            }
        }