diff options
25 files changed, 746 insertions, 524 deletions
diff --git a/concrete/init.lua b/concrete/init.lua index 4d5e781..66564ba 100644 --- a/concrete/init.lua +++ b/concrete/init.lua @@ -84,9 +84,9 @@ minetest.register_node(":technic:blast_resistant_concrete", { groups = {cracky=1, level=3, concrete=1}, sounds = default.node_sound_stone_defaults(), on_blast = function(pos, intensity) - if intensity > 1 then + if intensity > 9 then minetest.remove_node(pos) - minetest.add_item(pos, "technic:blast_resistant_concrete") + return {"technic:blast_resistant_concrete"} end end, }) diff --git a/technic/config.lua b/technic/config.lua index 81a2224..29321f9 100644 --- a/technic/config.lua +++ b/technic/config.lua @@ -9,6 +9,9 @@ local defaults = { enable_wind_mill = "false", enable_frames = "false", enable_corium_griefing = "true", + enable_radiation_protection = "true", + enable_entity_radiation_damage = "true", + enable_longterm_radiation_damage = "true", } for k, v in pairs(defaults) do diff --git a/technic/crafts.lua b/technic/crafts.lua index 8a8cd37..4859768 100644 --- a/technic/crafts.lua +++ b/technic/crafts.lua @@ -191,3 +191,14 @@ minetest.register_craft({ }, }) +minetest.register_craft({ + output = "default:dirt 2", + type = "shapeless", + replacements = {{"bucket:bucket_water","bucket:bucket_empty"}}, + recipe = { + "technic:stone_dust", + "group:leaves", + "bucket:bucket_water", + "group:sand", + }, +}) diff --git a/technic/helpers.lua b/technic/helpers.lua index 164cf7e..5780f27 100644 --- a/technic/helpers.lua +++ b/technic/helpers.lua @@ -63,64 +63,129 @@ technic.tube_inject_item = pipeworks.tube_inject_item or function(pos, start_pos end --- Based on code by Uberi: https://gist.github.com/Uberi/3125280 +--- Iterates over the node positions along the specified ray. +-- The returned positions will not include the starting position. function technic.trace_node_ray(pos, dir, range) - local p = vector.round(pos) - local x_step, y_step, z_step = 0, 0, 0 - local x_component, y_component, z_component = 0, 0, 0 - local x_intersect, y_intersect, z_intersect = 0, 0, 0 - - if dir.x == 0 then - x_intersect = math.huge - elseif dir.x > 0 then - x_step = 1 - x_component = 1 / dir.x - x_intersect = x_component - else - x_step = -1 - x_component = 1 / -dir.x - end - if dir.y == 0 then - y_intersect = math.huge - elseif dir.y > 0 then - y_step = 1 - y_component = 1 / dir.y - y_intersect = y_component - else - y_step = -1 - y_component = 1 / -dir.y - end - if dir.z == 0 then - z_intersect = math.huge - elseif dir.z > 0 then - z_step = 1 - z_component = 1 / dir.z - z_intersect = z_component - else - z_step = -1 - z_component = 1 / -dir.z - end + local x_step = dir.x > 0 and 1 or -1 + local y_step = dir.y > 0 and 1 or -1 + local z_step = dir.z > 0 and 1 or -1 + + local i = 1 + return function(p) + -- Approximation of where we should be if we weren't rounding + -- to nodes. This moves forward a bit faster then we do. + -- A correction is done below. + local real_x = pos.x + (dir.x * i) + local real_y = pos.y + (dir.y * i) + local real_z = pos.z + (dir.z * i) + + -- How far off we've gotten from where we should be. + local dx = math.abs(real_x - p.x) + local dy = math.abs(real_y - p.y) + local dz = math.abs(real_z - p.z) - return function() - if x_intersect < y_intersect then - if x_intersect < z_intersect then + -- If the real position moves ahead too fast, stop it so we + -- can catch up. If it gets too far ahead it will smooth + -- out our movement too much and we won't turn fast enough. + if dx + dy + dz < 2 then + i = i + 1 + end + + -- Step in whichever direction we're most off course in. + if dx > dy then + if dx > dz then p.x = p.x + x_step - x_intersect = x_intersect + x_component else p.z = p.z + z_step - z_intersect = z_intersect + z_component end - elseif y_intersect < z_intersect then + elseif dy > dz then p.y = p.y + y_step - y_intersect = y_intersect + y_component else p.z = p.z + z_step - z_intersect = z_intersect + z_component end if vector.distance(pos, p) > range then return nil end return p - end + end, vector.round(pos) +end + + +--- Like trace_node_ray, but includes extra positions close to the ray. +function technic.trace_node_ray_fat(pos, dir, range) + local x_step = dir.x > 0 and 1 or -1 + local y_step = dir.y > 0 and 1 or -1 + local z_step = dir.z > 0 and 1 or -1 + + local next_poses = {} + + local i = 1 + return function(p) + local ni, np = next(next_poses) + if np then + next_poses[ni] = nil + return np + end + + -- Approximation of where we should be if we weren't rounding + -- to nodes. This moves forward a bit faster then we do. + -- A correction is done below. + local real_x = pos.x + (dir.x * i) + local real_y = pos.y + (dir.y * i) + local real_z = pos.z + (dir.z * i) + + -- How far off we've gotten from where we should be. + local dx = math.abs(real_x - p.x) + local dy = math.abs(real_y - p.y) + local dz = math.abs(real_z - p.z) + + -- If the real position moves ahead too fast, stop it so we + -- can catch up. If it gets too far ahead it will smooth + -- out our movement too much and we won't turn fast enough. + if dx + dy + dz < 2 then + i = i + 1 + end + + -- Step in whichever direction we're most off course in. + local sx, sy, sz -- Whether we've already stepped along each axis + if dx > dy then + if dx > dz then + sx = true + p.x = p.x + x_step + else + sz = true + p.z = p.z + z_step + end + elseif dy > dz then + sy = true + p.y = p.y + y_step + else + sz = true + p.z = p.z + z_step + end + + if vector.distance(pos, p) > range then + return nil + end + + -- Add other positions that we're significantly off on. + -- We can just use fixed integer keys here because the + -- table will be completely cleared before we reach this + -- code block again. + local dlen = math.sqrt(dx*dx + dy*dy + dz*dz) + -- Normalized axis deltas + local dxn, dyn, dzn = dx / dlen, dy / dlen, dz / dlen + if not sx and dxn > 0.5 then + next_poses[1] = vector.new(p.x + x_step, p.y, p.z) + end + if not sy and dyn > 0.5 then + next_poses[2] = vector.new(p.x, p.y + y_step, p.z) + end + if not sz and dzn > 0.5 then + next_poses[3] = vector.new(p.x, p.y, p.z + z_step) + end + + return p + end, vector.round(pos) end diff --git a/technic/init.lua b/technic/init.lua index 70ad848..4464082 100644 --- a/technic/init.lua +++ b/technic/init.lua @@ -35,6 +35,9 @@ dofile(modpath.."/crafts.lua") -- Register functions dofile(modpath.."/register.lua") +-- Radiation +dofile(modpath.."/radiation.lua") + -- Machines dofile(modpath.."/machines/init.lua") diff --git a/technic/items.lua b/technic/items.lua index 27e05e4..a0edb96 100644 --- a/technic/items.lua +++ b/technic/items.lua @@ -194,14 +194,16 @@ for p = 0, 35 do -- a natural (0.7%-fissile) uranium block having the activity of -- 9 uranium ore blocks (due to 9 ingots per block). The group -- value is proportional to the square root of the activity, and - -- uranium ore has radioactive=1000. This yields radioactive=2065 - -- for a fully-depleted uranium block and radioactive=5286 for + -- uranium ore has radioactive=1. This yields radioactive=1.0 + -- for a fully-depleted uranium block and radioactive=2.6 for -- a 3.5%-fissile uranium block. + local radioactivity = math.floor(math.sqrt((1+5.55*p/35) * 18 / (1+5.55*7/35)) + 0.5); (ov or minetest.register_node)(block, { description = string.format(S("%.1f%%-Fissile Uranium Block"), p/10), tiles = {"technic_uranium_block.png"}, is_ground_content = true, - groups = {uranium_block=1, not_in_creative_inventory=nici, cracky=1, level=2, radioactive=math.floor(1000*math.sqrt((1+5.55*p/35) * 9 / (1+5.55*7/35)) + 0.5)}, + groups = {uranium_block=1, not_in_creative_inventory=nici, + cracky=1, level=2, radioactive=radioactivity}, sounds = default.node_sound_stone_defaults(), }); if not ov then @@ -219,3 +221,4 @@ for p = 0, 35 do }) end end + diff --git a/technic/legacy.lua b/technic/legacy.lua index 3600ec1..6a080e1 100644 --- a/technic/legacy.lua +++ b/technic/legacy.lua @@ -33,7 +33,7 @@ for old, new in pairs(technic.legacy_nodenames) do minetest.register_alias(old, new) end -for i = 0, 63 do +for i = 0, 64 do minetest.register_alias("technic:hv_cable"..i, "technic:hv_cable") minetest.register_alias("technic:mv_cable"..i, "technic:mv_cable") minetest.register_alias("technic:lv_cable"..i, "technic:lv_cable") diff --git a/technic/machines/HV/nuclear_reactor.lua b/technic/machines/HV/nuclear_reactor.lua index c7951ab..16bb928 100644 --- a/technic/machines/HV/nuclear_reactor.lua +++ b/technic/machines/HV/nuclear_reactor.lua @@ -110,18 +110,17 @@ section through the middle: CCCC CCCC CBBB BBBC - CBSS SSBC - CBSWWWSBC - CBSW#WSBC - CBSW|WSBC - CBSS|SSBC + CBLL LLBC + CBLWWWLBC + CBLW#WLBC + CBLW|WLBC + CBLL|LLBC CBBB|BBBC CCCC|CCCC - C = Concrete, B = Blast-resistant concrete, S = Stainless Steel, + C = Concrete, B = Blast-resistant concrete, L = Lead, W = water node, # = reactor core, | = HV cable -The man-hole and the HV cable are only in the middle, and the man-hole -is optional. +The man-hole is optional (but necessary for refueling). For the reactor to operate and not melt down, it insists on the inner 7x7x7 portion (from the core out to the blast-resistant concrete) @@ -139,6 +138,9 @@ be mandatory, and for historical reasons (that it predates the implementation of radiation) it needs to continue being adequate shielding of legacy reactors. If it ever ceases to be adequate shielding for new reactors, legacy ones should be grandfathered. + +For legacy reasons, if the reactor has a stainless steel layer instead +of a lead layer it will be converted to a lead layer. --]] local function reactor_structure_badness(pos) local vm = VoxelManip() @@ -149,11 +151,12 @@ local function reactor_structure_badness(pos) local area = VoxelArea:new({MinEdge=MinEdge, MaxEdge=MaxEdge}) local c_blast_concrete = minetest.get_content_id("technic:blast_resistant_concrete") - local c_stainless_steel = minetest.get_content_id("technic:stainless_steel_block") + local c_lead = minetest.get_content_id("technic:lead_block") + local c_steel = minetest.get_content_id("technic:stainless_steel_block") local c_water_source = minetest.get_content_id("default:water_source") local c_water_flowing = minetest.get_content_id("default:water_flowing") - local blastlayer, steellayer, waterlayer = 0, 0, 0 + local blast_layer, steel_layer, lead_layer, water_layer = 0, 0, 0, 0 for z = pos1.z, pos2.z do for y = pos1.y, pos2.y do @@ -163,28 +166,51 @@ local function reactor_structure_badness(pos) y == pos1.y or y == pos2.y or z == pos1.z or z == pos2.z then if cid == c_blast_concrete then - blastlayer = blastlayer + 1 + blast_layer = blast_layer + 1 end elseif x == pos1.x+1 or x == pos2.x-1 or - y == pos1.y+1 or y == pos2.y-1 or - z == pos1.z+1 or z == pos2.z-1 then - if cid == c_stainless_steel then - steellayer = steellayer + 1 + y == pos1.y+1 or y == pos2.y-1 or + z == pos1.z+1 or z == pos2.z-1 then + if cid == c_lead then + lead_layer = lead_layer + 1 + elseif cid == c_steel then + steel_layer = steel_layer + 1 end elseif x == pos1.x+2 or x == pos2.x-2 or - y == pos1.y+2 or y == pos2.y-2 or - z == pos1.z+2 or z == pos2.z-2 then + y == pos1.y+2 or y == pos2.y-2 or + z == pos1.z+2 or z == pos2.z-2 then if cid == c_water_source or cid == c_water_flowing then - waterlayer = waterlayer + 1 + water_layer = water_layer + 1 end end end end end - if waterlayer > 25 then waterlayer = 25 end - if steellayer > 96 then steellayer = 96 end - if blastlayer > 216 then blastlayer = 216 end - return (25 - waterlayer) + (96 - steellayer) + (216 - blastlayer) + + if steel_layer >= 96 then + for z = pos1.z+1, pos2.z-1 do + for y = pos1.y+1, pos2.y-1 do + for x = pos1.x+1, pos2.x-1 do + local vi = area:index(x, y, z) + if x == pos1.x+1 or x == pos2.x-1 or + y == pos1.y+1 or y == pos2.y-1 or + z == pos1.z+1 or z == pos2.z-1 then + if data[vi] == c_steel then + data[vi] = c_lead + end + end + end + end + end + vm:set_data(data) + vm:write_to_map() + lead_layer = steel_layer + end + + if water_layer > 25 then water_layer = 25 end + if lead_layer > 96 then lead_layer = 96 end + if blast_layer > 216 then blast_layer = 216 end + return (25 - water_layer) + (96 - lead_layer) + (216 - blast_layer) end @@ -292,7 +318,7 @@ minetest.register_node("technic:hv_nuclear_reactor_core", { minetest.register_node("technic:hv_nuclear_reactor_core_active", { tiles = {"technic_hv_nuclear_reactor_core.png"}, groups = {cracky=1, technic_machine=1, technic_hv=1, - radioactive=11000, not_in_creative_inventory=1}, + radioactive=4, not_in_creative_inventory=1}, legacy_facedir_simple = true, sounds = default.node_sound_wood_defaults(), drop = "technic:hv_nuclear_reactor_core", @@ -339,399 +365,3 @@ minetest.register_node("technic:hv_nuclear_reactor_core_active", { technic.register_machine("HV", "technic:hv_nuclear_reactor_core", technic.producer) technic.register_machine("HV", "technic:hv_nuclear_reactor_core_active", technic.producer) ---[[ -Radioactivity - -Radiation resistance represents the extent to which a material -attenuates radiation passing through it; i.e., how good a radiation -shield it is. This is identified per node type. For materials that -exist in real life, the radiation resistance value that this system -uses for a node type consisting of a solid cube of that material is the -(approximate) number of halvings of ionising radiation that is achieved -by a meter of the material in real life. This is approximately -proportional to density, which provides a good way to estimate it. -Homogeneous mixtures of materials have radiation resistance computed -by a simple weighted mean. Note that the amount of attenuation that -a material achieves in-game is not required to be (and is not) the -same as the attenuation achieved in real life. - -Radiation resistance for a node type may be specified in the node -definition, under the key "radiation_resistance". As an interim -measure, until node definitions widely include this, this code -knows a bunch of values for particular node types in several mods, -and values for groups of node types. The node definition takes -precedence if it specifies a value. Nodes for which no value at -all is known are taken to provide no radiation resistance at all; -this is appropriate for the majority of node types. Only node types -consisting of a fairly homogeneous mass of material should report -non-zero radiation resistance; anything with non-uniform geometry -or complex internal structure should show no radiation resistance. -Fractional resistance values are permitted. ---]] - -local default_radiation_resistance_per_node = { - ["default:brick"] = 13, - ["default:bronzeblock"] = 45, - ["default:clay"] = 15, - ["default:coalblock"] = 9.6, - ["default:cobble"] = 15, - ["default:copperblock"] = 46, - ["default:desert_cobble"] = 15, - ["default:desert_sand"] = 10, - ["default:desert_stone"] = 17, - ["default:desert_stonebrick"] = 17, - ["default:diamondblock"] = 24, - ["default:dirt"] = 8.2, - ["default:dirt_with_grass"] = 8.2, - ["default:dirt_with_grass_footsteps"] = 8.2, - ["default:dirt_with_snow"] = 8.2, - ["default:glass"] = 17, - ["default:goldblock"] = 170, - ["default:gravel"] = 10, - ["default:ice"] = 5.6, - ["default:lava_flowing"] = 8.5, - ["default:lava_source"] = 17, - ["default:mese"] = 21, - ["default:mossycobble"] = 15, - ["default:nyancat"] = 1000, - ["default:nyancat_rainbow"] = 1000, - ["default:obsidian"] = 18, - ["default:obsidian_glass"] = 18, - ["default:sand"] = 10, - ["default:sandstone"] = 15, - ["default:sandstonebrick"] = 15, - ["default:snowblock"] = 1.7, - ["default:steelblock"] = 40, - ["default:stone"] = 17, - ["default:stone_with_coal"] = 16, - ["default:stone_with_copper"] = 20, - ["default:stone_with_diamond"] = 18, - ["default:stone_with_gold"] = 34, - ["default:stone_with_iron"] = 20, - ["default:stone_with_mese"] = 17, - ["default:stonebrick"] = 17, - ["default:water_flowing"] = 2.8, - ["default:water_source"] = 5.6, - ["farming:desert_sand_soil"] = 10, - ["farming:desert_sand_soil_wet"] = 10, - ["farming:soil"] = 8.2, - ["farming:soil_wet"] = 8.2, - ["glooptest:akalin_crystal_glass"] = 21, - ["glooptest:akalinblock"] = 40, - ["glooptest:alatro_crystal_glass"] = 21, - ["glooptest:alatroblock"] = 40, - ["glooptest:amethystblock"] = 18, - ["glooptest:arol_crystal_glass"] = 21, - ["glooptest:crystal_glass"] = 21, - ["glooptest:emeraldblock"] = 19, - ["glooptest:heavy_crystal_glass"] = 21, - ["glooptest:mineral_akalin"] = 20, - ["glooptest:mineral_alatro"] = 20, - ["glooptest:mineral_amethyst"] = 17, - ["glooptest:mineral_arol"] = 20, - ["glooptest:mineral_desert_coal"] = 16, - ["glooptest:mineral_desert_iron"] = 20, - ["glooptest:mineral_emerald"] = 17, - ["glooptest:mineral_kalite"] = 20, - ["glooptest:mineral_ruby"] = 18, - ["glooptest:mineral_sapphire"] = 18, - ["glooptest:mineral_talinite"] = 20, - ["glooptest:mineral_topaz"] = 18, - ["glooptest:reinforced_crystal_glass"] = 21, - ["glooptest:rubyblock"] = 27, - ["glooptest:sapphireblock"] = 27, - ["glooptest:talinite_crystal_glass"] = 21, - ["glooptest:taliniteblock"] = 40, - ["glooptest:topazblock"] = 24, - ["mesecons_extrawires:mese_powered"] = 21, - ["moreblocks:cactus_brick"] = 13, - ["moreblocks:cactus_checker"] = 8.5, - ["moreblocks:circle_stone_bricks"] = 17, - ["moreblocks:clean_glass"] = 17, - ["moreblocks:coal_checker"] = 9.0, - ["moreblocks:coal_glass"] = 17, - ["moreblocks:coal_stone"] = 17, - ["moreblocks:coal_stone_bricks"] = 17, - ["moreblocks:glow_glass"] = 17, - ["moreblocks:grey_bricks"] = 15, - ["moreblocks:iron_checker"] = 11, - ["moreblocks:iron_glass"] = 17, - ["moreblocks:iron_stone"] = 17, - ["moreblocks:iron_stone_bricks"] = 17, - ["moreblocks:plankstone"] = 9.3, - ["moreblocks:split_stone_tile"] = 15, - ["moreblocks:split_stone_tile_alt"] = 15, - ["moreblocks:stone_tile"] = 15, - ["moreblocks:super_glow_glass"] = 17, - ["moreblocks:tar"] = 7.0, - ["moreblocks:wood_tile"] = 1.7, - ["moreblocks:wood_tile_center"] = 1.7, - ["moreblocks:wood_tile_down"] = 1.7, - ["moreblocks:wood_tile_flipped"] = 1.7, - ["moreblocks:wood_tile_full"] = 1.7, - ["moreblocks:wood_tile_left"] = 1.7, - ["moreblocks:wood_tile_right"] = 1.7, - ["moreblocks:wood_tile_up"] = 1.7, - ["moreores:mineral_mithril"] = 18, - ["moreores:mineral_silver"] = 21, - ["moreores:mineral_tin"] = 19, - ["moreores:mithril_block"] = 26, - ["moreores:silver_block"] = 53, - ["moreores:tin_block"] = 37, - ["snow:snow_brick"] = 2.8, - ["technic: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 default_radiation_resistance_per_group = { - concrete = 16, - tree = 3.4, - uranium_block = 500, - wood = 1.7, -} -local cache_radiation_resistance = {} -local function node_radiation_resistance(node_name) - local eff = cache_radiation_resistance[node_name] - if eff then return eff end - local def = minetest.registered_nodes[node_name] - eff = def and def.radiation_resistance or - default_radiation_resistance_per_node[node_name] - if def and not eff then - for g, v in pairs(def.groups) do - if v > 0 and default_radiation_resistance_per_group[g] then - eff = default_radiation_resistance_per_group[g] - break - end - end - end - if not eff then eff = 0 end - cache_radiation_resistance[node_name] = eff - return eff -end - ---[[ -Radioactive nodes cause damage to nearby players. The damage -effect depends on the intrinsic strength of the radiation source, -the distance between the source and the player, and the shielding -effect of the intervening material. These determine a rate of damage; -total damage caused is the integral of this over time. - -In the absence of effective shielding, for a specific source the -damage rate varies realistically in inverse proportion to the square -of the distance. (Distance is measured to the player's abdomen, -not to the nominal player position which corresponds to the foot.) -However, if the player is inside a non-walkable (liquid or gaseous) -radioactive node, the nominal distance could go to zero, yielding -infinite damage. In that case, the player's body is displacing the -radioactive material, so the effective distance should remain non-zero. -We therefore apply a lower distance bound of sqrt(0.75), which is -the maximum distance one can get from the node center within the node. - -A radioactive node is identified by being in the "radioactive" group, -and the group value signifies the strength of the radiation source. -The group value is 1000 times the distance from a node at which -an unshielded player will be damaged by 0.25 HP/s. Or, equivalently, -it is 2000 times the square root of the damage rate in HP/s that an -unshielded player 1 node away will take. - -Shielding is assessed by adding the shielding values of all nodes -between the source node and the player, ignoring the source node itself. -As in reality, shielding causes exponential attenuation of radiation. -However, the effect is scaled down relative to real life. A node with -radiation resistance value R yields attenuation of sqrt(R) * 0.1 nepers. -(In real life it would be about R * 0.69 nepers, by the definition -of the radiation resistance values.) The sqrt part of this formula -scales down the differences between shielding types, reflecting the -game's simplification of making expensive materials such as gold -readily available in cubes. The multiplicative factor in the -formula scales down the difference between shielded and unshielded -safe distances, avoiding the latter becoming impractically large. - -Damage is processed at rates down to 0.25 HP/s, which in the absence of -shielding is attained at the distance specified by the "radioactive" -group value. Computed damage rates below 0.25 HP/s result in no -damage at all to the player. This gives the player an opportunity -to be safe, and limits the range at which source/player interactions -need to be considered. ---]] -local abdomen_offset = vector.new(0, 1, 0) -local abdomen_offset_length = vector.length(abdomen_offset) -local cache_scaled_shielding = {} - -local function dmg_player(pos, o, strength) - local pl_pos = vector.add(o:getpos(), abdomen_offset) - local shielding = 0 - local dist = vector.distance(pos, pl_pos) - for ray_pos in technic.trace_node_ray(pos, - vector.direction(pos, pl_pos), dist) do - if not vector.equals(ray_pos, pos) then - local shield_name = minetest.get_node(ray_pos).name - local shield_val = cache_scaled_shielding[sname] - if not shield_val then - shield_val = math.sqrt(node_radiation_resistance(shield_name)) * 0.025 - cache_scaled_shielding[shield_name] = shield_val - end - shielding = shielding + shield_val - end - end - local dmg = (0.25e-6 * strength * strength) / - (math.max(0.75, dist * dist) * math.exp(shielding)) - if dmg >= 0.25 then - local dmg_int = math.floor(dmg) - -- The closer you are to getting one more damage point, - -- the more likely it will be added. - if math.random() < dmg - dmg_int then - dmg_int = dmg_int + 1 - end - if dmg_int > 0 then - o:set_hp(math.max(o:get_hp() - dmg_int, 0)) - end - end -end - -local function dmg_abm(pos, node) - local strength = minetest.get_item_group(node.name, "radioactive") - for _, o in pairs(minetest.get_objects_inside_radius(pos, - strength * 0.001 + abdomen_offset_length)) do - if o:is_player() then - dmg_player(pos, o, strength) - end - end -end - - -if minetest.setting_getbool("enable_damage") then - minetest.register_abm({ - nodenames = {"group:radioactive"}, - interval = 1, - chance = 1, - action = dmg_abm, - }) -end - --- Radioactive materials that can result from destroying a reactor -local griefing = technic.config:get_bool("enable_corium_griefing") - -for _, state in pairs({"flowing", "source"}) do - minetest.register_node("technic:corium_"..state, { - description = S(state == "source" and "Corium Source" or "Flowing Corium"), - drawtype = (state == "source" and "liquid" or "flowingliquid"), - [state == "source" and "tiles" or "special_tiles"] = {{ - name = "technic_corium_"..state.."_animated.png", - animation = { - type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, - length = 3.0, - }, - }}, - paramtype = "light", - paramtype2 = (state == "flowing" and "flowingliquid" or nil), - light_source = (state == "source" and 8 or 5), - walkable = false, - pointable = false, - diggable = false, - buildable_to = true, - drop = "", - drowning = 1, - liquidtype = state, - liquid_alternative_flowing = "technic:corium_flowing", - liquid_alternative_source = "technic:corium_source", - liquid_viscosity = LAVA_VISC, - liquid_renewable = false, - damage_per_second = 6, - post_effect_color = {a=192, r=80, g=160, b=80}, - groups = { - liquid = 2, - hot = 3, - igniter = (griefing and 1 or 0), - radioactive = (state == "source" and 32000 or 16000), - not_in_creative_inventory = (state == "flowing" and 1 or nil), - }, - }) -end - -if rawget(_G, "bucket") and bucket.register_liquid then - bucket.register_liquid( - "technic:corium_source", - "technic:corium_flowing", - "technic:bucket_corium", - "technic_bucket_corium.png", - "Corium Bucket" - ) -end - -minetest.register_node("technic:chernobylite_block", { - description = S("Chernobylite Block"), - tiles = {"technic_chernobylite_block.png"}, - is_ground_content = true, - groups = {cracky=1, radioactive=5000, level=2}, - sounds = default.node_sound_stone_defaults(), - light_source = 2, -}) - -minetest.register_abm({ - nodenames = {"group:water"}, - neighbors = {"technic:corium_source"}, - interval = 1, - chance = 1, - action = function(pos, node) - minetest.remove_node(pos) - end, -}) - -minetest.register_abm({ - nodenames = {"technic:corium_flowing"}, - neighbors = {"group:water"}, - interval = 1, - chance = 1, - action = function(pos, node) - minetest.set_node(pos, {name="technic:chernobylite_block"}) - end, -}) - -minetest.register_abm({ - nodenames = {"technic:corium_flowing"}, - interval = 5, - chance = (griefing and 10 or 1), - action = function(pos, node) - minetest.set_node(pos, {name="technic:chernobylite_block"}) - end, -}) - -if griefing then - minetest.register_abm({ - nodenames = {"technic:corium_source", "technic:corium_flowing"}, - interval = 4, - chance = 4, - action = function(pos, node) - for _, offset in ipairs({ - vector.new(1,0,0), - vector.new(-1,0,0), - vector.new(0,0,1), - vector.new(0,0,-1), - vector.new(0,-1,0), - }) do - if math.random(8) == 1 then - minetest.dig_node(vector.add(pos, offset)) - end - end - end, - }) -end - diff --git a/technic/machines/LV/water_mill.lua b/technic/machines/LV/water_mill.lua index c853310..acb778c 100644 --- a/technic/machines/LV/water_mill.lua +++ b/technic/machines/LV/water_mill.lua @@ -17,19 +17,21 @@ minetest.register_craft({ local function check_node_around_mill(pos) local node = minetest.get_node(pos) - if node.name == "default:water_flowing" or - node.name == "default:water_source" then - return true + if node.name == "default:water_flowing" + or node.name == "default:river_water_flowing" then + return node.param2 -- returns approx. water flow, if any end return false end local run = function(pos, node) local meta = minetest.get_meta(pos) - local water_nodes = 0 + local water_flow = 0 local lava_nodes = 0 local production_level = 0 local eu_supply = 0 + local max_output = 35 * 45 -- four param2's at 15 makes 60, cap it lower for "overload protection" + -- (plus we want the gen to report 100% if three sides have full flow) local positions = { {x=pos.x+1, y=pos.y, z=pos.z}, @@ -41,12 +43,12 @@ local run = function(pos, node) for _, p in pairs(positions) do local check = check_node_around_mill(p) if check then - water_nodes = water_nodes + 1 + water_flow = water_flow + check end end - production_level = 25 * water_nodes - eu_supply = 30 * water_nodes + eu_supply = math.min(35 * water_flow, max_output) + production_level = math.floor(100 * eu_supply / max_output) if production_level > 0 then meta:set_int("LV_EU_supply", eu_supply) diff --git a/technic/machines/MV/wind_mill.lua b/technic/machines/MV/wind_mill.lua index 1377c67..28a075d 100644 --- a/technic/machines/MV/wind_mill.lua +++ b/technic/machines/MV/wind_mill.lua @@ -33,8 +33,15 @@ local function check_wind_mill(pos) if pos.y < 30 then return false end + pos = {x=pos.x, y=pos.y, z=pos.z} for i = 1, 20 do - local node = minetest.get_node({x=pos.x, y=pos.y-i, z=pos.z}) + pos.y = pos.y - 1 + local node = minetest.get_node_or_nil(pos) + if not node then + -- we reached CONTENT_IGNORE, we can assume, that nothing changed + -- as the user will have to load the block to change it + return + end if node.name ~= "technic:wind_mill_frame" then return false end @@ -45,17 +52,17 @@ end local run = function(pos, node) local meta = minetest.get_meta(pos) local machine_name = S("Wind %s Generator"):format("MV") - local power = math.min(pos.y * 100, 5000) - if not check_wind_mill(pos) then + local check = check_wind_mill(pos) + if check == false then meta:set_int("MV_EU_supply", 0) meta:set_string("infotext", S("%s Improperly Placed"):format(machine_name)) - return - else + elseif check == true then + local power = math.min(pos.y * 100, 5000) meta:set_int("MV_EU_supply", power) + meta:set_string("infotext", S("@1 (@2 EU)", machine_name, technic.pretty_num(power))) end - - meta:set_string("infotext", S("@1 (@2 EU)", machine_name, technic.pretty_num(power))) + -- check == nil: assume nothing has changed end minetest.register_node("technic:wind_mill", { diff --git a/technic/machines/other/frames.lua b/technic/machines/other/frames.lua index b3f39b9..2d630a2 100644 --- a/technic/machines/other/frames.lua +++ b/technic/machines/other/frames.lua @@ -320,7 +320,7 @@ local nodeboxes= { else --local pointed_thing = {type = "node", under = pos} if pointed_thing then - minetest.item_place_node(itemstack, placer, pointed_thing) + return minetest.item_place_node(itemstack, placer, pointed_thing) end end end, diff --git a/technic/machines/register/cables.lua b/technic/machines/register/cables.lua index 28984c0..a7e72a3 100644 --- a/technic/machines/register/cables.lua +++ b/technic/machines/register/cables.lua @@ -11,8 +11,19 @@ function technic.get_cable_tier(name) return cable_tier[name] end -local function clear_networks() - technic.networks = {} +local function clear_networks(pos) + local positions = { + {x=pos.x+1, y=pos.y, z=pos.z}, + {x=pos.x-1, y=pos.y, z=pos.z}, + {x=pos.x, y=pos.y+1, z=pos.z}, + {x=pos.x, y=pos.y-1, z=pos.z}, + {x=pos.x, y=pos.y, z=pos.z+1}, + {x=pos.x, y=pos.y, z=pos.z-1}} + for _,connected_pos in pairs(positions) do + if technic.cables[minetest.hash_node_position(connected_pos)] then + technic.networks[technic.cables[minetest.hash_node_position(connected_pos)]] = nil + end + end end function technic.register_cable(tier, size) @@ -55,7 +66,7 @@ end local function clear_nets_if_machine(pos, node) for tier, machine_list in pairs(technic.machines) do if machine_list[node.name] ~= nil then - return clear_networks() + return clear_networks(pos) end end end diff --git a/technic/machines/register/centrifuge_recipes.lua b/technic/machines/register/centrifuge_recipes.lua index 05642f5..b4db47c 100644 --- a/technic/machines/register/centrifuge_recipes.lua +++ b/technic/machines/register/centrifuge_recipes.lua @@ -14,6 +14,7 @@ local recipes = { { "technic:bronze_dust 4", "technic:copper_dust 3", "technic:tin_dust" }, { "technic:stainless_steel_dust 4", "technic:wrought_iron_dust 3", "technic:chromium_dust" }, { "technic:brass_dust 3", "technic:copper_dust 2", "technic:zinc_dust" }, + { "default:dirt 4", "default:sand", "default:gravel", "default:clay_lump 2" }, } local function uranium_dust(p) @@ -34,5 +35,5 @@ if minetest.get_modpath("farming") then end for _, data in pairs(recipes) do - technic.register_separating_recipe({ input = { data[1] }, output = { data[2], data[3] } }) + technic.register_separating_recipe({ input = { data[1] }, output = { data[2], data[3], data[4] } }) end diff --git a/technic/machines/register/common.lua b/technic/machines/register/common.lua index ce0eee6..dfa2948 100644 --- a/technic/machines/register/common.lua +++ b/technic/machines/register/common.lua @@ -157,13 +157,13 @@ function technic.machine_after_dig_node(pos, oldnode, oldmetadata, player) if oldmetadata.inventory.upgrade1 and oldmetadata.inventory.upgrade1[1] then local stack = ItemStack(oldmetadata.inventory.upgrade1[1]) if not stack:is_empty() then - minetest.item_drop(stack, "", pos) + minetest.add_item(pos, stack) end end if oldmetadata.inventory.upgrade2 and oldmetadata.inventory.upgrade2[1] then local stack = ItemStack(oldmetadata.inventory.upgrade2[1]) if not stack:is_empty() then - minetest.item_drop(stack, "", pos) + minetest.add_item(pos, stack) end end end diff --git a/technic/machines/register/grinder_recipes.lua b/technic/machines/register/grinder_recipes.lua index 87c6ade..7eaa7d4 100644 --- a/technic/machines/register/grinder_recipes.lua +++ b/technic/machines/register/grinder_recipes.lua @@ -20,11 +20,12 @@ local recipes = { {"technic:zinc_lump", "technic:zinc_dust 2"}, {"technic:lead_lump", "technic:lead_dust 2"}, {"technic:sulfur_lump", "technic:sulfur_dust 2"}, + {"default:stone", "technic:stone_dust"}, + {"default:sand", "technic:stone_dust"}, -- Other {"default:cobble", "default:gravel"}, - {"default:gravel", "default:dirt"}, - {"default:stone", "default:sand"}, + {"default:gravel", "default:sand"}, {"default:sandstone", "default:sand 2"}, -- reverse recipe can be found in the compressor } @@ -103,6 +104,7 @@ register_dust("Sulfur", nil) register_dust("Tin", "moreores:tin_ingot") register_dust("Wrought Iron", "technic:wrought_iron_ingot") register_dust("Zinc", "technic:zinc_ingot") +register_dust("Stone", "default:stone") if minetest.get_modpath("gloopores") or minetest.get_modpath("glooptest") then register_dust("Akalin", "glooptest:akalin_ingot") register_dust("Alatro", "glooptest:alatro_ingot") diff --git a/technic/machines/supply_converter.lua b/technic/machines/supply_converter.lua index 32597de..a88651b 100644 --- a/technic/machines/supply_converter.lua +++ b/technic/machines/supply_converter.lua @@ -59,6 +59,7 @@ minetest.register_node("technic:supply_converter", { meta:set_float("active", false) end, technic_run = run, + technic_on_disable = run, }) minetest.register_craft({ diff --git a/technic/machines/switching_station.lua b/technic/machines/switching_station.lua index f7ec0b6..2051acf 100644 --- a/technic/machines/switching_station.lua +++ b/technic/machines/switching_station.lua @@ -32,6 +32,7 @@ -- This way the supplies are separated per network. technic.networks = {} +technic.cables = {} local S = technic.getter @@ -64,7 +65,8 @@ minetest.register_node("technic:switching_station",{ -------------------------------------------------- -- Add a wire node to the LV/MV/HV network -local add_new_cable_node = function(nodes, pos) +local add_new_cable_node = function(nodes, pos, network_id) + technic.cables[minetest.hash_node_position(pos)] = network_id -- Ignore if the node has already been added for i = 1, #nodes do if pos.x == nodes[i].x and @@ -78,31 +80,31 @@ local add_new_cable_node = function(nodes, pos) end -- Generic function to add found connected nodes to the right classification array -local check_node_subp = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, pos, machines, tier, sw_pos, from_below) +local check_node_subp = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, pos, machines, tier, sw_pos, from_below, network_id) technic.get_or_load_node(pos) local meta = minetest.get_meta(pos) local name = minetest.get_node(pos).name if technic.is_tier_cable(name, tier) then - add_new_cable_node(all_nodes, pos) + add_new_cable_node(all_nodes, pos,network_id) elseif machines[name] then --dprint(name.." is a "..machines[name]) if machines[name] == technic.producer then - add_new_cable_node(PR_nodes, pos) + add_new_cable_node(PR_nodes, pos, network_id) elseif machines[name] == technic.receiver then - add_new_cable_node(RE_nodes, pos) + add_new_cable_node(RE_nodes, pos, network_id) elseif machines[name] == technic.producer_receiver then - add_new_cable_node(PR_nodes, pos) - add_new_cable_node(RE_nodes, pos) + add_new_cable_node(PR_nodes, pos, network_id) + add_new_cable_node(RE_nodes, pos, network_id) elseif machines[name] == "SPECIAL" and (pos.x ~= sw_pos.x or pos.y ~= sw_pos.y or pos.z ~= sw_pos.z) and from_below then -- Another switching station -> disable it - add_new_cable_node(SP_nodes, pos) + add_new_cable_node(SP_nodes, pos, network_id) meta:set_int("active", 0) meta:set_string("active_pos", minetest.serialize(sw_pos)) elseif machines[name] == technic.battery then - add_new_cable_node(BA_nodes, pos) + add_new_cable_node(BA_nodes, pos, network_id) end meta:set_int(tier.."_EU_timeout", 2) -- Touch node @@ -110,7 +112,7 @@ local check_node_subp = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nod end -- Traverse a network given a list of machines and a cable type name -local traverse_network = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, i, machines, tier, sw_pos) +local traverse_network = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, i, machines, tier, sw_pos, network_id) local pos = all_nodes[i] local positions = { {x=pos.x+1, y=pos.y, z=pos.z}, @@ -121,7 +123,7 @@ local traverse_network = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_no {x=pos.x, y=pos.y, z=pos.z-1}} --print("ON") for i, cur_pos in pairs(positions) do - check_node_subp(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, cur_pos, machines, tier, sw_pos, i == 3) + check_node_subp(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, cur_pos, machines, tier, sw_pos, i == 3, network_id) end end @@ -153,7 +155,7 @@ local get_network = function(sw_pos, pos1, tier) local all_nodes = {pos1} repeat traverse_network(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, - i, technic.machines[tier], tier, sw_pos) + i, technic.machines[tier], tier, sw_pos, minetest.hash_node_position(pos1)) i = i + 1 until all_nodes[i] == nil technic.networks[minetest.hash_node_position(pos1)] = {tier = tier, PR_nodes = PR_nodes, diff --git a/technic/radiation.lua b/technic/radiation.lua new file mode 100644 index 0000000..13936f9 --- /dev/null +++ b/technic/radiation.lua @@ -0,0 +1,483 @@ +--[[ +Radioactivity + +Radiation resistance represents the extent to which a material +attenuates radiation passing through it; i.e., how good a radiation +shield it is. This is identified per node type. For materials that +exist in real life, the radiation resistance value that this system +uses for a node type consisting of a solid cube of that material is the +(approximate) number of halvings of ionising radiation that is achieved +by a meter of the material in real life. This is approximately +proportional to density, which provides a good way to estimate it. +Homogeneous mixtures of materials have radiation resistance computed +by a simple weighted mean. Note that the amount of attenuation that +a material achieves in-game is not required to be (and is not) the +same as the attenuation achieved in real life. + +Radiation resistance for a node type may be specified in the node +definition, under the key "radiation_resistance". As an interim +measure, until node definitions widely include this, this code +knows a bunch of values for particular node types in several mods, +and values for groups of node types. The node definition takes +precedence if it specifies a value. Nodes for which no value at +all is known are taken to provide no radiation resistance at all; +this is appropriate for the majority of node types. Only node types +consisting of a fairly homogeneous mass of material should report +non-zero radiation resistance; anything with non-uniform geometry +or complex internal structure should show no radiation resistance. +Fractional resistance values are permitted. +--]] + +local S = technic.getter + +local rad_resistance_node = { + ["default:brick"] = 13, + ["default:bronzeblock"] = 45, + ["default:clay"] = 15, + ["default:coalblock"] = 9.6, + ["default:cobble"] = 15, + ["default:copperblock"] = 46, + ["default:desert_cobble"] = 15, + ["default:desert_sand"] = 10, + ["default:desert_stone"] = 17, + ["default:desert_stonebrick"] = 17, + ["default:diamondblock"] = 24, + ["default:dirt"] = 8.2, + ["default:dirt_with_grass"] = 8.2, + ["default:dirt_with_grass_footsteps"] = 8.2, + ["default:dirt_with_snow"] = 8.2, + ["default:glass"] = 17, + ["default:goldblock"] = 170, + ["default:gravel"] = 10, + ["default:ice"] = 5.6, + ["default:lava_flowing"] = 8.5, + ["default:lava_source"] = 17, + ["default:mese"] = 21, + ["default:mossycobble"] = 15, + ["default:nyancat"] = 1000, + ["default:nyancat_rainbow"] = 1000, + ["default:obsidian"] = 18, + ["default:obsidian_glass"] = 18, + ["default:sand"] = 10, + ["default:sandstone"] = 15, + ["default:sandstonebrick"] = 15, + ["default:snowblock"] = 1.7, + ["default:steelblock"] = 40, + ["default:stone"] = 17, + ["default:stone_with_coal"] = 16, + ["default:stone_with_copper"] = 20, + ["default:stone_with_diamond"] = 18, + ["default:stone_with_gold"] = 34, + ["default:stone_with_iron"] = 20, + ["default:stone_with_mese"] = 17, + ["default:stonebrick"] = 17, + ["default:water_flowing"] = 2.8, + ["default:water_source"] = 5.6, + ["farming:desert_sand_soil"] = 10, + ["farming:desert_sand_soil_wet"] = 10, + ["farming:soil"] = 8.2, + ["farming:soil_wet"] = 8.2, + ["glooptest:akalin_crystal_glass"] = 21, + ["glooptest:akalinblock"] = 40, + ["glooptest:alatro_crystal_glass"] = 21, + ["glooptest:alatroblock"] = 40, + ["glooptest:amethystblock"] = 18, + ["glooptest:arol_crystal_glass"] = 21, + ["glooptest:crystal_glass"] = 21, + ["glooptest:emeraldblock"] = 19, + ["glooptest:heavy_crystal_glass"] = 21, + ["glooptest:mineral_akalin"] = 20, + ["glooptest:mineral_alatro"] = 20, + ["glooptest:mineral_amethyst"] = 17, + ["glooptest:mineral_arol"] = 20, + ["glooptest:mineral_desert_coal"] = 16, + ["glooptest:mineral_desert_iron"] = 20, + ["glooptest:mineral_emerald"] = 17, + ["glooptest:mineral_kalite"] = 20, + ["glooptest:mineral_ruby"] = 18, + ["glooptest:mineral_sapphire"] = 18, + ["glooptest:mineral_talinite"] = 20, + ["glooptest:mineral_topaz"] = 18, + ["glooptest:reinforced_crystal_glass"] = 21, + ["glooptest:rubyblock"] = 27, + ["glooptest:sapphireblock"] = 27, + ["glooptest:talinite_crystal_glass"] = 21, + ["glooptest:taliniteblock"] = 40, + ["glooptest:topazblock"] = 24, + ["mesecons_extrawires:mese_powered"] = 21, + ["moreblocks:cactus_brick"] = 13, + ["moreblocks:cactus_checker"] = 8.5, + ["moreblocks:circle_stone_bricks"] = 17, + ["moreblocks:clean_glass"] = 17, + ["moreblocks:coal_checker"] = 9.0, + ["moreblocks:coal_glass"] = 17, + ["moreblocks:coal_stone"] = 17, + ["moreblocks:coal_stone_bricks"] = 17, + ["moreblocks:glow_glass"] = 17, + ["moreblocks:grey_bricks"] = 15, + ["moreblocks:iron_checker"] = 11, + ["moreblocks:iron_glass"] = 17, + ["moreblocks:iron_stone"] = 17, + ["moreblocks:iron_stone_bricks"] = 17, + ["moreblocks:plankstone"] = 9.3, + ["moreblocks:split_stone_tile"] = 15, + ["moreblocks:split_stone_tile_alt"] = 15, + ["moreblocks:stone_tile"] = 15, + ["moreblocks:super_glow_glass"] = 17, + ["moreblocks:tar"] = 7.0, + ["moreblocks:wood_tile"] = 1.7, + ["moreblocks:wood_tile_center"] = 1.7, + ["moreblocks:wood_tile_down"] = 1.7, + ["moreblocks:wood_tile_flipped"] = 1.7, + ["moreblocks:wood_tile_full"] = 1.7, + ["moreblocks:wood_tile_left"] = 1.7, + ["moreblocks:wood_tile_right"] = 1.7, + ["moreblocks:wood_tile_up"] = 1.7, + ["moreores:mineral_mithril"] = 18, + ["moreores:mineral_silver"] = 21, + ["moreores:mineral_tin"] = 19, + ["moreores:mithril_block"] = 26, + ["moreores:silver_block"] = 53, + ["moreores:tin_block"] = 37, + ["snow:snow_brick"] = 2.8, + ["technic: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] + end + end + end + resistance = math.sqrt(resistance) + cache_radiation_resistance[node_name] = resistance + return resistance +end + + +--[[ +Radioactive nodes cause damage to nearby players. The damage +effect depends on the intrinsic strength of the radiation source, +the distance between the source and the player, and the shielding +effect of the intervening material. These determine a rate of damage; +total damage caused is the integral of this over time. + +In the absence of effective shielding, for a specific source the +damage rate varies realistically in inverse proportion to the square +of the distance. (Distance is measured to the player's abdomen, +not to the nominal player position which corresponds to the foot.) +However, if the player is inside a non-walkable (liquid or gaseous) +radioactive node, the nominal distance could go to zero, yielding +infinite damage. In that case, the player's body is displacing the +radioactive material, so the effective distance should remain non-zero. +We therefore apply a lower distance bound of sqrt(0.75), which is +the maximum distance one can get from the node center within the node. + +A radioactive node is identified by being in the "radioactive" group, +and the group value signifies the strength of the radiation source. +The group value is the distance from a node at which an unshielded +player will be damaged by 1 HP/s. Or, equivalently, it is the square +root of the damage rate in HP/s that an unshielded player one node +away will take. + +Shielding is assessed by adding the shielding values of all nodes +between the source node and the player, ignoring the source node itself. +As in reality, shielding causes exponential attenuation of radiation. +However, the effect is scaled down relative to real life. A node with +radiation resistance value R yields attenuation of sqrt(R) * 0.1 nepers. +(In real life it would be about R * 0.69 nepers, by the definition +of the radiation resistance values.) The sqrt part of this formula +scales down the differences between shielding types, reflecting the +game's simplification of making expensive materials such as gold +readily available in cubes. The multiplicative factor in the +formula scales down the difference between shielded and unshielded +safe distances, avoiding the latter becoming impractically large. + +Damage is processed at rates down to 0.2 HP/s, which in the absence of +shielding is attained at the distance specified by the "radioactive" +group value. Computed damage rates below 0.2 HP/s result in no +damage at all to the player. This gives the player an opportunity +to be safe, and limits the range at which source/player interactions +need to be considered. +--]] +local abdomen_offset = 1 +local cache_scaled_shielding = {} +local rad_dmg_cutoff = 0.2 +local radiated_players = {} + +local armor_enabled = technic.config:get_bool("enable_radiation_protection") +local entity_damage = technic.config:get_bool("enable_entity_radiation_damage") +local longterm_damage = technic.config:get_bool("enable_longterm_radiation_damage") + +local function apply_fractional_damage(o, dmg) + local dmg_int = math.floor(dmg) + -- The closer you are to getting one more damage point, + -- the more likely it will be added. + if math.random() < dmg - dmg_int then + dmg_int = dmg_int + 1 + end + if dmg_int > 0 then + local new_hp = math.max(o:get_hp() - dmg_int, 0) + o:set_hp(new_hp) + return new_hp == 0 + end + return false +end + +local function calculate_base_damage(node_pos, object_pos, strength) + local shielding = 0 + local dist = vector.distance(node_pos, object_pos) + + for ray_pos in technic.trace_node_ray(node_pos, + vector.direction(node_pos, object_pos), dist) do + local shield_name = minetest.get_node(ray_pos).name + shielding = shielding + node_radiation_resistance(shield_name) * 0.025 + end + + local dmg = (strength * strength) / + (math.max(0.75, dist * dist) * math.exp(shielding)) + + if dmg < rad_dmg_cutoff then return end + return dmg +end + +local function calculate_damage_multiplier(object) + local ag = object.get_armor_groups and object:get_armor_groups() + if not ag then + return 0 + end + if ag.immortal then + return 0 + end + if ag.radiation then + return 0.01 * ag.radiation + end + if ag.fleshy then + return math.sqrt(0.01 * ag.fleshy) + end + return 0 +end + +local function calculate_object_center(object) + if object:is_player() then + return {x=0, y=abdomen_offset, z=0} + end + return {x=0, y=0, z=0} +end + +local function dmg_object(pos, object, strength) + local obj_pos = vector.add(object:getpos(), calculate_object_center(object)) + local mul + if armor_enabled or entity_damage then + -- we need to check may the object be damaged even if armor is disabled + mul = calculate_damage_multiplier(object) + if mul == 0 then + return + end + end + local dmg = calculate_base_damage(pos, obj_pos, strength) + if not dmg then + return + end + if armor_enabled then + dmg = dmg * mul + end + apply_fractional_damage(object, dmg) + if longterm_damage and object:is_player() then + local pn = object:get_player_name() + radiated_players[pn] = (radiated_players[pn] or 0) + dmg + end +end + +local rad_dmg_mult_sqrt = math.sqrt(1 / rad_dmg_cutoff) +local function dmg_abm(pos, node) + local strength = minetest.get_item_group(node.name, "radioactive") + local max_dist = strength * rad_dmg_mult_sqrt + for _, o in pairs(minetest.get_objects_inside_radius(pos, + max_dist + abdomen_offset)) do + if entity_damage or o:is_player() then + dmg_object(pos, o, strength) + end + end +end + +if minetest.setting_getbool("enable_damage") then + minetest.register_abm({ + nodenames = {"group:radioactive"}, + interval = 1, + chance = 1, + action = dmg_abm, + }) + + if longterm_damage then + minetest.register_globalstep(function(dtime) + for pn, dmg in pairs(radiated_players) do + dmg = dmg - (dtime / 8) + local player = minetest.get_player_by_name(pn) + local killed + if player and dmg > rad_dmg_cutoff then + killed = apply_fractional_damage(player, (dmg * dtime) / 8) + else + dmg = nil + end + -- on_dieplayer will have already set this if the player died + if not killed then + radiated_players[pn] = dmg + end + end + end) + + minetest.register_on_dieplayer(function(player) + radiated_players[player:get_player_name()] = nil + end) + end +end + +-- Radioactive materials that can result from destroying a reactor +local griefing = technic.config:get_bool("enable_corium_griefing") + +for _, state in pairs({"flowing", "source"}) do + minetest.register_node("technic:corium_"..state, { + description = S(state == "source" and "Corium Source" or "Flowing Corium"), + drawtype = (state == "source" and "liquid" or "flowingliquid"), + [state == "source" and "tiles" or "special_tiles"] = {{ + name = "technic_corium_"..state.."_animated.png", + animation = { + type = "vertical_frames", + aspect_w = 16, + aspect_h = 16, + length = 3.0, + }, + }}, + paramtype = "light", + paramtype2 = (state == "flowing" and "flowingliquid" or nil), + light_source = (state == "source" and 8 or 5), + walkable = false, + pointable = false, + diggable = false, + buildable_to = true, + drop = "", + drowning = 1, + liquidtype = state, + liquid_alternative_flowing = "technic:corium_flowing", + liquid_alternative_source = "technic:corium_source", + liquid_viscosity = LAVA_VISC, + liquid_renewable = false, + damage_per_second = 6, + post_effect_color = {a=192, r=80, g=160, b=80}, + groups = { + liquid = 2, + hot = 3, + igniter = (griefing and 1 or 0), + radioactive = (state == "source" and 12 or 6), + not_in_creative_inventory = (state == "flowing" and 1 or nil), + }, + }) +end + +if rawget(_G, "bucket") and bucket.register_liquid then + bucket.register_liquid( + "technic:corium_source", + "technic:corium_flowing", + "technic:bucket_corium", + "technic_bucket_corium.png", + "Corium Bucket" + ) +end + +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}, + sounds = default.node_sound_stone_defaults(), + light_source = 2, +}) + +minetest.register_abm({ + nodenames = {"group:water"}, + neighbors = {"technic:corium_source"}, + interval = 1, + chance = 1, + action = function(pos, node) + minetest.remove_node(pos) + end, +}) + +minetest.register_abm({ + nodenames = {"technic:corium_flowing"}, + neighbors = {"group:water"}, + interval = 1, + chance = 1, + action = function(pos, node) + minetest.set_node(pos, {name="technic:chernobylite_block"}) + end, +}) + +minetest.register_abm({ + nodenames = {"technic:corium_flowing"}, + interval = 5, + chance = (griefing and 10 or 1), + action = function(pos, node) + minetest.set_node(pos, {name="technic:chernobylite_block"}) + end, +}) + +if griefing then + minetest.register_abm({ + nodenames = {"technic:corium_source", "technic:corium_flowing"}, + interval = 4, + chance = 4, + action = function(pos, node) + for _, offset in ipairs({ + vector.new(1,0,0), + vector.new(-1,0,0), + vector.new(0,0,1), + vector.new(0,0,-1), + vector.new(0,-1,0), + }) do + if math.random(8) == 1 then + minetest.dig_node(vector.add(pos, offset)) + end + end + end, + }) +end + diff --git a/technic/textures/technic_stone_dust.png b/technic/textures/technic_stone_dust.png Binary files differnew file mode 100644 index 0000000..ce9d9e4 --- /dev/null +++ b/technic/textures/technic_stone_dust.png diff --git a/technic/textures/technicx32/technic_stone_dust.png b/technic/textures/technicx32/technic_stone_dust.png Binary files differnew file mode 100644 index 0000000..3c49fe6 --- /dev/null +++ b/technic/textures/technicx32/technic_stone_dust.png diff --git a/technic/tools/mining_drill.lua b/technic/tools/mining_drill.lua index 8a25abe..e8e9bcb 100644 --- a/technic/tools/mining_drill.lua +++ b/technic/tools/mining_drill.lua @@ -252,10 +252,9 @@ local function mining_drill_mk2_setmode(user,itemstack) mode=mode+1 if mode>=5 then mode=1 end minetest.chat_send_player(player_name, S("Mining Drill Mk%d Mode %d"):format(2, mode)..": "..mining_drill_mode_text[mode][1]) - item["name"]="technic:mining_drill_mk2_"..mode + itemstack:set_name("technic:mining_drill_mk2_"..mode); meta["mode"]=mode - item["metadata"]=minetest.serialize(meta) - itemstack:replace(item) + itemstack:set_metadata(minetest.serialize(meta)) return itemstack end @@ -276,10 +275,9 @@ local function mining_drill_mk3_setmode(user,itemstack) mode=mode+1 if mode>=6 then mode=1 end minetest.chat_send_player(player_name, S("Mining Drill Mk%d Mode %d"):format(3, mode)..": "..mining_drill_mode_text[mode][1]) - item["name"]="technic:mining_drill_mk3_"..mode + itemstack:set_name("technic:mining_drill_mk3_"..mode); meta["mode"]=mode - item["metadata"]=minetest.serialize(meta) - itemstack:replace(item) + itemstack:set_metadata(minetest.serialize(meta)) return itemstack end diff --git a/technic/tools/mining_lasers.lua b/technic/tools/mining_lasers.lua index c09aa92..ef1eecb 100644 --- a/technic/tools/mining_lasers.lua +++ b/technic/tools/mining_lasers.lua @@ -38,8 +38,8 @@ local function laser_node(pos, node, player) minetest.remove_node(pos) minetest.add_particle({ pos = pos, - vel = {x=0, y=2, z=0}, - acc = {x=0, y=-1, z=0}, + velocity = {x=0, y=2, z=0}, + acceleration = {x=0, y=-1, z=0}, expirationtime = 1.5, size = 6 + math.random() * 2, texture = "smoke_puff.png^[transform" .. math.random(0, 7), @@ -61,17 +61,17 @@ local function laser_shoot(player, range, particle_texture, sound) local start_pos = vector.new(player_pos) -- Adjust to head height - start_pos.y = start_pos.y + 1.9 + start_pos.y = start_pos.y + 1.6 minetest.add_particle({ pos = startpos, - vel = dir, - acc = vector.multiply(dir, 50), + velocity = dir, + acceleration = vector.multiply(dir, 50), expirationtime = range / 11, size = 1, texture = particle_texture .. "^[transform" .. math.random(0, 7), }) minetest.sound_play(sound, {pos = player_pos, max_hear_distance = range}) - for pos in technic.trace_node_ray(start_pos, dir, range) do + for pos in technic.trace_node_ray_fat(start_pos, dir, range) do if minetest.is_protected(pos, player_name) then minetest.record_protection_violation(pos, player_name) break diff --git a/technic_worldgen/nodes.lua b/technic_worldgen/nodes.lua index a4fe2dd..f3a88e4 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=1000}, + groups = {cracky=3, radioactive=1}, sounds = default.node_sound_stone_defaults(), drop = "technic:uranium_lump", }) @@ -74,7 +74,7 @@ minetest.register_node(":technic:uranium_block", { description = S("Uranium Block"), tiles = { "technic_uranium_block.png" }, is_ground_content = true, - groups = {uranium_block=1, cracky=1, level=2, radioactive=3000}, + groups = {uranium_block=1, cracky=1, level=2, radioactive=2}, sounds = default.node_sound_stone_defaults() }) diff --git a/technic_worldgen/oregen.lua b/technic_worldgen/oregen.lua index 795f0ec..c6782e6 100644 --- a/technic_worldgen/oregen.lua +++ b/technic_worldgen/oregen.lua @@ -54,13 +54,13 @@ minetest.register_ore({ ore_type = "scatter", ore = "technic:mineral_zinc", wherein = "default:stone", - clust_scarcity = 8*8*8, - clust_num_ores = 4, - clust_size = 3, + clust_scarcity = 9*9*9, + clust_num_ores = 5, + clust_size = 7, y_min = -32, y_max = 2, - noise_params = zinc_params, - noise_threshhold = zinc_threshhold, + noise_params = lead_params, + noise_threshhold = lead_threshhold, }) minetest.register_ore({ |