From ab78f63ddfdfe4fb89303ad2c75efd278a1ad4ae Mon Sep 17 00:00:00 2001 From: TheChosenEvilOne Date: Sun, 25 Aug 2019 19:22:18 +0300 Subject: [PATCH 1/5] Dynamic configuration file. Signed-off-by: TheChosenEvilOne --- .../configuration/entries/game_options.dm | 5 +++ code/game/gamemodes/dynamic/dynamic.dm | 17 +++++++++ .../gamemodes/dynamic/dynamic_rulesets.dm | 2 +- .../dynamic/dynamic_rulesets_latejoin.dm | 2 +- .../dynamic/dynamic_rulesets_midround.dm | 2 +- config/dynamic.json | 36 +++++++++++++++++++ config/game_options.txt | 3 ++ 7 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 config/dynamic.json diff --git a/code/controllers/configuration/entries/game_options.dm b/code/controllers/configuration/entries/game_options.dm index 6a1e0b1d851..5ba38262c46 100644 --- a/code/controllers/configuration/entries/game_options.dm +++ b/code/controllers/configuration/entries/game_options.dm @@ -378,3 +378,8 @@ /datum/config_entry/number/monkeycap config_entry_value = 64 min_val = 0 + +/datum/config_entry/flag/dynamic_config_enabled + +/datum/config_entry/string/dynamic_config_file + config_entry_value = "config/dynamic.json" diff --git a/code/game/gamemodes/dynamic/dynamic.dm b/code/game/gamemodes/dynamic/dynamic.dm index cb7250f8109..18f83e0d85d 100644 --- a/code/game/gamemodes/dynamic/dynamic.dm +++ b/code/game/gamemodes/dynamic/dynamic.dm @@ -107,6 +107,8 @@ GLOBAL_VAR_INIT(dynamic_forced_threat_level, -1) var/highlander_executed = FALSE /// If a only ruleset has been executed. var/only_ruleset_executed = FALSE + /// Dynamic configuration, loaded on pre_setup + var/list/configuration = null /datum/game_mode/dynamic/admin_panel() var/list/dat = list("Game Mode Panel

Game Mode Panel

") @@ -287,6 +289,10 @@ GLOBAL_VAR_INIT(dynamic_forced_threat_level, -1) return TRUE /datum/game_mode/dynamic/pre_setup() + if(CONFIG_GET(flag/dynamic_config_enabled)) + var/json_file = file(CONFIG_GET(string/dynamic_config_file)) + if(fexists(json_file)) + configuration = json_decode(file2text(json_file)) for (var/rule in subtypesof(/datum/dynamic_ruleset)) var/datum/dynamic_ruleset/ruleset = new rule() // Simple check if the ruleset should be added to the lists. @@ -300,6 +306,17 @@ GLOBAL_VAR_INIT(dynamic_forced_threat_level, -1) if ("Midround") if (ruleset.weight) midround_rules += ruleset + if(configuration) + if(!configuration[ruleset.ruletype]) + continue + if(!configuration[ruleset.ruletype][ruleset.name]) + continue + var/rule_conf = configuration[ruleset.ruletype][ruleset.name] + for(var/variable in rule_conf) + if(!ruleset.vars[variable]) + stack_trace("Invalid dynamic configuration variable [variable] in [ruleset.ruletype] [ruleset.name]") + ruleset.vars[variable] = rule_conf[variable] + for(var/mob/dead/new_player/player in GLOB.player_list) if(player.ready == PLAYER_READY_TO_PLAY && player.mind) roundstart_pop_ready++ diff --git a/code/game/gamemodes/dynamic/dynamic_rulesets.dm b/code/game/gamemodes/dynamic/dynamic_rulesets.dm index dda888e1e60..ab97e64e9e5 100644 --- a/code/game/gamemodes/dynamic/dynamic_rulesets.dm +++ b/code/game/gamemodes/dynamic/dynamic_rulesets.dm @@ -168,7 +168,7 @@ candidates.Remove(P) continue else - if(!antag_flag in P.client.prefs.be_special || is_banned_from(P.ckey, list(antag_flag, ROLE_SYNDICATE))) + if(!(antag_flag in P.client.prefs.be_special) || is_banned_from(P.ckey, list(antag_flag, ROLE_SYNDICATE))) candidates.Remove(P) continue diff --git a/code/game/gamemodes/dynamic/dynamic_rulesets_latejoin.dm b/code/game/gamemodes/dynamic/dynamic_rulesets_latejoin.dm index 1340573e6c8..eda3d3ebfcc 100644 --- a/code/game/gamemodes/dynamic/dynamic_rulesets_latejoin.dm +++ b/code/game/gamemodes/dynamic/dynamic_rulesets_latejoin.dm @@ -17,7 +17,7 @@ candidates.Remove(P) continue else - if(!antag_flag in P.client.prefs.be_special || is_banned_from(P.ckey, list(antag_flag, ROLE_SYNDICATE))) + if(!(antag_flag in P.client.prefs.be_special) || is_banned_from(P.ckey, list(antag_flag, ROLE_SYNDICATE))) candidates.Remove(P) continue if (P.mind.assigned_role in restricted_roles) // Does their job allow for it? diff --git a/code/game/gamemodes/dynamic/dynamic_rulesets_midround.dm b/code/game/gamemodes/dynamic/dynamic_rulesets_midround.dm index ac530587534..0cf69d0baf1 100644 --- a/code/game/gamemodes/dynamic/dynamic_rulesets_midround.dm +++ b/code/game/gamemodes/dynamic/dynamic_rulesets_midround.dm @@ -44,7 +44,7 @@ candidates.Remove(M) continue else - if(!antag_flag in M.client.prefs.be_special || is_banned_from(M.ckey, list(antag_flag, ROLE_SYNDICATE))) + if(!(antag_flag in M.client.prefs.be_special) || is_banned_from(M.ckey, list(antag_flag, ROLE_SYNDICATE))) candidates.Remove(M) continue if (M.mind) diff --git a/config/dynamic.json b/config/dynamic.json new file mode 100644 index 00000000000..f396d16403b --- /dev/null +++ b/config/dynamic.json @@ -0,0 +1,36 @@ +{ + "Roundstart": { + "Traitors": { + "cost": 10, + "weight": 5, + "required_candidates": 1, + "high_population_requirement": 10, + "minimum_required_aged": 0, + "requirements": [ + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10 + ], + "protected_roles": [ + "Security Officer", + "Warden", + "Detective", + "Head of Security", + "Captain" + ], + "restricted_roles": [ + "Cyborg" + ], + "autotraitor_cooldown": 450 + } + }, + "Midround": {}, + "Latejoin": {} +} diff --git a/config/game_options.txt b/config/game_options.txt index 409f3599da6..cfa4ca18264 100644 --- a/config/game_options.txt +++ b/config/game_options.txt @@ -254,6 +254,9 @@ MAX_TICKETS_PER_ROLL 100 ## Uncomment to allow players to see the set odds of different rounds in secret/random in the get server revision screen. This will NOT tell the current roundtype. #SHOW_GAME_TYPE_ODDS +DYNAMIC_CONFIG_ENABLED +DYNAMIC_CONFIG_FILE "config/dynamic.json" + ## RANDOM EVENTS ### ## Comment this out to disable random events during the round. ALLOW_RANDOM_EVENTS From 19aa370acb80c7453a90e752eaa28f6b6c579108 Mon Sep 17 00:00:00 2001 From: TheChosenEvilOne Date: Sun, 25 Aug 2019 19:34:47 +0300 Subject: [PATCH 2/5] Config comments Signed-off-by: TheChosenEvilOne --- config/game_options.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/game_options.txt b/config/game_options.txt index cfa4ca18264..60abf784bb0 100644 --- a/config/game_options.txt +++ b/config/game_options.txt @@ -254,7 +254,10 @@ MAX_TICKETS_PER_ROLL 100 ## Uncomment to allow players to see the set odds of different rounds in secret/random in the get server revision screen. This will NOT tell the current roundtype. #SHOW_GAME_TYPE_ODDS +## Uncomment to enable dynamic ruleset config file. DYNAMIC_CONFIG_ENABLED + +## Dynamic ruleset config file location. DYNAMIC_CONFIG_FILE "config/dynamic.json" ## RANDOM EVENTS ### From 51e30dd02a9d822d4d7d63c24eeb2deac27c2aa0 Mon Sep 17 00:00:00 2001 From: TheChosenEvilOne Date: Sun, 25 Aug 2019 19:45:15 +0300 Subject: [PATCH 3/5] Allow higher accuracy requirements/antag caps. Signed-off-by: TheChosenEvilOne --- code/game/gamemodes/dynamic/dynamic_rulesets.dm | 2 +- .../gamemodes/dynamic/dynamic_rulesets_midround.dm | 4 ++-- .../gamemodes/dynamic/dynamic_rulesets_roundstart.dm | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/code/game/gamemodes/dynamic/dynamic_rulesets.dm b/code/game/gamemodes/dynamic/dynamic_rulesets.dm index ab97e64e9e5..8b00adda55d 100644 --- a/code/game/gamemodes/dynamic/dynamic_rulesets.dm +++ b/code/game/gamemodes/dynamic/dynamic_rulesets.dm @@ -92,7 +92,7 @@ return (threat_level >= high_population_requirement) else pop_per_requirement = pop_per_requirement > 0 ? pop_per_requirement : mode.pop_per_requirement - var/indice_pop = min(10,round(population/pop_per_requirement)+1) + var/indice_pop = min(requirements.len,round(population/pop_per_requirement)+1) return (threat_level >= requirements[indice_pop]) /// This is called if persistent variable is true everytime SSTicker ticks. diff --git a/code/game/gamemodes/dynamic/dynamic_rulesets_midround.dm b/code/game/gamemodes/dynamic/dynamic_rulesets_midround.dm index 0cf69d0baf1..e0b5226d304 100644 --- a/code/game/gamemodes/dynamic/dynamic_rulesets_midround.dm +++ b/code/game/gamemodes/dynamic/dynamic_rulesets_midround.dm @@ -313,14 +313,14 @@ cost = 35 requirements = list(90,90,90,80,60,40,30,20,10,10) high_population_requirement = 10 - var/operative_cap = list(2,2,3,3,4,5,5,5,5,5) + var/list/operative_cap = list(2,2,3,3,4,5,5,5,5,5) var/datum/team/nuclear/nuke_team flags = HIGHLANDER_RULESET /datum/dynamic_ruleset/midround/from_ghosts/nuclear/acceptable(population=0, threat=0) if (locate(/datum/dynamic_ruleset/roundstart/nuclear) in mode.executed_rules) return FALSE // Unavailable if nuke ops were already sent at roundstart - var/indice_pop = min(10,round(living_players.len/5)+1) + var/indice_pop = min(operative_cap.len, round(living_players.len/5)+1) required_candidates = operative_cap[indice_pop] return ..() diff --git a/code/game/gamemodes/dynamic/dynamic_rulesets_roundstart.dm b/code/game/gamemodes/dynamic/dynamic_rulesets_roundstart.dm index 56532ef5146..cd839214057 100644 --- a/code/game/gamemodes/dynamic/dynamic_rulesets_roundstart.dm +++ b/code/game/gamemodes/dynamic/dynamic_rulesets_roundstart.dm @@ -200,16 +200,16 @@ requirements = list(100,90,80,60,40,30,10,10,10,10) high_population_requirement = 10 flags = HIGHLANDER_RULESET - var/cultist_cap = list(2,2,2,3,3,4,4,4,4,4) + var/list/cultist_cap = list(2,2,2,3,3,4,4,4,4,4) var/datum/team/cult/main_cult /datum/dynamic_ruleset/roundstart/bloodcult/ready(forced = FALSE) - var/indice_pop = min(10,round(mode.roundstart_pop_ready/pop_per_requirement)+1) + var/indice_pop = min(cultist_cap.len, round(mode.roundstart_pop_ready/pop_per_requirement)+1) required_candidates = cultist_cap[indice_pop] . = ..() /datum/dynamic_ruleset/roundstart/bloodcult/pre_execute() - var/indice_pop = min(10,round(mode.roundstart_pop_ready/pop_per_requirement)+1) + var/indice_pop = min(cultist_cap.len, round(mode.roundstart_pop_ready/pop_per_requirement)+1) var/cultists = cultist_cap[indice_pop] for(var/cultists_number = 1 to cultists) if(candidates.len <= 0) @@ -258,18 +258,18 @@ requirements = list(90,90,90,80,60,40,30,20,10,10) high_population_requirement = 10 flags = HIGHLANDER_RULESET - var/operative_cap = list(2,2,2,3,3,3,4,4,5,5) + var/list/operative_cap = list(2,2,2,3,3,3,4,4,5,5) var/datum/team/nuclear/nuke_team /datum/dynamic_ruleset/roundstart/nuclear/ready(forced = FALSE) - var/indice_pop = min(10,round(mode.roundstart_pop_ready/pop_per_requirement)+1) + var/indice_pop = min(operative_cap.len,round(mode.roundstart_pop_ready/pop_per_requirement)+1) required_candidates = operative_cap[indice_pop] . = ..() /datum/dynamic_ruleset/roundstart/nuclear/pre_execute() // If ready() did its job, candidates should have 5 or more members in it - var/indice_pop = min(10,round(mode.roundstart_pop_ready/5)+1) + var/indice_pop = min(operative_cap.len, round(mode.roundstart_pop_ready/5)+1) var/operatives = operative_cap[indice_pop] for(var/operatives_number = 1 to operatives) if(candidates.len <= 0) From 1f093cdd9c6ce11341cfe62ed35131724cd3505c Mon Sep 17 00:00:00 2001 From: TheChosenEvilOne Date: Mon, 26 Aug 2019 19:39:38 +0300 Subject: [PATCH 4/5] oops Signed-off-by: TheChosenEvilOne --- code/game/gamemodes/dynamic/dynamic_rulesets.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/game/gamemodes/dynamic/dynamic_rulesets.dm b/code/game/gamemodes/dynamic/dynamic_rulesets.dm index 8b00adda55d..fe4aa64304c 100644 --- a/code/game/gamemodes/dynamic/dynamic_rulesets.dm +++ b/code/game/gamemodes/dynamic/dynamic_rulesets.dm @@ -164,7 +164,7 @@ candidates.Remove(P) continue if(antag_flag_override) - if(!antag_flag_override in P.client.prefs.be_special || is_banned_from(P.ckey, list(antag_flag_override, ROLE_SYNDICATE))) + if(!(antag_flag_override in P.client.prefs.be_special) || is_banned_from(P.ckey, list(antag_flag_override, ROLE_SYNDICATE))) candidates.Remove(P) continue else From 92424a44801cda55ac037ce1ead313d61007eaec Mon Sep 17 00:00:00 2001 From: TheChosenEvilOne Date: Fri, 30 Aug 2019 15:38:51 +0300 Subject: [PATCH 5/5] remove DYNAMIC_CONFIG_FILE Signed-off-by: TheChosenEvilOne --- code/controllers/configuration/entries/game_options.dm | 3 --- code/game/gamemodes/dynamic/dynamic.dm | 2 +- config/game_options.txt | 3 --- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/code/controllers/configuration/entries/game_options.dm b/code/controllers/configuration/entries/game_options.dm index 5ba38262c46..f3db9bb3159 100644 --- a/code/controllers/configuration/entries/game_options.dm +++ b/code/controllers/configuration/entries/game_options.dm @@ -380,6 +380,3 @@ min_val = 0 /datum/config_entry/flag/dynamic_config_enabled - -/datum/config_entry/string/dynamic_config_file - config_entry_value = "config/dynamic.json" diff --git a/code/game/gamemodes/dynamic/dynamic.dm b/code/game/gamemodes/dynamic/dynamic.dm index 18f83e0d85d..ee23ba9464e 100644 --- a/code/game/gamemodes/dynamic/dynamic.dm +++ b/code/game/gamemodes/dynamic/dynamic.dm @@ -290,7 +290,7 @@ GLOBAL_VAR_INIT(dynamic_forced_threat_level, -1) /datum/game_mode/dynamic/pre_setup() if(CONFIG_GET(flag/dynamic_config_enabled)) - var/json_file = file(CONFIG_GET(string/dynamic_config_file)) + var/json_file = file("config/dynamic.json") if(fexists(json_file)) configuration = json_decode(file2text(json_file)) for (var/rule in subtypesof(/datum/dynamic_ruleset)) diff --git a/config/game_options.txt b/config/game_options.txt index 60abf784bb0..82d6781708c 100644 --- a/config/game_options.txt +++ b/config/game_options.txt @@ -257,9 +257,6 @@ MAX_TICKETS_PER_ROLL 100 ## Uncomment to enable dynamic ruleset config file. DYNAMIC_CONFIG_ENABLED -## Dynamic ruleset config file location. -DYNAMIC_CONFIG_FILE "config/dynamic.json" - ## RANDOM EVENTS ### ## Comment this out to disable random events during the round. ALLOW_RANDOM_EVENTS