added NCF integration
This commit is contained in:
parent
3609e1526e
commit
8e79456c8f
3 changed files with 142 additions and 29 deletions
|
@ -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:
|
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 gyroscopes on the host grid.
|
||||||
- Disable all thrusters 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 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
|
- 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:
|
Additionally, whenever the host grid disconnects from a connector, the script will:
|
||||||
|
|
||||||
- Enable all gyroscopes on the host grid
|
- Enable all gyroscopes on the host grid.
|
||||||
- Enable all thrusters on the host grid that are prefixed with `[MANEUVERING]`
|
- 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 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
|
- 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.
|
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 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!
|
DO NOT MODIFY ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING!
|
||||||
=====================================================================================
|
=====================================================================================
|
||||||
|
|
||||||
|
|
123
Program.cs
123
Program.cs
|
@ -24,14 +24,17 @@ namespace IngameScript
|
||||||
{
|
{
|
||||||
MyIni _configIni = new MyIni();
|
MyIni _configIni = new MyIni();
|
||||||
bool _doPolling;
|
bool _doPolling;
|
||||||
string _connectorPrefix;
|
string _connectorString;
|
||||||
bool _manageGyroscopes;
|
bool _manageGyroscopes;
|
||||||
bool _rechargeBatteries;
|
bool _rechargeBatteries;
|
||||||
bool _stockpileGasTanks;
|
bool _stockpileGasTanks;
|
||||||
bool _manageThrusters;
|
bool _manageThrusters;
|
||||||
bool _enableAllThrustersOnUndock;
|
bool _enableAllThrustersOnUndock;
|
||||||
bool _manageManueveringThrusters;
|
bool _manageManueveringThrusters;
|
||||||
string _maneuveringThrusterPrefix;
|
string _maneuveringThrusterString;
|
||||||
|
bool _naniteControlFacilityIntegration;
|
||||||
|
string _naniteBeaconString;
|
||||||
|
string _naniteControlFacilityString;
|
||||||
|
|
||||||
MyIni _storageIni = new MyIni();
|
MyIni _storageIni = new MyIni();
|
||||||
bool _isDocked;
|
bool _isDocked;
|
||||||
|
@ -68,7 +71,7 @@ namespace IngameScript
|
||||||
// Write configuration to CustomData
|
// Write configuration to CustomData
|
||||||
_configIni.AddSection("AutomaticConnectorActions");
|
_configIni.AddSection("AutomaticConnectorActions");
|
||||||
_configIni.Set("AutomaticConnectorActions", "Polling", true);
|
_configIni.Set("AutomaticConnectorActions", "Polling", true);
|
||||||
_configIni.Set("AutomaticConnectorActions", "Connector_Prefix", "");
|
_configIni.Set("AutomaticConnectorActions", "Connector_String", "");
|
||||||
_configIni.Set("AutomaticConnectorActions", "Manage_Gyroscopes", true);
|
_configIni.Set("AutomaticConnectorActions", "Manage_Gyroscopes", true);
|
||||||
_configIni.Set("AutomaticConnectorActions", "Recharge_Batteries", true);
|
_configIni.Set("AutomaticConnectorActions", "Recharge_Batteries", true);
|
||||||
_configIni.Set("AutomaticConnectorActions", "Stockpile_Gas_Tanks", true);
|
_configIni.Set("AutomaticConnectorActions", "Stockpile_Gas_Tanks", true);
|
||||||
|
@ -81,9 +84,24 @@ namespace IngameScript
|
||||||
_configIni.Set("AutomaticConnectorActions", "Manage_Maneuvering_Thrusters", true);
|
_configIni.Set("AutomaticConnectorActions", "Manage_Maneuvering_Thrusters", true);
|
||||||
_configIni.Set(
|
_configIni.Set(
|
||||||
"AutomaticConnectorActions",
|
"AutomaticConnectorActions",
|
||||||
"Maneuvering_Thruster_Prefix",
|
"Maneuvering_Thruster_String",
|
||||||
"[MANEUVERING]"
|
"[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(
|
_configIni.SetComment(
|
||||||
"AutomaticConnectorActions",
|
"AutomaticConnectorActions",
|
||||||
"Polling",
|
"Polling",
|
||||||
|
@ -91,7 +109,7 @@ namespace IngameScript
|
||||||
);
|
);
|
||||||
_configIni.SetComment(
|
_configIni.SetComment(
|
||||||
"AutomaticConnectorActions",
|
"AutomaticConnectorActions",
|
||||||
"Connector_Prefix",
|
"Connector_String",
|
||||||
"If the connector's name contains this string, the script will manage it."
|
"If the connector's name contains this string, the script will manage it."
|
||||||
);
|
);
|
||||||
_configIni.SetComment(
|
_configIni.SetComment(
|
||||||
|
@ -126,16 +144,31 @@ namespace IngameScript
|
||||||
);
|
);
|
||||||
_configIni.SetComment(
|
_configIni.SetComment(
|
||||||
"AutomaticConnectorActions",
|
"AutomaticConnectorActions",
|
||||||
"Maneuvering_Thruster_Prefix",
|
"Maneuvering_Thruster_String",
|
||||||
"If the maneuvering thruster's name contains this string, the script will manage it."
|
"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();
|
Me.CustomData = _configIni.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up the script's configuration
|
// Set up the script's configuration
|
||||||
_doPolling = _configIni.Get("AutomaticConnectorActions", "Polling").ToBoolean();
|
_doPolling = _configIni.Get("AutomaticConnectorActions", "Polling").ToBoolean();
|
||||||
_connectorPrefix = _configIni
|
_connectorString = _configIni
|
||||||
.Get("AutomaticConnectorActions", "Connector_Prefix")
|
.Get("AutomaticConnectorActions", "Connector_String")
|
||||||
.ToString();
|
.ToString();
|
||||||
_manageGyroscopes = _configIni
|
_manageGyroscopes = _configIni
|
||||||
.Get("AutomaticConnectorActions", "Manage_Gyroscopes")
|
.Get("AutomaticConnectorActions", "Manage_Gyroscopes")
|
||||||
|
@ -155,8 +188,17 @@ namespace IngameScript
|
||||||
_manageManueveringThrusters = _configIni
|
_manageManueveringThrusters = _configIni
|
||||||
.Get("AutomaticConnectorActions", "Manage_Maneuvering_Thrusters")
|
.Get("AutomaticConnectorActions", "Manage_Maneuvering_Thrusters")
|
||||||
.ToBoolean();
|
.ToBoolean();
|
||||||
_maneuveringThrusterPrefix = _configIni
|
_maneuveringThrusterString = _configIni
|
||||||
.Get("AutomaticConnectorActions", "Maneuvering_Thruster_Prefix")
|
.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();
|
.ToString();
|
||||||
Echo("Configuration loaded!");
|
Echo("Configuration loaded!");
|
||||||
|
|
||||||
|
@ -180,6 +222,19 @@ namespace IngameScript
|
||||||
Echo($"Docking status set to {_isDocked} and saved to internal storage.");
|
Echo($"Docking status set to {_isDocked} and saved to internal storage.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool DoesGridHaveNaniteControlFacility()
|
||||||
|
{
|
||||||
|
List<IMyFunctionalBlock> naniteControlFacilities = new List<IMyFunctionalBlock>();
|
||||||
|
|
||||||
|
// 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()
|
private void Dock()
|
||||||
{
|
{
|
||||||
if (_manageThrusters == true)
|
if (_manageThrusters == true)
|
||||||
|
@ -260,6 +315,28 @@ namespace IngameScript
|
||||||
Echo("Set grid batteries to recharge.");
|
Echo("Set grid batteries to recharge.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_naniteControlFacilityIntegration && DoesGridHaveNaniteControlFacility())
|
||||||
|
{
|
||||||
|
Echo("Turning off grid Nanite Beacons...");
|
||||||
|
List<IMyFunctionalBlock> naniteBeacons = new List<IMyFunctionalBlock>();
|
||||||
|
|
||||||
|
// 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;
|
_isDocked = true;
|
||||||
Save();
|
Save();
|
||||||
}
|
}
|
||||||
|
@ -336,7 +413,7 @@ namespace IngameScript
|
||||||
maneuveringThrusters,
|
maneuveringThrusters,
|
||||||
maneuveringThruster =>
|
maneuveringThruster =>
|
||||||
maneuveringThruster.IsSameConstructAs(Me)
|
maneuveringThruster.IsSameConstructAs(Me)
|
||||||
&& maneuveringThruster.CustomName.Contains(_maneuveringThrusterPrefix)
|
&& maneuveringThruster.CustomName.Contains(_maneuveringThrusterString)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Enable all maneuvering thrusters on the grid
|
// Enable all maneuvering thrusters on the grid
|
||||||
|
@ -368,6 +445,26 @@ namespace IngameScript
|
||||||
Echo("Turned on grid thrusters.");
|
Echo("Turned on grid thrusters.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_naniteControlFacilityIntegration && !DoesGridHaveNaniteControlFacility())
|
||||||
|
{
|
||||||
|
Echo("Turning on grid Nanite Beacons...");
|
||||||
|
List<IMyFunctionalBlock> naniteBeacons = new List<IMyFunctionalBlock>();
|
||||||
|
|
||||||
|
// 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;
|
_isDocked = false;
|
||||||
Save();
|
Save();
|
||||||
}
|
}
|
||||||
|
@ -392,12 +489,12 @@ namespace IngameScript
|
||||||
List<IMyShipConnector> connectors = new List<IMyShipConnector>();
|
List<IMyShipConnector> connectors = new List<IMyShipConnector>();
|
||||||
|
|
||||||
// Get all connectors on the grid that are managed by the script
|
// 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(
|
GridTerminalSystem.GetBlocksOfType(
|
||||||
connectors,
|
connectors,
|
||||||
connector =>
|
connector =>
|
||||||
connector.IsSameConstructAs(Me)
|
connector.IsSameConstructAs(Me)
|
||||||
&& connector.CustomName.Contains(_connectorPrefix)
|
&& connector.CustomName.Contains(_connectorString)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (_isDocked == true)
|
if (_isDocked == true)
|
||||||
|
|
18
README.md
18
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:
|
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 gyroscopes on the host grid.
|
||||||
- Disable all thrusters 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 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
|
- 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:
|
Additionally, whenever the host grid disconnects from a connector, the script will:
|
||||||
|
|
||||||
- Enable all gyroscopes on the host grid
|
- Enable all gyroscopes on the host grid.
|
||||||
- Enable all thrusters on the host grid that are prefixed with `[MANEUVERING]`
|
- 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 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
|
- 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.
|
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.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue