kpoppel
2013-07-02 053fa59739f4b772174bf0a090969b3395ab3f98
commit | author | age
ee5c6c 1 -- This file includes the functions and data structures for registering machines and tools for LV, MV, HV types.
K 2 -- We use the technioc namespace for these functions and data to avoid eventual conflict.
3
4 -- register LV machines here
5 technic.LV_machines    = {}
6 technic.LV_power_tools = {}
7 technic.register_LV_machine = function(nodename,type)
8                  technic.LV_machines[nodename] = type
9                   end
10
11 technic.unregister_LV_machine = function(nodename,type)
12                    technic.LV_machines[nodename] = nil
13                 end
14
15 technic.register_LV_power_tool = function(craftitem,max_charge)
16                     technic.LV_power_tools[craftitem] = max_charge
17                  end
18
19 -- register MV machines here
20 technic.MV_machines    = {}
21 technic.MV_power_tools = {}
22 technic.register_MV_machine = function(nodename,type)
23                  technic.MV_machines[nodename] = type
24                   end
25
26 technic.unregister_MV_machine = function(nodename)
27                    technic.MV_machines[nodename] = nil
28                 end
29
30 technic.register_MV_power_tool = function(craftitem,max_charge)
31                     technic.MV_power_tools[craftitem] = max_charge
32                  end
33
34 -- register HV machines here
35 technic.HV_machines    = {}
36 technic.HV_power_tools = {}
37 technic.register_HV_machine = function(nodename,type)
38                  technic.HV_machines[nodename] = type
39                   end
40
41 technic.unregister_HV_machine = function(nodename)
42                    technic.HV_machines[nodename] = nil
43                 end
44
45 technic.register_HV_power_tool = function(craftitem,max_charge)
46                     technic.HV_power_tools[craftitem] = max_charge
47                  end
48
49
50 -- Utility functions. Not sure exactly what they do.. water.lua uses the two first.
51 function technic.get_RE_item_load (load1,max_load)
52    if load1==0 then load1=65535 end
53    local temp = 65536-load1
54    temp= temp/65535*max_load
55    return math.floor(temp + 0.5)
56 end
57
58 function technic.set_RE_item_load (load1,max_load)
59    if load1 == 0 then return 65535 end
60    local temp=load1/max_load*65535
61    temp=65536-temp
62    return math.floor(temp)
63 end
64
65 -- Wear down a tool depending on the remaining charge.
66 function technic.set_RE_wear (item_stack,load,max_load)
67    local temp=65536-math.floor(load/max_load*65535)
68    item_stack["wear"]=tostring(temp)
69    return item_stack
70 end