diff --git a/code/_helpers/game.dm b/code/_helpers/game.dm index c241a84994..838b11542a 100644 --- a/code/_helpers/game.dm +++ b/code/_helpers/game.dm @@ -218,40 +218,24 @@ return hear -var/mobs_radio_range_fired = 1 //CHOMPEdit +//CHOMPEdit - entire proc changed basically to use recursive listening /proc/get_mobs_in_radio_ranges(var/list/obj/item/device/radio/radios) set background = 1 - var/our_iter = num2text(++mobs_radio_range_fired) //CHOMPEdit . = list() // Returns a list of mobs who can hear any of the radios given in @radios - var/list/speaker_coverage = list() for(var/obj/item/device/radio/R as anything in radios) - var/turf/speaker = get_turf(R) - if(speaker) + if(get_turf(R)) for(var/turf/T in R.can_broadcast_to()) //CHOMPEdit - T.temp_check[our_iter] = TRUE //CHOMPEdit - speaker_coverage[T] = R + for (var/atom/movable/hearing in T) + if (hearing.recursive_listeners) + . |= hearing.recursive_listeners - CHECK_TICK //CHOMPEdit - // Try to find all the players who can hear the message - //CHOMPEdit Begin - //So, to explain a bit here: The old code that used to be here was pretty slow for a few reasons, most of which have been addressed now. - //Unsurprisingly, checking through the entire list of turfs within a radio's range for every mob's turf to see if it's in there is very slow. - //So, instead, we set a variable in a list on the turf that's unique to this runthrough(and thus multiple of these can run simultaneously) - //Then we just have to check if that variable is true for the turf the mob is on, and if it is, add that mob to our list. - for(var/i = 1; i <= player_list.len; i++) - var/mob/M = player_list[i] - var/turf/T = get_turf(M) - if(istype(T) && T.temp_check[our_iter]) - . += M - else if(istype(M,/mob/observer)) //Give ghosts global hearing. - . += M - CHECK_TICK - for(var/turf/T in speaker_coverage) - T.temp_check -= our_iter //Freeing up the memory. - //CHOMPEdit End - return . + for (var/mob/M as anything in .) + if (!istype(M) || !M.client) + . -= M + for (var/mob/observer/O in player_list) + . |= O /mob/proc/can_hear_radio(var/list/hearturfs) return FALSE diff --git a/code/game/atoms_movable_ch.dm b/code/game/atoms_movable_ch.dm new file mode 100644 index 0000000000..637a82bcf0 --- /dev/null +++ b/code/game/atoms_movable_ch.dm @@ -0,0 +1,51 @@ +#define NON_LISTENING_ATOM 0 +#define LISTENING_ATOM 1 +#define LISTENING_PLAYER 2 +//gonna be honest this is really just a ripoff of tg's recursive hearing +/atom/movable + var/recursive_listeners + var/listening_recursive = NON_LISTENING_ATOM + +/atom/movable/New() + . = ..() + if (listening_recursive) + set_listening(listening_recursive) + +/atom/movable/proc/set_listening(var/set_to) + if (listening_recursive && !set_to) + LAZYREMOVE(recursive_listeners, src) + if (!LAZYLEN(recursive_listeners)) + for (var/atom/movable/location as anything in get_nested_locs(src)) + LAZYREMOVE(location.recursive_listeners, src) + if (!listening_recursive && set_to) + LAZYADD(recursive_listeners, src) + for (var/atom/movable/location as anything in get_nested_locs(src)) + LAZYADD(location.recursive_listeners, src) + listening_recursive = set_to + +///Returns a list of all locations (except the area) the movable is within. +/proc/get_nested_locs(atom/movable/atom_on_location, include_turf = FALSE) + . = list() + var/atom/location = atom_on_location.loc + var/turf/our_turf = get_turf(atom_on_location) + while(location && location != our_turf) + . += location + location = location.loc + if(our_turf && include_turf) //At this point, only the turf is left, provided it exists. + . += our_turf + +/atom/movable/Exited(atom/movable/gone, atom/new_loc) + . = ..() + + if (!LAZYLEN(gone.recursive_listeners)) + return + for (var/atom/movable/location as anything in get_nested_locs(src)|src) + LAZYREMOVE(location.recursive_listeners, gone.recursive_listeners) + +/atom/movable/Entered(atom/movable/arrived, atom/old_loc) + . = ..() + + if (!LAZYLEN(arrived.recursive_listeners)) + return + for (var/atom/movable/location as anything in get_nested_locs(src)|src) + LAZYADD(location.recursive_listeners, arrived.recursive_listeners) diff --git a/code/game/turfs/turf_ch.dm b/code/game/turfs/turf_ch.dm deleted file mode 100644 index 403e60a319..0000000000 --- a/code/game/turfs/turf_ch.dm +++ /dev/null @@ -1,2 +0,0 @@ -/turf - var/list/temp_check = list() \ No newline at end of file diff --git a/code/modules/mob/login_ch.dm b/code/modules/mob/login_ch.dm new file mode 100644 index 0000000000..f61bb37ab0 --- /dev/null +++ b/code/modules/mob/login_ch.dm @@ -0,0 +1,3 @@ +/mob/Login() + . = ..() + set_listening(LISTENING_PLAYER) \ No newline at end of file diff --git a/code/modules/mob/logout.dm b/code/modules/mob/logout.dm index d965956dfe..ced40de20d 100644 --- a/code/modules/mob/logout.dm +++ b/code/modules/mob/logout.dm @@ -12,6 +12,7 @@ message_admins("Admin logout: [key_name(src)]") if(admins_number == 0) //Apparently the admin logging out is no longer an admin at this point, so we have to check this towards 0 and not towards 1. Awell. send2adminirc("[key_name(src)] logged out - no more admins online.") + set_listening(NON_LISTENING_ATOM) //maybe remove this, even if it will cause a teensy bit more lag ..() return 1 \ No newline at end of file diff --git a/code/modules/vore/eating/belly_obj_vr.dm b/code/modules/vore/eating/belly_obj_vr.dm index 68aeaea695..afe99433b0 100644 --- a/code/modules/vore/eating/belly_obj_vr.dm +++ b/code/modules/vore/eating/belly_obj_vr.dm @@ -308,6 +308,7 @@ // Called whenever an atom enters this belly /obj/belly/Entered(atom/movable/thing, atom/OldLoc) + . = ..() //CHOMPEdit: radios thing.belly_cycles = 0 //CHOMPEdit: reset cycle count if(istype(thing, /mob/observer)) //CHOMPEdit. Silence, spook. if(desc) diff --git a/modular_chomp/code/game/objects/structures/watercloset_ch.dm b/modular_chomp/code/game/objects/structures/watercloset_ch.dm index ea93649754..19f523cea9 100644 --- a/modular_chomp/code/game/objects/structures/watercloset_ch.dm +++ b/modular_chomp/code/game/objects/structures/watercloset_ch.dm @@ -108,6 +108,7 @@ return TRUE /obj/structure/biowaste_tank/Entered(atom/movable/thing, atom/OldLoc) + . = ..() if(istype(thing, /obj/item/weapon/reagent_containers/food)) qdel(thing) return diff --git a/vorestation.dme b/vorestation.dme index 2543ef9c13..75844125a0 100644 --- a/vorestation.dme +++ b/vorestation.dme @@ -566,6 +566,7 @@ #include "code\defines\procs\statistics.dm" #include "code\game\atoms.dm" #include "code\game\atoms_movable.dm" +#include "code\game\atoms_movable_ch.dm" #include "code\game\atoms_movable_vr.dm" #include "code\game\base_turf.dm" #include "code\game\periodic_news.dm" @@ -1704,7 +1705,6 @@ #include "code\game\turfs\simulated_ch.dm" #include "code\game\turfs\simulated_vr.dm" #include "code\game\turfs\turf.dm" -#include "code\game\turfs\turf_ch.dm" #include "code\game\turfs\turf_changing.dm" #include "code\game\turfs\turf_flick_animations.dm" #include "code\game\turfs\unsimulated.dm" @@ -2847,6 +2847,7 @@ #include "code\modules\mob\holder.dm" #include "code\modules\mob\inventory.dm" #include "code\modules\mob\login.dm" +#include "code\modules\mob\login_ch.dm" #include "code\modules\mob\login_vr.dm" #include "code\modules\mob\logout.dm" #include "code\modules\mob\mob.dm"