using System; using System.Text; using System.Collections; using System.Collections.Generic; using VRageMath; using VRage.Game; using Sandbox.ModAPI.Interfaces; using Sandbox.ModAPI.Ingame; using Sandbox.Game.EntityComponents; using VRage.Game.Components; using VRage.Collections; using VRage.Game.ObjectBuilders.Definitions; using VRage.Game.ModAPI.Ingame; using SpaceEngineers.Game.ModAPI.Ingame; namespace Tut2 { class Program : MyGridProgram { private const string inDoorName = "inDoor"; private const string outDoorName = "outDoor"; private const string timerName = "timerForClose"; private const string inLightName = "inLight"; private const string outLightName = "outLight"; private const string airVentName = "airVent"; private IMyDoor myDoorOut; private IMyDoor myDoorIn; private IMyTimerBlock myTimerForClose; private IMyLightingBlock myLightIn; private IMyLightingBlock myLightOut; private IMyAirVent myAirVent; private bool closeOut = false; // Konstruktor, wird beim Programmstart/Neukompilieren ausgeführt public Program() { var doorIn = GridTerminalSystem.GetBlockWithName(inDoorName); var doorOut = GridTerminalSystem.GetBlockWithName(outDoorName); var timerForClose = GridTerminalSystem.GetBlockWithName(timerName); var lightIn = GridTerminalSystem.GetBlockWithName(inLightName); var lightOut = GridTerminalSystem.GetBlockWithName(outLightName); var airVent = GridTerminalSystem.GetBlockWithName(airVentName); if (doorIn == null) { Echo($"{inDoorName} not found"); } if (doorIn == null) { Echo($"{outDoorName} not found"); } if (timerForClose == null) { Echo($"{timerName} not found"); } if (lightIn == null || !(lightIn is IMyLightingBlock)) { Echo($"{inLightName} not found"); } if (lightOut == null || !(lightOut is IMyLightingBlock)) { Echo($"{outLightName} not found"); } if (airVent == null) { Echo($"{airVentName} not found"); } myDoorOut = doorOut as IMyDoor; myDoorIn = doorIn as IMyDoor; myTimerForClose = timerForClose as IMyTimerBlock; myLightIn = lightIn as IMyLightingBlock; myLightOut = lightOut as IMyLightingBlock; myAirVent = airVent as IMyAirVent; closeOut = myDoorIn.Status == DoorStatus.Closed; } // Mit der Funktion Save kann man Werte über die Spielsession hinweg speichern public void Save() { } public void Main(string argument, UpdateType updateType) { if (argument == "close") { if(closeOut) { myDoorOut.CloseDoor(); myAirVent.ApplyAction("Depressurize_Off"); myLightIn.ApplyAction("OnOff_On"); } else { myDoorIn.CloseDoor(); myAirVent.ApplyAction("Depressurize_On"); myLightOut.ApplyAction("OnOff_On"); } myTimerForClose.StartCountdown(); } else if (argument == "open") { if (closeOut) { myDoorOut.ApplyAction("OnOff_Off"); myDoorIn.ApplyAction("OnOff_On"); myDoorIn.OpenDoor(); closeOut = false; myLightIn.ApplyAction("OnOff_Off"); } else { myDoorIn.ApplyAction("OnOff_Off"); myDoorOut.ApplyAction("OnOff_On"); myDoorOut.OpenDoor(); closeOut = true; myLightOut.ApplyAction("OnOff_Off"); } } } } }