Last active
April 27, 2018 22:48
-
-
Save aurorapar/3650e154c1c6d51c729746486fe8368a to your computer and use it in GitHub Desktop.
AutoMiner AI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IMyRemoteControl gps = null; | |
IMyRadioAntenna ant = null; | |
IMyShipController controller = null; | |
Vector3D home = new Vector3D(0,0,0); | |
string shipName = "Autominer-Ship"; | |
Vector3D lastCoords = new Vector3D(0,0,0); | |
List<Vector3D> allCoords = new List<Vector3D>(); | |
public Program() | |
{ | |
// The constructor, called only once every session and | |
// always before any other method is called. Use it to | |
// initialize your script. | |
// | |
// The constructor is optional and can be removed if not | |
// needed. | |
// | |
// It's recommended to set RuntimeInfo.UpdateFrequency | |
// here, which will allow your script to run itself without a | |
// timer block. | |
Runtime.UpdateFrequency = UpdateFrequency.Update100; | |
gps = GridTerminalSystem.GetBlockWithName("gps") as IMyRemoteControl; | |
ant = GridTerminalSystem.GetBlockWithName(shipName) as IMyRadioAntenna; | |
controller = GridTerminalSystem.GetBlockWithName("gps") as IMyShipController; | |
allCoords.Add(lastCoords); | |
for(int radius = 0; radius < 4950; radius += 50) | |
{ | |
for(double row = 0; row < Math.PI; row += Math.PI/4) | |
{ | |
for(double theta = 0; theta < 7/4*Math.PI; theta += Math.PI/4) | |
{ | |
int x = (int) (radius * Math.Sin(row) * Math.Cos(theta)); | |
int y = (int) (radius * Math.Sin(row) * Math.Sin(theta)); | |
int z = (int) (radius * Math.Cos(row)); | |
Vector3D newCoords = new Vector3D(x,y,z); | |
if(!lastCoords.Equals(newCoords)) | |
{ | |
lastCoords = newCoords; | |
allCoords.Add(newCoords); | |
} | |
} | |
} | |
} | |
} | |
public void Save() | |
{ | |
// Called when the program needs to save its state. Use | |
// this method to save your state to the Storage field | |
// or some other means. | |
// | |
// This method is optional and can be removed if not | |
// needed. | |
} | |
public void Main() | |
{ | |
// The main entry point of the script, invoked every time | |
// one of the programmable block's Run actions are invoked, | |
// or the script updates itself. The updateSource argument | |
// describes where the update came from. | |
// | |
// The method itself is required, but the arguments above | |
// can be removed if not needed. | |
var masses = controller.CalculateShipMass(); | |
float dryMass = masses.BaseMass; | |
float totalMass = masses.TotalMass; | |
//Check mass/volume | |
if(totalMass > 8000000) | |
{ | |
goHome(); | |
} | |
var containers = new List<IMyTerminalBlock>(); | |
GridTerminalSystem.GetBlocksOfType<IMyCargoContainer>(containers); | |
VRage.MyFixedPoint currentVolume = 0; | |
VRage.MyFixedPoint maxVolume = 0; | |
for (int i = 0; i < containers.Count; i++) | |
{ | |
IMyCargoContainer container = containers[i] as IMyCargoContainer; | |
IMyInventory containerInventory = container.GetInventory(0); | |
currentVolume += containerInventory.CurrentVolume; | |
maxVolume += containerInventory.MaxVolume; | |
} | |
double percentage = ((double)currentVolume / (double)maxVolume) * 100; | |
if(percentage > 85) | |
{ | |
goHome(); | |
} | |
//Check Velocity | |
List<IMyThrust> thrusters = new List<IMyThrust>(); | |
GridTerminalSystem.GetBlocksOfType(thrusters); | |
float thrust = 0; | |
foreach(var thruster in thrusters) | |
{ | |
thrust += thruster.CurrentThrust; | |
} | |
if(thrust == 0) | |
{ | |
goNext(); | |
} | |
List<IMySensorBlock> sensors = null; | |
GridTerminalSystem.GetBlocksOfType(sensors); | |
foreach(var sensor in sensors) | |
{ | |
if(sensor.IsActive) | |
{ | |
gps.SetAutoPilotEnabled(false); | |
break; | |
} | |
} | |
} | |
public void goNext() | |
{ | |
gps.ClearWaypoints(); | |
int points = 0; | |
allCoords.Remove(allCoords.First()); | |
foreach(var coord in allCoords) | |
{ | |
gps.AddWaypoint(coord, String.Format("Point {0}", points++)); | |
} | |
gps.AddWaypoint(home, String.Format("Point {0}", points++)); | |
List<MyWaypointInfo> waypoints = new List<MyWaypointInfo>(); | |
gps.GetWaypointInfo(waypoints); | |
string destination = waypoints.First().Coords.ToString(); | |
gps.SetAutoPilotEnabled(true); | |
return; | |
} | |
public void goHome() | |
{ | |
gps.ClearWaypoints(); | |
gps.AddWaypoint(home, "Home"); | |
gps.SetAutoPilotEnabled(true); | |
return; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IMyRemoteControl gps = null; | |
IMyRadioAntenna ant = null; | |
string shipName = "Autominer-Ship"; | |
public Program() | |
{ | |
// The constructor, called only once every session and | |
// always before any other method is called. Use it to | |
// initialize your script. | |
// | |
// The constructor is optional and can be removed if not | |
// needed. | |
// | |
// It's recommended to set RuntimeInfo.UpdateFrequency | |
// here, which will allow your script to run itself without a | |
// timer block. | |
Runtime.UpdateFrequency = UpdateFrequency.Update100; | |
} | |
public void Save() | |
{ | |
// Called when the program needs to save its state. Use | |
// this method to save your state to the Storage field | |
// or some other means. | |
// | |
// This method is optional and can be removed if not | |
// needed. | |
} | |
public void Main(string argument) | |
{ | |
// The main entry point of the script, invoked every time | |
// one of the programmable block's Run actions are invoked, | |
// or the script updates itself. The updateSource argument | |
// describes where the update came from. | |
// | |
// The method itself is required, but the arguments above | |
// can be removed if not needed. | |
gps = GridTerminalSystem.GetBlockWithName("gps") as IMyRemoteControl; | |
ant = GridTerminalSystem.GetBlockWithName(shipName) as IMyRadioAntenna; | |
string destination = gps.CurrentWaypoint.Coords.ToString(); | |
List<IMyShipDrill> drills = new List<IMyShipDrill>(); | |
GridTerminalSystem.GetBlocksOfType(drills); | |
bool drilling = false; | |
foreach(var drill in drills) | |
{ | |
if(drill.Enabled) | |
{ | |
drilling = true; | |
break; | |
} | |
} | |
if(drilling) | |
{ | |
message(String.Format("Mining on way to {0}\nCurrently at:\n{1}", destination, gps.GetPosition())); | |
} | |
else | |
{ | |
message(String.Format("Headed to {0}\nCurrently at:\n{1}", destination, gps.GetPosition())); | |
} | |
} | |
public void message(string message) | |
{ | |
ant.TransmitMessage(message, MyTransmitTarget.Owned); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment