Skip to content

Commit

Permalink
refactor: move defib code to component (#4406)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rerik007 authored Feb 20, 2024
1 parent 634fb03 commit dc10271
Show file tree
Hide file tree
Showing 9 changed files with 564 additions and 292 deletions.
13 changes: 13 additions & 0 deletions code/__DEFINES/dcs/signals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,19 @@
///from [/obj/effect/mine/proc/triggermine]:
#define COMSIG_MINE_TRIGGERED "minegoboom"

/// Defib-specific signals

/// Called when a defibrillator is first applied to someone. (mob/living/user, mob/living/target, harmful)
#define COMSIG_DEFIB_PADDLES_APPLIED "defib_paddles_applied"
/// Defib is out of power.
#define COMPONENT_BLOCK_DEFIB_DEAD (1<<0)
/// Something else: we won't have a custom message for this and should let the defib handle it.
#define COMPONENT_BLOCK_DEFIB_MISC (1<<1)
/// Called when a defib has been successfully used, and a shock has been applied. (mob/living/user, mob/living/target, harmful, successful)
#define COMSIG_DEFIB_SHOCK_APPLIED "defib_zap"
/// Called when a defib's cooldown has run its course and it is once again ready. ()
#define COMSIG_DEFIB_READY "defib_ready"

// /obj/item signals for economy
///called when an item is sold by the exports subsystem
#define COMSIG_ITEM_SOLD "item_sold"
Expand Down
4 changes: 2 additions & 2 deletions code/__DEFINES/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@

// Defib stats
/// Past this much time the patient is unrecoverable (in deciseconds).
#define DEFIB_TIME_LIMIT 300 SECONDS
#define DEFIB_TIME_LIMIT (300 SECONDS)
/// Brain damage starts setting in on the patient after some time left rotting.
#define DEFIB_TIME_LOSS 60 SECONDS
#define DEFIB_TIME_LOSS (60 SECONDS)

//different types of atom colorations
#define ADMIN_COLOUR_PRIORITY 1 //only used by rare effects like greentext coloring mobs and when admins varedit color
Expand Down
387 changes: 387 additions & 0 deletions code/datums/components/defibrillator.dm

Large diffs are not rendered by default.

50 changes: 12 additions & 38 deletions code/datums/mind.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2455,46 +2455,20 @@
log_and_message_admins("has opened [S]'s law manager.")
if("unemag")
var/mob/living/silicon/robot/R = current
if(istype(R))
R.emagged = 0
if(R.module)
if(R.activated(R.module.emag))
R.module_active = null
if(R.module_state_1 == R.module.emag)
R.module_state_1 = null
R.contents -= R.module.emag
else if(R.module_state_2 == R.module.emag)
R.module_state_2 = null
R.contents -= R.module.emag
else if(R.module_state_3 == R.module.emag)
R.module_state_3 = null
R.contents -= R.module.emag
R.clear_supplied_laws()
R.laws = new /datum/ai_laws/crewsimov
log_admin("[key_name(usr)] has un-emagged [key_name(current)]")
message_admins("[key_name_admin(usr)] has un-emagged [key_name_admin(current)]")
if(!istype(R))
return
R.unemag()
log_admin("[key_name(usr)] has un-emagged [key_name(current)]")
message_admins("[key_name_admin(usr)] has un-emagged [key_name_admin(current)]")

if("unemagcyborgs")
if(isAI(current))
var/mob/living/silicon/ai/ai = current
for(var/mob/living/silicon/robot/R in ai.connected_robots)
R.emagged = 0
if(R.module)
if(R.activated(R.module.emag))
R.module_active = null
if(R.module_state_1 == R.module.emag)
R.module_state_1 = null
R.contents -= R.module.emag
else if(R.module_state_2 == R.module.emag)
R.module_state_2 = null
R.contents -= R.module.emag
else if(R.module_state_3 == R.module.emag)
R.module_state_3 = null
R.contents -= R.module.emag
R.clear_supplied_laws()
R.laws = new /datum/ai_laws/crewsimov
log_admin("[key_name(usr)] has unemagged [key_name(ai)]'s cyborgs")
message_admins("[key_name_admin(usr)] has unemagged [key_name_admin(ai)]'s cyborgs")
if(!isAI(current))
return
var/mob/living/silicon/ai/ai = current
for(var/mob/living/silicon/robot/R in ai.connected_robots)
R.unemag()
log_admin("[key_name(usr)] has unemagged [key_name(ai)]'s cyborgs")
message_admins("[key_name_admin(usr)] has unemagged [key_name_admin(ai)]'s cyborgs")

else if(href_list["common"])
switch(href_list["common"])
Expand Down
5 changes: 4 additions & 1 deletion code/game/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
return

/atom/proc/emp_act(severity)
return
SEND_SIGNAL(src, COMSIG_ATOM_EMP_ACT, severity)

//amount of water acting : temperature of water in kelvin : object that called it (for shennagins)
/atom/proc/water_act(volume, temperature, source, method = REAGENT_TOUCH)
Expand Down Expand Up @@ -541,6 +541,9 @@
return

/atom/proc/emag_act(mob/user)
SEND_SIGNAL(src, COMSIG_ATOM_EMAG_ACT, user)

/atom/proc/unemag()
return

/atom/proc/cmag_act(mob/user)
Expand Down
Loading

0 comments on commit dc10271

Please sign in to comment.