Skip to content

Commit

Permalink
refact(surgery): make surgery a bit less painful to modify
Browse files Browse the repository at this point in the history
  • Loading branch information
intercepti0n authored Oct 29, 2023
1 parent 8beb0cd commit dc1bd56
Show file tree
Hide file tree
Showing 35 changed files with 3,284 additions and 3,035 deletions.
26 changes: 13 additions & 13 deletions baystation12.dme
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,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 @@ -459,6 +460,18 @@
#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\surgery\steps\bone.dm"
#include "code\datums\surgery\steps\face.dm"
#include "code\datums\surgery\steps\generic.dm"
#include "code\datums\surgery\steps\implant.dm"
#include "code\datums\surgery\steps\internal.dm"
#include "code\datums\surgery\steps\limb.dm"
#include "code\datums\surgery\steps\misc.dm"
#include "code\datums\surgery\steps\robotic.dm"
#include "code\datums\trading\_trading_defines.dm"
#include "code\datums\trading\ai.dm"
#include "code\datums\trading\armor.dm"
Expand Down Expand Up @@ -2832,19 +2845,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
23 changes: 23 additions & 0 deletions code/_helpers/surgery.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// Sorts GLOB surgeries list by priority.
/proc/sort_surgeries()
var/gap = length(GLOB.surgery_steps)
var/swapped = TRUE
while(gap > 1 || swapped)
swapped = FALSE
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]
var/datum/surgery_step/r = GLOB.surgery_steps[gap + i]
if(l.priority < r.priority)
GLOB.surgery_steps.Swap(i, gap + i)
swapped = TRUE

/// Creates and "centers" organ image for later use inside radial menu.
/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 @@ -969,30 +969,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,8 @@ 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

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

/mob/living/carbon/human/attackby(obj/item/I, mob/user)
Expand All @@ -154,4 +153,7 @@ avoid code duplication. This includes items that may sometimes act as a standard
else if(devour(I))
return 1

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

return ..()
25 changes: 25 additions & 0 deletions code/datums/surgery/_defines.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#define SURGERY_FAILURE -1

/// 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 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
#define STERILIZATION_DURATION 55
#define DETATCH_DURATION 52
#define TREAT_NECROSIS_DURATION 26
Loading

0 comments on commit dc1bd56

Please sign in to comment.