--[[ Signs Bot ========= Copyright (C) 2019-2021 Joachim Stolberg GPLv3 See LICENSE.txt for more information Signs Bot: interface for techage ]]-- -- Load support for I18n. local S = signs_bot.S local MAX_CAPA = signs_bot.MAX_CAPA local PWR_NEEDED = 8 if minetest.global_exists("techage") then local function on_power(pos) local mem = tubelib2.get_mem(pos) mem.power_available = true mem.charging = true signs_bot.infotext(pos, S("charging")) end local function on_nopower(pos) local mem = tubelib2.get_mem(pos) mem.power_available = false signs_bot.infotext(pos, S("no power")) end local Cable = techage.ElectricCable local power = networks.power signs_bot.register_inventory({"techage:chest_ta2", "techage:chest_ta3", "techage:chest_ta4", "techage:ta3_silo", "techage:ta4_silo", "techage:ta4_sensor_chest", "techage:ta4_reactor"}, { allow_inventory_put = function(pos, stack, player_name) return not minetest.is_protected(pos, player_name) end, allow_inventory_take = function(pos, stack, player_name) return not minetest.is_protected(pos, player_name) end, put = { listname = "main", }, take = { listname = "main", }, }) signs_bot.register_inventory({"techage:meltingpot", "techage:meltingpot_active"}, { allow_inventory_put = function(pos, stack, player_name) return not minetest.is_protected(pos, player_name) end, allow_inventory_take = function(pos, stack, player_name) return not minetest.is_protected(pos, player_name) end, put = { listname = "src", }, take = { listname = "dst", }, }) signs_bot.register_inventory({ "techage:ta2_autocrafter_pas", "techage:ta2_autocrafter_act", "techage:ta3_autocrafter_pas", "techage:ta3_autocrafter_act"}, { allow_inventory_put = function(pos, stack, player_name) return not minetest.is_protected(pos, player_name) end, allow_inventory_take = function(pos, stack, player_name) return not minetest.is_protected(pos, player_name) end, put = { listname = "src", }, take = { listname = "dst", }, }) signs_bot.register_inventory({ "techage:ta2_distributor_pas", "techage:ta2_distributor_act", "techage:ta3_distributor_pas", "techage:ta3_distributor_act", "techage:ta4_distributor_pas", "techage:ta4_distributor_act", "techage:ta4_high_performance_distributor_pas", "techage:ta4_high_performance_distributor_act"}, { allow_inventory_put = function(pos, stack, player_name) return not minetest.is_protected(pos, player_name) end, allow_inventory_take = function(pos, stack, player_name) return not minetest.is_protected(pos, player_name) end, put = { listname = "src", }, take = { listname = "src", }, }) local function percent_value(max_val, curr_val) return math.min(math.ceil(((curr_val or 0) * 100.0) / (max_val or 1.0)), 100) end signs_bot.percent_value = percent_value function signs_bot.formspec_battery_capa(max_capa, current_capa) local percent = percent_value(max_capa, current_capa) return "image[0.1,0;0.5,1;signs_bot_form_level_bg.png^[lowpart:".. percent..":signs_bot_form_level_fg.png]" end signs_bot.register_botcommand("ignite", { mod = "techage", params = "", num_param = 0, description = S("Ignite the techage charcoal lighter"), cmnd = function(base_pos, mem) local pos = signs_bot.lib.dest_pos(mem.robot_pos, mem.robot_param2, {0}) local node = tubelib2.get_node_lvm(pos) if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_ignite then minetest.registered_nodes[node.name].on_ignite(pos) end return signs_bot.DONE end, }) signs_bot.register_botcommand("low_batt", { mod = "techage", params = "", num_param = 1, description = S("Turns the bot off if the\nbattery power is below the\ngiven value in percent (1..99)"), check = function(val) val = tonumber(val) or 5 return val and val > 0 and val < 100 end, cmnd = function(base_pos, mem, val) val = tonumber(val) or 5 local pwr = percent_value(signs_bot.MAX_CAPA, mem.capa) if pwr < val then signs_bot.stop_robot(base_pos, mem) return signs_bot.TURN_OFF end return signs_bot.DONE end, }) signs_bot.register_botcommand("jump_low_batt", { mod = "techage", params = "