Hey Qon. I liked your script so much that I improved it a bit.
You can now save and restart at any time now. No variable used to store how far down the computer should dig before placing the robots and the compressor. Instead it looks for the floor that the robots dug to before.
Configurable robot types: Just change Robot <- 153; to the value for the robot you want to use.
Optional: build a simple spiral staircase around the center while it digs down.
Optional: Limit how deep you want it to dig. MaxLevel <- -608;
//Simple mining robot restarter
state <- 0;
Time <- 0;
MaxLevel <- -608; // Don't place robots deeper then this. There is nothing interesting below it.
ReturnLevel <- 0; // Return to this level (0=The level the robot was started at.)
Robot <- 153; // The VoxelType of our robots
Compressor <- 49; // The VoxelType of the Atomic Compressor
BuildStairs <- 1; // 0=Do not build stairs, 1=Build Stairs
function Voxel_Step()
{
local i,j,v,q;
local b;
if (Time == 0) {
Time = GetGameTime();
if (ReturnLevel == 0)
ReturnLevel = GetY();
}
if ( (GetGameTime() - Time) > 10 )
{
Time = GetGameTime();
} else {
return;
}
switch (state)
{
case 0: // Start up state. Try to figure out what to do
if (Look(5)==Compressor) { // Are we on top of a atomic compressor, Start at the begining.
state = 10;
break;
}
if (GetQuantity(Robot)==4) { // We have all out robots.
if (GetQuantity(Compressor)==1) { // and our compressor. Find a place to place them
state = 30;
break;
}
}
Move(5); // Move down if we can
log_err("Waiting for atomic compressor");
Time = Time + 5000;
break;
case 10: // Main state. Waiting for all the robots to finish there work.
if (Look(5)==Compressor) {
while(PullVoxelFrom(5)) {} // Pull all voxels from the atomic compressor
if (GetQuantity(Robot)==4) { // If all mining robots are picked up then we are move to the next step
state = 11;
}
} else {
// Something is wrong. Inform and restart
log_err( "No Atomic compressor found. Restarting." );
Time = Time + 5000;
state = 0;
}
break;
case 11:
if(!PullVoxelFrom(5)) { // Make sure the atomic compressor is empty
state = 12;
} else {
state = 10;
}
break;
case 12:
PickVoxel(5);
if (GetQuantity(Compressor)==1) { // Make sure the atomic compressor is on board
state = 30;
} else {
// Computer storage is probably full.
log_err("Storage full?");
Time = Time + 5000;
state == 10;
}
break;
case 30: // The compressor and all mining bots are in storage so its safe to dig down.
if (GetY() < MaxLevel) {
state = 100;
break;
}
v = Look(5);
b = GetVoxelProp(v,0)
if (!b) { // If voxel below is solid, pick it.
PickVoxel(5);
}
Move(5);
state = 31;
break;
case 31:
// Check if we have hit bottom
i = 0;
for (j=0; j<4; j++) { // Count the number of solid voxels on our sides
v = Look(j);
b = GetVoxelProp(v,0)
if (!b) {
i++;
}
}
if (i>2) { // We have hit bottom
state = 35;
} else {
state = 30;
if (BuildStairs == 1)
state = 32;
}
break;
case 32: // Build stairs
v = GetFirstNormalBlock();
state = 30; // Next state is 30 unless we say otherwise
if (v>0) {
i = ((GetY() % 8) + 8) % 8;
j = i / 2;
if (i%2 == 0) {
PlaceVoxel(j,v);
} else {
// Need to move to place the voxel. So deferre the placement to next step
if (Move(j)) {
state = 33;
} else {
if (Move((j+1)%4)) {
state = 34;
}
}
}
}
break;
case 33:
v = GetFirstNormalBlock();
i = ((GetY() % 8) + 8) % 8;
j = i / 2;
if (v>0)
PlaceVoxel((j+1)%4, v);
Move((j+2)%4); // Move Back
state = 30;
break;
case 34:
v = GetFirstNormalBlock();
i = ((GetY() % 8) + 8) % 8;
j = i / 2;
if (v>0)
PlaceVoxel(j, v);
Move((j+3)%4); // Move Back
state = 30;
break;
case 35:
Move(4); // Move up one so we are above the bottom
state = 40;
break;
case 40: // We are now at the bottom of our mining shaft, place the mining robots
q = GetQuantity(Robot);
if (q > 0) {
q--;
PickVoxel(q);
PlaceVoxel(q, Robot);
} else { // Mining bots placed
Move(4);
state = 50;
}
break;
case 50: // Place the atomic compressor between the mining bots
PlaceVoxel(5, Compressor);
state = 60;
break;
case 60:
if (Look(5)==Compressor) {
state = 10;
}
break;
case 100: // Done. Walk back up
if (GetY() >= ReturnLevel) {
state = 101;
break;
}
v = Look(4);
b = GetVoxelProp(v,0)
if (!b) { // If voxel above is solid, pick it.
PickVoxel(4);
}
Move(4);
break;
case 101: // Inform that we are done.
log_err("ALL WORK DONE!");
Time = Time + 15000; // only spam once every 15 seconds
break;
}
}
function GetFirstNormalBlock()
{
local a;
for (a=1; a<=10; a++)
{
if(GetQuantity(a)>0)
{
return a;
}
}
return 0;
}
function log_info(msg)
{
Display( "Robot at " + GetX() + "," + GetY() + "," + GetZ() + " Info: " + msg, 1000, 4, 0);
}
function log_err(msg)
{
Display( "ROBOT AT " + GetX() + "," + GetY() + "," + GetZ() + " Err: " + msg, 2000, 4, 2000);
Time = Time + 2000;
}
I have tested this script pretty extensively, so it should be fairly stable.
I'm currently working on a version where one computer will handle 4 (or more) compressors with 4 diggers each.