Skip to content

Commit 584228b

Browse files
ninjanomnomAbsolucy
authored andcommitted
Fixes hearing messages from speakers on another z level (515 fix) (#79888)
515 changed get_dist to return inf when either end is on another z level, instead of just the maximum range. `/mob/living/Hear` early returns when the speaker is too far away to hear. Previously we would get around this by passing in INFINITY as the range for the message, but the INFINITY define is just a very large number instead of real infinity which is what byond gives back for get_dist. I also improved the unit test a little while debugging this.
1 parent 2d7cc05 commit 584228b

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

code/__DEFINES/dcs/signals/signals_object.dm

+2
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@
298298
#define COMSIG_RADIO_NEW_FREQUENCY "radio_new_frequency"
299299
///called from base of /obj/item/radio/proc/talk_into(): (atom/movable/M, message, channel)
300300
#define COMSIG_RADIO_NEW_MESSAGE "radio_new_message"
301+
///called from base of /obj/item/radio/proc/on_receive_messgae(): (list/data)
302+
#define COMSIG_RADIO_RECEIVE_MESSAGE "radio_receive_message"
301303

302304
// /obj/item/pen signals
303305

code/game/machinery/telecomms/broadcasting.dm

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183

184184
for(var/obj/item/radio/called_radio as anything in radios)
185185
if(!QDELETED(called_radio))
186-
called_radio.on_recieve_message()
186+
called_radio.on_recieve_message(data)
187187

188188
// From the list of radios, find all mobs who can hear those.
189189
var/list/receive = get_hearers_in_radio_ranges(radios)

code/game/objects/items/devices/radio/radio.dm

+2-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,8 @@
420420
return TRUE
421421
return FALSE
422422

423-
/obj/item/radio/proc/on_recieve_message()
423+
/obj/item/radio/proc/on_recieve_message(list/data)
424+
SEND_SIGNAL(src, COMSIG_RADIO_RECEIVE_MESSAGE, data)
424425
flick_overlay_view(overlay_speaker_active, 5 SECONDS)
425426

426427
/obj/item/radio/ui_state(mob/user)

code/modules/mob/living/living_say.dm

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ GLOBAL_LIST_INIT(message_modes_stat_limits, list(
306306
var/dist = get_dist(speaker, src) - message_range
307307
if(dist > 0 && dist <= EAVESDROP_EXTRA_RANGE && !HAS_TRAIT(src, TRAIT_GOOD_HEARING) && !isobserver(src)) // ghosts can hear all messages clearly
308308
raw_message = stars(raw_message)
309-
if (dist > EAVESDROP_EXTRA_RANGE && !HAS_TRAIT(src, TRAIT_GOOD_HEARING) && !isobserver(src))
309+
if (message_range != INFINITY && dist > EAVESDROP_EXTRA_RANGE && !HAS_TRAIT(src, TRAIT_GOOD_HEARING) && !isobserver(src))
310310
return FALSE // Too far away and don't have good hearing, you can't hear anything
311311

312312
// we need to send this signal before compose_message() is used since other signals need to modify

code/modules/unit_tests/say.dm

+28-3
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,15 @@
5858

5959
/// This runs some simple speech tests on a speaker and listener and determines if a person can hear whispering or speaking as they are moved a distance away
6060
/datum/unit_test/speech
61-
var/list/handle_speech_result = null
62-
var/list/handle_hearing_result = null
6361
var/mob/living/carbon/human/speaker
6462
var/mob/living/carbon/human/listener
63+
var/list/handle_speech_result = null
64+
var/list/handle_hearing_result = null
65+
6566
var/obj/item/radio/speaker_radio
6667
var/obj/item/radio/listener_radio
68+
var/speaker_radio_heard_message = FALSE
69+
var/listener_radio_received_message = FALSE
6770

6871
/datum/unit_test/speech/proc/handle_speech(datum/source, list/speech_args)
6972
SIGNAL_HANDLER
@@ -99,6 +102,16 @@
99102
handle_hearing_result = list()
100103
handle_hearing_result += hearing_args
101104

105+
/datum/unit_test/speech/proc/handle_radio_hearing(datum/source, mob/living/user, message, channel)
106+
SIGNAL_HANDLER
107+
108+
speaker_radio_heard_message = TRUE
109+
110+
/datum/unit_test/speech/proc/handle_radio_speech(datum/source, list/data)
111+
SIGNAL_HANDLER
112+
113+
listener_radio_received_message = TRUE
114+
102115
/datum/unit_test/speech/Run()
103116
speaker = allocate(/mob/living/carbon/human/consistent)
104117
// Name changes to make understanding breakpoints easier
@@ -114,7 +127,10 @@
114127
listener.mock_client = mock_client
115128

116129
RegisterSignal(speaker, COMSIG_MOB_SAY, PROC_REF(handle_speech))
130+
RegisterSignal(speaker_radio, COMSIG_RADIO_NEW_MESSAGE, PROC_REF(handle_radio_hearing))
131+
117132
RegisterSignal(listener, COMSIG_MOVABLE_HEAR, PROC_REF(handle_hearing))
133+
RegisterSignal(listener_radio, COMSIG_RADIO_RECEIVE_MESSAGE, PROC_REF(handle_radio_speech))
118134

119135
// speaking and whispering should be hearable
120136
conversation(distance = 1)
@@ -169,6 +185,9 @@
169185
handle_hearing_result = null
170186

171187
/datum/unit_test/speech/proc/radio_test()
188+
speaker_radio_heard_message = FALSE
189+
listener_radio_received_message = FALSE
190+
172191
speaker.forceMove(run_loc_floor_bottom_left)
173192
listener.forceMove(locate((run_loc_floor_bottom_left.x + 10), run_loc_floor_bottom_left.y, run_loc_floor_bottom_left.z))
174193

@@ -186,11 +205,15 @@
186205

187206
speaker.say(pangram_quote)
188207
TEST_ASSERT(handle_speech_result, "Handle speech signal was not fired (radio test)")
189-
TEST_ASSERT(islist(handle_hearing_result), "Listener failed to hear radio message (radio test)")
208+
TEST_ASSERT(speaker_radio_heard_message, "Speaker's radio did not hear them speak (radio test)")
190209
TEST_ASSERT_EQUAL(speaker_radio.get_frequency(), listener_radio.get_frequency(), "Radio frequencies were not equal (radio test)")
210+
TEST_ASSERT(listener_radio_received_message, "Listener's radio did not receive the broadcast (radio test)")
211+
TEST_ASSERT(islist(handle_hearing_result), "Listener failed to hear radio message (radio test)")
191212

192213
handle_speech_result = null
193214
handle_hearing_result = null
215+
speaker_radio_heard_message = FALSE
216+
listener_radio_received_message = FALSE
194217

195218
speaker_radio.set_frequency(FREQ_CTF_RED)
196219
speaker.say(pangram_quote)
@@ -200,6 +223,8 @@
200223

201224
handle_speech_result = null
202225
handle_hearing_result = null
226+
speaker_radio_heard_message = FALSE
227+
listener_radio_received_message = FALSE
203228
speaker_radio.set_broadcasting(FALSE)
204229

205230
#undef NORMAL_HEARING_RANGE

0 commit comments

Comments
 (0)