Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact(surgery): make surgery a bit less painful to modify #10689

Merged
merged 37 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7534d21
make surgery_steps variable a GLOB
intercepti0n Oct 11, 2023
f027e32
disable old & enable new surgery_step
intercepti0n Oct 11, 2023
e5e53e4
update surgery_status field init
intercepti0n Oct 11, 2023
61ffe89
temporary disable medical integrated circuits
intercepti0n Oct 11, 2023
a0e6c94
properly disable medical circuits
intercepti0n Oct 14, 2023
3343211
improve surgery step code & add documentation
intercepti0n Oct 14, 2023
81f6a28
add more proc checks to surgery step
intercepti0n Oct 15, 2023
b7fde68
convert bone surgery steps
intercepti0n Oct 18, 2023
864b5b0
convert limb surgery steps
intercepti0n Oct 18, 2023
d40dc76
convert generic surgery steps
intercepti0n Oct 18, 2023
944f08f
update do_surgery proc logic
intercepti0n Oct 18, 2023
773ad71
remove old encased steps
intercepti0n Oct 18, 2023
e46e088
prettify old surgery helper procs
intercepti0n Oct 18, 2023
c3d961a
add extra checks to prevent tool switching during step
intercepti0n Oct 18, 2023
f798355
convert internal surgery steps
intercepti0n Oct 18, 2023
bda4fa6
convert face surgery steps
intercepti0n Oct 24, 2023
5162ba2
convert misc surgery steps
intercepti0n Oct 24, 2023
87fd190
purge metroid surgery steps
intercepti0n Oct 24, 2023
17220b6
purge remaining old surgery files
intercepti0n Oct 24, 2023
8220c02
fix associative issues
intercepti0n Oct 24, 2023
773b351
convert robotic surgery steps
intercepti0n Oct 24, 2023
4b90fb1
fix checks and proc calls in internal steps
intercepti0n Oct 24, 2023
25676b5
convert implant surgery steps
intercepti0n Oct 24, 2023
e22a083
fix logic in surgery status
intercepti0n Oct 24, 2023
5a87b05
add comments
intercepti0n Oct 24, 2023
d40717b
include surgery step files
intercepti0n Oct 24, 2023
ae39346
probably make integrated circuits work
intercepti0n Oct 24, 2023
6b604f5
fix integrated circuits not performing operations
intercepti0n Oct 25, 2023
669e39e
add fluff to some surgery errors
intercepti0n Oct 25, 2023
cf3e0e1
make Toby hate me less, at least i hope so
intercepti0n Oct 26, 2023
6f259fb
prettify radial menu canceling
intercepti0n Oct 26, 2023
37f7e61
make internal circuits work
intercepti0n Oct 26, 2023
f51b001
squash multiline comment
intercepti0n Oct 26, 2023
2a3bf74
fix zone check in head bone surgery step
intercepti0n Oct 27, 2023
b9db91c
add defines 'cause idk they're cool
intercepti0n Oct 27, 2023
6a0e91d
remove unhandled tool type
intercepti0n Oct 27, 2023
19cf19d
fix inability to cut limbs and insert organs
intercepti0n Oct 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions baystation12.dme
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
#include "code\_helpers\spawn_sync.dm"
#include "code\_helpers\sql.dm"
#include "code\_helpers\storage.dm"
#include "code\_helpers\surgery.dm"
#include "code\_helpers\text.dm"
#include "code\_helpers\text_processor.dm"
#include "code\_helpers\text_sql_encoding.dm"
Expand Down Expand Up @@ -450,6 +451,10 @@
#include "code\datums\supplypacks\security.dm"
#include "code\datums\supplypacks\supply.dm"
#include "code\datums\supplypacks\supplypack.dm"
#include "code\datums\surgery\_defines.dm"
#include "code\datums\surgery\surgery_item.dm"
#include "code\datums\surgery\surgery_status.dm"
#include "code\datums\surgery\surgery_step.dm"
#include "code\datums\trading\_trading_defines.dm"
#include "code\datums\trading\ai.dm"
#include "code\datums\trading\armor.dm"
Expand Down Expand Up @@ -1856,7 +1861,6 @@
#include "code\modules\integrated_electronics\subtypes\lists.dm"
#include "code\modules\integrated_electronics\subtypes\logic.dm"
#include "code\modules\integrated_electronics\subtypes\manipulation.dm"
#include "code\modules\integrated_electronics\subtypes\medical.dm"
#include "code\modules\integrated_electronics\subtypes\memory.dm"
#include "code\modules\integrated_electronics\subtypes\mining.dm"
#include "code\modules\integrated_electronics\subtypes\output.dm"
Expand Down Expand Up @@ -2801,19 +2805,6 @@
#include "code\modules\splash_text\splash_text.dm"
#include "code\modules\supermatter\setup_supermatter.dm"
#include "code\modules\supermatter\supermatter.dm"
#include "code\modules\surgery\_defines.dm"
#include "code\modules\surgery\bones.dm"
#include "code\modules\surgery\encased.dm"
#include "code\modules\surgery\face.dm"
#include "code\modules\surgery\generic.dm"
#include "code\modules\surgery\implant.dm"
#include "code\modules\surgery\limb_reattach.dm"
#include "code\modules\surgery\metroids.dm"
#include "code\modules\surgery\organs_internal.dm"
#include "code\modules\surgery\other.dm"
#include "code\modules\surgery\robotics.dm"
#include "code\modules\surgery\surgery.dm"
#include "code\modules\surgery\~defines.dm"
#include "code\modules\synthesized_instruments\echo_editor.dm"
#include "code\modules\synthesized_instruments\env_editor.dm"
#include "code\modules\synthesized_instruments\event_manager.dm"
Expand Down
5 changes: 0 additions & 5 deletions code/_helpers/global_access.dm
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,6 @@
return global.supply_drop;
if("supply_methods_")
return global.supply_methods_;
if("surgery_steps")
return global.surgery_steps;
if("swapmaps_byname")
return global.swapmaps_byname;
if("swapmaps_compiled_maxx")
Expand Down Expand Up @@ -1596,8 +1594,6 @@
global.supply_drop=newval;
if("supply_methods_")
global.supply_methods_=newval;
if("surgery_steps")
global.surgery_steps=newval;
if("swapmaps_byname")
global.swapmaps_byname=newval;
if("swapmaps_compiled_maxx")
Expand Down Expand Up @@ -2112,7 +2108,6 @@
"string_slot_flags",
"supply_drop",
"supply_methods_",
"surgery_steps",
"swapmaps_byname",
"swapmaps_compiled_maxx",
"swapmaps_compiled_maxy",
Expand Down
12 changes: 7 additions & 5 deletions code/_helpers/global_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ GLOBAL_LIST_EMPTY(landmarks_list) // List of all landmarks created.

var/global/list/cable_list = list() //Index for all cables, so that powernets don't have to look through the entire world all the time
var/global/list/chemical_reactions_list //list of all /datum/chemical_reaction datums. Used during chemical reactions
var/global/list/surgery_steps = list() //list of all surgery steps |BS12
var/global/list/side_effects = list() //list of all medical sideeffects types by thier names |BS12
var/global/list/mechas_list = list() //list of all mechs. Used by hostile mobs target tracking.
var/global/list/joblist = list() //list of all jobstypes, minus borg and AI
Expand Down Expand Up @@ -43,6 +42,9 @@ var/global/list/all_grabobjects[0]
// Uplinks
var/list/obj/item/device/uplink/world_uplinks = list()

// Surgery steps
GLOBAL_LIST_EMPTY(surgery_steps)

//Preferences stuff
//Hairstyles
GLOBAL_LIST_EMPTY(hair_styles_list) //stores /datum/sprite_accessory/hair indexed by name
Expand Down Expand Up @@ -185,10 +187,10 @@ var/global/list/string_slot_flags = list(
GLOB.body_marking_styles_list[M.name] = M

//Surgery Steps - Initialize all /datum/surgery_step into a list
paths = typesof(/datum/surgery_step)-/datum/surgery_step
for(var/T in paths)
var/datum/surgery_step/S = new T
surgery_steps += S
paths = typesof(/datum/surgery_step) - /datum/surgery_step
for(var/path in paths)
var/datum/surgery_step/S = new path()
GLOB.surgery_steps += S
sort_surgeries()

//List of job. I can't believe this was calculated multiple times per tick!
Expand Down
45 changes: 45 additions & 0 deletions code/_helpers/surgery.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/proc/sort_surgeries()
var/gap = length(GLOB.surgery_steps)
var/swapped = 1
while (gap > 1 || swapped)
swapped = 0
if(gap > 1)
gap = round(gap / 1.247330950103979)
if(gap < 1)
gap = 1
for(var/i = 1; gap + i <= length(GLOB.surgery_steps); i++)
var/datum/surgery_step/l = GLOB.surgery_steps[i] //Fucking hate
intercepti0n marked this conversation as resolved.
Show resolved Hide resolved
var/datum/surgery_step/r = GLOB.surgery_steps[gap+i] //how lists work here
if(l.priority < r.priority)
GLOB.surgery_steps.Swap(i, gap + i)
swapped = 1
intercepti0n marked this conversation as resolved.
Show resolved Hide resolved

//check if mob is lying down on something we can operate him on.
/proc/can_operate(mob/living/carbon/M, mob/living/carbon/user)
var/turf/T = get_turf(M)
if(locate(/obj/machinery/optable, T))
. = TRUE
if(locate(/obj/structure/bed, T))
. = TRUE
if(locate(/obj/structure/table, T))
. = TRUE
if(locate(/obj/effect/rune/, T))
. = TRUE

if(M == user)
var/hitzone = check_zone(user.zone_sel.selecting)
var/list/badzones = list(BP_HEAD)
if(user.hand)
badzones += BP_L_ARM
badzones += BP_L_HAND
else
badzones += BP_R_ARM
badzones += BP_R_HAND
if(hitzone in badzones)
return FALSE

/proc/agjust_organ_image(obj/item/organ/O)
var/image/I = image(icon = O.icon, icon_state = O.icon_state)
I.overlays = O.overlays
I.pixel_y = -5
return I
24 changes: 0 additions & 24 deletions code/_helpers/unsorted.dm
Original file line number Diff line number Diff line change
Expand Up @@ -945,30 +945,6 @@ var/global/list/common_tools = list(
/obj/item/clothing/mask/smokable/cigarette/can_puncture()
return lit

//check if mob is lying down on something we can operate him on.
/proc/can_operate(mob/living/carbon/M, mob/living/carbon/user)
var/turf/T = get_turf(M)
if(locate(/obj/machinery/optable, T))
. = TRUE
if(locate(/obj/structure/bed, T))
. = TRUE
if(locate(/obj/structure/table, T))
. = TRUE
if(locate(/obj/effect/rune/, T))
. = TRUE

if(M == user)
var/hitzone = check_zone(user.zone_sel.selecting)
var/list/badzones = list(BP_HEAD)
if(user.hand)
badzones += BP_L_ARM
badzones += BP_L_HAND
else
badzones += BP_R_ARM
badzones += BP_R_HAND
if(hitzone in badzones)
return FALSE

/proc/reverse_direction(dir)
switch(dir)
if(NORTH)
Expand Down
8 changes: 5 additions & 3 deletions code/_onclick/item_attack.dm
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ avoid code duplication. This includes items that may sometimes act as a standard

/mob/living/attackby(obj/item/I, mob/user)
if(!ismob(user))
return 0
if(can_operate(src, user) && I.do_surgery(src, user)) //Surgery
return 1
return FALSE

if(can_operate(src, user) && I.do_surgery(src, user))
return TRUE

return I.attack(src, user, user.zone_sel.selecting)

/mob/living/carbon/human/attackby(obj/item/I, mob/user)
Expand Down
23 changes: 23 additions & 0 deletions code/datums/surgery/_defines.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// Causes hands to become bloody.
#define BLOODY_HANDS (1 << 0)
/// Causes body to become bloody.
#define BLOODY_BODY (1 << 1)

/// Delta multiplier for all surgeries, ranges from 0.9 to 1.1.
#define SURGERY_DURATION_DELTA rand(9, 11) / 10

#define SURGERY_FAILURE -1
#define SURGERY_BLOCKED -2

#define CUT_DURATION 30
#define AMPUTATION_DURATION 125
#define CLAMP_DURATION 35
#define RETRACT_DURATION 25
#define CAUTERIZE_DURATION 35
#define GLUE_BONE_DURATION 35
#define BONE_MEND_DURATION 40
#define SAW_DURATION 50
#define DRILL_DURATION 70
#define ATTACH_DURATION 50
#define ORGAN_FIX_DURATION 35
#define CONNECT_DURATION 50
17 changes: 17 additions & 0 deletions code/datums/surgery/surgery_item.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/obj/item/proc/do_surgery(mob/living/carbon/target, mob/living/user)
if (!istype(target))
return FALSE

if (user.a_intent == I_HURT)
return FALSE

var/zone = user.zone_sel.selecting
if(zone in target.surgery_status.ongoing_steps)
to_chat(user, SPAN("warning", "You can't operate on this area while surgery is already in progress."))
return TRUE

for(var/datum/surgery_step/S in GLOB.surgery_steps)
if(S.do_step(user, target, src, zone))
return TRUE

return FALSE
20 changes: 20 additions & 0 deletions code/datums/surgery/surgery_status.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/datum/surgery_status
/**
* List of zones where surgery steps are currently performed.
*/
var/list/ongoing_steps = list()
/**
* Associative list of string -> type, where string is zone name and
* type is a reference to an operated organ.
*
* Exists 'cause of integrated crcuits.
*/
var/list/operated_organs = list()

/datum/surgery_status/proc/start_surgery(obj/item/organ/target_organ, target_zone)
LAZYADD(ongoing_steps, target_zone)
LAZYADDASSOC(operated_organs, target_zone, target_organ)

/datum/surgery_status/proc/stop_surgery(target_zone)
LAZYREMOVE(ongoing_steps, target_zone)
LAZYREMOVE(operated_organs, target_zone)
Loading
Loading