Files
Bubberstation/code/controllers/subsystem/processing/quirks.dm
Timberpoes ec2938c72c Refactors quirk code. (#59618)
Adds new signal - COMSIG_MOB_EQUIPPED_ITEM. Signal sent at the same time COMSIG_ITEM_EQUIPPED is and allows something to Register for every time a mob equips an item. Replaced a process() in /datum/quirk/badback with signals relating to this. Holds a weakref to any backpack it has registered signals with for use in its own remove() proc.

Removes snowflake code in /datum/quirk/light_step - This quirk no longer uses GetComponent to directly modify a component. Instead, the same code has been shifted into the component itself, which now checks for TRAIT_LIGHT_STEP and mods the volume and range accordingly.

Refactors quirk code in general - Quirks no longer do major logic in New() and no longer qdel themselves in New(). You now fully instantiate a quirk assigned to a var, then call /datum/quirk/proc/add_to_holder(). Various scenarios that shouldn't happen now get handled in this proc and calling code can cleanup properly. Quirks "support" having no quirk_holder - Since their default state is no quirk_holder until the quirk is added to a holder, and similarly quirks can be removed from a holder as well. Destroying a quirk with a quirk_holder will remove it from the quirk_holder properly. qdeling a quirk_holder will clean up any quirks attached to them.

Rethinks processing quirks - Quirks no longer all process automatically. The new logic changes mean their previous need to process() just to check if their quirk_holder had been QDELETED so they didn't become runtime factories has been removed by the refactored code. The few quirks that still process require processing_quirk = TRUE which will start them processing when added to a quirk_holder and stop processing on removal. This means there should be some many hundred fewer quirks process()ing 24/7 every shift.

Subtypes item quirks - A number of quirks are designed to give items to the player. There's code duplication and varying implementation issues, so item quirks have their own subtype with a proc and some vars to handle this. Quirks will no longer fail to give items at all (some quirks actually explictly qdel'd the items they give if the user had no free hands or slots) and will drop items on the floor in the worst-case scenario. Players will always get the opportunity to see messages related to item quirks as these are in a code path that, when the quirk is first added to a new mob, will either output immediately if the mob has a client, or wait for the mob to have a client otherwise.

"Roundstart quirks" paradigm removed - Quirks now have a path to add unique effects that aren't replicated if the quirk is transferred from one mob to another - add_unique(). Item spawning and other similar one-shot logic is done here. This means that adding a quirk to a mob will trigger the one-time effects. Transferring it between mobs (for example, slimepeople changing bodies or swapping a golem shell) will not. roundstart_quirks var renamed to just quirks since it genuinely is just a list of quirks the mob has from any source - Whether roundstart, admin or transferred.

Family Heirloom quirk - Heirloom is now a weakref.

Nyctophobia quirk - No longer process()es, now Registers COMSIG_MOVABLE_MOVED. Every footstep in the dark will slow you back to walking.

Reality Dissociation Syndrome quirk - No longer snowflakes behaviour for mindbreaker toxin on process. Now mindbreaker toxin has the anti-hallucination functionality built into its already existing HAS_TRAIT(M, TRAIT_INSANITY) check in on_mob_life.

Tongue Tied quirk - Now uses .getorganslot(ORGAN_SLOT_TONGUE) to find the tongue instead of locate() in internal_organs

Obsessed antag - Thanks to the Family Heirloom quirk now holding a weakref to the heirloom item itself, this antag type will no longer get the steal heirloom objective if the heirloom doesn't exist (ie. the weakref is null or fails to resolve, meaning the item has been destroyed)

Various quirks that were impossible to remove before are now removable - Examples being light step (which no longer directly modifies the footstep component) and bad back.

In addition, adds some extra documentation overall and improves compliance with code requirements in a number of procs (but certainly not all).

Probably various other little changes here and there to make the above all mesh together.
2021-06-13 15:47:15 -03:00

139 lines
5.0 KiB
Plaintext

#define EXP_ASSIGN_WAYFINDER 1200
#define RANDOM_QUIRK_BONUS 3
#define MINIMUM_RANDOM_QUIRKS 3
//Used to process and handle roundstart quirks
// - Quirk strings are used for faster checking in code
// - Quirk datums are stored and hold different effects, as well as being a vector for applying trait string
PROCESSING_SUBSYSTEM_DEF(quirks)
name = "Quirks"
init_order = INIT_ORDER_QUIRKS
flags = SS_BACKGROUND
runlevels = RUNLEVEL_GAME
wait = 1 SECONDS
var/list/quirks = list() //Assoc. list of all roundstart quirk datum types; "name" = /path/
var/list/quirk_points = list() //Assoc. list of quirk names and their "point cost"; positive numbers are good traits, and negative ones are bad
var/list/quirk_blacklist = list() //A list of quirks that can not be used with each other. Format: list(quirk1,quirk2),list(quirk3,quirk4)
///An assoc list of quirks that can be obtained as a hardcore character, and their hardcore value.
var/list/hardcore_quirks = list()
/datum/controller/subsystem/processing/quirks/Initialize(timeofday)
if(!quirks.len)
SetupQuirks()
quirk_blacklist = list(list("Blind","Nearsighted"), \
list("Jolly","Depression","Apathetic","Hypersensitive"), \
list("Ageusia","Vegetarian","Deviant Tastes"), \
list("Ananas Affinity","Ananas Aversion"), \
list("Alcohol Tolerance","Light Drinker"), \
list("Clown Fan","Mime Fan"), \
list("Bad Touch", "Friendly"), \
list("Extrovert", "Introvert"))
return ..()
/datum/controller/subsystem/processing/quirks/proc/SetupQuirks()
// Sort by Positive, Negative, Neutral; and then by name
var/list/quirk_list = sortList(subtypesof(/datum/quirk), /proc/cmp_quirk_asc)
for(var/type in quirk_list)
var/datum/quirk/quirk_type = type
if(initial(quirk_type.abstract_parent_type) == type)
continue
quirks[initial(quirk_type.name)] = quirk_type
quirk_points[initial(quirk_type.name)] = initial(quirk_type.value)
var/hardcore_value = initial(quirk_type.hardcore_value)
if(!hardcore_value)
continue
hardcore_quirks[quirk_type] += hardcore_value
/datum/controller/subsystem/processing/quirks/proc/AssignQuirks(mob/living/user, client/cli)
var/badquirk = FALSE
for(var/V in cli.prefs.all_quirks)
var/datum/quirk/Q = quirks[V]
if(Q)
user.add_quirk(Q)
else
stack_trace("Invalid quirk \"[V]\" in client [cli.ckey] preferences")
cli.prefs.all_quirks -= V
badquirk = TRUE
if(badquirk)
cli.prefs.save_character()
if(ishuman(user))
var/mob/living/carbon/human/human = user
human.hardcore_survival_score = cli.prefs.hardcore_survival_score //Only do this if we actually asign quirks, to prevent sillicons etc from getting the points.
// Assign wayfinding pinpointer granting quirk if they're new
if(cli.get_exp_living(TRUE) < EXP_ASSIGN_WAYFINDER && !user.has_quirk(/datum/quirk/item_quirk/needswayfinder))
user.add_quirk(/datum/quirk/item_quirk/needswayfinder)
/*
*Randomises the quirks for a specified mob
*/
/datum/controller/subsystem/processing/quirks/proc/randomise_quirks(mob/living/user)
var/bonus_quirks = max((length(user.quirks) + rand(-RANDOM_QUIRK_BONUS, RANDOM_QUIRK_BONUS)), MINIMUM_RANDOM_QUIRKS)
var/added_quirk_count = 0 //How many we've added
var/list/quirks_to_add = list() //Quirks we're adding
var/good_count = 0 //Maximum of 6 good perks
var/score //What point score we're at
///Cached list of possible quirks
var/list/possible_quirks = quirks.Copy()
//Create a random list of stuff to start with
while(bonus_quirks > added_quirk_count)
var/quirk = pick(possible_quirks) //quirk is a string
if(quirk in quirk_blacklist) //prevent blacklisted
possible_quirks -= quirk
continue
if(quirk_points[quirk] > 0)
good_count++
score += quirk_points[quirk]
quirks_to_add += quirk
possible_quirks -= quirk
added_quirk_count++
//But lets make sure we're balanced
while(score > 0)
if(!length(possible_quirks))//Lets not get stuck
break
var/quirk = pick(quirks)
if(quirk in quirk_blacklist) //prevent blacklisted
possible_quirks -= quirk
continue
if(!quirk_points[quirk] < 0)//negative only
possible_quirks -= quirk
continue
good_count++
score += quirk_points[quirk]
quirks_to_add += quirk
//And have benefits too
while(score < 0 && good_count <= MAX_QUIRKS)
if(!length(possible_quirks))//Lets not get stuck
break
var/quirk = pick(quirks)
if(quirk in quirk_blacklist) //prevent blacklisted
possible_quirks -= quirk
continue
if(!quirk_points[quirk] > 0) //positive only
possible_quirks -= quirk
continue
good_count++
score += quirk_points[quirk]
quirks_to_add += quirk
for(var/datum/quirk/quirk as anything in user.quirks)
if(quirk.name in quirks_to_add) //Don't delete ones we keep
quirks_to_add -= quirk.name //Already there, no need to add.
continue
user.remove_quirk(quirk.type) //these quirks are objects
for(var/datum/quirk/quirk as anything in quirks_to_add)
user.add_quirk(quirks[quirk]) //these are typepaths converted from string
#undef RANDOM_QUIRK_BONUS
#undef MINIMUM_RANDOM_QUIRKS