-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
qol: optimize trim, inheritance for animal_temp + components (#6209)
* meow * Update paradise.dme * Destroy() * comments * Update death_linked.dm * Update code/__HELPERS/text.dm Co-authored-by: BeebBeebBoob <[email protected]> --------- Co-authored-by: BeebBeebBoob <[email protected]>
- Loading branch information
1 parent
fef0557
commit 1bc45a9
Showing
5 changed files
with
179 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* ## Death link component | ||
* | ||
* When the owner of this component dies it also gibs a linked mobs | ||
*/ | ||
/datum/component/death_linked | ||
dupe_mode = COMPONENT_DUPE_UNIQUE_PASSARGS | ||
/// Mobs in that list will die when the user dies. Contains weakrefs | ||
var/list/linked_mobs | ||
|
||
/datum/component/death_linked/Initialize(list/mobs) | ||
. = ..() | ||
|
||
if(!isliving(parent)) | ||
return COMPONENT_INCOMPATIBLE | ||
|
||
for(var/mob/mob as anything in mobs) | ||
LAZYADD(linked_mobs, WEAKREF(mob)) | ||
|
||
/datum/component/death_linked/Destroy(force) | ||
LAZYNULL(linked_mobs) | ||
|
||
return ..() | ||
|
||
/datum/component/death_linked/InheritComponent(datum/component/death_linked/new_comp, i_am_original, list/mobs) | ||
if(!i_am_original) | ||
return | ||
|
||
if(!LAZYLEN(mobs)) | ||
return | ||
|
||
for(var/mob/mob as anything in mobs) | ||
LAZYADD(linked_mobs, WEAKREF(mob)) | ||
|
||
/datum/component/death_linked/RegisterWithParent() | ||
. = ..() | ||
RegisterSignal(parent, COMSIG_LIVING_DEATH, PROC_REF(on_death)) | ||
|
||
/datum/component/death_linked/UnregisterFromParent() | ||
. = ..() | ||
UnregisterSignal(parent, COMSIG_LIVING_DEATH) | ||
|
||
/datum/component/death_linked/proc/on_death(mob/living/target, gibbed) | ||
SIGNAL_HANDLER | ||
|
||
if(!LAZYLEN(linked_mobs)) | ||
return | ||
|
||
for(var/datum/weakref/weakref as anything in linked_mobs) | ||
var/mob/living/linked_mob_resolved = weakref.resolve() | ||
linked_mob_resolved?.gib() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** Holder Loving Component | ||
* | ||
* When you drop an object onto a turf it gets moved back into its parent holder | ||
* | ||
* Prevents you from force moving the object into any other location that isn't its parent holder | ||
*/ | ||
/datum/component/holderloving | ||
/** Item that parent is bound to. | ||
* We try to keep parent either directly in holder, or in holder's loc if loc is a mob, | ||
* and warp parent into holder if they go anywhere else. | ||
*/ | ||
var/atom/holder | ||
|
||
/datum/component/holderloving/Initialize(holder) | ||
if(!isitem(parent) || !holder) | ||
return COMPONENT_INCOMPATIBLE | ||
|
||
src.holder = holder | ||
|
||
/datum/component/holderloving/Destroy(force) | ||
holder = null | ||
|
||
return ..() | ||
|
||
/datum/component/holderloving/RegisterWithParent() | ||
RegisterSignal(holder, COMSIG_QDELETING, PROC_REF(holder_deleting)) | ||
RegisterSignal(parent, COMSIG_ITEM_DROPPED, PROC_REF(check_my_loc)) | ||
RegisterSignal(parent, COMSIG_ITEM_PRE_UNEQUIP, PROC_REF(can_be_moved)) | ||
|
||
/datum/component/holderloving/UnregisterFromParent() | ||
UnregisterSignal(holder, list(COMSIG_QDELETING)) | ||
UnregisterSignal(parent, list(COMSIG_ITEM_DROPPED, COMSIG_ITEM_PRE_UNEQUIP)) | ||
|
||
/datum/component/holderloving/proc/holder_deleting(datum/source, force) | ||
SIGNAL_HANDLER | ||
|
||
qdel(parent) | ||
|
||
/datum/component/holderloving/proc/is_valid_location(atom/location) | ||
SHOULD_BE_PURE(TRUE) | ||
|
||
if(location == holder || (location == holder.loc && ismob(holder.loc))) | ||
return TRUE | ||
|
||
return FALSE | ||
|
||
/datum/component/holderloving/proc/check_my_loc(datum/source, mob/user, slot) | ||
SIGNAL_HANDLER | ||
|
||
var/obj/item/item_parent = parent | ||
if(!is_valid_location(item_parent.loc)) | ||
item_parent.forceMove(holder) | ||
|
||
/datum/component/holderloving/proc/can_be_moved( | ||
obj/item/I, | ||
force, | ||
atom/newloc, | ||
no_move, | ||
invdrop, | ||
silent | ||
) | ||
SIGNAL_HANDLER | ||
|
||
// allow the item to be dropped on the turf so it can be later moved back into the holder as a convinience tool | ||
if(isturf(newloc) || is_valid_location(newloc)) | ||
return NONE | ||
|
||
// prevent this item from being moved anywhere else | ||
return COMPONENT_ITEM_BLOCK_UNEQUIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters