diff options
author | FaceDeer <derksenmobile@gmail.com> | 2017-10-12 03:06:24 -0600 |
---|---|---|
committer | FaceDeer <derksenmobile@gmail.com> | 2017-10-12 03:06:24 -0600 |
commit | 65f5ac8520a286ae062824147c2f0e3b0253c8ff (patch) | |
tree | 3b2fe0b773f872f18d7c842476e014235b432160 /util_execute_cycle.lua | |
parent | a44f517a4e17314adf3e6895d95a1f90096df026 (diff) |
add initial support for tapping technic power cables
Diffstat (limited to 'util_execute_cycle.lua')
-rw-r--r-- | util_execute_cycle.lua | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/util_execute_cycle.lua b/util_execute_cycle.lua index 29edcdb..d5f23f0 100644 --- a/util_execute_cycle.lua +++ b/util_execute_cycle.lua @@ -207,10 +207,25 @@ digtron.execute_dig_cycle = function(pos, clicker) local test_fuel_needed = test_build_fuel_cost + digging_fuel_cost - fuel_burning local test_fuel_burned = 0 - - if test_fuel_needed > 0 then - -- check for the available electrical power - test_fuel_burned = digtron.tap_batteries(layout.battery_holders, test_fuel_needed, true) + + local power_from_cables = 0 + if minetest.get_modpath("technic") then + local power_inputs = {} + for _, power_connector in pairs(layout.power_connectors) do + if power_connector.meta.fields.HV_network and power_connector.meta.fields.HV_EU_input then + power_inputs[power_connector.meta.fields.HV_network] = tonumber(power_connector.meta.fields.HV_EU_input) + end + end + for _, power in pairs(power_inputs) do + power_from_cables = power_from_cables + power + end + power_from_cables = power_from_cables / digtron.config.power_ratio + test_fuel_burned = power_from_cables + + if test_fuel_needed - test_fuel_burned > 0 then + -- check for the available electrical power + test_fuel_burned = test_fuel_burned + digtron.tap_batteries(layout.battery_holders, test_fuel_needed, true) + end end if (test_fuel_needed < test_fuel_burned) then exhaust = 0 -- all power needs met by electricity, don't blow smoke @@ -312,11 +327,13 @@ digtron.execute_dig_cycle = function(pos, clicker) minetest.sound_play("buzzer", {gain=0.5, pos=pos}) status_text = S("Digtron unexpectedly failed to execute one or more build operations, likely due to an inventory error.") .. "\n" end - + + local total_fuel_cost = math.max(digging_fuel_cost + building_fuel_cost - power_from_cables, 0) + -- actually burn the fuel needed - fuel_burning = fuel_burning - digging_fuel_cost + fuel_burning = fuel_burning - total_fuel_cost if digtron.config.particle_effects and exhaust == 1 then - table.insert(particle_systems, burn_smoke(pos, digging_fuel_cost)) + table.insert(particle_systems, burn_smoke(pos, total_fuel_cost)) end if fuel_burning < 0 then -- we tap into the batteries either way |