Skip to content

Commit

Permalink
Language radio keys 2
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMelbert committed Jan 20, 2025
1 parent d21a5b8 commit 5a84968
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 33 deletions.
9 changes: 9 additions & 0 deletions code/game/atoms_movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,9 @@
/atom/movable/proc/grant_all_languages(language_flags = ALL, grant_omnitongue = TRUE, source = LANGUAGE_MIND)
return get_language_holder().grant_all_languages(language_flags, grant_omnitongue, source)

/atom/movable/proc/grant_partial_language(language, amount = 50, source = LANGUAGE_ATOM)
return get_language_holder().grant_partial_language(language, amount, source)

/// Removes a single language.
/atom/movable/proc/remove_language(language, language_flags = ALL, source = LANGUAGE_ALL)
return get_language_holder().remove_language(language, language_flags, source)
Expand All @@ -1493,6 +1496,12 @@
/atom/movable/proc/remove_all_languages(source = LANGUAGE_ALL, remove_omnitongue = FALSE)
return get_language_holder().remove_all_languages(source, remove_omnitongue)

/atom/movable/proc/remove_partial_language(language, source = LANGUAGE_ALL)
return get_language_holder().remove_partial_language(language, source)

/atom/movable/proc/remove_all_partial_languages(source = LANGUAGE_ALL)
return get_language_holder().remove_all_partial_languages(source)

/// Adds a language to the blocked language list. Use this over remove_language in cases where you will give languages back later.
/atom/movable/proc/add_blocked_language(language, source = LANGUAGE_ATOM)
return get_language_holder().add_blocked_language(language, source)
Expand Down
124 changes: 119 additions & 5 deletions code/game/objects/items/devices/radio/encryptionkey.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,40 @@
var/independent = FALSE
/// What channels does this encryption key grant to the parent headset.
var/list/channels = list()
var/datum/language/translated_language
/// Assoc list of language to how well understood it is. 0 is invalid, 100 is perfect.
var/list/language_data

greyscale_config = /datum/greyscale_config/encryptionkey_basic
greyscale_colors = "#820a16#3758c4"

/obj/item/encryptionkey/examine(mob/user)
. = ..()
if(LAZYLEN(channels) || translate_binary)
if(LAZYLEN(channels) || translate_binary || LAZYLEN(language_data))
var/list/examine_text_list = list()
for(var/i in channels)
examine_text_list += "[GLOB.channel_tokens[i]] - [lowertext(i)]"

if(translate_binary)
examine_text_list += "[GLOB.channel_tokens[MODE_BINARY]] - [MODE_BINARY]"

. += span_notice("It can access the following channels; [jointext(examine_text_list, ", ")].")
if(length(examine_text_list))
. += span_notice("It can access the following channels; [jointext(examine_text_list, ", ")].")

var/list/language_text_list = list()
for(var/lang in language_data)
var/langstring = "[GLOB.language_datum_instances[lang].name]"
switch(language_data[lang])
if(25 to 50)
langstring += " (poor)"
if(50 to 75)
langstring += " (average)"
if(75 to 100)
langstring += " (good)"
language_text_list += langstring

if(length(language_text_list))
. += span_notice("It can translate the following languages; [jointext(language_text_list, ", ")].")

else
. += span_warning("Has no special codes in it. You should probably tell a coder!")

Expand All @@ -42,7 +61,9 @@
name = "binary translator key"
icon_state = "cypherkey_basic"
translate_binary = TRUE
translated_language = /datum/language/machine
language_data = list(
/datum/language/machine = 100,
)
greyscale_config = /datum/greyscale_config/encryptionkey_basic
greyscale_colors = "#24a157#3758c4"

Expand Down Expand Up @@ -221,7 +242,9 @@
RADIO_CHANNEL_ENTERTAINMENT = 1,
)
translate_binary = TRUE
translated_language = /datum/language/machine
language_data = list(
/datum/language/machine = 100,
)

/obj/item/encryptionkey/ai/evil //ported from NT, this goes 'inside' the AI.
name = "syndicate binary encryption key"
Expand All @@ -233,3 +256,94 @@

/obj/item/encryptionkey/secbot
channels = list(RADIO_CHANNEL_AI_PRIVATE = 1, RADIO_CHANNEL_SECURITY = 1)

// This is used for cargo goodies
/obj/item/encryptionkey/language
desc = "An encryption key that automatically translate some language into some other language you can hopefully understand."
icon_state = "cypherkey_cube"
greyscale_config = /datum/greyscale_config/encryptionkey_cube
greyscale_colors = "#339900#246202"

// Thsese are just for admins - the cargo goodies automatically generate these
/obj/item/encryptionkey/language/moth
name = "\improper Moffic translation key"
language_data = list(
/datum/language/moffic = 100,
)

/obj/item/encryptionkey/language/moth/budget
name = "budget Moffic translation key"
language_data = list(
/datum/language/moffic = 50,
)

/obj/item/encryptionkey/language/draconic
name = "\improper Draconic translation key"
language_data = list(
/datum/language/draconic = 100,
)

/obj/item/encryptionkey/language/draconic/budget
name = "budget Draconic translation key"
language_data = list(
/datum/language/draconic = 50,
)

/obj/item/encryptionkey/language/plasmaman
name = "\improper Calcic translation key"
language_data = list(
/datum/language/calcic = 100,
)

/obj/item/encryptionkey/language/plasmaman/budget
name = "budget Calcic translation key"
language_data = list(
/datum/language/calcic = 50,
)

/obj/item/encryptionkey/language/ethereal
name = "\improper Ethereal translation key"
language_data = list(
/datum/language/voltaic = 100,
)

/obj/item/encryptionkey/language/ethereal/budget
name = "budget Ethereal translation key"
language_data = list(
/datum/language/voltaic = 50,
)

/obj/item/encryptionkey/language/felinid
name = "\improper Felinid translation key"
language_data = list(
/datum/language/nekomimetic = 100,
)

/obj/item/encryptionkey/language/felinid/budget
name = "budget Felinid translation key"
language_data = list(
/datum/language/nekomimetic = 50,
)

/obj/item/encryptionkey/language/uncommon
name = "\improper Uncommon translation key"
language_data = list(
/datum/language/uncommon = 100,
)

/obj/item/encryptionkey/language/uncommon/budget
name = "budget Uncommon translation key"
language_data = list(
/datum/language/uncommon = 75, // better than average because common can already partially understand it
)

// This one is used in cargo
/obj/item/encryptionkey/language/all_crew
name = "crew cohesion translation key"
desc = "An encryption key that'll translate a little bit of a lot of languages. Might give you a hint of what's going on, maybe."

/obj/item/encryptionkey/language/all_crew/Initialize(mapload)
. = ..()
language_data = list()
for(var/lang in GLOB.uncommon_roundstart_languages)
language_data[lang] = 20
47 changes: 28 additions & 19 deletions code/game/objects/items/devices/radio/headset.dm
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ GLOBAL_LIST_INIT(channel_tokens, list(
slot_flags = ITEM_SLOT_EARS
dog_fashion = null
var/obj/item/encryptionkey/keyslot2 = null
/// A list of all languages that this headset allows the user to understand. Populated by language encryption keys.
var/list/language_list

// headset is too small to display overlays
overlay_speaker_idle = null
Expand Down Expand Up @@ -101,8 +99,32 @@ GLOBAL_LIST_INIT(channel_tokens, list(

/// Grants all the languages this headset allows the mob to understand via installed chips.
/obj/item/radio/headset/proc/grant_headset_languages(mob/grant_to)
var/list/language_list = keyslot?.language_data?.Copy()

if(keyslot2)
if(length(language_list))
for(var/language in keyslot2.language_data)
if(language_list[language] < keyslot2.language_data[language])
language_list[language] = keyslot2.language_data[language]
continue
language_list[language] = keyslot2.language_data[language]

else
language_list = keyslot2.language_data?.Copy()

for(var/language in language_list)
grant_to.grant_language(language, language_flags = UNDERSTOOD_LANGUAGE, source = LANGUAGE_RADIOKEY)
var/amount_understood = language_list[language]
if(amount_understood >= 100)
grant_to.grant_language(language, language_flags = UNDERSTOOD_LANGUAGE, source = LANGUAGE_RADIOKEY)
else
grant_to.grant_partial_language(language, amount = amount_understood, source = LANGUAGE_RADIOKEY)

/// Clears all radio related languages from the mob.
/obj/item/radio/headset/proc/remove_headset_languages(mob/remove_from)
if(QDELETED(remove_from))
return
remove_from.remove_all_languages(source = LANGUAGE_RADIOKEY)
remove_from.remove_all_partial_languages(source = LANGUAGE_RADIOKEY)

/obj/item/radio/headset/equipped(mob/user, slot, initial)
. = ..()
Expand All @@ -113,8 +135,7 @@ GLOBAL_LIST_INIT(channel_tokens, list(

/obj/item/radio/headset/dropped(mob/user, silent)
. = ..()
for(var/language in language_list)
user.remove_language(language, language_flags = UNDERSTOOD_LANGUAGE, source = LANGUAGE_RADIOKEY)
remove_headset_languages(user)

/obj/item/radio/headset/syndicate //disguised to look like a normal headset for stealth ops

Expand Down Expand Up @@ -419,22 +440,10 @@ GLOBAL_LIST_INIT(channel_tokens, list(
for(var/ch_name in channels)
secure_radio_connections[ch_name] = add_radio(src, GLOB.radiochannels[ch_name])

var/list/old_language_list = language_list?.Copy()
language_list = list()
if(keyslot?.translated_language)
language_list += keyslot.translated_language
if(keyslot2?.translated_language)
language_list += keyslot2.translated_language

// If we're equipped on a mob, we should make sure all the languages
// learned from our installed key chips are all still accurate
// Updates radio languages entirely for the mob wearing the headset
var/mob/mob_loc = loc
if(istype(mob_loc) && mob_loc.get_item_by_slot(slot_flags) == src)
// Remove all the languages we may not be able to know anymore
for(var/language in old_language_list)
mob_loc.remove_language(language, language_flags = UNDERSTOOD_LANGUAGE, source = LANGUAGE_RADIOKEY)

// And grant all the languages we definitely should know now
remove_headset_languages(mob_loc)
grant_headset_languages(mob_loc)

/obj/item/radio/headset/AltClick(mob/living/user)
Expand Down
71 changes: 70 additions & 1 deletion code/modules/cargo/goodies.dm
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,78 @@
/datum/supply_pack/goody/rapid_lighting_device
name = "Rapid Lighting Device (RLD)"
desc = "A device used to rapidly provide lighting sources to an area. Reload with iron, plasteel, glass or compressed matter cartridges."
cost = PAYCHECK_CREW * 10
cost = PAYCHECK_COMMAND * 10
contains = list(/obj/item/construction/rld)

// All this does is generate the supply packs for the language keys
/datum/supply_pack/goody/language_keys_constructor

/datum/supply_pack/goody/language_keys_constructor/generate_supply_packs()
. = list()

var/datum/preference/languages/language_pref = GLOB.preference_entries[/datum/preference/languages]
for(var/langtype in language_pref.selectable_languages)
var/datum/language/lang = GLOB.language_datum_instances[langtype]

var/datum/supply_pack/goody/language_keys/pack = new
pack.target_language = langtype
pack.translation_power = 100
pack.name = "[lang.name] radio translation key"
pack.desc = "A hi-tech radio encryption key that allows the wearer to understand [lang.name] when the radio is worn."
pack.cost = PAYCHECK_COMMAND * 12
pack.id = "[type]_[langtype]_full"
pack.contains = list(/obj/item/encryptionkey/language)

. += pack

var/datum/supply_pack/goody/language_keys/budget_pack = new
budget_pack.target_language = langtype
budget_pack.translation_power = (lang.mutual_understanding?[/datum/language/common] ? 75 : 50)
budget_pack.name = "[lang.name] budget radio translation key"
budget_pack.desc = "A budget radio encryption key that allows the wearer to understand *some* words in [lang.name] when the radio is worn."
budget_pack.cost = PAYCHECK_COMMAND * 4
budget_pack.id = "[type]_[langtype]_budget"
budget_pack.contains = list(/obj/item/encryptionkey/language)

. += budget_pack

// These are auto-generated by the language_keys_constructor
/datum/supply_pack/goody/language_keys
group = "Language Keys (Goodies)"
/// Language this pack is made for
var/target_language
/// How good the translation is
var/translation_power = 100

/datum/supply_pack/goody/language_keys/fill(obj/structure/closet/crate/crate)
var/obj/item/encryptionkey/language/key = new(crate)
key.language_data = list()
key.language_data[target_language] = translation_power // i am afraid of byond butchering this so i'm doing it across two lines
key.name = "\improper [src.name]"
key.desc = src.desc

var/list/jokes = list(
/datum/language/draconic = "The signal's not quite to scale.",
/datum/language/voltaic = "The signal's overpowering.",
/datum/language/nekomimetic = "The signal's rather scratchy.",
/datum/language/moffic = "The signal's a little fuzzy.",
/datum/language/calcic = "The signal lacks a bit of teeth.",
/datum/language/uncommon = "The signal's a bit distorted.",
)

if(jokes[target_language])
key.desc += " [jokes[target_language]]"

if(admin_spawned)
key.flags_1 |= ADMIN_SPAWNED_1

/datum/supply_pack/goody/all_crew_translation
name = "Crew Cohesion radio encryption key"
desc = "A radio encryption key that allows the wearer to understand a few words in most languages spoken by the crew."
group = "Language Keys (Goodies)"
cost = PAYCHECK_COMMAND * 16
contains = list(/obj/item/encryptionkey/language/all_crew)

/datum/supply_pack/goody/fishing_toolbox
name = "Fishing toolbox"
desc = "Complete toolbox set for your fishing adventure. Advanced hooks and lines sold separetely."
Expand Down
7 changes: 3 additions & 4 deletions code/modules/cargo/order.dm
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,10 @@
generateManifest(crate, account_holder, pack, pack.cost)
return crate

/datum/supply_order/proc/generateCombo(miscbox, misc_own, misc_contents, misc_cost)
for (var/I in misc_contents)
new I(miscbox)
/datum/supply_order/proc/generateCombo(obj/miscbox, misc_own, list/datum/supply_pack/misc_contents, misc_cost)
for (var/datum/supply_pack/pack as anything in misc_contents)
pack.fill(miscbox)
generateManifest(miscbox, misc_own, "", misc_cost)
return

/datum/supply_order/proc/append_order(list/new_contents, cost_increase)
for(var/i as anything in new_contents)
Expand Down
Loading

0 comments on commit 5a84968

Please sign in to comment.