mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-09 16:05:07 +00:00
## About The Previous Pull Request
#85308 reverted by #85929

~~Causes the round to not start when a player isn't eligible for any
jobs at a specific priority level due to runtimes trying to `pick()`
from an empty list aborting the entire job assignment stack.~~
(Fixed???? by
e0e9f2f430)
Maybe we should test merge this for a mo just to make sure no more
cheeky runtimes pop up before merging.
## About The Pull Request
This PR does a couple of minor things:
Makes the job debug logging a bit easier to follow.
Minorly brings some SSjob code up to code standards, converting proc
names to snake_case and doing some otherm is cleanup.
Refactored some stuff into different procs, updated some comments.
And some major things:
Changes the job assignment logic.
Old behaviour
> Assign dynamic priority roles
> Force one Head of Staff (if possible)
> Assign all AIs
> Assign overflow roles (bugged in 2 ways)
> Shuffle the available jobs list once, at the start of the random job
assignment loop
> Pick and assign random jobs for random players from High prefs down,
with a priority on Head of Staff roles
> Handle everyone that couldn't be assigned a random job
New behaviour
> Assign dynamic priority roles
> Assign all Head of Staff roles to players with High prefs
> If no Head of Staff was made in the above way, force one Head of Staff
(if possible)
> Assign all AIs
> Assign overflow roles (fixed)
> Prioritise and fill unfilled head roles at each job priority pref
level, from High prefs down.
> Build a list of all jobs that each unassigned player could be eligible
for at the above pref level.
> Pick a job from that list at random and assign it to the player.
> Handle everyone that couldn't be assigned a random job.
In reality there should be little impact on overall job assignment, the
code changes read more as semantics. For example, the priority check for
filling Head slots will have the same candidate pool in both old and new
versions, but in the new version we're more clearly saying that Heads
are important and we want to prioritise filling them for the sake of
round progression even though the outcome in new and old is the same.
A key change will lead to an increase in assistants - Overflow fixes.
Currently the code block to do early assignments to the Overflow role
doesn't work - or works but not as you'd expect. The idea was is that
because enabling the Overflow role in the prefs menu is an On/Off toggle
that sets the job to High priority when enabled and prevents any other
High priority pref, players that have the Overflow role enabled will
**always** get it. It's their highest priority job with infinite slots.
So we do a pass right at the start to give everyone with the Overflow
role enabled that role and save us wasting time later on in random job
code giving them that same role but with more work.
The problem is the code for this only assigns the Overflow role to
people with it set to Low priority in their prefs, resulting in log
readouts like:
```
[2024-07-27 09:49:43.469] DEBUG-JOB: DO, Running Overflow Check 1
[2024-07-27 09:49:43.469] DEBUG-JOB: Running FOC, Job: /datum/job/assistant, Level: Low Priority
[2024-07-27 09:49:43.472] DEBUG-JOB: FOC player job enabled at wrong level, Player: Radioprague, TheirLevel: Medium Priority, ReqLevel: Low Priority
[2024-07-27 09:49:43.472] DEBUG-JOB: FOC player job enabled at wrong level, Player: Caluan, TheirLevel: High Priority, ReqLevel: Low Priority
[2024-07-27 09:49:43.473] DEBUG-JOB: FOC player job enabled at wrong level, Player: Caractaser, TheirLevel: High Priority, ReqLevel: Low Priority
[2024-07-27 09:49:43.473] DEBUG-JOB: FOC player job enabled at wrong level, Player: Apsua, TheirLevel: High Priority, ReqLevel: Low Priority
[2024-07-27 09:49:43.475] DEBUG-JOB: FOC player job enabled at wrong level, Player: Bebrus2, TheirLevel: Medium Priority, ReqLevel: Low Priority
[2024-07-27 09:49:43.475] DEBUG-JOB: AC1, Candidates: 0
```
Where nobody gets pre-assigned the overflow role because their prefs are
all set to the High priority from being toggled... Except wait a second,
some people have it at Medium priority when it should just be a No
Role/High Priority Role toggle?
And herein we meet a problem. My hypothesis is that traits and stuff
that change the overflow have allowed players to set the "ordinary"
overflow role of Assistant to Medium and/or Low priority.
This still shows as enabled in the prefs menu, but leads to an outcome
where a player with assistant enabled is assigned Cook instead.
```
[2024-07-27 09:49:47.775] DEBUG-JOB: DO, Running Overflow Check 1
[2024-07-27 09:49:47.775] DEBUG-JOB: Running FOC, Job: /datum/job/assistant, Level: Low Priority
...
[2024-07-27 09:49:43.475] DEBUG-JOB: FOC player job enabled at wrong level, Player: Bebrus2, TheirLevel: Medium Priority, ReqLevel: Low Priority
...
[2024-07-27 09:49:47.987] DEBUG-JOB: Running AR, Player: Bebrus2, Job: /datum/job/cook, LateJoin: 0
```
So players with the Overflow job pref set to Low (an unexpected state,
should be disabled or High) would be guaranteed to get that role if none
of the higher priority Head of Staff/AI/Dynamic roles took over via the
bugged "force overflow for people with the pref enabled" proc.
Players with the Overflow job pref set to High would be guaranteed to
get that role if none of the higher priority Head of Staff/AI/Dynamic
roles took over via the random job assignment code giving them their
Highest priority role thanks to the infinite job slots of the Overflow.
And players with the Overflow job pref set to Medium (an unexpected
state, should be disabled or High) would get Assistant if the shuffle
step of the available jobs list put Assisstant before any of the other
jobs they had prefs enabled for at Medium that weren't already filled,
otherwise they'd get another random job.
This code is now changed to ignore the priority the player has set when
looking for people to fill the overflow role. As long as it **is**
enabled, the player will get it unless they're forced into a dynamic
ruleset role (AI when malf rolls) or a Head of Staff role due to their
other prefs (they have RD set to med or low, and no other player has a
Head of Staff at high so they get randomly picked and miss the overflow
role).
This will increase the number of assistants in shifts where their pref
state has Assisstant in the bugged Medium priority, but doesn't change
it for bugged Low and not-bugged High/On priority.
On the other side of the coin, we have how the random jobs are picked.
They're kinda not random, and I noticed this reading the logs then
reading the code.
The list of available jobs to pick from is randomly shuffled - but only
**once**. All players pull from a list of jobs in the same order. So you
end up with a log block like this:
```
[2024-07-27 09:49:47.985] DEBUG-JOB: DO pass, Player: Pierow, Level:3, Job:Botanist
[2024-07-27 09:49:47.985] DEBUG-JOB: Running AR, Player: Pierow, Job: /datum/job/botanist, LateJoin: 0
[2024-07-27 09:49:47.985] DEBUG-JOB: Player: Pierow is now Rank: Botanist, JCP:0, JPL:2
[2024-07-27 09:49:47.986] DEBUG-JOB: DO pass, Player: Daddos, Level:3, Job:Botanist
[2024-07-27 09:49:47.986] DEBUG-JOB: Running AR, Player: Daddos, Job: /datum/job/botanist, LateJoin: 0
[2024-07-27 09:49:47.986] DEBUG-JOB: Player: Daddos is now Rank: Botanist, JCP:1, JPL:2
[2024-07-27 09:49:47.986] DEBUG-JOB: FOC job filled and not overflow, Player: Bebrus2, Job: /datum/job/botanist, Current: 2, Limit: 2
[2024-07-27 09:49:47.987] DEBUG-JOB: FOC player job not enabled, Player: Bebrus2
[2024-07-27 09:49:47.987] DEBUG-JOB: DO pass, Player: Bebrus2, Level:3, Job:Cook
[2024-07-27 09:49:47.987] DEBUG-JOB: Running AR, Player: Bebrus2, Job: /datum/job/cook, LateJoin: 0
[2024-07-27 09:49:47.988] DEBUG-JOB: Player: Bebrus2 is now Rank: Cook, JCP:0, JPL:1
[2024-07-27 09:49:47.988] DEBUG-JOB: FOC player job not enabled, Player: Redwizz
[2024-07-27 09:49:47.988] DEBUG-JOB: FOC job filled and not overflow, Player: Redwizz, Job: /datum/job/cook, Current: 1, Limit: 1
```
The list is shuffled into an order of something like `list("Scientist",
"Botanist", "Cook", "Sec Officer", ...)` then iterated over for each
player. So every random job selection goes:
> "Does Player1 have Scientist enabled and at the right priority? No?
Okay, Botanist? Yes? You get botanist."
> "Does Player2 have Scientist enabled and at the right priority? No?
Okay, Botanist? Yes? You get botanist."
> "Does Player3 have Scientist enabled and at the right priority? No?
Okay, Botanist has no slots left so we'll remove it from the list. Okay,
Cook? Yes? You get cook."
> "Does Player4 have Scientist enabled and at the right priority? No?
Okay, Cook has no slots left so we'll remove it from the list. Okay, Sec
Officer? ..."
This can lead to stacked individual departments if it gets randomly
rolled to the start of the list in the shuffle, and completely empty
departments if they end up at the end.
On high pop shifts this is probably less of an issue. Player prefs add
noise to this and as departments at the front fill up, those at the back
pick up some of the lower pref players.
But have you ever had a shift where there's just like... No fucking sec
even though there's tons of players? The logging (before I made changes
in this PR) was a bit ass, but my hypothesis there is that sec officer
was shuffled right at the end of the random job list, so every other
department was filled up before sec officers were picked.
To mitigate this, I made the list shuffle every single time the game
picks a random available job for the player. This should lead to a more
balanced selection of available jobs by avoiding situations where the
code is biased towards packing some departments by accident.
## Why It's Good For The Game
Overflow fixes mean people who go to their prefs and see the Overflow
Role is On will all have the same experience - They will be the Overflow
role.
More random random job selection should prevent individual departments
having a jobs be stacked when it would have otherwise been possible for
a more balanced selection but the code unintentially biased random
departments to be overstaffed and understaffed each shift.
## Changelog
🆑
fix: Having the Overflow Role set to On will properly ensure you get
that role at a High priority as intended by the game code.
fix: Job selection is now a little bit more random. Fixes an
unintentional bias in random job assignment that could lead to
feast-or-famine for roles where everyone is assigned one job and nobody
is assigned another job.
/🆑
539 lines
17 KiB
Plaintext
539 lines
17 KiB
Plaintext
GLOBAL_LIST_EMPTY(preferences_datums)
|
|
|
|
/datum/preferences
|
|
var/client/parent
|
|
/// The path to the general savefile for this datum
|
|
var/path
|
|
/// Whether or not we allow saving/loading. Used for guests, if they're enabled
|
|
var/load_and_save = TRUE
|
|
/// Ensures that we always load the last used save, QOL
|
|
var/default_slot = 1
|
|
/// The maximum number of slots we're allowed to contain
|
|
var/max_save_slots = 3
|
|
|
|
/// Bitflags for communications that are muted
|
|
var/muted = NONE
|
|
/// Last IP that this client has connected from
|
|
var/last_ip
|
|
/// Last CID that this client has connected from
|
|
var/last_id
|
|
|
|
/// Cached changelog size, to detect new changelogs since last join
|
|
var/lastchangelog = ""
|
|
|
|
/// List of ROLE_X that the client wants to be eligible for
|
|
var/list/be_special = list() //Special role selection
|
|
|
|
/// Custom keybindings. Map of keybind names to keyboard inputs.
|
|
/// For example, by default would have "swap_hands" -> list("X")
|
|
var/list/key_bindings = list()
|
|
|
|
/// Cached list of keybindings, mapping keys to actions.
|
|
/// For example, by default would have "X" -> list("swap_hands")
|
|
var/list/key_bindings_by_key = list()
|
|
|
|
var/toggles = TOGGLES_DEFAULT
|
|
var/db_flags = NONE
|
|
var/chat_toggles = TOGGLES_DEFAULT_CHAT
|
|
var/ghost_form = "ghost"
|
|
|
|
//character preferences
|
|
var/slot_randomized //keeps track of round-to-round randomization of the character slot, prevents overwriting
|
|
|
|
var/list/randomise = list()
|
|
|
|
//Quirk list
|
|
var/list/all_quirks = list()
|
|
|
|
//Job preferences 2.0 - indexed by job title , no key or value implies never
|
|
var/list/job_preferences = list()
|
|
|
|
/// The current window, PREFERENCE_TAB_* in [`code/__DEFINES/preferences.dm`]
|
|
var/current_window = PREFERENCE_TAB_CHARACTER_PREFERENCES
|
|
|
|
var/unlock_content = 0
|
|
|
|
var/list/ignoring = list()
|
|
|
|
var/list/exp = list()
|
|
|
|
var/action_buttons_screen_locs = list()
|
|
|
|
///Someone thought we were nice! We get a little heart in OOC until we join the server past the below time (we can keep it until the end of the round otherwise)
|
|
var/hearted
|
|
///If we have a hearted commendations, we honor it every time the player loads preferences until this time has been passed
|
|
var/hearted_until
|
|
///What outfit typepaths we've favorited in the SelectEquipment menu
|
|
var/list/favorite_outfits = list()
|
|
|
|
/// A preview of the current character
|
|
var/atom/movable/screen/map_view/char_preview/character_preview_view
|
|
|
|
/// A list of instantiated middleware
|
|
var/list/datum/preference_middleware/middleware = list()
|
|
|
|
/// The json savefile for this datum
|
|
var/datum/json_savefile/savefile
|
|
|
|
/// The savefile relating to character preferences, PREFERENCE_CHARACTER
|
|
var/list/character_data
|
|
|
|
/// A list of keys that have been updated since the last save.
|
|
var/list/recently_updated_keys = list()
|
|
|
|
/// A cache of preference entries to values.
|
|
/// Used to avoid expensive READ_FILE every time a preference is retrieved.
|
|
var/value_cache = list()
|
|
|
|
/// If set to TRUE, will update character_profiles on the next ui_data tick.
|
|
var/tainted_character_profiles = FALSE
|
|
|
|
/datum/preferences/Destroy(force)
|
|
QDEL_NULL(character_preview_view)
|
|
QDEL_LIST(middleware)
|
|
value_cache = null
|
|
return ..()
|
|
|
|
/datum/preferences/New(client/parent)
|
|
src.parent = parent
|
|
|
|
for (var/middleware_type in subtypesof(/datum/preference_middleware))
|
|
middleware += new middleware_type(src)
|
|
|
|
if(IS_CLIENT_OR_MOCK(parent))
|
|
load_and_save = !is_guest_key(parent.key)
|
|
load_path(parent.ckey)
|
|
if(load_and_save && !fexists(path))
|
|
try_savefile_type_migration()
|
|
unlock_content = !!parent.IsByondMember()
|
|
if(unlock_content)
|
|
max_save_slots = 8
|
|
else
|
|
CRASH("attempted to create a preferences datum without a client or mock!")
|
|
load_savefile()
|
|
|
|
// give them default keybinds and update their movement keys
|
|
key_bindings = deep_copy_list(GLOB.default_hotkeys)
|
|
key_bindings_by_key = get_key_bindings_by_key(key_bindings)
|
|
randomise = get_default_randomization()
|
|
|
|
var/loaded_preferences_successfully = load_preferences()
|
|
if(loaded_preferences_successfully)
|
|
if(load_character())
|
|
return
|
|
//we couldn't load character data so just randomize the character appearance + name
|
|
randomise_appearance_prefs() //let's create a random character then - rather than a fat, bald and naked man.
|
|
if(parent)
|
|
apply_all_client_preferences()
|
|
parent.set_macros()
|
|
|
|
if(!loaded_preferences_successfully)
|
|
save_preferences()
|
|
save_character() //let's save this new random character so it doesn't keep generating new ones.
|
|
|
|
/datum/preferences/ui_interact(mob/user, datum/tgui/ui)
|
|
// There used to be code here that readded the preview view if you "rejoined"
|
|
// I'm making the assumption that ui close will be called whenever a user logs out, or loses a window
|
|
// If this isn't the case, kill me and restore the code, thanks
|
|
|
|
ui = SStgui.try_update_ui(user, src, ui)
|
|
if(!ui)
|
|
character_preview_view = create_character_preview_view(user)
|
|
|
|
ui = new(user, src, "PreferencesMenu")
|
|
ui.set_autoupdate(FALSE)
|
|
ui.open()
|
|
|
|
// HACK: Without this the character starts out really tiny because of some BYOND bug.
|
|
// You can fix it by changing a preference, so let's just forcably update the body to emulate this.
|
|
// Lemon from the future: this issue appears to replicate if the byond map (what we're relaying here)
|
|
// Is shown while the client's mouse is on the screen. As soon as their mouse enters the main map, it's properly scaled
|
|
// I hate this place
|
|
addtimer(CALLBACK(character_preview_view, TYPE_PROC_REF(/atom/movable/screen/map_view/char_preview, update_body)), 1 SECONDS)
|
|
|
|
/datum/preferences/ui_state(mob/user)
|
|
return GLOB.always_state
|
|
|
|
// Without this, a hacker would be able to edit other people's preferences if
|
|
// they had the ref to Topic to.
|
|
/datum/preferences/ui_status(mob/user, datum/ui_state/state)
|
|
return user.client == parent ? UI_INTERACTIVE : UI_CLOSE
|
|
|
|
/datum/preferences/ui_data(mob/user)
|
|
var/list/data = list()
|
|
|
|
if (tainted_character_profiles)
|
|
data["character_profiles"] = create_character_profiles()
|
|
tainted_character_profiles = FALSE
|
|
|
|
data["character_preferences"] = compile_character_preferences(user)
|
|
|
|
data["active_slot"] = default_slot
|
|
|
|
for (var/datum/preference_middleware/preference_middleware as anything in middleware)
|
|
data += preference_middleware.get_ui_data(user)
|
|
|
|
return data
|
|
|
|
/datum/preferences/ui_static_data(mob/user)
|
|
var/list/data = list()
|
|
|
|
data["character_profiles"] = create_character_profiles()
|
|
|
|
data["character_preview_view"] = character_preview_view.assigned_map
|
|
data["overflow_role"] = SSjob.get_job_type(SSjob.overflow_role).title
|
|
data["window"] = current_window
|
|
|
|
data["content_unlocked"] = unlock_content
|
|
|
|
for (var/datum/preference_middleware/preference_middleware as anything in middleware)
|
|
data += preference_middleware.get_ui_static_data(user)
|
|
|
|
return data
|
|
|
|
/datum/preferences/ui_assets(mob/user)
|
|
var/list/assets = list(
|
|
get_asset_datum(/datum/asset/spritesheet/preferences),
|
|
get_asset_datum(/datum/asset/json/preferences),
|
|
)
|
|
|
|
for (var/datum/preference_middleware/preference_middleware as anything in middleware)
|
|
assets += preference_middleware.get_ui_assets()
|
|
|
|
return assets
|
|
|
|
/datum/preferences/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
|
|
. = ..()
|
|
if (.)
|
|
return
|
|
|
|
switch (action)
|
|
if ("change_slot")
|
|
// Save existing character
|
|
save_character()
|
|
// SAFETY: `switch_to_slot` performs sanitization on the slot number
|
|
switch_to_slot(params["slot"])
|
|
return TRUE
|
|
if ("remove_current_slot")
|
|
remove_current_slot()
|
|
return TRUE
|
|
if ("rotate")
|
|
character_preview_view.setDir(turn(character_preview_view.dir, -90))
|
|
return TRUE
|
|
if ("set_preference")
|
|
var/requested_preference_key = params["preference"]
|
|
var/value = params["value"]
|
|
|
|
for (var/datum/preference_middleware/preference_middleware as anything in middleware)
|
|
if (preference_middleware.pre_set_preference(usr, requested_preference_key, value))
|
|
return TRUE
|
|
|
|
var/datum/preference/requested_preference = GLOB.preference_entries_by_key[requested_preference_key]
|
|
if (isnull(requested_preference))
|
|
return FALSE
|
|
|
|
// SAFETY: `update_preference` performs validation checks
|
|
if (!update_preference(requested_preference, value))
|
|
return FALSE
|
|
|
|
if (istype(requested_preference, /datum/preference/name))
|
|
tainted_character_profiles = TRUE
|
|
|
|
return TRUE
|
|
if ("set_color_preference")
|
|
var/requested_preference_key = params["preference"]
|
|
|
|
var/datum/preference/requested_preference = GLOB.preference_entries_by_key[requested_preference_key]
|
|
if (isnull(requested_preference))
|
|
return FALSE
|
|
|
|
if (!istype(requested_preference, /datum/preference/color))
|
|
return FALSE
|
|
|
|
var/default_value = read_preference(requested_preference.type)
|
|
|
|
// Yielding
|
|
var/new_color = input(
|
|
usr,
|
|
"Select new color",
|
|
null,
|
|
default_value || COLOR_WHITE,
|
|
) as color | null
|
|
|
|
if (!new_color)
|
|
return FALSE
|
|
|
|
if (!update_preference(requested_preference, new_color))
|
|
return FALSE
|
|
|
|
return TRUE
|
|
|
|
for (var/datum/preference_middleware/preference_middleware as anything in middleware)
|
|
var/delegation = preference_middleware.action_delegations[action]
|
|
if (!isnull(delegation))
|
|
return call(preference_middleware, delegation)(params, usr)
|
|
|
|
return FALSE
|
|
|
|
/datum/preferences/ui_close(mob/user)
|
|
save_character()
|
|
save_preferences()
|
|
QDEL_NULL(character_preview_view)
|
|
|
|
/datum/preferences/Topic(href, list/href_list)
|
|
. = ..()
|
|
if (.)
|
|
return
|
|
|
|
if (href_list["open_keybindings"])
|
|
current_window = PREFERENCE_TAB_KEYBINDINGS
|
|
update_static_data(usr)
|
|
ui_interact(usr)
|
|
return TRUE
|
|
|
|
/datum/preferences/proc/create_character_preview_view(mob/user)
|
|
character_preview_view = new(null, src)
|
|
character_preview_view.generate_view("character_preview_[REF(character_preview_view)]")
|
|
character_preview_view.update_body()
|
|
character_preview_view.display_to(user)
|
|
|
|
return character_preview_view
|
|
|
|
/datum/preferences/proc/compile_character_preferences(mob/user)
|
|
var/list/preferences = list()
|
|
|
|
for (var/datum/preference/preference as anything in get_preferences_in_priority_order())
|
|
if (!preference.is_accessible(src))
|
|
continue
|
|
|
|
var/value = read_preference(preference.type)
|
|
var/data = preference.compile_ui_data(user, value)
|
|
|
|
LAZYINITLIST(preferences[preference.category])
|
|
preferences[preference.category][preference.savefile_key] = data
|
|
|
|
|
|
for (var/datum/preference_middleware/preference_middleware as anything in middleware)
|
|
var/list/append_character_preferences = preference_middleware.get_character_preferences(user)
|
|
if (isnull(append_character_preferences))
|
|
continue
|
|
|
|
for (var/category in append_character_preferences)
|
|
if (category in preferences)
|
|
preferences[category] += append_character_preferences[category]
|
|
else
|
|
preferences[category] = append_character_preferences[category]
|
|
|
|
return preferences
|
|
|
|
/// Applies all PREFERENCE_PLAYER preferences
|
|
/datum/preferences/proc/apply_all_client_preferences()
|
|
for (var/datum/preference/preference as anything in get_preferences_in_priority_order())
|
|
if (preference.savefile_identifier != PREFERENCE_PLAYER)
|
|
continue
|
|
|
|
value_cache -= preference.type
|
|
preference.apply_to_client(parent, read_preference(preference.type))
|
|
|
|
/// A preview of a character for use in the preferences menu
|
|
/atom/movable/screen/map_view/char_preview
|
|
name = "character_preview"
|
|
|
|
/// The body that is displayed
|
|
var/mob/living/carbon/human/dummy/body
|
|
/// The preferences this refers to
|
|
var/datum/preferences/preferences
|
|
/// Whether we show current job clothes or nude/loadout only
|
|
var/show_job_clothes = TRUE
|
|
|
|
/atom/movable/screen/map_view/char_preview/Initialize(mapload, datum/preferences/preferences)
|
|
. = ..()
|
|
src.preferences = preferences
|
|
|
|
/atom/movable/screen/map_view/char_preview/Destroy()
|
|
QDEL_NULL(body)
|
|
preferences?.character_preview_view = null
|
|
preferences = null
|
|
return ..()
|
|
|
|
/// Updates the currently displayed body
|
|
/atom/movable/screen/map_view/char_preview/proc/update_body()
|
|
if (isnull(body))
|
|
create_body()
|
|
else
|
|
body.wipe_state()
|
|
|
|
appearance = preferences.render_new_preview_appearance(body, show_job_clothes)
|
|
|
|
/atom/movable/screen/map_view/char_preview/proc/create_body()
|
|
QDEL_NULL(body)
|
|
|
|
body = new
|
|
|
|
/datum/preferences/proc/create_character_profiles()
|
|
var/list/profiles = list()
|
|
|
|
for (var/index in 1 to max_save_slots)
|
|
// It won't be updated in the savefile yet, so just read the name directly
|
|
if (index == default_slot)
|
|
profiles += read_preference(/datum/preference/name/real_name)
|
|
continue
|
|
|
|
var/tree_key = "character[index]"
|
|
var/save_data = savefile.get_entry(tree_key)
|
|
var/name = save_data?["real_name"]
|
|
|
|
if (isnull(name))
|
|
profiles += null
|
|
continue
|
|
|
|
profiles += name
|
|
|
|
return profiles
|
|
|
|
/datum/preferences/proc/set_job_preference_level(datum/job/job, level)
|
|
if (!job)
|
|
return FALSE
|
|
|
|
if (level == JP_HIGH)
|
|
var/datum/job/overflow_role = SSjob.overflow_role
|
|
var/overflow_role_title = initial(overflow_role.title)
|
|
|
|
for(var/other_job in job_preferences)
|
|
if(job_preferences[other_job] == JP_HIGH)
|
|
// Overflow role needs to go to NEVER, not medium!
|
|
if(other_job == overflow_role_title)
|
|
job_preferences[other_job] = null
|
|
else
|
|
job_preferences[other_job] = JP_MEDIUM
|
|
|
|
if(level == null)
|
|
job_preferences -= job.title
|
|
else
|
|
job_preferences[job.title] = level
|
|
|
|
return TRUE
|
|
|
|
/datum/preferences/proc/GetQuirkBalance()
|
|
var/bal = 0
|
|
for(var/V in all_quirks)
|
|
var/datum/quirk/T = SSquirks.quirks[V]
|
|
bal -= initial(T.value)
|
|
return bal
|
|
|
|
/datum/preferences/proc/GetPositiveQuirkCount()
|
|
. = 0
|
|
for(var/q in all_quirks)
|
|
if(SSquirks.quirk_points[q] > 0)
|
|
.++
|
|
|
|
/datum/preferences/proc/validate_quirks()
|
|
if(CONFIG_GET(flag/disable_quirk_points))
|
|
return
|
|
if(GetQuirkBalance() < 0)
|
|
all_quirks = list()
|
|
|
|
/**
|
|
* Safely read a given preference datum from a given client.
|
|
*
|
|
* Reads the given preference datum from the given client, and guards against null client and null prefs.
|
|
* The client object is fickle and can go null at times, so use this instead of read_preference() if you
|
|
* want to ensure no runtimes.
|
|
*
|
|
* returns client.prefs.read_preference(prefs_to_read) or FALSE if something went wrong.
|
|
*
|
|
* Arguments:
|
|
* * client/prefs_holder - the client to read the pref from
|
|
* * datum/preference/pref_to_read - the type of preference datum to read.
|
|
*/
|
|
/proc/safe_read_pref(client/prefs_holder, datum/preference/pref_to_read)
|
|
if(!prefs_holder)
|
|
return FALSE
|
|
if(prefs_holder && !prefs_holder?.prefs)
|
|
stack_trace("[prefs_holder?.mob] ([prefs_holder?.ckey]) had null prefs, which shouldn't be possible!")
|
|
return FALSE
|
|
|
|
return prefs_holder?.prefs.read_preference(pref_to_read)
|
|
|
|
/**
|
|
* Get the given client's chat toggle prefs.
|
|
*
|
|
* Getter function for prefs.chat_toggles which guards against null client and null prefs.
|
|
* The client object is fickle and can go null at times, so use this instead of directly accessing the var
|
|
* if you want to ensure no runtimes.
|
|
*
|
|
* returns client.prefs.chat_toggles or FALSE if something went wrong.
|
|
*
|
|
* Arguments:
|
|
* * client/prefs_holder - the client to get the chat_toggles pref from.
|
|
*/
|
|
/proc/get_chat_toggles(client/target)
|
|
if(ismob(target))
|
|
var/mob/target_mob = target
|
|
target = target_mob.client
|
|
|
|
if(isnull(target))
|
|
return NONE
|
|
|
|
var/datum/preferences/preferences = target.prefs
|
|
if(isnull(preferences))
|
|
stack_trace("[key_name(target)] preference datum was null")
|
|
return NONE
|
|
|
|
return preferences.chat_toggles
|
|
|
|
/// Sanitizes the preferences, applies the randomization prefs, and then applies the preference to the human mob.
|
|
/datum/preferences/proc/safe_transfer_prefs_to(mob/living/carbon/human/character, icon_updates = TRUE, is_antag = FALSE)
|
|
apply_character_randomization_prefs(is_antag)
|
|
apply_prefs_to(character, icon_updates)
|
|
|
|
/// Applies the given preferences to a human mob.
|
|
/datum/preferences/proc/apply_prefs_to(mob/living/carbon/human/character, icon_updates = TRUE)
|
|
character.dna.features = list()
|
|
|
|
for (var/datum/preference/preference as anything in get_preferences_in_priority_order())
|
|
if (preference.savefile_identifier != PREFERENCE_CHARACTER)
|
|
continue
|
|
|
|
preference.apply_to_human(character, read_preference(preference.type))
|
|
|
|
character.dna.real_name = character.real_name
|
|
|
|
if(icon_updates)
|
|
character.icon_render_keys = list()
|
|
character.update_body(is_creating = TRUE)
|
|
|
|
SEND_SIGNAL(character, COMSIG_HUMAN_PREFS_APPLIED)
|
|
|
|
/// Returns whether the parent mob should have the random hardcore settings enabled. Assumes it has a mind.
|
|
/datum/preferences/proc/should_be_random_hardcore(datum/job/job, datum/mind/mind)
|
|
if(!read_preference(/datum/preference/toggle/random_hardcore))
|
|
return FALSE
|
|
if(job.job_flags & JOB_HEAD_OF_STAFF) //No heads of staff
|
|
return FALSE
|
|
for(var/datum/antagonist/antag as anything in mind.antag_datums)
|
|
if(antag.get_team()) //No team antags
|
|
return FALSE
|
|
return TRUE
|
|
|
|
/// Inverts the key_bindings list such that it can be used for key_bindings_by_key
|
|
/datum/preferences/proc/get_key_bindings_by_key(list/key_bindings)
|
|
var/list/output = list()
|
|
|
|
for (var/action in key_bindings)
|
|
for (var/key in key_bindings[action])
|
|
LAZYADD(output[key], action)
|
|
|
|
return output
|
|
|
|
/// Returns the default `randomise` variable ouptut
|
|
/datum/preferences/proc/get_default_randomization()
|
|
var/list/default_randomization = list()
|
|
|
|
for (var/preference_key in GLOB.preference_entries_by_key)
|
|
var/datum/preference/preference = GLOB.preference_entries_by_key[preference_key]
|
|
if (preference.is_randomizable() && preference.randomize_by_default)
|
|
default_randomization[preference_key] = RANDOM_ENABLED
|
|
|
|
return default_randomization
|