Fixes harddels in pinned module code, cleans up a musty pattern that I want to die (#64674)

* Please stop typecasting target, noooooooooooooooooo

* Fixes harddels in pinned module code

The logic for pinned modules was intentionally hanging references to the
mob that pinned the action button. I have depression.

The pinned_to list also was never fully cleared, but that would have
just exasperated the issue. I've converted its use of mobs to refs, and
its use of the module var into something better managed

(Friendly reminder that actions will persist in your nightmares forever
unless they are manually qdel'd, this code wasn't doing that.

Also cleaned up how the pinned_to list is managed, hopefully it's a bit
more action centered now
This commit is contained in:
LemonInTheDark
2022-02-06 11:32:09 -08:00
committed by GitHub
parent 77c9485ecb
commit b48cda6afa
5 changed files with 37 additions and 34 deletions

View File

@@ -4,16 +4,17 @@
check_flags = AB_CHECK_CONSCIOUS
/// Whether this action is intended for the AI. Stuff breaks a lot if this is done differently.
var/ai_action = FALSE
/// The MODsuit linked to this action
var/obj/item/mod/control/mod
/datum/action/item_action/mod/New(Target)
..()
mod = Target
if(!istype(Target, /obj/item/mod/control))
qdel(src)
return
if(ai_action)
background_icon_state = ACTION_BUTTON_DEFAULT_BACKGROUND
/datum/action/item_action/mod/Grant(mob/user)
var/obj/item/mod/control/mod = target
if(ai_action && user != mod.ai)
return
else if(!ai_action && user == mod.ai)
@@ -21,6 +22,7 @@
return ..()
/datum/action/item_action/mod/Remove(mob/user)
var/obj/item/mod/control/mod = target
if(ai_action && user != mod.ai)
return
else if(!ai_action && user == mod.ai)
@@ -30,6 +32,7 @@
/datum/action/item_action/mod/Trigger(trigger_flags)
if(!IsAvailable())
return FALSE
var/obj/item/mod/control/mod = target
if(mod.malfunctioning && prob(75))
mod.balloon_alert(usr, "button malfunctions!")
return FALSE
@@ -44,6 +47,7 @@
. = ..()
if(!.)
return
var/obj/item/mod/control/mod = target
if(trigger_flags & TRIGGER_SECONDARY_ACTION)
mod.quick_deploy(usr)
else
@@ -71,6 +75,7 @@
UpdateButtonIcon()
addtimer(CALLBACK(src, .proc/reset_ready), 3 SECONDS)
return
var/obj/item/mod/control/mod = target
reset_ready()
mod.toggle_activate(usr)
@@ -94,6 +99,7 @@
. = ..()
if(!.)
return
var/obj/item/mod/control/mod = target
mod.quick_module(usr)
/datum/action/item_action/mod/module/ai
@@ -108,6 +114,7 @@
. = ..()
if(!.)
return
var/obj/item/mod/control/mod = target
mod.ui_interact(usr)
/datum/action/item_action/mod/panel/ai
@@ -119,8 +126,8 @@
var/override = FALSE
/// Module we are linked to.
var/obj/item/mod/module/module
/// Mob we are pinned to.
var/mob/pinner
/// A ref to the mob we are pinned to.
var/pinner_ref
/datum/action/item_action/mod/pinned_module/New(Target, obj/item/mod/module/linked_module, mob/user)
if(isAI(user))
@@ -131,13 +138,21 @@
desc = "Quickly activate [linked_module]."
icon_icon = linked_module.icon
button_icon_state = linked_module.icon_state
pinner = user
RegisterSignal(linked_module, COMSIG_MODULE_ACTIVATED, .proc/on_module_activate)
RegisterSignal(linked_module, COMSIG_MODULE_DEACTIVATED, .proc/on_module_deactivate)
RegisterSignal(linked_module, COMSIG_MODULE_USED, .proc/on_module_use)
/datum/action/item_action/mod/pinned_module/Destroy()
module.pinned_to -= pinner_ref
module = null
return ..()
/datum/action/item_action/mod/pinned_module/Grant(mob/user)
if(user != pinner)
var/user_ref = REF(user)
if(!pinner_ref)
pinner_ref = user_ref
module.pinned_to[pinner_ref] = src
else if(pinner_ref != user_ref)
return
return ..()
@@ -145,6 +160,7 @@
. = ..()
if(!.)
return
var/obj/item/mod/control/mod = target
if(!mod.active)
mod.balloon_alert(usr, "suit not on!")
module.on_select()
@@ -153,6 +169,7 @@
. = ..(current_button, force = TRUE)
if(override)
return
var/obj/item/mod/control/mod = target
if(module == mod.selected_module)
current_button.add_overlay(image(icon = 'icons/hud/radial.dmi', icon_state = "module_selected", layer = FLOAT_LAYER-0.1))
else if(module.active)