mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 18:22:39 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -1,96 +0,0 @@
|
||||
var/datum/controller/process/planet/planet_controller = null
|
||||
|
||||
/datum/controller/process/planet
|
||||
var/list/planets = list()
|
||||
var/list/z_to_planet = list()
|
||||
|
||||
/datum/controller/process/planet/setup()
|
||||
name = "planet controller"
|
||||
planet_controller = src
|
||||
schedule_interval = 1 MINUTE
|
||||
start_delay = 20 SECONDS
|
||||
|
||||
var/list/planet_datums = typesof(/datum/planet) - /datum/planet
|
||||
for(var/P in planet_datums)
|
||||
var/datum/planet/NP = new P()
|
||||
planets.Add(NP)
|
||||
|
||||
allocateTurfs()
|
||||
|
||||
/datum/controller/process/planet/proc/allocateTurfs()
|
||||
for(var/turf/simulated/OT in outdoor_turfs)
|
||||
for(var/datum/planet/P in planets)
|
||||
if(OT.z in P.expected_z_levels)
|
||||
P.planet_floors |= OT
|
||||
OT.vis_contents |= P.weather_holder.visuals
|
||||
break
|
||||
outdoor_turfs.Cut() //Why were you in there INCORRECTLY?
|
||||
|
||||
for(var/turf/unsimulated/wall/planetary/PW in planetary_walls)
|
||||
for(var/datum/planet/P in planets)
|
||||
if(PW.type == P.planetary_wall_type)
|
||||
P.planet_walls |= PW
|
||||
break
|
||||
planetary_walls.Cut()
|
||||
|
||||
/datum/controller/process/planet/proc/unallocateTurf(var/turf/T)
|
||||
for(var/planet in planets)
|
||||
var/datum/planet/P = planet
|
||||
if(T.z in P.expected_z_levels)
|
||||
P.planet_floors -= T
|
||||
T.vis_contents -= P.weather_holder.visuals
|
||||
|
||||
/datum/controller/process/planet/doWork()
|
||||
if(outdoor_turfs.len || planetary_walls.len)
|
||||
allocateTurfs()
|
||||
|
||||
for(var/datum/planet/P in planets)
|
||||
P.process(schedule_interval / 10)
|
||||
SCHECK //Your process() really shouldn't take this long...
|
||||
|
||||
//Sun light needs changing
|
||||
if(P.needs_work & PLANET_PROCESS_SUN)
|
||||
P.needs_work &= ~PLANET_PROCESS_SUN
|
||||
// Remove old value from corners
|
||||
var/list/sunlit_corners = P.sunlit_corners
|
||||
var/old_lum_r = -P.sun["lum_r"]
|
||||
var/old_lum_g = -P.sun["lum_g"]
|
||||
var/old_lum_b = -P.sun["lum_b"]
|
||||
if(old_lum_r || old_lum_g || old_lum_b)
|
||||
for(var/C in P.sunlit_corners)
|
||||
var/datum/lighting_corner/LC = C
|
||||
LC.update_lumcount(old_lum_r, old_lum_g, old_lum_b)
|
||||
SCHECK
|
||||
sunlit_corners.Cut()
|
||||
|
||||
// Calculate new values to apply
|
||||
var/new_brightness = P.sun["brightness"]
|
||||
var/new_color = P.sun["color"]
|
||||
var/lum_r = new_brightness * GetRedPart (new_color) / 255
|
||||
var/lum_g = new_brightness * GetGreenPart(new_color) / 255
|
||||
var/lum_b = new_brightness * GetBluePart (new_color) / 255
|
||||
var/static/update_gen = -1 // Used to prevent double-processing corners. Otherwise would happen when looping over adjacent turfs.
|
||||
for(var/I in P.planet_floors)
|
||||
var/turf/simulated/T = I
|
||||
if(!T.lighting_corners_initialised)
|
||||
T.generate_missing_corners()
|
||||
for(var/C in T.get_corners())
|
||||
var/datum/lighting_corner/LC = C
|
||||
if(LC.update_gen != update_gen && LC.active)
|
||||
sunlit_corners += LC
|
||||
LC.update_gen = update_gen
|
||||
LC.update_lumcount(lum_r, lum_g, lum_b)
|
||||
SCHECK
|
||||
update_gen--
|
||||
P.sun["lum_r"] = lum_r
|
||||
P.sun["lum_g"] = lum_g
|
||||
P.sun["lum_b"] = lum_b
|
||||
|
||||
//Temperature needs updating
|
||||
if(P.needs_work & PLANET_PROCESS_TEMP)
|
||||
P.needs_work &= ~PLANET_PROCESS_TEMP
|
||||
//Set new temperatures
|
||||
for(var/W in P.planet_walls)
|
||||
var/turf/unsimulated/wall/planetary/wall = W
|
||||
wall.set_temperature(P.weather_holder.temperature)
|
||||
SCHECK
|
||||
@@ -1,56 +0,0 @@
|
||||
/datum/controller/process/radiation
|
||||
var/repository/radiation/linked = null
|
||||
|
||||
/datum/controller/process/radiation/setup()
|
||||
name = "radiation controller"
|
||||
schedule_interval = 20 // every 2 seconds
|
||||
linked = radiation_repository
|
||||
|
||||
/datum/controller/process/radiation/doWork()
|
||||
sources_decay()
|
||||
cache_expires()
|
||||
irradiate_targets()
|
||||
|
||||
// Step 1 - Sources Decay
|
||||
/datum/controller/process/radiation/proc/sources_decay()
|
||||
var/list/sources = linked.sources
|
||||
for(var/thing in sources)
|
||||
var/datum/radiation_source/S = thing
|
||||
if(QDELETED(S))
|
||||
sources.Remove(S)
|
||||
continue
|
||||
if(S.decay)
|
||||
S.update_rad_power(S.rad_power - config.radiation_decay_rate)
|
||||
if(S.rad_power <= config.radiation_lower_limit)
|
||||
sources.Remove(S)
|
||||
SCHECK // This scheck probably just wastes resources, but better safe than sorry in this case.
|
||||
|
||||
// Step 2 - Cache Expires
|
||||
/datum/controller/process/radiation/proc/cache_expires()
|
||||
var/list/resistance_cache = linked.resistance_cache
|
||||
for(var/thing in resistance_cache)
|
||||
var/turf/T = thing
|
||||
if(QDELETED(T))
|
||||
resistance_cache.Remove(T)
|
||||
continue
|
||||
if((length(T.contents) + 1) != resistance_cache[T])
|
||||
resistance_cache.Remove(T) // If its stale REMOVE it! It will get added if its needed.
|
||||
SCHECK
|
||||
|
||||
// Step 3 - Registered irradiatable things are checked for radiation
|
||||
/datum/controller/process/radiation/proc/irradiate_targets()
|
||||
var/list/registered_listeners = living_mob_list // For now just use this. Nothing else is interested anyway.
|
||||
if(length(linked.sources) > 0)
|
||||
for(var/thing in registered_listeners)
|
||||
var/atom/A = thing
|
||||
if(QDELETED(A))
|
||||
continue
|
||||
var/turf/T = get_turf(thing)
|
||||
var/rads = linked.get_rads_at_turf(T)
|
||||
if(rads)
|
||||
A.rad_act(rads)
|
||||
SCHECK
|
||||
|
||||
/datum/controller/process/radiation/statProcess()
|
||||
..()
|
||||
stat(null, "[linked.sources.len] sources, [linked.resistance_cache.len] cached turfs")
|
||||
@@ -1,169 +0,0 @@
|
||||
/var/datum/controller/process/scheduler/scheduler
|
||||
|
||||
/************
|
||||
* Scheduler *
|
||||
************/
|
||||
/datum/controller/process/scheduler
|
||||
var/list/scheduled_tasks
|
||||
|
||||
/datum/controller/process/scheduler/setup()
|
||||
name = "scheduler"
|
||||
schedule_interval = 1 SECOND
|
||||
scheduled_tasks = list()
|
||||
scheduler = src
|
||||
|
||||
/datum/controller/process/scheduler/doWork()
|
||||
var/world_time = world.time
|
||||
for(last_object in scheduled_tasks)
|
||||
var/datum/scheduled_task/scheduled_task = last_object
|
||||
if(world_time < scheduled_task.trigger_time)
|
||||
break // Too early for this one, and therefore too early for all remaining.
|
||||
try
|
||||
unschedule(scheduled_task)
|
||||
scheduled_task.pre_process()
|
||||
scheduled_task.process()
|
||||
scheduled_task.post_process()
|
||||
catch(var/exception/e)
|
||||
catchException(e, last_object)
|
||||
SCHECK
|
||||
|
||||
// We've been restarted, probably due to having a massive list of tasks.
|
||||
// Lets copy over the task list as safely as we can and try to chug thru it...
|
||||
// Note: We won't be informed about tasks being destroyed, but this is the best we can do.
|
||||
/datum/controller/process/scheduler/copyStateFrom(var/datum/controller/process/scheduler/target)
|
||||
scheduled_tasks = list()
|
||||
for(var/datum/scheduled_task/st in target.scheduled_tasks)
|
||||
if(!QDELETED(st) && istype(st))
|
||||
schedule(st)
|
||||
scheduler = src
|
||||
|
||||
// We are being killed. Least we can do is deregister all those events we registered
|
||||
/datum/controller/process/scheduler/onKill()
|
||||
for(var/st in scheduled_tasks)
|
||||
GLOB.destroyed_event.unregister(st, src)
|
||||
|
||||
/datum/controller/process/scheduler/statProcess()
|
||||
..()
|
||||
stat(null, "[scheduled_tasks.len] task\s")
|
||||
|
||||
/datum/controller/process/scheduler/proc/schedule(var/datum/scheduled_task/st)
|
||||
dd_insertObjectList(scheduled_tasks, st)
|
||||
|
||||
/datum/controller/process/scheduler/proc/unschedule(var/datum/scheduled_task/st)
|
||||
scheduled_tasks -= st
|
||||
|
||||
/**********
|
||||
* Helpers *
|
||||
**********/
|
||||
/proc/schedule_task_in(var/in_time, var/procedure, var/list/arguments = list())
|
||||
return schedule_task(world.time + in_time, procedure, arguments)
|
||||
|
||||
/proc/schedule_callback_in(var/in_time, var/datum/callback)
|
||||
return schedule_callback(world.time + in_time, callback)
|
||||
|
||||
/proc/schedule_task_with_source_in(var/in_time, var/source, var/procedure, var/list/arguments = list())
|
||||
return schedule_task_with_source(world.time + in_time, source, procedure, arguments)
|
||||
|
||||
/proc/schedule_task(var/trigger_time, var/procedure, var/list/arguments)
|
||||
var/datum/scheduled_task/st = new/datum/scheduled_task(trigger_time, procedure, arguments, /proc/destroy_scheduled_task, list())
|
||||
scheduler.schedule(st)
|
||||
return st
|
||||
|
||||
/proc/schedule_callback(var/trigger_time, var/datum/callback)
|
||||
var/datum/scheduled_task/callback/st = new/datum/scheduled_task/callback(trigger_time, callback, /proc/destroy_scheduled_task, list())
|
||||
scheduler.schedule(st)
|
||||
return st
|
||||
|
||||
/proc/schedule_task_with_source(var/trigger_time, var/source, var/procedure, var/list/arguments)
|
||||
var/datum/scheduled_task/st = new/datum/scheduled_task/source(trigger_time, source, procedure, arguments, /proc/destroy_scheduled_task, list())
|
||||
scheduler.schedule(st)
|
||||
return st
|
||||
|
||||
/proc/schedule_repeating_task(var/trigger_time, var/repeat_interval, var/procedure, var/list/arguments)
|
||||
var/datum/scheduled_task/st = new/datum/scheduled_task(trigger_time, procedure, arguments, /proc/repeat_scheduled_task, list(repeat_interval))
|
||||
scheduler.schedule(st)
|
||||
return st
|
||||
|
||||
/proc/schedule_repeating_task_with_source(var/trigger_time, var/repeat_interval, var/source, var/procedure, var/list/arguments)
|
||||
var/datum/scheduled_task/st = new/datum/scheduled_task/source(trigger_time, source, procedure, arguments, /proc/repeat_scheduled_task, list(repeat_interval))
|
||||
scheduler.schedule(st)
|
||||
return st
|
||||
|
||||
/*************
|
||||
* Task Datum *
|
||||
*************/
|
||||
/datum/scheduled_task
|
||||
var/trigger_time
|
||||
var/procedure
|
||||
var/list/arguments
|
||||
var/task_after_process
|
||||
var/list/task_after_process_args
|
||||
|
||||
/datum/scheduled_task/New(var/trigger_time, var/procedure, var/list/arguments, var/proc/task_after_process, var/list/task_after_process_args)
|
||||
..()
|
||||
src.trigger_time = trigger_time
|
||||
src.procedure = procedure
|
||||
src.arguments = arguments ? arguments : list()
|
||||
src.task_after_process = task_after_process ? task_after_process : /proc/destroy_scheduled_task
|
||||
src.task_after_process_args = istype(task_after_process_args) ? task_after_process_args : list()
|
||||
task_after_process_args += src
|
||||
|
||||
/datum/scheduled_task/Destroy()
|
||||
scheduler.unschedule(src)
|
||||
procedure = null
|
||||
arguments.Cut()
|
||||
task_after_process = null
|
||||
task_after_process_args.Cut()
|
||||
return ..()
|
||||
|
||||
/datum/scheduled_task/dd_SortValue()
|
||||
return trigger_time
|
||||
|
||||
/datum/scheduled_task/proc/pre_process()
|
||||
task_triggered_event.raise_event(list(src))
|
||||
|
||||
/datum/scheduled_task/proc/process()
|
||||
if(procedure)
|
||||
call(procedure)(arglist(arguments))
|
||||
|
||||
/datum/scheduled_task/proc/post_process()
|
||||
call(task_after_process)(arglist(task_after_process_args))
|
||||
|
||||
// Resets the trigger time, has no effect if the task has already triggered
|
||||
/datum/scheduled_task/proc/trigger_task_in(var/trigger_in)
|
||||
src.trigger_time = world.time + trigger_in
|
||||
|
||||
/datum/scheduled_task/callback
|
||||
var/datum/callback/callback
|
||||
|
||||
/datum/scheduled_task/callback/New(var/trigger_time, var/datum/callback, var/proc/task_after_process, var/list/task_after_process_args)
|
||||
src.callback = callback
|
||||
..(trigger_time = trigger_time, task_after_process = task_after_process, task_after_process_args = task_after_process_args)
|
||||
|
||||
/datum/scheduled_task/callback/process()
|
||||
callback.Invoke()
|
||||
|
||||
/datum/scheduled_task/source
|
||||
var/datum/source
|
||||
|
||||
/datum/scheduled_task/source/New(var/trigger_time, var/datum/source, var/procedure, var/list/arguments, var/proc/task_after_process, var/list/task_after_process_args)
|
||||
src.source = source
|
||||
GLOB.destroyed_event.register(src.source, src, /datum/scheduled_task/source/proc/source_destroyed)
|
||||
..(trigger_time, procedure, arguments, task_after_process, task_after_process_args)
|
||||
|
||||
/datum/scheduled_task/source/Destroy()
|
||||
source = null
|
||||
return ..()
|
||||
|
||||
/datum/scheduled_task/source/process()
|
||||
call(source, procedure)(arglist(arguments))
|
||||
|
||||
/datum/scheduled_task/source/proc/source_destroyed()
|
||||
qdel(src)
|
||||
|
||||
/proc/destroy_scheduled_task(var/datum/scheduled_task/st)
|
||||
qdel(st)
|
||||
|
||||
/proc/repeat_scheduled_task(var/trigger_delay, var/datum/scheduled_task/st)
|
||||
st.trigger_time = world.time + trigger_delay
|
||||
scheduler.schedule(st)
|
||||
135
code/controllers/subsystems/radiation.dm
Normal file
135
code/controllers/subsystems/radiation.dm
Normal file
@@ -0,0 +1,135 @@
|
||||
SUBSYSTEM_DEF(radiation)
|
||||
name = "Radiation"
|
||||
wait = 2 SECONDS
|
||||
flags = SS_NO_INIT
|
||||
|
||||
var/list/sources = list() // all radiation source datums
|
||||
var/list/sources_assoc = list() // Sources indexed by turf for de-duplication.
|
||||
var/list/resistance_cache = list() // Cache of turf's radiation resistance.
|
||||
|
||||
var/tmp/list/current_sources = list()
|
||||
var/tmp/list/current_res_cache = list()
|
||||
var/tmp/list/listeners = list()
|
||||
|
||||
/datum/controller/subsystem/radiation/fire(resumed = FALSE)
|
||||
if (!resumed)
|
||||
current_sources = sources.Copy()
|
||||
current_res_cache = resistance_cache.Copy()
|
||||
listeners = living_mob_list.Copy()
|
||||
|
||||
while(current_sources.len)
|
||||
var/datum/radiation_source/S = current_sources[current_sources.len]
|
||||
current_sources.len--
|
||||
|
||||
if(QDELETED(S))
|
||||
sources -= S
|
||||
else if(S.decay)
|
||||
S.update_rad_power(S.rad_power - config.radiation_decay_rate)
|
||||
if (MC_TICK_CHECK)
|
||||
return
|
||||
|
||||
while(current_res_cache.len)
|
||||
var/turf/T = current_res_cache[current_res_cache.len]
|
||||
current_res_cache.len--
|
||||
|
||||
if(QDELETED(T))
|
||||
resistance_cache -= T
|
||||
else if((length(T.contents) + 1) != resistance_cache[T])
|
||||
resistance_cache -= T // If its stale REMOVE it! It will get added if its needed.
|
||||
if (MC_TICK_CHECK)
|
||||
return
|
||||
|
||||
if(!sources.len)
|
||||
listeners.Cut()
|
||||
|
||||
while(listeners.len)
|
||||
var/atom/A = listeners[listeners.len]
|
||||
listeners.len--
|
||||
|
||||
if(!QDELETED(A))
|
||||
var/turf/T = get_turf(A)
|
||||
var/rads = get_rads_at_turf(T)
|
||||
if(rads)
|
||||
A.rad_act(rads)
|
||||
if (MC_TICK_CHECK)
|
||||
return
|
||||
|
||||
/datum/controller/subsystem/radiation/stat_entry()
|
||||
..("S:[sources.len], RC:[resistance_cache.len]")
|
||||
|
||||
// Ray trace from all active radiation sources to T and return the strongest effect.
|
||||
/datum/controller/subsystem/radiation/proc/get_rads_at_turf(var/turf/T)
|
||||
. = 0
|
||||
if(!istype(T))
|
||||
return
|
||||
|
||||
for(var/value in sources)
|
||||
var/datum/radiation_source/source = value
|
||||
if(source.rad_power < .)
|
||||
continue // Already being affected by a stronger source
|
||||
if(source.source_turf.z != T.z)
|
||||
continue // Radiation is not multi-z
|
||||
if(source.respect_maint)
|
||||
var/area/A = T.loc
|
||||
if(A.flags & RAD_SHIELDED)
|
||||
continue // In shielded area
|
||||
|
||||
var/dist = get_dist(source.source_turf, T)
|
||||
if(dist > source.range)
|
||||
continue // Too far to possibly affect
|
||||
if(source.flat)
|
||||
. = max(., source.rad_power)
|
||||
continue // No need to ray trace for flat field
|
||||
|
||||
// Okay, now ray trace to find resistence!
|
||||
var/turf/origin = source.source_turf
|
||||
var/working = source.rad_power
|
||||
while(origin != T)
|
||||
origin = get_step_towards(origin, T) //Raytracing
|
||||
if(!resistance_cache[origin]) //Only get the resistance if we don't already know it.
|
||||
origin.calc_rad_resistance()
|
||||
if(origin.cached_rad_resistance)
|
||||
working = round((working / (origin.cached_rad_resistance * config.radiation_resistance_multiplier)), 0.1)
|
||||
if((working <= .) || (working <= RADIATION_THRESHOLD_CUTOFF))
|
||||
break // Already affected by a stronger source (or its zero...)
|
||||
. = max((working / (dist ** 2)), .) //Butchered version of the inverse square law. Works for this purpose
|
||||
if(. <= RADIATION_THRESHOLD_CUTOFF)
|
||||
. = 0
|
||||
|
||||
// Add a radiation source instance to the repository. It will override any existing source on the same turf.
|
||||
/datum/controller/subsystem/radiation/proc/add_source(var/datum/radiation_source/S)
|
||||
if(!isturf(S.source_turf))
|
||||
return
|
||||
var/datum/radiation_source/existing = sources_assoc[S.source_turf]
|
||||
if(existing)
|
||||
qdel(existing)
|
||||
sources += S
|
||||
sources_assoc[S.source_turf] = S
|
||||
|
||||
// Creates a temporary radiation source that will decay
|
||||
/datum/controller/subsystem/radiation/proc/radiate(source, power) //Sends out a radiation pulse, taking walls into account
|
||||
if(!(source && power)) //Sanity checking
|
||||
return
|
||||
var/datum/radiation_source/S = new()
|
||||
S.source_turf = get_turf(source)
|
||||
S.update_rad_power(power)
|
||||
add_source(S)
|
||||
|
||||
// Sets the radiation in a range to a constant value.
|
||||
/datum/controller/subsystem/radiation/proc/flat_radiate(source, power, range, var/respect_maint = TRUE) //VOREStation edit; Respect shielded areas by default please.
|
||||
if(!(source && power && range))
|
||||
return
|
||||
var/datum/radiation_source/S = new()
|
||||
S.flat = TRUE
|
||||
S.range = range
|
||||
S.respect_maint = respect_maint
|
||||
S.source_turf = get_turf(source)
|
||||
S.update_rad_power(power)
|
||||
add_source(S)
|
||||
|
||||
// Irradiates a full Z-level. Hacky way of doing it, but not too expensive.
|
||||
/datum/controller/subsystem/radiation/proc/z_radiate(var/atom/source, power, var/respect_maint = TRUE) //VOREStation edit; Respect shielded areas by default please.
|
||||
if(!(power && source))
|
||||
return
|
||||
var/turf/epicentre = locate(round(world.maxx / 2), round(world.maxy / 2), source.z)
|
||||
flat_radiate(epicentre, power, world.maxx, respect_maint)
|
||||
Reference in New Issue
Block a user