SHOW:
|
|
- or go back to the newest paste.
| 1 | --tBasePC v 1.02 | |
| 2 | ||
| 3 | --MasterPC--never break it or you're fucked... | |
| 4 | ||
| 5 | --variables-- | |
| 6 | local worker = {}
| |
| 7 | local wtblin = 0 --"workerTableIndex" - for RednetListener() | |
| 8 | local rednetTimeout = 2 | |
| 9 | local jobNumber = 0 --for GetJobForTurtle() | |
| 10 | --functions-- | |
| 11 | function JobConstructor() | |
| 12 | ||
| 13 | job = {}
| |
| 14 | local i = 0 | |
| 15 | local length --this is how many subjobs per job are given | |
| 16 | local ilje = 1 --indexLastJobEnd | |
| 17 | function DoNumberShit(_k) | |
| 18 | --print(_k) | |
| 19 | --print(i) | |
| 20 | if _k == length then ilje = ilje + length end | |
| 21 | i = i + 1 | |
| 22 | end | |
| 23 | ||
| 24 | --JobTurtlePlacer-- | |
| 25 | job[i] = "TurtlePlacer" | |
| 26 | i = i + 1 | |
| 27 | ilje = 1 | |
| 28 | - | length = 7-1 |
| 28 | + | |
| 29 | - | for k = 0,length do |
| 29 | + | |
| 30 | - | job[i] = "Digger 2 0 " .. 3*(k)+1 .. " x 48" |
| 30 | + | for k = 6, 0, -1 do |
| 31 | job[i] = "Diggerx1 2 0 " .. 3*(k)+1 .. " x 48" | |
| 32 | DoNumberShit(k) | |
| 33 | end | |
| 34 | - | -- --JobDigSecondTunnelRight at y = -1 -- |
| 34 | + | |
| 35 | - | -- length = 7-1 |
| 35 | + | --JobDigSecondTunnelRight at y = -1 -- |
| 36 | for k = 6, 0, -1 do | |
| 37 | - | -- job[i] = "Digger 4 -1 " .. 3*(k)+1 .. " x 46" |
| 37 | + | job[i] = "Diggerx1 4 -1 " .. 3*(k)+1 .. " x 46" |
| 38 | DoNumberShit(k) | |
| 39 | - | -- end |
| 39 | + | |
| 40 | ||
| 41 | -- --[[ --JobDigFirstTunnel Straight at x = 3 -- | |
| 42 | -- length = 6 | |
| 43 | -- for k = 0, length do | |
| 44 | -- job[i] = "Digger 4 -1 " .. 3*(k)+1 .. " y 49" | |
| 45 | -- DoNumberShit(k) | |
| 46 | -- end ]] | |
| 47 | ||
| 48 | - | --JobDigTerrain from (-2, 0, 0) to (50, 50, ~~20) |
| 48 | + | --JobDigTerrain from (-2, 1, 0) to (50, 50, ~~20) |
| 49 | - | length = 50 |
| 49 | + | |
| 50 | - | for k = -2, 50 do |
| 50 | + | for k = -2, math.floor(xLength/2)*2-1, 2 do |
| 51 | - | for h = 0, 6 do |
| 51 | + | for h = 6, 0, -1 do |
| 52 | - | job[i] = "Digger " .. k .. " 0 " .. 3*(h)+1 .. " y 50" |
| 52 | + | job[i] = "Digger " .. k .. " 1 " .. 3*(h)+1 .. " y 50" |
| 53 | DoNumberShit(k) | |
| 54 | end | |
| 55 | end | |
| 56 | if xLength/2 == math.floor(xLength/2) then | |
| 57 | - | --JobExcavate from (-2, 0, 0) to (50, 50, ~~ground) |
| 57 | + | for h = 6, 0, -1 do |
| 58 | job[i] = "Diggerx1 " .. xLength .. " 1 " .. 3*(h)+1 .. " y 50" | |
| 59 | i = i + 1 | |
| 60 | end | |
| 61 | end | |
| 62 | - | for x = 0, xLength do |
| 62 | + | |
| 63 | - | for z = 0, zJobCount-1 do |
| 63 | + | --JobExcavate from (0, 1, 0) to (50, 50, ~~ground) |
| 64 | - | job[i] = "Miner " .. x .. " 0 " .. -(3*z+2) .. " y " .. yLength |
| 64 | + | local sx = 0 |
| 65 | - | --print(job[i]) sleep(1) |
| 65 | + | local sy = 1 |
| 66 | local sz = 0 | |
| 67 | local xLength = 50 | |
| 68 | local yLength = 50 | |
| 69 | local zLength = computerHeight - 1 --positive if excavating downwards | |
| 70 | local zJobCount = math.floor(zLength/3) | |
| 71 | for x = sx, sx+math.floor((xLength)/2)*2-1, 2 do | |
| 72 | for z = sz+zJobCount-1, sz, -1 do | |
| 73 | job[i] = "Miner " .. sx+x .. " " .. sy .. " " .. sz-(3*z+2) .. " y " .. yLength | |
| 74 | --print(job[i]) sleep(0.1) | |
| 75 | i = i + 1 | |
| 76 | end | |
| 77 | end | |
| 78 | if (xLength)/2 == math.floor((xLength)/2) then | |
| 79 | for z = sz+zJobCount-1, sz, -1 do | |
| 80 | job[i] = "Minerx1 " .. sx+xLength .. " " .. sy .. " " .. sz-(3*z+2) .. " y " .. yLength | |
| 81 | --print(job[i]) sleep(0.1) | |
| 82 | i = i + 1 | |
| 83 | end | |
| 84 | end | |
| 85 | ||
| 86 | --JobBuildFloor at height z with width x and depth y | |
| 87 | local sx, sy, sz, sd = 0, 0, -1, "y" | |
| 88 | local xLength = 50 | |
| 89 | local yLength = 50 | |
| 90 | local z = -1 | |
| 91 | local jobCount = math.floor(xLength/2) | |
| 92 | for x = 0, math.floor(xLength/2)*2-1, 2 do | |
| 93 | job[i] = "Floorx2 " .. x+sx .. " " .. sy .. " " .. sz .. " " .. sd .. " " .. yLength | |
| 94 | --print(job[i]) sleep(0.5) | |
| 95 | i = i + 1 | |
| 96 | end | |
| 97 | if math.floor(xLength/2) == xLength/2 then | |
| 98 | job[i] = "Floorx1 " .. xLength+sx .. " " .. sy .. " " .. sz .. " " .. sd .. " " .. yLength | |
| 99 | --print(job[i]) sleep(0.5) | |
| 100 | i = i + 1 | |
| 101 | end | |
| 102 | ||
| 103 | print("Total Jobs to do: " .. i)
| |
| 104 | end | |
| 105 | function Split(str, pat) | |
| 106 | local t = {}
| |
| 107 | local fpat = "(.-)" .. pat | |
| 108 | local last_end = 1 | |
| 109 | local s, e, cap = str:find(fpat, 1) | |
| 110 | while s do | |
| 111 | if s ~= 1 or cap ~= "" then | |
| 112 | table.insert(t,cap) | |
| 113 | end | |
| 114 | last_end = e+1 | |
| 115 | s, e, cap = str:find(fpat, last_end) | |
| 116 | end | |
| 117 | if last_end <= #str then | |
| 118 | cap = str:sub(last_end) | |
| 119 | table.insert(t, cap) | |
| 120 | end | |
| 121 | return t | |
| 122 | end | |
| 123 | function SendAndGetResponse(_recID, _message) | |
| 124 | SendMessage(_recID, _message) | |
| 125 | local startedTime = os.clock() | |
| 126 | while (os.clock() - startedTime) <= rednetTimeout do | |
| 127 | local id, msg, dis = rednet.receive(rednetTimeout) | |
| 128 | if id == _recID or _recID == 0 then | |
| 129 | local splitMessage = Split(msg, " ") | |
| 130 | if (splitMessage[1] == "pa") then | |
| 131 | return msg | |
| 132 | end | |
| 133 | end | |
| 134 | end | |
| 135 | return false | |
| 136 | end | |
| 137 | function SendAndGetResponseNoTimeout(_recID, _message) | |
| 138 | sendMessage(_recID ,_message) | |
| 139 | while true do | |
| 140 | local id, msg, dis = rednet.receive(0) | |
| 141 | if id == _recID or _recID == 0 then | |
| 142 | local splitMessage = split(msg, " ") | |
| 143 | if (splitMessage[1] == "pa") then | |
| 144 | return msg | |
| 145 | end | |
| 146 | end | |
| 147 | end | |
| 148 | end | |
| 149 | function SendMessage(_recID, _message) | |
| 150 | rednet.send(_recID, _message) | |
| 151 | end | |
| 152 | function ConsoleInput() | |
| 153 | print("Ready for console input!")
| |
| 154 | while true do | |
| 155 | local cmd = Split(read(), " ") | |
| 156 | if cmd[1] == "job" then | |
| 157 | if cmd[2] == "do" then | |
| 158 | local function Arguments() | |
| 159 | local i = 4 | |
| 160 | local arguments = "" | |
| 161 | while cmd[i] do | |
| 162 | arguments = arguments .. " " .. cmd[i] | |
| 163 | end | |
| 164 | i = i + 1 | |
| 165 | return arguments | |
| 166 | end | |
| 167 | if cmd[3] == "TurtlePlacer" or cmd[3] == "Digger" or cmd[3] == "Miner" then | |
| 168 | table.insert(job, jobNumber, cmd[3] .. Arguments()) | |
| 169 | end | |
| 170 | end | |
| 171 | end | |
| 172 | end | |
| 173 | end | |
| 174 | - | print("Welcome to Project Alpha!")
|
| 174 | + | |
| 175 | while true do | |
| 176 | --print("Ready for RednetInput")
| |
| 177 | - | RednetListener() |
| 177 | + | |
| 178 | local splitMessage = Split(message, " ") | |
| 179 | if splitMessage[1] == "pa" then | |
| 180 | if splitMessage[2] == "setup" then | |
| 181 | if splitMessage[3] == "locate" then | |
| 182 | rednet.send(id, "pa setup masterHere") | |
| 183 | worker[wtblin] = id | |
| 184 | wtblin = wtblin + 1 | |
| 185 | print("Worker" .. wtblin .. " listed")
| |
| 186 | print("Has id " .. tonumber(worker[wtblin-1]))
| |
| 187 | end | |
| 188 | elseif splitMessage[2] == "job" then | |
| 189 | if splitMessage[3] == "request" then | |
| 190 | local job = GetJobForTurtle() | |
| 191 | print("Turtle " .. id .. " now has job " .. job)
| |
| 192 | if SendAndGetResponse(id, "pa job do " .. job) ~= "pa job confirm" then | |
| 193 | jobNumber = jobNumber - 1 | |
| 194 | print("JobRequestReceived - but not confirmed!!!")
| |
| 195 | end | |
| 196 | end | |
| 197 | end | |
| 198 | end | |
| 199 | end | |
| 200 | end | |
| 201 | function GetJobForTurtle() | |
| 202 | jobNumber = jobNumber + 1 | |
| 203 | return job[jobNumber - 1] | |
| 204 | end | |
| 205 | function GetHeightFromPlayer() | |
| 206 | print("Please type the computers actual height (look at minimap)")
| |
| 207 | computerHeight = tonumber(read()) | |
| 208 | while computerHeight < 1 or computerHeight > 255 do | |
| 209 | print("must be between 1 and 255!")
| |
| 210 | computerHeight = tonumber(read()) | |
| 211 | end | |
| 212 | print("computerHeight set to " .. computerHeight)
| |
| 213 | end | |
| 214 | ||
| 215 | --welcome message-- | |
| 216 | rednet.open("top")
| |
| 217 | print("Welcome to tBase!")
| |
| 218 | GetHeightFromPlayer() | |
| 219 | JobConstructor() | |
| 220 | parallel.waitForAny(RednetListener, ConsoleInput) --enables rednetListener while be able to access command line |