bug fixes by kurik:
fail at initial energy read from fuel time protection check for keyboard set
This commit is contained in:
parent
08f61c0865
commit
5d6e7326b6
73
commands.lua
73
commands.lua
@ -47,11 +47,14 @@ end
|
|||||||
local check_operations = function(name, quit)
|
local check_operations = function(name, quit)
|
||||||
if basic_robot.maxoperations~=0 then
|
if basic_robot.maxoperations~=0 then
|
||||||
local data = basic_robot.data[name];
|
local data = basic_robot.data[name];
|
||||||
local operations = data.operations;
|
local operations = data.operations-1;
|
||||||
if operations > 0 then data.operations = operations-1 else
|
if operations >= 0 then
|
||||||
|
data.operations = operations
|
||||||
|
else
|
||||||
if quit then
|
if quit then
|
||||||
error("robot out of available operations in one step."); return
|
error("robot out of available operations in one step."); return false
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -83,14 +86,25 @@ end
|
|||||||
|
|
||||||
basic_robot.commands.turn = function (name, angle)
|
basic_robot.commands.turn = function (name, angle)
|
||||||
local obj = basic_robot.data[name].obj;
|
local obj = basic_robot.data[name].obj;
|
||||||
local yaw = obj:getyaw()+angle;
|
local yaw;
|
||||||
|
-- more precise turns by 1 degree resolution
|
||||||
|
local mult = math.pi/180;
|
||||||
|
local yaw = obj:getyaw();
|
||||||
|
yaw = math.floor((yaw+angle)/mult+0.5)*mult;
|
||||||
obj:setyaw(yaw);
|
obj:setyaw(yaw);
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
basic_robot.digcosts = { -- 1 energy = 1 coal
|
||||||
|
["default:stone"] = 1/25,
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
basic_robot.commands.dig = function(name,dir)
|
basic_robot.commands.dig = function(name,dir)
|
||||||
|
|
||||||
local energy = 0;
|
local energy = 0;
|
||||||
check_operations(name);
|
check_operations(name,true)
|
||||||
|
|
||||||
local obj = basic_robot.data[name].obj;
|
local obj = basic_robot.data[name].obj;
|
||||||
local pos = pos_in_dir(obj, dir)
|
local pos = pos_in_dir(obj, dir)
|
||||||
@ -104,28 +118,20 @@ basic_robot.commands.dig = function(name,dir)
|
|||||||
local spos = obj:get_luaentity().spawnpos;
|
local spos = obj:get_luaentity().spawnpos;
|
||||||
local inv = minetest.get_meta(spos):get_inventory();
|
local inv = minetest.get_meta(spos):get_inventory();
|
||||||
|
|
||||||
--require coal to dig
|
--require energy to dig
|
||||||
if nodename == "default:stone" and basic_robot.use_coal then
|
if basic_robot.dig_require_energy then
|
||||||
local meta = minetest.get_meta(spos);
|
local digcost = basic_robot.digcosts[nodename];
|
||||||
local fuel = meta:get_int("fuel")-1;
|
if digcost then
|
||||||
if fuel<0 then -- attempt to refuel
|
local data = basic_robot.data[name];
|
||||||
local stack = ItemStack("default:coal_lump 10");
|
local energy = (data.menergy or 0) - digcost;
|
||||||
if inv:contains_item("main", stack) then
|
if energy<0 then
|
||||||
meta:set_int("fuel",50) -- 50 digs with 10 coal
|
return false, "need " .. digcost .. " energy "
|
||||||
inv:remove_item("main", stack)
|
|
||||||
else
|
|
||||||
error("#OUT OF FUEL: please insert 10 coal lumps to dig")
|
|
||||||
basic_robot.data[name].obj:remove();
|
|
||||||
basic_robot.data[name].obj=nil;
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
else
|
data.menergy = energy;
|
||||||
meta:set_int("fuel",fuel)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if not inv then return end
|
if not inv then return end
|
||||||
--inv:add_item("main",ItemStack( nodename ));
|
--inv:add_item("main",ItemStack( nodename ));
|
||||||
|
|
||||||
@ -357,7 +363,7 @@ end
|
|||||||
basic_robot.commands.attack = function(name, target) -- attack range 4, damage 5
|
basic_robot.commands.attack = function(name, target) -- attack range 4, damage 5
|
||||||
|
|
||||||
local energy = 0;
|
local energy = 0;
|
||||||
check_operations(name);
|
check_operations(name,true);
|
||||||
|
|
||||||
local reach = 4;
|
local reach = 4;
|
||||||
local damage = 5;
|
local damage = 5;
|
||||||
@ -402,7 +408,8 @@ basic_robot.commands.grab = function(name,target)
|
|||||||
end
|
end
|
||||||
|
|
||||||
basic_robot.commands.read_book = function (itemstack) -- itemstack should contain book
|
basic_robot.commands.read_book = function (itemstack) -- itemstack should contain book
|
||||||
local data = minetest.deserialize(itemstack:get_metadata())
|
local data = itemstack:get_meta():to_table().fields -- 0.4.16
|
||||||
|
--local data = minetest.deserialize(itemstack:get_metadata()) -- pre 0.4.16
|
||||||
if data then
|
if data then
|
||||||
return data.title,data.text;
|
return data.title,data.text;
|
||||||
else
|
else
|
||||||
@ -423,9 +430,10 @@ basic_robot.commands.write_book = function(name,title,text) -- returns itemstack
|
|||||||
data.page = 1
|
data.page = 1
|
||||||
data.page_max = math.ceil((#data.text:gsub("[^\n]", "") + 1) / lpp)
|
data.page_max = math.ceil((#data.text:gsub("[^\n]", "") + 1) / lpp)
|
||||||
data.owner = name
|
data.owner = name
|
||||||
local data_str = minetest.serialize(data)
|
--local data_str = minetest.serialize(data) -- pre 0.4.16
|
||||||
|
--new_stack:set_metadata(data_str);
|
||||||
|
new_stack:get_meta():from_table({fields = data}) -- 0.4.16
|
||||||
|
|
||||||
new_stack:set_metadata(data_str);
|
|
||||||
return new_stack;
|
return new_stack;
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -519,6 +527,7 @@ basic_robot.commands.activate = function(name,mode, dir)
|
|||||||
|
|
||||||
local effector=table.mesecons.effector;
|
local effector=table.mesecons.effector;
|
||||||
|
|
||||||
|
if not mode then mode = 1 end
|
||||||
if mode > 0 then
|
if mode > 0 then
|
||||||
if not effector.action_on then return false end
|
if not effector.action_on then return false end
|
||||||
effector.action_on(tpos,node,16)
|
effector.action_on(tpos,node,16)
|
||||||
@ -597,9 +606,11 @@ basic_robot.commands.keyboard = {
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
set = function(spos,pos,type)
|
set = function(data,pos,type)
|
||||||
|
|
||||||
|
local owner = data.owner;
|
||||||
|
if minetest.is_protected(pos,owner) then return false end -- with fast protect checks this shouldnt be problem!
|
||||||
|
|
||||||
if math.abs(pos.x-spos.x)>10 or math.abs(pos.y-spos.y)>10 or math.abs(pos.z-spos.z)>10 then return false end
|
|
||||||
local nodename;
|
local nodename;
|
||||||
if type == 0 then
|
if type == 0 then
|
||||||
nodename = "air"
|
nodename = "air"
|
||||||
@ -796,16 +807,16 @@ basic_robot.commands.machine = {
|
|||||||
local stack = ItemStack(input);
|
local stack = ItemStack(input);
|
||||||
if not inv:contains_item("main",stack) then return nil,"2: no input material" end
|
if not inv:contains_item("main",stack) then return nil,"2: no input material" end
|
||||||
|
|
||||||
-- read energy value of input
|
-- read energy value of input ( coal lump = 1)
|
||||||
local add_energy = basic_robot.technic.fuels[input];
|
local add_energy = basic_robot.technic.fuels[input];
|
||||||
if not add_energy then -- lookup fuel value
|
if not add_energy then -- lookup fuel value
|
||||||
local fueladd, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = {stack}})
|
local fueladd, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = {stack}})
|
||||||
if fueladd.time > 0 then
|
if fueladd.time > 0 then
|
||||||
add_energy = fueladd.time;
|
add_energy = fueladd.time/40; -- fix by kurik
|
||||||
else
|
else
|
||||||
return nil, "3: material can not be used as a fuel"
|
return nil, "3: material can not be used as a fuel"
|
||||||
end
|
end
|
||||||
if add_energy>0 then basic_robot.technic.fuels[input] = add_energy/40 end
|
if add_energy>0 then basic_robot.technic.fuels[input] = add_energy end
|
||||||
end
|
end
|
||||||
|
|
||||||
inv:remove_item("main", stack);
|
inv:remove_item("main", stack);
|
||||||
|
23
init.lua
23
init.lua
@ -8,8 +8,8 @@ basic_robot.call_limit = 48; -- how many execution calls per script run allowed
|
|||||||
basic_robot.bad_inventory_blocks = { -- disallow taking from these nodes inventories
|
basic_robot.bad_inventory_blocks = { -- disallow taking from these nodes inventories
|
||||||
["craft_guide:sign_wall"] = true,
|
["craft_guide:sign_wall"] = true,
|
||||||
}
|
}
|
||||||
basic_robot.maxoperations = 1; -- how many operations available per run, 0 = unlimited
|
basic_robot.maxoperations = 1; -- how many operations (dig, generate energy,..) available per run, 0 = unlimited
|
||||||
basic_robot.use_coal = true; -- does robot require coal to dig stone?
|
basic_robot.dig_require_energy = true; -- does robot require energy to dig?
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
|
||||||
@ -276,7 +276,7 @@ function getSandboxEnv (name)
|
|||||||
|
|
||||||
keyboard = {
|
keyboard = {
|
||||||
get = function() return commands.keyboard.get(name) end,
|
get = function() return commands.keyboard.get(name) end,
|
||||||
set = function(pos,type) return commands.keyboard.set(basic_robot.data[name].spawnpos,pos,type) end,
|
set = function(pos,type) return commands.keyboard.set(basic_robot.data[name],pos,type) end,
|
||||||
read = function(pos) return minetest.get_node(pos).name end,
|
read = function(pos) return minetest.get_node(pos).name end,
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1246,7 +1246,8 @@ local on_receive_robot_form = function(pos, formname, fields, sender)
|
|||||||
local text = "";
|
local text = "";
|
||||||
for i=1,16 do
|
for i=1,16 do
|
||||||
local itemstack = inv:get_stack("library", i);
|
local itemstack = inv:get_stack("library", i);
|
||||||
local data = minetest.deserialize(itemstack:get_metadata())
|
local data = itemstack:get_meta():to_table().fields -- 0.4.16
|
||||||
|
--local data = minetest.deserialize(itemstack:get_metadata()) -- pre 0.4.16
|
||||||
if data then
|
if data then
|
||||||
text = string.sub(data.title or "",1,32);
|
text = string.sub(data.title or "",1,32);
|
||||||
else
|
else
|
||||||
@ -1376,7 +1377,7 @@ minetest.register_on_player_receive_fields(
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local robot_formname = "robot_book_";
|
local robot_formname = "robot_book_"; -- book editing gui
|
||||||
if string.find(formname,robot_formname) then
|
if string.find(formname,robot_formname) then
|
||||||
local p = string.find(formname,":");
|
local p = string.find(formname,":");
|
||||||
local sel = tonumber(string.sub(formname, string.len(robot_formname)+1,p-1)) or 1;
|
local sel = tonumber(string.sub(formname, string.len(robot_formname)+1,p-1)) or 1;
|
||||||
@ -1388,7 +1389,7 @@ minetest.register_on_player_receive_fields(
|
|||||||
local meta = minetest.get_meta(libpos);
|
local meta = minetest.get_meta(libpos);
|
||||||
local inv = minetest.get_meta(libpos):get_inventory();local itemstack = inv:get_stack("library", sel);
|
local inv = minetest.get_meta(libpos):get_inventory();local itemstack = inv:get_stack("library", sel);
|
||||||
if itemstack then
|
if itemstack then
|
||||||
local data = minetest.deserialize(itemstack:get_metadata())
|
local data = itemstack:get_meta():to_table().fields -- 0.4.16, old minetest.deserialize(itemstack:get_metadata())
|
||||||
if not data then data = {} end
|
if not data then data = {} end
|
||||||
local text = fields.book or "";
|
local text = fields.book or "";
|
||||||
data.text = text or ""
|
data.text = text or ""
|
||||||
@ -1398,9 +1399,12 @@ minetest.register_on_player_receive_fields(
|
|||||||
data.owner = data.owner or ""
|
data.owner = data.owner or ""
|
||||||
local lpp = 14
|
local lpp = 14
|
||||||
data.page_max = math.ceil((#text:gsub("[^\n]", "") + 1) / lpp)
|
data.page_max = math.ceil((#text:gsub("[^\n]", "") + 1) / lpp)
|
||||||
local data_str = minetest.serialize(data)
|
|
||||||
|
--local data_str = minetest.serialize(data)
|
||||||
local new_stack = ItemStack("default:book_written")
|
local new_stack = ItemStack("default:book_written")
|
||||||
new_stack:set_metadata(data_str);
|
|
||||||
|
new_stack:get_meta():from_table({fields = data}) -- 0.4.16
|
||||||
|
--new_stack:set_metadata(data_str);
|
||||||
inv:set_stack("library",sel, new_stack);
|
inv:set_stack("library",sel, new_stack);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1411,7 +1415,7 @@ minetest.register_on_player_receive_fields(
|
|||||||
--minetest.chat_send_all(fields.book or "")
|
--minetest.chat_send_all(fields.book or "")
|
||||||
local inv = minetest.get_meta(libpos):get_inventory();local itemstack = inv:get_stack("library", sel);
|
local inv = minetest.get_meta(libpos):get_inventory();local itemstack = inv:get_stack("library", sel);
|
||||||
if itemstack then
|
if itemstack then
|
||||||
local data = minetest.deserialize(itemstack:get_metadata()) or {};
|
local data = itemstack:get_meta():to_table().fields -- 0.4.16, old minetest.deserialize(itemstack:get_metadata()) or {};
|
||||||
meta:set_string("code", data.text or "")
|
meta:set_string("code", data.text or "")
|
||||||
robot_spawner_update_form(libpos);
|
robot_spawner_update_form(libpos);
|
||||||
minetest.chat_send_player(player:get_player_name(),"#robot: program loaded from book")
|
minetest.chat_send_player(player:get_player_name(),"#robot: program loaded from book")
|
||||||
@ -1431,6 +1435,7 @@ function(name, message)
|
|||||||
data.listen_msg = message;
|
data.listen_msg = message;
|
||||||
data.listen_speaker = name;
|
data.listen_speaker = name;
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
//lua minetest.get_player_by_name("rnd"):set_properties({visual_size = {x=1,y=1}})
|
|
||||||
|
|
||||||
local name = "rnd"; local player = minetest.get_player_by_name(name); player:set_properties({visual = "upright_sprite"});player:set_properties({textures={"default_tool_diamondpick.png"}})
|
|
||||||
|
|
||||||
|
|
||||||
// change to robot
|
|
||||||
local name = "rnd"; local player = minetest.get_player_by_name(name); player:set_properties({visual = "cube"});player:set_properties({textures={"arrow.png^[transformR90","basic_machine_side.png","basic_machine_side.png","basic_machine_side.png","face.png","basic_machine_side.png"}});player:set_properties({collisionbox={-0.5,-0.5,-0.5,0.5,0.5,0.5}})
|
|
||||||
|
|
||||||
//LawnGreen
|
|
||||||
|
|
||||||
local name = "rnd"; local player = minetest.get_player_by_name(name); player:set_properties({visual = "sprite"});player:set_properties({textures={"farming_bottle_ethanol.png"}});player:set_properties({collisionbox={-0.5,-0.5,-0.5,0.5,0.5,0.5}});player:set_properties({visual_size = {x=2,y=2}})
|
|
||||||
|
|
||||||
//farming_blueberry_muffin
|
|
||||||
local name = "rnd"; local player = minetest.get_player_by_name(name); player:set_properties({visual = "cube"});player:set_properties({textures={"farming_pumpkin_face_off.png","farming_pumpkin_face_off.png","farming_pumpkin_face_off.png","farming_pumpkin_face_off.png","farming_pumpkin_face_off.png","farming_pumpkin_face_off.png"}});player:set_properties({collisionbox={-0.5,-0.5,-0.5,0.5,0.5,0.5}})
|
|
||||||
|
|
||||||
--nyan cat
|
|
||||||
//lua local name = "rnd"; local player = minetest.get_player_by_name(name); player:set_properties({visual = "cube"});player:set_properties({textures = {"nyancat_side.png", "nyancat_side.png", "nyancat_side.png","nyancat_side.png", "nyancat_front.png", "nyancat_back.png"}});player:set_properties({collisionbox={-0.5,-0.5,-0.5,0.5,0.5,0.5}})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local name = "rnd1"; local player = minetest.get_player_by_name(name); player:set_nametag_attributes({text = "Friend of Giorge"});
|
|
||||||
|
|
||||||
//lua local player = minetest.get_player_by_name("pro2");minetest.sound_play("nyan",{object = player,gain = 1.0,max_hear_distance = 8,loop = false})
|
|
||||||
|
|
||||||
|
|
||||||
//lua local player = minetest.get_player_by_name("rnd");player:set_properties({visual = "mesh",textures = {"mobs_spider.png"},mesh = "mobs_spider.x",visual_size = {x=7,y=7}})
|
|
||||||
|
|
||||||
|
|
||||||
//lua local player = minetest.get_player_by_name("rnd");player:set_properties({visual = "mesh",textures = {"mobs_dungeon_master.png"},mesh = "mobs_dungeon_master.b3d",visual_size = {x=1,y=1}})
|
|
||||||
|
|
||||||
//lua local player = minetest.get_player_by_name("best");player:set_properties({visual = "mesh",textures = {"zmobs_mese_monster.png"},mesh = "zmobs_mese_monster.x",visual_size = {x=1,y=1}})
|
|
||||||
|
|
||||||
//lua local player = minetest.get_player_by_name("rnd1");player:set_properties({visual = "mesh",textures = {"mobs_oerkki.png"},mesh = "mobs_oerkki.b3d",visual_size = {x=1,y=1}})
|
|
||||||
|
|
||||||
//lua local player = minetest.get_player_by_name("rnd1");player:set_properties({visual = "mesh",textures = {"mobs_stone_monster.png"},mesh = "mobs_stone_monster.b3d",visual_size = {x=1,y=1}})
|
|
||||||
|
|
||||||
|
|
||||||
mesh = "zmobs_lava_flan.x",
|
|
||||||
textures = {
|
|
||||||
{"zmobs_lava_flan.png"},
|
|
||||||
{"zmobs_lava_flan2.png"},
|
|
||||||
{"zmobs_lava_flan3.png"},
|
|
||||||
},
|
|
||||||
----------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//lua local player = minetest.get_player_by_name("towner");player:set_physics_override({speed=0.05})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user