Initial commit
This commit is contained in:
commit
c30eb4e092
9 changed files with 570 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
AutomaticConnectorActions.mdk.local.ini
|
||||||
|
bin/*
|
||||||
|
obj/*
|
26
AutomaticConnectorActions.csproj
Normal file
26
AutomaticConnectorActions.csproj
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netframework48</TargetFramework>
|
||||||
|
<RootNamespace>IngameScript</RootNamespace>
|
||||||
|
<LangVersion>6</LangVersion>
|
||||||
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
<Configurations>Release;Debug</Configurations>
|
||||||
|
<Platforms>x64</Platforms>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Mal.Mdk2.PbAnalyzers" Version="2.1.10">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Mal.Mdk2.PbPackager" Version="2.0.13">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Mal.Mdk2.References" Version="2.2.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="Instructions.readme" />
|
||||||
|
<AdditionalFiles Include="Instructions.readme" />
|
||||||
|
<AdditionalFiles Include="thumb.png" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
22
AutomaticConnectorActions.mdk.ini
Normal file
22
AutomaticConnectorActions.mdk.ini
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
; This file is project specific and should be checked in to source control.
|
||||||
|
|
||||||
|
[mdk]
|
||||||
|
; This is a programmable block script project.
|
||||||
|
; You should not change this.
|
||||||
|
type=programmableblock
|
||||||
|
|
||||||
|
; Toggle trace (on|off) (verbose output)
|
||||||
|
trace=off
|
||||||
|
|
||||||
|
; What type of minification to use (none|trim|stripcomments|lite|full)
|
||||||
|
; none: No minification
|
||||||
|
; trim: Removes unused types (NOT members).
|
||||||
|
; stripcomments: trim + removes comments.
|
||||||
|
; lite: stripcomments + removes leading/trailing whitespace.
|
||||||
|
; full: lite + renames identifiers to shorter names.
|
||||||
|
minify=full
|
||||||
|
|
||||||
|
; A list of files and folder to ignore when creating the script.
|
||||||
|
; This is a comma separated list of glob patterns.
|
||||||
|
; See https://code.visualstudio.com/docs/editor/glob-patterns
|
||||||
|
ignores=obj/**/*,MDK/**/*,**/*.debug.cs
|
25
AutomaticConnectorActions.sln
Normal file
25
AutomaticConnectorActions.sln
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.5.002.0
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomaticConnectorActions", "AutomaticConnectorActions.csproj", "{D92867FB-CC92-4C92-9351-7F4722903B9D}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{D92867FB-CC92-4C92-9351-7F4722903B9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D92867FB-CC92-4C92-9351-7F4722903B9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D92867FB-CC92-4C92-9351-7F4722903B9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D92867FB-CC92-4C92-9351-7F4722903B9D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {B0297F9C-7544-49C6-8C20-C535445FE9BE}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
53
Instructions.readme
Normal file
53
Instructions.readme
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
=====================================================================================
|
||||||
|
Automatic Connector Actions
|
||||||
|
Made by cswimr
|
||||||
|
Unminified source code available at https://www.coastalcommits.com/cswimr/AutomaticConnectorActions
|
||||||
|
=====================================================================================
|
||||||
|
|
||||||
|
This script will do the following things automatically whenever the host grid connects via a connector to another grid:
|
||||||
|
|
||||||
|
- Disable all gyroscopes on the host grid
|
||||||
|
- Disable all thrusters on the host grid
|
||||||
|
- Set all gas tanks (Oxygen and Hydrogen) on the host grid to Stockpile
|
||||||
|
- Set the recharge mode of all batteries on the host grid to Recharge
|
||||||
|
|
||||||
|
Additionally, whenever the host grid disconnects from a connector, the script will:
|
||||||
|
|
||||||
|
- Enable all gyroscopes on the host grid
|
||||||
|
- Enable all thrusters on the host grid that are prefixed with `[MANEUVERING]`
|
||||||
|
- Set all gas tanks (Oxygen and Hydrogen) on the host grid to not Stockpile
|
||||||
|
- Set the recharge mode of all batteries on the host grid to Auto
|
||||||
|
|
||||||
|
This allows for ships to dock with piston connectors without having to convert the other grid to a station.
|
||||||
|
You can also do this with normal timer blocks and event controllers, but they are not very reliable in my personal experience.
|
||||||
|
|
||||||
|
You can optionally invoke the script manually, through something like an event controller. The arguments are as follows:
|
||||||
|
|
||||||
|
- `dock` - Triggers the docking process
|
||||||
|
- `undock` - Triggers the undocking process
|
||||||
|
|
||||||
|
If you want to use the script manually,
|
||||||
|
you should disable `Polling` in the Custom Data field of the programmable block running the script.
|
||||||
|
|
||||||
|
All configuration for this script is stored in the Programmable Block's Custom Data field.
|
||||||
|
Please DO NOT modify anything inside of this script unless you know what you're doing!
|
||||||
|
|
||||||
|
=====================================================================================
|
||||||
|
|
||||||
|
DO NOT MODIFY ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING!
|
||||||
|
=====================================================================================
|
||||||
|
|
||||||
|
DO NOT MODIFY ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING!
|
||||||
|
=====================================================================================
|
||||||
|
|
||||||
|
DO NOT MODIFY ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING!
|
||||||
|
=====================================================================================
|
||||||
|
|
||||||
|
DO NOT MODIFY ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING!
|
||||||
|
=====================================================================================
|
||||||
|
|
||||||
|
DO NOT MODIFY ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING!
|
||||||
|
=====================================================================================
|
||||||
|
|
||||||
|
DO NOT MODIFY ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING!
|
||||||
|
=====================================================================================
|
7
LICENSE
Normal file
7
LICENSE
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
Copyright 2024 cswimr
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
410
Program.cs
Normal file
410
Program.cs
Normal file
|
@ -0,0 +1,410 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Immutable;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Sandbox.Game.EntityComponents;
|
||||||
|
using Sandbox.ModAPI.Ingame;
|
||||||
|
using Sandbox.ModAPI.Interfaces;
|
||||||
|
using SpaceEngineers.Game.ModAPI.Ingame;
|
||||||
|
using VRage;
|
||||||
|
using VRage.Collections;
|
||||||
|
using VRage.Game;
|
||||||
|
using VRage.Game.Components;
|
||||||
|
using VRage.Game.GUI.TextPanel;
|
||||||
|
using VRage.Game.ModAPI.Ingame;
|
||||||
|
using VRage.Game.ModAPI.Ingame.Utilities;
|
||||||
|
using VRage.Game.ObjectBuilders.Definitions;
|
||||||
|
using VRageMath;
|
||||||
|
|
||||||
|
namespace IngameScript
|
||||||
|
{
|
||||||
|
partial class Program : MyGridProgram
|
||||||
|
{
|
||||||
|
MyIni _configIni = new MyIni();
|
||||||
|
bool _doPolling;
|
||||||
|
string _connectorPrefix;
|
||||||
|
bool _manageGyroscopes;
|
||||||
|
bool _rechargeBatteries;
|
||||||
|
bool _stockpileGasTanks;
|
||||||
|
bool _manageThrusters;
|
||||||
|
bool _enableAllThrustersOnUndock;
|
||||||
|
bool _manageManueveringThrusters;
|
||||||
|
string _maneuveringThrusterPrefix;
|
||||||
|
|
||||||
|
MyIni _storageIni = new MyIni();
|
||||||
|
bool _isDocked;
|
||||||
|
|
||||||
|
public Program()
|
||||||
|
{
|
||||||
|
Echo("Loading storage...");
|
||||||
|
// Parse storage configuration
|
||||||
|
MyIniParseResult storageResult;
|
||||||
|
if (!_storageIni.TryParse(Storage, out storageResult))
|
||||||
|
{
|
||||||
|
throw new Exception(
|
||||||
|
$"Encountered error attempting to parse storage: {storageResult}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_isDocked = _storageIni.Get("AutomaticConnectorActions", "Is_Docked").ToBoolean();
|
||||||
|
|
||||||
|
Echo("Loading configuration...");
|
||||||
|
// Parse CustomData configuration
|
||||||
|
MyIniParseResult configResult;
|
||||||
|
if (!_configIni.TryParse(Me.CustomData, out configResult))
|
||||||
|
{
|
||||||
|
throw new Exception(
|
||||||
|
$"Encountered error attempting to parse CustomData: {configResult}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the CustomData configuration contains the AutomaticConnectorActions section
|
||||||
|
if (!_configIni.ContainsSection("AutomaticConnectorActions"))
|
||||||
|
{
|
||||||
|
Echo(
|
||||||
|
"CustomData does not contain the AutomaticConnectorActions section. Adding..."
|
||||||
|
);
|
||||||
|
// Write configuration to CustomData
|
||||||
|
_configIni.AddSection("AutomaticConnectorActions");
|
||||||
|
_configIni.Set("AutomaticConnectorActions", "Polling", true);
|
||||||
|
_configIni.Set("AutomaticConnectorActions", "Connector_Prefix", "");
|
||||||
|
_configIni.Set("AutomaticConnectorActions", "Manage_Gyroscopes", true);
|
||||||
|
_configIni.Set("AutomaticConnectorActions", "Recharge_Batteries", true);
|
||||||
|
_configIni.Set("AutomaticConnectorActions", "Stockpile_Gas_Tanks", true);
|
||||||
|
_configIni.Set("AutomaticConnectorActions", "Manage_Thrusters", true);
|
||||||
|
_configIni.Set(
|
||||||
|
"AutomaticConnectorActions",
|
||||||
|
"Enable_All_Thrusters_On_Undock",
|
||||||
|
false
|
||||||
|
);
|
||||||
|
_configIni.Set("AutomaticConnectorActions", "Manage_Maneuvering_Thrusters", true);
|
||||||
|
_configIni.Set(
|
||||||
|
"AutomaticConnectorActions",
|
||||||
|
"Maneuvering_Thruster_Prefix",
|
||||||
|
"[MANEUVERING]"
|
||||||
|
);
|
||||||
|
_configIni.SetComment("AutomaticConnectorActions", "Polling", "Enable polling");
|
||||||
|
_configIni.SetComment(
|
||||||
|
"AutomaticConnectorActions",
|
||||||
|
"Connector_Prefix",
|
||||||
|
"Connector prefix"
|
||||||
|
);
|
||||||
|
_configIni.SetComment(
|
||||||
|
"AutomaticConnectorActions",
|
||||||
|
"Manage_Gyroscopes",
|
||||||
|
"Manage gyroscopes"
|
||||||
|
);
|
||||||
|
_configIni.SetComment(
|
||||||
|
"AutomaticConnectorActions",
|
||||||
|
"Recharge_Batteries",
|
||||||
|
"Recharge batteries"
|
||||||
|
);
|
||||||
|
_configIni.SetComment(
|
||||||
|
"AutomaticConnectorActions",
|
||||||
|
"Stockpile_Gas_Tanks",
|
||||||
|
"Stockpile gas tanks"
|
||||||
|
);
|
||||||
|
_configIni.SetComment(
|
||||||
|
"AutomaticConnectorActions",
|
||||||
|
"Manage_Thrusters",
|
||||||
|
"Manage thrusters"
|
||||||
|
);
|
||||||
|
_configIni.SetComment(
|
||||||
|
"AutomaticConnectorActions",
|
||||||
|
"Enable_All_Thrusters_On_Undock",
|
||||||
|
"Enable all thrusters on undock"
|
||||||
|
);
|
||||||
|
_configIni.SetComment(
|
||||||
|
"AutomaticConnectorActions",
|
||||||
|
"Manage_Maneuvering_Thrusters",
|
||||||
|
"Manage maneuvering thrusters"
|
||||||
|
);
|
||||||
|
_configIni.SetComment(
|
||||||
|
"AutomaticConnectorActions",
|
||||||
|
"Maneuvering_Thruster_Prefix",
|
||||||
|
"Prefix for maneuvering thrusters"
|
||||||
|
);
|
||||||
|
Me.CustomData = _configIni.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up the script's configuration
|
||||||
|
_doPolling = _configIni.Get("AutomaticConnectorActions", "Polling").ToBoolean();
|
||||||
|
_connectorPrefix = _configIni
|
||||||
|
.Get("AutomaticConnectorActions", "Connector_Prefix")
|
||||||
|
.ToString();
|
||||||
|
_manageGyroscopes = _configIni
|
||||||
|
.Get("AutomaticConnectorActions", "Manage_Gyroscopes")
|
||||||
|
.ToBoolean();
|
||||||
|
_rechargeBatteries = _configIni
|
||||||
|
.Get("AutomaticConnectorActions", "Recharge_Batteries")
|
||||||
|
.ToBoolean();
|
||||||
|
_stockpileGasTanks = _configIni
|
||||||
|
.Get("AutomaticConnectorActions", "Stockpile_Gas_Tanks")
|
||||||
|
.ToBoolean();
|
||||||
|
_manageThrusters = _configIni
|
||||||
|
.Get("AutomaticConnectorActions", "Manage_Thrusters")
|
||||||
|
.ToBoolean();
|
||||||
|
_enableAllThrustersOnUndock = _configIni
|
||||||
|
.Get("AutomaticConnectorActions", "Enable_All_Thrusters_On_Undock")
|
||||||
|
.ToBoolean();
|
||||||
|
_manageManueveringThrusters = _configIni
|
||||||
|
.Get("AutomaticConnectorActions", "Manage_Maneuvering_Thrusters")
|
||||||
|
.ToBoolean();
|
||||||
|
_maneuveringThrusterPrefix = _configIni
|
||||||
|
.Get("AutomaticConnectorActions", "Maneuvering_Thruster_Prefix")
|
||||||
|
.ToString();
|
||||||
|
Echo("Configuration loaded!");
|
||||||
|
|
||||||
|
if (_doPolling == true)
|
||||||
|
{
|
||||||
|
Echo("Polling enabled. Script will run every 10 ticks.");
|
||||||
|
Runtime.UpdateFrequency = UpdateFrequency.Update10;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Echo("Polling disabled. Script will only run manually.");
|
||||||
|
Runtime.UpdateFrequency = UpdateFrequency.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Save(bool isDocked)
|
||||||
|
{
|
||||||
|
_isDocked = isDocked;
|
||||||
|
_storageIni.Clear();
|
||||||
|
_storageIni.Set("AutomaticConnectorActions", "Is_Docked", isDocked);
|
||||||
|
Storage = _storageIni.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Dock()
|
||||||
|
{
|
||||||
|
if (_manageThrusters == true)
|
||||||
|
{
|
||||||
|
Echo("Turning off grid thrusters...");
|
||||||
|
List<IMyThrust> thrusters = new List<IMyThrust>();
|
||||||
|
|
||||||
|
// Get all thrusters on the grid
|
||||||
|
GridTerminalSystem.GetBlocksOfType(
|
||||||
|
thrusters,
|
||||||
|
thruster => thruster.IsSameConstructAs(Me)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Disable all thrusters on the grid
|
||||||
|
foreach (IMyThrust thruster in thrusters)
|
||||||
|
{
|
||||||
|
thruster.Enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Echo("Turned off grid thrusters.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_manageGyroscopes == true)
|
||||||
|
{
|
||||||
|
Echo("Turning off grid gyroscopes...");
|
||||||
|
List<IMyGyro> gyroscopes = new List<IMyGyro>();
|
||||||
|
|
||||||
|
// Get all gyroscopes on the grid
|
||||||
|
GridTerminalSystem.GetBlocksOfType(
|
||||||
|
gyroscopes,
|
||||||
|
gyroscope => gyroscope.IsSameConstructAs(Me)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Disable all gyroscopes on the grid
|
||||||
|
foreach (IMyGyro gyro in gyroscopes)
|
||||||
|
{
|
||||||
|
gyro.Enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Echo("Turned off grid gyroscopes.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_stockpileGasTanks == true)
|
||||||
|
{
|
||||||
|
Echo("Setting grid gas tanks to stockpile...");
|
||||||
|
List<IMyGasTank> gasTanks = new List<IMyGasTank>();
|
||||||
|
|
||||||
|
// Get all gas tanks on the grid
|
||||||
|
GridTerminalSystem.GetBlocksOfType(
|
||||||
|
gasTanks,
|
||||||
|
gasTank => gasTank.IsSameConstructAs(Me)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Stockpile all gas tanks on the grid
|
||||||
|
foreach (IMyGasTank gasTank in gasTanks)
|
||||||
|
{
|
||||||
|
gasTank.Stockpile = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Echo("Set grid gas tanks to stockpile.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_rechargeBatteries == true)
|
||||||
|
{
|
||||||
|
Echo("Setting grid batteries to recharge...");
|
||||||
|
List<IMyBatteryBlock> batteries = new List<IMyBatteryBlock>();
|
||||||
|
|
||||||
|
// Get all batteries on the grid
|
||||||
|
GridTerminalSystem.GetBlocksOfType(
|
||||||
|
batteries,
|
||||||
|
battery => battery.IsSameConstructAs(Me)
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach (IMyBatteryBlock battery in batteries)
|
||||||
|
{
|
||||||
|
battery.ChargeMode = ChargeMode.Recharge;
|
||||||
|
}
|
||||||
|
Echo("Set grid batteries to recharge.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Save(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Undock()
|
||||||
|
{
|
||||||
|
if (_rechargeBatteries == true)
|
||||||
|
{
|
||||||
|
Echo("Setting grid batteries to auto...");
|
||||||
|
List<IMyBatteryBlock> batteries = new List<IMyBatteryBlock>();
|
||||||
|
|
||||||
|
// Get all batteries on the grid
|
||||||
|
GridTerminalSystem.GetBlocksOfType(
|
||||||
|
batteries,
|
||||||
|
battery => battery.IsSameConstructAs(Me)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Set all batteries on the grid to auto
|
||||||
|
foreach (IMyBatteryBlock battery in batteries)
|
||||||
|
{
|
||||||
|
battery.ChargeMode = ChargeMode.Auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
Echo("Set grid batteries to auto.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_stockpileGasTanks == true)
|
||||||
|
{
|
||||||
|
Echo("Setting grid gas tanks to not stockpile...");
|
||||||
|
List<IMyGasTank> gasTanks = new List<IMyGasTank>();
|
||||||
|
|
||||||
|
// Get all gas tanks on the grid
|
||||||
|
GridTerminalSystem.GetBlocksOfType(
|
||||||
|
gasTanks,
|
||||||
|
gasTank => gasTank.IsSameConstructAs(Me)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Disable stockpiling on all gas tanks on the grid
|
||||||
|
foreach (IMyGasTank gasTank in gasTanks)
|
||||||
|
{
|
||||||
|
gasTank.Stockpile = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Echo("Set grid gas tanks to not stockpile.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_manageGyroscopes == true)
|
||||||
|
{
|
||||||
|
Echo("Turning on grid gyroscopes...");
|
||||||
|
List<IMyGyro> gyroscopes = new List<IMyGyro>();
|
||||||
|
|
||||||
|
// Get all gyroscopes on the grid
|
||||||
|
GridTerminalSystem.GetBlocksOfType(
|
||||||
|
gyroscopes,
|
||||||
|
gyroscope => gyroscope.IsSameConstructAs(Me)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Enable all gyroscopes on the grid
|
||||||
|
foreach (IMyGyro gyro in gyroscopes)
|
||||||
|
{
|
||||||
|
gyro.Enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Echo("Turned on grid gyroscopes.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_manageManueveringThrusters == true)
|
||||||
|
{
|
||||||
|
Echo("Turning on grid maneuvering thrusters...");
|
||||||
|
List<IMyThrust> maneuveringThrusters = new List<IMyThrust>();
|
||||||
|
|
||||||
|
// Get all thrusters on the grid that are considered maneuvering thrusters
|
||||||
|
GridTerminalSystem.GetBlocksOfType(
|
||||||
|
maneuveringThrusters,
|
||||||
|
maneuveringThruster =>
|
||||||
|
maneuveringThruster.IsSameConstructAs(Me)
|
||||||
|
&& maneuveringThruster.CustomName.Contains(_maneuveringThrusterPrefix)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Enable all maneuvering thrusters on the grid
|
||||||
|
foreach (IMyThrust maneuveringThruster in maneuveringThrusters)
|
||||||
|
{
|
||||||
|
maneuveringThruster.Enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Echo("Turned on grid maneuvering thrusters.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_enableAllThrustersOnUndock == true)
|
||||||
|
{
|
||||||
|
Echo("Turning on grid thrusters...");
|
||||||
|
List<IMyThrust> thrusters = new List<IMyThrust>();
|
||||||
|
|
||||||
|
// Get all thrusters on the grid
|
||||||
|
GridTerminalSystem.GetBlocksOfType(
|
||||||
|
thrusters,
|
||||||
|
thruster => thruster.IsSameConstructAs(Me)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Enable all thrusters on the grid
|
||||||
|
foreach (IMyThrust thruster in thrusters)
|
||||||
|
{
|
||||||
|
thruster.Enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Echo("Turned on grid thrusters.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Save(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Main(string argument, UpdateType updateSource)
|
||||||
|
{
|
||||||
|
if (argument == "dock")
|
||||||
|
{
|
||||||
|
Echo("Script ran manually. Docking...");
|
||||||
|
Dock();
|
||||||
|
Echo("Docking complete!");
|
||||||
|
}
|
||||||
|
else if (argument == "undock")
|
||||||
|
{
|
||||||
|
Echo("Script ran manually. Undocking...");
|
||||||
|
Undock();
|
||||||
|
Echo("Undocking complete!");
|
||||||
|
}
|
||||||
|
else if (string.IsNullOrEmpty(argument))
|
||||||
|
{
|
||||||
|
Echo("Polling...");
|
||||||
|
List<IMyShipConnector> connectors = new List<IMyShipConnector>();
|
||||||
|
|
||||||
|
// Get all connectors on the grid
|
||||||
|
GridTerminalSystem.GetBlocksOfType(
|
||||||
|
connectors,
|
||||||
|
connector =>
|
||||||
|
connector.IsSameConstructAs(Me)
|
||||||
|
&& connector.CustomName.Contains(_connectorPrefix)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (_isDocked == true)
|
||||||
|
{
|
||||||
|
foreach (IMyShipConnector connector in connectors)
|
||||||
|
{
|
||||||
|
if (connector.IsConnected == _isDocked)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Undock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
README.md
Normal file
24
README.md
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# Automatic Connector Actions
|
||||||
|
|
||||||
|
This script will do the following things automatically whenever the host grid connects via a connector to another grid:
|
||||||
|
|
||||||
|
- Disable all gyroscopes on the host grid
|
||||||
|
- Disable all thrusters on the host grid
|
||||||
|
- Set all gas tanks (Oxygen and Hydrogen) on the host grid to Stockpile
|
||||||
|
- Set the recharge mode of all batteries on the host grid to Recharge
|
||||||
|
|
||||||
|
Additionally, whenever the host grid disconnects from a connector, the script will:
|
||||||
|
|
||||||
|
- Enable all gyroscopes on the host grid
|
||||||
|
- Enable all thrusters on the host grid that are prefixed with `[MANEUVERING]`
|
||||||
|
- Set all gas tanks (Oxygen and Hydrogen) on the host grid to not Stockpile
|
||||||
|
- Set the recharge mode of all batteries on the host grid to Auto
|
||||||
|
|
||||||
|
This allows for ships to dock with piston connectors without having to convert the other grid to a station. You can also do this with normal timer blocks and event controllers, but they are not very reliable in my personal experience.
|
||||||
|
|
||||||
|
You can optionally invoke the script manually, through something like an event controller. The arguments are as follows:
|
||||||
|
|
||||||
|
- `dock` - Triggers the docking process
|
||||||
|
- `undock` - Triggers the undocking process
|
||||||
|
|
||||||
|
If you want to use the script manually, you should disable `Polling` in the Custom Data field of the programmable block running the script.
|
BIN
thumb.png
Normal file
BIN
thumb.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 389 KiB |
Loading…
Reference in a new issue