1+ #define CAN_HEAR_MASTERS (1 << 0 )
2+ #define CAN_HEAR_ACTIVE_HOLOCALLS (1 << 1 )
3+ #define CAN_HEAR_RECORD_MODE (1 << 2 )
4+ #define CAN_HEAR_ALL_FLAGS (CAN_HEAR_MASTERS | CAN_HEAR_ACTIVE_HOLOCALLS | CAN_HEAR_RECORD_MODE )
5+
16/* Holograms!
27 * Contains:
38 * Holopad
@@ -42,7 +47,8 @@ GLOBAL_LIST_EMPTY(holopads)
4247 max_integrity = 300
4348 armor = list (MELEE = 50 , BULLET = 20 , LASER = 20 , ENERGY = 20 , BOMB = 0 , BIO = 0 , RAD = 0 , FIRE = 50 , ACID = 0 )
4449 circuit = / obj / item/ circuitboard/ machine/ holopad
45- // / List of living mobs that use the holopad
50+ // / associative lazylist of the form: list(mob calling us = hologram representing that mob).
51+ // / this is only populated for holopads answering calls from another holopad
4652 var /list /masters
4753 // / Holoray-mob link
4854 var /list /holorays
@@ -83,10 +89,8 @@ GLOBAL_LIST_EMPTY(holopads)
8389 var /padname = null
8490 // / Holopad Harassment Cooldown
8591 var /holopad_cooldown = 20 SECONDS
86-
87- / obj / machinery/ holopad/ Initialize()
88- . = .. ()
89- become_hearing_sensitive ()
92+ // /bitfield. used to turn on and off hearing sensitivity depending on if we can act on Hear() at all - meant for lowering the number of unessesary hearable atoms
93+ var /can_hear_flags = NONE
9094
9195/ obj / machinery/ holopad/ secure
9296 name = " secure holopad"
@@ -156,9 +160,8 @@ obj/machinery/holopad/secure/Initialize(mapload)
156160 if (outgoing_call)
157161 outgoing_call. ConnectionFailure(src )
158162
159- for (var /I in holo_calls)
160- var /datum /holocall/HC = I
161- HC . ConnectionFailure(src )
163+ for (var /datum /holocall/holocall_to_disconnect as anything in holo_calls)
164+ holocall_to_disconnect. ConnectionFailure(src )
162165
163166 for (var /I in masters)
164167 clear_holo (I)
@@ -360,13 +363,59 @@ obj/machinery/holopad/secure/Initialize(mapload)
360363 outgoing_call. Disconnect(src )
361364 return TRUE
362365
366+
367+ // setters
368+ /* *
369+ * setter for can_hear_flags. handles adding or removing the given flag on can_hear_flags and then adding hearing sensitivity or removing it depending on the final state
370+ * this is necessary because holopads are a significant fraction of the hearable atoms on station which increases the cost of procs that iterate through hearables
371+ * so we need holopads to not be hearable until it is needed
372+ *
373+ * * flag - one of the can_hear_flags flag defines
374+ * * set_flag - boolean, if TRUE sets can_hear_flags to that flag and might add hearing sensitivity if can_hear_flags was NONE before,
375+ * if FALSE unsets the flag and possibly removes hearing sensitivity
376+ */
377+ / obj / machinery/ holopad/ proc / set_can_hear_flags(flag, set_flag = TRUE )
378+ if (! (flag & CAN_HEAR_ALL_FLAGS ))
379+ return FALSE // the given flag doesnt exist
380+
381+ if (set_flag)
382+ if (can_hear_flags == NONE )// we couldnt hear before, so become hearing sensitive
383+ become_hearing_sensitive ()
384+
385+ can_hear_flags |= flag
386+ return TRUE
387+
388+ else
389+ can_hear_flags &= ~ flag
390+ if (can_hear_flags == NONE )
391+ lose_hearing_sensitivity ()
392+
393+ return TRUE
394+
395+ // /setter for adding/removing holocalls to this holopad. used to update the holo_calls list and can_hear_flags
396+ // /adds the given holocall if add_holocall is TRUE, removes if FALSE
397+ / obj / machinery/ holopad/ proc / set_holocall( datum / holocall/ holocall_to_update, add_holocall = TRUE )
398+ if (! istype(holocall_to_update))
399+ return FALSE
400+
401+ if (add_holocall)
402+ set_can_hear_flags (CAN_HEAR_ACTIVE_HOLOCALLS )
403+ LAZYADD (holo_calls, holocall_to_update)
404+
405+ else
406+ LAZYREMOVE (holo_calls, holocall_to_update)
407+ if (! LAZYLEN (holo_calls))
408+ set_can_hear_flags (CAN_HEAR_ACTIVE_HOLOCALLS , FALSE )
409+
410+ return TRUE
411+
412+
363413/* *
364414 * hangup_all_calls: Disconnects all current holocalls from the holopad
365415 */
366416/ obj / machinery/ holopad/ proc / hangup_all_calls()
367- for (var /I in holo_calls)
368- var /datum /holocall/HC = I
369- HC . Disconnect(src )
417+ for (var /datum /holocall/holocall_to_disconnect as anything in holo_calls)
418+ holocall_to_disconnect. Disconnect(src )
370419
371420// do not allow AIs to answer calls or people will use it to meta the AI sattelite
372421/ obj / machinery/ holopad/ attack_ai( mob / living/ silicon/ ai/ user)
@@ -464,10 +513,12 @@ For the other part of the code, check silicon say.dm. Particularly robot talk.*/
464513 if (masters[master] && speaker != master)
465514 master. relay_speech(message, speaker, message_language, raw_message, radio_freq, spans, message_mods)
466515
467- for (var /I in holo_calls)
468- var /datum /holocall/HC = I
469- if (HC . connected_holopad == src && speaker != HC . hologram)
470- HC . user. Hear(message, speaker, message_language, raw_message, radio_freq, spans, message_mods)
516+ for (var /datum /holocall/holocall_to_update as anything in holo_calls)
517+ if (holocall_to_update. connected_holopad == src )// if we answered this call originating from another holopad
518+ if (speaker == holocall_to_update. hologram && holocall_to_update. user. client?. prefs. read_preference(/ datum / preference/ toggle/ enable_runechat))
519+ holocall_to_update. user. create_chat_message(speaker, message_language, raw_message, spans)
520+ else
521+ holocall_to_update. user. Hear(message, speaker, message_language, raw_message, radio_freq, spans, message_mods)
471522
472523 if (outgoing_call && speaker == outgoing_call. user)
473524 outgoing_call. hologram. say(raw_message)
@@ -498,6 +549,7 @@ For the other part of the code, check silicon say.dm. Particularly robot talk.*/
498549/ obj / machinery/ holopad/ proc / set_holo( mob / living/ user, obj / effect/ overlay/ holo_pad_hologram/ h)
499550 LAZYSET (masters, user, h)
500551 LAZYSET (holorays, user, new / obj / effect/ overlay/ holoray(loc))
552+ set_can_hear_flags (CAN_HEAR_MASTERS )
501553 var /mob /living/silicon/ai/AI = user
502554 if (istype(AI ))
503555 AI . current = src
@@ -518,6 +570,8 @@ For the other part of the code, check silicon say.dm. Particularly robot talk.*/
518570 if (istype(AI ) && AI . current == src )
519571 AI . current = null
520572 LAZYREMOVE (masters, user) // Discard AI from the list of those who use holopad
573+ if (! LAZYLEN (masters))
574+ set_can_hear_flags (CAN_HEAR_MASTERS , set_flag = FALSE )
521575 qdel (holorays[user])
522576 LAZYREMOVE (holorays, user)
523577 SetLightsAndPower ()
@@ -637,6 +691,7 @@ For the other part of the code, check silicon say.dm. Particularly robot talk.*/
637691 return
638692 disk. record = new
639693 record_mode = TRUE
694+ set_can_hear_flags (CAN_HEAR_RECORD_MODE )
640695 record_start = world . time
641696 record_user = user
642697 disk. record. set_caller_image(user)
@@ -706,6 +761,7 @@ For the other part of the code, check silicon say.dm. Particularly robot talk.*/
706761 if (record_mode)
707762 record_mode = FALSE
708763 record_user = null
764+ set_can_hear_flags (CAN_HEAR_RECORD_MODE , FALSE )
709765
710766/ obj / machinery/ holopad/ proc / record_clear()
711767 if (disk && disk. record)
@@ -748,3 +804,7 @@ For the other part of the code, check silicon say.dm. Particularly robot talk.*/
748804
749805#undef HOLOPAD_PASSIVE_POWER_USAGE
750806#undef HOLOGRAM_POWER_USAGE
807+ #undef CAN_HEAR_MASTERS
808+ #undef CAN_HEAR_ACTIVE_HOLOCALLS
809+ #undef CAN_HEAR_RECORD_MODE
810+ #undef CAN_HEAR_ALL_FLAGS
0 commit comments