VS: Fix a destroy by creating a subsystem

This commit is contained in:
Arokha Sieyes
2018-02-20 00:21:42 -05:00
parent e3215c98e1
commit f47ae8e03c
2 changed files with 85 additions and 33 deletions

View File

@@ -1,3 +1,6 @@
#define SSTRANSCORE_IMPLANTS 1
#define SSTRANSCORE_BACKUPS 2
////////////////////////////////
//// Mind/body data storage system
//// for the resleeving tech
@@ -6,39 +9,102 @@
SUBSYSTEM_DEF(transcore)
name = "Transcore"
priority = 20
wait = 1 MINUTE
flags = SS_BACKGROUND|SS_NO_TICK_CHECK|SS_NO_INIT
wait = 3 MINUTES
flags = SS_BACKGROUND|SS_NO_INIT
runlevels = RUNLEVEL_GAME
// THINGS
var/overdue_time = 15 MINUTES
var/core_dumped = FALSE // Core has been dumped! Also set can_fire = 0 when you set this.
var/current_step = SSTRANSCORE_IMPLANTS
var/cost_backups = 0
var/cost_implants = 0
var/datum/transhuman/mind_record/list/backed_up = list() // All known mind records, indexed by MR.mindname/mind.name
var/datum/transhuman/mind_record/list/has_left = list() // Why do we even have this?
var/datum/transhuman/body_record/list/body_scans = list() // All known body records, indexed by BR.mydna.name
var/obj/item/weapon/implant/backup/list/implants = list() // All OPERATING implants that are being ticked
/datum/controller/subsystem/transcore/fire()
for(var/N in backed_up)
var/datum/transhuman/mind_record/curr_MR = backed_up[N]
if(!curr_MR)
log_debug("Tried to process [N] in transcore w/o a record!")
var/list/current_run = list()
/datum/controller/subsystem/transcore/fire(resumed = 0)
var/timer = TICK_USAGE
INTERNAL_PROCESS_STEP(SSTRANSCORE_IMPLANTS,TRUE,process_implants,cost_implants,SSTRANSCORE_BACKUPS)
INTERNAL_PROCESS_STEP(SSTRANSCORE_BACKUPS,FALSE,process_backups,cost_backups,SSTRANSCORE_IMPLANTS)
/datum/controller/subsystem/transcore/proc/process_implants(resumed = 0)
if (!resumed)
src.current_run = implants.Copy()
var/list/current_run = src.current_run
while(current_run.len)
var/obj/item/weapon/implant/backup/imp = current_run[current_run.len]
current_run.len--
//Remove if not in a human anymore.
if(!imp || !ishuman(imp.loc))
implants -= imp
continue
//We're in a human, at least.
var/mob/living/carbon/human/H = imp.loc
BITSET(H.hud_updateflag, BACKUP_HUD)
if(H == imp.imp_in && H.mind && H.stat < DEAD)
SStranscore.m_backup(H.mind,H.nif)
persist_nif_data(H)
if(MC_TICK_CHECK)
return
/datum/controller/subsystem/transcore/proc/process_backups(resumed = 0)
if (!resumed)
src.current_run = backed_up.Copy()
var/list/current_run = src.current_run
while(current_run.len)
var/name = current_run[current_run.len]
var/datum/transhuman/mind_record/curr_MR = current_run[name]
current_run -= name
//Invalid record
if(!curr_MR)
log_debug("Tried to process [name] in transcore w/o a record!")
backed_up -= name
continue
//Onetimes do not get processing or notifications
if(curr_MR.one_time)
continue
//Timing check
var/since_backup = world.time - curr_MR.last_update
if(since_backup < overdue_time)
curr_MR.dead_state = MR_NORMAL
else
if(curr_MR.dead_state != MR_DEAD) //First time switching to dead
notify(N)
notify(name)
curr_MR.dead_state = MR_DEAD
/datum/controller/subsystem/transcore/stat_entry(msg)
if(MC_TICK_CHECK)
return
/datum/controller/subsystem/transcore/stat_entry()
var/msg = list()
if(core_dumped)
msg += "CORE DUMPED | "
msg += "MR: [backed_up.len] | BR: [body_scans.len]"
..(msg)
msg += "$:{"
msg += "IM:[round(cost_implants,1)]|"
msg += "BK:[round(cost_backups,1)]"
msg += "} "
msg += "#:{"
msg += "IM:[implants.len]|"
msg += "BK:[backed_up.len]"
msg += "} "
..(jointext(msg, null))
/datum/controller/subsystem/transcore/Recover()
if (istype(SStranscore.body_scans))
@@ -131,3 +197,6 @@ SUBSYSTEM_DEF(transcore)
core_dumped = TRUE
can_fire = FALSE
return disk.stored.len
#undef SSTRANSCORE_BACKUPS
#undef SSTRANSCORE_IMPLANTS

View File

@@ -9,8 +9,6 @@
desc = "A mindstate backup implant that occasionally stores a copy of one's mind on a central server for backup purposes."
icon = 'icons/vore/custom_items_vr.dmi'
icon_state = "backup_implant"
var/last_attempt
var/attempt_delay = 5 MINUTES
/obj/item/weapon/implant/backup/get_data()
var/dat = {"
@@ -25,6 +23,10 @@
<b>Integrity:</b> Generally very survivable. Susceptible to being destroyed by acid."}
return dat
/obj/item/weapon/implant/backup/Destroy()
SStranscore.implants -= src
return ..()
/obj/item/weapon/implant/backup/implanted(var/mob/living/carbon/human/H)
..()
if(istype(H))
@@ -32,29 +34,10 @@
if(other_imp && other_imp.imp_in == H)
qdel(other_imp) //implant fight
if(H.mind && H.stat < DEAD) //One right now, on implanting.
SStranscore.m_backup(H.mind)
last_attempt = world.time
backup()
SStranscore.implants |= src
return 1
/obj/item/weapon/implant/backup/proc/backup()
last_attempt = world.time
var/mob/living/carbon/human/H = loc
//We're in a human, at least.
if(istype(H))
BITSET(H.hud_updateflag, BACKUP_HUD)
//Okay we've got a mind at least
if(H == imp_in && H.mind && H.stat < DEAD)
SStranscore.m_backup(H.mind,H.nif)
persist_nif_data(H)
spawn(attempt_delay)
backup()
//New, modern implanter instead of old style implanter.
/obj/item/weapon/backup_implanter
name = "backup implanter"