From 762bf6fe62df554103fb38606251c5c69bc1c69a Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Fri, 5 Feb 2021 23:05:30 +0100 Subject: [PATCH] [MIRROR] Fixes Traitor Uplinks Being Set to Existing Radio Channels (#3118) * Fixes Traitor Uplinks Being Set to Existing Radio Channels (#56608) * Fixes Traitor Uplinks Being Set to Existing Radio Channels Co-authored-by: Kylerace --- code/__HELPERS/radio.dm | 20 +++++++++++++++++--- code/datums/components/uplink.dm | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/code/__HELPERS/radio.dm b/code/__HELPERS/radio.dm index dc52299025f..99d9e3eebc3 100644 --- a/code/__HELPERS/radio.dm +++ b/code/__HELPERS/radio.dm @@ -1,4 +1,4 @@ -// Ensure the frequency is within bounds of what it should be sending/receiving at +/// Ensure the frequency is within bounds of what it should be sending/receiving at /proc/sanitize_frequency(frequency, free = FALSE) frequency = round(frequency) if(free) @@ -8,12 +8,26 @@ if(!(. % 2)) // Ensure the last digit is an odd number . += 1 -// Format frequency by moving the decimal. +/// Format frequency by moving the decimal. /proc/format_frequency(frequency) frequency = text2num(frequency) return "[round(frequency / 10)].[frequency % 10]" -//Opposite of format, returns as a number +///Opposite of format, returns as a number /proc/unformat_frequency(frequency) frequency = text2num(frequency) return frequency * 10 + +///returns a random unused frequency between MIN_FREE_FREQ & MAX_FREE_FREQ if free = TRUE, and MIN_FREQ & MAX_FREQ if FALSE +/proc/return_unused_frequency(free = FALSE) + var/start = free ? MIN_FREE_FREQ : 1459//MIN_FREQ + var/end = free ? MAX_FREE_FREQ : 1460//MAX_FREQ + + var/freq_to_check = 0 + do + freq_to_check = rand(start, end) + if(!(freq_to_check % 2)) // Ensure the last digit is an odd number + freq_to_check++ + while((freq_to_check == 0) || ("[freq_to_check]" in GLOB.reverseradiochannels)) + + return freq_to_check diff --git a/code/datums/components/uplink.dm b/code/datums/components/uplink.dm index 5073ec6a616..de07e0834e0 100644 --- a/code/datums/components/uplink.dm +++ b/code/datums/components/uplink.dm @@ -331,7 +331,7 @@ if(istype(parent,/obj/item/pda)) return "[rand(100,999)] [pick(GLOB.phonetic_alphabet)]" else if(istype(parent,/obj/item/radio)) - return sanitize_frequency(rand(MIN_FREQ, MAX_FREQ)) + return return_unused_frequency() else if(istype(parent,/obj/item/pen)) var/list/L = list() for(var/i in 1 to PEN_ROTATIONS)