Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cyborg Inventory Refactor #27788

Merged
merged 15 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions code/__DEFINES/dcs/item_signals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,10 @@
#define COMSIG_SPEED_POTION_APPLIED "speed_potion"
#define SPEED_POTION_STOP (1<<0)

// Cyborg specific items

/// from /mob/living/silicon/robot/proc/activate_item() (mob/user), A general signal for if a specific borg item needs something done when being activated.
#define COMSIG_CYBORG_ITEM_ACTIVATED "cyborg_activation"

/// from /mob/living/silicon/robot/proc/deactivate_item() (mob/user), A general signal for if a specific borg item needs something done when being deactivated.
#define COMSIG_CYBORG_ITEM_DEACTIVATED "cyborg_deactivation"
10 changes: 10 additions & 0 deletions code/__DEFINES/silicon_defines.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#define CYBORG_MODULE_ONE 1
#define CYBORG_MODULE_TWO 2
#define CYBORG_MODULE_THREE 3
#define CYBORG_EMPTY_MODULE 0

#define CYBORG_MAX_MODULES 3

/// These are the screen locations of a cyborg's modules 1, 2, and 3 in that order.
#define CYBORG_HUD_LOCATIONS list("CENTER-2:16,SOUTH:5", "CENTER-1 :16,SOUTH:5", "CENTER :16,SOUTH:5")

144 changes: 63 additions & 81 deletions code/_onclick/hud/robot_hud.dm
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,42 @@
return TRUE


/atom/movable/screen/robot/module1
name = "module1"
icon_state = "inv1"

/atom/movable/screen/robot/module1/Click()
if(..())
return
if(isrobot(usr))
var/mob/living/silicon/robot/R = usr
R.toggle_module(1)

/atom/movable/screen/robot/module2
name = "module2"
icon_state = "inv2"

/atom/movable/screen/robot/module2/Click()
if(..())
return
if(isrobot(usr))
var/mob/living/silicon/robot/R = usr
R.toggle_module(2)

/atom/movable/screen/robot/module3
name = "module3"
icon_state = "inv3"

/atom/movable/screen/robot/module3/Click()
if(..())
/atom/movable/screen/robot/active_module
name = "module"
icon_state = "inv"
/// If it's slot 1, 2, or 3
var/module_number = 1
BiancaWilkson marked this conversation as resolved.
Show resolved Hide resolved
/// Where the string for the deactivated icon state is stored
var/deactivated_icon_string
/// Where the string for the activated icon state is stored
var/activated_icon_string
/// If it should have a green background
var/active = FALSE

/atom/movable/screen/robot/active_module/Initialize(mapload, slot_number)
. = ..()
module_number = slot_number
name = name + "[module_number]"
icon_state = icon_state + "[module_number]"
deactivated_icon_string = icon_state
activated_icon_string = icon_state + " +a"

/// Updates the background of the module to be active
/atom/movable/screen/robot/active_module/proc/activate()
icon_state = activated_icon_string
active = TRUE

/// Updates the background of the module to be inactive
/atom/movable/screen/robot/active_module/proc/deactivate()
icon_state = deactivated_icon_string
active = FALSE

/atom/movable/screen/robot/active_module/Click()
if(..() || !module_number)
BiancaWilkson marked this conversation as resolved.
Show resolved Hide resolved
return
if(isrobot(usr))
var/mob/living/silicon/robot/R = usr
R.toggle_module(3)

R.toggle_module(module_number)

/atom/movable/screen/robot/radio
name = "radio"
Expand Down Expand Up @@ -114,6 +117,7 @@
var/shown_robot_modules = FALSE // Used to determine whether they have the module menu shown or not
var/atom/movable/screen/robot_modules_background


/datum/hud/robot/New(mob/user)
..()

Expand All @@ -137,22 +141,11 @@
static_inventory += using

//Module select
using = new /atom/movable/screen/robot/module1()
using.screen_loc = ui_inv1
static_inventory += using
mymobR.inv1 = using

using = new /atom/movable/screen/robot/module2()
using.screen_loc = ui_inv2
static_inventory += using
mymobR.inv2 = using

using = new /atom/movable/screen/robot/module3()
using.screen_loc = ui_inv3
static_inventory += using
mymobR.inv3 = using

//End of module select
for(var/i in 1 to CYBORG_MAX_MODULES)
using = new /atom/movable/screen/robot/active_module(src, i)
using.screen_loc = CYBORG_HUD_LOCATIONS[i]
static_inventory += using
mymobR.inventory_screens += using

//Sec/Med HUDs
using = new /atom/movable/screen/ai/sensors()
Expand Down Expand Up @@ -212,10 +205,8 @@

/datum/hud/robot/Destroy()
var/mob/living/silicon/robot/myrob = mymob
myrob.inv1 = null
myrob.hands = null
myrob.inv2 = null
myrob.inv3 = null
QDEL_LAZYLIST(myrob.inventory_screens)
myrob.lamp_button = null
myrob.thruster_button = null

Expand Down Expand Up @@ -271,29 +262,29 @@
var/y = 1

for(var/atom/movable/A in R.module.modules)
if((A != R.module_state_1) && (A != R.module_state_2) && (A != R.module_state_3))
//Module is not currently active
screenmob.client.screen += A
if(x < 0)
A.screen_loc = "CENTER[x]:16,SOUTH+[y]:7"
else
A.screen_loc = "CENTER+[x]:16,SOUTH+[y]:7"
A.layer = ABOVE_HUD_LAYER
A.plane = ABOVE_HUD_PLANE

x++
if(x == 4)
x = -4
y++
if(A in R.all_active_items) // Don't need to display it if it's already active
continue
screenmob.client.screen += A
if(x < 0)
A.screen_loc = "CENTER[x]:16,SOUTH+[y]:7"
else
A.screen_loc = "CENTER+[x]:16,SOUTH+[y]:7"
A.layer = ABOVE_HUD_LAYER
A.plane = ABOVE_HUD_PLANE

x++
if(x == 4)
x = -4
y++

else
//Modules display is hidden
screenmob.client.screen -= module_store_icon

for(var/atom/A in R.module.modules)
if((A != R.module_state_1) && (A != R.module_state_2) && (A != R.module_state_3))
//Module is not currently active
screenmob.client.screen -= A
if(A in R.all_active_items) // Don't need to display it if it's already active
continue
screenmob.client.screen -= A
shown_robot_modules = FALSE
screenmob.client.screen -= robot_modules_background

Expand All @@ -304,23 +295,14 @@

var/mob/screenmob = viewer || R

var/held_items = list(R.module_state_1, R.module_state_2, R.module_state_3)
if(!screenmob.hud_used)
return
if(screenmob.hud_used.hud_shown)
for(var/i in 1 to length(held_items))
var/obj/item/I = held_items[i]
if(I)
switch(i)
if(1)
I.screen_loc = ui_inv1
if(2)
I.screen_loc = ui_inv2
if(3)
I.screen_loc = ui_inv3
else
return
screenmob.client.screen += I
for(var/i in 1 to length(R.all_active_items))
var/obj/item/active_item = R.all_active_items[i]
if(active_item)
active_item.screen_loc = CYBORG_HUD_LOCATIONS[i]
screenmob.client.screen |= active_item
else
for(var/obj/item/I in held_items)
for(var/obj/item/I in R.all_active_items)
screenmob.client.screen -= I
2 changes: 1 addition & 1 deletion code/game/objects/items.dm
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ GLOBAL_DATUM_INIT(welding_sparks, /mutable_appearance, mutable_appearance('icons
return
var/mob/living/silicon/robot/R = user
if(!R.low_power_mode) // Can't equip modules with an empty cell.
R.activate_module(src)
R.activate_item(src)
R.hud_used.update_robot_modules_display()

// Due to storage type consolidation this should get used more now.
Expand Down
23 changes: 21 additions & 2 deletions code/game/objects/items/weapons/storage/bags.dm
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,26 @@
. = ..()
if(listening_to == user)
return
begin_listening(src, user)

/obj/item/storage/bag/ore/proc/begin_listening(datum/source, mob/user) // Even though its unused, the datum/source argument is required to make the signals work.
SIGNAL_HANDLER // COMSIG_CYBORG_ITEM_ACTIVATED
if(listening_to)
UnregisterSignal(listening_to, COMSIG_MOVABLE_MOVED)
RegisterSignal(user, COMSIG_MOVABLE_MOVED, PROC_REF(pickup_ores))
listening_to = user

/obj/item/storage/bag/ore/dropped()
. = ..()
/obj/item/storage/bag/ore/proc/end_listening()
SIGNAL_HANDLER // COMSIG_CYBORG_ITEM_DEACTIVATED
if(listening_to)
UnregisterSignal(listening_to, COMSIG_MOVABLE_MOVED)
listening_to = null


/obj/item/storage/bag/ore/dropped()
. = ..()
end_listening()

/obj/item/storage/bag/ore/proc/pickup_ores(mob/living/user)
SIGNAL_HANDLER // COMSIG_MOVABLE_MOVED
var/turf/simulated/floor/plating/asteroid/tile = get_turf(user)
Expand All @@ -208,6 +217,16 @@
name = "cyborg mining satchel"
flags = NODROP

/obj/item/storage/bag/ore/cyborg/Initialize(mapload)
. = ..()
RegisterSignal(src, COMSIG_CYBORG_ITEM_ACTIVATED, PROC_REF(begin_listening))
RegisterSignal(src, COMSIG_CYBORG_ITEM_DEACTIVATED, PROC_REF(end_listening))

/obj/item/storage/bag/ore/cyborg/Destroy()
UnregisterSignal(src, COMSIG_CYBORG_ITEM_ACTIVATED)
UnregisterSignal(src, COMSIG_CYBORG_ITEM_DEACTIVATED)
. = ..()
BiancaWilkson marked this conversation as resolved.
Show resolved Hide resolved

/// miners, your messiah has arrived
/obj/item/storage/bag/ore/holding
name = "mining satchel of holding"
Expand Down
9 changes: 3 additions & 6 deletions code/game/turfs/simulated/floor/transparent.dm
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@
R = user.get_inactive_hand()
else if(isrobot(user))
var/mob/living/silicon/robot/robouser = user
if(istype(robouser.module_state_1, /obj/item/stack/sheet/metal))
R = robouser.module_state_1
else if(istype(robouser.module_state_2, /obj/item/stack/sheet/metal))
R = robouser.module_state_2
else if(istype(robouser.module_state_3, /obj/item/stack/sheet/metal))
R = robouser.module_state_3
var/metal_slot = robouser.get_module_by_item(/obj/item/stack/sheet/metal)
if(metal_slot)
R = robouser.all_active_items[metal_slot]

if(!istype(R, /obj/item/stack/sheet/metal) || R.get_amount() < 2)
to_chat(user, "<span class='danger'>You also need to hold two sheets of metal to dismantle \the [src]!</span>")
Expand Down
4 changes: 2 additions & 2 deletions code/game/turfs/simulated/minerals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@

else if(isrobot(AM))
var/mob/living/silicon/robot/R = AM
if(istype(R.module_active, /obj/item/pickaxe))
attack_by(R.module_active, R)
if(istype(R.selected_item, /obj/item/pickaxe))
attack_by(R.selected_item, R)

else if(ismecha(AM))
var/obj/mecha/M = AM
Expand Down
2 changes: 1 addition & 1 deletion code/modules/admin/topic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2786,7 +2786,7 @@
R.module.modules += I
I.loc = R.module
R.module.rebuild_modules()
R.activate_module(I)
R.activate_item(I)
R.module.fix_modules()

if(number == 1)
Expand Down
Loading
Loading