Skip to content

Commit

Permalink
Made radiation configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
numberZero authored and ShadowNinja committed Feb 26, 2017
1 parent 51be33d commit b739ed6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
2 changes: 2 additions & 0 deletions technic/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ local defaults = {
enable_wind_mill = "false",
enable_frames = "false",
enable_corium_griefing = "true",
enable_entity_radiation_damage = "true",
enable_longterm_radiation_damage = "true",
}

for k, v in pairs(defaults) do
Expand Down
55 changes: 31 additions & 24 deletions technic/radiation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ local cache_scaled_shielding = {}
local rad_dmg_cutoff = 0.2
local radiated_players = {}

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,
Expand Down Expand Up @@ -297,17 +300,17 @@ end

local function dmg_object(pos, object, strength)
local obj_pos = vector.add(object:getpos(), calculate_object_center(object))
local dmg = calculate_base_damage(pos, obj_pos, strength)
if not dmg then
return
end
local mul = calculate_damage_multiplier(object)
if mul == 0 then
return
end
local dmg = calculate_base_damage(pos, obj_pos, strength)
if not dmg then
return
end
dmg = dmg * mul
apply_fractional_damage(object, dmg)
if object:is_player() then
if longterm_damage and object:is_player() then
local pn = object:get_player_name()
radiated_players[pn] = (radiated_players[pn] or 0) + dmg
end
Expand All @@ -319,7 +322,9 @@ local function dmg_abm(pos, node)
local max_dist = strength * rad_dmg_mult_sqrt
for _, o in pairs(minetest.get_objects_inside_radius(pos,
max_dist + abdomen_offset)) do
dmg_object(pos, o, strength)
if entity_damage or o:is_player() then
dmg_object(pos, o, strength)
end
end
end

Expand All @@ -331,26 +336,28 @@ if minetest.setting_getbool("enable_damage") then
action = dmg_abm,
})

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
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
end)
end)

minetest.register_on_dieplayer(function(player)
radiated_players[player:get_player_name()] = nil
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
Expand Down

0 comments on commit b739ed6

Please sign in to comment.