Skip to content

Commit

Permalink
refactor: surgery's code polishing, few fixes and tweaks (ss220-space…
Browse files Browse the repository at this point in the history
…#4436)

* refactor: surgery cleaning

* Vladisvell vision

* more plasmaman and insectitoid surgeries

* 2 -> define (merge changes)

* user zone, not target

* spanss macroses

* initiator spans too

* remove this while

* fixes
  • Loading branch information
Rerik007 authored Apr 12, 2024
1 parent 3582e46 commit 23de041
Show file tree
Hide file tree
Showing 77 changed files with 4,344 additions and 2,580 deletions.
14 changes: 12 additions & 2 deletions code/__DEFINES/dcs/signals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@
#define COMSIG_ATOM_ORBIT_STOP "atom_orbit_stop"
///from base of atom/hitby(atom/movable/AM, skipcatch, hitpush, blocked, datum/thrownthing/throwingdatum)
#define COMSIG_ATOM_HITBY "atom_hitby"
/// Called when an atom is sharpened or dulled.
#define COMSIG_ATOM_UPDATE_SHARPNESS "atom_update_sharpness"

// Attack signals. These should share the returned flags, to standardize the attack chain.
// The chain currently works like:
// tool_act -> pre_attackby -> target.attackby (item.attack) -> afterattack
// You can use these signal responses to cancel the attack chain at a certain point from most attack signal types.
/// This response cancels the attack chain entirely. If sent early, it might cause some later effects to be skipped.
#define COMPONENT_CANCEL_ATTACK_CHAIN (1<<0)

/////////////////
///from base of atom/attack_ghost(): (mob/dead/observer/ghost)
#define COMSIG_ATOM_ATTACK_GHOST "atom_attack_ghost"
Expand Down Expand Up @@ -583,8 +593,8 @@
///from base of obj/item/attack_obj(): (/obj, /mob)
#define COMSIG_ITEM_ATTACK_OBJ "item_attack_obj"
#define COMPONENT_NO_ATTACK_OBJ (1<<0)
///from base of obj/item/pre_attack(): (atom/target, mob/user, params)
#define COMSIG_ITEM_PRE_ATTACK "item_pre_attack"
///from base of obj/item/pre_attackby(): (atom/target, mob/user, params)
#define COMSIG_ITEM_PRE_ATTACKBY "item_pre_attackby"
#define COMPONENT_NO_ATTACK (1<<0)
///from base of obj/item/afterattack(): (atom/target, mob/user, params)
#define COMSIG_ITEM_AFTERATTACK "item_afterattack"
Expand Down
1 change: 1 addition & 0 deletions code/__DEFINES/genetics.dm
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,4 @@
#define EXOTIC_COLOR "exotic_blood_colour"
#define NO_OBESITY "no_obesity"
#define RUNIC_MIND "runic_mind"
#define REPEATSURGERY "repeat_syrgery"
2 changes: 1 addition & 1 deletion code/__DEFINES/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@

#define isexternalorgan(A) (istype((A), /obj/item/organ/external))

#define hasorgans(A) (ishuman(A))
#define hasorgans(A) (iscarbon(A))

#define is_admin(user) (check_rights(R_ADMIN, 0, (user)) != 0)

Expand Down
75 changes: 75 additions & 0 deletions code/__DEFINES/surgery_defines.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/// Defines for surgery and other stuff.


// Used in surgery step to determine how blood should be spread to the doc
/// Don't splash any blood.
#define SURGERY_BLOODSPREAD_NONE 0
/// Cover the surgeon's hands in blood.
#define SURGERY_BLOODSPREAD_HANDS 1
/// Cover the surgeon's body in blood.
#define SURGERY_BLOODSPREAD_FULLBODY 2

// The type of surgeries that an initiator can start.
// Note that this doesn't apply for surgeries applied on missing organs.
/// An initiator with this can start surgeries on organic organs. Make sure that anything that can be sharp gets this as well.
#define SURGERY_INITIATOR_ORGANIC 1
/// An initiator with this can start surgeries on robotic organs.
#define SURGERY_INITIATOR_ROBOTIC 2

// How "open" an organ is.

/// Closed up.
#define ORGAN_CLOSED 0

// Different defines for different organ types, though both can still reference ORGAN_CLOSED
/// An organic limb that's been opened, at least once.
#define ORGAN_ORGANIC_OPEN 1
/// An organ that's encased, probably with bone, where that casing has been cut through.
#define ORGAN_ORGANIC_ENCASED_OPEN 2

/// Synthetic organ that's been unscrewed.
#define ORGAN_SYNTHETIC_LOOSENED 3
/// Synthetic organ that's had its panel opened.
#define ORGAN_SYNTHETIC_OPEN 4

// Return defines for surgery steps

/// Return this from begin_step() to abort the step and not try the surgery.
#define SURGERY_BEGINSTEP_ABORT (-1)

/// Return this from begin_step() to skip the current step entirely and proceed to the next one.
/// Use this if you would end up leaving someone in an invalid state.
#define SURGERY_BEGINSTEP_SKIP (1)

// Return these from end_step/fail_step to indicate the next move

/// The surgery step was not completed for some reason, and the next action will again be on this step.
#define SURGERY_STEP_INCOMPLETE 0
/// The surgery step was completed, and the surgery should continue to the next step.
#define SURGERY_STEP_CONTINUE 1
/// This step will automatically be retried without question as long as this is returned.
/// Be very cautious with this one! Make sure that any flow where this is used has an exit condition where something else will be returned.
/// Otherwise, the user will be stuck in a loop!
#define SURGERY_STEP_RETRY_ALWAYS 2
/// This surgery step will be conditionally retried, so long as the surgery step's can_repeat() proc returns TRUE.
/// Otherwise, it'll behave just like SURGERY_STEP_INCOMPLETE.
#define SURGERY_STEP_RETRY 3


// Return values for surgery_step.initiate().
// Before you ask, yes, we need another definition for surgery steps here, since these control how we will act on the attack-chain
// side of things.
// Unless you're changing the mechanics of the surgery attack chain, you almost surely don't want to use these, and should
// instead be using the above SURGERY_STEP_X defines.

/// The surgery initiation isn't even going to be started. If you're working with the attack chain, this is probably what you'll be using.
#define SURGERY_INITIATE_CONTINUE_CHAIN 0

/// The surgery initiaition was a success. We're advancing the current surgery.
#define SURGERY_INITIATE_SUCCESS 1

/// The surgery initiation was interrupted, or for some reason never completed. We don't want to return FALSE to the attack chain, though.
#define SURGERY_INITIATE_FAILURE 2

/// The surgery never reached (or finished) the do_after. Go back to the state we were in before this even happened.
#define SURGERY_INITIATE_INTERRUPTED 3
25 changes: 25 additions & 0 deletions code/__DEFINES/tools.dm
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
// Tool tools
#define TOOL_CROWBAR "crowbar"
#define TOOL_MULTITOOL "multitool"
#define TOOL_SCREWDRIVER "screwdriver"
#define TOOL_WIRECUTTER "wirecutter"
#define TOOL_WRENCH "wrench"
#define TOOL_WELDER "welder"

// Surgery tools
#define TOOL_RETRACTOR "retractor"
#define TOOL_HEMOSTAT "hemostat"
#define TOOL_CAUTERY "cautery"
#define TOOL_DRILL "drill"
#define TOOL_SCALPEL "scalpel"
#define TOOL_SAW "saw"
#define TOOL_BONESET "bonesetter"
#define TOOL_BONEGEL "bonegel"
#define TOOL_FIXOVEIN "fixovein"

GLOBAL_LIST_INIT(surgery_tool_behaviors, list(
TOOL_RETRACTOR,
TOOL_HEMOSTAT,
TOOL_CAUTERY,
TOOL_DRILL,
TOOL_SCALPEL,
TOOL_SAW,
TOOL_BONESET,
TOOL_BONEGEL,
TOOL_FIXOVEIN,
TOOL_SCREWDRIVER
))

#define MIN_TOOL_SOUND_DELAY 20

//Crowbar messages
Expand Down
6 changes: 5 additions & 1 deletion code/__DEFINES/traits/declarations.dm
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,16 @@ Remember to update _globalvars/traits.dm if you're adding/removing/renaming trai
/// We have some form of forced gravity acting on us
#define TRAIT_FORCED_GRAVITY "forced_gravity"

//item traits
//***** ITEM TRAITS *****//
#define TRAIT_CMAGGED "cmagged"
/// The items needs two hands to be carried
#define TRAIT_NEEDS_TWO_HANDS "needstwohands"
/// Properly wielded two handed item
#define TRAIT_WIELDED "wielded"
/// A surgical tool; when in hand in help intent (and with a surgery in progress) won't attack the user
#define TRAIT_SURGICAL "surgical_tool"
/// An advanced surgical tool. If a surgical tool has this flag, it will be able to automatically repeat steps until they succeed.
#define TRAIT_ADVANCED_SURGICAL "advanced_surgical"

///Movement type traits for movables. See elements/movetype_handler.dm
#define TRAIT_MOVE_GROUND "move_ground"
Expand Down
6 changes: 6 additions & 0 deletions code/__HELPERS/tool_helpers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@
istype(W, /obj/item/bonegel) || \
istype(W, /obj/item/bonesetter)
)

/proc/is_surgery_tool_by_behavior(obj/item/W)
if(!istype(W))
return FALSE
var/tool_behavior = W.tool_behaviour
return tool_behavior in GLOB.surgery_tool_behaviors
3 changes: 2 additions & 1 deletion code/_onclick/click.dm
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@
animals lunging, etc.
*/
/mob/proc/RangedAttack(atom/A, params)
SEND_SIGNAL(src, COMSIG_MOB_ATTACK_RANGED, A, params)
if(SEND_SIGNAL(src, COMSIG_MOB_ATTACK_RANGED, A, params) & COMPONENT_CANCEL_ATTACK_CHAIN)
return TRUE
/*
Restrained ClickOn
Expand Down
30 changes: 8 additions & 22 deletions code/_onclick/item_attack.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@

// Called when the item is in the active hand, and clicked; alternately, there is an 'activate held object' verb or you can hit pagedown.
/obj/item/proc/attack_self(mob/user)
if(SEND_SIGNAL(src, COMSIG_ITEM_ATTACK_SELF, user) & COMPONENT_NO_INTERACT)
var/signal_ret = SEND_SIGNAL(src, COMSIG_ITEM_ATTACK_SELF, user)
if(signal_ret & COMPONENT_NO_INTERACT)
return
return
if(signal_ret & COMPONENT_CANCEL_ATTACK_CHAIN)
return TRUE

/obj/item/proc/pre_attackby(atom/A, mob/living/user, params) //do stuff before attackby!
if(SEND_SIGNAL(src, COMSIG_ITEM_PRE_ATTACKBY, A, user, params) & COMPONENT_CANCEL_ATTACK_CHAIN)
return TRUE
if(is_hot(src) && A.reagents && !ismob(A))
to_chat(user, "<span class='notice'>You heat [A] with [src].</span>")
A.reagents.temperature_reagents(is_hot(src))
Expand All @@ -40,29 +44,11 @@
return I.attack(src, user)

/obj/item/proc/attack(mob/living/target, mob/living/user, def_zone)
SEND_SIGNAL(src, COMSIG_ITEM_ATTACK, target, user)
if(SEND_SIGNAL(src, COMSIG_ITEM_ATTACK, target, user) & COMPONENT_CANCEL_ATTACK_CHAIN)
return TRUE
SEND_SIGNAL(user, COMSIG_MOB_ITEM_ATTACK, target, user)
if(flags & (NOBLUDGEON))
return FALSE
if(can_operate(target)) //Checks if mob is lying down on table for surgery
if(istype(src,/obj/item/robot_parts))//popup override for direct attach
if(!attempt_initiate_surgery(src, target, user,1))
return FALSE
else
return TRUE
if(istype(src,/obj/item/organ/external))
var/obj/item/organ/external/E = src
if(E.is_robotic()) // Robot limbs are less messy to attach
if(!attempt_initiate_surgery(src, target, user,1))
return FALSE
else
return TRUE
var/obj/item/organ/external/O = target.get_organ(user.zone_selected)
if((is_sharp(src) || (isscrewdriver(src) && O?.is_robotic())) && user.a_intent == INTENT_HELP)
if(!attempt_initiate_surgery(src, target, user))
return FALSE
else
return TRUE

if (check_item_eat(target, user))
return FALSE
Expand Down
8 changes: 4 additions & 4 deletions code/_onclick/observer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
examinate(A)

/atom/proc/attack_ghost(mob/dead/observer/user)
if(!istype(user))
return FALSE
if(SEND_SIGNAL(src, COMSIG_ATOM_ATTACK_GHOST, user) & COMPONENT_CANCEL_ATTACK_CHAIN)
return TRUE
if(user.client)
if(user.gas_scan && atmos_scan(user=user, target=src, silent=TRUE))
if(user.gas_scan && atmos_scan(user = user, target = src, silent = TRUE))
return TRUE
return FALSE

Expand All @@ -75,7 +75,7 @@
robot_healthscan(user, src)
else if(ishuman(src))
healthscan(user, src, 1, TRUE)
. = ..()
return ..()

// ---------------------------------------
// And here are some good things for free:
Expand Down
4 changes: 2 additions & 2 deletions code/_onclick/other_mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@


/atom/proc/attack_hand(mob/user)
SEND_SIGNAL(src, COMSIG_ATOM_ATTACK_HAND, user)
return
if(SEND_SIGNAL(src, COMSIG_ATOM_ATTACK_HAND, user) & COMPONENT_CANCEL_ATTACK_CHAIN)
return TRUE

/*
/mob/living/carbon/human/RestrainedClickOn(var/atom/A) -- Handled by carbons
Expand Down
Loading

0 comments on commit 23de041

Please sign in to comment.