diff --git a/basic_machines/generator.lua b/basic_machines/generator.lua new file mode 100644 index 0000000..6b14378 --- /dev/null +++ b/basic_machines/generator.lua @@ -0,0 +1,236 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2019 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + + TA3 Tiny Oil Power Generator + +]]-- + +-- for lazy programmers +local S = function(pos) if pos then return minetest.pos_to_string(pos) end end +local P = minetest.string_to_pos +local M = minetest.get_meta + +-- Load support for intllib. +local MP = minetest.get_modpath("techage") +local I,_ = dofile(MP.."/intllib.lua") + +local Power = techage.ElectricCable +local provide_power = techage.power.provide_power +local power_switched = techage.power.power_switched +local firebox = techage.firebox + +local CYCLE_TIME = 2 +local PWR_CAPA = 12 +local BURN_CYCLE_FACTOR = 2.5 + +local function formspec(self, pos, mem) + local fuel_percent = 0 + if mem.generating then + fuel_percent = ((mem.burn_cycles or 1) * 100) / (mem.burn_cycles_total or 1) + end + return "size[8,7]".. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + "list[current_name;fuel;0.5,1;1,1;]".. + "image[1.5,1;1,1;default_furnace_fire_bg.png^[lowpart:".. + fuel_percent..":default_furnace_fire_fg.png]".. + "button[3,1;1.8,1;update;"..I("Update").."]".. + "image_button[5.5,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. + "image[6.5,0.5;1,2;"..techage.power.formspec_power_bar(PWR_CAPA, mem.provided).."]".. + "list[current_player;main;0,3;8,4;]".. + default.get_hotbar_bg(0, 3) +end + +local function can_start(pos, mem, state) + if mem.burn_cycles > 0 then return true end + local inv = M(pos):get_inventory() + return not inv:is_empty("fuel") +end + +local function start_node(pos, mem, state) + mem.generating = true + power_switched(pos) + minetest.sound_play("techage_generator", { + pos = pos, + gain = 1, + max_hear_distance = 7}) +end + +local function stop_node(pos, mem, state) + mem.generating = false + mem.provided = 0 + power_switched(pos) +end + +local State = techage.NodeStates:new({ + node_name_passive = "techage:tiny_generator", + node_name_active = "techage:tiny_generator_on", + cycle_time = CYCLE_TIME, + standby_ticks = 0, + formspec_func = formspec, + can_start = can_start, + start_node = start_node, + stop_node = stop_node, +}) + +local function burning(pos, mem) + local ratio = math.max((mem.provided or PWR_CAPA) / PWR_CAPA, 0.02) + + mem.burn_cycles = (mem.burn_cycles or 0) - ratio + if mem.burn_cycles <= 0 then + local taken = firebox.get_fuel(pos) + if taken then + mem.burn_cycles = firebox.Burntime[taken:get_name()] / CYCLE_TIME * BURN_CYCLE_FACTOR + mem.burn_cycles_total = mem.burn_cycles + return true + else + State:fault(pos, mem) + return false + end + else + return true + end +end + +local function node_timer(pos, elapsed) + local mem = tubelib2.get_mem(pos) + if mem.generating and burning(pos, mem) then + mem.provided = provide_power(pos, PWR_CAPA) + minetest.sound_play("techage_generator", { + pos = pos, + gain = 1, + max_hear_distance = 7}) + return true + else + mem.provided = 0 + end + return false +end + +local function on_receive_fields(pos, formname, fields, player) + if minetest.is_protected(pos, player:get_player_name()) then + return + end + local mem = tubelib2.get_mem(pos) + State:state_button_event(pos, mem, fields) + + if fields.update then + M(pos):set_string("formspec", formspec(State, pos, mem)) + end +end + +local function allow_metadata_inventory(pos, listname, index, stack, player) + if minetest.is_protected(pos, player:get_player_name()) then + return 0 + end + if stack:get_name() == "techage:oil_source" then + return stack:get_count() + end + return 0 +end + +local function on_rightclick(pos) + local mem = tubelib2.get_mem(pos) + M(pos):set_string("formspec", formspec(State, pos, mem)) +end + +minetest.register_node("techage:tiny_generator", { + description = "Tiny Power Generator", + tiles = { + -- up, down, right, left, back, front + "techage_appl_electric_gen_top.png^techage_frame_ta3_top.png", + "techage_appl_electric_gen_top.png^techage_frame_ta3.png", + "techage_appl_electric_gen_side.png^techage_appl_hole_electric.png^techage_frame_ta3.png", + "techage_appl_electric_gen_side.png^techage_frame_ta3.png", + "techage_appl_electric_gen_front.png^[transformFX]^techage_frame_ta3.png", + "techage_appl_electric_gen_front.png^techage_frame_ta3.png", + }, + paramtype2 = "facedir", + groups = {cracky=2, crumbly=2, choppy=2}, + on_rotate = screwdriver.disallow, + is_ground_content = false, + + on_construct = function(pos) + local mem = tubelib2.init_mem(pos) + mem.generating = false + mem.burn_cycles = 0 + local meta = M(pos) + meta:set_string("formspec", formspec(State, pos, mem)) + local inv = meta:get_inventory() + inv:set_size('fuel', 1) + end, + + allow_metadata_inventory_put = allow_metadata_inventory, + allow_metadata_inventory_take = allow_metadata_inventory, + on_receive_fields = on_receive_fields, + on_rightclick = on_rightclick, + on_timer = node_timer, + can_dig = techage.firebox.can_dig, +}) + +minetest.register_node("techage:tiny_generator_on", { + description = "Tiny Power Generator", + tiles = { + -- up, down, right, left, back, front + "techage_appl_electric_gen_top.png^techage_frame_ta3_top.png", + "techage_appl_electric_gen_top.png^techage_frame_ta3.png", + "techage_appl_electric_gen_side.png^techage_appl_hole_electric.png^techage_frame_ta3.png", + "techage_appl_electric_gen_side.png^techage_frame_ta3.png", + { + image = "techage_appl_electric_gen_front4.png^[transformFX]^techage_frame4_ta3.png", + backface_culling = false, + animation = { + type = "vertical_frames", + aspect_w = 32, + aspect_h = 32, + length = 0.8, + }, + }, + { + image = "techage_appl_electric_gen_front4.png^techage_frame4_ta3.png", + backface_culling = false, + animation = { + type = "vertical_frames", + aspect_w = 32, + aspect_h = 32, + length = 0.8, + }, + }, + }, + paramtype = "light", + paramtype2 = "facedir", + groups = {not_in_creative_inventory=1}, + diggable = false, + light_source = 4, + on_rotate = screwdriver.disallow, + is_ground_content = false, + + allow_metadata_inventory_put = allow_metadata_inventory, + allow_metadata_inventory_take = allow_metadata_inventory, + on_receive_fields = on_receive_fields, + on_rightclick = on_rightclick, + on_timer = node_timer, + can_dig = techage.firebox.can_dig, +}) + +techage.power.register_node({"techage:tiny_generator", "techage:tiny_generator_on"}, { + conn_sides = {"R"}, + power_network = Power, +}) + +minetest.register_craft({ + output = "techage:tiny_generator", + recipe = { + {'default:steel_ingot', 'techage:usmium_nuggets', 'default:steel_ingot'}, + {'dye:red', 'basic_materials:gear_steel', 'techage:electric_cableS'}, + {'default:steel_ingot', 'techage:vacuum_tube', 'default:steel_ingot'}, + }, +}) diff --git a/coal_power_station/boiler_top.lua b/coal_power_station/boiler_top.lua index c8d4635..5912355 100644 --- a/coal_power_station/boiler_top.lua +++ b/coal_power_station/boiler_top.lua @@ -23,7 +23,7 @@ local I,_ = dofile(MP.."/intllib.lua") local CYCLE_TIME = 4 local STANDBY_TICKS = 2 -local COUNTDOWN_TICKS = 2 +local COUNTDOWN_TICKS = 20 local HEAT_STEP = 10 local WATER_CONSUMPTION = 0.1 local MAX_WATER = 10 @@ -66,16 +66,18 @@ local function formspec(self, pos, mem) end local function can_start(pos, mem, state) - return mem.temperature and mem.temperature > 80 + return mem.temperature and mem.temperature >= 80 end local function start_node(pos, mem, state) mem.running = transfer(pos, "start", nil) + mem.power_ratio = 0 end local function stop_node(pos, mem, state) transfer(pos, "stop", nil) mem.running = false + mem.power_ratio = 0 end local State = techage.NodeStates:new({ @@ -123,15 +125,15 @@ local function steaming(pos, mem, temp) local wc = WATER_CONSUMPTION * (mem.power_ratio or 1) mem.water_level = math.max((mem.water_level or 0) - wc, 0) mem.running = transfer(pos, "running", nil) - if temp >= 80 then - if mem.running then - State:keep_running(pos, mem, COUNTDOWN_TICKS) + if not mem.running then + State:fault(pos, mem) + elseif temp > 20 then + if temp < 80 then + State:stop(pos, mem) + minetest.get_node_timer(pos):start(CYCLE_TIME) else - State:fault(pos, mem) + State:keep_running(pos, mem, COUNTDOWN_TICKS) end - else - State:stop(pos, mem) - minetest.get_node_timer(pos):start(CYCLE_TIME) end end diff --git a/coal_power_station/firebox.lua b/coal_power_station/firebox.lua index b118cb5..184c607 100644 --- a/coal_power_station/firebox.lua +++ b/coal_power_station/firebox.lua @@ -24,6 +24,7 @@ local I,_ = dofile(MP.."/intllib.lua") local firebox = techage.firebox local CYCLE_TIME = 2 +local BURN_CYCLE_FACTOR = 0.5 local function firehole(pos, on) local param2 = minetest.get_node(pos).param2 @@ -50,11 +51,12 @@ local function node_timer(pos, elapsed) nil, -- network {"techage:coalboiler_top"} -- nodenames ) - mem.burn_cycles = (mem.burn_cycles or 0) - math.max((ratio or 0.02), 0.02) + ratio = math.max((ratio or 0.02), 0.02) + mem.burn_cycles = (mem.burn_cycles or 0) - ratio if mem.burn_cycles <= 0 then local taken = firebox.get_fuel(pos) if taken then - mem.burn_cycles = firebox.Burntime[taken:get_name()] / CYCLE_TIME + mem.burn_cycles = firebox.Burntime[taken:get_name()] / CYCLE_TIME * BURN_CYCLE_FACTOR mem.burn_cycles_total = mem.burn_cycles else mem.running = false diff --git a/coal_power_station/generator.lua b/coal_power_station/generator.lua index 43493f1..240c91c 100644 --- a/coal_power_station/generator.lua +++ b/coal_power_station/generator.lua @@ -208,7 +208,7 @@ techage.register_node({"techage:generator", "techage:generator_on"}, { mem.triggered = 2 mem.power_level = payload if mem.generating then - return math.max((mem.provided or PWR_CAPA) / PWR_CAPA, 0.1) + return math.max((mem.provided or PWR_CAPA) / PWR_CAPA, 0.02) else return 0 end diff --git a/coal_power_station/help.lua b/coal_power_station/help.lua index dae3a7f..51bbf76 100644 --- a/coal_power_station/help.lua +++ b/coal_power_station/help.lua @@ -50,7 +50,8 @@ techage.register_help_page("Coal Power Station", HelpText, nil, Images) local PowerConsumption = S([[ Power consumption and supply: -- TA3 Generator: 80 +- TA3 Power Station: 80 +- TA3 Tiny Generator: 12 - TA3 Akku Box: 10 (in both dirs) - TA3 Oil Drill Box: 16 - TA3 Oil Pumpjack: 16 @@ -67,6 +68,21 @@ Power consumption and supply: techage.register_help_page("Power Consumption", PowerConsumption, "techage:t3_source", nil) +local BurnCycles = S([[ +Burning times with one oil item for +Stream Engine / Power Station / Tiny Generator: + +Power max. : 25 / 80 / 12 +Oil burn time/s : 32 / 20 / 100 + +burn time at power 2 : 400 / 800 / 600 +burn time at power 10 : 80 / 160 / 120 +burn time at power 20 : 40 / 80 / -- +]]) + +techage.register_help_page("Oil Burning Times", BurnCycles, "techage:t3_source", nil) + + techage.register_help_page(S("TA3 Electronic Fab"), S([[Used to produce WLAN Chips, needed for TA4 machines.]]), "techage:ta3_electronic_fab_pas") diff --git a/init.lua b/init.lua index 5568998..1509a4d 100644 --- a/init.lua +++ b/init.lua @@ -89,6 +89,7 @@ else dofile(MP.."/basic_machines/autocrafter.lua") dofile(MP.."/basic_machines/forceload.lua") dofile(MP.."/basic_machines/electronic_fab.lua") + dofile(MP.."/basic_machines/generator.lua") -- Coal power station dofile(MP.."/coal_power_station/help.lua") diff --git a/power/power.lua b/power/power.lua index d44fb98..72337f6 100644 --- a/power/power.lua +++ b/power/power.lua @@ -390,6 +390,7 @@ end function techage.power.formspec_power_bar(max_power, current_power) local percent = techage.power.percent(max_power, current_power) + percent = (percent + 5) / 1.22 -- texture correction return "techage_form_level_bg.png^[lowpart:"..percent..":techage_form_level_fg.png" end diff --git a/sounds/techage_generator.ogg b/sounds/techage_generator.ogg new file mode 100644 index 0000000..52c6014 Binary files /dev/null and b/sounds/techage_generator.ogg differ diff --git a/steam_engine/firebox.lua b/steam_engine/firebox.lua index aa2714a..feec67a 100644 --- a/steam_engine/firebox.lua +++ b/steam_engine/firebox.lua @@ -24,6 +24,7 @@ local I,_ = dofile(MP.."/intllib.lua") local firebox = techage.firebox local CYCLE_TIME = 2 +local BURN_CYCLE_FACTOR = 0.8 local function node_timer(pos, elapsed) local mem = tubelib2.get_mem(pos) @@ -41,7 +42,7 @@ local function node_timer(pos, elapsed) if mem.burn_cycles <= 0 then local taken = firebox.get_fuel(pos) if taken then - mem.burn_cycles = firebox.Burntime[taken:get_name()] / CYCLE_TIME + mem.burn_cycles = firebox.Burntime[taken:get_name()] / CYCLE_TIME * BURN_CYCLE_FACTOR mem.burn_cycles_total = mem.burn_cycles else mem.running = false diff --git a/textures/techage_appl_electric_gen_front.png b/textures/techage_appl_electric_gen_front.png new file mode 100644 index 0000000..f76b6f1 Binary files /dev/null and b/textures/techage_appl_electric_gen_front.png differ diff --git a/textures/techage_appl_electric_gen_front4.png b/textures/techage_appl_electric_gen_front4.png new file mode 100644 index 0000000..63dcf72 Binary files /dev/null and b/textures/techage_appl_electric_gen_front4.png differ diff --git a/textures/techage_appl_electric_gen_side.png b/textures/techage_appl_electric_gen_side.png new file mode 100644 index 0000000..b021d62 Binary files /dev/null and b/textures/techage_appl_electric_gen_side.png differ diff --git a/textures/techage_appl_electric_gen_top.png b/textures/techage_appl_electric_gen_top.png new file mode 100644 index 0000000..77354ea Binary files /dev/null and b/textures/techage_appl_electric_gen_top.png differ diff --git a/textures/techage_appl_electric_power.png b/textures/techage_appl_electric_power.png deleted file mode 100644 index bb49b7e..0000000 Binary files a/textures/techage_appl_electric_power.png and /dev/null differ diff --git a/textures/techage_electric_power.png b/textures/techage_electric_power.png deleted file mode 100644 index f5a7a2b..0000000 Binary files a/textures/techage_electric_power.png and /dev/null differ