From 563a951975016d759adb879de00ecf1bfd11a797 Mon Sep 17 00:00:00 2001 From: AffectedArc07 Date: Tue, 23 Apr 2019 10:55:36 +0100 Subject: [PATCH] SSevents & SSholiday --- code/__DEFINES/subsystems.dm | 1 + code/__HELPERS/names.dm | 4 +- code/_globalvars/misc.dm | 2 - code/controllers/Processes/event.dm | 15 -- .../subsystem/events.dm} | 161 +++--------------- code/controllers/subsystem/holiday.dm | 31 ++++ code/controllers/verbs.dm | 2 +- code/game/gamemodes/gameticker.dm | 8 +- code/modules/events/event.dm | 6 +- code/modules/events/event_procs.dm | 120 +++++++++++++ code/modules/events/false_alarm.dm | 2 +- code/modules/holiday/holiday.dm | 6 +- code/modules/paperwork/paper.dm | 2 +- code/modules/paperwork/paperbin.dm | 2 +- code/modules/station_goals/shield.dm | 2 +- paradise.dme | 5 +- 16 files changed, 196 insertions(+), 173 deletions(-) rename code/{modules/events/event_manager.dm => controllers/subsystem/events.dm} (73%) create mode 100644 code/controllers/subsystem/holiday.dm create mode 100644 code/modules/events/event_procs.dm diff --git a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm index 5ade3b0baef..515186642fe 100644 --- a/code/__DEFINES/subsystems.dm +++ b/code/__DEFINES/subsystems.dm @@ -61,6 +61,7 @@ #define INIT_ORDER_LANGUAGE 6 #define INIT_ORDER_MACHINES 5 #define INIT_ORDER_CIRCUIT 4 +#define INIT_ORDER_HOLIDAY 3 #define INIT_ORDER_TIMER 1 #define INIT_ORDER_DEFAULT 0 #define INIT_ORDER_AIR -1 diff --git a/code/__HELPERS/names.dm b/code/__HELPERS/names.dm index 930a8ee9de5..5b90cda376e 100644 --- a/code/__HELPERS/names.dm +++ b/code/__HELPERS/names.dm @@ -49,10 +49,10 @@ var/religion_name = null name = "" // Prefix - for(var/holiday_name in holiday_master.holidays) + for(var/holiday_name in SSholiday.holidays) if(holiday_name == "Friday the 13th") random = 13 - var/datum/holiday/holiday = holiday_master.holidays[holiday_name] + var/datum/holiday/holiday = SSholiday.holidays[holiday_name] name = holiday.getStationPrefix() //get normal name if(!name) diff --git a/code/_globalvars/misc.dm b/code/_globalvars/misc.dm index f0bb813a336..0b8c8d58a95 100644 --- a/code/_globalvars/misc.dm +++ b/code/_globalvars/misc.dm @@ -1,8 +1,6 @@ var/global/obj/effect/overlay/plmaster = null var/global/obj/effect/overlay/slmaster = null -// Event Manager, the manager for events. -var/datum/event_manager/event_manager = new() // Announcer intercom, because too much stuff creates an intercom for one message then hard del()s it. var/global/obj/item/radio/intercom/global_announcer = create_global_announcer() var/global/obj/item/radio/intercom/command/command_announcer = create_command_announcer() diff --git a/code/controllers/Processes/event.dm b/code/controllers/Processes/event.dm index 42e8c4bcc1d..ee3e1310f1c 100644 --- a/code/controllers/Processes/event.dm +++ b/code/controllers/Processes/event.dm @@ -1,18 +1,3 @@ -/datum/controller/process/event/setup() - name = "event" - schedule_interval = 20 // every 2 seconds - if(!holiday_master) - holiday_master = new - holiday_master.Setup() - -/datum/controller/process/event/doWork() - event_manager.process() - holiday_master.process() - -///////// -//Holiday controller -///////// - var/global/datum/controller/holiday/holiday_master //This has to be defined before world. /datum/controller/holiday diff --git a/code/modules/events/event_manager.dm b/code/controllers/subsystem/events.dm similarity index 73% rename from code/modules/events/event_manager.dm rename to code/controllers/subsystem/events.dm index 1545ddbbdf0..7d0b20b129d 100644 --- a/code/modules/events/event_manager.dm +++ b/code/controllers/subsystem/events.dm @@ -1,19 +1,25 @@ -/datum/event_manager +SUBSYSTEM_DEF(events) + name = "Events" + init_order = INIT_ORDER_EVENTS + runlevels = RUNLEVEL_GAME + // Report events at the end of the rouund + var/report_at_round_end = 0 + + // UI vars var/window_x = 700 var/window_y = 600 - var/report_at_round_end = 0 var/table_options = " align='center'" var/head_options = " style='font-weight:bold;'" var/row_options1 = " width='85px'" var/row_options2 = " width='260px'" var/row_options3 = " width='150px'" + + // Event vars var/datum/event_container/selected_event_container = null - - var/list/datum/event/active_events = list() - var/list/datum/event/finished_events = list() - - var/list/datum/event/allEvents - var/list/datum/event_container/event_containers = list( + var/list/active_events = list() + var/list/finished_events = list() + var/list/allEvents + var/list/event_containers = list( EVENT_LEVEL_MUNDANE = new/datum/event_container/mundane, EVENT_LEVEL_MODERATE = new/datum/event_container/moderate, EVENT_LEVEL_MAJOR = new/datum/event_container/major @@ -21,18 +27,19 @@ var/datum/event_meta/new_event = new -/datum/event_manager/New() +/datum/controller/subsystem/events/Initialize() allEvents = subtypesof(/datum/event) + ..() -/datum/event_manager/proc/process() - for(var/datum/event/E in event_manager.active_events) +/datum/controller/subsystem/events/fire() + for(var/datum/event/E in active_events) E.process() for(var/i = EVENT_LEVEL_MUNDANE to EVENT_LEVEL_MAJOR) var/list/datum/event_container/EC = event_containers[i] EC.process() -/datum/event_manager/proc/event_complete(var/datum/event/E) +/datum/controller/subsystem/events/proc/event_complete(var/datum/event/E) if(!E.event_meta) // datum/event is used here and there for random reasons, maintaining "backwards compatibility" log_debug("Event of '[E.type]' with missing meta-data has completed.") return @@ -57,11 +64,11 @@ log_debug("Event '[EM.name]' has completed at [station_time_timestamp()].") -/datum/event_manager/proc/delay_events(var/severity, var/delay) +/datum/controller/subsystem/events/proc/delay_events(var/severity, var/delay) var/list/datum/event_container/EC = event_containers[severity] EC.next_event_time += delay -/datum/event_manager/proc/Interact(var/mob/living/user) +/datum/controller/subsystem/events/proc/Interact(var/mob/living/user) var/html = GetInteractWindow() @@ -69,7 +76,7 @@ popup.set_content(html) popup.open() -/datum/event_manager/proc/RoundEnd() +/datum/controller/subsystem/events/proc/RoundEnd() if(!report_at_round_end) return @@ -89,7 +96,7 @@ to_chat(world, message) -/datum/event_manager/proc/GetInteractWindow() +/datum/controller/subsystem/events/proc/GetInteractWindow() var/html = "Refresh" if(selected_event_container) @@ -197,7 +204,7 @@ return html -/datum/event_manager/Topic(href, href_list) +/datum/controller/subsystem/events/Topic(href, href_list) if(..()) return @@ -290,123 +297,3 @@ EC.next_event = null Interact(usr) - -/client/proc/forceEvent(var/type in event_manager.allEvents) - set name = "Trigger Event (Debug Only)" - set category = "Debug" - - if(!holder) - return - - if(ispath(type)) - new type(new /datum/event_meta(EVENT_LEVEL_MAJOR)) - message_admins("[key_name_admin(usr)] has triggered an event. ([type])", 1) - -/client/proc/event_manager_panel() - set name = "Event Manager Panel" - set category = "Event" - if(event_manager) - event_manager.Interact(usr) - feedback_add_details("admin_verb","EMP") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc! - return - -/proc/findEventArea() //Here's a nice proc to use to find an area for your event to land in! - var/area/candidate = null - - var/list/safe_areas = list( - /area/turret_protected/ai, - /area/turret_protected/ai_upload, - /area/engine, - /area/solar, - /area/holodeck, - /area/shuttle/arrival, - /area/shuttle/escape, - /area/shuttle/escape_pod1/station, - /area/shuttle/escape_pod2/station, - /area/shuttle/escape_pod3/station, - /area/shuttle/escape_pod5/station, - /area/shuttle/specops/station, - /area/shuttle/prison/station, - /area/shuttle/administration/station - ) - - //These are needed because /area/engine has to be removed from the list, but we still want these areas to get fucked up. - var/list/danger_areas = list( - /area/engine/break_room, - /area/engine/chiefs_office) - - var/list/event_areas = list() - - for(var/areapath in the_station_areas) - event_areas += typesof(areapath) - for(var/areapath in safe_areas) - event_areas -= typesof(areapath) - for(var/areapath in danger_areas) - event_areas += typesof(areapath) - - while(event_areas.len > 0) - var/list/event_turfs = null - candidate = locate(pick_n_take(event_areas)) - event_turfs = get_area_turfs(candidate) - if(event_turfs.len > 0) - break - - return candidate - -/datum/event/proc/num_players() - var/players = 0 - for(var/mob/living/carbon/human/P in GLOB.player_list) - if(P.client) - players++ - return players - -// Returns how many characters are currently active(not logged out, not AFK for more than 10 minutes) -// with a specific role. -// Note that this isn't sorted by department, because e.g. having a roboticist shouldn't make meteors spawn. -/proc/number_active_with_role() - var/list/active_with_role = list() - active_with_role["Engineer"] = 0 - active_with_role["Medical"] = 0 - active_with_role["Security"] = 0 - active_with_role["Scientist"] = 0 - active_with_role["AI"] = 0 - active_with_role["Cyborg"] = 0 - active_with_role["Janitor"] = 0 - active_with_role["Botanist"] = 0 - active_with_role["Any"] = GLOB.player_list.len - - for(var/mob/M in GLOB.player_list) - if(!M.mind || !M.client || M.client.inactivity > 10 * 10 * 60) // longer than 10 minutes AFK counts them as inactive - continue - - if(istype(M, /mob/living/silicon/robot) && M:module && M:module.name == "engineering robot module") - active_with_role["Engineer"]++ - if(M.mind.assigned_role in list("Chief Engineer", "Station Engineer")) - active_with_role["Engineer"]++ - - if(istype(M, /mob/living/silicon/robot) && M:module && M:module.name == "medical robot module") - active_with_role["Medical"]++ - if(M.mind.assigned_role in list("Chief Medical Officer", "Medical Doctor")) - active_with_role["Medical"]++ - - if(istype(M, /mob/living/silicon/robot) && M:module && M:module.name == "security robot module") - active_with_role["Security"]++ - if(M.mind.assigned_role in security_positions) - active_with_role["Security"]++ - - if(M.mind.assigned_role in list("Research Director", "Scientist")) - active_with_role["Scientist"]++ - - if(M.mind.assigned_role == "AI") - active_with_role["AI"]++ - - if(M.mind.assigned_role == "Cyborg") - active_with_role["Cyborg"]++ - - if(M.mind.assigned_role == "Janitor") - active_with_role["Janitor"]++ - - if(M.mind.assigned_role == "Botanist") - active_with_role["Botanist"]++ - - return active_with_role diff --git a/code/controllers/subsystem/holiday.dm b/code/controllers/subsystem/holiday.dm new file mode 100644 index 00000000000..a5eb957a80f --- /dev/null +++ b/code/controllers/subsystem/holiday.dm @@ -0,0 +1,31 @@ +SUBSYSTEM_DEF(holiday) + name = "Holiday" + init_order = INIT_ORDER_HOLIDAY // 3 + flags = SS_NO_FIRE + var/list/holidays + +/datum/controller/subsystem/holiday/Initialize(start_timeofday) + if(!config.allow_holidays) + return ..() //Holiday stuff was not enabled in the config! + + var/YY = text2num(time2text(world.timeofday, "YY")) // get the current year + var/MM = text2num(time2text(world.timeofday, "MM")) // get the current month + var/DD = text2num(time2text(world.timeofday, "DD")) // get the current day + + for(var/H in subtypesof(/datum/holiday)) + var/datum/holiday/holiday = new H() + if(holiday.shouldCelebrate(DD, MM, YY)) + holiday.celebrate() + if(!holidays) + holidays = list() + holidays[holiday.name] = holiday + + if(holidays) + holidays = shuffle(holidays) + world.update_status() + for(var/datum/holiday/H in holidays) + if(H.eventChance) + if(prob(H.eventChance)) + H.handle_event() + + ..() \ No newline at end of file diff --git a/code/controllers/verbs.dm b/code/controllers/verbs.dm index 6d077ee5173..525d00399fa 100644 --- a/code/controllers/verbs.dm +++ b/code/controllers/verbs.dm @@ -60,7 +60,7 @@ debug_variables(cameranet) feedback_add_details("admin_verb","DCameras") if("Event") - debug_variables(event_manager) + debug_variables(SSevents) feedback_add_details("admin_verb","DEvent") if("Alarm") debug_variables(alarm_manager) diff --git a/code/game/gamemodes/gameticker.dm b/code/game/gamemodes/gameticker.dm index c2268063822..a68f2db4e53 100644 --- a/code/game/gamemodes/gameticker.dm +++ b/code/game/gamemodes/gameticker.dm @@ -172,10 +172,10 @@ var/round_start_time = 0 to_chat(world, "Enjoy the game!") world << sound('sound/AI/welcome.ogg')// Skie - if(holiday_master.holidays) + if(SSholiday.holidays) to_chat(world, "and...") - for(var/holidayname in holiday_master.holidays) - var/datum/holiday/holiday = holiday_master.holidays[holidayname] + for(var/holidayname in SSholiday.holidays) + var/datum/holiday/holiday = SSholiday.holidays[holidayname] to_chat(world, "

[holiday.greet()]

") spawn(0) // Forking dynamic room selection @@ -506,7 +506,7 @@ var/round_start_time = 0 mode.declare_station_goal_completion() //Ask the event manager to print round end information - event_manager.RoundEnd() + SSevents.RoundEnd() return 1 diff --git a/code/modules/events/event.dm b/code/modules/events/event.dm index 0f5c43059e8..a5e07840d34 100644 --- a/code/modules/events/event.dm +++ b/code/modules/events/event.dm @@ -137,12 +137,12 @@ end() endedAt = world.time - event_manager.active_events -= src - event_manager.event_complete(src) + SSevents.active_events -= src + SSevents.event_complete(src) /datum/event/New(var/datum/event_meta/EM) // event needs to be responsible for this, as stuff like APLUs currently make their own events for curious reasons - event_manager.active_events += src + SSevents.active_events += src if(!EM) EM = new /datum/event_meta(EVENT_LEVEL_MAJOR, "Unknown, Most likely admin called", src.type) diff --git a/code/modules/events/event_procs.dm b/code/modules/events/event_procs.dm new file mode 100644 index 00000000000..02ae1454597 --- /dev/null +++ b/code/modules/events/event_procs.dm @@ -0,0 +1,120 @@ + +/client/proc/forceEvent(var/type in SSevents.allEvents) + set name = "Trigger Event (Debug Only)" + set category = "Debug" + + if(!holder) + return + + if(ispath(type)) + new type(new /datum/event_meta(EVENT_LEVEL_MAJOR)) + message_admins("[key_name_admin(usr)] has triggered an event. ([type])", 1) + +/client/proc/event_manager_panel() + set name = "Event Manager Panel" + set category = "Event" + if(SSevents) + SSevents.Interact(usr) + feedback_add_details("admin_verb","EMP") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc! + return + +/proc/findEventArea() //Here's a nice proc to use to find an area for your event to land in! + var/area/candidate = null + + var/list/safe_areas = list( + /area/turret_protected/ai, + /area/turret_protected/ai_upload, + /area/engine, + /area/solar, + /area/holodeck, + /area/shuttle/arrival, + /area/shuttle/escape, + /area/shuttle/escape_pod1/station, + /area/shuttle/escape_pod2/station, + /area/shuttle/escape_pod3/station, + /area/shuttle/escape_pod5/station, + /area/shuttle/specops/station, + /area/shuttle/prison/station, + /area/shuttle/administration/station + ) + + //These are needed because /area/engine has to be removed from the list, but we still want these areas to get fucked up. + var/list/danger_areas = list( + /area/engine/break_room, + /area/engine/chiefs_office) + + var/list/event_areas = list() + + for(var/areapath in the_station_areas) + event_areas += typesof(areapath) + for(var/areapath in safe_areas) + event_areas -= typesof(areapath) + for(var/areapath in danger_areas) + event_areas += typesof(areapath) + + while(event_areas.len > 0) + var/list/event_turfs = null + candidate = locate(pick_n_take(event_areas)) + event_turfs = get_area_turfs(candidate) + if(event_turfs.len > 0) + break + + return candidate + +// Returns how many characters are currently active(not logged out, not AFK for more than 10 minutes) +// with a specific role. +// Note that this isn't sorted by department, because e.g. having a roboticist shouldn't make meteors spawn. +/proc/number_active_with_role() + var/list/active_with_role = list() + active_with_role["Engineer"] = 0 + active_with_role["Medical"] = 0 + active_with_role["Security"] = 0 + active_with_role["Scientist"] = 0 + active_with_role["AI"] = 0 + active_with_role["Cyborg"] = 0 + active_with_role["Janitor"] = 0 + active_with_role["Botanist"] = 0 + active_with_role["Any"] = GLOB.player_list.len + + for(var/mob/M in GLOB.player_list) + if(!M.mind || !M.client || M.client.inactivity > 10 * 10 * 60) // longer than 10 minutes AFK counts them as inactive + continue + + if(istype(M, /mob/living/silicon/robot) && M:module && M:module.name == "engineering robot module") + active_with_role["Engineer"]++ + if(M.mind.assigned_role in list("Chief Engineer", "Station Engineer")) + active_with_role["Engineer"]++ + + if(istype(M, /mob/living/silicon/robot) && M:module && M:module.name == "medical robot module") + active_with_role["Medical"]++ + if(M.mind.assigned_role in list("Chief Medical Officer", "Medical Doctor")) + active_with_role["Medical"]++ + + if(istype(M, /mob/living/silicon/robot) && M:module && M:module.name == "security robot module") + active_with_role["Security"]++ + if(M.mind.assigned_role in security_positions) + active_with_role["Security"]++ + + if(M.mind.assigned_role in list("Research Director", "Scientist")) + active_with_role["Scientist"]++ + + if(M.mind.assigned_role == "AI") + active_with_role["AI"]++ + + if(M.mind.assigned_role == "Cyborg") + active_with_role["Cyborg"]++ + + if(M.mind.assigned_role == "Janitor") + active_with_role["Janitor"]++ + + if(M.mind.assigned_role == "Botanist") + active_with_role["Botanist"]++ + + return active_with_role + +/datum/event/proc/num_players() + var/players = 0 + for(var/mob/living/carbon/human/P in GLOB.player_list) + if(P.client) + players++ + return players diff --git a/code/modules/events/false_alarm.dm b/code/modules/events/false_alarm.dm index e63805d6a1d..a0aa17596fd 100644 --- a/code/modules/events/false_alarm.dm +++ b/code/modules/events/false_alarm.dm @@ -4,7 +4,7 @@ /datum/event/falsealarm/announce() var/weight = pickweight(list(EVENT_LEVEL_MUNDANE = 60, EVENT_LEVEL_MODERATE = 30, EVENT_LEVEL_MAJOR = 10)) - var/datum/event_container/container = event_manager.event_containers[weight] + var/datum/event_container/container = SSevents.event_containers[weight] var/datum/event/E = container.acquire_event() var/datum/event/Event = new E message_admins("False Alarm: [Event]") diff --git a/code/modules/holiday/holiday.dm b/code/modules/holiday/holiday.dm index 414df7f7589..f87422e2ad1 100644 --- a/code/modules/holiday/holiday.dm +++ b/code/modules/holiday/holiday.dm @@ -345,9 +345,9 @@ if(!istype(H)) return H.celebrate() - if(!holiday_master.holidays) - holiday_master.holidays = list() - holiday_master.holidays[H.name] = H + if(!SSholiday.holidays) + SSholiday.holidays = list() + SSholiday.holidays[H.name] = H //update our hub status world.update_status() diff --git a/code/modules/paperwork/paper.dm b/code/modules/paperwork/paper.dm index d5ca6b0b0f8..528864b18a6 100644 --- a/code/modules/paperwork/paper.dm +++ b/code/modules/paperwork/paper.dm @@ -108,7 +108,7 @@ /obj/item/paper/attack_self(mob/living/user as mob) user.examinate(src) - if(rigged && (holiday_master.holidays && holiday_master.holidays[APRIL_FOOLS])) + if(rigged && (SSholiday.holidays && SSholiday.holidays[APRIL_FOOLS])) if(spam_flag == 0) spam_flag = 1 playsound(loc, 'sound/items/bikehorn.ogg', 50, 1) diff --git a/code/modules/paperwork/paperbin.dm b/code/modules/paperwork/paperbin.dm index e8643c97cff..c9169a09757 100644 --- a/code/modules/paperwork/paperbin.dm +++ b/code/modules/paperwork/paperbin.dm @@ -72,7 +72,7 @@ papers.Remove(P) else P = new /obj/item/paper - if(holiday_master.holidays && holiday_master.holidays[APRIL_FOOLS]) + if(SSholiday.holidays && SSholiday.holidays[APRIL_FOOLS]) if(prob(30)) P.info = "HONK HONK HONK HONK HONK HONK HONK
HOOOOOOOOOOOOOOOOOOOOOONK
APRIL FOOLS
" P.rigged = 1 diff --git a/code/modules/station_goals/shield.dm b/code/modules/station_goals/shield.dm index a4444938d96..09ccb3ce36b 100644 --- a/code/modules/station_goals/shield.dm +++ b/code/modules/station_goals/shield.dm @@ -175,7 +175,7 @@ change_meteor_chance(0.5) /obj/machinery/satellite/meteor_shield/proc/change_meteor_chance(mod) - for(var/datum/event_container/container in event_manager.event_containers) + for(var/datum/event_container/container in SSevents.event_containers) for(var/datum/event_meta/M in container.available_events) if(M.event_type == /datum/event/meteor_wave) M.weight *= mod diff --git a/paradise.dme b/paradise.dme index e478048e4d8..a3e0c872707 100644 --- a/paradise.dme +++ b/paradise.dme @@ -198,7 +198,6 @@ #include "code\controllers\subsystem.dm" #include "code\controllers\verbs.dm" #include "code\controllers\Processes\alarm.dm" -#include "code\controllers\Processes\event.dm" #include "code\controllers\Processes\fast_process.dm" #include "code\controllers\Processes\lighting.dm" #include "code\controllers\Processes\npcai.dm" @@ -209,8 +208,10 @@ #include "code\controllers\subsystem\air.dm" #include "code\controllers\subsystem\assets.dm" #include "code\controllers\subsystem\atoms.dm" +#include "code\controllers\subsystem\events.dm" #include "code\controllers\subsystem\fires.dm" #include "code\controllers\subsystem\garbage.dm" +#include "code\controllers\subsystem\holiday.dm" #include "code\controllers\subsystem\icon_smooth.dm" #include "code\controllers\subsystem\jobs.dm" #include "code\controllers\subsystem\machinery.dm" @@ -1418,7 +1419,7 @@ #include "code\modules\events\electrical_storm.dm" #include "code\modules\events\event.dm" #include "code\modules\events\event_container.dm" -#include "code\modules\events\event_manager.dm" +#include "code\modules\events\event_procs.dm" #include "code\modules\events\false_alarm.dm" #include "code\modules\events\floorcluwne.dm" #include "code\modules\events\grid_check.dm"