diff --git a/Instructions.readme b/Instructions.readme index d7e4528..970603f 100644 --- a/Instructions.readme +++ b/Instructions.readme @@ -6,17 +6,19 @@ Unminified source code available at https://www.coastalcommits.com/cswimr/Automa 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 +- 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. +- Check if a Nanite Control Facility is present any grid connected to the host grid. If one is present, disable all Nanite Beacons on the host grid. 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 +- 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. +- Check if a Nanite Control Facility is present on the host grid. If one is not present, enable all Nanite Beacons on the host grid. 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. @@ -34,6 +36,18 @@ Please DO NOT modify anything inside of this script unless you know what you're ===================================================================================== +MIT LICENSE + +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. + +===================================================================================== + DO NOT MODIFY ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING! ===================================================================================== diff --git a/Program.cs b/Program.cs index 5b320db..9179fc8 100644 --- a/Program.cs +++ b/Program.cs @@ -24,14 +24,17 @@ namespace IngameScript { MyIni _configIni = new MyIni(); bool _doPolling; - string _connectorPrefix; + string _connectorString; bool _manageGyroscopes; bool _rechargeBatteries; bool _stockpileGasTanks; bool _manageThrusters; bool _enableAllThrustersOnUndock; bool _manageManueveringThrusters; - string _maneuveringThrusterPrefix; + string _maneuveringThrusterString; + bool _naniteControlFacilityIntegration; + string _naniteBeaconString; + string _naniteControlFacilityString; MyIni _storageIni = new MyIni(); bool _isDocked; @@ -68,7 +71,7 @@ namespace IngameScript // Write configuration to CustomData _configIni.AddSection("AutomaticConnectorActions"); _configIni.Set("AutomaticConnectorActions", "Polling", true); - _configIni.Set("AutomaticConnectorActions", "Connector_Prefix", ""); + _configIni.Set("AutomaticConnectorActions", "Connector_String", ""); _configIni.Set("AutomaticConnectorActions", "Manage_Gyroscopes", true); _configIni.Set("AutomaticConnectorActions", "Recharge_Batteries", true); _configIni.Set("AutomaticConnectorActions", "Stockpile_Gas_Tanks", true); @@ -81,9 +84,24 @@ namespace IngameScript _configIni.Set("AutomaticConnectorActions", "Manage_Maneuvering_Thrusters", true); _configIni.Set( "AutomaticConnectorActions", - "Maneuvering_Thruster_Prefix", + "Maneuvering_Thruster_String", "[MANEUVERING]" ); + _configIni.Set( + "AutomaticConnectorActions", + "Nanite_Control_Facility_Integration", + true + ); + _configIni.Set( + "AutomaticConnectorActions", + "Nanite_Beacon_String", + "Nanite Beacon" + ); + _configIni.Set( + "AutomaticConnectorActions", + "Nanite_Control_Facility_String", + "Nanite Control Facility" + ); _configIni.SetComment( "AutomaticConnectorActions", "Polling", @@ -91,7 +109,7 @@ namespace IngameScript ); _configIni.SetComment( "AutomaticConnectorActions", - "Connector_Prefix", + "Connector_String", "If the connector's name contains this string, the script will manage it." ); _configIni.SetComment( @@ -126,16 +144,31 @@ namespace IngameScript ); _configIni.SetComment( "AutomaticConnectorActions", - "Maneuvering_Thruster_Prefix", + "Maneuvering_Thruster_String", "If the maneuvering thruster's name contains this string, the script will manage it." ); + _configIni.SetComment( + "AutomaticConnectorActions", + "Nanite_Control_Facility_Integration", + "If this is enabled, the script will disable and enable Nanite Beacons from the Nanite Control Facility mod when docking and undocking, respectively. This setting exists to cut down on NCF scanning times." + ); + _configIni.SetComment( + "AutomaticConnectorActions", + "Nanite_Beacon_String", + "If the Nanite Beacon's name contains this string, the script will manage it." + ); + _configIni.SetComment( + "AutomaticConnectorActions", + "Nanite_Control_Facility_String", + "If the Nanite Control Facility's name contains this string, the script will manage it." + ); Me.CustomData = _configIni.ToString(); } // Set up the script's configuration _doPolling = _configIni.Get("AutomaticConnectorActions", "Polling").ToBoolean(); - _connectorPrefix = _configIni - .Get("AutomaticConnectorActions", "Connector_Prefix") + _connectorString = _configIni + .Get("AutomaticConnectorActions", "Connector_String") .ToString(); _manageGyroscopes = _configIni .Get("AutomaticConnectorActions", "Manage_Gyroscopes") @@ -155,8 +188,17 @@ namespace IngameScript _manageManueveringThrusters = _configIni .Get("AutomaticConnectorActions", "Manage_Maneuvering_Thrusters") .ToBoolean(); - _maneuveringThrusterPrefix = _configIni - .Get("AutomaticConnectorActions", "Maneuvering_Thruster_Prefix") + _maneuveringThrusterString = _configIni + .Get("AutomaticConnectorActions", "Maneuvering_Thruster_String") + .ToString(); + _naniteControlFacilityIntegration = _configIni + .Get("AutomaticConnectorActions", "Nanite_Control_Facility_Integration") + .ToBoolean(); + _naniteBeaconString = _configIni + .Get("AutomaticConnectorActions", "Nanite_Beacon_String") + .ToString(); + _naniteControlFacilityString = _configIni + .Get("AutomaticConnectorActions", "Nanite_Control_Facility_String") .ToString(); Echo("Configuration loaded!"); @@ -180,6 +222,19 @@ namespace IngameScript Echo($"Docking status set to {_isDocked} and saved to internal storage."); } + private bool DoesGridHaveNaniteControlFacility() + { + List naniteControlFacilities = new List(); + + // Get all functional blocks on the grid that are Nanite Control Facilities + GridTerminalSystem.GetBlocksOfType( + naniteControlFacilities, + naniteControlFacility => + naniteControlFacility.CustomName.Contains(_naniteControlFacilityString) + ); + return naniteControlFacilities.Count > 0; + } + private void Dock() { if (_manageThrusters == true) @@ -260,6 +315,28 @@ namespace IngameScript Echo("Set grid batteries to recharge."); } + if (_naniteControlFacilityIntegration && DoesGridHaveNaniteControlFacility()) + { + Echo("Turning off grid Nanite Beacons..."); + List naniteBeacons = new List(); + + // Get all nanite beacons on the grid + GridTerminalSystem.GetBlocksOfType( + naniteBeacons, + naniteBeacon => + naniteBeacon.IsSameConstructAs(Me) + && naniteBeacon.CustomName.Contains(_naniteBeaconString) + ); + + // Disable all nanite beacons on the grid + foreach (IMyFunctionalBlock naniteBeacon in naniteBeacons) + { + naniteBeacon.Enabled = false; + } + + Echo("Turned off grid Nanite Beacons."); + } + _isDocked = true; Save(); } @@ -336,7 +413,7 @@ namespace IngameScript maneuveringThrusters, maneuveringThruster => maneuveringThruster.IsSameConstructAs(Me) - && maneuveringThruster.CustomName.Contains(_maneuveringThrusterPrefix) + && maneuveringThruster.CustomName.Contains(_maneuveringThrusterString) ); // Enable all maneuvering thrusters on the grid @@ -368,6 +445,26 @@ namespace IngameScript Echo("Turned on grid thrusters."); } + if (_naniteControlFacilityIntegration && !DoesGridHaveNaniteControlFacility()) + { + Echo("Turning on grid Nanite Beacons..."); + List naniteBeacons = new List(); + + // Get all nanite beacons on the grid + GridTerminalSystem.GetBlocksOfType( + naniteBeacons, + naniteBeacon => naniteBeacon.CustomName.Contains(_naniteBeaconString) + ); + + // Enable all nanite beacons on the grid + foreach (IMyFunctionalBlock naniteBeacon in naniteBeacons) + { + naniteBeacon.Enabled = true; + } + + Echo("Turned on grid Nanite Beacons."); + } + _isDocked = false; Save(); } @@ -392,12 +489,12 @@ namespace IngameScript List connectors = new List(); // Get all connectors on the grid that are managed by the script - Echo($"Retrieving connectors, filtering by \"{_connectorPrefix}\"..."); + Echo($"Retrieving connectors, filtering by \"{_connectorString}\"..."); GridTerminalSystem.GetBlocksOfType( connectors, connector => connector.IsSameConstructAs(Me) - && connector.CustomName.Contains(_connectorPrefix) + && connector.CustomName.Contains(_connectorString) ); if (_isDocked == true) diff --git a/README.md b/README.md index ba52049..b90eac4 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,19 @@ 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 +- 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. +- Check if a Nanite Control Facility is present any grid connected to the host grid. If one is present, disable all Nanite Beacons on the host grid. 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 +- 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. +- Check if a Nanite Control Facility is present on the host grid. If one is not present, enable all Nanite Beacons on the host grid. 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.