From 0684a1c763092bc8f4ccf9dcf132274f1c5ce9ce Mon Sep 17 00:00:00 2001 From: Doster <63081538+Doster-d@users.noreply.github.com> Date: Fri, 13 Oct 2023 09:57:05 +0300 Subject: [PATCH] tweak(jobs): move jobs to toml with map support --- .../subsystems/initialization/misc.dm | 2 +- code/game/jobs/job/job.dm | 4 ++ code/game/jobs/job/silicon.dm | 4 ++ code/game/jobs/job_controller.dm | 35 ++++++----------- config/example/jobs.toml | 38 +++++++++++++++++++ config/example/jobs.txt | 37 ------------------ 6 files changed, 59 insertions(+), 61 deletions(-) create mode 100644 config/example/jobs.toml delete mode 100644 config/example/jobs.txt diff --git a/code/controllers/subsystems/initialization/misc.dm b/code/controllers/subsystems/initialization/misc.dm index 9a345ac2971..e3d38c228c4 100644 --- a/code/controllers/subsystems/initialization/misc.dm +++ b/code/controllers/subsystems/initialization/misc.dm @@ -12,7 +12,7 @@ SUBSYSTEM_DEF(misc) job_master = new /datum/controller/occupations() job_master.SetupOccupations(setup_titles=1) - job_master.LoadJobs("config/jobs.txt") + job_master.LoadJobs("config/jobs.toml") GLOB.syndicate_code_phrase = generate_code_phrase() GLOB.code_phrase_highlight_rule = generate_code_regex(GLOB.syndicate_code_phrase, @"\u0430-\u0451") // Russian chars only diff --git a/code/game/jobs/job/job.dm b/code/game/jobs/job/job.dm index 0b863416a63..897c8887192 100644 --- a/code/game/jobs/job/job.dm +++ b/code/game/jobs/job/job.dm @@ -168,3 +168,7 @@ /datum/job/proc/is_species_allowed(datum/species/S) return !GLOB.using_map.is_species_job_restricted(S, src) + +/datum/job/proc/set_positions(value) + total_positions = value + spawn_positions = value diff --git a/code/game/jobs/job/silicon.dm b/code/game/jobs/job/silicon.dm index 10b80d220b7..abbd7d15873 100644 --- a/code/game/jobs/job/silicon.dm +++ b/code/game/jobs/job/silicon.dm @@ -15,6 +15,10 @@ hud_icon = "hudblank" preview_override = list("Default", 'icons/mob/hologram.dmi') +/datum/job/ai/set_positions() + . = ..() + total_positions = 0 + /datum/job/ai/equip(mob/living/carbon/human/H) if(!H) return 0 return 1 diff --git a/code/game/jobs/job_controller.dm b/code/game/jobs/job_controller.dm index 6a0a8e2c174..fc6caf02cfd 100644 --- a/code/game/jobs/job_controller.dm +++ b/code/game/jobs/job_controller.dm @@ -546,39 +546,28 @@ var/global/datum/controller/occupations/job_master BITSET(H.hud_updateflag, SPECIALROLE_HUD) return H - proc/LoadJobs(jobsfile) //ran during round setup, reads info from jobs.txt -- Urist + proc/LoadJobs(jobsfile) //ran during round setup, reads info from jobs.toml -- Urist if(!config.misc.load_jobs_from_txt) - return 0 + return FALSE - var/list/jobEntries = file2list(jobsfile) + var/raw_data = FROM_TOML(return_file_text(jobsfile)) - for(var/job in jobEntries) - if(!job) - continue + var/list/jobEntries = raw_data[GLOB.using_map.name] - job = trim(job) - if (!length(job)) + for(var/job in jobEntries) + if(!length(job) || !isnum(jobEntries[job])) continue - var/pos = findtext(job, "=") - var/name = null - var/value = null - - if(pos) - name = copytext(job, 1, pos) - value = copytext(job, pos + 1) - else - continue + var/name = replacetext_char(job, "_", " ") + var/value = jobEntries[job] if(name && value) var/datum/job/J = GetJob(name) - if(!J) continue - J.total_positions = text2num(value) - J.spawn_positions = text2num(value) - if(name == "AI")//I dont like this here but it will do for now - J.total_positions = 0 + if(!J) + continue + J.set_positions(value) - return 1 + return TRUE proc/HandleFeedbackGathering() diff --git a/config/example/jobs.toml b/config/example/jobs.toml new file mode 100644 index 00000000000..f09765addb5 --- /dev/null +++ b/config/example/jobs.toml @@ -0,0 +1,38 @@ +[Exodus] +Captain = 1 +Head_of_Personnel = 1 +Head_of_Security = 1 +Chief_Engineer = 1 +Research_Director = 1 +Chief_Medical_Officer = 1 + +Station_Engineer = 5 +Roboticist = 1 + +Medical_Doctor = 5 +Geneticist = 2 +Virologist = 1 + +Scientist = 3 +Chemist = 2 + +Bartender = 1 +Botanist = 2 +Chef = 1 +Janitor = 1 +Quartermaster = 1 +Shaft_Miner = 3 + +Warden = 1 +Detective = 1 +Security_Officer = 5 + +Assistant = -1 +Atmospheric_Technician = 4 +Cargo_Technician = 3 +Chaplain = 1 +Lawyer = 2 +Librarian = 1 + +AI = 1 +Cyborg = 1 diff --git a/config/example/jobs.txt b/config/example/jobs.txt deleted file mode 100644 index 8279ed18b1a..00000000000 --- a/config/example/jobs.txt +++ /dev/null @@ -1,37 +0,0 @@ -Captain=1 -Head of Personnel=1 -Head of Security=1 -Chief Engineer=1 -Research Director=1 -Chief Medical Officer=1 - -Station Engineer=5 -Roboticist=1 - -Medical Doctor=5 -Geneticist=2 -Virologist=1 - -Scientist=3 -Chemist=2 - -Bartender=1 -Botanist=2 -Chef=1 -Janitor=1 -Quartermaster=1 -Shaft Miner=3 - -Warden=1 -Detective=1 -Security Officer=5 - -Assistant=-1 -Atmospheric Technician=4 -Cargo Technician=3 -Chaplain=1 -Lawyer=2 -Librarian=1 - -AI=1 -Cyborg=1 \ No newline at end of file