Ports Sun Controller to Subsystem

This commit is contained in:
Fox McCloud
2018-03-25 19:23:26 -04:00
parent 338631744f
commit 2b6a6eb812
9 changed files with 63 additions and 464 deletions

View File

@@ -1,197 +0,0 @@
var/kill_air = 0
var/global/datum/controller/process/air_system/air_master
/datum/controller/process/air_system
var/list/excited_groups = list()
var/list/active_turfs = list()
var/list/hotspots = list()
//Special functions lists
var/list/turf/simulated/active_super_conductivity = list()
var/list/turf/simulated/high_pressure_delta = list()
var/current_cycle = 0
var/failed_ticks = 0
var/tick_progress = 0
// Stats
var/last_active = 0
var/last_excited = 0
var/last_hpd = 0
var/last_hotspots = 0
var/last_asc = 0
/datum/controller/process/air_system/setup()
name = "air"
schedule_interval = 4
start_delay = 4
var/watch = start_watch()
log_startup_progress("Processing geometry...")
setup_overlays() // Assign icons and such for gas-turf-overlays
setup_allturfs() // Get all currently active tiles that need processing each atmos tick.
log_startup_progress(" Geometry processed in [stop_watch(watch)]s.")
/datum/controller/process/air_system/doWork()
if(kill_air)
return 1
current_cycle++
process_pipenets()
process_atmos_machinery()
process_active_turfs()
process_excited_groups()
process_high_pressure_delta()
process_hotspots()
process_super_conductivity()
return 1
/datum/controller/process/air_system/statProcess()
..()
stat(null, "[last_active] active")
stat(null, "[last_excited] EG | [last_hpd] HPD | [last_asc] ASC | [last_hotspots] Hot")
stat(null, "[pipe_networks.len] pipe nets, [deferred_pipenet_rebuilds.len] deferred")
stat(null, "[atmos_machinery.len] atmos machines")
DECLARE_GLOBAL_CONTROLLER(air_system, air_master)
/datum/controller/process/air_system/proc/process_hotspots()
last_hotspots = hotspots.len
for(var/obj/effect/hotspot/H in hotspots)
H.process()
SCHECK
/datum/controller/process/air_system/proc/process_super_conductivity()
last_asc = active_super_conductivity.len
for(var/turf/simulated/T in active_super_conductivity)
T.super_conduct()
SCHECK
/datum/controller/process/air_system/proc/process_high_pressure_delta()
last_hpd = high_pressure_delta.len
for(var/turf/T in high_pressure_delta)
T.high_pressure_movements()
T.pressure_difference = 0
SCHECK
high_pressure_delta.Cut()
/datum/controller/process/air_system/proc/process_active_turfs()
last_active = active_turfs.len
for(var/turf/simulated/T in active_turfs)
T.process_cell()
SCHECK
/datum/controller/process/air_system/proc/process_pipenets()
for(last_object in deferred_pipenet_rebuilds)
var/obj/machinery/atmospherics/M = last_object
if(istype(M) && isnull(M.gcDestroyed))
try
M.build_network()
catch(var/exception/e)
catchException(e, M)
SCHECK
else
catchBadType(M)
deferred_pipenet_rebuilds -= M
for(last_object in pipe_networks)
var/datum/pipeline/pipeNetwork = last_object
if(istype(pipeNetwork) && isnull(pipeNetwork.gcDestroyed))
try
pipeNetwork.process()
catch(var/exception/e)
catchException(e, pipeNetwork)
SCHECK
else
catchBadType(pipeNetwork)
pipe_networks -= pipeNetwork
/datum/controller/process/air_system/proc/process_atmos_machinery()
for(last_object in atmos_machinery)
var/obj/machinery/M = last_object
if(istype(M) && isnull(M.gcDestroyed))
try
if(M.process_atmos() == PROCESS_KILL)
atmos_machinery.Remove(M)
continue
catch(var/exception/e)
catchException(e, M)
else
catchBadType(M)
atmos_machinery -= M
SCHECK
/datum/controller/process/air_system/proc/remove_from_active(var/turf/simulated/T)
if(istype(T))
T.excited = 0
active_turfs -= T
if(T.excited_group)
T.excited_group.garbage_collect()
/datum/controller/process/air_system/proc/add_to_active(var/turf/simulated/T, var/blockchanges = 1)
if(istype(T) && T.air)
T.excited = 1
active_turfs |= T
if(blockchanges && T.excited_group)
T.excited_group.garbage_collect()
else
for(var/direction in cardinal)
if(!(T.atmos_adjacent_turfs & direction))
continue
var/turf/simulated/S = get_step(T, direction)
if(istype(S))
add_to_active(S)
/datum/controller/process/air_system/proc/setup_allturfs(var/turfs_in = world)
for(var/turf/simulated/T in turfs_in)
T.CalculateAdjacentTurfs()
if(!T.blocks_air)
T.update_visuals()
for(var/direction in cardinal)
if(!(T.atmos_adjacent_turfs & direction))
continue
var/turf/enemy_tile = get_step(T, direction)
if(istype(enemy_tile,/turf/simulated/))
var/turf/simulated/enemy_simulated = enemy_tile
if(!T.air.compare(enemy_simulated.air))
T.excited = 1
active_turfs |= T
break
else
if(!T.air.check_turf_total(enemy_tile))
T.excited = 1
active_turfs |= T
/datum/controller/process/air_system/proc/process_excited_groups()
last_excited = excited_groups.len
for(var/datum/excited_group/EG in excited_groups)
EG.breakdown_cooldown++
if(EG.breakdown_cooldown == 10)
EG.self_breakdown()
SCHECK
return
if(EG.breakdown_cooldown > 20)
EG.dismantle()
SCHECK
/datum/controller/process/air_system/proc/setup_overlays()
plmaster = new /obj/effect/overlay()
plmaster.icon = 'icons/effects/tile_effects.dmi'
plmaster.icon_state = "plasma"
plmaster.layer = FLY_LAYER
plmaster.mouse_opacity = 0
slmaster = new /obj/effect/overlay()
slmaster.icon = 'icons/effects/tile_effects.dmi'
slmaster.icon_state = "sleeping_agent"
slmaster.layer = FLY_LAYER
slmaster.mouse_opacity = 0
icemaster = new /obj/effect/overlay()
icemaster.icon = 'icons/turf/overlays.dmi'
icemaster.icon_state = "snowfloor"
icemaster.layer = TURF_LAYER+0.1
icemaster.mouse_opacity = 0

View File

@@ -1,53 +0,0 @@
var/global/datum/controller/process/spacedrift/drift_master
/datum/controller/process/spacedrift
var/list/processing_list = list()
/datum/controller/process/spacedrift/setup()
name = "spacedrift"
schedule_interval = 5
start_delay = 20
log_startup_progress("Spacedrift starting up.")
/datum/controller/process/spacedrift/statProcess()
..()
stat(null, "P:[processing_list.len]")
/datum/controller/process/spacedrift/doWork()
var/list/currentrun = processing_list.Copy()
while(currentrun.len)
var/atom/movable/AM = currentrun[currentrun.len]
currentrun.len--
if(!AM)
processing_list -= AM
SCHECK
continue
if(AM.inertia_next_move > world.time)
SCHECK
continue
if(!AM.loc || AM.loc != AM.inertia_last_loc || AM.Process_Spacemove(0))
AM.inertia_dir = 0
if(!AM.inertia_dir)
AM.inertia_last_loc = null
processing_list -= AM
SCHECK
continue
var/old_dir = AM.dir
var/old_loc = AM.loc
AM.inertia_moving = TRUE
step(AM, AM.inertia_dir)
AM.inertia_moving = FALSE
AM.inertia_next_move = world.time + AM.inertia_move_delay
if(AM.loc == old_loc)
AM.inertia_dir = 0
AM.setDir(old_dir)
AM.inertia_last_loc = AM.loc
SCHECK
DECLARE_GLOBAL_CONTROLLER(spacedrift, drift_master)

View File

@@ -1,61 +0,0 @@
var/global/datum/controller/process/sun/sun
/datum/controller/process/sun
var/angle
var/dx
var/dy
var/rate
var/list/solars = list() // for debugging purposes, references solars list at the constructor
/datum/controller/process/sun/setup()
name = "sun"
schedule_interval = 600 // every 60 seconds
log_startup_progress("Sun ticker starting up.")
angle = rand (0,360) // the station position to the sun is randomised at round start
rate = rand(50,200)/100 // 50% - 200% of standard rotation
if(prob(50)) // same chance to rotate clockwise than counter-clockwise
rate = -rate
/datum/controller/process/sun/doWork()
calc_position()
update_solar_machinery()
DECLARE_GLOBAL_CONTROLLER(sun, sun)
// calculate the sun's position given the time of day
// at the standard rate (100%) the angle is increase/decreased by 6 degrees every minute.
// a full rotation thus take a game hour in that case
/datum/controller/process/sun/proc/calc_position()
angle = (360 + angle + rate * 6) % 360 // increase/decrease the angle to the sun, adjusted by the rate
// now calculate and cache the (dx,dy) increments for line drawing
var/s = sin(angle)
var/c = cos(angle)
// Either "abs(s) < abs(c)" or "abs(s) >= abs(c)"
// In both cases, the greater is greater than 0, so, no "if 0" check is needed for the divisions
if(abs(s) < abs(c))
dx = s / abs(c)
dy = c / abs(c)
else
dx = s / abs(s)
dy = c / abs(s)
//now tell the solar control computers to update their status and linked devices
/datum/controller/process/sun/proc/update_solar_machinery()
for(last_object in solars)
var/obj/machinery/power/solar_control/SC = last_object
if(istype(SC) && isnull(SC.gcDestroyed))
if(!SC.powernet)
solars -= SC
continue
try
SC.update()
catch(var/exception/e)
catchException(e, SC)
SCHECK
else
catchBadType(SC)
solars -= SC

View File

@@ -1,138 +0,0 @@
#define MAX_THROWING_DIST 512 // 2 z-levels on default width
#define MAX_TICKS_TO_MAKE_UP 3 //how many missed ticks will we attempt to make up for this run.
var/global/datum/controller/process/throwing/throw_master
/datum/controller/process/throwing
var/list/processing_list
/datum/controller/process/throwing/setup()
name = "throwing"
schedule_interval = 1
start_delay = 20
log_startup_progress("Throw ticker starting up.")
/datum/controller/process/throwing/statProcess()
..()
stat(null, "P:[processing_list.len]")
/datum/controller/process/throwing/started()
..()
if(!processing_list)
processing_list = list()
/datum/controller/process/throwing/doWork()
for(last_object in processing_list)
var/atom/movable/AM = last_object
if(istype(AM) && isnull(AM.gcDestroyed))
var/datum/thrownthing/TT = processing_list[AM]
if(istype(TT) && isnull(TT.gcDestroyed))
TT.tick()
SCHECK
else
catchBadType(TT)
processing_list -= AM
AM.throwing = null
else
catchBadType(AM)
processing_list -= AM
SCHECK
DECLARE_GLOBAL_CONTROLLER(throwing, throw_master)
/datum/thrownthing
var/atom/movable/thrownthing
var/atom/target
var/turf/target_turf
var/init_dir
var/maxrange
var/speed
var/mob/thrower
var/diagonals_first
var/dist_travelled = 0
var/start_time
var/dist_x
var/dist_y
var/dx
var/dy
var/pure_diagonal
var/diagonal_error
var/datum/callback/callback
/datum/thrownthing/proc/tick()
var/atom/movable/AM = thrownthing
if(!isturf(AM.loc) || !AM.throwing)
finalize()
return
if(dist_travelled && hitcheck()) //to catch sneaky things moving on our tile while we slept
finalize()
return
var/atom/step
// calculate how many tiles to move, making up for any missed ticks.
if((dist_travelled >= maxrange || AM.loc == target_turf) && has_gravity(AM, AM.loc))
finalize()
return
if(dist_travelled <= max(dist_x, dist_y)) //if we haven't reached the target yet we home in on it, otherwise we use the initial direction
step = get_step(AM, get_dir(AM, target_turf))
else
step = get_step(AM, init_dir)
if(!pure_diagonal && !diagonals_first) // not a purely diagonal trajectory and we don't want all diagonal moves to be done first
if(diagonal_error >= 0 && max(dist_x, dist_y) - dist_travelled != 1) // we do a step forward unless we're right before the target
step = get_step(AM, dx)
diagonal_error += (diagonal_error < 0) ? dist_x / 2 : -dist_y
if(!step) // going off the edge of the map makes get_step return null, don't let things go off the edge
finalize()
return
AM.Move(step, get_dir(AM, step))
if(!AM.throwing) // we hit something during our move
finalize(hit = TRUE)
return
dist_travelled++
if(dist_travelled > MAX_THROWING_DIST)
finalize()
return
/datum/thrownthing/proc/finalize(hit = FALSE)
set waitfor = 0
throw_master.processing_list -= thrownthing
// done throwning, either because it hit something or it finished moving
thrownthing.throwing = null
if(!hit)
for(var/thing in get_turf(thrownthing)) //looking for our target on the turf we land on.
var/atom/A = thing
if(A == target)
hit = 1
thrownthing.throw_impact(A, src)
break
if(!hit)
thrownthing.throw_impact(get_turf(thrownthing), src) // we haven't hit something yet and we still must, let's hit the ground.
thrownthing.newtonian_move(init_dir)
else
thrownthing.newtonian_move(init_dir)
if(callback)
callback.Invoke()
/datum/thrownthing/proc/hit_atom(atom/A)
thrownthing.throw_impact(A, src)
thrownthing.newtonian_move(init_dir)
finalize(TRUE)
/datum/thrownthing/proc/hitcheck()
for(var/thing in get_turf(thrownthing))
var/atom/movable/AM = thing
if(AM == thrownthing)
continue
if(AM.density && !(AM.pass_flags & LETPASSTHROW) && !(AM.flags & ON_BORDER))
thrownthing.throwing = null
thrownthing.throw_impact(AM, src)
return TRUE