Skip to content

Commit

Permalink
Cyborg Omnitool Refactor (#83880)
Browse files Browse the repository at this point in the history
- Complete rewrite of borg omnitool code;
- - Borgs that use omnitools now have a "Omni Toolbox" that holds
whatever tools the Omnitool would cover. The toolbox keeps track of
Omnitool "Arms" in a list, as well as when to upgrade (or downgrade)
tool speed. The toolbox is not seen by the player directly.
- - Omnitool "Arms" will display available tools based on the Omni
Toolbox's contents. Selecting one does not move the tool out of the
toolbox, but instead simply overrides any following clicks with a melee
attack chain of the selected item. This is reminiscent of how borg
apparatus tools work. When selecting a tool, the Omnitool "arm" will
also set its own icon state to match the tool selected.
- - Because all Omnitool "arms" are using the same tools from the same
toolbox, actions done with one can be seen from another. For example,
using the first Omnitool to scan the Silo with the engineer borg's
multitool will update the tool's buffer, and it can be used later, even
if the multitool is selected by the second Omnitool.
- Because we're now using real tools, rather than a single tool item
faking tool usage via tool flags, almost all interactions with tools
should properly carry over.
- Added Cyborg versions of the medical toolset, for use with the Medical
Cyborg omnitool, so that we can finally use the really nice borg-version
medical tool sprites.
Easier to read code.
Fixes #83667
Fixes #83537
Fixes #83077
Fixes #82918 partially; Heating beakers works, but the tile quick-swap
function will not function; the action is initiated by a click from the
tile stack rather than the crowbar.
:cl:
fix: Refactored borg omnitool code, fixing most of the unique
interaction issues.
/:cl:

---------

Co-authored-by: MrMelbert <[email protected]>
  • Loading branch information
2 people authored and Constellado committed Dec 25, 2024
1 parent b9f3c43 commit 725f66f
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 34 deletions.
7 changes: 5 additions & 2 deletions code/datums/components/surgery_initiator.dm
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,11 @@
required_tool_type = TOOL_SCREWDRIVER

if(iscyborg(user))
close_tool = locate(/obj/item/cautery) in user.held_items
if(!close_tool)
var/has_cautery = FALSE
for(var/obj/item/borg/cyborg_omnitool/toolarm in user.held_items)
if(toolarm.selected && istype(toolarm.selected, /obj/item/cautery))
has_cautery = TRUE
if(!has_cautery)
patient.balloon_alert(user, "need a cautery in an inactive slot to stop the surgery!")
return
else if(!close_tool || close_tool.tool_behaviour != required_tool_type)
Expand Down
7 changes: 5 additions & 2 deletions code/game/machinery/telecomms/machine_interactions.dm
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,11 @@
var/mob/living/silicon/ai/U = user
multitool = U.aiMulti
else if(iscyborg(user) && in_range(user, src))
if(istype(user.get_active_held_item(), /obj/item/multitool))
multitool = user.get_active_held_item()
var/mob/living/silicon/robot/borguser = user
for(var/obj/item/borg/cyborg_omnitool/toolarm in borguser.held_items)
if(istype(toolarm.selected, /obj/item/multitool))
multitool = toolarm.selected
break
return multitool

/obj/machinery/telecomms/proc/canAccess(mob/user)
Expand Down
140 changes: 140 additions & 0 deletions code/game/objects/items/robot/items/tools.dm
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,144 @@
projectile.speed *= (1 / projectile_speed_coefficient)
projectile.cut_overlay(projectile_effect)

//////////////////////
///CYBORG OMNITOOLS///
//////////////////////

/**
Onmi Toolboxs act as a cache of tools for a particular borg's omnitools. Not all borg
get a toolbox (as not all borgs use omnitools), and those that do can only have one
toolbox. The toolbox keeps track of a borg's omnitool arms, and handles speed upgrades.
Omnitools are the actual tool arms for the cyborg to interact with. When attack_self
is called, they can select a tool from the toolbox. The tool is not moved, and instead
only referenced in place of the omnitool's own attacks. The omnitool also takes on
the tool's sprite, which completes the illusion. In this way, multiple tools are
shared between multiple omnitool arms. A multitool's buffer, for example, will not
depend on which omnitool arm was used to set it.
*/
/obj/item/cyborg_omnitoolbox
name = "broken cyborg toolbox"
desc = "Some internal part of a broken cyborg."
icon = 'icons/mob/silicon/robot_items.dmi'
icon_state = "lollipop"
toolspeed = 10
///List of Omnitool "arms" that the borg has.
var/list/omnitools = list()
///List of paths for tools. These will be created during Initialize()
var/list/toolpaths = list()
///Target Toolspeed to set after reciving an omnitool upgrade
var/upgraded_toolspeed = 10
///Whether we currently have the upgraded speed
var/currently_upgraded = FALSE

/obj/item/cyborg_omnitoolbox/Initialize(mapload)
. = ..()
if(!toolpaths.len)
return

var/obj/item/newitem
for(var/newpath in toolpaths)
newitem = new newpath(src)
newitem.toolspeed = toolspeed //In case thse have different base speeds as stand-alone tools on other borgs
ADD_TRAIT(newitem, TRAIT_NODROP, CYBORG_ITEM_TRAIT)

/obj/item/cyborg_omnitoolbox/proc/set_upgrade(upgrade = FALSE)
for(var/obj/item/tool in contents)
if(upgrade)
tool.toolspeed = upgraded_toolspeed
else
tool.toolspeed = toolspeed
currently_upgraded = upgrade

/obj/item/cyborg_omnitoolbox/engineering
toolspeed = 0.5
upgraded_toolspeed = 0.3
toolpaths = list(
/obj/item/wrench/cyborg,
/obj/item/wirecutters/cyborg,
/obj/item/screwdriver/cyborg,
/obj/item/crowbar/cyborg,
/obj/item/multitool/cyborg,
)

/obj/item/cyborg_omnitoolbox/medical
toolspeed = 1
upgraded_toolspeed = 0.7
toolpaths = list(
/obj/item/scalpel/cyborg,
/obj/item/surgicaldrill/cyborg,
/obj/item/hemostat/cyborg,
/obj/item/retractor/cyborg,
/obj/item/cautery/cyborg,
/obj/item/circular_saw/cyborg,
/obj/item/bonesetter/cyborg,
)

/obj/item/borg/cyborg_omnitool
name = "broken cyborg tool arm"
desc = "Some internal part of a broken cyborg."
icon = 'icons/mob/silicon/robot_items.dmi'
icon_state = "lollipop"
///Ref to the toolbox, since our own loc will be changing
var/obj/item/cyborg_omnitoolbox/toolbox
///Ref to currently selected tool, if any
var/obj/item/selected

/obj/item/borg/cyborg_omnitool/Initialize(mapload)
. = ..()
if(!iscyborg(loc.loc))
return
var/obj/item/robot_model/model = loc
var/obj/item/cyborg_omnitoolbox/chassis_toolbox = model.toolbox
if(!chassis_toolbox)
return
toolbox = chassis_toolbox
toolbox.omnitools += src

/obj/item/borg/cyborg_omnitool/attack_self(mob/user)
var/list/radial_menu_options = list()
for(var/obj/item/borgtool in toolbox.contents)
radial_menu_options[borgtool] = image(icon = borgtool.icon, icon_state = borgtool.icon_state)
var/obj/item/potential_new_tool = show_radial_menu(user, src, radial_menu_options, require_near = TRUE, tooltips = TRUE)
if(!potential_new_tool)
return ..()
if(potential_new_tool == selected)
return ..()
for(var/obj/item/borg/cyborg_omnitool/coworker in toolbox.omnitools)
if(coworker.selected == potential_new_tool)
coworker.deselect() //Can I borrow that please
break
selected = potential_new_tool
icon_state = selected.icon_state
playsound(src, 'sound/items/change_jaws.ogg', 50, TRUE)
return ..()

/obj/item/borg/cyborg_omnitool/proc/deselect()
if(!selected)
return
selected = null
icon_state = initial(icon_state)
playsound(src, 'sound/items/change_jaws.ogg', 50, TRUE)

/obj/item/borg/cyborg_omnitool/cyborg_unequip()
deselect()
return ..()

/obj/item/borg/cyborg_omnitool/pre_attack(atom/atom, mob/living/user, params)
if(selected)
selected.melee_attack_chain(user, atom, params)
return TRUE
return ..()

/obj/item/borg/cyborg_omnitool/engineering
name = "engineering omni-toolset"
desc = "A set of engineering tools used by cyborgs to conduct various engineering tasks."
icon_state = "toolkit_engiborg"

/obj/item/borg/cyborg_omnitool/medical
name = "surgical omni-toolset"
desc = "A set of surgical tools used by cyborgs to operate on various surgical operations."
icon_state = "toolkit_medborg"

#undef PKBORG_DAMPEN_CYCLE_DELAY
28 changes: 12 additions & 16 deletions code/game/objects/items/robot/robot_upgrades.dm
Original file line number Diff line number Diff line change
Expand Up @@ -422,19 +422,18 @@
. = ..()
if(!.)
return .
for(var/obj/item/borg/cyborg_omnitool/medical/omnitool_upgrade in cyborg.model.modules)
if(omnitool_upgrade.upgraded)
to_chat(user, span_warning("This unit is already equipped with an omnitool upgrade!"))
return FALSE
for(var/obj/item/borg/cyborg_omnitool/medical/omnitool in cyborg.model.modules)
omnitool.upgrade_omnitool()
if(cyborg.model.toolbox.currently_upgraded)
to_chat(user, span_warning("This unit is already equipped with an omnitool upgrade!"))
return FALSE
cyborg.model.toolbox.set_upgrade(TRUE)
ADD_TRAIT(cyborg, TRAIT_FASTMED, REF(src))

/obj/item/borg/upgrade/surgery_omnitool/deactivate(mob/living/silicon/robot/cyborg, mob/living/user = usr)
. = ..()
if(!.)
return .
for(var/obj/item/borg/cyborg_omnitool/omnitool in cyborg.model.modules)
omnitool.downgrade_omnitool()
cyborg.model.toolbox.set_upgrade(FALSE)
REMOVE_TRAIT(cyborg, TRAIT_FASTMED, REF(src))

/obj/item/borg/upgrade/engineering_omnitool
name = "cyborg engineering omni-tool upgrade"
Expand All @@ -449,19 +448,16 @@
. = ..()
if(!.)
return .
for(var/obj/item/borg/cyborg_omnitool/engineering/omnitool_upgrade in cyborg.model.modules)
if(omnitool_upgrade.upgraded)
to_chat(user, span_warning("This unit is already equipped with an omnitool upgrade!"))
return FALSE
for(var/obj/item/borg/cyborg_omnitool/engineering/omnitool in cyborg.model.modules)
omnitool.upgrade_omnitool()
if(cyborg.model.toolbox.currently_upgraded)
to_chat(user, span_warning("This unit is already equipped with an omnitool upgrade!"))
return FALSE
cyborg.model.toolbox.set_upgrade(TRUE)

/obj/item/borg/upgrade/engineering_omnitool/deactivate(mob/living/silicon/robot/cyborg, mob/living/user = usr)
. = ..()
if(!.)
return .
for(var/obj/item/borg/cyborg_omnitool/omnitool in cyborg.model.modules)
omnitool.downgrade_omnitool()
cyborg.model.toolbox.set_upgrade(FALSE)

/obj/item/borg/upgrade/defib
name = "medical cyborg defibrillator"
Expand Down
33 changes: 19 additions & 14 deletions code/modules/mob/living/silicon/robot/robot_model.dm
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,17 @@
var/list/ride_offset_y = list("north" = 4, "south" = 4, "east" = 3, "west" = 3)
///List of skins the borg can be reskinned to, optional
var/list/borg_skins
///Omnitoolbox, holder of certain borg tools. Not all models have one
var/obj/item/cyborg_omnitoolbox/toolbox
///Path to toolbox, if a model gets one
var/toolbox_path

/obj/item/robot_model/Initialize(mapload)
. = ..()

if(toolbox_path)
toolbox = new toolbox_path(src)

for(var/path in basic_modules)
var/obj/item/new_module = new path(src)
basic_modules += new_module
Expand Down Expand Up @@ -385,6 +393,7 @@
model_select_icon = "engineer"
model_traits = list(TRAIT_NEGATES_GRAVITY)
hat_offset = -4
toolbox_path = /obj/item/cyborg_omnitoolbox/engineering

/obj/item/robot_model/janitor
name = "Janitor"
Expand Down Expand Up @@ -655,14 +664,9 @@
/obj/item/borg/apparatus/beaker,
/obj/item/reagent_containers/dropper,
/obj/item/reagent_containers/syringe,
/obj/item/surgical_drapes,
/obj/item/retractor,
/obj/item/hemostat,
/obj/item/cautery,
/obj/item/surgicaldrill,
/obj/item/scalpel,
/obj/item/circular_saw,
/obj/item/bonesetter,
/obj/item/borg/cyborg_omnitool/medical,
/obj/item/borg/cyborg_omnitool/medical,
/obj/item/surgical_drapes/cyborg,
/obj/item/blood_filter,
/obj/item/extinguisher/mini,
/obj/item/emergency_bed/silicon,
Expand All @@ -680,6 +684,7 @@
model_select_icon = "medical"
model_traits = list(TRAIT_PUSHIMMUNE)
hat_offset = 3
toolbox_path = /obj/item/cyborg_omnitoolbox/medical
borg_skins = list(
"Machinified Doctor" = list(SKIN_ICON_STATE = "medical"),
"Qualified Doctor" = list(SKIN_ICON_STATE = "qualified_doctor"),
Expand Down Expand Up @@ -865,12 +870,10 @@
/obj/item/reagent_containers/borghypo/syndicate,
/obj/item/shockpaddles/syndicate/cyborg,
/obj/item/healthanalyzer,
/obj/item/surgical_drapes,
/obj/item/retractor,
/obj/item/hemostat,
/obj/item/cautery,
/obj/item/surgicaldrill,
/obj/item/scalpel,
/obj/item/borg/cyborg_omnitool/medical,
/obj/item/borg/cyborg_omnitool/medical,
/obj/item/surgical_drapes/cyborg,
/obj/item/blood_filter,
/obj/item/melee/energy/sword/cyborg/saw,
/obj/item/bonesetter,
/obj/item/blood_filter,
Expand All @@ -887,6 +890,7 @@
model_select_icon = "malf"
model_traits = list(TRAIT_PUSHIMMUNE)
hat_offset = 3
toolbox_path = /obj/item/cyborg_omnitoolbox/medical

/obj/item/robot_model/saboteur
name = "Syndicate Saboteur"
Expand Down Expand Up @@ -919,6 +923,7 @@
model_select_icon = "malf"
model_traits = list(TRAIT_PUSHIMMUNE, TRAIT_NEGATES_GRAVITY)
hat_offset = -4
toolbox_path = /obj/item/cyborg_omnitoolbox/engineering
canDispose = TRUE

/obj/item/robot_model/syndicate/kiltborg
Expand Down
4 changes: 4 additions & 0 deletions code/modules/surgery/surgery.dm
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@
if(isnull(step))
return FALSE
var/obj/item/tool = user.get_active_held_item()
if(istype(tool, /obj/item/borg/cyborg_omnitool)) //catches borg surgeries
var/obj/item/borg/cyborg_omnitool/toolarm = tool
if(toolarm.selected)
tool = toolarm.selected
if(step.try_op(user, target, user.zone_selected, tool, src, try_to_fail))
return TRUE
if(tool && tool.item_flags & SURGICAL_TOOL) //Just because you used the wrong tool it doesn't mean you meant to whack the patient with it
Expand Down
Loading

0 comments on commit 725f66f

Please sign in to comment.