public Airlock(IMyGridTerminalSystem GridTerminalSystem, int Id, string Action = "") { this.GridTerminalSystem = GridTerminalSystem; this.Id = Id; if (Action != "") { switch (Action) { case "pressurize": this.Pressurize(); break; case "depressurize": this.Depressurize(); break; } } else if (this.Status != null) { switch (this.Status) { case "pressurize": this.Pressurize(); break; case "depressurize": this.Depressurize(); break; } } this.UpdateStatus(); }
public Elevator(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action<string> echo, TimeSpan elapsedTime) { GridTerminalSystem = grid; Echo = echo; ElapsedTime = elapsedTime; Me = me; }
public Example(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action<string> echo, TimeSpan elapsedTime) : base(grid, me, echo, elapsedTime) { EasyBlocks monitoredBlocks = Blocks; // The event will be added to all these blocks AddEvents( monitoredBlocks, delegate(EasyBlock block) { // When this function returns true, the event is triggered return block.Damage() > 1; // when the block is damage more than 1% }, damaged1Percent // this is called when the event is triggered ); }
private long start = 0; // Time at start of program #endregion Fields #region Constructors /*** Constructor ***/ public EasyAPI(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action<string> echo, TimeSpan elapsedTime) { this.clock = this.start = DateTime.Now.Ticks; this.delta = 0; this.GridTerminalSystem = EasyAPI.grid = grid; this.Echo = echo; this.ElapsedTime = elapsedTime; this.ArgumentActions = new Dictionary<string,List<Action>>(); this.Events = new List<IEasyEvent>(); this.Schedule = new List<EasyInterval>(); this.Intervals = new List<EasyInterval>(); // Get the Programmable Block that is running this script (thanks to LordDevious and LukeStrike) this.Self = new EasyBlock(me); this.Reset(); }
public Example(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action<string> echo, TimeSpan elapsedTime) : base(grid, me, echo, elapsedTime) { // Create menu this.menu = new EasyMenu("Test Menu", new [] { new EasyMenuItem("Play Sound", playSound), new EasyMenuItem("Door Status", new[] { new EasyMenuItem("Door 1", toggleDoor, doorStatus), new EasyMenuItem("Door 2", toggleDoor, doorStatus), new EasyMenuItem("Door 3", toggleDoor, doorStatus), new EasyMenuItem("Door 4", toggleDoor, doorStatus) }), new EasyMenuItem("Do Nothing") }); // Get blocks this.speaker = Blocks.Named("MenuSpeaker").FindOrFail("MenuSpeaker not found!"); this.lcd = new EasyLCD(Blocks.Named("MenuLCD").FindOrFail("MenuLCD not found!")); // Handle Arguments On("Up", delegate() { this.menu.Up(); doUpdates(); }); On("Down", delegate() { this.menu.Down(); doUpdates(); }); On("Choose", delegate() { this.menu.Choose(); doUpdates(); }); On("Back", delegate() { this.menu.Back(); doUpdates(); }); }
public DroneNavigation(IMyCubeGrid ship, IMyControllableEntity shipControls, List<IMyEntity> nearbyFloatingObjects, double maxEngagementRange) { //stuff passed from sip _shipControls = shipControls; Ship = ship; GridTerminalSystem = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(ship); _nearbyFloatingObjects = nearbyFloatingObjects; var value = (ship.LocalAABB.Max - ship.LocalAABB.Center).Length(); if (ship.Physics.Mass > 100000) FollowRange = 600 + value; else FollowRange = 400 + value; ShipOrientation(); FindGyros(); _initialized = true; }
internal MyProductBlock(IMyGridTerminalSystem TerminalSystem, IMyCubeGrid CubeGrid, string nameStore) { GetBlocks(TerminalSystem, CubeGrid, nameStore); }
public Console(IMyGridTerminalSystem gridTerminalSystem, string filesStorage) { Shell = new Shell(gridTerminalSystem, filesStorage); GridTerminalSystem = gridTerminalSystem; }
public Ship(IMyTerminalBlock remote, IMyGridTerminalSystem gts, MyGridProgram pro, String Name = "LCDebug") { GridTerminalSystem = gts; this.remote = remote; PopulateGyros(); lastPos = remote.GetPosition(); Me = pro; PopulateThrusters(); // GetStoredInScreen(Name); }
private void SetUpDrone(IMyEntity entity) { IMyGridTerminalSystem gridTerminal = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid((IMyCubeGrid)entity); List <Sandbox.ModAPI.Ingame.IMyTerminalBlock> T = new List <Sandbox.ModAPI.Ingame.IMyTerminalBlock>(); gridTerminal.GetBlocksOfType <IMyTerminalBlock>(T); var droneType = GetDroneType(T); if (droneType.DroneType != DroneTypes.NotADrone) { try { switch (droneType.DroneType) { case DroneTypes.PlayerDrone: { PlayerDrone dro = new PlayerDrone(entity, droneType.Broadcasting); Util.GetInstance().Log("[ConquestMod.SetUpDrone] Found New Player Drone. id=" + dro.GetOwnerId()); pManager.AddDrone(dro); break; } case DroneTypes.MothershipDrone: { MothershipDrone dro = new MothershipDrone(entity, droneType.Broadcasting); entity.DisplayName = ""; ((IMyCubeGrid)entity).Name = ""; ((IMyCubeGrid)entity).ChangeGridOwnership(cManager.GetMothershipID(), MyOwnershipShareModeEnum.Faction); ((IMyCubeGrid)entity).UpdateOwnership(cManager.GetMothershipID(), true); Util.GetInstance().Log("[ConquestMod.SetUpDrone] found new conquest drone"); cManager.AddMothership(dro); break; } case DroneTypes.ConquestDrone: { ConquestDrone dro = new ConquestDrone(entity, droneType.Broadcasting); entity.DisplayName = ""; ((IMyCubeGrid)entity).Name = ""; ((IMyCubeGrid)entity).ChangeGridOwnership(cManager.GetMothershipID(), MyOwnershipShareModeEnum.Faction); ((IMyCubeGrid)entity).UpdateOwnership(cManager.GetMothershipID(), true); Util.GetInstance().Log("[ConquestMod.SetUpDrone] found new conquest drone"); cManager.AddDrone(dro); break; } default: { //Util.Notify("broken drone type"); break; } } } catch (Exception e) { //MyAPIGateway.Entities.RemoveEntity(entity); Util.GetInstance().LogError(e.ToString()); } } }
public AppsDirectoryFileSystemObject(string name, IFileSystemObject parentFileSystemObject, IMyGridTerminalSystem gridTerminalSystem) : base(name, parentFileSystemObject) { this.gridTerminalSystem = gridTerminalSystem; }
public T Get(IMyGridTerminalSystem gridTerminalSystem) { if (cache == null || random.NextDouble() < 1.01) { cache = lookup(gridTerminalSystem); } return cache; }
public static GridCargo Get(IMyGridTerminalSystem gts) { return(new GridCargo(gts)); }
public ConfigReader(IMyGridTerminalSystem gridTerminal, IMyTerminalBlock terminalBlock, String configLCDName) { this.terminalBlock = terminalBlock; this.gridTerminal = gridTerminal; this.configLCDName = configLCDName; }
private void DeleteReverse(SettingsBlockEnforcementItem blockEnforcementSetting, int remove, IMyCubeGrid grid) { int count = 0; IMyGridTerminalSystem gridTerminal = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(grid); List <Sandbox.ModAPI.IMyTerminalBlock> blocksToRemove = new List <Sandbox.ModAPI.IMyTerminalBlock>( ); List <IMyTerminalBlock> blockstoProcess = new List <IMyTerminalBlock>(); gridTerminal.GetBlocksOfType <IMyTerminalBlock>(blockstoProcess); for (int r = blockstoProcess.Count - 1; r >= 0; r--) { Sandbox.ModAPI.IMyTerminalBlock block = (Sandbox.ModAPI.IMyTerminalBlock)blockstoProcess[r]; switch (blockEnforcementSetting.Mode) { case SettingsBlockEnforcementItem.EnforcementMode.BlockSubtypeId: if (!string.IsNullOrEmpty(block.BlockDefinition.SubtypeId) && block.BlockDefinition.SubtypeId.Contains(blockEnforcementSetting.BlockSubtypeId)) { blocksToRemove.Add(block); count++; } break; case SettingsBlockEnforcementItem.EnforcementMode.BlockTypeId: if (block.BlockDefinition.TypeIdString.Contains(blockEnforcementSetting.BlockTypeId)) { blocksToRemove.Add(block); count++; } break; } if (count == remove) { break; } } /* * List<MyObjectBuilder_CubeBlock> blocksToRemove = new List<MyObjectBuilder_CubeBlock>(); * for (int r = gridBuilder.CubeBlocks.Count - 1; r >= 0; r--) * { * MyObjectBuilder_CubeBlock block = gridBuilder.CubeBlocks[r]; * if (block.GetId().ToString().Contains(id)) * { * blocksToRemove.Add(block); * count++; * } * * if (count == remove) * break; * } */ if (blocksToRemove.Count < 1) { return; } List <Vector3I> razeList = new List <Vector3I>( ); foreach (Sandbox.ModAPI.IMyTerminalBlock block in blocksToRemove) { razeList.Add(block.Min); } Wrapper.GameAction(() => { grid.RazeBlocks(razeList); }); }
public BlockHelper(IMyGridTerminalSystem GridTerminalSystem) { this.GridTerminalSystem = GridTerminalSystem; }
internal SectionBlocks(IMyGridTerminalSystem sys, IMyBlockGroup blocks) { blocks.GetBlocksOfType <IMyAirVent>(vents); blocks.GetBlocksOfType <IMySoundBlock>(alarms); blocks.GetBlocksOfType <IMyLightingBlock>(o2Lights); }
public void Init(IMyGridTerminalSystem gts, IMyCubeGrid desiredGrid) { this.airVents = GetAirVents(gts, desiredGrid); this.buttons = GetButtons(gts, desiredGrid); this.doors = GetDoors(gts, desiredGrid); }
public void Scan(IMyGridTerminalSystem gts, GridManager gridManager) { this.assemblers.Clear(); gts.GetBlocksOfType(this.assemblers, a => a.GetInventory(1) != null && gridManager.Manages(a.CubeGrid)); }
public AssemblerManager(IMyGridTerminalSystem gts, GridManager gridManager, IProcessSpawner spawner) { this.Scan(gts, gridManager); spawner.Spawn(p => this.Scan(gts, gridManager), "assembler-scanner", period: 100); }
public Example(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action <string> echo, TimeSpan elapsedTime) : base(grid, me, echo, elapsedTime) { // Create menu this.menu = new EasyMenu("Explore", new [] { new EasyMenuItem("Actions", delegate(EasyMenuItem actionsItem) { List <string> types = new List <string>(); for (int n = 0; n < Blocks.Count(); n++) { var block = Blocks.GetBlock(n); if (!types.Contains(block.Type())) { types.Add(block.Type()); } } types.Sort(); actionsItem.children.Clear(); for (int n = 0; n < types.Count; n++) { actionsItem.children.Add(new EasyMenuItem(types[n], delegate(EasyMenuItem typeItem) { typeItem.children.Clear(); var blocks = Blocks.OfType(typeItem.Text); for (int o = 0; o < blocks.Count(); o++) { var block = blocks.GetBlock(o); typeItem.children.Add(new EasyMenuItem(block.Name(), delegate(EasyMenuItem blockItem) { blockItem.children.Clear(); var actions = block.GetActions(); for (int p = 0; p < actions.Count; p++) { var action = actions[p]; blockItem.children.Add(new EasyMenuItem(action.Name + "", delegate(EasyMenuItem actionItem) { block.ApplyAction(action.Id); return(false); })); } blockItem.children.Sort(); return(true); })); } typeItem.children.Sort(); return(true); })); } actionsItem.children.Sort(); return(true); }) }); // Get blocks this.timer = Blocks.Named("MenuTimer").FindOrFail("MenuTimer not found!"); this.screen = Blocks.Named("MenuLCD").FindOrFail("MenuLCD not found!"); this.lcd = new EasyLCD(this.screen); Every(100 * Milliseconds, doUpdates); // Run doUpdates every 100 milliseconds }
private void ScanForBlockItems( ) { HashSet <IMyEntity> entities = new HashSet <IMyEntity>( ); try { MyAPIGateway.Entities.GetEntities(entities); } catch (Exception ex) { Essentials.Log.Error("Entity list busy, skipping scan.", ex); } foreach (IMyEntity entity in entities) { if (!(entity is IMyCubeGrid)) { continue; } if (entity.Physics == null) { continue; } if (!entity.InScene) { continue; } IMyCubeGrid grid = (IMyCubeGrid)entity; IMyGridTerminalSystem gridTerminal = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(grid); Dictionary <SettingsBlockEnforcementItem, int> blocks = new Dictionary <SettingsBlockEnforcementItem, int>( ); List <IMyTerminalBlock> blockstoProcess = new List <IMyTerminalBlock>( ); gridTerminal.GetBlocksOfType <IMyTerminalBlock>(blockstoProcess); foreach (IMyTerminalBlock myTerminalBlock in blockstoProcess) { IMyTerminalBlock block = myTerminalBlock; foreach (SettingsBlockEnforcementItem item in PluginSettings.Instance.BlockEnforcementItems) { if (item.Mode == SettingsBlockEnforcementItem.EnforcementMode.Off) { continue; } if (item.Mode == SettingsBlockEnforcementItem.EnforcementMode.BlockTypeId && string.IsNullOrEmpty(item.BlockTypeId)) { Essentials.Log.Warn("Block Enforcement item for \"{0}\" is set to mode BlockTypeId but does not have BlockTypeId set."); continue; } if (item.Mode == SettingsBlockEnforcementItem.EnforcementMode.BlockSubtypeId && string.IsNullOrEmpty(item.BlockSubtypeId)) { Essentials.Log.Warn("Block Enforcement item for \"{0}\" is set to mode BlockSubtypeId but does not have BlockSubtypeId set."); continue; } if (item.Mode == SettingsBlockEnforcementItem.EnforcementMode.BlockSubtypeId && !string.IsNullOrEmpty(block.BlockDefinition.SubtypeId) && block.BlockDefinition.SubtypeId.Contains(item.BlockSubtypeId)) { if (blocks.ContainsKey(item)) { blocks[item] += 1; } else { blocks.Add(item, 1); } } if (item.Mode == SettingsBlockEnforcementItem.EnforcementMode.BlockTypeId && !string.IsNullOrEmpty(block.BlockDefinition.TypeIdString) && block.BlockDefinition.TypeIdString.Contains(item.BlockTypeId)) { if (blocks.ContainsKey(item)) { blocks[item] += 1; } else { blocks.Add(item, 1); } } } } /* * MyObjectBuilder_CubeGrid gridBuilder = CubeGrids.SafeGetObjectBuilder(grid); * if (gridBuilder == null) * continue; * * Dictionary<string, int> blocks = new Dictionary<string, int>(); * foreach (MyObjectBuilder_CubeBlock block in gridBuilder.CubeBlocks) * { * foreach(SettingsBlockEnforcementItem item in PluginSettings.Instance.BlockEnforcementItems) * { * if (!item.Enabled) * continue; * * if (block.GetId().ToString().Contains(item.BlockTypeId)) * { * if (blocks.ContainsKey(item.BlockTypeId)) * blocks[item.BlockTypeId] += 1; * else * blocks.Add(item.BlockTypeId, 1); * } * } * } */ foreach (SettingsBlockEnforcementItem item in PluginSettings.Instance.BlockEnforcementItems) { if (item.Mode == SettingsBlockEnforcementItem.EnforcementMode.Off) { continue; } if (!blocks.ContainsKey(item)) { continue; } if (blocks[item] > item.MaxPerGrid) { //foreach(long playerId in CubeGrids.GetBigOwners(gridBuilder)) foreach (long playerId in grid.BigOwners) { ulong steamId = PlayerMap.Instance.GetSteamIdFromPlayerId(playerId); if (steamId > 0) { //Communication.SendPrivateInformation(steamId, string.Format("You have exceeded the max block count of {0} on the ship '{1}'. We are removing {2} blocks to enforce this block limit.", item.BlockTypeId, gridBuilder.DisplayName, blocks[item.BlockTypeId] - item.MaxPerGrid)); Communication.SendPrivateInformation(steamId, string.Format("You have exceeded the max block count of {0} on the ship '{1}'. We are removing {2} blocks to enforce this block limit.", item.BlockTypeId, grid.DisplayName, blocks[item] - item.MaxPerGrid)); } } //DeleteReverse(item.BlockTypeId, blocks[item.BlockTypeId] - item.MaxPerGrid, grid, gridBuilder); DeleteReverse(item, blocks[item] - item.MaxPerGrid, grid); } } } }
public T Get(IMyGridTerminalSystem g) { if (block == null || g.GetBlockWithId(block.EntityId) == null) { block = lookup(g); } return block; }
public Environment(MyGridProgram GridProgram, IMyGridTerminalSystem GridTerminalSystem, BaconDebug Debug) { this.GridProgram = GridProgram; this.GridTerminalSystem = GridTerminalSystem; this.Debug = Debug; }
private GridCargo(IMyGridTerminalSystem gts) { GTS = gts; }
public BaconDebug(string a, IMyGridTerminalSystem b, MyGridProgram c, int d) { this.k = d; var e = new List <IMyTerminalBlock>(); b.GetBlocksOfType <IMyTextPanel>(e, ((IMyTerminalBlock f) => f.CustomName.Contains(a) && f.CubeGrid.Equals(c.Me.CubeGrid))); h = e.ConvertAll <IMyTextPanel>(f => f as IMyTextPanel); this.i = c; newScope("BaconDebug"); }
public DoorManager(IMyGridTerminalSystem gts) { this.gts = gts; }
public void FindBlocks <Type>(IMyGridTerminalSystem TB, List <Type> res, Func <Type, bool> Fp = null) where Type : class { TB.GetBlocksOfType <Type>(res, x => Complies((x as IMyTerminalBlock)) && (Fp == null || Fp(x))); }
public PilotAssist(IMyGridTerminalSystem grid) { this.grid = grid; }
public Drone(IMyEntity ent, BroadcastingTypes broadcasting) { var ship = (IMyCubeGrid)ent; double maxEngagementRange = ConquestMod.MaxEngagementRange; broadcastingType = broadcasting; Ship = ship; var lstSlimBlock = new List<IMySlimBlock>(); GridTerminalSystem = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(ship); //If it has any type of cockipt ship.GetBlocks(lstSlimBlock, (x) => x.FatBlock is IMyShipController); FindWeapons(); //If no cockpit the ship is either no ship or is broken. if (lstSlimBlock.Count != 0) { //Make the controls be the cockpit ShipControls = lstSlimBlock[0].FatBlock as IMyControllableEntity; _ownerId = ((Sandbox.ModAPI.IMyTerminalBlock)ShipControls).OwnerId; #region Activate Beacons && Antennas //Maximise radius on antennas and beacons. lstSlimBlock.Clear(); ship.GetBlocks(lstSlimBlock, (x) => x.FatBlock is IMyRadioAntenna); foreach (var block in lstSlimBlock) { IMyRadioAntenna antenna = (IMyRadioAntenna)block.FatBlock; if (antenna != null) { //antenna.GetActionWithName("SetCustomName").Apply(antenna, new ListReader<TerminalActionParameter>(new List<TerminalActionParameter>() { TerminalActionParameter.Get("Combat Drone " + _manualGats.Count) })); antenna.SetValueFloat("Radius", 5000);//antenna.GetMaximum<float>("Radius")); ITerminalAction act = antenna.GetActionWithName("OnOff_On"); act.Apply(antenna); } } lstSlimBlock = new List<IMySlimBlock>(); ship.GetBlocks(lstSlimBlock, (x) => x.FatBlock is IMyBeacon); foreach (var block in lstSlimBlock) { IMyBeacon beacon = (IMyBeacon)block.FatBlock; if (beacon != null) { beacon.SetValueFloat("Radius", 5000);//beacon.GetMaximum<float>("Radius")); ITerminalAction act = beacon.GetActionWithName("OnOff_On"); act.Apply(beacon); } } #endregion //SetWeaponPower(true); //AmmoManager.ReloadReactors(_allReactors); //AmmoManager.ReloadGuns(_manualGats); ship.GetBlocks(lstSlimBlock, x => x is IMyEntity); List<IMyTerminalBlock> massBlocks = new List<IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType<IMyVirtualMass>(massBlocks); List<IMyTerminalBlock> allTerminalBlocks = new List<IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType<IMyCubeBlock>(allTerminalBlocks); HealthBlockBase = allTerminalBlocks.Count; if (ShipControls != null) { navigation = new DroneNavigation(ship, ShipControls, _nearbyFloatingObjects, maxEngagementRange); } } Ship.OnBlockAdded += RecalcMaxHp; myNumber = numDrones; numDrones++; }
public Shell(IMyGridTerminalSystem gridTerminalSystem, string filesStorage) { RootDirectory = new RootDirectory(gridTerminalSystem, filesStorage); CurrentDirectoryPath = RootDirectory; }
public void FindBlocks(IMyGridTerminalSystem TB, List <IMyTerminalBlock> res, Func <IMyTerminalBlock, bool> Fp = null) { TB.SearchBlocksOfName(inv ? "" : Val, res, x => Complies(x) && (Fp == null || Fp(x))); }
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 } } }
public InventoryController(Program program) { _prog = program; _grid = _prog.GridTerminalSystem; }
public SingleAxisThrustShip(IMyTerminalBlock remote, IMyGridTerminalSystem gts, MyGridProgram pro) : base(remote, gts, pro) { }
public Example(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action<string> echo, TimeSpan elapsedTime) : base(grid, me, echo, elapsedTime) { // Start your code here }
public static IMyFaction GetOwnerFaction(this IMyCubeGrid Grid, bool RecalculateOwners = false) { try { if (RecalculateOwners) { (Grid as MyCubeGrid).RecalculateOwners(); } IMyFaction FactionFromBigowners = null; IMyFaction Faction = null; if (Grid.BigOwners.Count > 0 && Grid.BigOwners[0] != 0) { long OwnerID = Grid.BigOwners[0]; FactionFromBigowners = GeneralExtensions.FindOwnerFactionById(OwnerID); } else { Grid.LogError("Grid.GetOwnerFaction", new Exception("Cannot get owner faction via BigOwners.", new Exception("BigOwners is empty."))); } IMyGridTerminalSystem Term = Grid.GetTerminalSystem(); List <IMyTerminalBlock> AllTermBlocks = new List <IMyTerminalBlock>(); Term.GetBlocks(AllTermBlocks); if (AllTermBlocks.Empty()) { Grid.DebugWrite("Grid.GetOwnerFaction", $"Terminal system is empty!"); return(null); } var BiggestOwnerGroup = AllTermBlocks.GroupBy(x => x.GetOwnerFactionTag()).OrderByDescending(gp => gp.Count()).FirstOrDefault(); if (BiggestOwnerGroup != null) { string factionTag = BiggestOwnerGroup.Key; Faction = MyAPIGateway.Session.Factions.TryGetFactionByTag(factionTag); if (Faction != null) { Grid.DebugWrite("Grid.GetOwnerFaction", $"Found owner faction {factionTag} via terminal system"); } return(Faction ?? FactionFromBigowners); } else { Grid.DebugWrite("Grid.GetOwnerFaction", $"CANNOT GET FACTION TAGS FROM TERMINALSYSTEM!"); List <IMyShipController> Controllers = Grid.GetBlocks <IMyShipController>(); if (Controllers.Any()) { List <IMyShipController> MainControllers; if (Controllers.Any(x => x.IsMainCockpit(), out MainControllers)) { Faction = MyAPIGateway.Session.Factions.TryGetFactionByTag(MainControllers[0].GetOwnerFactionTag()); if (Faction != null) { Grid.DebugWrite("Grid.GetOwnerFaction", $"Found owner faction {Faction.Tag} via main cockpit"); return(Faction ?? FactionFromBigowners); } } // Controls falls down if faction was not found by main cockpit Faction = MyAPIGateway.Session.Factions.TryGetFactionByTag(Controllers[0].GetOwnerFactionTag()); if (Faction != null) { Grid.DebugWrite("Grid.GetOwnerFaction", $"Found owner faction {Faction.Tag} via cockpit"); return(Faction ?? FactionFromBigowners); } else { Grid.DebugWrite("Grid.GetOwnerFaction", $"Unable to owner faction via cockpit!"); Faction = MyAPIGateway.Session.Factions.TryGetFactionByTag(AllTermBlocks.First().GetOwnerFactionTag()); if (Faction != null) { Grid.DebugWrite("Grid.GetOwnerFaction", $"Found owner faction {Faction.Tag} via first terminal block"); return(Faction ?? FactionFromBigowners); } else { Grid.DebugWrite("Grid.GetOwnerFaction", $"Unable to owner faction via first terminal block!"); return(Faction ?? FactionFromBigowners); } } } else { Faction = MyAPIGateway.Session.Factions.TryGetFactionByTag(AllTermBlocks.First().GetOwnerFactionTag()); if (Faction != null) { Grid.DebugWrite("Grid.GetOwnerFaction", $"Found owner faction {Faction.Tag} via first terminal block"); return(Faction ?? FactionFromBigowners); } else { Grid.DebugWrite("Grid.GetOwnerFaction", $"Unable to owner faction via first terminal block!"); return(Faction ?? FactionFromBigowners); } } } } catch (Exception Scrap) { Grid.LogError("Faction.GetOwnerFaction", Scrap); return(null); } }
private List <IMyTerminalBlock> GetBlocksInCurrentGrid(IMyProgrammableBlock pbInstance, IMyGridTerminalSystem GTS) { List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>(); GTS.GetBlocks(blocks); return(blocks.Where(block => block.CubeGrid == pbInstance.CubeGrid).ToList()); }
public AutoHoverController(IMyGridTerminalSystem gts, IMyProgrammableBlock pb) { Me = pb; GridTerminalSystem = gts; remote = GridTerminalSystem.GetBlockWithName(RemoteControlName) as IMyRemoteControl; gyro = GridTerminalSystem.GetBlockWithName(GyroName) as IMyGyro; if (!String.IsNullOrEmpty(TextPanelName)) screen = GridTerminalSystem.GetBlockWithName(TextPanelName) as IMyTextPanel; var list = new List<IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType<IMyGyro>(list, x => x.CubeGrid == Me.CubeGrid && x != gyro); gyros = list.ConvertAll(x => (IMyGyro)x); gyros.Insert(0, gyro); gyros = gyros.GetRange(0, GyroCount); mode = "Hover"; setSpeed = 0; }
public DoorProgress(IMyGridTerminalSystem gts) { }
/// <summary> /// /// Nastaveni terminaloveho systemu /// </summary> /// <param name="gts">Terminal</param> public static void Init(IMyGridTerminalSystem gts) { terminal = gts; }
public ItemManager(IMyGridTerminalSystem terminal) { this.terminal = terminal; }
public static void initialize(IMyGridTerminalSystem GridTerminalSystem) { _GridTerminalSystem = GridTerminalSystem; LCD = new display(); ship = new state(); }
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")); } } }