diff --git a/code/__DEFINES/dcs/signals/signals_mod.dm b/code/__DEFINES/dcs/signals/signals_mod.dm index e5c27a902a6..2533b698528 100644 --- a/code/__DEFINES/dcs/signals/signals_mod.dm +++ b/code/__DEFINES/dcs/signals/signals_mod.dm @@ -1,17 +1,27 @@ //MODsuit signals /// Called when a module is selected to be the active one from on_select(obj/item/mod/module/module) #define COMSIG_MOD_MODULE_SELECTED "mod_module_selected" +/// Called when a MOD deploys one or more of its parts. +#define COMSIG_MOD_DEPLOYED "mod_deployed" +/// Called when a MOD retracts one or more of its parts. +#define COMSIG_MOD_RETRACTED "mod_retracted" +/// Called when a MOD is finished toggling itself. +#define COMSIG_MOD_TOGGLED "mod_toggled" /// Called when a MOD activation is called from toggle_activate(mob/user) #define COMSIG_MOD_ACTIVATE "mod_activate" /// Cancels the suit's activation #define MOD_CANCEL_ACTIVATE (1 << 0) +/// Called when a MOD finishes having a module removed from it. +#define COMSIG_MOD_MODULE_REMOVED "mod_module_removed" +/// Called when a MOD finishes having a module added to it. +#define COMSIG_MOD_MODULE_ADDED "mod_module_added" /// Called when a MOD is having modules removed from crowbar_act(mob/user, obj/crowbar) #define COMSIG_MOD_MODULE_REMOVAL "mod_module_removal" /// Cancels the removal of modules #define MOD_CANCEL_REMOVAL (1 << 0) /// Called when a module attempts to activate, however it does. At the end of checks so you can add some yourself, or work on trigger behavior (mob/user) #define COMSIG_MODULE_TRIGGERED "mod_module_triggered" - // Cancels activation, with no message. include feedback on your cancel. + /// Cancels activation, with no message. Include feedback on your cancel. #define MOD_ABORT_USE (1<<0) /// Called when a module activates, after all checks have passed and cooldown started. #define COMSIG_MODULE_ACTIVATED "mod_module_activated" diff --git a/code/modules/mod/mod_activation.dm b/code/modules/mod/mod_activation.dm index 2fc7cdf595e..a236206b5e1 100644 --- a/code/modules/mod/mod_activation.dm +++ b/code/modules/mod/mod_activation.dm @@ -26,6 +26,7 @@ var/parts_to_check = mod_parts - part if(part.loc == src) deploy(user, part) + on_mod_deployed(user) for(var/obj/item/checking_part as anything in parts_to_check) if(checking_part.loc != src) continue @@ -33,6 +34,7 @@ break else retract(user, part) + on_mod_retracted(user) for(var/obj/item/checking_part as anything in parts_to_check) if(checking_part.loc == src) continue @@ -45,11 +47,12 @@ balloon_alert(user, "deactivate the suit first!") playsound(src, 'sound/machines/scanbuzz.ogg', 25, TRUE, SILENCED_SOUND_EXTRARANGE) return FALSE - var/deploy = FALSE + var/deploy = TRUE for(var/obj/item/part as anything in mod_parts) - if(part.loc != src) + if(part.loc == src) continue - deploy = TRUE + deploy = FALSE + break for(var/obj/item/part as anything in mod_parts) if(deploy && part.loc == src) deploy(null, part) @@ -59,6 +62,10 @@ span_notice("[src] [deploy ? "deploys" : "retracts"] its' parts with a mechanical hiss."), span_hear("You hear a mechanical hiss.")) playsound(src, 'sound/mecha/mechmove03.ogg', 25, TRUE, SHORT_RANGE_SOUND_EXTRARANGE) + if(deploy) + on_mod_deployed(user) + else + on_mod_retracted(user) return TRUE /// Deploys a part of the suit onto the user. @@ -178,6 +185,7 @@ else playsound(src, 'sound/machines/synth_no.ogg', 50, TRUE, SHORT_RANGE_SOUND_EXTRARANGE, frequency = 6000) activating = FALSE + SEND_SIGNAL(src, COMSIG_MOD_TOGGLED, user) return TRUE ///Seals or unseals the given part @@ -243,4 +251,10 @@ /obj/item/mod/control/proc/has_wearer() return wearer +/obj/item/mod/control/proc/on_mod_deployed(mob/user) + SEND_SIGNAL(src, COMSIG_MOD_DEPLOYED, user) + +/obj/item/mod/control/proc/on_mod_retracted(mob/user) + SEND_SIGNAL(src, COMSIG_MOD_RETRACTED, user) + #undef MOD_ACTIVATION_STEP_FLAGS diff --git a/code/modules/mod/mod_control.dm b/code/modules/mod/mod_control.dm index 2baa588030c..5a91fe0fcba 100644 --- a/code/modules/mod/mod_control.dm +++ b/code/modules/mod/mod_control.dm @@ -349,6 +349,7 @@ uninstall(module_to_remove) module_to_remove.forceMove(drop_location()) crowbar.play_tool_sound(src, 100) + SEND_SIGNAL(src, COMSIG_MOD_MODULE_REMOVED, user) return TRUE balloon_alert(user, "no modules!") playsound(src, 'sound/machines/scanbuzz.ogg', 25, TRUE, SILENCED_SOUND_EXTRARANGE) @@ -361,6 +362,7 @@ playsound(src, 'sound/machines/scanbuzz.ogg', 25, TRUE, SILENCED_SOUND_EXTRARANGE) return FALSE install(attacking_item, user) + SEND_SIGNAL(src, COMSIG_MOD_MODULE_ADDED, user) return TRUE else if(istype(attacking_item, /obj/item/mod/core)) if(!open) diff --git a/code/modules/wiremod/shell/module.dm b/code/modules/wiremod/shell/module.dm index 5bb837134b3..81b767a5b78 100644 --- a/code/modules/wiremod/shell/module.dm +++ b/code/modules/wiremod/shell/module.dm @@ -79,7 +79,10 @@ var/obj/item/mod/module/attached_module /// The name of the module to select - var/datum/port/input/module_to_select + var/datum/port/input/option/module_to_select + + /// The signal to toggle deployment of the modsuit + var/datum/port/input/toggle_deploy /// The signal to toggle the suit var/datum/port/input/toggle_suit @@ -90,32 +93,56 @@ /// A reference to the wearer of the MODsuit var/datum/port/output/wearer + /// Whether or not the suit is deployed + var/datum/port/output/deployed + + /// Whether or not the suit is activated + var/datum/port/output/activated + /// The name of the last selected module var/datum/port/output/selected_module + /// A list of the names of all currently deployed parts + var/datum/port/output/deployed_parts + /// The signal that is triggered when a module is selected var/datum/port/output/on_module_selected + /// The signal that is triggered when the suit is deployed by a signal + var/datum/port/output/on_deploy + + /// The signal that is triggered when the suit has finished toggling itself after being activated by a signal + var/datum/port/output/on_toggle_finish + +/obj/item/circuit_component/mod_adapter_core/populate_options() + module_to_select = add_option_port("Module to Select", list()) + /obj/item/circuit_component/mod_adapter_core/populate_ports() // Input Signals - module_to_select = add_input_port("Module to Select", PORT_TYPE_STRING) + toggle_deploy = add_input_port("Toggle Deployment", PORT_TYPE_SIGNAL) toggle_suit = add_input_port("Toggle Suit", PORT_TYPE_SIGNAL) select_module = add_input_port("Select Module", PORT_TYPE_SIGNAL) // States wearer = add_output_port("Wearer", PORT_TYPE_ATOM) + deployed = add_output_port("Deployed", PORT_TYPE_NUMBER) + activated = add_output_port("Activated", PORT_TYPE_NUMBER) selected_module = add_output_port("Selected Module", PORT_TYPE_STRING) + deployed_parts = add_output_port("Deployed Parts", PORT_TYPE_LIST(PORT_TYPE_STRING)) // Output Signals on_module_selected = add_output_port("On Module Selected", PORT_TYPE_SIGNAL) + on_deploy = add_output_port("On Deploy", PORT_TYPE_SIGNAL) + on_toggle_finish = add_output_port("Finished Toggling", PORT_TYPE_SIGNAL) /obj/item/circuit_component/mod_adapter_core/register_shell(atom/movable/shell) . = ..() if(istype(shell, /obj/item/mod/module)) attached_module = shell - RegisterSignal(attached_module, COMSIG_MOVABLE_MOVED, .proc/on_move) + RegisterSignal(attached_module, COMSIG_MOVABLE_MOVED, .proc/on_move) /obj/item/circuit_component/mod_adapter_core/unregister_shell(atom/movable/shell) - UnregisterSignal(attached_module, COMSIG_MOVABLE_MOVED) - attached_module = null + if(attached_module) + UnregisterSignal(attached_module, COMSIG_MOVABLE_MOVED) + attached_module = null return ..() /obj/item/circuit_component/mod_adapter_core/input_received(datum/port/input/port) @@ -127,29 +154,86 @@ module = potential_module if(COMPONENT_TRIGGERED_BY(toggle_suit, port)) INVOKE_ASYNC(attached_module.mod, /obj/item/mod/control.proc/toggle_activate, attached_module.mod.wearer) + if(COMPONENT_TRIGGERED_BY(toggle_deploy, port)) + INVOKE_ASYNC(attached_module.mod, /obj/item/mod/control.proc/quick_deploy, attached_module.mod.wearer) if(attached_module.mod.active && module && COMPONENT_TRIGGERED_BY(select_module, port)) INVOKE_ASYNC(module, /obj/item/mod/module.proc/on_select) /obj/item/circuit_component/mod_adapter_core/proc/on_move(atom/movable/source, atom/old_loc, dir, forced) SIGNAL_HANDLER if(istype(source.loc, /obj/item/mod/control)) - RegisterSignal(source.loc, COMSIG_MOD_MODULE_SELECTED, .proc/on_module_select) - RegisterSignal(source.loc, COMSIG_ITEM_EQUIPPED, .proc/equip_check) - equip_check() + var/obj/item/mod/control/mod = source.loc + RegisterSignal(mod, COMSIG_MOD_MODULE_SELECTED, .proc/on_module_select) + RegisterSignal(mod, COMSIG_MOD_DEPLOYED, .proc/on_mod_part_toggled) + RegisterSignal(mod, COMSIG_MOD_RETRACTED, .proc/on_mod_part_toggled) + RegisterSignal(mod, COMSIG_MOD_TOGGLED, .proc/on_mod_toggled) + RegisterSignal(mod, COMSIG_MOD_MODULE_ADDED, .proc/on_module_changed) + RegisterSignal(mod, COMSIG_MOD_MODULE_REMOVED, .proc/on_module_changed) + RegisterSignal(mod, COMSIG_ITEM_EQUIPPED, .proc/equip_check) + wearer.set_output(mod.wearer) + var/modules_list = list() + for(var/obj/item/mod/module/module in mod.modules) + if(module.module_type != MODULE_PASSIVE) + modules_list += module.name + module_to_select.possible_options = modules_list + if (module_to_select.possible_options.len) + module_to_select.set_value(module_to_select.possible_options[1]) else if(istype(old_loc, /obj/item/mod/control)) UnregisterSignal(old_loc, list(COMSIG_MOD_MODULE_SELECTED, COMSIG_ITEM_EQUIPPED)) + UnregisterSignal(old_loc, COMSIG_MOD_DEPLOYED) + UnregisterSignal(old_loc, COMSIG_MOD_RETRACTED) + UnregisterSignal(old_loc, COMSIG_MOD_TOGGLED) + UnregisterSignal(old_loc, COMSIG_MOD_MODULE_ADDED) + UnregisterSignal(old_loc, COMSIG_MOD_MODULE_REMOVED) selected_module.set_output(null) wearer.set_output(null) + deployed.set_output(FALSE) + activated.set_output(FALSE) /obj/item/circuit_component/mod_adapter_core/proc/on_module_select(datum/source, obj/item/mod/module/module) SIGNAL_HANDLER selected_module.set_output(module.name) on_module_selected.set_output(COMPONENT_SIGNAL) +/obj/item/circuit_component/mod_adapter_core/proc/on_module_changed() + SIGNAL_HANDLER + var/modules_list = list() + for(var/obj/item/mod/module/module in attached_module.mod.modules) + if(module.module_type != MODULE_PASSIVE) + modules_list += module.name + module_to_select.possible_options = modules_list + if (module_to_select.possible_options.len) + module_to_select.set_value(module_to_select.possible_options[1]) + +/obj/item/circuit_component/mod_adapter_core/proc/on_mod_part_toggled() + SIGNAL_HANDLER + var/string_list = list() + var/is_deployed = TRUE + for(var/obj/item/part as anything in attached_module.mod.mod_parts) + if(part.loc == attached_module.mod) + is_deployed = FALSE + else + var/part_name = "Undefined" + if(istype(part, /obj/item/clothing/head/mod)) + part_name = "Helmet" + if(istype(part, /obj/item/clothing/suit/mod)) + part_name = "Chestplate" + if(istype(part, /obj/item/clothing/gloves/mod)) + part_name = "Gloves" + if(istype(part, /obj/item/clothing/shoes/mod)) + part_name = "Boots" + string_list += part_name + deployed_parts.set_output(string_list) + deployed.set_output(is_deployed) + on_deploy.set_output(COMPONENT_SIGNAL) + +/obj/item/circuit_component/mod_adapter_core/proc/on_mod_toggled() + SIGNAL_HANDLER + activated.set_output(attached_module.mod.active) + on_toggle_finish.set_output(COMPONENT_SIGNAL) /obj/item/circuit_component/mod_adapter_core/proc/equip_check() SIGNAL_HANDLER - if(!attached_module.mod?.wearer) return wearer.set_output(attached_module.mod.wearer)