Files
Paradise/code/game/objects/objs.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

384 lines
11 KiB
Plaintext

/obj
//var/datum/module/mod //not used
var/origin_tech = null //Used by R&D to determine what research bonuses it grants.
animate_movement = 2
var/list/species_exception = null // list() of species types, if a species cannot put items in a certain slot, but species type is in list, it will be able to wear that item
var/sharp = FALSE // whether this object cuts
var/in_use = FALSE // If we have a user using us, this will be set on. We will check if the user has stopped using us, and thus stop updating and LAGGING EVERYTHING!
var/damtype = "brute"
var/force = 0
// You can define armor as a list in datum definition (e.g. `armor = list("fire" = 80, "brute" = 10)`),
// which would be converted to armor datum during initialization.
// Setting `armor` to a list on an *existing* object would inevitably runtime. Use `getArmor()` instead.
var/datum/armor/armor
var/obj_integrity //defaults to max_integrity
var/max_integrity = 500
var/integrity_failure = 0 //0 if we have no special broken behavior
///Damage under this value will be completely ignored
var/damage_deflection = 0
var/resistance_flags = NONE // INDESTRUCTIBLE
var/custom_fire_overlay // Update_fire_overlay will check if a different icon state should be used
var/acid_level = 0 //how much acid is on that obj
var/can_be_hit = TRUE //can this be bludgeoned by items?
var/Mtoollink = FALSE // variable to decide if an object should show the multitool menu linking menu, not all objects use it
var/being_shocked = FALSE
var/speed_process = FALSE
var/on_blueprints = FALSE //Are we visible on the station blueprints at roundstart?
var/force_blueprints = FALSE //forces the obj to be on the blueprints, regardless of when it was created.
var/suicidal_hands = FALSE // Does it requires you to hold it to commit suicide with it?
/// Is it emagged or not?
var/emagged = FALSE
/obj/New()
..()
if(obj_integrity == null)
obj_integrity = max_integrity
if(on_blueprints && isturf(loc))
var/turf/T = loc
if(force_blueprints)
T.add_blueprints(src)
else
T.add_blueprints_preround(src)
/obj/Initialize(mapload)
. = ..()
if(islist(armor))
armor = getArmor(arglist(armor))
else if(!armor)
armor = getArmor()
else if(!istype(armor, /datum/armor))
stack_trace("Invalid type [armor.type] found in .armor during /obj Initialize()")
if(sharp)
AddComponent(/datum/component/surgery_initiator)
/obj/Topic(href, href_list, nowindow = FALSE, datum/ui_state/state = GLOB.default_state)
// Calling Topic without a corresponding window open causes runtime errors
if(!nowindow && ..())
return TRUE
// In the far future no checks are made in an overriding Topic() beyond if(..()) return
// Instead any such checks are made in CanUseTopic()
if(ui_status(usr, state, href_list) == STATUS_INTERACTIVE)
CouldUseTopic(usr)
return FALSE
CouldNotUseTopic(usr)
return TRUE
/obj/proc/CouldUseTopic(mob/user)
var/atom/host = ui_host()
host.add_fingerprint(user)
/obj/proc/CouldNotUseTopic(mob/user)
// Nada
/obj/Destroy()
if(!ismachinery(src))
if(!speed_process)
STOP_PROCESSING(SSobj, src) // TODO: Have a processing bitflag to reduce on unnecessary loops through the processing lists
else
STOP_PROCESSING(SSfastprocess, src)
return ..()
//user: The mob that is suiciding
//damagetype: The type of damage the item will inflict on the user
//BRUTELOSS = 1
//FIRELOSS = 2
//TOXLOSS = 4
//OXYLOSS = 8
//SHAME = 16
//OBLITERATION = 32
//Output a creative message and then return the damagetype done
/obj/proc/suicide_act(mob/user)
return FALSE
/obj/assume_air(datum/gas_mixture/giver)
if(loc)
return loc.assume_air(giver)
else
return null
/obj/remove_air(amount)
if(loc)
return loc.remove_air(amount)
else
return null
/obj/return_air()
if(loc)
return loc.return_air()
else
return null
/obj/proc/handle_internal_lifeform(mob/lifeform_inside_me, breath_request)
//Return: (NONSTANDARD)
// null if object handles breathing logic for lifeform
// datum/air_group to tell lifeform to process using that breath return
//DEFAULT: Take air from turf to give to have mob process
if(breath_request > 0)
var/datum/gas_mixture/environment = return_air()
var/breath_percentage = BREATH_VOLUME / environment.return_volume()
return remove_air(environment.total_moles() * breath_percentage)
else
return null
/obj/proc/updateUsrDialog()
if(in_use)
var/is_in_use = FALSE
var/list/nearby = viewers(1, src)
for(var/mob/M in nearby)
if((M.client && M.machine == src))
is_in_use = TRUE
src.attack_hand(M)
if(istype(usr, /mob/living/silicon/ai) || istype(usr, /mob/living/silicon/robot))
if(!(usr in nearby))
if(usr.client && usr.machine==src) // && M.machine == src is omitted because if we triggered this by using the dialog, it doesn't matter if our machine changed in between triggering it and this - the dialog is probably still supposed to refresh.
is_in_use = TRUE
src.attack_ai(usr)
// check for TK users
if(istype(usr, /mob/living/carbon/human))
if(istype(usr.l_hand, /obj/item/tk_grab) || istype(usr.r_hand, /obj/item/tk_grab/))
if(!(usr in nearby))
if(usr.client && usr.machine == src)
is_in_use = TRUE
src.attack_hand(usr)
in_use = is_in_use
/obj/proc/updateDialog()
// Check that people are actually using the machine. If not, don't update anymore.
if(in_use)
var/list/nearby = viewers(1, src)
var/is_in_use = FALSE
for(var/mob/M in nearby)
if((M.client && M.machine == src))
is_in_use = TRUE
src.interact(M)
var/ai_in_use = AutoUpdateAI(src)
if(!ai_in_use && !is_in_use)
in_use = FALSE
/obj/proc/interact(mob/user)
return
/mob/proc/unset_machine()
if(machine)
UnregisterSignal(machine, COMSIG_PARENT_QDELETING)
machine.on_unset_machine(src)
machine = null
//called when the user unsets the machine.
/atom/movable/proc/on_unset_machine(mob/user)
return
/mob/proc/set_machine(obj/O)
if(src.machine)
unset_machine()
src.machine = O
if(istype(O))
O.in_use = TRUE
RegisterSignal(O, COMSIG_PARENT_QDELETING, .proc/unset_machine)
/obj/item/proc/updateSelfDialog()
var/mob/M = src.loc
if(istype(M) && M.client && M.machine == src)
src.attack_self(M)
/obj/proc/hide(h)
return
/obj/proc/hear_talk(mob/M, list/message_pieces)
return
/obj/proc/hear_message(mob/M, text)
/obj/proc/multitool_menu(mob/user, obj/item/multitool/P)
return "<b>NO MULTITOOL_MENU!</b>"
/obj/proc/linkWith(mob/user, obj/buffer, context)
return FALSE
/obj/proc/unlinkFrom(mob/user, obj/buffer)
return FALSE
/obj/proc/canLink(obj/O, list/context)
return FALSE
/obj/proc/isLinkedWith(obj/O)
return FALSE
/obj/proc/getLink(idx)
return null
/obj/proc/linkMenu(obj/O)
var/dat = ""
if(canLink(O, list()))
dat += " <a href='?src=[UID()];link=1'>\[Link\]</a> "
return dat
/obj/proc/format_tag(label, varname, act = "set_tag")
var/value = vars[varname]
if(!value || value == "")
value = "-----"
return "<b>[label]:</b> <a href=\"?src=[UID()];[act]=[varname]\">[value]</a>"
/obj/proc/update_multitool_menu(mob/user)
var/obj/item/multitool/P = get_multitool(user)
if(!istype(P))
return FALSE
var/dat = {"<html>
<head>
<title>[name] Configuration</title>
<style type="text/css">
html,body {
font-family:courier;
background:#999999;
color:#333333;
}
a {
color:#000000;
text-decoration:none;
border-bottom:1px solid black;
}
</style>
</head>
<body>
<h3>[name]</h3>
"}
if(allowed(user))//no, assistants, you're not ruining all vents on the station with just a multitool
dat += multitool_menu(user, P)
if(Mtoollink)
if(P)
if(P.buffer)
var/id = null
if("id_tag" in P.buffer.vars)
id = P.buffer:id_tag
dat += "<p><b>MULTITOOL BUFFER:</b> [P.buffer] [id ? "([id])" : ""]"
dat += linkMenu(P.buffer)
if(P.buffer)
dat += "<a href='?src=[UID()];flush=1'>\[Flush\]</a>"
dat += "</p>"
else
dat += "<p><b>MULTITOOL BUFFER:</b> <a href='?src=[UID()];buffer=1'>\[Add Machine\]</a></p>"
else
dat += "<b>ACCESS DENIED</a>"
dat += "</body></html>"
user << browse(dat, "window=mtcomputer")
user.set_machine(src)
onclose(user, "mtcomputer")
/obj/proc/default_welder_repair(mob/user, obj/item/I) //Returns TRUE if the object was successfully repaired. Fully repairs an object (setting BROKEN to FALSE), default repair time = 40
if(obj_integrity >= max_integrity)
to_chat(user, "<span class='notice'>[src] does not need repairs.</span>")
return
if(I.tool_behaviour != TOOL_WELDER)
return
if(!I.tool_use_check(user, 0))
return
var/time = max(50 * (1 - obj_integrity / max_integrity), 5)
WELDER_ATTEMPT_REPAIR_MESSAGE
if(I.use_tool(src, user, time, volume = I.tool_volume))
WELDER_REPAIR_SUCCESS_MESSAGE
obj_integrity = max_integrity
update_icon()
return TRUE
/obj/proc/default_unfasten_wrench(mob/user, obj/item/I, time = 20)
if(!anchored && !isfloorturf(loc))
user.visible_message("<span class='warning'>A floor must be present to secure [src]!</span>")
return FALSE
if(I.tool_behaviour != TOOL_WRENCH)
return FALSE
if(!I.tool_use_check(user, 0))
return FALSE
if(!(flags & NODECONSTRUCT))
to_chat(user, "<span class='notice'>Now [anchored ? "un" : ""]securing [name].</span>")
if(I.use_tool(src, user, time, volume = I.tool_volume))
to_chat(user, "<span class='notice'>You've [anchored ? "un" : ""]secured [name].</span>")
anchored = !anchored
return TRUE
return FALSE
/obj/water_act(volume, temperature, source, method = REAGENT_TOUCH)
. = ..()
extinguish()
acid_level = 0
/obj/singularity_pull(S, current_size)
..()
if(!anchored || current_size >= STAGE_FIVE)
step_towards(src, S)
/obj/proc/container_resist(mob/living)
return
/obj/proc/CanAStarPass(ID, dir, caller)
. = !density
/obj/proc/on_mob_move(dir, mob/user)
return
/obj/proc/makeSpeedProcess()
if(speed_process)
return
speed_process = TRUE
STOP_PROCESSING(SSobj, src)
START_PROCESSING(SSfastprocess, src)
/obj/proc/makeNormalProcess()
if(!speed_process)
return
speed_process = FALSE
START_PROCESSING(SSobj, src)
STOP_PROCESSING(SSfastprocess, src)
/obj/vv_get_dropdown()
. = ..()
.["Delete all of type"] = "?_src_=vars;delall=[UID()]"
if(!speed_process)
.["Make speed process"] = "?_src_=vars;makespeedy=[UID()]"
else
.["Make normal process"] = "?_src_=vars;makenormalspeed=[UID()]"
.["Modify armor values"] = "?_src_=vars;modifyarmor=[UID()]"
/obj/proc/check_uplink_validity()
return TRUE
/obj/proc/cult_conceal() //Called by cult conceal spell
return
/obj/proc/cult_reveal() //Called by cult reveal spell and chaplain's bible
return
/// Set whether the item should be sharp or not
/obj/proc/set_sharpness(new_sharp_val)
if(sharp == new_sharp_val)
return
sharp = new_sharp_val
SEND_SIGNAL(src, COMSIG_ATOM_UPDATE_SHARPNESS)
if(!sharp && new_sharp_val)
AddComponent(/datum/component/surgery_initiator)
/obj/proc/force_eject_occupant(mob/target)
// This proc handles safely removing occupant mobs from the object if they must be teleported out (due to being SSD/AFK, by admin teleport, etc) or transformed.
// In the event that the object doesn't have an overriden version of this proc to do it, log a runtime so one can be added.
CRASH("Proc force_eject_occupant() is not overriden on a machine containing a mob.")