diff --git a/code/__HELPERS/game.dm b/code/__HELPERS/game.dm index 0f0b095f2f5..b9679e9c685 100644 --- a/code/__HELPERS/game.dm +++ b/code/__HELPERS/game.dm @@ -161,6 +161,8 @@ // The old system would loop through lists for a total of 5000 per function call, in an empty server. // This new system will loop at around 1000 in an empty server. +// SCREW THAT SHIT, we're not recursing. + /proc/get_mobs_in_view(var/R, var/atom/source) // Returns a list of mobs in range of R from source. Used in radio and say code. @@ -172,18 +174,45 @@ var/list/range = hear(R, T) - for(var/atom/A in range) - if(ismob(A)) - var/mob/M = A - if(M.client) - hear += M - //world.log << "Start = [M] - [get_turf(M)] - ([M.x], [M.y], [M.z])" - else if(istype(A, /obj/item/device/radio)) - hear += A + for(var/mob/M in range) + if(M.client) + hear += M + + var/list/objects = list() - if(isobj(A) || ismob(A)) - hear |= recursive_mob_check(A, hear, 3, 1, 0, 1) + var/list/obj_to_check = list() //IF SOMEONE DOESN'T HEAR SOMETHING AND ARE IN INSIDE A CONTAINER ADD IT TO THIS LIST. + obj_to_check += typesof(/obj/item/device/paicard) + obj_to_check += typesof(/obj/item/device/aicard) + obj_to_check += typesof(/obj/machinery/computer/aifixer) + for(var/obj/O in range) //Get a list of objects in hearing range. We'll check to see if any clients have their "eye" set to the object + if(istype(O, /obj/item/device/radio)) //This avoids all that bullshit with recursion. FUCK RECURSION ~Ccomp + hear += O + if(O.type in obj_to_check) + for(var/mob/living/M in O.contents) + if(!(M in hear)) + hear += M + + + objects += O + + for(var/client/C in clients) + if(!istype(C) || !C.eye) + continue //I have no idea when this client check would be needed, but if this runtimes people won't hear anything + //So kinda paranoid about runtime avoidance. + if(C.mob in hear) + continue + if(C.eye in (hear|objects)) + if(!(C.mob in hear)) + hear += C.mob + + else if(!(C.mob in hear)) + if(C.mob.loc in (hear|objects)) + hear += C.mob + else if(C.mob.loc.loc in (hear|objects)) + hear += C.mob + + return hear