From 28b4f95c8b42421c91d79497e41a6405b05218fc Mon Sep 17 00:00:00 2001 From: ShadowLarkens Date: Wed, 7 Apr 2021 20:58:42 -0700 Subject: [PATCH] Make unnatural resizing even better and more efficient with the power of DCS:tm: --- code/__defines/dcs/signals.dm | 2 + code/datums/components/resize_guard.dm | 19 ++++++++ code/game/atoms.dm | 1 + code/modules/admin/verbs/resize.dm | 4 -- code/modules/mob/living/living_defines_vr.dm | 2 - code/modules/nifsoft/software/15_misc.dm | 2 +- code/modules/vore/resizing/resize_vr.dm | 51 ++++---------------- code/modules/vore/resizing/sizegun_vr.dm | 6 +-- vorestation.dme | 1 + 9 files changed, 35 insertions(+), 53 deletions(-) create mode 100644 code/datums/components/resize_guard.dm diff --git a/code/__defines/dcs/signals.dm b/code/__defines/dcs/signals.dm index 26b1d2d44aa..017c92c9222 100644 --- a/code/__defines/dcs/signals.dm +++ b/code/__defines/dcs/signals.dm @@ -80,6 +80,8 @@ #define COMSIG_ATOM_UPDATED_ICON "atom_updated_icon" ///from base of atom/Entered(): (atom/movable/entering, /atom) #define COMSIG_ATOM_ENTERED "atom_entered" +/// Sent from the atom that just Entered src. From base of atom/Entered(): (/atom/entered_atom, /atom/oldLoc) +#define COMSIG_ATOM_ENTERING "atom_entering" ///from base of atom/Exit(): (/atom/movable/exiting, /atom/newloc) #define COMSIG_ATOM_EXIT "atom_exit" #define COMPONENT_ATOM_BLOCK_EXIT (1<<0) diff --git a/code/datums/components/resize_guard.dm b/code/datums/components/resize_guard.dm new file mode 100644 index 00000000000..724d2524431 --- /dev/null +++ b/code/datums/components/resize_guard.dm @@ -0,0 +1,19 @@ +/datum/component/resize_guard + +/datum/component/resize_guard/Initialize() + if(!isliving(parent)) + return COMPONENT_INCOMPATIBLE + +/datum/component/resize_guard/RegisterWithParent() + // When our parent mob enters any atom, we check resize + RegisterSignal(parent, COMSIG_ATOM_ENTERING, .proc/check_resize) + +/datum/component/resize_guard/UnregisterFromParent() + UnregisterSignal(parent, COMSIG_ATOM_ENTERING) + +/datum/component/resize_guard/proc/check_resize() + var/area/A = get_area(parent) + if(A?.limit_mob_size) + var/mob/living/L = parent + L.resize(L.size_multiplier) + qdel(src) \ No newline at end of file diff --git a/code/game/atoms.dm b/code/game/atoms.dm index c20c29be7b9..e4ad20f5d48 100644 --- a/code/game/atoms.dm +++ b/code/game/atoms.dm @@ -638,6 +638,7 @@ . = ..() GLOB.moved_event.raise_event(AM, old_loc, AM.loc) SEND_SIGNAL(src, COMSIG_ATOM_ENTERED, AM, old_loc) + SEND_SIGNAL(AM, COMSIG_ATOM_ENTERING, src, old_loc) /atom/Exit(atom/movable/AM, atom/new_loc) . = ..() diff --git a/code/modules/admin/verbs/resize.dm b/code/modules/admin/verbs/resize.dm index fc723c52781..140ce75393a 100644 --- a/code/modules/admin/verbs/resize.dm +++ b/code/modules/admin/verbs/resize.dm @@ -17,10 +17,6 @@ to_chat(src,"[L] will lose this size upon moving into an area where this size is not allowed.") else if(very_big) // made an extreme size in an area that doesn't allow it, assume adminbuse to_chat(src,"[L] will retain this normally unallowed size outside this area.") - L.size_uncapped = TRUE - else if(L.size_uncapped) // made a normal size after having been an extreme adminbuse size - to_chat(src,"[L] now returned to normal area-based size limitations.") - L.size_uncapped = FALSE L.resize(size_multiplier, animate = TRUE, uncapped = TRUE, ignore_prefs = TRUE) diff --git a/code/modules/mob/living/living_defines_vr.dm b/code/modules/mob/living/living_defines_vr.dm index dfe3b76c92e..4a872a240e7 100644 --- a/code/modules/mob/living/living_defines_vr.dm +++ b/code/modules/mob/living/living_defines_vr.dm @@ -6,8 +6,6 @@ appearance_flags = TILE_BOUND|PIXEL_SCALE|KEEP_TOGETHER var/hunger_rate = DEFAULT_HUNGER_FACTOR var/resizable = TRUE - var/size_uncapped = FALSE //Determines if a mob's size obedies the resize cap, used for adminbus resize. - //custom say verbs var/custom_say = null var/custom_ask = null diff --git a/code/modules/nifsoft/software/15_misc.dm b/code/modules/nifsoft/software/15_misc.dm index dede84b0d92..79592fa030a 100644 --- a/code/modules/nifsoft/software/15_misc.dm +++ b/code/modules/nifsoft/software/15_misc.dm @@ -134,7 +134,7 @@ to_chat(nif.human,"The safety features of the NIF Program prevent you from choosing this size.") return else - if(nif.human.resize(new_size/100, ignore_prefs = TRUE)) + if(nif.human.resize(new_size/100, uncapped=nif.human.has_large_resize_bounds(), ignore_prefs = TRUE)) to_chat(nif.human,"You set the size to [new_size]%") nif.human.visible_message("Swirling grey mist envelops [nif.human] as they change size!","Swirling streams of nanites wrap around you as you change size!") spawn(0) diff --git a/code/modules/vore/resizing/resize_vr.dm b/code/modules/vore/resizing/resize_vr.dm index fa11f0cbbdd..04c3e47dba2 100644 --- a/code/modules/vore/resizing/resize_vr.dm +++ b/code/modules/vore/resizing/resize_vr.dm @@ -1,6 +1,3 @@ -GLOBAL_LIST_EMPTY(size_uncapped_mobs) -GLOBAL_VAR(size_uncapped_mobs_timer) - // Adding needed defines to /mob/living // Note: Polaris had this on /mob/living/carbon/human We need it higher up for animals and stuff. /mob/living @@ -62,41 +59,6 @@ GLOBAL_VAR(size_uncapped_mobs_timer) /proc/is_extreme_size(size) return (size < RESIZE_MINIMUM || size > RESIZE_MAXIMUM) -/proc/add_to_uncapped_list(var/mob/living/L) - if(L.size_uncapped) - return - if(!GLOB.size_uncapped_mobs.len) - //Could be a subsystem but arguably a giant waste of time to make into a subsystem. A subsystem that is paused on and off all the time? Eh. - //If you're that worried, make metrics for how often this even runs and then decide. - GLOB.size_uncapped_mobs_timer = addtimer(CALLBACK(GLOBAL_PROC, .check_uncapped_list), 2 SECONDS, TIMER_LOOP | TIMER_UNIQUE | TIMER_STOPPABLE) - GLOB.size_uncapped_mobs |= weakref(L) - -/proc/remove_from_uncapped_list(var/mob/living/L) - if(!GLOB.size_uncapped_mobs.len) - return - - GLOB.size_uncapped_mobs -= weakref(L) - - if(!GLOB.size_uncapped_mobs.len) - deltimer(GLOB.size_uncapped_mobs_timer) - GLOB.size_uncapped_mobs_timer = null - -/proc/check_uncapped_list() - for(var/weakref/wr in GLOB.size_uncapped_mobs) - var/mob/living/L = wr.resolve() - if(!istype(L) || L.size_uncapped) - GLOB.size_uncapped_mobs -= wr - continue - - // If we get here, you're a mob, and you don't have admin exclusion (size_uncapped) to being big, and you're very likely big. - // If you're not abnormally big, the below will do nothing, so it's fine to run anyway. - if(!L.has_large_resize_bounds()) - L.resize(L.size_multiplier, ignore_prefs = TRUE) //Calling this will have resize() clamp it - GLOB.size_uncapped_mobs -= wr - - if(!GLOB.size_uncapped_mobs.len) - deltimer(GLOB.size_uncapped_mobs_timer) - GLOB.size_uncapped_mobs_timer = null /** * Resizes the mob immediately to the desired mod, animating it growing/shrinking. @@ -107,9 +69,16 @@ GLOBAL_VAR(size_uncapped_mobs_timer) /mob/living/proc/resize(var/new_size, var/animate = TRUE, var/uncapped = FALSE, var/ignore_prefs = FALSE) if(!uncapped) new_size = clamp(new_size, RESIZE_MINIMUM, RESIZE_MAXIMUM) - remove_from_uncapped_list(src) - else if(is_extreme_size(new_size)) - add_to_uncapped_list(src) + var/datum/component/resize_guard/guard = GetComponent(/datum/component/resize_guard) + if(guard) + qdel(guard) + else if(has_large_resize_bounds()) + if(is_extreme_size(new_size)) + AddComponent(/datum/component/resize_guard) + else + var/datum/component/resize_guard/guard = GetComponent(/datum/component/resize_guard) + if(guard) + qdel(guard) if(size_multiplier == new_size) return 1 diff --git a/code/modules/vore/resizing/sizegun_vr.dm b/code/modules/vore/resizing/sizegun_vr.dm index 88d0154befe..41775af2a52 100644 --- a/code/modules/vore/resizing/sizegun_vr.dm +++ b/code/modules/vore/resizing/sizegun_vr.dm @@ -114,12 +114,8 @@ to_chat(firer, "[M] will lose this size upon moving into an area where this size is not allowed.") else if(very_big) // made an extreme size in an area that doesn't allow it, assume adminbuse to_chat(firer, "[M] will retain this normally unallowed size outside this area.") - M.size_uncapped = TRUE - else if(M.size_uncapped) // made a normal size after having been an extreme adminbuse size - to_chat(firer, "[M] now returned to normal area-based size limitations.") - M.size_uncapped = FALSE - M.resize(set_size, uncapped = TRUE, ignoring_prefs = TRUE) // Always ignores prefs, caution is advisable + M.resize(set_size, uncapped = TRUE, ignore_prefs = TRUE) // Always ignores prefs, caution is advisable to_chat(M, "The beam fires into your body, changing your size!") M.updateicon() diff --git a/vorestation.dme b/vorestation.dme index 432e070c9d7..864123a144b 100644 --- a/vorestation.dme +++ b/vorestation.dme @@ -336,6 +336,7 @@ #include "code\datums\autolathe\tools.dm" #include "code\datums\autolathe\tools_vr.dm" #include "code\datums\components\_component.dm" +#include "code\datums\components\resize_guard.dm" #include "code\datums\elements\_element.dm" #include "code\datums\game_masters\_common.dm" #include "code\datums\helper_datums\construction_datum.dm"