Files
Bubberstation/code/datums/components/ai_retaliate_advanced.dm
Mothblocks c1d68698fb Micro-optimize qdel by only permitting one parameter (#80628)
Productionizes #80615.

The core optimization is this:

```patch
-	var/hint = to_delete.Destroy(arglist(args.Copy(2))) // Let our friend know they're about to get fucked up.
+	var/hint = to_delete.Destroy(force) // Let our friend know they're about to get fucked up.
```

We avoid a heap allocation in the form of copying the args over to a new
list. A/B testing shows this results in 33% better overtime, and in a
real round shaving off a full second of self time and 0.4 seconds of
overtime--both of these would be doubled in the event this is merged as
the new proc was only being run 50% of the time.
2023-12-28 13:52:44 -08:00

38 lines
1.4 KiB
Plaintext

/**
* Attached to a mob with an AI controller, passes things which have damaged it to a blackboard.
* The AI controller is responsible for doing anything with that information.
* Differs from the element as it passes new entries through a callback.
*/
/datum/component/ai_retaliate_advanced
/// Callback to a mob for custom behaviour
var/datum/callback/post_retaliate_callback
/datum/component/ai_retaliate_advanced/Initialize(datum/callback/post_retaliate_callback)
if(!ismob(parent))
return ELEMENT_INCOMPATIBLE
src.post_retaliate_callback = post_retaliate_callback
parent.AddElement(/datum/element/relay_attackers)
ADD_TRAIT(parent, TRAIT_SUBTREE_REQUIRED_OPERATIONAL_DATUM, type)
/datum/component/ai_retaliate_advanced/Destroy(force)
post_retaliate_callback = null
return ..()
/datum/component/ai_retaliate_advanced/RegisterWithParent()
RegisterSignal(parent, COMSIG_ATOM_WAS_ATTACKED, PROC_REF(on_attacked))
/datum/component/ai_retaliate_advanced/UnregisterFromParent()
UnregisterSignal(parent, COMSIG_ATOM_WAS_ATTACKED)
/// Add an attacking atom to a blackboard list of things which attacked us
/datum/component/ai_retaliate_advanced/proc/on_attacked(mob/victim, atom/attacker)
SIGNAL_HANDLER
if (!victim.ai_controller)
return
victim.ai_controller.insert_blackboard_key_lazylist(BB_BASIC_MOB_RETALIATE_LIST, attacker)
post_retaliate_callback?.InvokeAsync(attacker)