The events system is garbage.

This commit is contained in:
AffectedArc07
2021-05-16 14:31:50 +01:00
parent da705c7e17
commit f259500810
8 changed files with 86 additions and 57 deletions
@@ -14,6 +14,12 @@
target = text2num(input)\
}
/// Wrapper to not overwrite a variable if a list key doesnt exist. Auto casts to number, and accepts a macro argument for number maths (ds to min for example)
#define CONFIG_LOAD_NUM_MULT(target, input, multiplier) \
if(!isnull(input)) {\
target = text2num(input) multiplier\
}
/// Wrapper to not overwrite a variable if a list key doesnt exist. Auto casts to string.
#define CONFIG_LOAD_STR(target, input) \
if(!isnull(input)) {\
@@ -15,6 +15,8 @@ GLOBAL_DATUM_INIT(configuration, /datum/server_configuration, new())
var/datum/configuration_section/database_configuration/database
/// Holder for the Discord configuration datum
var/datum/configuration_section/discord_configuration/discord
/// Holder for the Event configuration datum
var/datum/configuration_section/event_configuration/event
/// Holder for the gateway configuration datum
var/datum/configuration_section/gateway_configuration/gateway
/// Holder for the job configuration datum
@@ -45,6 +47,7 @@ GLOBAL_DATUM_INIT(configuration, /datum/server_configuration, new())
custom_sprites = new()
database = new()
discord = new()
event = new()
gateway = new()
jobs = new()
logging = new()
@@ -65,6 +68,7 @@ GLOBAL_DATUM_INIT(configuration, /datum/server_configuration, new())
custom_sprites.load_data(raw_config_data["custom_sprites_configuration"])
database.load_data(raw_config_data["database_configuration"])
discord.load_data(raw_config_data["discord_configuration"])
event.load_data(raw_config_data["event_configuration"])
gateway.load_data(raw_config_data["gateway_configuration"])
jobs.load_data(raw_config_data["job_configuration"])
logging.load_data(raw_config_data["logging_configuration"])
@@ -0,0 +1,61 @@
/// Config holder for all stuff relating to ingame random events
/datum/configuration_section/event_configuration
/// Do we want to enable random events at all
var/enable_random_events = TRUE
/// Assoc list of when the first event in a group can run. key: severity | value: assoc list with upper and low bounds (key: "upper"/"lower" | value: time in deciseconds)
var/list/first_run_times = list(
EVENT_LEVEL_MUNDANE = null,
EVENT_LEVEL_MODERATE = null,
EVENT_LEVEL_MAJOR = list("lower" = 40 MINUTES, "upper" = 50 MINUTES)
) // <---- Whoever designed this needs to be shot
/// Assoc list of lower bounds of event delays. key: severity | value: delay (deciseconds)
var/list/delay_lower_bound = list(
EVENT_LEVEL_MUNDANE = 5 MINUTES,
EVENT_LEVEL_MODERATE = 15 MINUTES,
EVENT_LEVEL_MAJOR = 25 MINUTES
)
/// Assoc list of lower bounds of event delays. key: severity | value: delay (deciseconds)
var/list/delay_upper_bound = list(
EVENT_LEVEL_MUNDANE = 7.5 MINUTES,
EVENT_LEVEL_MODERATE = 22.5 MINUTES,
EVENT_LEVEL_MAJOR = 35 MINUTES
)
/// Expected time of a round in deciseconds
var/expected_round_length = 120 MINUTES // This macro is equivilent to 72,000 deciseconds
/datum/configuration_section/event_configuration/load_data(list/data)
// Use the load wrappers here. That way the default isnt made 'null' if you comment out the config line
CONFIG_LOAD_BOOL(enable_random_events, data["allow_random_events"])
// Wrapper cant be used here due to it being multiplied
if(isnum(data["expected_round_length"]))
expected_round_length = data["expected_round_length"] MINUTES // Convert from minutes to deciseconds
// Load event severities. This is quite awful but needs to be done so we can account for config mistakes. This event system is awful
if(islist(data["event_delay_lower_bounds"]))
CONFIG_LOAD_NUM_MULT(delay_lower_bound[EVENT_LEVEL_MUNDANE], data["event_delay_lower_bounds"]["mundane"], MINUTES)
CONFIG_LOAD_NUM_MULT(delay_lower_bound[EVENT_LEVEL_MODERATE], data["event_delay_lower_bounds"]["moderate"], MINUTES)
CONFIG_LOAD_NUM_MULT(delay_lower_bound[EVENT_LEVEL_MAJOR], data["event_delay_lower_bounds"]["major"], MINUTES)
// Same here. I hate this.
if(islist(data["event_delay_upper_bounds"]))
CONFIG_LOAD_NUM_MULT(delay_upper_bound[EVENT_LEVEL_MUNDANE], data["event_delay_upper_bounds"]["mundane"], MINUTES)
CONFIG_LOAD_NUM_MULT(delay_upper_bound[EVENT_LEVEL_MODERATE], data["event_delay_upper_bounds"]["moderate"], MINUTES)
CONFIG_LOAD_NUM_MULT(delay_upper_bound[EVENT_LEVEL_MAJOR], data["event_delay_upper_bounds"]["major"], MINUTES)
// And for the worst, the first run delays. I hate this so much -aa07
if(islist(data["event_initial_delays"]))
for(var/list/assoclist in data["event_initial_delays"])
var/target = null
switch(assoclist["severity"])
if("mundane")
target = EVENT_LEVEL_MUNDANE
if("moderate")
target = EVENT_LEVEL_MODERATE
if("major")
target = EVENT_LEVEL_MAJOR
ASSERT(target in list(EVENT_LEVEL_MUNDANE, EVENT_LEVEL_MODERATE, EVENT_LEVEL_MAJOR))
first_run_times[target] = list("lower" = assoclist["lower_bound"] MINUTES, "upper" = assoclist["upper_bound"] MINUTES)