Cyborg Inventory Refactor (#27788)

* Initial variable changes

* Add defines

* oh my god huds

* Removes update_items(), it seems useless but this might need reverting later

* the hud doesn't work but the inventory itself seems to

* Renames a var, gets inventory working properly

* Activation/Deactivation support, ore bag fixed

* Fixes CL and also this would have been a massive, hilarious bug

* Apply suggestions from code review

Dr and Lewc reviews

Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com>
Co-authored-by: Drsmail <60036448+Drsmail@users.noreply.github.com>
Signed-off-by: BiancaWilkson <42818125+BiancaWilkson@users.noreply.github.com>

* Update code/_onclick/hud/robot_hud.dm

Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com>
Signed-off-by: BiancaWilkson <42818125+BiancaWilkson@users.noreply.github.com>

* Fixes a comment

* Wait I forgot this worked like this for a reason

* Lewc Suggestions

Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com>
Signed-off-by: BiancaWilkson <42818125+BiancaWilkson@users.noreply.github.com>

* Burza Suggestions

Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com>
Signed-off-by: BiancaWilkson <42818125+BiancaWilkson@users.noreply.github.com>

---------

Signed-off-by: BiancaWilkson <42818125+BiancaWilkson@users.noreply.github.com>
Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com>
Co-authored-by: Drsmail <60036448+Drsmail@users.noreply.github.com>
Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com>
This commit is contained in:
BiancaWilkson
2025-02-12 16:55:11 -05:00
committed by GitHub
parent c895b91bb3
commit 4fdc79ca90
14 changed files with 250 additions and 308 deletions
@@ -3,15 +3,18 @@
//Returns the thing in our active hand (whatever is in our active module-slot, in this case)
/mob/living/silicon/robot/get_active_hand()
return module_active
return selected_item
/mob/living/silicon/robot/get_all_slots()
return list(module_state_1, module_state_2, module_state_3)
return all_active_items
/*-------TODOOOOOOOOOO--------*/
/mob/living/silicon/robot/proc/uneq_module(obj/item/O)
if(!O)
return 0
return FALSE
var/index = all_active_items.Find(O)
if(!index)
return FALSE
O.mouse_opacity = MOUSE_OPACITY_OPAQUE
@@ -24,23 +27,25 @@
for(var/X in O.actions) // Remove assocated actions
var/datum/action/A = X
A.Remove(src)
all_active_items[index] = CYBORG_EMPTY_MODULE
SEND_SIGNAL(O, COMSIG_CYBORG_ITEM_DEACTIVATED, src)
selected_item = null
var/atom/movable/screen/robot/active_module/screen = inventory_screens[index]
screen.icon_state = screen.deactivated_icon_string
if(module_active == O)
module_active = null
if(module_state_1 == O)
inv1.icon_state = "inv1"
module_state_1 = null
else if(module_state_2 == O)
inv2.icon_state = "inv2"
module_state_2 = null
else if(module_state_3 == O)
module_state_3 = null
inv3.icon_state = "inv3"
if(hud_used)
hud_used.update_robot_modules_display()
return 1
return TRUE
/*
* Returns the index of the first open module slot a borg has, or FALSE if they already have a full hotbar.
*/
/mob/living/silicon/robot/proc/get_open_slot()
for(var/i in 1 to CYBORG_MAX_MODULES)
if(!all_active_items[i]) // Since CYBORG_EMPTY_MODULE is 0 this has to be a ! check.
return i
return FALSE
/mob/living/silicon/robot/proc/activate_module(obj/item/O)
/mob/living/silicon/robot/proc/activate_item(obj/item/O)
if(!(locate(O) in module.modules) && !(O in module.emag_modules))
return
if(activated(O))
@@ -53,32 +58,22 @@
if((cell.charge * 100 / cell.maxcharge) < B.powerneeded)
to_chat(src, "Not enough power to activate [B.name]!")
return
if(!module_state_1)
O.mouse_opacity = initial(O.mouse_opacity)
module_state_1 = O
O.layer = ABOVE_HUD_LAYER
O.plane = ABOVE_HUD_PLANE
O.screen_loc = inv1.screen_loc
contents += O
set_actions(O)
else if(!module_state_2)
O.mouse_opacity = initial(O.mouse_opacity)
module_state_2 = O
O.layer = ABOVE_HUD_LAYER
O.plane = ABOVE_HUD_PLANE
O.screen_loc = inv2.screen_loc
contents += O
set_actions(O)
else if(!module_state_3)
O.mouse_opacity = initial(O.mouse_opacity)
module_state_3 = O
O.layer = ABOVE_HUD_LAYER
O.plane = ABOVE_HUD_PLANE
O.screen_loc = inv3.screen_loc
contents += O
set_actions(O)
else
var/slot = get_open_slot()
if(!slot)
to_chat(src, "You need to disable a module first!")
return
SEND_SIGNAL(O, COMSIG_CYBORG_ITEM_ACTIVATED, src)
O.mouse_opacity = initial(O.mouse_opacity)
all_active_items[slot] = O
deactivate_all()
var/atom/movable/screen/robot/active_module/to_activate = inventory_screens[slot]
to_activate.activate()
selected_item = O
O.layer = ABOVE_HUD_LAYER
O.plane = ABOVE_HUD_PLANE
O.screen_loc = CYBORG_HUD_LOCATIONS[slot]
contents += O
set_actions(O)
observer_screen_update(O, add = TRUE)
check_module_damage(FALSE)
update_icons()
@@ -89,33 +84,25 @@
A.Grant(src)
/mob/living/silicon/robot/proc/uneq_active()
uneq_module(module_active)
uneq_module(selected_item)
/mob/living/silicon/robot/proc/uneq_all()
uneq_module(module_state_1)
uneq_module(module_state_2)
uneq_module(module_state_3)
for(var/obj/item/O in all_active_items)
uneq_module(O)
/mob/living/silicon/robot/proc/uneq_numbered(module)
if(module < 1 || module > 3) return
/// Deactivate all the screen objects, removing the green background from all of them
/mob/living/silicon/robot/proc/deactivate_all()
for(var/atom/movable/screen/robot/active_module/to_deactivate in inventory_screens)
to_deactivate.deactivate()
switch(module)
if(1)
uneq_module(module_state_1)
if(2)
uneq_module(module_state_2)
if(3)
uneq_module(module_state_3)
/mob/living/silicon/robot/proc/uneq_numbered(index)
if(module < 1 || module > CYBORG_MAX_MODULES)
return
uneq_module(all_active_items[index])
/// Returns true if O is in the cyborg's hotbar, false otherwise
/mob/living/silicon/robot/proc/activated(obj/item/O)
if(module_state_1 == O)
return 1
else if(module_state_2 == O)
return 1
else if(module_state_3 == O)
return 1
else
return 0
return (O in all_active_items)
/mob/living/silicon/robot/drop_item()
var/obj/item/gripper/G = get_active_hand()
@@ -126,124 +113,94 @@
//Helper procs for cyborg modules on the UI.
//These are hackish but they help clean up code elsewhere.
//module_selected(module) - Checks whether the module slot specified by "module" is currently selected.
/mob/living/silicon/robot/proc/module_selected(module) //Module is 1-3
return module == get_selected_module()
//module_selected(module) - Checks whether the module slot specified by "index" is currently selected.
/mob/living/silicon/robot/proc/module_selected(index) //Index is 1-3
return index == get_selected_module()
//module_active(module) - Checks whether there is a module active in the slot specified by "module".
/mob/living/silicon/robot/proc/module_active(module) //Module is 1-3
if(module < 1 || module > 3) return 0
//is_module_active(module) - Checks whether there is a item active in the slot specified by "index".
/mob/living/silicon/robot/proc/is_module_active(index) //Index is 1-3
return all_active_items[index]
switch(module)
if(1)
if(module_state_1)
return 1
if(2)
if(module_state_2)
return 1
if(3)
if(module_state_3)
return 1
return 0
//get_selected_module() - Returns the slot number of the currently selected module. Returns 0 if no modules are selected.
//get_selected_module() - Returns the slot number of the currently selected item. Returns 0 if no items are selected.
/mob/living/silicon/robot/proc/get_selected_module()
if(module_state_1 && module_active == module_state_1)
return 1
else if(module_state_2 && module_active == module_state_2)
return 2
else if(module_state_3 && module_active == module_state_3)
return 3
if(!selected_item)
return FALSE
return all_active_items.Find(selected_item)
return 0
/*
* Returns a list of the slots of a cyborg's hotbar that have an item in it, or false if all are empty
*/
/mob/living/silicon/robot/proc/get_filled_modules()
var/list/indicies = list()
for(var/i in 1 to length(all_active_items))
if(!all_active_items[i])
continue
indicies += i
if(!length(indicies))
return FALSE
return indicies
//select_module(module) - Selects the module slot specified by "module"
/mob/living/silicon/robot/proc/select_module(module) //Module is 1-3
if(module < 1 || module > 3) return
if(!module_active(module)) return
switch(module)
if(1)
if(module_active != module_state_1)
inv1.icon_state = "inv1 +a"
inv2.icon_state = "inv2"
inv3.icon_state = "inv3"
module_active = module_state_1
if(2)
if(module_active != module_state_2)
inv1.icon_state = "inv1"
inv2.icon_state = "inv2 +a"
inv3.icon_state = "inv3"
module_active = module_state_2
if(3)
if(module_active != module_state_3)
inv1.icon_state = "inv1"
inv2.icon_state = "inv2"
inv3.icon_state = "inv3 +a"
module_active = module_state_3
if(module < 1 || module > CYBORG_MAX_MODULES)
return
selected_item = null
for(var/i in 1 to CYBORG_MAX_MODULES)
var/atom/movable/screen/robot/active_module/inventory = inventory_screens[i]
if(module == i)
inventory.activate()
selected_item = all_active_items[module]
else
inventory.deactivate()
update_icons()
return
//deselect_module(module) - Deselects the module slot specified by "module"
/mob/living/silicon/robot/proc/deselect_module(module) //Module is 1-3
if(module < 1 || module > 3) return
switch(module)
if(1)
if(module_active == module_state_1)
inv1.icon_state = "inv1"
module_active = null
if(2)
if(module_active == module_state_2)
inv2.icon_state = "inv2"
module_active = null
if(3)
if(module_active == module_state_3)
inv3.icon_state = "inv3"
module_active = null
if(module < 1 || module > CYBORG_MAX_MODULES)
return
selected_item = null
for(var/i in 1 to CYBORG_MAX_MODULES)
var/atom/movable/screen/robot/active_module/inventory = inventory_screens[i]
inventory.deactivate()
update_icons()
return
//toggle_module(module) - Toggles the selection of the module slot specified by "module".
/mob/living/silicon/robot/proc/toggle_module(module) //Module is 1-3
if(module < 1 || module > 3) return
if(module < 1 || module > CYBORG_MAX_MODULES)
return
if(module_selected(module))
deselect_module(module)
else
if(module_active(module))
select_module(module)
else
deselect_module(get_selected_module()) //If we can't do select anything, at least deselect the current module.
return
return
select_module(module)
//cycle_modules() - Cycles through the list of selected modules.
//cycle_modules() - Cycles through the cyborg's modules, or selects the first module if none are selected.
/mob/living/silicon/robot/proc/cycle_modules()
var/slot_start = get_selected_module()
if(slot_start) deselect_module(slot_start) //Only deselect if we have a selected slot.
var/active_slot = 0
for(var/atom/movable/screen/robot/active_module/item in inventory_screens)
if(item.active)
active_slot = item.module_number
var/next_slot = (active_slot % CYBORG_MAX_MODULES) + 1
select_module(next_slot)
var/slot_num
if(slot_start == 0)
slot_num = 0
slot_start = 3
else
slot_num = slot_start
do
slot_num++
if(slot_num > 3) slot_num = 1 //Wrap around.
if(module_active(slot_num))
select_module(slot_num)
return
while(slot_start != slot_num) //If we wrap around without finding any free slots, just give up.
return
/mob/living/silicon/robot/unequip_to(obj/item/target, atom/destination, force = FALSE, silent = FALSE, drop_inventory = TRUE, no_move = FALSE)
if(target == module_active)
if(target == selected_item)
uneq_active(target)
return ..()
/*
* Tries to find and return the module number/index of an item in a borg's inventory using a path
* to_find - ther path of an item that you want to check if it is in any of the borg's 3 active slots
* Returns the index, or FALSE if it's not active
*/
/mob/living/silicon/robot/proc/get_module_by_item(obj/item/to_check)
for(var/i in 1 to CYBORG_MAX_MODULES)
if(istype(all_active_items[i], to_check.type))
return i
return FALSE
/mob/living/silicon/robot/proc/update_module_icon()
if(!hands)
return
@@ -11,7 +11,6 @@
if(.)
handle_robot_hud_updates()
handle_robot_cell()
update_items()
/mob/living/silicon/robot/proc/handle_robot_cell()
@@ -109,17 +108,6 @@
/mob/living/silicon/robot/proc/update_items() // What in the Sam hell is this?
if(client)
for(var/obj/I in get_all_slots())
client.screen |= I
if(module_state_1)
module_state_1:screen_loc = ui_inv1
if(module_state_2)
module_state_2:screen_loc = ui_inv2
if(module_state_3)
module_state_3:screen_loc = ui_inv3
//Robots on fire
/mob/living/silicon/robot/handle_fire()
. = ..()
@@ -21,18 +21,16 @@ GLOBAL_LIST_INIT(robot_verbs_default, list(
// HUD stuff.
var/atom/movable/screen/hands = null
var/atom/movable/screen/inv1 = null
var/atom/movable/screen/inv2 = null
var/atom/movable/screen/inv3 = null
var/list/inventory_screens = list()
var/atom/movable/screen/lamp_button = null
var/atom/movable/screen/thruster_button = null
// 3 Modules can be activated at any one time.
/// A reference to the type of cyborg it is, i.e. Engineering, Security, Medical etc.
var/obj/item/robot_module/module = null
var/module_active = null
var/module_state_1 = null
var/module_state_2 = null
var/module_state_3 = null
/// The item the borg currently has selected, or null if nothing is selected
var/selected_item
/// The list of up to 3 items the borg can have "equipped". The contents will either be CYBORG_EMPTY_MODULE for nothing, or the item selected
var/list/all_active_items = list(CYBORG_EMPTY_MODULE, CYBORG_EMPTY_MODULE, CYBORG_EMPTY_MODULE)
var/obj/item/radio/borg/radio = null
var/mob/living/silicon/ai/connected_ai = null
@@ -1292,29 +1290,29 @@ GLOBAL_LIST_INIT(robot_verbs_default, list(
/mob/living/silicon/robot/Topic(href, href_list)
if(..())
return 1
return TRUE
if(usr != src)
return 1
return TRUE
if(href_list["mach_close"])
var/t1 = "window=[href_list["mach_close"]]"
unset_machine()
src << browse(null, t1)
return 1
return TRUE
if(href_list["mod"])
var/obj/item/O = locate(href_list["mod"])
if(istype(O) && (O.loc == src))
O.attack_self__legacy__attackchain(src)
return 1
return TRUE
if(href_list["act"])
var/obj/item/O = locate(href_list["act"])
if(!istype(O) || !(O.loc == src || O.loc == src.module))
return 1
return TRUE
activate_module(O)
activate_item(O)
//Show alerts window if user clicked on "Show alerts" in chat
if(href_list["showalerts"])
@@ -1324,22 +1322,11 @@ GLOBAL_LIST_INIT(robot_verbs_default, list(
if(href_list["deact"])
var/obj/item/O = locate(href_list["deact"])
if(activated(O))
if(module_state_1 == O)
module_state_1 = null
contents -= O
else if(module_state_2 == O)
module_state_2 = null
contents -= O
else if(module_state_3 == O)
module_state_3 = null
contents -= O
else
to_chat(src, "Module isn't activated.")
uneq_module(O)
else
to_chat(src, "Module isn't activated")
return 1
return 1
return TRUE
return TRUE
/mob/living/silicon/robot/proc/radio_menu()
radio.interact(src)
@@ -1660,7 +1647,7 @@ GLOBAL_LIST_INIT(robot_verbs_default, list(
/mob/living/silicon/robot/destroyer/borg_icons()
if(base_icon == "")
base_icon = icon_state
if(module_active && istype(module_active,/obj/item/borg/destroyer/mobility))
if(selected_item && istype(selected_item, /obj/item/borg/destroyer/mobility))
icon_state = "[base_icon]-roll"
else
icon_state = base_icon
@@ -1738,27 +1725,21 @@ GLOBAL_LIST_INIT(robot_verbs_default, list(
return
/mob/living/silicon/robot/proc/check_module_damage(makes_sound = TRUE)
if(modules_break)
if(health < 50) //Gradual break down of modules as more damage is sustained
if(uneq_module(module_state_3))
if(makes_sound)
audible_message("<span class='warning'>[src] sounds an alarm! \"SYSTEM ERROR: Module 3 OFFLINE.\"</span>")
playsound(loc, 'sound/machines/warning-buzzer.ogg', 50, TRUE)
to_chat(src, "<span class='userdanger'>SYSTEM ERROR: Module 3 OFFLINE.</span>")
if(health < 0)
if(uneq_module(module_state_2))
if(makes_sound)
audible_message("<span class='warning'>[src] sounds an alarm! \"SYSTEM ERROR: Module 2 OFFLINE.\"</span>")
playsound(loc, 'sound/machines/warning-buzzer.ogg', 60, TRUE)
to_chat(src, "<span class='userdanger'>SYSTEM ERROR: Module 2 OFFLINE.</span>")
if(health < -50)
if(uneq_module(module_state_1))
if(makes_sound)
audible_message("<span class='warning'>[src] sounds an alarm! \"CRITICAL ERROR: All modules OFFLINE.\"</span>")
playsound(loc, 'sound/machines/warning-buzzer.ogg', 75, TRUE)
to_chat(src, "<span class='userdanger'>CRITICAL ERROR: All modules OFFLINE.</span>")
if(!modules_break)
return
var/list/broken_modules = list()
if(health < 50) //Gradual break down of modules as more damage is sustained
broken_modules += CYBORG_MODULE_THREE
if(health < 0)
broken_modules += CYBORG_MODULE_TWO
if(health < -50)
broken_modules += CYBORG_MODULE_ONE
for(var/i in 1 to length(broken_modules))
if(uneq_module(all_active_items[broken_modules[i]])) // Since a full list of broken modules would be (3, 2, 1) it has to be a bit wonky
if(makes_sound)
audible_message("<span class='warning'>[src] sounds an alarm! \"SYSTEM ERROR: Module [broken_modules[i]] OFFLINE.\"</span>")
playsound(loc, 'sound/machines/warning-buzzer.ogg', 50, TRUE)
to_chat(src, "<span class='userdanger'>SYSTEM ERROR: Module [broken_modules[i]] OFFLINE.</span>")
/mob/living/silicon/robot/advanced_reagent_vision()
return has_advanced_reagent_vision
@@ -14,7 +14,7 @@
// Counteract magboot slow in 0G.
if(!has_gravity(src) && HAS_TRAIT(src, TRAIT_MAGPULSE))
. -= 2 // The slowdown value on the borg magpulse.
if(module_active && istype(module_active,/obj/item/borg/destroyer/mobility))
if(selected_item && istype(selected_item, /obj/item/borg/destroyer/mobility))
. -= 3
. = min(., slowdown_cap)