Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Toupie

Pages: 1 ... 3 4 [5]
61
Programming with Blackvoxel / Re: Simple mining bot restarter
« on: October 11, 2013, 08:15:27 pm »
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;

Code: [Select]
//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.

62
Troubleshooting & Bug Reports / Re: The v1.21 bug report thread
« on: October 11, 2013, 07:53:00 pm »
Running Blackvoxel in windowed mode on Windows 7. So these bugs may only exist there.

  • The game hogs the mouse even when it does not have focus. If I use alt-tab to switch to another application Blackvoxel still hides the mouse cursor and rotates the view when I try to move the mouse to the focused window.
  • Even when the mouse is hidden in the game, you can still drag and drop the icons on the right toolbar. Happens often that I pick up those icons by mistake since it is impossible to see where the mouse cursor are when it is hidden. Drag and drop should only be enabled when the mouse cursor is visible. (This also happens when Blackvoxel is run fullscreen.)
  • If two sequencers are placed so close together that there is at least one voxel that they both can use as input, one of them will operate extremely slow. Like only pick up voxels once ever 15-20 seconds.
  • Manufacturing recipe for Silicon Wafer is messed up. The manual say 10 x BlackRock Blue Sky. But to actually make it you also need to add 1 x BlackRock Blue, but you will get the BlackRock Blue also as the output. Also all manufacturing instructions in the manual (on the web) that uses the Silicon Wafer links to the wrong place if you click it.
  • Not sure if it is a bug or not. According to the manual Voxel bitmaps are supposed to use the lower right part as the inventory icon, but they use the same area for the inventory icon as for the top of the voxel.
  • Robot programing. GetGameTime() returns a negative number. Which causes all the examples that use GetGameTime() to not work. It's still possible to make it work, but not like in the examples. Windows specific bug??


Pages: 1 ... 3 4 [5]