From a12ec65678912daab0404db04692b19edbb7e329 Mon Sep 17 00:00:00 2001 From: skull132 Date: Fri, 23 Oct 2015 06:41:54 +0300 Subject: [PATCH] Configurable Age Restrictions Makes the age restrictions on jobs editable on the fly from a new config file. --- code/controllers/configuration.dm | 7 +++ code/game/jobs/job/job.dm | 6 ++- code/game/jobs/job_controller.dm | 2 + code/modules/admin/banjob.dm | 4 ++ code/modules/client/preferences.dm | 17 ++++--- code/world.dm | 2 + config/example/age_restrictions.txt | 71 +++++++++++++++++++++++++++++ 7 files changed, 102 insertions(+), 7 deletions(-) create mode 100644 config/example/age_restrictions.txt diff --git a/code/controllers/configuration.dm b/code/controllers/configuration.dm index 6ae5692a..4080c325 100644 --- a/code/controllers/configuration.dm +++ b/code/controllers/configuration.dm @@ -157,6 +157,8 @@ var/list/contact_levels = list(1, 5) // Defines which Z-levels which, for example, a Code Red announcement may affect var/list/player_levels = list(1, 3, 4, 5, 6) // Defines all Z-levels a character can typically reach + var/list/age_restrictions = list() // Holds all of the age restrictions for jobs and antag roles in a single associated list + /datum/configuration/New() var/list/L = typesof(/datum/game_mode) - /datum/game_mode for (var/T in L) @@ -576,6 +578,11 @@ else log_misc("Unknown setting in configuration: '[name]'") + else if (type == "age_restrictions") + name = replacetext(name, "_", " ") + age_restrictions += name + age_restrictions[name] = text2num(value) + /datum/configuration/proc/loadsql(filename) // -- TLE var/list/Lines = file2list(filename) for(var/t in Lines) diff --git a/code/game/jobs/job/job.dm b/code/game/jobs/job/job.dm index b0de91e9..7ed5b7d0 100644 --- a/code/game/jobs/job/job.dm +++ b/code/game/jobs/job/job.dm @@ -70,4 +70,8 @@ if(!isnum(minimal_player_age)) return 0 - return max(0, minimal_player_age - C.player_age) \ No newline at end of file + return max(0, minimal_player_age - C.player_age) + +/datum/job/proc/fetch_age_restriction() + if (config.age_restrictions[lowertext(title)]) + minimal_player_age = config.age_restrictions[lowertext(title)] diff --git a/code/game/jobs/job_controller.dm b/code/game/jobs/job_controller.dm index f4acb6bd..c7da1724 100644 --- a/code/game/jobs/job_controller.dm +++ b/code/game/jobs/job_controller.dm @@ -24,6 +24,8 @@ var/global/datum/controller/occupations/job_master if(!job) continue if(job.faction != faction) continue occupations += job + if (config && config.use_age_restriction_for_jobs) + job.fetch_age_restriction() return 1 diff --git a/code/modules/admin/banjob.dm b/code/modules/admin/banjob.dm index df251ef6..0c5f8e90 100644 --- a/code/modules/admin/banjob.dm +++ b/code/modules/admin/banjob.dm @@ -26,6 +26,10 @@ var/jobban_keylist[0] //to store the keys & ranks if(config.usewhitelist && !check_whitelist(M)) return "Whitelisted Job" + if (config.use_age_restriction_for_jobs) + if (config.age_restrictions[rank] && M.client.player_age < config.age_restrictions[rank]) + return "Age Restricted" + for (var/s in jobban_keylist) if( findtext(s,"[M.ckey] - [rank]") == 1 ) var/startpos = findtext(s, "## ")+3 diff --git a/code/modules/client/preferences.dm b/code/modules/client/preferences.dm index 2f7ec095..cea406ad 100644 --- a/code/modules/client/preferences.dm +++ b/code/modules/client/preferences.dm @@ -429,13 +429,18 @@ datum/preferences src.be_special = 0 else var/n = 0 + var/banned = null for (var/i in special_roles) if(special_roles[i]) //if mode is available on the server - if(jobban_isbanned(user, i)) - dat += "Be [i]: \[BANNED]
" - else if(i == "pai candidate") - if(jobban_isbanned(user, "pAI")) - dat += "Be [i]: \[BANNED]
" + banned = jobban_isbanned(user, i) + if (i == "pai candidate") + banned = jobban_isbanned(user, "pAI") + + if (banned == "Age Restricted") + var/time = config.age_restrictions[i] - user.client.player_age + dat += "Be [i]: \[IN [time] DAYS]
" + else if (banned) + dat += "Be [i]: \[BANNED]
" else dat += "Be [i]: [src.be_special&(1<
" n++ @@ -1680,4 +1685,4 @@ var/list/limb_connection_data /datum/preferences/proc/make_sure_we_have_a_brain_type_for_machines() if (species=="Machine") if(!machine_brain_type) - machine_brain_type="Posibrain" \ No newline at end of file + machine_brain_type="Posibrain" diff --git a/code/world.dm b/code/world.dm index 12723a6b..a34081dc 100644 --- a/code/world.dm +++ b/code/world.dm @@ -271,6 +271,8 @@ var/master_server_password // apply some settings from config.. abandon_allowed = config.respawn + if (config.use_age_restriction_for_jobs) + config.load("config/age_restrictions.txt","age_restrictions") /hook/startup/proc/loadMods() world.load_mods() diff --git a/config/example/age_restrictions.txt b/config/example/age_restrictions.txt new file mode 100644 index 00000000..a0d3d3cf --- /dev/null +++ b/config/example/age_restrictions.txt @@ -0,0 +1,71 @@ +#Try to keep up to date. +#Replace all spaces in the job titles with underscores, otherwise the config will not load properly + +#These are all the titles (var/title) of the different job datums +#Station jobs +#Command +Captain 0 +Head_of_Personnel 0 +Head_of_Security 0 +Chief_Engineer 0 +Research_Director 0 +Chief_Medical_Officer 0 + +#Engineering +Station_Engineer 0 +Atmospheric_Technician 0 +Engineering_Apprentice 0 + +#Medical +Medical_Doctor 0 +Psychiatrist 0 +Chemist 0 +Emergency_Medical_Tech 0 +Nursing_Intern 0 + +#Science +Scientist 0 +Geneticist 0 +Roboticist 0 +Xenobiologist 0 +Lab_Assistant 0 + +#Security +Warden 0 +Detective 0 +Forensic_Technician 0 +Security_Officer 0 +Security_Cadet 0 + +#Civilian +Bartender 0 +Botanist 0 +Chef 0 +Janitor 0 +Librarian 0 +Quartermaster 0 +Cargo_Technician 0 +Shaft_Miner 0 +Lawyer 0 +Chaplain 0 +Assistant 0 +Internal_Affairs_Agent 0 + +#Synth +AI 0 +Cyborg 0 +pAI 0 + +#This is fetched from the special_roles global list. +#Antags +traitor 0 +operative 0 +changeling 0 +wizard 0 +malf_AI 0 +revolutionary 0 +cultist 0 +ninja 0 +vox_raider 0 +vampire 0 +mutineer 0