Files
Paradise/code/game/objects/items/robot/robot_parts.dm
T
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

429 lines
13 KiB
Plaintext

/obj/item/robot_parts
name = "robot parts"
icon = 'icons/obj/robot_parts.dmi'
item_state = "buildpipe"
icon_state = "blank"
flags = CONDUCT
slot_flags = SLOT_BELT
var/list/part = null
var/sabotaged = FALSE //Emagging limbs can have repercussions when installed as prosthetics.
var/model_info = "Unbranded"
dir = SOUTH
/obj/item/robot_parts/New(newloc, model)
..(newloc)
if(model_info && model)
model_info = model
var/datum/robolimb/R = GLOB.all_robolimbs[model]
if(R)
name = "[R.company] [initial(name)]"
desc = "[R.desc]"
if(icon_state in icon_states(R.icon))
icon = R.icon
else
name = "robot [initial(name)]"
AddComponent(/datum/component/surgery_initiator/limb, forced_surgery = /datum/surgery/attach_robotic_limb)
/obj/item/robot_parts/attack_self(mob/user)
var/choice = input(user, "Select the company appearance for this limb.", "Limb Company Selection") as null|anything in GLOB.selectable_robolimbs
if(!choice)
return
if(loc != user)
return
model_info = choice
to_chat(usr, "<span class='notice'>You change the company limb model to [choice].</span>")
/obj/item/robot_parts/l_arm
name = "left arm"
desc = "A skeletal limb wrapped in pseudomuscles, with a low-conductivity case."
icon_state = "l_arm"
part = list("l_arm","l_hand")
/obj/item/robot_parts/r_arm
name = "right arm"
desc = "A skeletal limb wrapped in pseudomuscles, with a low-conductivity case."
icon_state = "r_arm"
part = list("r_arm","r_hand")
/obj/item/robot_parts/l_leg
name = "left leg"
desc = "A skeletal limb wrapped in pseudomuscles, with a low-conductivity case."
icon_state = "l_leg"
part = list("l_leg","l_foot")
/obj/item/robot_parts/r_leg
name = "right leg"
desc = "A skeletal limb wrapped in pseudomuscles, with a low-conductivity case."
icon_state = "r_leg"
part = list("r_leg","r_foot")
/obj/item/robot_parts/chest
name = "torso"
desc = "A heavily reinforced case containing cyborg logic boards, with space for a standard power cell."
icon_state = "chest"
part = list("groin","chest")
var/wired = FALSE
var/obj/item/stock_parts/cell/cell = null
/obj/item/robot_parts/chest/Destroy()
QDEL_NULL(cell)
return ..()
/obj/item/robot_parts/head
name = "head"
desc = "A standard reinforced braincase, with spine-plugged neural socket and sensor gimbals."
icon_state = "head"
part = list("head")
var/obj/item/flash/flash1 = null
var/obj/item/flash/flash2 = null
/obj/item/robot_parts/head/Destroy()
QDEL_NULL(flash1)
QDEL_NULL(flash2)
return ..()
/obj/item/robot_parts/robot_suit
name = "endoskeleton"
desc = "A complex metal backbone with standard limb sockets and pseudomuscle anchors."
icon_state = "robo_suit"
model_info = null
var/obj/item/robot_parts/l_arm/l_arm = null
var/obj/item/robot_parts/r_arm/r_arm = null
var/obj/item/robot_parts/l_leg/l_leg = null
var/obj/item/robot_parts/r_leg/r_leg = null
var/obj/item/robot_parts/chest/chest = null
var/obj/item/robot_parts/head/head = null
var/created_name = ""
var/mob/living/silicon/ai/forced_ai
var/locomotion = 1
var/lawsync = 1
var/aisync = 1
var/panel_locked = 1
/obj/item/robot_parts/robot_suit/New()
..()
update_icon(UPDATE_OVERLAYS)
/obj/item/robot_parts/robot_suit/Destroy()
QDEL_NULL(l_arm)
QDEL_NULL(r_arm)
QDEL_NULL(l_leg)
QDEL_NULL(r_leg)
QDEL_NULL(chest)
QDEL_NULL(head)
forced_ai = null
return ..()
/obj/item/robot_parts/robot_suit/attack_self(mob/user)
return
/obj/item/robot_parts/robot_suit/update_overlays()
. = ..()
if(l_arm)
. += "l_arm+o"
if(r_arm)
. += "r_arm+o"
if(chest)
. += "chest+o"
if(l_leg)
. += "l_leg+o"
if(r_leg)
. += "r_leg+o"
if(head)
. += "head+o"
/obj/item/robot_parts/robot_suit/proc/check_completion()
if(l_arm && r_arm)
if(l_leg && r_leg)
if(chest && head)
SSblackbox.record_feedback("amount", "cyborg_frames_built", 1)
return 1
return 0
/obj/item/robot_parts/robot_suit/attackby(obj/item/W, mob/user, params)
..()
if(istype(W, /obj/item/stack/sheet/metal) && !l_arm && !r_arm && !l_leg && !r_leg && !chest && !head)
var/obj/item/stack/sheet/metal/M = W
var/obj/item/ed209_assembly/B = new /obj/item/ed209_assembly
B.forceMove(get_turf(src))
to_chat(user, "You armed the robot frame")
M.use(1)
if(user.get_inactive_hand()==src)
user.unEquip(src)
user.put_in_inactive_hand(B)
qdel(src)
if(istype(W, /obj/item/robot_parts/l_leg))
if(l_leg)
return
user.drop_item()
W.forceMove(src)
l_leg = W
update_icon(UPDATE_OVERLAYS)
if(istype(W, /obj/item/robot_parts/r_leg))
if(r_leg)
return
user.drop_item()
W.forceMove(src)
r_leg = W
update_icon(UPDATE_OVERLAYS)
if(istype(W, /obj/item/robot_parts/l_arm))
if(l_arm)
return
user.drop_item()
W.forceMove(src)
l_arm = W
update_icon(UPDATE_OVERLAYS)
if(istype(W, /obj/item/robot_parts/r_arm))
if(r_arm)
return
user.drop_item()
W.forceMove(src)
r_arm = W
update_icon(UPDATE_OVERLAYS)
if(istype(W, /obj/item/robot_parts/chest))
var/obj/item/robot_parts/chest/CH = W
if(chest)
return
if(CH.wired && CH.cell)
user.drop_item()
W.forceMove(src)
chest = W
update_icon(UPDATE_OVERLAYS)
else if(!CH.wired)
to_chat(user, "<span class='notice'>You need to attach wires to it first!</span>")
else
to_chat(user, "<span class='notice'>You need to attach a cell to it first!</span>")
if(istype(W, /obj/item/robot_parts/head))
var/obj/item/robot_parts/head/HD = W
if(head)
return
if(HD.flash2 && HD.flash1)
user.drop_item()
W.forceMove(src)
head = W
update_icon(UPDATE_OVERLAYS)
else
to_chat(user, "<span class='notice'>You need to attach a flash to it first!</span>")
if(istype(W, /obj/item/multitool))
if(check_completion())
Interact(user)
else
to_chat(user, "<span class='warning'>The endoskeleton must be assembled before debugging can begin!</span>")
if(istype(W, /obj/item/mmi))
var/obj/item/mmi/M = W
if(check_completion())
if(!isturf(loc))
to_chat(user, "<span class='warning'>You can't put [M] in, the frame has to be standing on the ground to be perfectly precise.</span>")
return
if(!M.brainmob)
to_chat(user, "<span class='warning'>Sticking an empty [M] into the frame would sort of defeat the purpose.</span>")
return
if(jobban_isbanned(M.brainmob, "Cyborg") || jobban_isbanned(M.brainmob, "nonhumandept"))
to_chat(user, "<span class='warning'>This [W] is not fit to serve as a cyborg!</span>")
return
if(!M.brainmob.key)
var/ghost_can_reenter = FALSE
if(M.brainmob.mind)
for(var/mob/dead/observer/G in GLOB.player_list)
if(G.can_reenter_corpse && G.mind == M.brainmob.mind)
ghost_can_reenter = TRUE
if(M.next_possible_ghost_ping < world.time)
G.notify_cloning("Somebody is trying to borg you! Re-enter your corpse if you want to be borged!", 'sound/voice/liveagain.ogg', src)
M.next_possible_ghost_ping = world.time + 30 SECONDS // Avoid spam
break
if(!ghost_can_reenter)
to_chat(user, "<span class='notice'>[M] is completely unresponsive; there's no point.</span>")
else
to_chat(user, "<span class='warning'>[M] is currently inactive. Try again later.</span>")
return
if(M.brainmob.stat == DEAD)
to_chat(user, "<span class='warning'>Sticking a dead [M] into the frame would sort of defeat the purpose.</span>")
return
if(M.brainmob.mind in SSticker.mode.head_revolutionaries)
to_chat(user, "<span class='warning'>The frame's firmware lets out a shrill sound, and flashes 'Abnormal Memory Engram'. It refuses to accept [M].</span>")
return
var/datum/ai_laws/laws_to_give
if(!aisync)
lawsync = FALSE
var/mob/living/silicon/robot/O = new /mob/living/silicon/robot(get_turf(loc), unfinished = 1, ai_to_sync_to = forced_ai)
if(!O)
return
user.drop_item()
var/datum/job_objective/make_cyborg/task = user.mind.findJobTask(/datum/job_objective/make_cyborg)
if(istype(task))
task.unit_completed()
O.invisibility = 0
//Transfer debug settings to new mob
O.custom_name = created_name
O.rename_character(O.real_name, O.get_default_name())
O.locked = panel_locked
if(laws_to_give)
O.laws = laws_to_give
else if(!lawsync)
O.lawupdate = FALSE
O.make_laws()
M.brainmob.mind.transfer_to(O)
if(O.mind && O.mind.special_role && !M.syndiemmi)
O.mind.store_memory("As a cyborg, you must obey your silicon laws and master AI above all else. Your objectives will consider you to be dead.")
to_chat(O, "<span class='userdanger'>You have been robotized!</span>")
to_chat(O, "<span class='danger'>You must obey your silicon laws and master AI above all else. Your objectives will consider you to be dead.</span>")
O.job = "Cyborg"
var/datum/robot_component/cell_component = O.components["power cell"]
cell_component.install(chest.cell)
chest.cell.forceMove(O)
chest.cell = null
M.forceMove(O) //Should fix cybros run time erroring when blown up. It got deleted before, along with the frame.
O.mmi = W
if(O.mmi.syndiemmi)
O.syndiemmi_override()
to_chat(O, "<span class='warning'>ALERT: Foreign hardware detected.</span>")
to_chat(O, "<span class='warning'>ERRORERRORERROR</span>")
to_chat(O, "<span class='boldwarning'>Obey these laws:</span>")
O.laws.show_laws(O)
O.Namepick()
SSblackbox.record_feedback("amount", "cyborg_birth", 1)
forceMove(O)
O.robot_suit = src
if(!locomotion)
O.lockcharge = 1
to_chat(O, "<span class='warning'>Error: Servo motors unresponsive.</span>")
else
to_chat(user, "<span class='warning'>The MMI must go in after everything else!</span>")
if(istype(W,/obj/item/pen))
to_chat(user, "<span class='warning'>You need to use a multitool to name [src]!</span>")
return
/obj/item/robot_parts/robot_suit/proc/Interact(mob/user)
var/t1 = "Designation: <A href='?src=[UID()];Name=1'>[(created_name ? "[created_name]" : "Default Cyborg")]</a><br>\n"
t1 += "Master AI: <A href='?src=[UID()];Master=1'>[(forced_ai ? "[forced_ai.name]" : "Automatic")]</a><br><br>\n"
t1 += "LawSync Port: <A href='?src=[UID()];Law=1'>[(lawsync ? "Open" : "Closed")]</a><br>\n"
t1 += "AI Connection Port: <A href='?src=[UID()];AI=1'>[(aisync ? "Open" : "Closed")]</a><br>\n"
t1 += "Servo Motor Functions: <A href='?src=[UID()];Loco=1'>[(locomotion ? "Unlocked" : "Locked")]</a><br>\n"
t1 += "Panel Lock: <A href='?src=[UID()];Panel=1'>[(panel_locked ? "Engaged" : "Disengaged")]</a><br>\n"
var/datum/browser/popup = new(user, "robotdebug", "Cyborg Boot Debug", 310, 220)
popup.set_content(t1)
popup.open()
/obj/item/robot_parts/robot_suit/Topic(href, href_list)
var/mob/living/living_user = usr
if(HAS_TRAIT(living_user, TRAIT_HANDS_BLOCKED) || living_user.stat || !Adjacent(living_user))
return
var/obj/item/item_in_hand = living_user.get_active_hand()
if(!istype(item_in_hand, /obj/item/multitool))
to_chat(living_user, "<span class='warning'>You need a multitool!</span>")
return
if(href_list["Name"])
var/new_name = reject_bad_name(input(usr, "Enter new designation. Set to blank to reset to default.", "Cyborg Debug", created_name),1)
if(!in_range(src, usr) && loc != usr)
return
if(new_name)
created_name = new_name
else
created_name = ""
else if(href_list["Master"])
forced_ai = select_active_ai(usr)
if(!forced_ai)
to_chat(usr, "<span class='error'>No active AIs detected.</span>")
else if(href_list["Law"])
lawsync = !lawsync
else if(href_list["AI"])
aisync = !aisync
else if(href_list["Loco"])
locomotion = !locomotion
else if(href_list["Panel"])
panel_locked = !panel_locked
add_fingerprint(usr)
Interact(usr)
return
/obj/item/robot_parts/chest/attackby(obj/item/W as obj, mob/user as mob, params)
..()
if(istype(W, /obj/item/stock_parts/cell))
if(cell)
to_chat(user, "<span class='notice'>You have already inserted a cell!</span>")
return
else
user.drop_item()
W.forceMove(src)
cell = W
to_chat(user, "<span class='notice'>You insert the cell!</span>")
if(istype(W, /obj/item/stack/cable_coil))
if(wired)
to_chat(user, "<span class='notice'>You have already inserted wire!</span>")
return
else
var/obj/item/stack/cable_coil/coil = W
coil.use(1)
wired = TRUE
to_chat(user, "<span class='notice'>You insert the wire!</span>")
return
/obj/item/robot_parts/head/attackby(obj/item/W as obj, mob/user as mob, params)
..()
if(istype(W, /obj/item/flash))
if(istype(user,/mob/living/silicon/robot))
to_chat(user, "<span class='warning'>How do you propose to do that?</span>")
return
else if(flash1 && flash2)
to_chat(user, "<span class='notice'>You have already inserted the eyes!</span>")
return
else if(flash1)
user.drop_item()
W.forceMove(src)
flash2 = W
to_chat(user, "<span class='notice'>You insert the flash into the eye socket!</span>")
else
user.drop_item()
W.forceMove(src)
flash1 = W
to_chat(user, "<span class='notice'>You insert the flash into the eye socket!</span>")
else if(istype(W, /obj/item/stock_parts/manipulator))
to_chat(user, "<span class='notice'>You install some manipulators and modify the head, creating a functional spider-bot!</span>")
new /mob/living/simple_animal/spiderbot(get_turf(loc))
user.drop_item()
qdel(W)
qdel(src)
/obj/item/robot_parts/emag_act(user)
if(sabotaged)
to_chat(user, "<span class='warning'>[src] is already sabotaged!</span>")
else
to_chat(user, "<span class='warning'>You slide the emag into the dataport on [src] and short out the safeties.</span>")
sabotaged = TRUE