SHOW:
|
|
- or go back to the newest paste.
| 1 | --//БЕЗ Апгрейда инвентрь. | |
| 2 | --//БЕЗ зарядки из ресурсов в инвентре | |
| 3 | --//Зарядка от зарядной станции на месте старта. | |
| 4 | --// В 1 слот нужно положить сундук. | |
| 5 | ||
| 6 | - | --//объявляем прочие переменные |
| 6 | + | --//объявляем прочие переменные |
| 7 | local alternate = 0 | |
| 8 | local done = false | |
| 9 | local robot = require("robot");
| |
| 10 | --//иницианализируем генератор | |
| 11 | local component = require("component")
| |
| 12 | - | local gen = component.generator |
| 12 | + | --local gen = component.generator |
| 13 | - | |
| 13 | + | |
| 14 | local COMP = require("computer")
| |
| 15 | - | |
| 15 | + | |
| 16 | local depth = 0 | |
| 17 | local unloaded = 0 | |
| 18 | local collected = 0 | |
| 19 | - | |
| 19 | + | |
| 20 | local xPos,zPos = 0,0 | |
| 21 | local xDir,zDir = 0,1 | |
| 22 | - | |
| 22 | + | |
| 23 | --//вводим и проверяем данные: размер и глубину | |
| 24 | local size | |
| 25 | - | |
| 25 | + | |
| 26 | - | function Collect() |
| 26 | + | function Collect() |
| 27 | - | local bFull = true |
| 27 | + | local bFull = true |
| 28 | - | local ISize = robot.inventorySize() |
| 28 | + | local ISize = robot.inventorySize() |
| 29 | - | --local nTotalItems = 0 |
| 29 | + | --local nTotalItems = 0 |
| 30 | - | for n = 3, ISize do |
| 30 | + | for n = 3, ISize do |
| 31 | - | if robot.count(n) == 0 then |
| 31 | + | if robot.count(n) == 0 then |
| 32 | - | bFull = false |
| 32 | + | bFull = false |
| 33 | - | end |
| 33 | + | end |
| 34 | - | |
| 34 | + | |
| 35 | - | end |
| 35 | + | end |
| 36 | - | |
| 36 | + | |
| 37 | - | if bFull then |
| 37 | + | if bFull then |
| 38 | - | print( "No empty slots left." ) |
| 38 | + | print( "No empty slots left." ) |
| 39 | - | --return false |
| 39 | + | --return false |
| 40 | - | end |
| 40 | + | end |
| 41 | - | --return true |
| 41 | + | --return true |
| 42 | - | return not bFull |
| 42 | + | return not bFull |
| 43 | end | |
| 44 | - | |
| 44 | + | |
| 45 | function Unload() | |
| 46 | - | local ISize = robot.inventorySize() |
| 46 | + | local ISize = robot.inventorySize() |
| 47 | - | |
| 47 | + | |
| 48 | - | print( "Unloading items..." ) |
| 48 | + | print( "Unloading items..." ) |
| 49 | - | for n = 1 , ISize do |
| 49 | + | for n = 1 , ISize do |
| 50 | - | robot.select(n) |
| 50 | + | robot.select(n) |
| 51 | - | while robot.count(n) > 0 do |
| 51 | + | while robot.count(n) > 0 do |
| 52 | - | robot.drop() |
| 52 | + | robot.drop() |
| 53 | - | end |
| 53 | + | end |
| 54 | - | end |
| 54 | + | end |
| 55 | - | --collected = 0 |
| 55 | + | --collected = 0 |
| 56 | - | robot.select(3) |
| 56 | + | robot.select(3) |
| 57 | end | |
| 58 | - | |
| 58 | + | |
| 59 | function GoTo( x, y, z, xd, zd ) | |
| 60 | - | while depth > y do |
| 60 | + | while depth > y do |
| 61 | - | if robot.up() then |
| 61 | + | if robot.up() then |
| 62 | - | depth = depth - 1 |
| 62 | + | depth = depth - 1 |
| 63 | - | elseif robot.swingUp() then |
| 63 | + | elseif robot.swingUp() then |
| 64 | - | Collect() |
| 64 | + | Collect() |
| 65 | - | else |
| 65 | + | else |
| 66 | - | os.sleep( 0.5 ) |
| 66 | + | os.sleep( 0.5 ) |
| 67 | - | end |
| 67 | + | end |
| 68 | - | end |
| 68 | + | end |
| 69 | - | |
| 69 | + | |
| 70 | - | if xPos > x then |
| 70 | + | if xPos > x then |
| 71 | - | while xDir ~= -1 do |
| 71 | + | while xDir ~= -1 do |
| 72 | - | TurnLeft() |
| 72 | + | TurnLeft() |
| 73 | - | end |
| 73 | + | end |
| 74 | - | while xPos > x do |
| 74 | + | while xPos > x do |
| 75 | - | if robot.forward() then |
| 75 | + | if robot.forward() then |
| 76 | - | xPos = xPos - 1 |
| 76 | + | xPos = xPos - 1 |
| 77 | - | elseif robot.swing() then |
| 77 | + | elseif robot.swing() then |
| 78 | - | Collect() |
| 78 | + | Collect() |
| 79 | - | else |
| 79 | + | else |
| 80 | - | os.sleep( 0.5 ) |
| 80 | + | os.sleep( 0.5 ) |
| 81 | - | end |
| 81 | + | end |
| 82 | - | end |
| 82 | + | end |
| 83 | - | elseif xPos < x then |
| 83 | + | elseif xPos < x then |
| 84 | - | while xDir ~= 1 do |
| 84 | + | while xDir ~= 1 do |
| 85 | - | TurnLeft() |
| 85 | + | TurnLeft() |
| 86 | - | end |
| 86 | + | end |
| 87 | - | while xPos < x do |
| 87 | + | while xPos < x do |
| 88 | - | if robot.forward() then |
| 88 | + | if robot.forward() then |
| 89 | - | xPos = xPos + 1 |
| 89 | + | xPos = xPos + 1 |
| 90 | - | elseif robot.swing() then |
| 90 | + | elseif robot.swing() then |
| 91 | - | Collect() |
| 91 | + | Collect() |
| 92 | - | else |
| 92 | + | else |
| 93 | - | os.sleep( 0.5 ) |
| 93 | + | os.sleep( 0.5 ) |
| 94 | - | end |
| 94 | + | end |
| 95 | - | end |
| 95 | + | end |
| 96 | - | end |
| 96 | + | end |
| 97 | - | |
| 97 | + | |
| 98 | - | if zPos > z then |
| 98 | + | if zPos > z then |
| 99 | - | while zDir ~= -1 do |
| 99 | + | while zDir ~= -1 do |
| 100 | - | TurnLeft() |
| 100 | + | TurnLeft() |
| 101 | - | end |
| 101 | + | end |
| 102 | - | while zPos > z do |
| 102 | + | while zPos > z do |
| 103 | - | if robot.forward() then |
| 103 | + | if robot.forward() then |
| 104 | - | zPos = zPos - 1 |
| 104 | + | zPos = zPos - 1 |
| 105 | - | elseif robot.swing() then |
| 105 | + | elseif robot.swing() then |
| 106 | - | Collect() |
| 106 | + | Collect() |
| 107 | - | else |
| 107 | + | else |
| 108 | - | os.sleep( 0.5 ) |
| 108 | + | os.sleep( 0.5 ) |
| 109 | - | end |
| 109 | + | end |
| 110 | - | end |
| 110 | + | end |
| 111 | - | elseif zPos < z then |
| 111 | + | elseif zPos < z then |
| 112 | - | while zDir ~= 1 do |
| 112 | + | while zDir ~= 1 do |
| 113 | - | TurnLeft() |
| 113 | + | TurnLeft() |
| 114 | - | end |
| 114 | + | end |
| 115 | - | while zPos < z do |
| 115 | + | while zPos < z do |
| 116 | - | if robot.forward() then |
| 116 | + | if robot.forward() then |
| 117 | - | zPos = zPos + 1 |
| 117 | + | zPos = zPos + 1 |
| 118 | - | elseif robot.swing() then |
| 118 | + | elseif robot.swing() then |
| 119 | - | Collect() |
| 119 | + | Collect() |
| 120 | - | else |
| 120 | + | else |
| 121 | - | os.sleep( 0.5 ) |
| 121 | + | os.sleep( 0.5 ) |
| 122 | - | end |
| 122 | + | end |
| 123 | - | end |
| 123 | + | end |
| 124 | - | end |
| 124 | + | end |
| 125 | - | |
| 125 | + | |
| 126 | - | while depth < y do |
| 126 | + | while depth < y do |
| 127 | - | if robot.down() then |
| 127 | + | if robot.down() then |
| 128 | - | depth = depth + 1 |
| 128 | + | depth = depth + 1 |
| 129 | - | elseif robot.swingDown() then |
| 129 | + | elseif robot.swingDown() then |
| 130 | - | Collect() |
| 130 | + | Collect() |
| 131 | - | else |
| 131 | + | else |
| 132 | - | os.sleep( 0.5 ) |
| 132 | + | os.sleep( 0.5 ) |
| 133 | - | end |
| 133 | + | end |
| 134 | - | end |
| 134 | + | end |
| 135 | - | |
| 135 | + | |
| 136 | - | while zDir ~= zd or xDir ~= xd do |
| 136 | + | while zDir ~= zd or xDir ~= xd do |
| 137 | - | TurnLeft() |
| 137 | + | TurnLeft() |
| 138 | - | end |
| 138 | + | end |
| 139 | end | |
| 140 | - | |
| 140 | + | |
| 141 | local function ReturnStart() | |
| 142 | - | local x,y,z,xd,zd = xPos,depth,zPos,xDir,zDir |
| 142 | + | local x,y,z,xd,zd = xPos,depth,zPos,xDir,zDir |
| 143 | - | print( "Returning to surface...", x,y,z,xd,zd) |
| 143 | + | print( "Returning to surface...", x,y,z,xd,zd) |
| 144 | - | GoTo( 0,0,0,0,-1 ) |
| 144 | + | GoTo( 0,0,0,0,-1 ) |
| 145 | - | |
| 145 | + | |
| 146 | - | Unload() |
| 146 | + | Unload() |
| 147 | - | |
| 147 | + | |
| 148 | - | print( "Resuming mining..." ) |
| 148 | + | print( "Resuming mining..." ) |
| 149 | - | GoTo( x,y,z,xd,zd ) |
| 149 | + | GoTo( x,y,z,xd,zd ) |
| 150 | end | |
| 151 | - | |
| 151 | + | |
| 152 | function RobotDown() | |
| 153 | - | if not Collect() then |
| 153 | + | if not Collect() then |
| 154 | - | ReturnStart() |
| 154 | + | ReturnStart() |
| 155 | - | --return false |
| 155 | + | --return false |
| 156 | - | end |
| 156 | + | end |
| 157 | - | |
| 157 | + | |
| 158 | - | local i = 1 |
| 158 | + | local i = 1 |
| 159 | - | repeat |
| 159 | + | |
| 160 | - | robot.swingDown() |
| 160 | + | robot.swingDown() |
| 161 | - | i = i + 1 |
| 161 | + | i = i + 1 |
| 162 | - | if i == 30 then |
| 162 | + | if i == 30 then |
| 163 | - | return false |
| 163 | + | return false |
| 164 | - | end |
| 164 | + | end |
| 165 | - | until not robot.detectDown() |
| 165 | + | until not robot.detectDown() |
| 166 | - | |
| 166 | + | |
| 167 | - | robot.down() |
| 167 | + | robot.down() |
| 168 | - | |
| 168 | + | |
| 169 | - | depth = depth + 1 |
| 169 | + | depth = depth + 4 |
| 170 | - | if math.fmod( depth, 10 ) == 0 then |
| 170 | + | if math.fmod( depth, 10 ) == 0 then |
| 171 | - | print( "Descended " .. depth .. " metres." ) |
| 171 | + | print( "Descended " .. depth .. " metres." ) |
| 172 | - | end |
| 172 | + | end |
| 173 | - | return true |
| 173 | + | return true |
| 174 | end | |
| 175 | - | |
| 175 | + | |
| 176 | function RobotForward() | |
| 177 | - | if not Collect() then |
| 177 | + | if not Collect() then |
| 178 | - | ReturnStart() |
| 178 | + | ReturnStart() |
| 179 | - | --return false |
| 179 | + | --return false |
| 180 | - | end |
| 180 | + | end |
| 181 | - | |
| 181 | + | |
| 182 | - | local i = 0 |
| 182 | + | local i = 0 |
| 183 | ||
| 184 | - | if COMP.energy() < 5000 then |
| 184 | + | if COMP.energy() < 5000 then |
| 185 | - | Refuel() |
| 185 | + | Refuel() |
| 186 | - | end |
| 186 | + | end |
| 187 | - | |
| 187 | + | |
| 188 | repeat | |
| 189 | - | robot.swing() |
| 189 | + | robot.swing() |
| 190 | - | i = i + 1 |
| 190 | + | i = i + 1 |
| 191 | - | if i == 50 then |
| 191 | + | if i == 50 then |
| 192 | - | return false |
| 192 | + | return false |
| 193 | - | end |
| 193 | + | end |
| 194 | until not robot.detect() | |
| 195 | robot.forward() | |
| 196 | - | |
| 196 | + | |
| 197 | - | xPos = xPos + xDir |
| 197 | + | xPos = xPos + xDir |
| 198 | - | zPos = zPos + zDir |
| 198 | + | zPos = zPos + zDir |
| 199 | - | |
| 199 | + | |
| 200 | - | return true |
| 200 | + | return true |
| 201 | end | |
| 202 | - | |
| 202 | + | |
| 203 | function TurnLeft() | |
| 204 | - | robot.turnLeft() |
| 204 | + | robot.turnLeft() |
| 205 | - | xDir, zDir = -zDir, xDir |
| 205 | + | xDir, zDir = -zDir, xDir |
| 206 | end | |
| 207 | - | |
| 207 | + | |
| 208 | function TurnRight() | |
| 209 | - | robot.turnRight() |
| 209 | + | robot.turnRight() |
| 210 | - | xDir, zDir = zDir, -xDir |
| 210 | + | xDir, zDir = zDir, -xDir |
| 211 | end | |
| 212 | - | |
| 212 | + | |
| 213 | function Refuel() | |
| 214 | - | --local selectedSlot = robot.select() |
| 214 | + | --local selectedSlot = robot.select() |
| 215 | - | --begin |
| 215 | + | --begin |
| 216 | - | --print("Refuel...")
|
| 216 | + | --print("Refuel...")
|
| 217 | - | --robot.select(16) |
| 217 | + | --robot.select(16) |
| 218 | - | --gen.insert(8) |
| 218 | + | --gen.insert(8) |
| 219 | - | --robot.select(selectedSlot) |
| 219 | + | --robot.select(selectedSlot) |
| 220 | - | |
| 220 | + | |
| 221 | - | -- зарядка от "зарядника" |
| 221 | + | -- зарядка от "зарядника" |
| 222 | - | local x,y,z,xd,zd = xPos,depth,zPos,xDir,zDir |
| 222 | + | local x,y,z,xd,zd = xPos,depth,zPos,xDir,zDir |
| 223 | - | print( "Returning to surface...", x,y,z,xd,zd) |
| 223 | + | print( "Returning to surface...", x,y,z,xd,zd) |
| 224 | - | GoTo( 0,0,0,0,-1 ) |
| 224 | + | GoTo( 0,0,0,0,-1 ) |
| 225 | - | |
| 225 | + | |
| 226 | - | Unload() |
| 226 | + | Unload() |
| 227 | - | |
| 227 | + | |
| 228 | - | while COMP.energy() < 20200 do |
| 228 | + | while COMP.energy() < 20200 do |
| 229 | - | print("Пробуем зарядиться...")
|
| 229 | + | print("Пробуем зарядиться...")
|
| 230 | - | os.sleep(60) |
| 230 | + | os.sleep(60) |
| 231 | - | end |
| 231 | + | end |
| 232 | - | |
| 232 | + | |
| 233 | - | print( "Resuming mining..." ) |
| 233 | + | print( "Resuming mining..." ) |
| 234 | - | GoTo( x,y,z,xd,zd ) |
| 234 | + | GoTo( x,y,z,xd,zd ) |
| 235 | - | |
| 235 | + | |
| 236 | end | |
| 237 | - | |
| 237 | + | |
| 238 | function StartQuarry(size) | |
| 239 | - | while not done do |
| 239 | + | while not done do |
| 240 | - | |
| 240 | + | |
| 241 | - | if COMP.energy() < 5000 then |
| 241 | + | if COMP.energy() < 5000 then |
| 242 | - | Refuel() |
| 242 | + | Refuel() |
| 243 | - | end |
| 243 | + | end |
| 244 | - | |
| 244 | + | |
| 245 | - | for n = 1, size do |
| 245 | + | for n = 1, size do |
| 246 | - | for m=1, size - 1 do |
| 246 | + | for m=1, size - 1 do |
| 247 | - | if not RobotForward() then |
| 247 | + | if not RobotForward() then |
| 248 | - | done = true |
| 248 | + | done = true |
| 249 | - | print("Done")
|
| 249 | + | print("Done")
|
| 250 | - | break |
| 250 | + | break |
| 251 | - | end |
| 251 | + | end |
| 252 | - | end |
| 252 | + | end |
| 253 | - | |
| 253 | + | |
| 254 | - | if n < size then |
| 254 | + | if n < size then |
| 255 | - | if math.fmod(n + alternate,2) == 0 then |
| 255 | + | if math.fmod(n + alternate,2) == 0 then |
| 256 | - | TurnLeft() |
| 256 | + | TurnLeft() |
| 257 | - | if not RobotForward() then |
| 257 | + | if not RobotForward() then |
| 258 | - | done = true |
| 258 | + | done = true |
| 259 | - | break |
| 259 | + | break |
| 260 | - | end |
| 260 | + | end |
| 261 | - | TurnLeft() |
| 261 | + | TurnLeft() |
| 262 | - | else |
| 262 | + | else |
| 263 | - | TurnRight() |
| 263 | + | TurnRight() |
| 264 | - | if not RobotForward() then |
| 264 | + | if not RobotForward() then |
| 265 | - | done = true |
| 265 | + | done = true |
| 266 | - | break |
| 266 | + | break |
| 267 | - | end |
| 267 | + | end |
| 268 | - | TurnRight() |
| 268 | + | TurnRight() |
| 269 | - | end |
| 269 | + | end |
| 270 | - | end |
| 270 | + | end |
| 271 | - | |
| 271 | + | |
| 272 | - | if done == true then |
| 272 | + | if done == true then |
| 273 | - | print("Done")
|
| 273 | + | print("Done")
|
| 274 | - | break |
| 274 | + | break |
| 275 | - | end |
| 275 | + | end |
| 276 | - | end |
| 276 | + | end |
| 277 | - | |
| 277 | + | |
| 278 | - | if size > 1 then |
| 278 | + | if size > 1 then |
| 279 | - | if math.fmod(size,2) == 0 then |
| 279 | + | if math.fmod(size,2) == 0 then |
| 280 | - | TurnRight() |
| 280 | + | TurnRight() |
| 281 | - | else |
| 281 | + | else |
| 282 | - | if alternate == 0 then |
| 282 | + | if alternate == 0 then |
| 283 | - | TurnLeft() |
| 283 | + | TurnLeft() |
| 284 | - | else |
| 284 | + | else |
| 285 | - | TurnRight() |
| 285 | + | TurnRight() |
| 286 | - | end |
| 286 | + | end |
| 287 | - | alternate = 1 - alternate |
| 287 | + | alternate = 1 - alternate |
| 288 | - | end |
| 288 | + | end |
| 289 | - | end |
| 289 | + | end |
| 290 | - | |
| 290 | + | |
| 291 | print("Level " .. depth)
| |
| 292 | - | |
| 292 | + | |
| 293 | - | if done == true then |
| 293 | + | if done == true then |
| 294 | - | print("Done")
|
| 294 | + | print("Done")
|
| 295 | - | end |
| 295 | + | end |
| 296 | - | |
| 296 | + | |
| 297 | - | if not RobotDown() then |
| 297 | + | if not RobotDown() then |
| 298 | - | done = true |
| 298 | + | done = true |
| 299 | - | print("Done")
|
| 299 | + | print("Done")
|
| 300 | - | break |
| 300 | + | break |
| 301 | - | end |
| 301 | + | end |
| 302 | end | |
| 303 | end | |
| 304 | - | |
| 304 | + | |
| 305 | - | size = 3 |
| 305 | + | size = 32 |
| 306 | - | |
| 306 | + | |
| 307 | if COMP.energy() < 5000 then | |
| 308 | - | Refuel() |
| 308 | + | Refuel() |
| 309 | end | |
| 310 | - | |
| 310 | + | |
| 311 | print( "Excavating..." ) | |
| 312 | if not RobotDown() then | |
| 313 | - | print("Done")
|
| 313 | + | print("Done")
|
| 314 | else | |
| 315 | - | robot.select(3) |
| 315 | + | robot.select(3) |
| 316 | - | StartQuarry(size) |
| 316 | + | StartQuarry(size) |
| 317 | end | |
| 318 | - | |
| 318 | + | |
| 319 | -- Return to where we started | |
| 320 | GoTo( 0,0,0,0,-1 ) | |
| 321 | Unload() | |
| 322 | GoTo( 0,0,0,0,1 ) | |
| 323 | - | |
| 323 | + | |
| 324 | - | |
| 324 | + | |
| 325 | done1 = 2 | |
| 326 | - | while done1 == 2 do |
| 326 | + | while done1 == 2 do |
| 327 | - | print("Я закончил, выключи меня.")
|
| 327 | + | print("Я закончил, выключи меня.")
|
| 328 | - | os.sleep(6000) |
| 328 | + | os.sleep(6000) |
| 329 | - | end |
| 329 | + | end |