mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-08-26 05:27:01 +01:00
Optimizes some functions (#24049)
* Optimizes some functions * Update code/__HELPERS/unsorted.dm Co-authored-by: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com> * Cached per AI now * no more 80k character jumpscares * parent functions exist * I need a new keyboard * Update code/modules/surgery/organs/vocal_cords.dm Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com> * Update code/modules/mob/living/silicon/ai/ai_say.dm Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com> * Update code/__HELPERS/game.dm Co-authored-by: Contrabang <91113370+Contrabang@users.noreply.github.com> * Update code/__HELPERS/game.dm Co-authored-by: Contrabang <91113370+Contrabang@users.noreply.github.com> --------- Co-authored-by: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com> Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com> Co-authored-by: Contrabang <91113370+Contrabang@users.noreply.github.com> Co-authored-by: S34N <12197162+S34NW@users.noreply.github.com>
This commit is contained in:
co-authored by
AffectedArc07
Burzah
Contrabang
S34N
parent
176e12ff04
commit
cc0eee4b4d
+5
-20
@@ -159,30 +159,22 @@
|
||||
// It will keep doing this until it checks every content possible. This will fix any problems with mobs, that are inside objects,
|
||||
// being unable to hear people due to being in a box within a bag.
|
||||
|
||||
/proc/recursive_mob_check(atom/O, list/L = list(), recursion_limit = 3, client_check = 1, sight_check = 1, include_radio = 1)
|
||||
|
||||
//GLOB.debug_mob += O.contents.len
|
||||
/proc/recursive_mob_check(atom/O, list/L = list(), recursion_limit = 3, client_check = TRUE, sight_check = TRUE)
|
||||
if(!recursion_limit)
|
||||
return L
|
||||
for(var/atom/A in O.contents)
|
||||
|
||||
if(ismob(A))
|
||||
var/mob/M = A
|
||||
if(client_check && !M.client)
|
||||
L |= recursive_mob_check(A, L, recursion_limit - 1, client_check, sight_check, include_radio)
|
||||
L |= recursive_mob_check(A, L, recursion_limit - 1, client_check, sight_check)
|
||||
continue
|
||||
if(sight_check && !isInSight(A, O))
|
||||
continue
|
||||
L |= M
|
||||
//log_world("[recursion_limit] = [M] - [get_turf(M)] - ([M.x], [M.y], [M.z])")
|
||||
|
||||
else if(include_radio && isradio(A))
|
||||
if(sight_check && !isInSight(A, O))
|
||||
continue
|
||||
L |= A
|
||||
|
||||
if(isobj(A) || ismob(A))
|
||||
L |= recursive_mob_check(A, L, recursion_limit - 1, client_check, sight_check, include_radio)
|
||||
L |= recursive_mob_check(A, L, recursion_limit - 1, client_check, sight_check)
|
||||
return L
|
||||
|
||||
// The old system would loop through lists for a total of 5000 per function call, in an empty server.
|
||||
@@ -197,23 +189,17 @@
|
||||
if(!T)
|
||||
return hear
|
||||
|
||||
var/list/range = hear(R, T)
|
||||
|
||||
for(var/atom/A in range)
|
||||
for(var/atom/A in hear(R, T))
|
||||
if(ismob(A))
|
||||
var/mob/M = A
|
||||
if(M.client || include_clientless)
|
||||
hear += M
|
||||
//log_world("Start = [M] - [get_turf(M)] - ([M.x], [M.y], [M.z])")
|
||||
else if(isradio(A))
|
||||
hear += A
|
||||
|
||||
if(isobj(A) || ismob(A))
|
||||
hear |= recursive_mob_check(A, hear, 3, 1, 0, 1)
|
||||
hear |= recursive_mob_check(A, hear, 3, TRUE, FALSE)
|
||||
|
||||
return hear
|
||||
|
||||
|
||||
/proc/get_mobs_in_radio_ranges(list/obj/item/radio/radios)
|
||||
. = list()
|
||||
// Returns a list of mobs who can hear any of the radios given in @radios
|
||||
@@ -235,7 +221,6 @@
|
||||
for(var/turf/T in hear(R.canhear_range,speaker))
|
||||
speaker_coverage[T] = T
|
||||
|
||||
|
||||
// Try to find all the players who can hear the message
|
||||
for(var/A in GLOB.player_list + GLOB.hear_radio_list)
|
||||
var/mob/M = A
|
||||
|
||||
@@ -720,16 +720,19 @@ Returns 1 if the chain up to the area contains the given typepath
|
||||
//Takes: Area type as text string or as typepath OR an instance of the area.
|
||||
//Returns: A list of all turfs in areas of that type of that type in the world.
|
||||
/proc/get_area_turfs(areatype)
|
||||
if(!areatype) return null
|
||||
if(istext(areatype)) areatype = text2path(areatype)
|
||||
if(!areatype)
|
||||
return
|
||||
if(istext(areatype))
|
||||
areatype = text2path(areatype)
|
||||
if(isarea(areatype))
|
||||
var/area/areatemp = areatype
|
||||
areatype = areatemp.type
|
||||
|
||||
var/list/turfs = list()
|
||||
for(var/area/N in world)
|
||||
for(var/area/N as anything in GLOB.all_areas)
|
||||
if(istype(N, areatype))
|
||||
for(var/turf/T in N) turfs += T
|
||||
for(var/turf/T in N)
|
||||
turfs += T
|
||||
return turfs
|
||||
|
||||
//Takes: Area type as text string or as typepath OR an instance of the area.
|
||||
@@ -754,7 +757,7 @@ Returns 1 if the chain up to the area contains the given typepath
|
||||
var/y_pos
|
||||
var/z_pos
|
||||
|
||||
/area/proc/move_contents_to(area/A, turf_to_leave, direction)
|
||||
/area/proc/move_contents_to(area/A, turf_to_leave, direction) // someone rewrite this function i beg of you
|
||||
//Takes: Area. Optional: turf type to leave behind.
|
||||
//Returns: Nothing.
|
||||
//Notes: Attempts to move the contents of one area to another area.
|
||||
@@ -763,7 +766,7 @@ Returns 1 if the chain up to the area contains the given typepath
|
||||
|
||||
if(!A || !src) return 0
|
||||
|
||||
var/list/turfs_src = get_area_turfs(src.type)
|
||||
var/list/turfs_src = get_area_turfs(type)
|
||||
var/list/turfs_trg = get_area_turfs(A.type)
|
||||
|
||||
var/src_min_x = 0
|
||||
|
||||
@@ -81,7 +81,6 @@
|
||||
|
||||
add_fingerprint(user)
|
||||
|
||||
|
||||
//the equivalent of the standard version of attack() but for object targets.
|
||||
/obj/item/proc/attack_obj(obj/O, mob/living/user, params)
|
||||
if(SEND_SIGNAL(src, COMSIG_ITEM_ATTACK_OBJ, O, user) & COMPONENT_NO_ATTACK_OBJ)
|
||||
|
||||
@@ -83,33 +83,47 @@ SUBSYSTEM_DEF(mapping)
|
||||
log_startup_progress("Skipping lavaland ruins...")
|
||||
|
||||
// Now we make a list of areas for teleport locs
|
||||
// Located below is some of the worst code I've ever seen
|
||||
// Checking all areas to see if they have a turf in them? Nice one ssmapping!
|
||||
|
||||
var/list/all_areas = list()
|
||||
for(var/area/areas in world)
|
||||
all_areas += areas
|
||||
|
||||
teleportlocs = list()
|
||||
for(var/area/AR in world)
|
||||
for(var/area/AR as anything in all_areas)
|
||||
if(AR.no_teleportlocs)
|
||||
continue
|
||||
if(teleportlocs[AR.name])
|
||||
continue
|
||||
var/turf/picked = safepick(get_area_turfs(AR.type))
|
||||
var/list/pickable_turfs = list()
|
||||
for(var/turf/turfs in AR)
|
||||
pickable_turfs += turfs
|
||||
var/turf/picked = safepick(pickable_turfs)
|
||||
if(picked && is_station_level(picked.z))
|
||||
teleportlocs[AR.name] = AR
|
||||
|
||||
teleportlocs = sortAssoc(teleportlocs)
|
||||
|
||||
|
||||
ghostteleportlocs = list()
|
||||
for(var/area/AR in world)
|
||||
for(var/area/AR as anything in all_areas)
|
||||
if(ghostteleportlocs[AR.name])
|
||||
continue
|
||||
var/list/turfs = get_area_turfs(AR.type)
|
||||
if(turfs.len)
|
||||
var/list/pickable_turfs = list()
|
||||
for(var/turf/turfs in AR)
|
||||
pickable_turfs += turfs
|
||||
if(length(pickable_turfs))
|
||||
ghostteleportlocs[AR.name] = AR
|
||||
|
||||
ghostteleportlocs = sortAssoc(ghostteleportlocs)
|
||||
|
||||
// Now we make a list of areas that exist on the station. Good for if you don't want to select areas that exist for one station but not others. Directly references
|
||||
existing_station_areas = list()
|
||||
for(var/area/AR in world)
|
||||
var/turf/picked = safepick(get_area_turfs(AR.type))
|
||||
for(var/area/AR as anything in all_areas)
|
||||
var/list/pickable_turfs = list()
|
||||
for(var/turf/turfs in AR)
|
||||
pickable_turfs += turfs
|
||||
var/turf/picked = safepick(pickable_turfs)
|
||||
if(picked && is_station_level(picked.z))
|
||||
existing_station_areas += AR
|
||||
|
||||
|
||||
@@ -280,7 +280,7 @@
|
||||
runechat_text = "[copytext(text, 1, 101)]..."
|
||||
var/list/can_see = get_mobs_in_view(1, user) //Allows silicon & mmi mobs carried around to see the emotes of the person carrying them around.
|
||||
can_see |= viewers(user, null)
|
||||
for(var/mob/O in can_see)
|
||||
for(var/mob/O as anything in can_see)
|
||||
if(O.status_flags & PASSEMOTES)
|
||||
for(var/obj/item/holder/H in O.contents)
|
||||
H.show_message(text, EMOTE_VISIBLE)
|
||||
|
||||
+1
-1
@@ -1096,7 +1096,7 @@ GLOBAL_LIST_EMPTY(blood_splatter_icons)
|
||||
if(!message)
|
||||
return
|
||||
var/list/speech_bubble_hearers = list()
|
||||
for(var/mob/M in get_mobs_in_view(7, src))
|
||||
for(var/mob/M as anything in get_mobs_in_view(7, src))
|
||||
M.show_message("<span class='game say'><span class='name'>[src]</span> [atom_say_verb], \"[message]\"</span>", 2, null, 1)
|
||||
if(M.client)
|
||||
speech_bubble_hearers += M.client
|
||||
|
||||
@@ -571,7 +571,7 @@
|
||||
else if(istype(loc, /obj/machinery/hologram/holopad))
|
||||
var/obj/machinery/hologram/holopad/H = loc
|
||||
name = "[H]"
|
||||
for(var/mob/M in get_mobs_in_view(7, H))
|
||||
for(var/mob/M as anything in get_mobs_in_view(7, H))
|
||||
M.hear_say(message_pieces, verb, FALSE, src)
|
||||
name = real_name
|
||||
return TRUE
|
||||
@@ -587,7 +587,7 @@
|
||||
|
||||
/mob/living/simple_animal/demon/pulse_demon/visible_message(message, self_message, blind_message)
|
||||
// overriden because pulse demon is quite often in non-turf locs, and /mob/visible_message acts differently there
|
||||
for(var/mob/M in get_mobs_in_view(7, src))
|
||||
for(var/mob/M as anything in get_mobs_in_view(7, src))
|
||||
if(M.see_invisible < invisibility)
|
||||
continue //can't view the invisible
|
||||
var/msg = message
|
||||
|
||||
@@ -83,7 +83,7 @@
|
||||
for(var/obj/O in view(14, get_turf(src)))
|
||||
O.hear_talk(user, message_to_multilingual("<span class='[span]'>[message]</span>"))
|
||||
|
||||
for(var/mob/M in get_mobs_in_view(7, src))
|
||||
for(var/mob/M as anything in get_mobs_in_view(7, src))
|
||||
if((M.client?.prefs.toggles2 & PREFTOGGLE_2_RUNECHAT) && M.can_hear())
|
||||
M.create_chat_message(user, message, FALSE, "big")
|
||||
|
||||
|
||||
@@ -26,10 +26,6 @@
|
||||
/obj/item/radio/beacon/hear_talk()
|
||||
return
|
||||
|
||||
|
||||
/obj/item/radio/beacon/send_hear()
|
||||
return null
|
||||
|
||||
/// Probably a better way of doing this, I'm lazy.
|
||||
/obj/item/radio/beacon/bacon
|
||||
|
||||
|
||||
@@ -542,11 +542,6 @@ GLOBAL_LIST_EMPTY(deadsay_radio_systems)
|
||||
return -1
|
||||
return canhear_range
|
||||
|
||||
/obj/item/radio/proc/send_hear(freq, level)
|
||||
var/range = receive_range(freq, level)
|
||||
if(range > -1)
|
||||
return get_mobs_in_view(canhear_range, src)
|
||||
|
||||
/obj/item/radio/proc/is_listening()
|
||||
var/is_listening = TRUE
|
||||
if(!on)
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
/datum/action/changeling/resonant_shriek/sting_action(mob/user)
|
||||
if(istype(user.loc, /obj/machinery/atmospherics))
|
||||
return FALSE
|
||||
for(var/mob/living/M in get_mobs_in_view(4, user))
|
||||
for(var/mob/living/M as anything in get_mobs_in_view(4, user))
|
||||
if(iscarbon(M))
|
||||
if(ishuman(M))
|
||||
var/mob/living/carbon/human/H = M
|
||||
|
||||
@@ -135,6 +135,9 @@ GLOBAL_LIST_INIT(ai_verbs_default, list(
|
||||
/mob/living/silicon/proc/subsystem_law_manager,
|
||||
/mob/living/silicon/proc/subsystem_power_monitor)
|
||||
|
||||
/// The cached AI annoucement help menu.
|
||||
var/ai_announcement_string_menu
|
||||
|
||||
/mob/living/silicon/ai/proc/add_ai_verbs()
|
||||
add_verb(src, GLOB.ai_verbs_default)
|
||||
add_verb(src, silicon_subsystems)
|
||||
@@ -1545,6 +1548,13 @@ GLOBAL_LIST_INIT(ai_verbs_default, list(
|
||||
var/mob/dead/observer/ghost = .
|
||||
ghost.forceMove(old_turf)
|
||||
|
||||
/mob/living/silicon/ai/can_vv_get(var_name)
|
||||
if(!..())
|
||||
return FALSE
|
||||
if(var_name == "ai_announcement_string_menu") // This single var has over 80 thousand characters in it. Not something you really want when VVing the AI
|
||||
return FALSE
|
||||
return TRUE
|
||||
|
||||
/mob/living/silicon/ai/proc/blurb_it()
|
||||
addtimer(CALLBACK(src, TYPE_PROC_REF(/mob/living/silicon/ai, show_ai_blurb)), 1 SECONDS)
|
||||
|
||||
|
||||
@@ -74,24 +74,25 @@ GLOBAL_VAR_INIT(announcing_vox, 0) // Stores the time of the last announcement
|
||||
set desc = "Display a list of vocal words to announce to the crew."
|
||||
set category = "AI Commands"
|
||||
|
||||
var/list/dat = list()
|
||||
if(!ai_announcement_string_menu)
|
||||
var/list/dat = list()
|
||||
|
||||
dat += "Here is a list of words you can type into the 'Announcement' button to create sentences to vocally announce to everyone on the same level at you.<BR> \
|
||||
<UL><LI>You can also click on the word to preview it.</LI>\
|
||||
<LI>You can only say 30 words for every announcement.</LI>\
|
||||
<LI>Do not use punctuation as you would normally, if you want a pause you can use the full stop and comma characters by separating them with spaces, like so: 'Alpha . Test , Bravo'.</LI></UL>\
|
||||
<font class='bad'>WARNING:</font><BR>Misuse of the announcement system will get you job banned.<HR>"
|
||||
dat += "Here is a list of words you can type into the 'Announcement' button to create sentences to vocally announce to everyone on the same level at you.<br> \
|
||||
<ul><li>You can also click on the word to preview it.</li>\
|
||||
<li>You can only say 30 words for every announcement.</li>\
|
||||
<li>Do not use punctuation as you would normally, if you want a pause you can use the full stop and comma characters by separating them with spaces, like so: 'Alpha . Test , Bravo'.</li></ul>\
|
||||
<font class='bad'>WARNING:</font><br>Misuse of the announcement system will get you job banned.<hr>"
|
||||
|
||||
// Show alert and voice sounds separately
|
||||
var/vox_words = GLOB.vox_sounds - GLOB.vox_alerts
|
||||
dat += help_format(GLOB.vox_alerts)
|
||||
dat += "<hr>"
|
||||
dat += help_format(vox_words)
|
||||
// Show alert and voice sounds separately
|
||||
var/vox_words = GLOB.vox_sounds - GLOB.vox_alerts
|
||||
dat += help_format(GLOB.vox_alerts)
|
||||
dat += "<hr>"
|
||||
dat += help_format(vox_words)
|
||||
|
||||
var/string_dat = dat.Join("")
|
||||
ai_announcement_string_menu = dat.Join("")
|
||||
|
||||
var/datum/browser/popup = new(src, "announce_help", "Announcement Help", 500, 400)
|
||||
popup.set_content(string_dat)
|
||||
popup.set_content(ai_announcement_string_menu)
|
||||
popup.open()
|
||||
|
||||
/mob/living/silicon/ai/proc/help_format(word_list)
|
||||
@@ -122,8 +123,8 @@ GLOBAL_VAR_INIT(announcing_vox, 0) // Stores the time of the last announcement
|
||||
var/list/words = splittext(trim(message), " ")
|
||||
var/list/incorrect_words = list()
|
||||
|
||||
if(words.len > 30)
|
||||
words.len = 30
|
||||
if(length(words) > 30)
|
||||
words.Cut(31)
|
||||
|
||||
for(var/word in words)
|
||||
word = lowertext(trim(word))
|
||||
@@ -133,7 +134,7 @@ GLOBAL_VAR_INIT(announcing_vox, 0) // Stores the time of the last announcement
|
||||
if(!GLOB.vox_sounds[word])
|
||||
incorrect_words += word
|
||||
|
||||
if(incorrect_words.len)
|
||||
if(length(incorrect_words))
|
||||
to_chat(src, "<span class='warning'>These words are not available on the announcement system: [english_list(incorrect_words)].</span>")
|
||||
return
|
||||
|
||||
@@ -143,11 +144,10 @@ GLOBAL_VAR_INIT(announcing_vox, 0) // Stores the time of the last announcement
|
||||
message_admins("[key_name_admin(src)] made a vocal announcement: [message].")
|
||||
|
||||
for(var/word in words)
|
||||
play_vox_word(word, src.z, null)
|
||||
play_vox_word(word, z, null)
|
||||
|
||||
ai_voice_announcement_to_text(words)
|
||||
|
||||
|
||||
/mob/living/silicon/ai/proc/ai_voice_announcement_to_text(words)
|
||||
var/words_string = jointext(words, " ")
|
||||
// Don't go through .Announce because we need to filter by clients which have TTS enabled
|
||||
|
||||
@@ -139,7 +139,7 @@
|
||||
|
||||
/mob/visible_message(message, self_message, blind_message)
|
||||
if(!isturf(loc)) // mobs inside objects (such as lockers) shouldn't have their actions visible to those outside the object
|
||||
for(var/mob/M in get_mobs_in_view(3, src))
|
||||
for(var/mob/M as anything in get_mobs_in_view(3, src))
|
||||
if(M.see_invisible < invisibility)
|
||||
continue //can't view the invisible
|
||||
var/msg = message
|
||||
@@ -151,7 +151,7 @@
|
||||
msg = blind_message
|
||||
M.show_message(msg, EMOTE_VISIBLE, blind_message, EMOTE_AUDIBLE)
|
||||
return
|
||||
for(var/mob/M in get_mobs_in_view(7, src))
|
||||
for(var/mob/M as anything in get_mobs_in_view(7, src))
|
||||
if(M.see_invisible < invisibility)
|
||||
continue //can't view the invisible
|
||||
var/msg = message
|
||||
@@ -164,7 +164,7 @@
|
||||
// message is output to anyone who can see, e.g. "The [src] does something!"
|
||||
// blind_message (optional) is what blind people will hear e.g. "You hear something!"
|
||||
/atom/proc/visible_message(message, blind_message)
|
||||
for(var/mob/M in get_mobs_in_view(7, src))
|
||||
for(var/mob/M as anything in get_mobs_in_view(7, src))
|
||||
if(!M.client)
|
||||
continue
|
||||
M.show_message(message, EMOTE_VISIBLE, blind_message, EMOTE_AUDIBLE)
|
||||
@@ -180,7 +180,7 @@
|
||||
if(hearing_distance)
|
||||
range = hearing_distance
|
||||
var/msg = message
|
||||
for(var/mob/M in get_mobs_in_view(range, src))
|
||||
for(var/mob/M as anything in get_mobs_in_view(range, src))
|
||||
M.show_message(msg, EMOTE_AUDIBLE, deaf_message, EMOTE_VISIBLE)
|
||||
|
||||
// based on say code
|
||||
@@ -206,7 +206,7 @@
|
||||
var/range = 7
|
||||
if(hearing_distance)
|
||||
range = hearing_distance
|
||||
for(var/mob/M in get_mobs_in_view(range, src))
|
||||
for(var/mob/M as anything in get_mobs_in_view(range, src))
|
||||
M.show_message(message, EMOTE_AUDIBLE, deaf_message, EMOTE_VISIBLE)
|
||||
|
||||
/mob/proc/findname(msg)
|
||||
|
||||
@@ -138,8 +138,6 @@
|
||||
var/area/where_to_move = pick(all_possible_areas) // Grabs a random area that isn't restricted
|
||||
var/turf/target_area_turfs = get_area_turfs(where_to_move) // Grabs the turfs from said area
|
||||
target_turf = pick(target_area_turfs) // Grabs a single turf from the entire list
|
||||
return
|
||||
|
||||
|
||||
/obj/singularity/energy_ball/proc/handle_energy()
|
||||
if(energy >= energy_to_raise)
|
||||
|
||||
@@ -157,10 +157,10 @@ GLOBAL_DATUM_INIT(multispin_words, /regex, regex("like a record baby"))
|
||||
/obj/item/organ/internal/vocal_cords/colossus/speak_with(message)
|
||||
var/log_message = uppertext(message)
|
||||
message = lowertext(message)
|
||||
playsound(get_turf(owner), 'sound/magic/invoke_general.ogg', 300, 1, 5)
|
||||
playsound(get_turf(owner), 'sound/magic/invoke_general.ogg', 300, TRUE, 5)
|
||||
|
||||
var/list/mob/living/listeners = list()
|
||||
for(var/mob/living/L in get_mobs_in_view(8, owner, TRUE))
|
||||
for(var/mob/living/L as anything in get_mobs_in_view(8, owner, TRUE))
|
||||
if(L.can_hear() && !L.null_rod_check() && L != owner && L.stat != DEAD)
|
||||
if(ishuman(L))
|
||||
var/mob/living/carbon/human/H = L
|
||||
|
||||
Reference in New Issue
Block a user