System for restricting quirks based on species, no more blood deficiency on bloodless species (#90326)

## About The Pull Request
Quirks can now define if they're "species appropriate," where the base
proc's behavior is simply "does this species already have the quirk's
main trait"
I am unsure if that on its own imposes any new restrictions, currently.

Additionally, blood deficiency cannot be picked on any species without
blood or that doesn't breathe.
I'm sure there's more that might make sense, I'm open to suggestions

Alternative to #90238
## Why It's Good For The Game
Currently, reduces the possibility of taking something like blood
deficiency on a race which suffers no downside from it in order to get
free positive quirks.
Future-ly, potentially allows quirks exclusive to only a select few
species as offered by #90238
## Changelog
🆑
fix: Species without blood can no longer be blood deficient
/🆑
This commit is contained in:
FlufflesTheDog
2025-04-05 19:42:52 +02:00
committed by GitHub
parent 46168e6881
commit 5bc18586a7
9 changed files with 87 additions and 10 deletions
+19 -3
View File
@@ -231,6 +231,8 @@ GLOBAL_LIST_EMPTY(preferences_datums)
if (istype(requested_preference, /datum/preference/name))
tainted_character_profiles = TRUE
for(var/datum/preference_middleware/preference_middleware as anything in middleware)
preference_middleware.post_set_preference(ui.user, requested_preference_key, value)
return TRUE
if ("set_color_preference")
var/requested_preference_key = params["preference"]
@@ -419,10 +421,24 @@ GLOBAL_LIST_EMPTY(preferences_datums)
.++
/datum/preferences/proc/validate_quirks()
if(CONFIG_GET(flag/disable_quirk_points))
return
if(GetQuirkBalance() < 0)
var/datum/species/species_type = read_preference(/datum/preference/choiced/species)
var/list/quirks_removed
for(var/quirk_name in all_quirks)
var/quirk_path = SSquirks.quirks[quirk_name]
var/datum/quirk/quirk_prototype = SSquirks.quirk_prototypes[quirk_path]
if(!quirk_prototype.is_species_appropriate(species_type))
all_quirks -= quirk_name
LAZYADD(quirks_removed, quirk_name)
var/list/feedback
if(LAZYLEN(quirks_removed))
LAZYADD(feedback, "The following quirks are incompatible with your species:")
LAZYADD(feedback, quirks_removed)
if(!CONFIG_GET(flag/disable_quirk_points) && GetQuirkBalance() < 0)
LAZYADD(feedback, "Your quirks have been reset.")
all_quirks = list()
if(LAZYLEN(feedback))
to_chat(parent, boxed_message(span_greentext(feedback.Join("\n"))))
/**
* Safely read a given preference datum from a given client.
@@ -50,3 +50,7 @@
/// Called when a character is changed.
/datum/preference_middleware/proc/on_new_character(mob/user)
return
/// Called after every update_preference
/datum/preference_middleware/proc/post_set_preference(mob/user, preference, value)
return
@@ -6,6 +6,41 @@
"give_quirk" = PROC_REF(give_quirk),
"remove_quirk" = PROC_REF(remove_quirk),
)
/datum/preference_middleware/quirks/pre_set_preference(mob/user, preference, value)
if(preference != "species")
return
var/list/incompatible_quirks
var/selected_species_type = GLOB.species_list[value]
for(var/quirk_name in preferences.all_quirks)
var/quirk_path = SSquirks.quirks[quirk_name]
var/datum/quirk/quirk_prototype = SSquirks.quirk_prototypes[quirk_path]
if(!quirk_prototype.is_species_appropriate(selected_species_type))
LAZYADD(incompatible_quirks, quirk_name)
if(!LAZYLEN(incompatible_quirks))
return
var/list/message = list("The following quirks are incompatible with your selected species and will be removed: [incompatible_quirks.Join(", ")].")
if(CONFIG_GET(flag/disable_quirk_points))
message += "Would you like to continue?"
else
message += "If you do not have enough points to cover the removed quirks, your quirks will be reset. Would you like to continue?"
var/response = tgui_alert(user, message.Join(" "), "Quirks Incompatible", list("Yes", "No"))
if(response != "Yes")
return TRUE
/datum/preference_middleware/quirks/post_set_preference(mob/user, preference, value)
if(preference != "species")
return
tainted = TRUE
preferences.validate_quirks()
/datum/preference_middleware/quirks/proc/get_species_compatibility()
var/list/species_blacklist = list()
var/datum/species/mob_species = preferences.read_preference(/datum/preference/choiced/species)
for(var/datum/quirk/quirk_type as anything in SSquirks.quirk_prototypes)
if(!SSquirks.quirk_prototypes[quirk_type].is_species_appropriate(mob_species))
species_blacklist += quirk_type::name
return species_blacklist
/datum/preference_middleware/quirks/get_ui_static_data(mob/user)
if (preferences.current_window != PREFERENCE_TAB_CHARACTER_PREFERENCES)
@@ -14,6 +49,7 @@
var/list/data = list()
data["selected_quirks"] = get_selected_quirks()
data["species_disallowed_quirks"] = get_species_compatibility()
return data
@@ -23,6 +59,7 @@
if (tainted)
tainted = FALSE
data["selected_quirks"] = get_selected_quirks()
data["species_disallowed_quirks"] = get_species_compatibility()
return data
@@ -63,6 +100,7 @@
/datum/preference_middleware/quirks/proc/give_quirk(list/params, mob/user)
var/quirk_name = params["quirk"]
preferences.validate_quirks()
var/list/new_quirks = preferences.all_quirks | quirk_name
if (SSquirks.filter_invalid_quirks(new_quirks) != new_quirks)
// If the client is sending an invalid give_quirk, that means that