diff --git a/code/datums/components/jetpack.dm b/code/datums/components/jetpack.dm index 629953f16e0..902a4a3430a 100644 --- a/code/datums/components/jetpack.dm +++ b/code/datums/components/jetpack.dm @@ -3,8 +3,8 @@ // So propulsion through space on move, that sort of thing /datum/component/jetpack dupe_mode = COMPONENT_DUPE_UNIQUE_PASSARGS + /// Checks to ensure if we can move & if we can activate var/datum/callback/check_on_move - var/datum/callback/get_mover /// If we should stabilize ourselves when not drifting var/stabilize = FALSE /// The signal we listen for as an activation @@ -13,6 +13,7 @@ var/deactivation_signal /// The return flag our parent expects for a failed activation var/return_flag + /// The effect system for the jet pack trail var/datum/effect_system/trail_follow/trail /// The typepath to instansiate our trail as, when we need it var/effect_type @@ -23,11 +24,10 @@ * * activation_signal - Signal we activate on * * deactivation_signal - Signal we deactivate on * * return_flag - Flag to return if activation fails - * * get_mover - Callback we use to get the "moving" thing, for trail purposes, alongside signal registration * * check_on_move - Callback we call each time we attempt a move, we expect it to retun true if the move is ok, false otherwise. It expects an arg, TRUE if fuel should be consumed, FALSE othewise * * effect_type - Type of trail_follow to spawn */ -/datum/component/jetpack/Initialize(stabilize, activation_signal, deactivation_signal, return_flag, datum/callback/get_mover, datum/callback/check_on_move, datum/effect_system/trail_follow/effect_type) +/datum/component/jetpack/Initialize(stabilize, activation_signal, deactivation_signal, return_flag, datum/callback/check_on_move, datum/effect_system/trail_follow/effect_type) . = ..() if(!isatom(parent)) return COMPONENT_INCOMPATIBLE @@ -38,15 +38,14 @@ if(deactivation_signal) RegisterSignal(parent, deactivation_signal, PROC_REF(deactivate)) - src.check_on_move = check_on_move - src.get_mover = get_mover src.stabilize = stabilize - src.return_flag = return_flag + src.check_on_move = check_on_move src.activation_signal = activation_signal src.deactivation_signal = deactivation_signal + src.return_flag = return_flag src.effect_type = effect_type -/datum/component/jetpack/InheritComponent(datum/component/component, original, stabilize, activation_signal, deactivation_signal, return_flag, datum/callback/get_mover, datum/callback/check_on_move, datum/effect_system/trail_follow/effect_type) +/datum/component/jetpack/InheritComponent(datum/component/component, original, stabilize, activation_signal, deactivation_signal, return_flag, datum/callback/check_on_move, datum/effect_system/trail_follow/effect_type) UnregisterSignal(parent, src.activation_signal) if(src.deactivation_signal) UnregisterSignal(parent, src.deactivation_signal) @@ -54,50 +53,56 @@ if(deactivation_signal) RegisterSignal(parent, deactivation_signal, PROC_REF(deactivate)) - src.check_on_move = check_on_move - src.get_mover = get_mover src.stabilize = stabilize + src.check_on_move = check_on_move src.activation_signal = activation_signal src.deactivation_signal = deactivation_signal + src.return_flag = return_flag src.effect_type = effect_type - if(trail && effect_type != trail.type) - QDEL_NULL(trail) - setup_trail() + if(trail && trail.effect_type != effect_type) + setup_trail(trail.holder) /datum/component/jetpack/Destroy() - QDEL_NULL(trail) + if(trail) + QDEL_NULL(trail) QDEL_NULL(check_on_move) return ..() -/datum/component/jetpack/proc/setup_trail() - var/mob/moving = get_mover.Invoke() - if(!moving || trail) - return +/datum/component/jetpack/proc/setup_trail(mob/user) + if(trail) + QDEL_NULL(trail) + trail = new effect_type trail.auto_process = FALSE - trail.set_up(moving) + trail.set_up(user) + trail.start() /datum/component/jetpack/proc/activate(datum/source, mob/user) SIGNAL_HANDLER - if(!thrust(user)) + + if(!check_on_move.Invoke(TRUE)) return return_flag - trail.start() + RegisterSignal(user, COMSIG_MOVABLE_MOVED, PROC_REF(move_react)) RegisterSignal(user, COMSIG_MOVABLE_PRE_MOVE, PROC_REF(pre_move_react)) RegisterSignal(user, COMSIG_MOVABLE_SPACEMOVE, PROC_REF(spacemove_react)) RegisterSignal(user, COMSIG_MOVABLE_DRIFT_VISUAL_ATTEMPT, PROC_REF(block_starting_visuals)) RegisterSignal(user, COMSIG_MOVABLE_DRIFT_BLOCK_INPUT, PROC_REF(ignore_ending_block)) + setup_trail(user) + /datum/component/jetpack/proc/deactivate(datum/source, mob/user) SIGNAL_HANDLER - if(user) - UnregisterSignal(user, COMSIG_MOVABLE_MOVED) - UnregisterSignal(user, COMSIG_MOVABLE_PRE_MOVE) - UnregisterSignal(user, COMSIG_MOVABLE_SPACEMOVE) - UnregisterSignal(user, COMSIG_MOVABLE_DRIFT_VISUAL_ATTEMPT) - UnregisterSignal(user, COMSIG_MOVABLE_DRIFT_BLOCK_INPUT) - QDEL_NULL(trail) //delete AFTER unregistering the mob, otherwise you'll get runtimes. + + UnregisterSignal(user, COMSIG_MOVABLE_MOVED) + UnregisterSignal(user, COMSIG_MOVABLE_PRE_MOVE) + UnregisterSignal(user, COMSIG_MOVABLE_SPACEMOVE) + UnregisterSignal(user, COMSIG_MOVABLE_DRIFT_VISUAL_ATTEMPT) + UnregisterSignal(user, COMSIG_MOVABLE_DRIFT_BLOCK_INPUT) + + if(trail) + QDEL_NULL(trail) /datum/component/jetpack/proc/move_react(mob/user) SIGNAL_HANDLER @@ -133,8 +138,6 @@ /datum/component/jetpack/proc/thrust() if(!check_on_move.Invoke(TRUE)) return FALSE - if(!trail) - setup_trail() trail.generate_effect() return TRUE diff --git a/code/game/objects/items/tanks/jetpack.dm b/code/game/objects/items/tanks/jetpack.dm index 39f6608e8a3..339894eb2d8 100644 --- a/code/game/objects/items/tanks/jetpack.dm +++ b/code/game/objects/items/tanks/jetpack.dm @@ -10,25 +10,38 @@ actions_types = list(/datum/action/item_action/set_internals, /datum/action/item_action/toggle_jetpack, /datum/action/item_action/jetpack_stabilization) var/gas_type = /datum/gas/oxygen var/on = FALSE - var/stabilizers = FALSE var/full_speed = TRUE // If the jetpack will have a speedboost in space/nograv or not - var/datum/callback/get_mover - var/datum/callback/check_on_move + var/stabilize = FALSE + var/thrust_callback /obj/item/tank/jetpack/Initialize(mapload) . = ..() - get_mover = CALLBACK(src, PROC_REF(get_user)) - check_on_move = CALLBACK(src, PROC_REF(allow_thrust), 0.01) AddElement(/datum/element/update_icon_updates_onmob, ITEM_SLOT_SUITSTORE) - refresh_jetpack() + thrust_callback = CALLBACK(src, PROC_REF(allow_thrust), 0.01) + configure_jetpack(stabilize) /obj/item/tank/jetpack/Destroy() - get_mover = null - check_on_move = null + thrust_callback = null return ..() -/obj/item/tank/jetpack/proc/refresh_jetpack() - AddComponent(/datum/component/jetpack, stabilizers, COMSIG_JETPACK_ACTIVATED, COMSIG_JETPACK_DEACTIVATED, JETPACK_ACTIVATION_FAILED, get_mover, check_on_move, /datum/effect_system/trail_follow/ion) +/** + * configures/re-configures the jetpack component + * + * Arguments + * stabilize - Should this jetpack be stabalized + */ +/obj/item/tank/jetpack/proc/configure_jetpack(stabilize) + src.stabilize = stabilize + + AddComponent( \ + /datum/component/jetpack, \ + src.stabilize, \ + COMSIG_JETPACK_ACTIVATED, \ + COMSIG_JETPACK_DEACTIVATED, \ + JETPACK_ACTIVATION_FAILED, \ + thrust_callback, \ + /datum/effect_system/trail_follow/ion \ + ) /obj/item/tank/jetpack/item_action_slot_check(slot) if(slot & slot_flags) @@ -55,8 +68,8 @@ cycle(user) else if(istype(action, /datum/action/item_action/jetpack_stabilization)) if(on) - set_stabilizers(!stabilizers) - to_chat(user, span_notice("You turn the jetpack stabilization [stabilizers ? "on" : "off"].")) + configure_jetpack(!stabilize) + to_chat(user, span_notice("You turn the jetpack stabilization [stabilize ? "on" : "off"].")) else toggle_internals(user) @@ -73,13 +86,8 @@ else turn_off(user) to_chat(user, span_notice("You turn the jetpack off.")) - update_item_action_buttons() -/obj/item/tank/jetpack/proc/set_stabilizers(new_stabilizers) - if(new_stabilizers == stabilizers) - return - stabilizers = new_stabilizers - refresh_jetpack() + update_item_action_buttons() /obj/item/tank/jetpack/update_icon_state() . = ..() @@ -97,14 +105,17 @@ /obj/item/tank/jetpack/proc/turn_off(mob/user) SEND_SIGNAL(src, COMSIG_JETPACK_DEACTIVATED, user) on = FALSE - set_stabilizers(FALSE) update_icon(UPDATE_ICON_STATE) if(user) user.remove_movespeed_modifier(/datum/movespeed_modifier/jetpack/fullspeed) /obj/item/tank/jetpack/proc/allow_thrust(num, use_fuel = TRUE) + if(!ismob(loc)) + return FALSE + var/mob/user = loc + if((num < 0.005 || air_contents.total_moles() < num)) - turn_off(get_user()) + turn_off(user) return FALSE // We've got the gas, it's chill @@ -113,19 +124,13 @@ var/datum/gas_mixture/removed = remove_air(num) if(removed.total_moles() < 0.005) - turn_off(get_user()) + turn_off(user) return FALSE var/turf/T = get_turf(src) T.assume_air(removed) return TRUE -// Gives the jetpack component the user it expects -/obj/item/tank/jetpack/proc/get_user() - if(!ismob(loc)) - return null - return loc - /obj/item/tank/jetpack/suicide_act(mob/living/user) if (!ishuman(user)) return @@ -146,9 +151,10 @@ full_speed = FALSE //moves at modsuit jetpack speeds /obj/item/tank/jetpack/improvised/allow_thrust(num) - var/mob/user = get_user() - if(!user) + if(!ismob(loc)) return FALSE + + var/mob/user = loc if(rand(0,250) == 0) to_chat(user, span_notice("You feel your jetpack's engines cut out.")) turn_off(user) diff --git a/code/modules/mod/modules/_module.dm b/code/modules/mod/modules/_module.dm index 36f0f84d201..882796704bc 100644 --- a/code/modules/mod/modules/_module.dm +++ b/code/modules/mod/modules/_module.dm @@ -96,7 +96,7 @@ //specifically a to_chat because the user is phased out. to_chat(mod.wearer, span_warning("You cannot activate this right now.")) return FALSE - if(SEND_SIGNAL(src, COMSIG_MODULE_TRIGGERED) & MOD_ABORT_USE) + if(SEND_SIGNAL(src, COMSIG_MODULE_TRIGGERED, mod.wearer) & MOD_ABORT_USE) return FALSE if(module_type == MODULE_ACTIVE) if(mod.selected_module && !mod.selected_module.on_deactivation(display_message = FALSE)) @@ -136,7 +136,7 @@ UnregisterSignal(mod.wearer, used_signal) used_signal = null mod.wearer.update_clothing(mod.slot_flags) - SEND_SIGNAL(src, COMSIG_MODULE_DEACTIVATED) + SEND_SIGNAL(src, COMSIG_MODULE_DEACTIVATED, mod.wearer) return TRUE /// Called when the module is used @@ -151,7 +151,7 @@ //specifically a to_chat because the user is phased out. to_chat(mod.wearer, span_warning("You cannot activate this right now.")) return FALSE - if(SEND_SIGNAL(src, COMSIG_MODULE_TRIGGERED) & MOD_ABORT_USE) + if(SEND_SIGNAL(src, COMSIG_MODULE_TRIGGERED, mod.wearer) & MOD_ABORT_USE) return FALSE COOLDOWN_START(src, cooldown_timer, cooldown_time) addtimer(CALLBACK(mod.wearer, TYPE_PROC_REF(/mob, update_clothing), mod.slot_flags), cooldown_time+1) //need to run it a bit after the cooldown starts to avoid conflicts diff --git a/code/modules/mod/modules/modules_general.dm b/code/modules/mod/modules/modules_general.dm index 8054ccdc78c..ab878f5e0eb 100644 --- a/code/modules/mod/modules/modules_general.dm +++ b/code/modules/mod/modules/modules_general.dm @@ -96,32 +96,38 @@ cooldown_time = 0.5 SECONDS overlay_state_inactive = "module_jetpack" overlay_state_active = "module_jetpack_on" - /// Do we stop the wearer from gliding in space. - var/stabilizers = FALSE /// Do we give the wearer a speed buff. var/full_speed = FALSE - var/datum/callback/get_mover - var/datum/callback/check_on_move + var/stabilize = FALSE + var/thrust_callback /obj/item/mod/module/jetpack/Initialize(mapload) . = ..() - get_mover = CALLBACK(src, PROC_REF(get_user)) - check_on_move = CALLBACK(src, PROC_REF(allow_thrust)) - refresh_jetpack() + thrust_callback = CALLBACK(src, PROC_REF(allow_thrust)) + configure_jetpack(stabilize) /obj/item/mod/module/jetpack/Destroy() - get_mover = null - check_on_move = null + thrust_callback = null return ..() -/obj/item/mod/module/jetpack/proc/refresh_jetpack() - AddComponent(/datum/component/jetpack, stabilizers, COMSIG_MODULE_TRIGGERED, COMSIG_MODULE_DEACTIVATED, MOD_ABORT_USE, get_mover, check_on_move, /datum/effect_system/trail_follow/ion/grav_allowed) +/** + * configures/re-configures the jetpack component + * + * Arguments + * stabilize - Should this jetpack be stabalized + */ +/obj/item/mod/module/jetpack/proc/configure_jetpack(stabilize) + src.stabilize = stabilize -/obj/item/mod/module/jetpack/proc/set_stabilizers(new_stabilizers) - if(stabilizers == new_stabilizers) - return - stabilizers = new_stabilizers - refresh_jetpack() + AddComponent( \ + /datum/component/jetpack, \ + src.stabilize, \ + COMSIG_MODULE_TRIGGERED, \ + COMSIG_MODULE_DEACTIVATED, \ + MOD_ABORT_USE, \ + thrust_callback, \ + /datum/effect_system/trail_follow/ion/grav_allowed \ + ) /obj/item/mod/module/jetpack/on_activation() . = ..() @@ -137,12 +143,12 @@ /obj/item/mod/module/jetpack/get_configuration() . = ..() - .["stabilizers"] = add_ui_configuration("Stabilizers", "bool", stabilizers) + .["stabilizers"] = add_ui_configuration("Stabilizers", "bool", stabilize) /obj/item/mod/module/jetpack/configure_edit(key, value) switch(key) if("stabilizers") - set_stabilizers(text2num(value)) + configure_jetpack(text2num(value)) /obj/item/mod/module/jetpack/proc/allow_thrust(use_fuel = TRUE) if(!use_fuel) @@ -151,9 +157,6 @@ return FALSE return TRUE -/obj/item/mod/module/jetpack/proc/get_user() - return mod.wearer - /obj/item/mod/module/jetpack/advanced name = "MOD advanced ion jetpack module" desc = "An improvement on the previous model of electric thrusters. This one achieves higher speeds through \ diff --git a/code/modules/mod/modules/modules_timeline.dm b/code/modules/mod/modules/modules_timeline.dm index 4a71ce44d21..f403da6387e 100644 --- a/code/modules/mod/modules/modules_timeline.dm +++ b/code/modules/mod/modules/modules_timeline.dm @@ -92,9 +92,9 @@ return MOD_CANCEL_ACTIVATE ///Signal fired when wearer attempts to trigger modules, if attempting while time is stopped -/obj/item/mod/module/rewinder/proc/on_module_triggered(datum/source) +/obj/item/mod/module/rewinder/proc/on_module_triggered(datum/source, mob/user) SIGNAL_HANDLER - balloon_alert(mod.wearer, "not while rewinding!") + balloon_alert(user, "not while rewinding!") return MOD_ABORT_USE ///Timestopper - Need I really explain? It's the wizard's time stop, but the user channels it by not moving instead of a duration. diff --git a/code/modules/surgery/organs/internal/cyberimp/augments_chest.dm b/code/modules/surgery/organs/internal/cyberimp/augments_chest.dm index 49b0ba08a43..60322a7f8d6 100644 --- a/code/modules/surgery/organs/internal/cyberimp/augments_chest.dm +++ b/code/modules/surgery/organs/internal/cyberimp/augments_chest.dm @@ -128,22 +128,18 @@ actions_types = list(/datum/action/item_action/organ_action/toggle) w_class = WEIGHT_CLASS_NORMAL var/on = FALSE - var/datum/callback/get_mover - var/datum/callback/check_on_move /obj/item/organ/internal/cyberimp/chest/thrusters/Initialize(mapload) . = ..() - get_mover = CALLBACK(src, PROC_REF(get_user)) - check_on_move = CALLBACK(src, PROC_REF(allow_thrust), 0.01) - refresh_jetpack() - -/obj/item/organ/internal/cyberimp/chest/thrusters/Destroy() - get_mover = null - check_on_move = null - return ..() - -/obj/item/organ/internal/cyberimp/chest/thrusters/proc/refresh_jetpack() - AddComponent(/datum/component/jetpack, FALSE, COMSIG_THRUSTER_ACTIVATED, COMSIG_THRUSTER_DEACTIVATED, THRUSTER_ACTIVATION_FAILED, get_mover, check_on_move, /datum/effect_system/trail_follow/ion) + AddComponent( \ + /datum/component/jetpack, \ + FALSE, \ + COMSIG_THRUSTER_ACTIVATED, \ + COMSIG_THRUSTER_DEACTIVATED, \ + THRUSTER_ACTIVATION_FAILED, \ + CALLBACK(src, PROC_REF(allow_thrust), 0.01), \ + /datum/effect_system/trail_follow/ion \ + ) /obj/item/organ/internal/cyberimp/chest/thrusters/Remove(mob/living/carbon/thruster_owner, special = 0) if(on) @@ -166,7 +162,7 @@ if(!silent) to_chat(owner, span_warning("Your thrusters set seems to be broken!")) return - if(SEND_SIGNAL(src, COMSIG_THRUSTER_ACTIVATED) & THRUSTER_ACTIVATION_FAILED) + if(SEND_SIGNAL(src, COMSIG_THRUSTER_ACTIVATED, owner) & THRUSTER_ACTIVATION_FAILED) return on = TRUE @@ -178,7 +174,7 @@ /obj/item/organ/internal/cyberimp/chest/thrusters/proc/deactivate(silent = FALSE) if(!on) return - SEND_SIGNAL(src, COMSIG_THRUSTER_DEACTIVATED) + SEND_SIGNAL(src, COMSIG_THRUSTER_DEACTIVATED, owner) owner.remove_movespeed_modifier(/datum/movespeed_modifier/jetpack/cybernetic) if(!silent) to_chat(owner, span_notice("You turn your thrusters set off.")) @@ -223,6 +219,3 @@ deactivate(silent = TRUE) return FALSE - -/obj/item/organ/internal/cyberimp/chest/thrusters/proc/get_user() - return owner