private IMyDoor GetNearestGateOnDifferentGrid(IMyDoor sourceGate) { List <Sandbox.ModAPI.IMySlimBlock> gateList = GetGateList(); double distance = 0.0d; IMyDoor nearest = null; //MyAPIGateway.Utilities.ShowNotification("Searching for portals", 250); foreach (var gate in gateList) { // Skip disabled, or destroyed gates // Skip if on same grid as source gate if (gate.IsDestroyed || !gate.FatBlock.IsFunctional || gate.FatBlock.GetTopMostParent().EntityId == sourceGate.GetTopMostParent().EntityId) { continue; } // THen find the closest. if (distance == 0.0d || (entrance_g.GetPosition() - gate.FatBlock.GetPosition()).Length() < distance) { nearest = gate.FatBlock as IMyDoor; distance = (entrance_g.GetPosition() - gate.FatBlock.GetPosition()).Length(); } } //if(nearest != null) //MyAPIGateway.Utilities.ShowNotification("Nearest Gate = " + nearest.CustomName, 250); return(nearest); }
/// <param name="eager">Should the trigger execute as soon as the door starts opening?</param> /// <param name="raw">Use raw status. Triggers twice: Opening, Open.</param> public DoorStatusChangedTrigger(ISelector <IMyDoor> door, bool eager = true, bool raw = false) { _door = door.GetBlock(); _doorStatus = GetStatus(); _eager = eager; _raw = raw; }
public void Scan(MyGridProgram program) { this.doors.Clear(); this.sases.Clear(); program.GridTerminalSystem.GetBlocksOfType(this.tmpDoorList, d => d.CubeGrid == program.Me.CubeGrid && d.IsFunctional); foreach (IMyDoor door in this.tmpDoorList) { var match = SAS_DOOR_RE.Match(door.DisplayNameText); if (match != null) { IMyDoor otherDoor = this.tmpSases.GetValueOrDefault(match.Groups[1].Value); if (otherDoor != null) { this.sases.Add(new Sas($"{match.Groups[1].Value})", door, otherDoor)); this.tmpSases.Remove(match.Groups[1].Value); } else { this.tmpSases.Add(match.Groups[1].Value, door); } } else { this.doors.Add(door); } } this.doors.AddRange(this.tmpSases.Values); this.logger?.Invoke($"Found {this.doors.Count} doors and {this.sases.Count} sases"); this.tmpSases.Clear(); }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { entrance_g = this.Entity as IMyDoor; entrance_g.NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME; // MyAPIGateway.Utilities.ShowNotification("Is Running", 10000, MyFontEnum.Red); entrance_g.DoorStateChanged += DoorSateChanged; }
// 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"); } } }
public void calibration() { FinishedCycle = false; //Find which direction the user is entering by checking //which sensor is detecting the user ActivatedSensor = SensorList.Find(match => { return(match.IsActive); }); //Find which door the user entered by checking which door is open ActivatedDoor = DoorList.Find(match => { return(match.Status == DoorStatus.Open); }); //Determine which sensor is the one not active OppositeSensor = SensorList.Find(match => { return(!match.IsActive); }); //Close all doors to prepare for airlock cycle foreach (var door in DoorList) { if (door.Status != DoorStatus.Closed) { door.CloseDoor(); Echo($"{door.CustomName} closed"); } } //TODO: LCD screen setup }
protected void LoadAirlock(string baseName) { string ventName = String.Format("Air Vent ({0} Airlock)", baseName); string intDoorName = String.Format("Airlock Door: Int. ({0})", baseName); string extDoorName = String.Format("Airlock Door: Ext. ({0})", baseName); vent = (IMyAirVent)GridTerminalSystem.GetBlockWithName(ventName); intDoor = (IMyDoor)GridTerminalSystem.GetBlockWithName(intDoorName); extDoor = (IMyDoor)GridTerminalSystem.GetBlockWithName(extDoorName); if (vent == null) { throw new Exception("Missing airvent: " + ventName); } if (intDoor == null) { throw new Exception("Missing int. door: " + intDoorName); } if (extDoor == null) { throw new Exception("Missing ext. door: " + extDoorName); } intClosed = intDoor.OpenRatio == 0f; intOpened = intDoor.OpenRatio == 1f; extClosed = extDoor.OpenRatio == 0f; extOpened = extDoor.OpenRatio == 1f; ventLevel = vent.GetOxygenLevel(); evacDone = ventLevel < 0.00001; presDone = ventLevel > 0.99; }
public DoorInfo(IMyDoor door, string description = "") : base(description) { Current = door.OpenRatio; Max = 1.0f; DoorStatus = door.Status; Open = (door.Status == DoorStatus.Open); Close = (door.Status == DoorStatus.Closed); }
public void AddDoor(IMyDoor door, ManagedDoorSettings settings) => _managedDoors.Add(new ManagedDoor() { Door = door, Settings = settings, LastStatus = door.Status, CloseAfter = _dateTimeProvider.Now + settings.AutoCloseInterval, });
/// <summary> /// Gets actions for blocks implementing IMyDoor. /// </summary> public static void GetDoorActions(IMyTerminalBlock tBlock, List <IScrollableAction> actions) { IMyDoor doorBlock = (IMyDoor)tBlock; actions.Add(new BlockAction( () => "Open/Close", () => doorBlock.ToggleDoor())); }
protected bool Valid(IMyDoor door) { if (door == null) { ReportItem("Access: door == null!", StatusReport.Type.ERROR); return(false); } return(true); }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { Container.Entity.NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME; m_block = (IMyCubeBlock)Entity; m_block.IsWorkingChanged += Block_IsWorkingChanged; m_door = (IMyDoor)Entity; m_door.DoorStateChanged += Block_DoorStateChanged; }
public TimableDoor(IMyDoor door, TimeSpan doorOpenTimeSpan) { this.door = door; this.doorOpenTimeSpan = doorOpenTimeSpan; oldIsOpen = IsCurrentlyOpen; if (IsCurrentlyOpen) { opendTimestamp = DateTime.Now.Ticks; } }
bool FuncTest(IMyDoor block) { //Door //Interface name: IMyDoor //Parent: IMyFunctionalBlock //Fields: bool Open = block.Open; return(true); }
public bool Open() { IMyDoor door = Block as IMyDoor; if (door != null) { return(door.Status == DoorStatus.Open); } return(false); }
public AirLock(IMyBlockGroup airLockGroup) { if (airLockGroup == null) { throw new ArgumentNullException("airLockGroup cannot be null"); } _InsideDoor = ParseFromGroup <IMyDoor>(airLockGroup, "In"); _OutsideDoor = ParseFromGroup <IMyDoor>(airLockGroup, "Out"); _AirVent = ParseFromGroup <IMyAirVent>(airLockGroup, "Vent"); }
public AirlockConstruct(ISelector <IMyDoor> innerDoor, ISelector <IMyDoor> outerDoor, ISelector <IMyAirVent> vent) { _innerDoor = innerDoor.GetBlock(); _outerDoor = outerDoor.GetBlock(); _vent = vent.GetBlock(); _status = _vent.Status; _enabled = _vent.Enabled; CycleAction = new ScriptableAction(() => Cycle()); PressurizeAction = new ScriptableAction(() => Cycle(true)); DepressurizeAction = new ScriptableAction(() => Cycle(false)); _triggers.Add(new IntervalTrigger(300).Then(new ScriptableAction(Update))); }
void ProcessJobs() { if (schedule.Count > 0 && schedule[0].TTJ <= 0) { Job curr = schedule[0]; schedule.RemoveAt(0); string name = "ANTI-"; IMyDoor antiDoor = GridTerminalSystem.GetBlockWithName("[NO-RENAME] Anti Door " + curr.misNo) as IMyDoor; switch (curr.type) { case JobType.OpenDoor: if (antiDoor != null) { antiDoor.OpenDoor(); } break; case JobType.Launch: IMyProgrammableBlock missile = GridTerminalSystem.GetBlockWithName(name + curr.misNo) as IMyProgrammableBlock; if (missile == null) { string message = "ABORTING LAUNCH: MISSILE DOES NOT EXIST: \"" + name + curr.misNo + "\""; Output(message); Function(false); //ErrorOutput(message); return; } else { Entry target; long id; if (curr.code.Length > 0 && long.TryParse(curr.code, out id) && TryGetAMT(id, out target)) { missile.TryRun("prep " + target.Position.X + " " + target.Position.Y + " " + target.Position.Z + " " + curr.code); } } break; case JobType.CloseDoor: if (antiDoor != null) { antiDoor.CloseDoor(); } break; } } foreach (Job job in schedule) { --job.TTJ; } }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { //Get door that script it attatched to. Door = Entity as IMyDoor; //Set up detonation callback when 'door' is opened. Door.DoorStateChanged += Detonate; m_objectBuilder = objectBuilder; //DEBUG //MyLogger.Default.ToScreen = false ; //MyLogger.Default.WriteLine("Successfully placed a bolt"); }
public IMyDoor MaxOpenRatio(List <IMyDoor> Doors) { IMyDoor Match = null; for (int i = 0; i < Doors.Count; i++) { if (Match == null || Doors[i].OpenRatio > Match.OpenRatio) { Match = Doors[i]; } } return(Match); }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { Log.DebugWrite(DebugLevel.Info, "Init Called"); this.objectBuilder = objectBuilder; block = (IMyDoor)Entity; if (block.BlockDefinition.SubtypeName == "LgParachute" || block.BlockDefinition.SubtypeName == "SmParachute") { Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME; valid = true; block.DoorStateChanged += Block_DoorStateChanged; } }
public void Main(string argument) { foreach (KeyValuePair <string, List <IMyDoor> > Group in getInterlockGroups()) { IMyDoor MaxOpenDoor = MaxOpenRatio(Group.Value); foreach (IMyDoor Door in Group.Value) { if (!Door.Equals(MaxOpenDoor)) { Door.ApplyAction("Open_Off"); } } } }
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 bool Open() { IMyDoor door = Block as IMyDoor; if (door != null) { // Not sure what was intended here but Open is obsolete. // Not sure if this is supposed to open a door or get the // status so just return true for now. // return door.Status; return(true); } return(false); }
private void InitDoor(IMyDoor door) { allDoors.Add(door); output.Print("Found door " + door.CustomName); string[] data = door.CustomData.Split(program.delimiterChars); if (data.Length >= 2) { string airlockTag = data[0]; string inOut = data[1]; Airlock airlock = GetAirlock(airlockTag); airlock.AddDoor(door, inOut); } }
public static bool IsAirtightBlock(IMySlimBlock block, Vector3I pos, Vector3 normal) { var def = block.BlockDefinition as MyCubeBlockDefinition; if (def == null) { return(false); } var airtight = IsAirtightFromDefinition(def, block.BuildLevelRatio); if (airtight != AirTightMode.USE_MOUNTS) { return(airtight == AirTightMode.SEALED); } Matrix matrix; block.Orientation.GetMatrix(out matrix); matrix.TransposeRotationInPlace(); Vector3 position = (block.FatBlock == null ? Vector3.Zero : (pos - block.FatBlock.Position)); Vector3I cell = Vector3I.Round(Vector3.Transform(position, matrix) + def.Center); Vector3I side = Vector3I.Round(Vector3.Transform(normal, matrix)); var pressurized = def.IsCubePressurized[cell][side]; if (pressurized == MyCubeBlockDefinition.MyCubePressurizationMark.PressurizedAlways) { return(true); } IMyDoor door = block.FatBlock as IMyDoor; if (door != null && (door.Status == DoorStatus.Closed || door.Status == DoorStatus.Closing)) { if (pressurized == MyCubeBlockDefinition.MyCubePressurizationMark.PressurizedClosed) { return(true); } else { return(IsDoorAirtightInternal(def, ref side, door.IsFullyClosed)); } } return(false); }
public bool AssignMembersFromAirVent(IMyAirVent newVent, ShipSystems shipSystems) { this.airVent = newVent; string desiredStateString = GetKeyValue(newVent.CustomData, "AirlockController.DesiredState"); if (desiredStateString == null) { return(false); // State string wasn't found. } this.desiredState = getStateFromString(desiredStateString); string airSideDoorName = GetKeyValue(newVent.CustomData, "AirlockController.AirSideDoorName"); if (airSideDoorName == null) { return(false); } for (int i = 0; i < shipSystems.doors.Count; ++i) { if (shipSystems.doors[i].CustomName == airSideDoorName) { this.airSideDoor = shipSystems.doors[i]; } } if (this.airSideDoor == null) { return(false); // Specified door wasn't found. } string spaceSideDoorName = GetKeyValue(newVent.CustomData, "AirlockController.SpaceSideDoorName"); if (spaceSideDoorName == null) { return(false); } for (int i = 0; i < shipSystems.doors.Count; ++i) { if (shipSystems.doors[i].CustomName == spaceSideDoorName) { this.spaceSideDoor = shipSystems.doors[i]; } } if (this.spaceSideDoor == null) { return(false); // Specified door wasn't found. } return(true); }
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; }
public void AddDoor(IMyDoor door, string role) { switch (role.ToLower()) { case "in": inner = door; break; case "out": outer = door; break; default: break; } }
public override void Init(Sandbox.Common.ObjectBuilders.MyObjectBuilder_EntityBase objectBuilder) { // Type Sandbox.Common.Components.MyEntityComponentBase used in Init not allowed in script logRefCount++; myDoor = this.Entity as IMyDoor; myDoorBlock = this.Entity as Sandbox.ModAPI.IMyCubeBlock; // hook up events myDoor.DoorStateChanged += MyAutoDoor_DoorStateChanged; myDoor.NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME; SetupToggleAction(); // try to setup the action //LogMessage("Started Logging", false); }
public Door(IMyDoor door) { this.door = door; }
private void init() { #region initialization oldPBName = Me.CustomName; unique_id = (new Random()).Next(); all_blocks_found = true; autopilot_en = true; location_name = "UNKNOWN"; // For spinner counter = 0; string parse = Me.CustomName.Replace(BLOCK_PREFIX, ""); int id1 = Me.CustomName.IndexOf('['); int id2 = Me.CustomName.IndexOf(']'); if (id1 >= 0 && id2 >= 0) { parse = parse.Substring(id1 + 1, id2 - id1 - 1); } else { parse = ""; } BaconArgs Args = BaconArgs.parse(parse); IS_BASE = (Args.getFlag('b') > 0); DOCK_LEFT = (Args.getFlag('l') > 0); IS_PLANET = (Args.getFlag('p') > 0); if (IS_PLANET) IS_BASE = true; List<string> nameArg = Args.getOption("name"); if (nameArg.Count > 0 && nameArg[0] != null) { location_name = nameArg[0]; } // Set all known blocks to null or clear lists lcdPanel = null; messageReceiver = null; WANProgram = null; connector = null; remoteControl = null; door = null; timer = null; landLight = null; mainGear = 0; gyros.Clear(); destinations.Clear(); gears.Clear(); // Get all blocks List<IMyTerminalBlock> blks = new List<IMyTerminalBlock>(); GridTerminalSystem.SearchBlocksOfName(BLOCK_PREFIX, blks, hasPrefix); num_blocks_found = blks.Count; // Assign blocks to variables as appropriate foreach (var blk in blks) { // LCD panel for printing if (blk is IMyTextPanel) { lcdPanel = blk as IMyTextPanel; lcdPanel.ShowPublicTextOnScreen(); lcdPanel.SetValueFloat("FontSize", 1.2f); } // Wico Area Network programmable block else if (blk is IMyProgrammableBlock && !blk.Equals(Me)) { WANProgram = blk as IMyProgrammableBlock; } // Autopilot else if (!IS_BASE && blk is IMyRemoteControl) { remoteControl = blk as IMyRemoteControl; } /* Ship or station connector for docking * Used to connect to station and for orientation info */ else if (!IS_PLANET && blk is IMyShipConnector) { connector = blk as IMyShipConnector; } /* Door used for docking; used for orientation information * since it's more obvious which way a door faces than a connector */ else if (!IS_PLANET && blk is IMyDoor) { door = blk as IMyDoor; } // Gyros for ship orientation else if (!IS_BASE && blk is IMyGyro) { IMyGyro g = blk as IMyGyro; gyros.Add(g); } // Timer block so that we can orient ship properly - requires multiple calls/sec else if (!IS_BASE && blk is IMyTimerBlock) { timer = blk as IMyTimerBlock; timer.SetValueFloat("TriggerDelay", 1.0f); } // Light (interior or spotlight) determines where we will land else if (IS_BASE && IS_PLANET && blk is IMyInteriorLight) { landLight = blk as IMyInteriorLight; } // Landing gear.... else if (!IS_BASE && blk is IMyLandingGear) { IMyLandingGear gear = blk as IMyLandingGear; gears.Add(gear); if (gear.CustomName.ToLower().Contains("main")) { mainGear = gears.Count - 1; } } } // Make sure all gyros reset resetGyros(); // Clear block list blks.Clear(); // Get text panel blocks used by Wico Area Network for communication GridTerminalSystem.GetBlocksOfType<IMyTextPanel>(blks, hasWANRPrefix); if (blks.Count == 0) { Echo("Error: Can't find message received text panel for Wico Area Network"); all_blocks_found = false; } else { messageReceiver = blks[0] as IMyTextPanel; messageReceiver.WritePublicTitle(""); messageReceiver.WritePrivateTitle("NAV"); } if (WANProgram == null) { Echo("Error: Can't find programming block for Wico Area Network"); all_blocks_found = false; } if (lcdPanel == null) { Echo("Error: Expect 1 LCD"); all_blocks_found = false; } if (!IS_PLANET && connector == null) { Echo("Error: Can't find any connectors to use for docking"); all_blocks_found = false; } if (!IS_BASE && remoteControl == null) { Echo("Error: Can't find any remote control blocks"); all_blocks_found = false; } if (!IS_PLANET && door == null) { Echo("Error: Can't find door"); all_blocks_found = false; } if (!IS_BASE && gyros.Count == 0) { Echo("Error: No gyros detected"); all_blocks_found = false; } if (!IS_BASE && timer == null) { Echo("Error: No timer found"); all_blocks_found = false; } if (IS_PLANET && landLight == null) { Echo("Error: No light for landing ship destination found"); all_blocks_found = false; } if (!IS_BASE && gears.Count == 0) { Echo("Warning: no landing gear found. You will not be able to land on planets"); } // Init communicator state machine comm = communicate().GetEnumerator(); // Clear autopilot state machine fly = null; #endregion }