clean up a bunch of stuff
This commit is contained in:
parent
b25f88cee0
commit
0f7875d7cd
1 changed files with 48 additions and 54 deletions
102
Program.cs
102
Program.cs
|
@ -39,6 +39,14 @@ namespace IngameScript
|
|||
MyIni _storageIni = new MyIni();
|
||||
bool _isDocked;
|
||||
|
||||
List<IMyShipConnector> _connectors = new List<IMyShipConnector>();
|
||||
List<IMyShipWelder> _naniteControlFacilities = new List<IMyShipWelder>();
|
||||
List<IMyUpgradeModule> _naniteBeacons = new List<IMyUpgradeModule>();
|
||||
List<IMyGyro> _gyroscopes = new List<IMyGyro>();
|
||||
List<IMyThrust> _thrusters = new List<IMyThrust>();
|
||||
List<IMyGasTank> _gasTanks = new List<IMyGasTank>();
|
||||
List<IMyBatteryBlock> _batteries = new List<IMyBatteryBlock>();
|
||||
|
||||
public Program()
|
||||
{
|
||||
Echo("Loading storage...");
|
||||
|
@ -219,37 +227,38 @@ namespace IngameScript
|
|||
_storageIni.Clear();
|
||||
_storageIni.Set("AutomaticConnectorActions", "Is_Docked", _isDocked);
|
||||
Storage = _storageIni.ToString();
|
||||
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
|
||||
// Nanite Control Facilities are considered IMyShipWelder
|
||||
GridTerminalSystem.GetBlocksOfType(
|
||||
naniteControlFacilities,
|
||||
_naniteControlFacilities,
|
||||
naniteControlFacility =>
|
||||
naniteControlFacility.CustomName.Contains(_naniteControlFacilityString)
|
||||
);
|
||||
return naniteControlFacilities.Count > 0;
|
||||
return _naniteControlFacilities.Count > 0;
|
||||
}
|
||||
|
||||
private void Dock()
|
||||
{
|
||||
if (_isDocked == true)
|
||||
{
|
||||
Echo("Already docked.");
|
||||
return;
|
||||
}
|
||||
if (_manageThrusters == true)
|
||||
{
|
||||
Echo("Turning off grid thrusters...");
|
||||
List<IMyThrust> thrusters = new List<IMyThrust>();
|
||||
|
||||
// Get all thrusters on the grid
|
||||
GridTerminalSystem.GetBlocksOfType(
|
||||
thrusters,
|
||||
_thrusters,
|
||||
thruster => thruster.IsSameConstructAs(Me)
|
||||
);
|
||||
|
||||
// Disable all thrusters on the grid
|
||||
foreach (IMyThrust thruster in thrusters)
|
||||
foreach (IMyThrust thruster in _thrusters)
|
||||
{
|
||||
thruster.Enabled = false;
|
||||
}
|
||||
|
@ -260,16 +269,14 @@ namespace IngameScript
|
|||
if (_manageGyroscopes == true)
|
||||
{
|
||||
Echo("Turning off grid gyroscopes...");
|
||||
List<IMyGyro> gyroscopes = new List<IMyGyro>();
|
||||
|
||||
// Get all gyroscopes on the grid
|
||||
GridTerminalSystem.GetBlocksOfType(
|
||||
gyroscopes,
|
||||
_gyroscopes,
|
||||
gyroscope => gyroscope.IsSameConstructAs(Me)
|
||||
);
|
||||
|
||||
// Disable all gyroscopes on the grid
|
||||
foreach (IMyGyro gyro in gyroscopes)
|
||||
foreach (IMyGyro gyro in _gyroscopes)
|
||||
{
|
||||
gyro.Enabled = false;
|
||||
}
|
||||
|
@ -280,16 +287,14 @@ namespace IngameScript
|
|||
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,
|
||||
_gasTanks,
|
||||
gasTank => gasTank.IsSameConstructAs(Me)
|
||||
);
|
||||
|
||||
// Stockpile all gas tanks on the grid
|
||||
foreach (IMyGasTank gasTank in gasTanks)
|
||||
foreach (IMyGasTank gasTank in _gasTanks)
|
||||
{
|
||||
gasTank.Stockpile = true;
|
||||
}
|
||||
|
@ -300,15 +305,14 @@ namespace IngameScript
|
|||
if (_rechargeBatteries == true)
|
||||
{
|
||||
Echo("Setting grid batteries to recharge...");
|
||||
List<IMyBatteryBlock> batteries = new List<IMyBatteryBlock>();
|
||||
|
||||
;
|
||||
// Get all batteries on the grid
|
||||
GridTerminalSystem.GetBlocksOfType(
|
||||
batteries,
|
||||
_batteries,
|
||||
battery => battery.IsSameConstructAs(Me)
|
||||
);
|
||||
|
||||
foreach (IMyBatteryBlock battery in batteries)
|
||||
foreach (IMyBatteryBlock battery in _batteries)
|
||||
{
|
||||
battery.ChargeMode = ChargeMode.Recharge;
|
||||
}
|
||||
|
@ -318,18 +322,16 @@ namespace IngameScript
|
|||
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,
|
||||
_naniteBeacons,
|
||||
naniteBeacon =>
|
||||
naniteBeacon.IsSameConstructAs(Me)
|
||||
&& naniteBeacon.CustomName.Contains(_naniteBeaconString)
|
||||
);
|
||||
|
||||
// Disable all nanite beacons on the grid
|
||||
foreach (IMyFunctionalBlock naniteBeacon in naniteBeacons)
|
||||
foreach (IMyFunctionalBlock naniteBeacon in _naniteBeacons)
|
||||
{
|
||||
naniteBeacon.Enabled = false;
|
||||
}
|
||||
|
@ -343,19 +345,22 @@ namespace IngameScript
|
|||
|
||||
private void Undock()
|
||||
{
|
||||
if (_isDocked == false)
|
||||
{
|
||||
Echo("Already undocked.");
|
||||
return;
|
||||
}
|
||||
if (_rechargeBatteries == true)
|
||||
{
|
||||
Echo("Setting grid batteries to auto...");
|
||||
List<IMyBatteryBlock> batteries = new List<IMyBatteryBlock>();
|
||||
|
||||
// Get all batteries on the grid
|
||||
GridTerminalSystem.GetBlocksOfType(
|
||||
batteries,
|
||||
_batteries,
|
||||
battery => battery.IsSameConstructAs(Me)
|
||||
);
|
||||
|
||||
// Set all batteries on the grid to auto
|
||||
foreach (IMyBatteryBlock battery in batteries)
|
||||
foreach (IMyBatteryBlock battery in _batteries)
|
||||
{
|
||||
battery.ChargeMode = ChargeMode.Auto;
|
||||
}
|
||||
|
@ -366,16 +371,14 @@ namespace IngameScript
|
|||
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,
|
||||
_gasTanks,
|
||||
gasTank => gasTank.IsSameConstructAs(Me)
|
||||
);
|
||||
|
||||
// Disable stockpiling on all gas tanks on the grid
|
||||
foreach (IMyGasTank gasTank in gasTanks)
|
||||
foreach (IMyGasTank gasTank in _gasTanks)
|
||||
{
|
||||
gasTank.Stockpile = false;
|
||||
}
|
||||
|
@ -386,16 +389,14 @@ namespace IngameScript
|
|||
if (_manageGyroscopes == true)
|
||||
{
|
||||
Echo("Turning on grid gyroscopes...");
|
||||
List<IMyGyro> gyroscopes = new List<IMyGyro>();
|
||||
|
||||
// Get all gyroscopes on the grid
|
||||
GridTerminalSystem.GetBlocksOfType(
|
||||
gyroscopes,
|
||||
_gyroscopes,
|
||||
gyroscope => gyroscope.IsSameConstructAs(Me)
|
||||
);
|
||||
|
||||
// Enable all gyroscopes on the grid
|
||||
foreach (IMyGyro gyro in gyroscopes)
|
||||
foreach (IMyGyro gyro in _gyroscopes)
|
||||
{
|
||||
gyro.Enabled = true;
|
||||
}
|
||||
|
@ -406,18 +407,16 @@ namespace IngameScript
|
|||
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,
|
||||
_thrusters,
|
||||
maneuveringThruster =>
|
||||
maneuveringThruster.IsSameConstructAs(Me)
|
||||
&& maneuveringThruster.CustomName.Contains(_maneuveringThrusterString)
|
||||
);
|
||||
|
||||
// Enable all maneuvering thrusters on the grid
|
||||
foreach (IMyThrust maneuveringThruster in maneuveringThrusters)
|
||||
foreach (IMyThrust maneuveringThruster in _thrusters)
|
||||
{
|
||||
maneuveringThruster.Enabled = true;
|
||||
}
|
||||
|
@ -428,16 +427,14 @@ namespace IngameScript
|
|||
if (_enableAllThrustersOnUndock == true)
|
||||
{
|
||||
Echo("Turning on grid thrusters...");
|
||||
List<IMyThrust> thrusters = new List<IMyThrust>();
|
||||
|
||||
// Get all thrusters on the grid
|
||||
GridTerminalSystem.GetBlocksOfType(
|
||||
thrusters,
|
||||
_thrusters,
|
||||
thruster => thruster.IsSameConstructAs(Me)
|
||||
);
|
||||
|
||||
// Enable all thrusters on the grid
|
||||
foreach (IMyThrust thruster in thrusters)
|
||||
foreach (IMyThrust thruster in _thrusters)
|
||||
{
|
||||
thruster.Enabled = true;
|
||||
}
|
||||
|
@ -448,16 +445,14 @@ namespace IngameScript
|
|||
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,
|
||||
_naniteBeacons,
|
||||
naniteBeacon => naniteBeacon.CustomName.Contains(_naniteBeaconString)
|
||||
);
|
||||
|
||||
// Enable all nanite beacons on the grid
|
||||
foreach (IMyFunctionalBlock naniteBeacon in naniteBeacons)
|
||||
foreach (IMyFunctionalBlock naniteBeacon in _naniteBeacons)
|
||||
{
|
||||
naniteBeacon.Enabled = true;
|
||||
}
|
||||
|
@ -486,12 +481,11 @@ namespace IngameScript
|
|||
else if (string.IsNullOrEmpty(argument))
|
||||
{
|
||||
Echo("Polling...");
|
||||
List<IMyShipConnector> connectors = new List<IMyShipConnector>();
|
||||
|
||||
;
|
||||
// Get all connectors on the grid that are managed by the script
|
||||
Echo($"Retrieving connectors, filtering by \"{_connectorString}\"...");
|
||||
GridTerminalSystem.GetBlocksOfType(
|
||||
connectors,
|
||||
_connectors,
|
||||
connector =>
|
||||
connector.IsSameConstructAs(Me)
|
||||
&& connector.CustomName.Contains(_connectorString)
|
||||
|
@ -499,7 +493,7 @@ namespace IngameScript
|
|||
|
||||
if (_isDocked == true)
|
||||
{
|
||||
foreach (IMyShipConnector connector in connectors)
|
||||
foreach (IMyShipConnector connector in _connectors)
|
||||
{
|
||||
if (connector.IsConnected == true)
|
||||
{
|
||||
|
@ -518,7 +512,7 @@ namespace IngameScript
|
|||
}
|
||||
else if (_isDocked == false)
|
||||
{
|
||||
foreach (IMyShipConnector connector in connectors)
|
||||
foreach (IMyShipConnector connector in _connectors)
|
||||
{
|
||||
if (connector.IsConnected == true)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue