Files
Paradise/code/modules/surgery/helpers.dm
Luc 346a1b8142 Yet Another Surgery Refactor (#18325)
* Initial commit

Fixes up surgery.dm
Adds some tool behavior

* More basic changes

* Checkpointing: this is a little gross right now

* Add signal COMPONENT_CANCEL_ATTACK_CHAIN

* Cleans up surgery initiator

* Mostly gets surgery (and canceling it) working

* Add abstract proxy surgery steps

Also adds them to organ manipulation

* Clean up most existing surgeries

* Rework organ openness, adds define for aborting a beginstep

* surgery works again, also implements retry defines

* fix surgery computer

* add limb repair to synth implant removal

* retry implant checks

* Clean up abductor surgeries as well as some other things

* A lot
- Reworks organ manipulation to use a series of surgery steps instead
- Fixes some runtimes with open hands
- Lets mito zero out the germ level while treating necrosis
- Adds a debug surgery tool

* add debug surgery tool, note some TODOs for later

* Add conditional check for surgeries repeating

* update surgery retry logic to make it more of a bonus

* Lets abductors automatically retry any failed surgery steps

* Rework robotic surgery to use abstract/proxy steps

* Bunch of bugfixes and more!
- Limb reattachment works properly now, you can just slap a limb onto a person
- If the limb isn't robotic, it'll be useless until the surgery is finished with a hemostat, though it might be enough to get the patient out of the OR.

* Remove more now-implicit checks

* Slight reorganization

* more fixes across the board

* Remove unused variable

* Trying not to lose my mind here
- Does away with can_run() entirely
- Cleans up visible messages in code
- begin steps should now all have ..() afterwards
- slime bone surgery should be fixed now
- more docs

* Robotic  surgery is stoppable with a crowbar, all surgery can_start now checks parent

* Fix some broken robotic typepaths

* Typepath fixes, do away with some last TODOs

* Forgor

* Last cleanups before we go gold

* jk lol

* Make early surgery termination clearer

* More "last" cleanups

* Fixes tool flags, surgery initiation

- Fixes surgery not being startable by sharp objects
- Moves surgical tool flags to item traits

* Clean up surgery cancellation, especially for borgos

* I think this should GC better

* Apply suggestions from code review

Co-authored-by: Sirryan2002 <80364400+Sirryan2002@users.noreply.github.com>

* Status is now step number

* Add a 20% chance to find nothing during organ manipulation

* Improve documentation, make forced_surgery a normal arg

* Charlie's reviews

* Why are abductors like this

* Little more verification, ensuring limb augmentation and organ manip healing work properly

* Fix torso organ manip being unfinishable

* Fix cavity implants, open-hand/any item steps

* Make sharp objects not try to start an operation with help intent

* Comments, quick target fix

* Re-order list so advanced bruise pack is pulled first

* Make surgical gripper function like an open hand

* Make mito only use one unit per organ for now

* Check if user is on operable surface before trying to operate

* Reduce admin logging

* Fix some bugs that appeared during the testmerge
- you can no longer start robotic surgeries with a scalpel (lol)
- you can now cancel surgeries on the first step after I fixed some bugs that I introduced (woo hoo)
- Synthetic limb attachment is now combined into a single startable surgery step, though still retains the fun flavor of both

* Swats some more bugs
- (hopefully) fixes a huge source of runtimes where we tried to check if we could run surgeries before checking if the surgery used an organ
- In doing so, moves the logic for determining if a surgery can start to the mob-level
- Fixes robotic reattachment surgery not working

* multi-bug drifting???

- Fixes a bug where a branching surgery with an any tool option could possibly override a step with a matching tool
- Fixes some intermediate surgeries failing due to not having specified possible_locs

* A few more fixes
- Fixes any surgery tool steps again
- Fixes cavity surgery again

* Hopefully fixes getting stuck in robotic organ manip

* Remove extra parent call

* Steel review

* Steel review

* Fix spacing for possible locs

* Roundstart traits

* Advanced surgical traits and other hal fixes

Co-authored-by: Sirryan2002 <80364400+Sirryan2002@users.noreply.github.com>
2022-09-16 18:48:43 +01:00

78 lines
3.0 KiB
Plaintext

/proc/get_pain_modifier(mob/living/carbon/human/target) //returns modfier to make surgery harder if patient is conscious and feels pain
if(target.stat == DEAD) // Operating on dead people is easy
return 1
var/datum/status_effect/incapacitating/sleeping/S = target.IsSleeping()
if(target.stat == UNCONSCIOUS && !(S?.voluntary))
// Either unconscious due to something other than sleep,
// or "sleeping" due to being hard knocked out (N2O or similar), rather than just napping.
// Either way, not easily woken up.
return 1
if(HAS_TRAIT(target, TRAIT_NOPAIN))//if you don't feel pain, you can hold still
return 1
if(target.reagents.has_reagent("hydrocodone"))//really good pain killer
return 0.99
if(target.reagents.has_reagent("morphine"))//Just as effective as Hydrocodone, but has an addiction chance
return 0.99
var/drunk = target.get_drunkenness()
if(drunk >= 80)//really damn drunk
return 0.95
if(drunk >= 40)//pretty drunk
return 0.9
if(target.reagents.has_reagent("sal_acid")) //it's better than nothing, as far as painkillers go.
return 0.85
if(drunk >= 15)//a little drunk
return 0.85
return 0.8 //20% failure chance
/proc/get_location_modifier(mob/target)
var/turf/T = get_turf(target)
if(locate(/obj/machinery/optable, T))
return 1
if(locate(/obj/structure/bed/roller/holo, T))
return 0.9
if(locate(/obj/structure/table, T) || locate(/obj/structure/bed/roller, T))
return 0.8
if(locate(/obj/structure/bed, T))
return 0.7
return 0.5
//check if mob is lying down on something we can operate on.
/proc/on_operable_surface(mob/living/carbon/target)
if(locate(/obj/machinery/optable, target.loc) && IS_HORIZONTAL(target))
return TRUE
if(locate(/obj/structure/bed, target.loc) && (IS_HORIZONTAL(target)))
return TRUE
if(locate(/obj/structure/table, target.loc) && (IS_HORIZONTAL(target)))
return TRUE
return FALSE
// Called when a limb containing this object is placed back on a body
/atom/movable/proc/attempt_become_organ(obj/item/organ/external/parent,mob/living/carbon/human/H)
return 0
/// Check to see if a surgical operation proposed on ourselves is valid or not. We are the target of the surgery
/mob/living/proc/can_run_surgery(datum/surgery/surgery, mob/surgeon, obj/item/organ/external/affecting)
if(!affecting)
// try to pull it if it isn't passed in (it's a parameter mostly for optimization purposes)
affecting = get_organ(check_zone(surgeon.zone_selected))
if(!surgery.possible_locs.Find(surgeon.zone_selected))
return
if(affecting)
if(!surgery.requires_bodypart)
return
if((surgery.requires_organic_bodypart && affecting.is_robotic()) || (!surgery.requires_organic_bodypart && !affecting.is_robotic()))
return
if(surgery.requires_real_bodypart && !affecting.is_primary_organ())
return
else if(surgery.requires_bodypart) //mob with no limb in surgery zone when we need a limb
return
if(surgery.lying_required && !IS_HORIZONTAL(src))
return
if(!surgery.self_operable && src == surgeon)
return
if(!surgery.can_start(surgeon, src))
return
return TRUE