Remove lv, mv, and hv tiers from power tools.

Theyre already tiered with Mk1-3 (at least drill is, more in the future).
Tools can be considered as designed for different tiers of circuits thx to their power needs.
For example Mk3 will require ages to load in LV batbox.
Batboxes load tools timining: LV standard (1000EU), MV 4x faster (4000EU), HV 16x faster (16000EU)
Also since 1EU is the same in any circuit it is possible to move energy from one to another with portable devices like crystals.

Other changes:
- moved charge/discharge functions to battery_boxes_commons.lua
- added UI style backgrounds for all the batboxes
This commit is contained in:
RealBadAngel 2013-07-17 19:14:01 +02:00
parent 55a0a40963
commit 3bc6cad671
11 changed files with 45 additions and 299 deletions

@ -1,4 +1,4 @@
-- Minetest 0.4.6 mod: technic
-- Minetest 0.4.7 mod: technic
-- namespace: technic
-- (c) 2012-2013 by RealBadAngel <mk@realbadangel.pl>

@ -17,13 +17,15 @@ local battery_box_formspec =
"invsize[8,9;]"..
"image[1,1;1,2;technic_power_meter_bg.png]"..
"list[current_name;src;3,1;1,1;]"..
"image[4,1;1,1;technic_battery_reload.png]"..
"list[current_name;dst;5,1;1,1;]"..
"label[0,0;HV Battery Box]"..
"label[3,0;Charge]"..
"label[5,0;Discharge]"..
"label[1,3;Power level]"..
"list[current_player;main;0,5;8,4;]"
"list[current_player;main;0,5;8,4;]"..
"background[-0.19,-0.25;8.4,9.75;ui_form_bg.png]"..
"background[0,0;8,4;ui_hv_battery_box.png]"..
"background[0,5;8,4;ui_main_inventory.png]"
minetest.register_node("technic:hv_battery_box", {
description = "HV Battery Box",
@ -84,92 +86,6 @@ for i = 1,8,1 do
})
end
local power_tools = technic.HV_power_tools
local function charge_HV_tools(meta, charge)
--charge registered power tools
local inv = meta:get_inventory()
if not inv:is_empty("src") then
local srcstack = inv:get_stack("src", 1)
local src_item = srcstack:to_table()
local src_meta = get_item_meta(src_item["metadata"])
local toolname = src_item["name"]
if power_tools[toolname] ~= nil then
-- Set meta data for the tool if it didn't do it itself :-(
src_meta = get_item_meta(src_item["metadata"])
if src_meta==nil then
src_meta = {}
src_meta["technic_hv_power_tool"] = true
src_meta["charge"] = 0
else
if src_meta["technic_hv_power_tool"] == nil then
src_meta["technic_hv_power_tool"] = true
src_meta["charge"] = 0
end
end
-- Do the charging
local item_max_charge = power_tools[toolname]
local tool_charge = src_meta["charge"]
local charge_step = 1000 -- how much to charge per tick
if tool_charge < item_max_charge and tool_charge > 0 then
if tool_charge - charge_step < 0 then
charge_step = charge
end
if tool_charge + charge_step > item_max_charge then
charge_step = item_max_charge - tool_charge
end
tool_charge = tool_charge + charge_step
charge = charge - charge_step
technic.set_RE_wear(src_item, tool_charge, item_max_charge)
src_meta["charge"] = tool_charge
src_item["metadata"] = set_item_meta(src_meta)
inv:set_stack("src", 1, src_item)
end
end
end
return charge -- return the remaining charge in the battery
end
local function discharge_HV_tools(meta, charge, max_charge)
-- discharging registered power tools
local inv = meta:get_inventory()
if not inv:is_empty("dst") then
srcstack = inv:get_stack("dst", 1)
src_item = srcstack:to_table()
local src_meta = get_item_meta(src_item["metadata"])
local toolname = src_item["name"]
if power_tools[toolname] ~= nil then
-- Set meta data for the tool if it didn't do it itself :-(
src_meta = get_item_meta(src_item["metadata"]) or {}
if src_meta["technic_hv_power_tool"] == nil then
src_meta["technic_hv_power_tool"] = true
src_meta["charge"] = 0
end
-- Do the discharging
local item_max_charge = power_tools[toolname]
local tool_charge = src_meta["charge"]
local charge_step = 4000 -- how much to discharge per tick
if tool_charge > 0 and charge < max_charge then
if tool_charge + charge_step > max_charge then
charge_step = max_charge - charge
end
if tool_charge - charge_step < 0 then
charge_step = charge
end
tool_charge = tool_charge - charge_step
charge = charge + charge_step
technic.set_RE_wear(src_item, tool_charge, item_max_charge)
src_meta["charge"] = tool_charge
src_item["metadata"] = set_item_meta(src_meta)
inv:set_stack("dst", 1, src_item)
end
end
end
return charge -- return the remaining charge in the battery
end
minetest.register_abm({
nodenames = {"technic:hv_battery_box", "technic:hv_battery_box1", "technic:hv_battery_box2",
"technic:hv_battery_box3", "technic:hv_battery_box4", "technic:hv_battery_box5",
@ -192,8 +108,8 @@ minetest.register_abm({
end
-- Charging/discharging tools here
current_charge = charge_HV_tools(meta, current_charge)
current_charge = discharge_HV_tools(meta, current_charge, max_charge)
current_charge = charge_tools(meta, current_charge, 16000)
current_charge = discharge_tools(meta, current_charge, max_charge, 16000)
-- Set a demand (we allow batteries to charge on less than the demand though)
meta:set_int("HV_EU_demand", math.min(max_charge_rate, max_charge-current_charge))

@ -3,6 +3,7 @@ local path = technic.modpath.."/machines"
dofile(path.."/switching_station.lua")
dofile(path.."/supply_converter.lua")
dofile(path.."/alloy_furnaces_commons.lua")
dofile(path.."/battery_boxes_commons.lua")
dofile(path.."/lv/init.lua")
dofile(path.."/mv/init.lua")
dofile(path.."/hv/init.lua")

@ -1,8 +1,8 @@
-- LV Battery box and some other nodes...
technic.register_LV_power_tool("technic:battery",10000)
technic.register_MV_power_tool("technic:red_energy_crystal",100000)
technic.register_HV_power_tool("technic:green_energy_crystal",250000)
technic.register_HV_power_tool("technic:blue_energy_crystal",500000)
technic.register_power_tool("technic:battery",10000)
technic.register_power_tool("technic:red_energy_crystal",100000)
technic.register_power_tool("technic:green_energy_crystal",250000)
technic.register_power_tool("technic:blue_energy_crystal",500000)
minetest.register_craft({
output = 'technic:battery 1',
@ -47,7 +47,7 @@ local battery_box_formspec =
"image[1,1;1,2;technic_power_meter_bg.png]"..
"list[current_name;src;3,1;1,1;]"..
"list[current_name;dst;5,1;1,1;]"..
"label[0,0;Battery box]"..
"label[0,0;LV Battery Box]"..
"label[3,0;Charge]"..
"label[5,0;Discharge]"..
"label[1,3;Power level]"..
@ -116,89 +116,6 @@ for i=1,8,1 do
})
end
local power_tools = technic.LV_power_tools
local charge_LV_tools = function(meta, charge)
--charge registered power tools
local inv = meta:get_inventory()
if inv:is_empty("src")==false then
local srcstack = inv:get_stack("src", 1)
local src_item=srcstack:to_table()
local src_meta=get_item_meta(src_item["metadata"])
local toolname = src_item["name"]
if power_tools[toolname] ~= nil then
-- Set meta data for the tool if it didn't do it itself :-(
src_meta=get_item_meta(src_item["metadata"])
if src_meta==nil then
src_meta={}
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
else
if src_meta["technic_power_tool"]==nil then
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
end
end
-- Do the charging
local item_max_charge = power_tools[toolname]
local load = src_meta["charge"]
local load_step = 1000 -- how much to charge per tick
if load<item_max_charge and charge>0 then
if charge-load_step<0 then load_step=charge end
if load+load_step>item_max_charge then load_step=item_max_charge-load end
load=load+load_step
charge=charge-load_step
technic.set_RE_wear(src_item,load,item_max_charge)
src_meta["charge"] = load
src_item["metadata"] = set_item_meta(src_meta)
inv:set_stack("src", 1, src_item)
end
end
end
return charge -- return the remaining charge in the battery
end
local discharge_LV_tools = function(meta, charge, max_charge)
-- discharging registered power tools
local inv = meta:get_inventory()
if inv:is_empty("dst") == false then
srcstack = inv:get_stack("dst", 1)
src_item=srcstack:to_table()
local src_meta=get_item_meta(src_item["metadata"])
local toolname = src_item["name"]
if power_tools[toolname] ~= nil then
-- Set meta data for the tool if it didn't do it itself :-(
src_meta=get_item_meta(src_item["metadata"])
if src_meta==nil then
src_meta={}
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
else
if src_meta["technic_power_tool"]==nil then
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
end
end
-- Do the discharging
local item_max_charge = power_tools[toolname]
local load = src_meta["charge"]
local load_step = 4000 -- how much to discharge per tick
if load>0 and charge<max_charge then
if charge+load_step>max_charge then load_step=max_charge-charge end
if load-load_step<0 then load_step=load end
load=load-load_step
charge=charge+load_step
technic.set_RE_wear(src_item,load,item_max_charge)
src_meta["charge"]=load
src_item["metadata"]=set_item_meta(src_meta)
inv:set_stack("dst", 1, src_item)
end
end
end
return charge -- return the remaining charge in the battery
end
minetest.register_abm(
{nodenames = {"technic:battery_box","technic:battery_box1","technic:battery_box2","technic:battery_box3","technic:battery_box4",
"technic:battery_box5","technic:battery_box6","technic:battery_box7","technic:battery_box8"},
@ -223,8 +140,8 @@ minetest.register_abm(
end
-- Charging/discharging tools here
current_charge = charge_LV_tools(meta, current_charge)
current_charge = discharge_LV_tools(meta, current_charge, max_charge)
current_charge = charge_tools(meta, current_charge, 1000)
current_charge = discharge_tools(meta, current_charge, max_charge, 1000)
-- Set a demand (we allow batteries to charge on less than the demand though)
meta:set_int("LV_EU_demand", math.min(max_charge_rate, max_charge-current_charge))

@ -9,16 +9,18 @@ minetest.register_craft(
})
local battery_box_formspec =
"invsize[8,9;]"..
"image[1,1;1,2;technic_power_meter_bg.png]"..
"list[current_name;src;3,1;1,1;]"..
"image[4,1;1,1;technic_battery_reload.png]"..
"list[current_name;dst;5,1;1,1;]"..
"label[0,0;MV_Battery box]"..
"label[3,0;Charge]"..
"label[5,0;Discharge]"..
"label[1,3;Power level]"..
"list[current_player;main;0,5;8,4;]"
"invsize[8,9;]"..
"image[1,1;1,2;technic_power_meter_bg.png]"..
"list[current_name;src;3,1;1,1;]"..
"list[current_name;dst;5,1;1,1;]"..
"label[0,0;MV Battery Box]"..
"label[3,0;Charge]"..
"label[5,0;Discharge]"..
"label[1,3;Power level]"..
"list[current_player;main;0,5;8,4;]"..
"background[-0.19,-0.25;8.4,9.75;ui_form_bg.png]"..
"background[0,0;8,4;ui_mv_battery_box.png]"..
"background[0,5;8,4;ui_main_inventory.png]"
minetest.register_node(
"technic:mv_battery_box", {
@ -78,89 +80,6 @@ for i=1,8,1 do
})
end
local power_tools = technic.MV_power_tools
local charge_MV_tools = function(meta, charge)
--charge registered power tools
local inv = meta:get_inventory()
if inv:is_empty("src")==false then
local srcstack = inv:get_stack("src", 1)
local src_item=srcstack:to_table()
local src_meta=get_item_meta(src_item["metadata"])
local toolname = src_item["name"]
if power_tools[toolname] ~= nil then
-- Set meta data for the tool if it didn't do it itself :-(
src_meta=get_item_meta(src_item["metadata"])
if src_meta==nil then
src_meta={}
src_meta["technic_mv_power_tool"]=true
src_meta["charge"]=0
else
if src_meta["technic_mv_power_tool"]==nil then
src_meta["technic_mv_power_tool"]=true
src_meta["charge"]=0
end
end
-- Do the charging
local item_max_charge = power_tools[toolname]
local load = src_meta["charge"]
local load_step = 1000 -- how much to charge per tick
if load<item_max_charge and charge>0 then
if charge-load_step<0 then load_step=charge end
if load+load_step>item_max_charge then load_step=item_max_charge-load end
load=load+load_step
charge=charge-load_step
technic.set_RE_wear(src_item,load,item_max_charge)
src_meta["charge"] = load
src_item["metadata"] = set_item_meta(src_meta)
inv:set_stack("src", 1, src_item)
end
end
end
return charge -- return the remaining charge in the battery
end
local discharge_MV_tools = function(meta, charge, max_charge)
-- discharging registered power tools
local inv = meta:get_inventory()
if inv:is_empty("dst") == false then
srcstack = inv:get_stack("dst", 1)
src_item=srcstack:to_table()
local src_meta=get_item_meta(src_item["metadata"])
local toolname = src_item["name"]
if power_tools[toolname] ~= nil then
-- Set meta data for the tool if it didn't do it itself :-(
src_meta=get_item_meta(src_item["metadata"])
if src_meta==nil then
src_meta={}
src_meta["technic_mv_power_tool"]=true
src_meta["charge"]=0
else
if src_meta["technic_mv_power_tool"]==nil then
src_meta["technic_mv_power_tool"]=true
src_meta["charge"]=0
end
end
-- Do the discharging
local item_max_charge = power_tools[toolname]
local load = src_meta["charge"]
local load_step = 4000 -- how much to discharge per tick
if load>0 and charge<max_charge then
if charge+load_step>max_charge then load_step=max_charge-charge end
if load-load_step<0 then load_step=load end
load=load-load_step
charge=charge+load_step
technic.set_RE_wear(src_item,load,item_max_charge)
src_meta["charge"]=load
src_item["metadata"]=set_item_meta(src_meta)
inv:set_stack("dst", 1, src_item)
end
end
end
return charge -- return the remaining charge in the battery
end
minetest.register_abm(
{
nodenames = {"technic:mv_battery_box","technic:mv_battery_box1","technic:mv_battery_box2","technic:mv_battery_box3","technic:mv_battery_box4",
@ -187,8 +106,8 @@ minetest.register_abm(
end
-- Charging/discharging tools here
current_charge = charge_MV_tools(meta, current_charge)
current_charge = discharge_MV_tools(meta, current_charge, max_charge)
current_charge = charge_tools(meta, current_charge, 4000)
current_charge = discharge_tools(meta, current_charge, max_charge, 4000)
-- Set a demand (we allow batteries to charge on less than the demand though)
meta:set_int("MV_EU_demand", math.min(max_charge_rate, max_charge-current_charge))

@ -1,9 +1,15 @@
-- This file includes the functions and data structures for registering machines and tools for LV, MV, HV types.
-- We use the technic namespace for these functions and data to avoid eventual conflict.
-- register power tools here
technic.power_tools = {}
technic.register_power_tool = function(craftitem,max_charge)
technic.power_tools[craftitem] = max_charge
end
-- register LV machines here
technic.LV_machines = {}
technic.LV_power_tools = {}
technic.register_LV_machine = function(nodename,type)
technic.LV_machines[nodename] = type
end
@ -12,10 +18,6 @@ technic.unregister_LV_machine = function(nodename,type)
technic.LV_machines[nodename] = nil
end
technic.register_LV_power_tool = function(craftitem,max_charge)
technic.LV_power_tools[craftitem] = max_charge
end
-- register MV machines here
technic.MV_machines = {}
technic.MV_power_tools = {}
@ -27,10 +29,6 @@ technic.unregister_MV_machine = function(nodename)
technic.MV_machines[nodename] = nil
end
technic.register_MV_power_tool = function(craftitem,max_charge)
technic.MV_power_tools[craftitem] = max_charge
end
-- register HV machines here
technic.HV_machines = {}
technic.HV_power_tools = {}
@ -42,11 +40,6 @@ technic.unregister_HV_machine = function(nodename)
technic.HV_machines[nodename] = nil
end
technic.register_HV_power_tool = function(craftitem,max_charge)
technic.HV_power_tools[craftitem] = max_charge
end
-- Utility functions. Not sure exactly what they do.. water.lua uses the two first.
function technic.get_RE_item_load (load1,max_load)
if load1==0 then load1=65535 end

@ -3,7 +3,7 @@ local chainsaw_max_charge = 30000 -- 30000 - Maximum charge of the saw
local chainsaw_charge_per_node = 12 -- 12 - Gives 2500 nodes on a single charge (about 50 complete normal trees)
local chainsaw_leaves = true -- true - Cut down entire trees, leaves and all
technic.register_LV_power_tool ("technic:chainsaw",chainsaw_max_charge)
technic.register_power_tool ("technic:chainsaw",chainsaw_max_charge)
minetest.register_tool("technic:chainsaw", {
description = "Chainsaw",

@ -1,7 +1,7 @@
-- original code comes from walkin_light mod by Echo http://minetest.net/forum/viewtopic.php?id=2621
local flashlight_max_charge=30000
technic.register_LV_power_tool ("technic:flashlight",flashlight_max_charge)
technic.register_power_tool ("technic:flashlight",flashlight_max_charge)
minetest.register_tool("technic:flashlight", {
description = "Flashlight",

@ -210,7 +210,7 @@ function drill_dig_it4 (pos,player)
drill_dig_it0 (pos,player)
end
technic.register_MV_power_tool ("technic:mining_drill",mining_drill_max_charge)
technic.register_power_tool ("technic:mining_drill",mining_drill_max_charge)
minetest.register_tool("technic:mining_drill", {
description = "Mining Drill Mk1",
inventory_image = "technic_mining_drill.png",
@ -243,10 +243,10 @@ minetest.register_tool("technic:mining_drill_mk2", {
return itemstack
end,
})
technic.register_HV_power_tool ("technic:mining_drill_mk2",mining_drill_mk2_max_charge)
technic.register_power_tool ("technic:mining_drill_mk2",mining_drill_mk2_max_charge)
for i=1,4,1 do
technic.register_HV_power_tool ("technic:mining_drill_mk2_"..i,mining_drill_mk2_max_charge)
technic.register_power_tool ("technic:mining_drill_mk2_"..i,mining_drill_mk2_max_charge)
minetest.register_tool("technic:mining_drill_mk2_"..i, {
description = "Mining Drill Mk2 in Mode "..i,
inventory_image = "technic_mining_drill_mk2.png^technic_tool_mode"..i..".png",
@ -267,10 +267,10 @@ minetest.register_tool("technic:mining_drill_mk3", {
return itemstack
end,
})
technic.register_HV_power_tool ("technic:mining_drill_mk3",mining_drill_mk3_max_charge)
technic.register_power_tool ("technic:mining_drill_mk3",mining_drill_mk3_max_charge)
for i=1,5,1 do
technic.register_HV_power_tool ("technic:mining_drill_mk3_"..i,mining_drill_mk3_max_charge)
technic.register_power_tool ("technic:mining_drill_mk3_"..i,mining_drill_mk3_max_charge)
minetest.register_tool("technic:mining_drill_mk3_"..i, {
description = "Mining Drill Mk3 in Mode "..i,
inventory_image = "technic_mining_drill_mk3.png^technic_tool_mode"..i..".png",

@ -1,5 +1,5 @@
local laser_mk1_max_charge=40000
technic.register_LV_power_tool ("technic:laser_mk1",laser_mk1_max_charge)
technic.register_power_tool ("technic:laser_mk1",laser_mk1_max_charge)
local laser_shoot = function(itemstack, player, pointed_thing)
local laser_straight_mode=0

@ -1,5 +1,5 @@
local sonic_screwdriver_max_charge=15000
technic.register_HV_power_tool ("technic:sonic_screwdriver",sonic_screwdriver_max_charge)
technic.register_power_tool ("technic:sonic_screwdriver",sonic_screwdriver_max_charge)
minetest.register_tool("technic:sonic_screwdriver", {
description = "Sonic Screwdriver",