From 970929034ef87a32a98b6686415ba7ce8ff9d6a1 Mon Sep 17 00:00:00 2001 From: Antoonij <42318445+Antoonij@users.noreply.github.com> Date: Fri, 22 Nov 2024 09:23:26 +0100 Subject: [PATCH 1/6] meow --- code/__HELPERS/text.dm | 27 ++------ code/datums/components/animal_temperature.dm | 66 +++++++++++++++----- code/datums/components/death_linked.dm | 47 ++++++++++++++ code/datums/components/holderloving.dm | 64 +++++++++++++++++++ paradise.dme | 2 + 5 files changed, 170 insertions(+), 36 deletions(-) create mode 100644 code/datums/components/death_linked.dm create mode 100644 code/datums/components/holderloving.dm diff --git a/code/__HELPERS/text.dm b/code/__HELPERS/text.dm index 2369f9c8f64..3b6ce478cfc 100644 --- a/code/__HELPERS/text.dm +++ b/code/__HELPERS/text.dm @@ -307,9 +307,12 @@ return "" -//Returns a string with reserved characters and spaces before the first word and after the last word removed. -/proc/trim(text) - return trim_reduced(text) +/// Returns a string with reserved characters and spaces before the first word and after the last word removed. +/proc/trim(text, max_length) + if(max_length) + text = copytext_char(text, 1, max_length) + + return trimtext(text) /// Returns a string that does not exceed max_length characters in size /proc/trim_length(text, max_length) @@ -803,21 +806,3 @@ if(ofthree == 0) return "[num]" return "[num / (10 ** (ofthree * 3))][GLOB.si_suffixes[round(length(GLOB.si_suffixes) / 2) + ofthree + 1]]" - -//Returns a string with reserved characters and spaces after the first and last letters removed -//Like trim(), but very slightly faster. worth it for niche usecases -/proc/trim_reduced(text) - var/starting_coord = 1 - var/text_len = length(text) - for (var/i in 1 to text_len) - if (text2ascii(text, i) > 32) - starting_coord = i - break - - for (var/i = text_len, i >= starting_coord, i--) - if (text2ascii(text, i) > 32) - return copytext(text, starting_coord, i + 1) - - if(starting_coord > 1) - return copytext(text, starting_coord) - return "" diff --git a/code/datums/components/animal_temperature.dm b/code/datums/components/animal_temperature.dm index b224564995f..c490a4afc66 100644 --- a/code/datums/components/animal_temperature.dm +++ b/code/datums/components/animal_temperature.dm @@ -1,31 +1,67 @@ /datum/component/animal_temperature dupe_mode = COMPONENT_DUPE_UNIQUE_PASSARGS /// Min body temp - var/minbodytemp + var/minbodytemp = 250 /// Max body temp - var/maxbodytemp + var/maxbodytemp = 350 /// Damage when below min temp - var/cold_damage + var/cold_damage = 2 /// Damage when above max temp - var/heat_damage + var/heat_damage = 2 /// If true - alert will be shown - var/show_alert + var/show_alert = FALSE /datum/component/animal_temperature/Initialize( - minbodytemp = 250, - maxbodytemp = 350, - cold_damage = 2, - heat_damage = 2, - show_alert = FALSE + minbodytemp, + maxbodytemp, + cold_damage, + heat_damage, + show_alert ) if(!isanimal(parent)) return COMPONENT_INCOMPATIBLE - src.minbodytemp = minbodytemp - src.maxbodytemp = maxbodytemp - src.cold_damage = cold_damage - src.heat_damage = heat_damage - src.show_alert = show_alert + if(!isnull(minbodytemp)) + src.minbodytemp = minbodytemp + + if(!isnull(maxbodytemp)) + src.maxbodytemp = maxbodytemp + + if(!isnull(cold_damage)) + src.cold_damage = cold_damage + + if(!isnull(heat_damage)) + src.heat_damage = heat_damage + + if(!isnull(show_alert)) + src.show_alert = show_alert + +/datum/component/animal_temperature/InheritComponent( + datum/component/animal_temperature/new_comp, + i_am_original, + minbodytemp, + maxbodytemp, + cold_damage, + heat_damage, + show_alert +) + if(!i_am_original) + return + + if(!isnull(minbodytemp)) + src.minbodytemp = minbodytemp + + if(!isnull(maxbodytemp)) + src.maxbodytemp = maxbodytemp + + if(!isnull(cold_damage)) + src.cold_damage = cold_damage + + if(!isnull(heat_damage)) + src.heat_damage = heat_damage + + if(!isnull(show_alert)) + src.show_alert = show_alert /datum/component/animal_temperature/RegisterWithParent() RegisterSignal(parent, COMSIG_ANIMAL_HANDLE_ENVIRONMENT, PROC_REF(handle_environment)) diff --git a/code/datums/components/death_linked.dm b/code/datums/components/death_linked.dm new file mode 100644 index 00000000000..3c509a17bfc --- /dev/null +++ b/code/datums/components/death_linked.dm @@ -0,0 +1,47 @@ +/** + * ## 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 + /// The mob that also dies when the user dies. Contains weakrefs + var/list/linked_mobs = list() + +/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/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) + +/// signal called by the stat of the target changing +/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() diff --git a/code/datums/components/holderloving.dm b/code/datums/components/holderloving.dm new file mode 100644 index 00000000000..36ab0182752 --- /dev/null +++ b/code/datums/components/holderloving.dm @@ -0,0 +1,64 @@ +/** 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/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 diff --git a/paradise.dme b/paradise.dme index 85c7ad843a5..51018fb1cb6 100644 --- a/paradise.dme +++ b/paradise.dme @@ -446,6 +446,7 @@ #include "code\datums\components\conveyor_movement.dm" #include "code\datums\components\cross_shock.dm" #include "code\datums\components\decal.dm" +#include "code\datums\components\death_linked.dm" #include "code\datums\components\ritual_object.dm" #include "code\datums\components\defibrillator.dm" #include "code\datums\components\drift.dm" @@ -456,6 +457,7 @@ #include "code\datums\components\force_move.dm" #include "code\datums\components\fullauto.dm" #include "code\datums\components\hide_highest_offset.dm" +#include "code\datums\components\holderloving.dm" #include "code\datums\components\jackboots.dm" #include "code\datums\components\jetpack.dm" #include "code\datums\components\label.dm" From 88d8b234e26713e52919f9ff397b2959b26dadac Mon Sep 17 00:00:00 2001 From: Antoonij <42318445+Antoonij@users.noreply.github.com> Date: Sat, 23 Nov 2024 19:17:05 +0100 Subject: [PATCH 2/6] Update paradise.dme --- paradise.dme | 1 - 1 file changed, 1 deletion(-) diff --git a/paradise.dme b/paradise.dme index 34d21624674..c3dc7750a39 100644 --- a/paradise.dme +++ b/paradise.dme @@ -447,7 +447,6 @@ #include "code\datums\components\cross_shock.dm" #include "code\datums\components\decal.dm" #include "code\datums\components\death_linked.dm" -#include "code\datums\components\ritual_object.dm" #include "code\datums\components\defibrillator.dm" #include "code\datums\components\drift.dm" #include "code\datums\components\ducttape.dm" From 1ce9025dfe5a8ed5b1374221d97b20de98b60c7e Mon Sep 17 00:00:00 2001 From: Antoonij <42318445+Antoonij@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:52:34 +0100 Subject: [PATCH 3/6] Destroy() --- code/datums/components/death_linked.dm | 5 +++++ code/datums/components/holderloving.dm | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/code/datums/components/death_linked.dm b/code/datums/components/death_linked.dm index 3c509a17bfc..f119961e5d6 100644 --- a/code/datums/components/death_linked.dm +++ b/code/datums/components/death_linked.dm @@ -17,6 +17,11 @@ 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 diff --git a/code/datums/components/holderloving.dm b/code/datums/components/holderloving.dm index 36ab0182752..6340ff9b1db 100644 --- a/code/datums/components/holderloving.dm +++ b/code/datums/components/holderloving.dm @@ -17,6 +17,11 @@ 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)) From 1ab204ab3bf4c4cf0f6a9bfce90b69208f24f750 Mon Sep 17 00:00:00 2001 From: Antoonij <42318445+Antoonij@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:55:03 +0100 Subject: [PATCH 4/6] comments --- code/datums/components/death_linked.dm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/code/datums/components/death_linked.dm b/code/datums/components/death_linked.dm index f119961e5d6..16209ccba23 100644 --- a/code/datums/components/death_linked.dm +++ b/code/datums/components/death_linked.dm @@ -5,7 +5,7 @@ */ /datum/component/death_linked dupe_mode = COMPONENT_DUPE_UNIQUE_PASSARGS - /// The mob that also dies when the user dies. Contains weakrefs + /// Mobs in that list will die when the user dies. Contains weakrefs var/list/linked_mobs = list() /datum/component/death_linked/Initialize(list/mobs) @@ -40,7 +40,6 @@ . = ..() UnregisterSignal(parent, COMSIG_LIVING_DEATH) -/// signal called by the stat of the target changing /datum/component/death_linked/proc/on_death(mob/living/target, gibbed) SIGNAL_HANDLER From 924e4e2499b487593fb8d9d68d25ee6cd5fa504c Mon Sep 17 00:00:00 2001 From: Antoonij <42318445+Antoonij@users.noreply.github.com> Date: Sat, 21 Dec 2024 17:32:29 +0100 Subject: [PATCH 5/6] Update death_linked.dm --- code/datums/components/death_linked.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/datums/components/death_linked.dm b/code/datums/components/death_linked.dm index 16209ccba23..4fba8d5f68d 100644 --- a/code/datums/components/death_linked.dm +++ b/code/datums/components/death_linked.dm @@ -6,7 +6,7 @@ /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 = list() + var/list/linked_mobs /datum/component/death_linked/Initialize(list/mobs) . = ..() From 7f486b6bfbe8e0816c18052182964aec435fc651 Mon Sep 17 00:00:00 2001 From: Antoonij <42318445+Antoonij@users.noreply.github.com> Date: Sat, 4 Jan 2025 13:37:04 +0100 Subject: [PATCH 6/6] Update code/__HELPERS/text.dm Co-authored-by: BeebBeebBoob --- code/__HELPERS/text.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/__HELPERS/text.dm b/code/__HELPERS/text.dm index 3b6ce478cfc..7e693fa506f 100644 --- a/code/__HELPERS/text.dm +++ b/code/__HELPERS/text.dm @@ -312,7 +312,7 @@ if(max_length) text = copytext_char(text, 1, max_length) - return trimtext(text) + return trimtext(text) || "" /// Returns a string that does not exceed max_length characters in size /proc/trim_length(text, max_length)