diff --git a/technic/doc/api.md b/technic/doc/api.md index c8d22d32..8e800fc6 100644 --- a/technic/doc/api.md +++ b/technic/doc/api.md @@ -193,6 +193,12 @@ Groups: * UNRELIABLE. Indicates whether the item or node belongs to technic * `connect_sides = {"top", "left", ...}` * Extends the Minetest API. Indicates where the machine can be connected. +* `radioactive = ` + * Makes the node radioactive. + * ``: Strength of the node's radiation (ex. `2`). +* `rad_resistant = ` + * Makes the node resistant to radiation. + * ``: Strength of the node's resistance (ex. `80`). Additional definition fields: @@ -251,7 +257,7 @@ The switching station is the center of all electricity distribution. It collects power from sources (PR), distributes it to sinks (RE), and uses the excess/shortfall to charge and discharge batteries (BA). -As a thumb of rule, "EU" (energy unit) values are expressed in kW. +As a rule of thumb, "EU" (energy unit) values are expressed in kW. Network functionality: @@ -266,6 +272,20 @@ Network functionality: 5. If the total demand is more than the available power all RE nodes will be shut down. We have a brown-out situation. + +## Radiation +* `technic.register_rad_resistance(node_name, resistance)` + * Sets the radiation resistance of the given node. + * `node_name`: name of the node + * `resistance`: number, radiation resistance of the node +* `technic.register_group_resistance(group_name, resistance)` + * Sets the radiation resistance of the given group of nodes. + * `group_name`: name of the group + * `resistance`: number, radiation resistance of the group +* `technic.cache_resistances()` + * Cache radiation resistances after Technic loads. + + ## Deprecated functions Following functions are either no longer used by technic, or are planned to diff --git a/technic/radiation.lua b/technic/radiation.lua index 7092b697..73a86265 100644 --- a/technic/radiation.lua +++ b/technic/radiation.lua @@ -28,9 +28,20 @@ or complex internal structure should show no radiation resistance. Fractional resistance values are permitted. --]] +-- Function to register node-specific resistance +function technic.register_rad_resistance(node_name, resistance) + local node = minetest.registered_nodes[node_name] + if node then + if not node.groups then + node.groups = {} + end + node.groups.rad_resistant = resistance + end +end + local S = technic.getter -local rad_resistance_node = { +local node_resistances = { ["default:brick"] = 13, ["default:bronzeblock"] = 45, ["default:clay"] = 15, @@ -147,56 +158,56 @@ local rad_resistance_node = { ["moreores:silver_block"] = 53, ["snow:snow_brick"] = 2.8, ["basic_materials:brass_block"] = 43, - ["technic:carbon_steel_block"] = 40, - ["technic:cast_iron_block"] = 40, - ["technic:chernobylite_block"] = 40, - ["technic:chromium_block"] = 37, ["technic:corium_flowing"] = 40, ["technic:corium_source"] = 80, - ["technic:granite"] = 18, - ["technic:lead_block"] = 80, - ["technic:marble"] = 18, - ["technic:marble_bricks"] = 18, - ["technic:mineral_chromium"] = 19, - ["technic:mineral_uranium"] = 71, - ["technic:mineral_zinc"] = 19, - ["technic:stainless_steel_block"] = 40, - ["technic:zinc_block"] = 36, ["tnt:tnt"] = 11, ["tnt:tnt_burning"] = 11, } -local rad_resistance_group = { - concrete = 16, - tree = 3.4, - uranium_block = 500, - wood = 1.7, -} -local cache_radiation_resistance = {} -local function node_radiation_resistance(node_name) - local resistance = cache_radiation_resistance[node_name] - if resistance then - return resistance - end - local def = minetest.registered_nodes[node_name] - if not def then - cache_radiation_resistance[node_name] = 0 - return 0 - end - resistance = def.radiation_resistance or - rad_resistance_node[node_name] - if not resistance then - resistance = 0 - for g, v in pairs(def.groups) do - if v > 0 and rad_resistance_group[g] then - resistance = resistance + rad_resistance_group[g] + +-- Register all node resistances at once +for node_name, resistance in pairs(node_resistances) do + technic.register_rad_resistance(node_name, resistance) +end + +-- Function to register group-specific resistance +function technic.register_group_resistance(group_name, resistance) + for node_name, node_def in pairs(minetest.registered_nodes) do + if node_def.groups[group_name] then + if not node_def.groups.rad_resistant then + node_def.groups.rad_resistant = resistance end end end - resistance = math.sqrt(resistance) - cache_radiation_resistance[node_name] = resistance - return resistance end +technic.register_group_resistance("concrete", 16) +technic.register_group_resistance("tree", 3.4) +technic.register_group_resistance("uranium_block", 500) +technic.register_group_resistance("wood", 1.7) + +--Radiation resistances cache +technic.resistance_cache = {} + +function technic.cache_resistances() + for node_name, node_def in pairs(minetest.registered_nodes) do + local resistance = 0 + if node_def.groups and node_def.groups.rad_resistant then + resistance = node_def.groups.rad_resistant + end + technic.resistance_cache[node_name] = resistance + end +end + +local function node_radiation_resistance(node_name) + technic.cache_resistances() + + local cached_resistance = technic.resistance_cache[node_name] + if cached_resistance then + return math.sqrt(cached_resistance) + else + return 0 + end +end --[[ Radioactive nodes cause damage to nearby players. The damage @@ -456,7 +467,7 @@ minetest.register_node("technic:chernobylite_block", { description = S("Chernobylite Block"), tiles = {"technic_chernobylite_block.png"}, is_ground_content = true, - groups = {cracky=1, radioactive=4, level=2}, + groups = {cracky=1, radioactive=4, level=2, rad_resistant=40}, sounds = default.node_sound_stone_defaults(), light_source = 2, }) diff --git a/technic_worldgen/nodes.lua b/technic_worldgen/nodes.lua index 90888e43..34bbd3cd 100644 --- a/technic_worldgen/nodes.lua +++ b/technic_worldgen/nodes.lua @@ -5,7 +5,7 @@ minetest.register_node( ":technic:mineral_uranium", { description = S("Uranium Ore"), tiles = { "default_stone.png^technic_mineral_uranium.png" }, is_ground_content = true, - groups = {cracky=3, radioactive=1}, + groups = {cracky=3, radioactive=1, rad_resistant=71}, sounds = default.node_sound_stone_defaults(), drop = "technic:uranium_lump", }) @@ -14,7 +14,7 @@ minetest.register_node( ":technic:mineral_chromium", { description = S("Chromium Ore"), tiles = { "default_stone.png^technic_mineral_chromium.png" }, is_ground_content = true, - groups = {cracky=3}, + groups = {cracky=3, rad_resistant=19}, sounds = default.node_sound_stone_defaults(), drop = "technic:chromium_lump", }) @@ -23,7 +23,7 @@ minetest.register_node( ":technic:mineral_zinc", { description = S("Zinc Ore"), tiles = { "default_stone.png^technic_mineral_zinc.png" }, is_ground_content = true, - groups = {cracky=3}, + groups = {cracky=3, rad_resistant=19}, sounds = default.node_sound_stone_defaults(), drop = "technic:zinc_lump", }) @@ -50,7 +50,7 @@ minetest.register_node( ":technic:granite", { description = S("Granite"), tiles = { "technic_granite.png" }, is_ground_content = true, - groups = {cracky=1}, + groups = {cracky=1, rad_resistant=18}, sounds = default.node_sound_stone_defaults(), }) @@ -58,7 +58,7 @@ minetest.register_node( ":technic:granite_bricks", { description = S("Granite Bricks"), tiles = { "technic_granite_bricks.png" }, is_ground_content = false, - groups = {cracky=1}, + groups = {cracky=1, rad_resistant=18}, sounds = default.node_sound_stone_defaults(), }) @@ -66,7 +66,7 @@ minetest.register_node( ":technic:marble", { description = S("Marble"), tiles = { "technic_marble.png" }, is_ground_content = true, - groups = {cracky=3, marble=1}, + groups = {cracky=3, marble=1, rad_resistant=18}, sounds = default.node_sound_stone_defaults(), }) @@ -74,7 +74,7 @@ minetest.register_node( ":technic:marble_bricks", { description = S("Marble Bricks"), tiles = { "technic_marble_bricks.png" }, is_ground_content = false, - groups = {cracky=3}, + groups = {cracky=3, rad_resistant=18}, sounds = default.node_sound_stone_defaults(), }) @@ -90,7 +90,7 @@ minetest.register_node(":technic:chromium_block", { description = S("Chromium Block"), tiles = { "technic_chromium_block.png" }, is_ground_content = true, - groups = {cracky=1, level=2}, + groups = {cracky=1, level=2, rad_resistant=37}, sounds = default.node_sound_stone_defaults() }) @@ -98,7 +98,7 @@ minetest.register_node(":technic:zinc_block", { description = S("Zinc Block"), tiles = { "technic_zinc_block.png" }, is_ground_content = true, - groups = {cracky=1, level=2}, + groups = {cracky=1, level=2, rad_resistant=36}, sounds = default.node_sound_stone_defaults() }) @@ -106,7 +106,7 @@ minetest.register_node(":technic:lead_block", { description = S("Lead Block"), tiles = { "technic_lead_block.png" }, is_ground_content = true, - groups = {cracky=1, level=2}, + groups = {cracky=1, level=2, rad_resistant=80}, sounds = default.node_sound_stone_defaults() }) @@ -121,7 +121,7 @@ minetest.register_node(":technic:cast_iron_block", { description = S("Cast Iron Block"), tiles = { "technic_cast_iron_block.png" }, is_ground_content = true, - groups = {cracky=1, level=2}, + groups = {cracky=1, level=2, rad_resistant=40}, sounds = default.node_sound_stone_defaults() }) @@ -129,7 +129,7 @@ minetest.register_node(":technic:carbon_steel_block", { description = S("Carbon Steel Block"), tiles = { "technic_carbon_steel_block.png" }, is_ground_content = true, - groups = {cracky=1, level=2}, + groups = {cracky=1, level=2, rad_resistant=40}, sounds = default.node_sound_stone_defaults() }) @@ -137,7 +137,7 @@ minetest.register_node(":technic:stainless_steel_block", { description = S("Stainless Steel Block"), tiles = { "technic_stainless_steel_block.png" }, is_ground_content = true, - groups = {cracky=1, level=2}, + groups = {cracky=1, level=2, rad_resistant=40}, sounds = default.node_sound_stone_defaults() })