Skip to content

Commit

Permalink
[MIRROR] General maintenance for frames (#2147)
Browse files Browse the repository at this point in the history
* General maintenance for frames (#81473)

## About The Pull Request
Builds upon the changes in
tgstation/tgstation#81477

**1. Qol**
- Adds detailed examines & screentips for building & deconstructing both
machine & computer frames
- Adding a circuitboard from a rped to a computer frame will
automatically screw it in place like before

**2. Code Improvements**
- Merged procs like `update_path_names()` , `get_requested_amt()` etc
into their required places to reduce proc calls
- Autodocs procs like `add_cable()`, `add_glass()` etc. makes them
private
- Moved code for machine frame into its own file

* General maintenance for frames

---------

Co-authored-by: NovaBot <[email protected]>
Co-authored-by: SyncIt21 <[email protected]>
  • Loading branch information
3 people authored Feb 29, 2024
1 parent acedd84 commit 5ec5eb8
Show file tree
Hide file tree
Showing 5 changed files with 645 additions and 489 deletions.
2 changes: 1 addition & 1 deletion code/__DEFINES/construction/structures.dm
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
#define GEAR_SECURE 1
#define GEAR_LOOSE 2

// Stationary gas tanks
//Stationary gas tanks
#define TANK_FRAME 0
#define TANK_PLATING_UNSECURED 1

Expand Down
233 changes: 166 additions & 67 deletions code/game/machinery/computer/buildandrepair.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,92 @@
/obj/structure/frame/computer/Initialize(mapload)
. = ..()
AddComponent(/datum/component/simple_rotation)
register_context()
update_appearance(UPDATE_ICON_STATE)

/obj/structure/frame/computer/deconstruct(disassembled = TRUE)
if(!(obj_flags & NO_DECONSTRUCTION))
var/atom/drop_loc = drop_location()
if(state == FRAME_COMPUTER_STATE_GLASSED)
if(disassembled)
new /obj/item/stack/sheet/glass(drop_loc, 2)
else
new /obj/item/shard(drop_loc)
new /obj/item/shard(drop_loc)
if(state >= FRAME_COMPUTER_STATE_WIRED)
new /obj/item/stack/cable_coil(drop_loc, 5)

return ..()

/obj/structure/frame/computer/add_context(atom/source, list/context, obj/item/held_item, mob/user)
. = NONE
if(isnull(held_item))
return

switch(state)
if(FRAME_COMPUTER_STATE_EMPTY)
if(held_item.tool_behaviour == TOOL_WRENCH)
context[SCREENTIP_CONTEXT_LMB] = "[anchored ? "Un" : ""]anchor"
return CONTEXTUAL_SCREENTIP_SET
else if(anchored && istype(held_item, /obj/item/circuitboard/computer))
context[SCREENTIP_CONTEXT_LMB] = "Install board"
return CONTEXTUAL_SCREENTIP_SET
else if(held_item.tool_behaviour == TOOL_WELDER)
context[SCREENTIP_CONTEXT_LMB] = "Unweld frame"
return CONTEXTUAL_SCREENTIP_SET
else if(held_item.tool_behaviour == TOOL_SCREWDRIVER)
context[SCREENTIP_CONTEXT_LMB] = "Disassemble frame"
return CONTEXTUAL_SCREENTIP_SET
if(FRAME_COMPUTER_STATE_BOARD_INSTALLED)
if(held_item.tool_behaviour == TOOL_CROWBAR)
context[SCREENTIP_CONTEXT_LMB] = "Pry out board"
return CONTEXTUAL_SCREENTIP_SET
else if(held_item.tool_behaviour == TOOL_SCREWDRIVER)
context[SCREENTIP_CONTEXT_LMB] = "Secure board"
return CONTEXTUAL_SCREENTIP_SET
if(FRAME_COMPUTER_STATE_BOARD_SECURED)
if(held_item.tool_behaviour == TOOL_SCREWDRIVER)
context[SCREENTIP_CONTEXT_LMB] = "Unsecure board"
return CONTEXTUAL_SCREENTIP_SET
else if(istype(held_item, /obj/item/stack/cable_coil))
context[SCREENTIP_CONTEXT_LMB] = "Install cable"
return CONTEXTUAL_SCREENTIP_SET
if(FRAME_COMPUTER_STATE_WIRED)
if(held_item.tool_behaviour == TOOL_WIRECUTTER)
context[SCREENTIP_CONTEXT_LMB] = "Cut out cable"
return CONTEXTUAL_SCREENTIP_SET
else if(istype(held_item, /obj/item/stack/sheet/glass))
context[SCREENTIP_CONTEXT_LMB] = "Install panel"
return CONTEXTUAL_SCREENTIP_SET
if(FRAME_COMPUTER_STATE_GLASSED)
if(held_item.tool_behaviour == TOOL_CROWBAR)
context[SCREENTIP_CONTEXT_LMB] = "Pry out glass"
return CONTEXTUAL_SCREENTIP_SET
else if(held_item.tool_behaviour == TOOL_SCREWDRIVER)
context[SCREENTIP_CONTEXT_LMB] = "Complete frame"
return CONTEXTUAL_SCREENTIP_SET

/obj/structure/frame/computer/examine(user)
. = ..()

switch(state)
if(FRAME_STATE_EMPTY)
. += span_notice("It can be [EXAMINE_HINT("wrenched")] [anchored ? "loose" : "in place"].")
if(anchored)
. += span_warning("It's missing a circuit board.")
. += span_notice("It can be [EXAMINE_HINT("welded")] or [EXAMINE_HINT("screwed")] apart.")
if(FRAME_COMPUTER_STATE_BOARD_INSTALLED)
. += span_warning("An [circuit.name] is installed and should be [EXAMINE_HINT("screwed")] in place.")
. += span_notice("The circuit board can be [EXAMINE_HINT("pried")] out.")
if(FRAME_COMPUTER_STATE_BOARD_SECURED)
. += span_warning("Its requires [EXAMINE_HINT("5 cable")] pieces to wire it.")
. += span_notice("The circuit board can be [EXAMINE_HINT("screwed")] loose.")
if(FRAME_COMPUTER_STATE_WIRED)
. += span_notice("The wires can be cut out with [EXAMINE_HINT("wire cutters")].")
. += span_warning("Its requires [EXAMINE_HINT("2 glass")] sheets to complete the screen.")
if(FRAME_COMPUTER_STATE_GLASSED)
. += span_notice("The screen can be [EXAMINE_HINT("pried")] out.")
. += span_notice("The moniter can be [EXAMINE_HINT("screwed")] to complete it")

/obj/structure/frame/computer/circuit_added(obj/item/circuitboard/added)
state = FRAME_COMPUTER_STATE_BOARD_INSTALLED
Expand All @@ -22,7 +108,45 @@
if(state != FRAME_COMPUTER_STATE_EMPTY)
balloon_alert(user, "circuit already installed!")
return FALSE
return ..()
if(!anchored && istype(board))
balloon_alert(user, "frame must be anchored!")
return FALSE
. = ..()
if(. && !by_hand) // Installing via RPED auto-secures it
state = FRAME_COMPUTER_STATE_BOARD_SECURED
update_appearance(UPDATE_ICON_STATE)
return .

/obj/structure/frame/computer/install_parts_from_part_replacer(mob/living/user, obj/item/storage/part_replacer/replacer, no_sound = FALSE)
switch(state)
if(FRAME_COMPUTER_STATE_BOARD_SECURED)
var/obj/item/stack/cable_coil/cable = locate() in replacer
if(isnull(cable))
return FALSE

if(add_cabling(user, cable, time = 0))
if(!no_sound)
replacer.play_rped_sound()
if(replacer.works_from_distance)
user.Beam(src, icon_state = "rped_upgrade", time = 0.5 SECONDS)
no_sound = TRUE
return install_parts_from_part_replacer(user, replacer, no_sound = no_sound) // Recursive call to handle the next part

return FALSE

if(FRAME_COMPUTER_STATE_WIRED)
var/obj/item/stack/sheet/glass/glass_sheets = locate() in replacer
if(isnull(glass_sheets))
return FALSE

if(add_glass(user, glass_sheets, time = 0))
if(!no_sound)
replacer.play_rped_sound()
if(replacer.works_from_distance)
user.Beam(src, icon_state = "rped_upgrade", time = 0.5 SECONDS)
return TRUE

return FALSE

/obj/structure/frame/computer/item_interaction(mob/living/user, obj/item/tool, list/modifiers, is_right_clicking)
. = ..()
Expand All @@ -48,11 +172,9 @@
if(istype(tool, /obj/item/storage/part_replacer))
return install_parts_from_part_replacer(user, tool) ? ITEM_INTERACT_SUCCESS : ITEM_INTERACT_BLOCKING

return .

/obj/structure/frame/computer/screwdriver_act(mob/living/user, obj/item/tool)
. = ..()
if(. != NONE)
if(. & ITEM_INTERACT_ANY_BLOCKER)
return .

switch(state)
Expand Down Expand Up @@ -83,6 +205,9 @@
return ITEM_INTERACT_BLOCKING

/obj/structure/frame/computer/crowbar_act(mob/living/user, obj/item/tool)
if(user.combat_mode)
return NONE

switch(state)
if(FRAME_COMPUTER_STATE_BOARD_INSTALLED)
tool.play_tool_sound(src)
Expand All @@ -92,14 +217,12 @@
return ITEM_INTERACT_SUCCESS

if(FRAME_COMPUTER_STATE_BOARD_SECURED)
if(!user.combat_mode)
balloon_alert(user, "unsecure the circuit!")
return ITEM_INTERACT_BLOCKING
balloon_alert(user, "unsecure the circuit!")
return ITEM_INTERACT_BLOCKING

if(FRAME_COMPUTER_STATE_WIRED)
if(!user.combat_mode)
balloon_alert(user, "remove the wiring!")
return ITEM_INTERACT_BLOCKING
balloon_alert(user, "remove the wiring!")
return ITEM_INTERACT_BLOCKING

if(FRAME_COMPUTER_STATE_GLASSED)
tool.play_tool_sound(src)
Expand All @@ -111,38 +234,34 @@
dropped_glass.add_fingerprint(user)
return ITEM_INTERACT_SUCCESS

/obj/structure/frame/computer/install_parts_from_part_replacer(mob/living/user, obj/item/storage/part_replacer/replacer, no_sound = FALSE)
switch(state)
if(FRAME_COMPUTER_STATE_BOARD_SECURED)
var/obj/item/stack/cable_coil/cable = locate() in replacer
if(isnull(cable))
return FALSE

if(add_cabling(user, cable, time = 0))
if(!no_sound)
replacer.play_rped_sound()
if(replacer.works_from_distance)
user.Beam(src, icon_state = "rped_upgrade", time = 0.5 SECONDS)
no_sound = TRUE
return install_parts_from_part_replacer(user, replacer, no_sound = no_sound) // Recursive call to handle the next part

return FALSE
/obj/structure/frame/computer/wirecutter_act(mob/living/user, obj/item/tool)
if(user.combat_mode)
return NONE

if(FRAME_COMPUTER_STATE_WIRED)
var/obj/item/stack/sheet/glass/glass_sheets = locate() in replacer
if(isnull(glass_sheets))
return FALSE
if(state != FRAME_COMPUTER_STATE_WIRED)
return ITEM_INTERACT_BLOCKING

if(add_glass(user, glass_sheets, time = 0))
if(!no_sound)
replacer.play_rped_sound()
if(replacer.works_from_distance)
user.Beam(src, icon_state = "rped_upgrade", time = 0.5 SECONDS)
return TRUE
tool.play_tool_sound(src)
balloon_alert(user, "cables removed")
state = FRAME_COMPUTER_STATE_BOARD_SECURED
update_appearance(UPDATE_ICON_STATE)

return FALSE
var/obj/item/stack/cable_coil/dropped_cables = new (drop_location(), 5)
if (!QDELETED(dropped_cables))
dropped_cables.add_fingerprint(user)
return ITEM_INTERACT_SUCCESS

/**
* Adds cable to the computer to wire it
* Arguments
*
* * mob/living/user - the player who is adding the cable
* * obj/item/stack/cable_coil/cable - the cable we are trying to add
* * time - time taken to complete the operation
*/
/obj/structure/frame/computer/proc/add_cabling(mob/living/user, obj/item/stack/cable_coil/cable, time = 2 SECONDS)
PRIVATE_PROC(TRUE)

if(state != FRAME_COMPUTER_STATE_BOARD_SECURED)
return FALSE
if(!cable.tool_start_check(user, amount = 5))
Expand All @@ -156,7 +275,17 @@
update_appearance(UPDATE_ICON_STATE)
return TRUE

/**
* Adds glass sheets to the computer to complete the screen
* Arguments
*
* * mob/living/user - the player who is adding the glass
* * obj/item/stack/sheet/glass/glass - the glass we are trying to add
* * time - time taken to complete the operation
*/
/obj/structure/frame/computer/proc/add_glass(mob/living/user, obj/item/stack/sheet/glass/glass, time = 2 SECONDS)
PRIVATE_PROC(TRUE)

if(state != FRAME_COMPUTER_STATE_WIRED)
return FALSE
if(!glass.tool_start_check(user, amount = 2))
Expand All @@ -171,22 +300,6 @@
update_appearance(UPDATE_ICON_STATE)
return TRUE

/obj/structure/frame/computer/wirecutter_act(mob/living/user, obj/item/tool)
if(state != FRAME_COMPUTER_STATE_WIRED)
return NONE

tool.play_tool_sound(src)
balloon_alert(user, "cables removed")
state = FRAME_COMPUTER_STATE_BOARD_SECURED
update_appearance(UPDATE_ICON_STATE)
var/obj/item/stack/cable_coil/dropped_cables = new (drop_location(), 5)
if (!QDELETED(dropped_cables))
dropped_cables.add_fingerprint(user)
return ITEM_INTERACT_SUCCESS

/obj/structure/frame/computer/AltClick(mob/user)
return ..() // This hotkey is BLACKLISTED since it's used by /datum/component/simple_rotation

/obj/structure/frame/computer/finalize_construction(mob/living/user, obj/item/tool)
tool.play_tool_sound(src)
var/obj/machinery/new_machine = new circuit.build_path(loc)
Expand Down Expand Up @@ -221,20 +334,6 @@
qdel(src)
return TRUE

/obj/structure/frame/computer/deconstruct(disassembled = TRUE)
if(!(obj_flags & NO_DECONSTRUCTION))
var/atom/drop_loc = drop_location()
if(state == FRAME_COMPUTER_STATE_GLASSED)
if(disassembled)
new /obj/item/stack/sheet/glass(drop_loc, 2)
else
new /obj/item/shard(drop_loc)
new /obj/item/shard(drop_loc)
if(state >= FRAME_COMPUTER_STATE_WIRED)
new /obj/item/stack/cable_coil(drop_loc, 5)

return ..()

/// Helpers for rcd
/obj/structure/frame/computer/rcd
icon = 'icons/hud/radial.dmi'
Expand Down
Loading

0 comments on commit 5ec5eb8

Please sign in to comment.