Job refactor 2: less hardcoded lists (#60578)

* Job refactor 2: less hardcoded lists

* Obsessed can happen
This commit is contained in:
Rohesie
2021-08-05 16:13:05 -03:00
committed by GitHub
parent 392a74693d
commit 6c4134d1ea
67 changed files with 644 additions and 489 deletions
+39 -51
View File
@@ -142,62 +142,50 @@ GLOBAL_DATUM_INIT(data_core, /datum/datacore, new)
if(foundrecord)
foundrecord.fields["rank"] = assignment
/datum/datacore/proc/get_manifest()
var/list/manifest_out = list(
"Command",
"Security",
"Engineering",
"Medical",
"Science",
"Supply",
"Service",
"Silicon"
)
var/list/departments = list(
"Command" = GLOB.command_positions,
"Security" = GLOB.security_positions + GLOB.security_sub_positions,
"Engineering" = GLOB.engineering_positions,
"Medical" = GLOB.medical_positions,
"Science" = GLOB.science_positions,
"Supply" = GLOB.supply_positions,
"Service" = GLOB.service_positions,
"Silicon" = GLOB.nonhuman_positions
)
var/list/heads = GLOB.command_positions + list("Quartermaster")
for(var/datum/data/record/t in GLOB.data_core.general)
var/name = t.fields["name"]
var/rank = t.fields["rank"]
var/has_department = FALSE
for(var/department in departments)
var/list/jobs = departments[department]
if(rank in jobs)
if(!manifest_out[department])
manifest_out[department] = list()
// Append to beginning of list if captain or department head
if (rank == "Captain" || (department != "Command" && (rank in heads)))
manifest_out[department] = list(list(
"name" = name,
"rank" = rank
)) + manifest_out[department]
else
manifest_out[department] += list(list(
"name" = name,
"rank" = rank
))
has_department = TRUE
if(!has_department)
if(!manifest_out["Misc"])
manifest_out["Misc"] = list()
manifest_out["Misc"] += list(list(
/datum/datacore/proc/get_manifest()
// First we build up the order in which we want the departments to appear in.
var/list/manifest_out = list()
for(var/datum/job_department/department as anything in SSjob.joinable_departments)
manifest_out[department.department_name] = list()
manifest_out[DEPARTMENT_UNASSIGNED] = list()
var/list/departments_by_type = SSjob.joinable_departments_by_type
for(var/datum/data/record/record as anything in GLOB.data_core.general)
var/name = record.fields["name"]
var/rank = record.fields["rank"]
var/datum/job/job = SSjob.GetJob(rank)
if(!job || !(job.job_flags & JOB_CREW_MANIFEST) || !LAZYLEN(job.departments_list)) // In case an unlawful custom rank is added.
var/list/misc_list = manifest_out[DEPARTMENT_UNASSIGNED]
misc_list[++misc_list.len] = list(
"name" = name,
"rank" = rank
))
for (var/department in departments)
if (!manifest_out[department])
"rank" = rank,
)
continue
for(var/department_type as anything in job.departments_list)
var/datum/job_department/department = departments_by_type[department_type]
if(!department)
stack_trace("get_manifest() failed to get job department for [department_type] of [job.type]")
continue
var/list/entry = list(
"name" = name,
"rank" = rank,
)
var/list/department_list = manifest_out[department.department_name]
if(istype(job, department.department_head))
department_list.Insert(1, null)
department_list[1] = entry
else
department_list[++department_list.len] = entry
// Trim the empty categories.
for (var/department in manifest_out)
if(!length(manifest_out[department]))
manifest_out -= department
return manifest_out
/datum/datacore/proc/get_manifest_html(monochrome = FALSE)
var/list/manifest = get_manifest()
var/dat = {"
@@ -80,7 +80,7 @@
var/datum/mind/guilty_conscience = user.mind
if(guilty_conscience) //sec and medical are immune to becoming guilty through attack (we don't check holy because holy shouldn't be able to attack eachother anyways)
var/datum/job/job = guilty_conscience.assigned_role
if(job.departments & (DEPARTMENT_MEDICAL | DEPARTMENT_SECURITY))
if(job.departments_bitflags & (DEPARTMENT_BITFLAG_MEDICAL | DEPARTMENT_BITFLAG_SECURITY))
return
if(declaration)
to_chat(owner, span_notice("[user] is now considered guilty by [GLOB.deity] from your declaration."))
@@ -109,10 +109,10 @@
var/mob/living/carbon/human/target_human = target_creature
var/datum/job/job = target_human.mind?.assigned_role
var/is_holy = target_human.mind?.holy_role
if(is_holy || (job?.departments & DEPARTMENT_SECURITY))
if(is_holy || (job?.departments_bitflags & DEPARTMENT_BITFLAG_SECURITY))
to_chat(honorbound_human, span_warning("There is nothing righteous in attacking the <b>just</b>."))
return FALSE
if(job?.departments & DEPARTMENT_MEDICAL)
if(job?.departments_bitflags & DEPARTMENT_BITFLAG_MEDICAL)
to_chat(honorbound_human, span_warning("If you truly think this healer is not <b>innocent</b>, declare them guilty."))
return FALSE
//THE INNOCENT
@@ -272,7 +272,7 @@
if(!silent)
to_chat(user, span_warning("Followers of [GLOB.deity] cannot be evil!"))
return FALSE
if(guilty_conscience.assigned_role.departments & DEPARTMENT_SECURITY)
if(guilty_conscience.assigned_role.departments_bitflags & DEPARTMENT_BITFLAG_SECURITY)
if(!silent)
to_chat(user, span_warning("Members of security are uncorruptable! You cannot declare one evil!"))
return FALSE
@@ -149,7 +149,7 @@
/datum/station_trait/deathrattle_department/proc/on_job_after_spawn(datum/source, datum/job/job, mob/living/spawned, client/player_client)
SIGNAL_HANDLER
if(!(job.departments & department_to_apply_to))
if(!(job.departments_bitflags & department_to_apply_to))
return
var/obj/item/implant/deathrattle/implant_to_give = new()
@@ -160,43 +160,43 @@
/datum/station_trait/deathrattle_department/service
trait_flags = NONE
weight = 1
department_to_apply_to = DEPARTMENT_SERVICE
department_to_apply_to = DEPARTMENT_BITFLAG_SERVICE
department_name = "Service"
/datum/station_trait/deathrattle_department/cargo
trait_flags = NONE
weight = 1
department_to_apply_to = DEPARTMENT_CARGO
department_to_apply_to = DEPARTMENT_BITFLAG_CARGO
department_name = "Cargo"
/datum/station_trait/deathrattle_department/engineering
trait_flags = NONE
weight = 1
department_to_apply_to = DEPARTMENT_ENGINEERING
department_to_apply_to = DEPARTMENT_BITFLAG_ENGINEERING
department_name = "Engineering"
/datum/station_trait/deathrattle_department/command
trait_flags = NONE
weight = 1
department_to_apply_to = DEPARTMENT_COMMAND
department_to_apply_to = DEPARTMENT_BITFLAG_COMMAND
department_name = "Command"
/datum/station_trait/deathrattle_department/science
trait_flags = NONE
weight = 1
department_to_apply_to = DEPARTMENT_SCIENCE
department_to_apply_to = DEPARTMENT_BITFLAG_SCIENCE
department_name = "Science"
/datum/station_trait/deathrattle_department/security
trait_flags = NONE
weight = 1
department_to_apply_to = DEPARTMENT_SECURITY
department_to_apply_to = DEPARTMENT_BITFLAG_SECURITY
department_name = "Security"
/datum/station_trait/deathrattle_department/medical
trait_flags = NONE
weight = 1
department_to_apply_to = DEPARTMENT_MEDICAL
department_to_apply_to = DEPARTMENT_BITFLAG_MEDICAL
department_name = "Medical"
/datum/station_trait/deathrattle_all