Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt(radiation): speed up radiation traveling #10716

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions code/__defines/radiation.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#define MAX_RADIATION_DIST (world.view * 2)
#define RADIATION_DISTANCE_MULT(DST) (log(2, max(2, DST + 2)))
#define RADIATION_MIN_IONIZATION (10 ELECTRONVOLT)
#define RADIATION_CALC_OBJ_RESIST(rad_info, obj) ((obj.atom_flags & ATOM_FLAG_OPEN_CONTAINER) ? 0 : obj.rad_resist[rad_info.radiation_type])

#define RADIATION_ALPHA_PARTICLE "alpha_particle"
#define RADIATION_BETA_PARTICLE "beta_particle"
#define RADIATION_HAWKING "hawking"
Expand Down
23 changes: 20 additions & 3 deletions code/controllers/subsystems/radiation.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
GLOBAL_DATUM_INIT(rad_instance, /datum/radiation, new(1, RADIATION_ALPHA_PARTICLE))

SUBSYSTEM_DEF(radiation)
name = "Radiation"
wait = 2 SECONDS
Expand Down Expand Up @@ -40,16 +42,31 @@ SUBSYSTEM_DEF(radiation)
log_debug("NULLSPACE ALERT: [A.name] | loc: `[A.loc]` | ckey: `[A.ckey]`")
continue

var/list/sources = get_sources_in_range(T)
for(var/datum/radiation_source/source in sources)
if(source.info.activity <= 0 || source.info.energy <= 0)
qdel(source)

if(!source.info.is_ionizing())
var/turf/source_turf = get_turf(source.holder)

if(source_turf.z != T.z)
continue // Radiation is not multi-z

var/E = source.info.energy / RADIATION_DISTANCE_MULT(get_dist(T, source_turf))

if(isobj(source.holder))
var/obj/current_obj = source.holder
E = max(E - RADIATION_CALC_OBJ_RESIST(source.info, current_obj), 0)

if(E < RADIATION_MIN_IONIZATION)
continue

if(source.flat)
A.rad_act(source, get_turf(A))
if(source.respect_maint)
var/area/AR = T.loc
if(AR.area_flags & AREA_FLAG_RAD_SHIELDED)
continue // In shielded area

A.rad_act(source, T)
else
A.rad_act(source, source.holder)
if (MC_TICK_CHECK)
Expand Down
36 changes: 17 additions & 19 deletions code/modules/radiation/radiation.dm
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@

specific_activity = activity

/datum/radiation/proc/copy()
var/datum/radiation/R = new(activity, radiation_type, energy)
/datum/radiation/proc/copy(datum/radiation/target)
target.activity = activity
target.radiation_type = radiation_type
target.energy = energy
target.specific_activity = specific_activity
target.quality_factor = quality_factor

R.specific_activity = specific_activity

return R
return target

/datum/radiation/proc/is_ionizing()
return energy >= (10 ELECTRONVOLT)
return energy >= RADIATION_MIN_IONIZATION

/datum/radiation/proc/travel(atom/source, atom/target)
var/atom/current_point = source
Expand All @@ -58,11 +60,15 @@

if(isobj(current_point))
var/obj/current_obj = current_point
energy = max(energy - current_obj.calc_rad_resistance(src), 0)
energy = max(energy - RADIATION_CALC_OBJ_RESIST(src, current_obj), 0)
current_point = current_point.loc

var/dst = get_dist(get_turf(source), get_turf(target))
energy /= log(2, max(2, dst + 2))

if (dst > MAX_RADIATION_DIST)
return FALSE

energy /= RADIATION_DISTANCE_MULT(dst)

if(!is_ionizing())
return FALSE
Expand All @@ -74,7 +80,7 @@
continue

var/obj/current_obj = current_point
energy = max(energy - current_obj.calc_rad_resistance(src), 0)
energy = max(energy - RADIATION_CALC_OBJ_RESIST(src, current_obj), 0)

if(!is_ionizing())
return FALSE
Expand All @@ -98,7 +104,7 @@
target_parent = target_parent.loc
continue

energy = max(energy - target_parent.calc_rad_resistance(src), 0)
energy = max(energy - RADIATION_CALC_OBJ_RESIST(src, target_parent), 0)

if(!is_ionizing())
return FALSE
Expand All @@ -118,7 +124,7 @@
if(source_turf != current_turf)
for(var/obj/O in current_turf)
if(O.density)
energy = max(energy - O.calc_rad_resistance(src), 0)
energy = max(energy - RADIATION_CALC_OBJ_RESIST(src, O), 0)
break

current_point = get_step_towards(current_turf, target)
Expand Down Expand Up @@ -148,14 +154,6 @@

return Clamp(resist, 0.0, 1.0)

/obj/proc/calc_rad_resistance(datum/radiation/info)
var/resist = rad_resist[info.radiation_type]

if(atom_flags & ATOM_FLAG_OPEN_CONTAINER)
return 0

return resist

/// This is used when radiation is exposed from the outside.
///
/// When something is exposing radiation inside of the mob - use `radiation` variable directly.
Expand Down
4 changes: 2 additions & 2 deletions code/modules/radiation/radiation_source.dm
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
else
info.energy = new_energy
if(!flat)
range = world.view * 2
range = MAX_RADIATION_DIST

/datum/radiation_source/proc/travel(atom/target)
var/datum/radiation/R = info.copy()
var/datum/radiation/R = info.copy(GLOB.rad_instance)

var/atom/source = flat ? get_turf(target) : holder
R.travel(source, target)
Expand Down
Loading