diff --git a/README.txt b/README.txt index 5950b38..a247eec 100644 --- a/README.txt +++ b/README.txt @@ -18,4 +18,12 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ----------------------------------------------------------------------- \ No newline at end of file +---------------------------------------------------------------------- + + +GAMEPLAY: + +- robot has limited operations available every run ( 1 run per 1 second). +- while using for loops, while loops or function calls it is limited to default 48 such code executions per run +- while using 'physical' operations like move/dig robot has (default) 10 operations available per run. Default costs are + move=2, dig = 6, insert = 2, place = 2, machine.generate = 6, machine.smelt = 6, machine.grind = 6, \ No newline at end of file diff --git a/commands.lua b/commands.lua index 68b9c84..6956116 100644 --- a/commands.lua +++ b/commands.lua @@ -115,7 +115,7 @@ end basic_robot.digcosts = { -- 1 energy = 1 coal ["default:stone"] = 1/25, - + ["default:cloud"] = 10^8, } @@ -433,9 +433,18 @@ basic_robot.commands.grab = function(name,target) end +--local minetest_version = minetest.get_version().string; basic_robot.commands.read_book = function (itemstack) -- itemstack should contain book - local data = itemstack:get_meta():to_table().fields -- 0.4.16 - --local data = minetest.deserialize(itemstack:get_metadata()) -- pre 0.4.16 + local data; + --if minetest_version == "0.4.16" then + data = itemstack:get_meta():to_table().fields -- 0.4.16 + if data and data.text then + data.text = data.text:gsub(string.char(13),string.char(10)) --for unknown reason books sometime? convert \n (10) to CR (13) + end + -- else + -- local data = minetest.deserialize(itemstack:get_metadata()) -- pre 0.4.16 + -- end + if data then return data.title,data.text; else @@ -539,6 +548,8 @@ end local robot_activate_furnace = minetest.registered_nodes["default:furnace"].on_metadata_inventory_put; -- this function will activate furnace basic_robot.commands.activate = function(name,mode, dir) + + check_operations(name,2,true); local obj = basic_robot.data[name].obj; local tpos = pos_in_dir(obj, dir); -- position of target block in front @@ -896,7 +907,7 @@ basic_robot.commands.machine = { -- convert fuel into energy generate_power = function(name,input, amount) -- fuel used, if no fuel then amount specifies how much energy builtin generator should produce - check_operations(name,1.5, true) + check_operations(name,6, true) if amount and amount>0 then -- attempt to generate power from builtin generator local pos = basic_robot.data[name].spawnpos; -- position of spawner block @@ -943,7 +954,7 @@ basic_robot.commands.machine = { smelt = function(name,input,amount) -- input material, amount of energy used for smelt local energy = 0; -- can only do one step at a run time - check_operations(name,2,true) + check_operations(name,6,true) if string.find(input," ") then return nil, "0: only one item per smelt" end @@ -1005,6 +1016,7 @@ basic_robot.commands.machine = { -- grind grind = function(name,input) --[in] ={fuel cost, out, quantity of material required for processing} + check_operations(name,6,true) local recipe = basic_robot.technic.grinder_recipes[input]; if not recipe then return nil, "unknown recipe" end local cost = recipe[1]; local output = recipe[2]; @@ -1035,6 +1047,7 @@ basic_robot.commands.machine = { -- compress compress = function(name,input) --[in] ={fuel cost, out, quantity of material required for processing} + check_operations(name,6,true) local recipe = basic_robot.technic.compressor_recipes[input]; if not recipe then return nil, "unknown recipe" end local cost = recipe[1]; local output = recipe[2]; @@ -1061,13 +1074,15 @@ basic_robot.commands.machine = { end, transfer_power = function(name,amount,target) + + check_operations(name,2, true); local pos = basic_robot.data[name].spawnpos; local data = basic_robot.data[name]; local tdata = basic_robot.data[target]; if not tdata then return nil, "target inactive" end local energy = 0; -- can only do one step at a run time - check_operations(name,0.5, true); + energy = data.menergy or 0; if amount>energy then return nil,"energy too low" end diff --git a/init.lua b/init.lua index 695257e..4351cbd 100644 --- a/init.lua +++ b/init.lua @@ -21,11 +21,11 @@ basic_robot.bad_inventory_blocks = { -- disallow taking from these nodes invento basic_robot.http_api = minetest.request_http_api(); -basic_robot.version = "2018/07/22a"; +basic_robot.version = "2018/07/23a"; basic_robot.data = {}; -- stores all robot related data --[[ -[name] = { sandbox= .., bytecode = ..., ram = ..., obj = robot object, spawnpos= ..., authlevel = ...} +[name] = { sandbox= .., bytecode = ..., ram = ..., obj = robot object, spawnpos= ..., authlevel = ... , t = code execution time} robot object = object of entity, used to manipulate movements and more --]] basic_robot.ids = {}; -- stores maxid for each player @@ -52,6 +52,7 @@ function getSandboxEnv (name) left_up = 11, right_up = 12, forward_up = 13, backward_up = 14 } + if not basic_robot.data[name].rom then basic_robot.data[name].rom = {} end -- create rom if not yet existing local env = { pcall=pcall, @@ -398,16 +399,6 @@ function getSandboxEnv (name) tonumber = tonumber, pairs = pairs, ipairs = ipairs, error = error, type=type, - --_ccounter = basic_robot.data[name].ccounter, -- counts how many executions of critical spots in script - - -- increase_ccounter = - -- function() - -- local _ccounter = basic_robot.data[name].ccounter; - -- if _ccounter > basic_robot.call_limit then - -- error("Execution limit " .. basic_robot.call_limit .. " exceeded"); - -- end - -- basic_robot.data[name].ccounter = _ccounter + 1; - -- end, }; -- ROBOT FUNCTIONS: move,dig, place,insert,take,check_inventory,activate,read_node,read_text,write_text @@ -565,7 +556,7 @@ end local identify_strings = function(code) -- returns list of positions {start,end} of literal strings in lua code - local i = 0; local j; local length = string.len(code); + local i = 0; local j; local _; local length = string.len(code); local mode = 0; -- 0: not in string, 1: in '...' string, 2: in "..." string, 3. in [==[ ... ]==] string local modes = { {"'","'"}, @@ -616,38 +607,24 @@ is_inside_string = function(strings,pos) -- is position inside one of the string return strings[mid][1]<=pos and pos<=strings[mid][2] end ---[[ -is_inside_string = function(pos,script) - local i1=string.find (script, "\"", 1); - if not i1 then - return false - end - local i2=0; - local par = 1; - - if pos