Skip to content

Instantly share code, notes, and snippets.

@BlueNexus
Last active December 15, 2016 17:34
Show Gist options
  • Save BlueNexus/46c406f3a0799034381b8d37f4d1407e to your computer and use it in GitHub Desktop.
Save BlueNexus/46c406f3a0799034381b8d37f4d1407e to your computer and use it in GitHub Desktop.
#define DECAY_RATE 0.1
var/list/to_process = list(
datum/rad_handler
var/list/sources = list()
var/list/irradiated = list()
datum/rad_handler/process()
for(var/turf/T in irradiated)
irradiated[T] -= DECAY_RATE
for(var/emitter in sources)
radiate(emitter, emitter.rad_power, emitter.rad_range)
to_process.cut()
datum/rad_handler/proc/radiate(source, power, range)
var/turf/epicentre = get_turf(source)
var/to_process = list()
to_process[epicentre] = power
//Gather turfs to try and irradiate
for(var/direction in cardinal)
var/turf/T = get_step(epicentre, direction)
T.get_rad_area(epicentre, range, direction)
for(var/spot in to_process)
var/turf/origin = get_turf(epicentre)
var/turf/dest = spot
var/working = power
while(origin != dest)
origin = get_step(origin, get_dir(origin, dest))
if(!to_process[origin])
to_process[origin] = working
working -= origin.rad_resistance
else
to_process[origin] = max(to_process[origin], working)
for(var/spot in to_process)
irradiated[spot] = (max((to_process[origin]) / (get_dist(epicentre, spot) ** 2)), irradiated[spot])
turf/proc/get_rad_area(epicentre, range, direction)
var/testing = true //not sure if the following is necessary or not, so making sure
if(testing)
if(src in to_process)
return
to_process[src] = null
if(get_dist(src, epicentre) >= range)
return
var/turf/T = get_step(src, direction)
if(T)
T.get_rad_area(epicentre, range, direction)
T = get_step(src, turn(direction,90))
if(T)
T.get_rad_area(epicentre, range, turn(direction,90))
T = get_step(src, turn(direction,-90))
if(T)
T.get_rad_area(epicentre, range, turn(direction,90))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment